/**************************************************************************************************************/
// 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 check_zip(form)
{
	if (!tableBusy)
	{	
		
			
			zip=form.zip.value;
			//alert(zip);
			if(zip =="" || isNaN(zip))
			{
				alert("Invalid Zip Code");
				document.freequoteform.zip.value = "";
				document.freequoteform.zip.focus();					
				return false;
			}
			else
			{
				var url = "zip_action.php?zip="+zip;		
				tableHttp.open("GET", url, true);
				tableHttp.onreadystatechange = checkCategoryListResponse;
				tableBusy = true;
				tableHttp.send(null);
			}
		
	}
}

function checkCategoryListResponse()
{
	if (tableHttp.readyState == 4)
	{
		if (tableHttp.responseText.indexOf('invalid') == -1)
		{
			try
			{
				var output = tableHttp.responseText;
				
				if(output == "")
				{
					alert("Invalid Zip Code");
					document.freequoteform.zip.value = "";
					document.freequoteform.zip.focus();					
					tableBusy = false;
					return false;
				}
				else
				{
					output1 = output.split("|");
					document.freequoteform.city.value = output1[0];	
					document.freequoteform.state.value = output1[2];
				}
				
					
				tableBusy = false;
			
			} // end try 
			catch (e)
			{
				alert("Error: " + e.description) ;
			} // end try catch
		} // end if response index -1
	} // end if readystate 4
} // end tableresponse function

