function initLocal()
{
}

function initCommon()
{
  /* Fix now implemented in XSL *
  // Initialize menu for Internet Explorer
  if (isIE())
  {
    initMenuIE();
  }
  */

  // Add menu fix for ehtml serialization
  var MENU_EHTML_FIX = '@import url("/commons/styles/neptune/common/menu-ehtml-fix.css");';

  if (!isIE() && !isMozilla())
  {
    var stylesheets = document.styleSheets;

    if (stylesheets.length > 0)
    {
      if (Boolean(stylesheets.item(0).insertRule))
      {
        stylesheets.item(0).insertRule(MENU_EHTML_FIX, 0);
      }
    }
  }
}

/* Utility Functions */

function getHeaderID(id)
{
  return id.toLowerCase().replace(/\W/g, "_").replace(/^_+|_+$/, "");
}

function getHeaderName(id)
{
  return id.replace(/[\W_]/g, " ").replace(/\b\w/g, upper).replace(/\b\w{1,3}\b/g, upper);

  function upper()
  {
    return arguments[0].toUpperCase();
  }
}

/* Form Submissions */

function validateChangePasswordForm()
{
  var password = document.getElementById('newPassword');
  var confPassword = document.getElementById('confPassword');

  var success = true;
  var msg;

  if (/\s/.test(password.value))
  {
    success = false;

    msg = 'Password cannot contain spaces.';
  }

  else if (password.value.length < 8)
  {
    success = false;

    msg = 'Password must be at least 8 characters long.';
  }

  else if (password.value != confPassword.value)
  {
    success = false;

    msg = 'The password and confirmation password do not match.';
  }

  if (!success)
  {
    alert(msg);
  }

  return(success);
}

function processConfirmedSubmit(url, target)
{
  var success = confirmSubmit();

  if (success)
  {
    openWindow(url, target);

    return (true);
  }

  else
  {
    return (false);
  }
}

function confirmSubmit()
{
  return (confirm('Are you sure you want to submit?'));
}

function openWindow(url, target)
{
  var winRef = window.open(url, target, 'menubar=no,location=no,resizable=yes,scrollbars=yes,status=yes');
  winRef.focus();
}

function openWindowStd(url, target)
{
  var winRef = window.open(url, target);
  winRef.focus();
}

/* End Form Submissions */



function getDescendentNodes(parentNode, tagName, className)
{
  switch(arguments.length)
  {
    case 2:
    {
      if (parentNode == null || !parentNode.hasChildNodes())
        return (null);

      var tagNodes;
      var childNodes = new Array();
      var childNode;

      if (Boolean(parentNode.getElementsByTagName))
      {
        tagNodes = parentNode.getElementsByTagName(tagName);
      }

      else
      {
        return;
      }

      for (var i = 0, n = tagNodes.length; i < n; ++i)
      {
        childNode = tagNodes[i];

        if (childNode.nodeType == 1)
        {
          childNodes.push(childNode);
        }
      }

      return (childNodes);
    }

    case 3:
    {
      if (parentNode == null || !parentNode.hasChildNodes())
        return (null);

      var tagNodes = parentNode.getElementsByTagName(tagName);
      var childNodes = new Array();
      var childNode;

      for (var i = 0, n = tagNodes.length; i < n; ++i)
      {
        childNode = tagNodes[i];

        if (childNode.nodeType == 1
          && childNode.className == className)
        {
          childNodes.push(childNode);
        }
      }

      return (childNodes);
    }

    default:
      return (null);
  }
}

function getFirstDescendentNode(parentNode, tagName, className)
{
  switch(arguments.length)
  {
    case 2:
      if (parentNode == null || !parentNode.hasChildNodes())
        return (null);

      var tagNodes = parentNode.getElementsByTagName(tagName);
      var childNode;

      for (var i = 0, n = tagNodes.length; i < n; ++i)
      {
        childNode = tagNodes[i];

        if (childNode.nodeType == 1)
        {
          break;
        }

        else
        {
          childNode = null;
        }
      }

      return (childNode);

    case 3:
      if (parentNode == null || !parentNode.hasChildNodes())
        return (null);

      var tagNodes = parentNode.getElementsByTagName(tagName);
      var childNode;

      for (var i = 0, n = tagNodes.length; i < n; ++i)
      {
        childNode = tagNodes[i];

        if (childNode.nodeType == 1
          && childNode.className == className)
        {
          break;
        }

        else
        {
          childNode = null;
        }
      }

      return (childNode);

    default:
      return (null);
  }
}

function getChildNodes(parentNode, tagName, className)
{
  switch(arguments.length)
  {
    case 2:
    {
      if (parentNode == null || !parentNode.hasChildNodes())
        return (null);

      var allChildNodes = parentNode.childNodes;
      var childNodes = new Array();
      var childNode;

      for (var i = 0, n = allChildNodes.length; i < n; ++i)
      {
        childNode = allChildNodes[i];

        if (childNode.nodeType == 1
          && childNode.tagName.toLowerCase() == tagName)
        {
          childNodes.push(childNode);
        }
      }

      return (childNodes);
    }

    case 3:
    {
      if (parentNode == null || !parentNode.hasChildNodes())
        return (null);

      var allChildNodes = parentNode.childNodes;
      var childNodes = new Array();
      var childNode;

      for (var i = 0, n = allChildNodes.length; i < n; ++i)
      {
        childNode = allChildNodes[i];

        if (childNode.nodeType == 1
          && childNode.className == className
          && childNode.tagName.toLowerCase() == tagName)
        {
          childNodes.push(childNode);
        }
      }

      return (childNodes);
    }

    default:
      return (null);
  }
}

function getFirstChildNode(parentNode, tagName, className)
{
  switch(arguments.length)
  {
    case 2:
    {
      if (parentNode == null || !parentNode.hasChildNodes())
        return (null);

      var allChildNodes = parentNode.childNodes;
      var childNode;

      for (var i = 0, n = allChildNodes.length; i < n; ++i)
      {
        childNode = allChildNodes[i];

        if (childNode.nodeType == 1
          && childNode.tagName.toLowerCase() == tagName)
        {
          break;
        }

        else
        {
          childNode = null;
        }
      }

      return (childNode);
    }

    case 3:
    {
      if (parentNode == null || !parentNode.hasChildNodes())
        return (null);

      var allChildNodes = parentNode.childNodes;
      var childNode;

      for (var i = 0, n = allChildNodes.length; i < n; ++i)
      {
        childNode = allChildNodes[i];

        if (childNode.nodeType == 1
          && childNode.className == className
          && childNode.tagName.toLowerCase() == tagName)
        {
          break;
        }

        else
        {
          childNode = null;
        }
      }

      return (childNode);
    }

    default:
      return (null);
  }
}

function isMozilla()
{
  return(navigator.appName == 'Netscape');
}

function isIE()
{
  return(navigator.appName == 'Microsoft Internet Explorer');
}

function showMaxWin(nUrl)
{
  var h = screen.availHeight-50;
  var w = screen.availWidth-25;
  var features = 'width='+w+', height='+h+',top=10,left=10,resizable=1,scrollbars=0';
  NewWin=window.open(nUrl,'NewWin',features);
}

function fixedScenario()
{
	var elem = document.getElementById('fixed-scenario');
	if (elem != null)
	{
		runScenario(elem);
	}
}

function autoShowSelects()
{
	var elem = document.getElementById('autoshow-selects');
	if (elem != null)
	{
		alert('found it!');
		alert(elem.childNodes[1].id);
		elem.childNodes[1].firstChild.onclick();
	}
}
