/*
	************************************************************

		utility.js
		intended for generic use on any page
		included by leui.asp
 */

/*
	myGetElementById
	Given
		an object id or name
	Return
		the object, or null if not found
	Notes
		* this function is for browsers that don't understand the built-in
		  getElementById function
		* searchs ID first, then name for matching formObjID value	
*/
function myGetElementById(formObjID)
{
	var numForms = top.document.forms.length;
	var numElemsOnForm;
	var foundObj = false;
	var objFound = null;
	
	for (var i=0; (i<numForms && foundObj == false); i++)
	{
		numElemsOnForm = top.document.forms[i].elements.length;
		
		for(var j=0; (j<numElemsOnForm && foundObj == false); j++)
		{
			if(top.document.forms[i].elements[j].ID == formObjID || top.document.forms[i].elements[j].name == formObjID)
			{
				objFound = top.document.forms[i].elements[j];
				foundObj = true;
			}
		}
	}
	
	return objFound;
}

/*
	whatsMyFormName
	Given
		the name of a form control
	Return
		the name of the form that contains the form, or 'notFound' if not found 
	Author 
		a.c.
	Call method:
		whatsMyFormName('txtSomeTextBoxOnAForm');
*/

function whatsMyFormName(formObjName)
{
	var numForms = top.document.forms.length;
	var numElemsOnForm;
	var foundName = false;
	var nameFound = new String('notFound');
	
	for (var i=0; (i<numForms && foundName == false); i++)
	{
		numElemsOnForm = top.document.forms[i].elements.length;
		
		for(var j=0; (j<numElemsOnForm && foundName == false); j++)
		{
			if(top.document.forms[i].elements[j].name == formObjName)
			{
				nameFound = top.document.forms[i].name;
				foundName = true;
			}
		}
	}
	
	return nameFound.toString();
}
/*
	hideLinks
	Given
		the name of the span to be hidden.
	Return
		the original html string that has been hidden 
	Author 
		Kevin DePolo
	Call method:
		hideLinks('addLinks');
*/
function hideLinks(spanName){ 
	if (document.all && !document.getElementById) {
		//Netscape does not support document.all 
		submitHTML = document.all[spanName].innerHTML;
		document.all[spanName].innerHTML = '';
	}
	else {
	    if (document.getElementById(spanName)) {
	        submitHTML = document.getElementById(spanName).innerHTML;
	        document.getElementById(spanName).innerHTML = '';
	    }
	}
	return submitHTML;
}
/*
    hideLinks2
    Input
        spanName: The name of the span to be hidden.
    Return
        HTML string that was removed/hidden. 
    Author 
        Randy Skedel
    Call method:
        hideLinks2(sHTML, 'addLinks');
*/
function hideLinks2(spanName) {
    var sNavHTML_temp = hideLinks(spanName);
    if (sNavHTML_temp != '') {
        sNavHTML = sNavHTML_temp;
        }
}
/*
	unHideLinks
	Given
		the html string to be displayed
		the name of the span to display the html string
	Return
		none
	Author 
		Kevin DePolo
	Call method:
		unHideLinks('htmldatastring', 'addLinks');
*/
function unHideLinks(htmlstring, spanName) {
	if (document.all && !document.getElementById) {
		//Netscape does not support document.all  
		 document.all[spanName].innerHTML = htmlstring;
	}
	else { 
		document.getElementById(spanName).innerHTML = htmlstring; 
	}
}
/*
    unHideLinks2
    Given
        the html string to be displayed
        the name of the span to display the html string
    Return
        none
    Author 
        Randy Skedel
    Call method:
        unHideLinks('htmldatastring', 'addLinks');
*/
function unHideLinks2(htmlstring, spanName) {
    if (htmlstring != '') {
        unHideLinks(htmlstring, spanName);
    }
}

//This function is used on all pages to take the <Enter> key as a form submit.
if (document.layers)
  document.captureEvents(Event.KEYDOWN);
  document.onkeydown =
    function (evt) { 
      var keyCode = evt ? (evt.which ? evt.which : evt.keyCode) : event.keyCode;
      if (keyCode == 13)   //13 = the code for pressing ENTER 
      {
         if (window.validate) {
            //Only take the enter key for IE.
            if ((document.all) && (this.activeElement.type != 'textarea')) {
                //Do not run form validate, it user changed payer.  Do payer validate.
                if (this.activeElement == document.forms.frmGlobalPayer.CustomerNumber) {
                    return true;
                }
                else {
                    validate();
                    return false;
                    }
            }           
         }
      }
  }
  
  // AJAX -  To get descriptions
  function populateSpanAJAX(spanName, pageURL) {
      var xmlHttp;
      try {
          // Firefox, Opera 8.0+, Safari
          xmlHttp = new XMLHttpRequest();
      }
      catch (e) {
          // Internet Explorer
          try {
              xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
          }
          catch (e) {
              try {
                  xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
              }
              catch (e) {
                  alert("Your browser does not support AJAX!");
                  return false;
              }
          }
      }
      xmlHttp.onreadystatechange = function() {
          if (xmlHttp.readyState == 4) {
              if (document.all && !document.getElementById) {
                  //Netscape does not support document.all
                  document.all[spanName].innerHTML = xmlHttp.responseText;
              }
              else {
                  document.getElementById(spanName).innerHTML = xmlHttp.responseText;
              }
          }
      }
      xmlHttp.open("GET", pageURL, true);
      xmlHttp.send(null);
  }
 