/**************************************************************************************************************/
// Create xmlhttp object based on browsertype
function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
	  xmlhttp.overrideMimeType("text/xml"); 
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}
/**************************************************************************************************************/
// Define global variables to be used throughout
var tableBusy = false;
var tableHttp = getHTTPObject();
var step1Over = false;
var row = "";
/**************************************************************************************************************/

function getState(form)
{
	//document.getElementById('imgProgress').style.display = 'inline';
	if (!tableBusy)
	{
		countryId = eval("document."+form).pcatId.value;
		eval("document."+form).catId.options.length = 0;			
		eval("document."+form).catId.options[0] = new Option("Loading...","");
		var url = "action.php?form_name="+form+"&mode=getState&countryid=" + countryId;		
		tableHttp.open("GET", url, true);
		tableHttp.onreadystatechange = checkStateResponse;
		tableBusy = true;
		tableHttp.send(null);
	}
}
function checkStateResponse()
{
	if (tableHttp.readyState == 4)
	{
		if (tableHttp.responseText.indexOf('invalid') == -1)
		{
			try
			{
				var xmlRecord = tableHttp.responseXML.getElementsByTagName('catId');

				// Use the first data record to supply status, summary, etc
				var output = xmlRecord[0].getElementsByTagName('statename').item(0).firstChild.data;
				var outputform = xmlRecord[0].getElementsByTagName('formname').item(0).firstChild.data;
				
				if (output == "No SubCategory|")
				{
					eval("document."+outputform).catId.options.length = 0;
				}
				else
				{
					var stateBox = eval("document."+outputform).catId;
					stateBox.options.length = 0;
					
					var outputArr = new Array();
					outputArr = output.split(":");

					var list = outputArr;

					for(i=0;i<list.length;i=i+1)
					{
						var stateString = list[i];
						var stateArr = new Array();
						stateArr = stateString.split("|");
						stateBox.options[i] = new Option(stateArr[0],stateArr[1]);	//new Option('new text','new value');
					}
					
				}
				
				// Draw Record status and nav buttons
				//document.getElementById('checkresponse').innerHTML = output;				
				
				tableBusy = false;
				//document.getElementById('imgProgress').style.display = 'none';
				
			} // end try 
			catch(e)
			{
				alert("Error: " + e) ;
			} // end try catch
		} // end if response index -1
	} // end if readystate 4
} // end tableresponse function