
//Convert to proper case function
function PCase(s)
{
  return s.toLowerCase().replace(/^(.)|\s(.)/g, 
          function($1) { return $1.toUpperCase(); });
}

//AJAX Functions:::::::::::::::::::::::::::::::::::::::::::::::
var obj;
var elementID;
function GetDataViaAJAX(PageName,QRY,elemID,DivShow,DivHide,miscParms)
{
	if(window.XMLHttpRequest){
      // Firefox, Safari, Opera...
      obj = new XMLHttpRequest();
   } else if(window.ActiveXObject) {
      // Internet Explorer 5+
      try
      {obj = new ActiveXObject("Msxml2.XMLHTTP");}
      catch(e)
      {
      try
      {obj = new ActiveXObject("Microsoft.XMLHTTP");}
      catch(e1)
      {
      obj = null;
      }
      }
   } else {
      // There is an error creating the object,
      // just as an old browser is being used.
      alert('Problem creating the XMLHttpRequest object, Please upgrade your browser');
      obj = null;
   } 
if(obj!=null)
{
var theLink = PageName + "?parm1=" + QRY + "&parm2=" + miscParms

if (DivShow !='NA'){
//hide or show necessary DIVs
var styleShow = getStyleObject(DivShow);
//styleShow.visibility = "visible";
styleShow.display = "block";
var styleHide = getStyleObject(DivHide);
//styleHide.visibility = "hidden";
styleHide.display = "none";
}

  elementID = elemID;
 //show temporary message
  var combo1 = document.getElementById(elementID);
  combo1.disabled = false;
  combo1.options[0] = new Option('Loading options, Please wait...');
  combo1.focus();
    
  obj.onreadystatechange = ProcessResponse;
  obj.open("GET", theLink ,  true);
  obj.send(null); 
          
}
return false;
}
function ProcessResponse()
{
	if(obj.readyState == 4)
	{	
		if(obj.status == 200)
		{		
		var dsRoot=obj.responseXML.documentElement;  
		var combo1 = document.getElementById(elementID);
		 //clear out list
			for (var count = combo1.options.length-1;
			count >-1; count--)
			{
			combo1.options[count] = null;
			}
		var optionText =  dsRoot.getElementsByTagName('optionText');
		var optionValue = dsRoot.getElementsByTagName('optionValue');
		
		var text; 
		var optionVal;
		var listItem;
		if (optionText.length > 1){
		
		combo1.options[0] = new Option('---Please Select one----','NADA');
		}
			for (var count = 0; count < optionText.length; count++)
			{
		    //alert(optionText[count].childNodes[0].nodeValue);
		    optionVal =getInnerText(optionText[count].childNodes[0]);
		   ////optionVal =optionText[count].childNodes[0].nodeValue;
		    ////optionVal = (optionValue[count].textContent || 
			////optionValue[count].innerText || optionValue[count].text);
			
			////text = optionValue[count].childNodes[0].nodeValue;
			text =getInnerText(optionValue[count].childNodes[0]);
			/////text = (optionText[count].textContent || 
			////optionText[count].innerText || optionText[count].text);
			//listItem = new Option(PCase(text),optionVal,  false, false);
			listItem = new Option(optionVal,text,  false, false);
			combo1.options[combo1.length] = listItem;
			}
		}
		else
		{
		alert("Error retrieving data!" );
		}
	}
	
}
function getInnerText (node) {
//alert(node);
  if (typeof node.textContent != 'undefined')
  {
    return node.textContent;
  }
  else if (typeof node.innerText != 'undefined')
  {
    return node.innerText;
  }
  else if (typeof node.text != 'undefined')
  {
    return node.text;
  }
  else
  {
    switch (node.nodeType)
    {
      case 3:
      case 4:
        return node.nodeValue;
        break;
      case 1:
      case 11:
        var innerText = '';
        for (var i = 0; i < node.childNodes.length; i++)
        {
          innerText += getInnerText(node.childNodes[i]);
        }
        return innerText;
        break;
      default:
        return '';
    }
  }
}

//********************************************
function getStyleObject(objectId) {
  // checkW3C DOM, then MSIE 4, then NN 4.
  //
  if(document.getElementById && document.getElementById(objectId)) {
	return document.getElementById(objectId).style;
   }
   else if (document.all && document.all(objectId)) {  
	return document.all(objectId).style;
   } 
   else if (document.layers && document.layers[objectId]) { 
	return document.layers[objectId];
   } else {
	return false;
   }
}
//****************************************8

//END AJAX FUNCTIONS::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::