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();
    }
    catch (e)
    {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}
var http = getHTTPObject();			// We create the HTTP Object


var cityTextBoxID;					// Global variable for city text box
var stateListID;				// Global for State DropDown list
var divID;						// Global for DIV elements that keeps lists
var listID;						//Global for list box that hold cities returned from server
var extraRowID;					// Global for extra row <TR></TR> that will be visible or not
var hiddenStateID;				// Global that will keep State

function OnCityChanged1(cityTextID,divClientID,listBoxClientID,rowID)
{
	var cityTextBoxIDtmp="_ctl0_"+cityTextID;
	var divIDtmp=divClientID;
	var listIDtmp="_ctl0:"+listBoxClientID;
	var extraRowIDtmp=rowID;
	
	var selectedCityName;
	var listBoxElements=document.getElementsByName(listIDtmp);   // this is done because FireFox and Netscape
	selectedCityName=listBoxElements[0].options[listBoxElements[0].selectedIndex].value;
	var textBox=document.getElementById(cityTextBoxIDtmp);
	textBox.value=selectedCityName;
	document.getElementById(divIDtmp).style.display="none";
	document.getElementById(extraRowIDtmp).style.display="none";
	
	//var test=document.getElementById("_ctl0_usr_BOLNumber");
		
}

			 
function SendRequest(zipCodeBoxID,countryListID,cityTextID,divClientID,listBoxClientID,rowID,hiddenID)
{
	zipCodeBoxID="_ctl0_"+zipCodeBoxID;
	countryDropDownID="_ctl0:"+countryListID+":_ctl1";		// drop down list State/Country
	stateListID="_ctl0:"+countryListID+":_ctl0";			// drop own list State/Country
	cityTextBoxID="_ctl0_"+cityTextID;
	divID=divClientID;
	listID="_ctl0:"+listBoxClientID;
	extraRowID=rowID;
	hiddenStateID="_ctl0_"+hiddenID;
		
	var test=document.getElementById("_ctl0_usr_BOLNumber");			// for testting
	var zipCode=document.getElementById(zipCodeBoxID).value; 
	var countryList=document.getElementsByName(countryDropDownID);
	var country=countryList[0].options[countryList[0].selectedIndex].value;
	
	var charNumber=5;
	if(country=="2")
		charNumber=6;
		
	if(zipCode.length==charNumber)
	{
		var url = "CreateBOL.aspx?";
		var request="paramZipCode="+zipCode+"&paramCountry="+country; //&paramType="+type
		http.open("GET", url + request, true);
		http.onreadystatechange = handleHttpResponse;
		http.send(null);
	}
}
	
	
function handleHttpResponse()
{
	//div.innerHTML="No data returned!";
  if (http.readyState == 4) 
  {
  	var results = http.responseText.split(",");
  	var update=results[1];
    var citiesList=results[0];
    var stateAbrev=results[2];
    
   	if(update=="true")
  	{
  	    
  	
  		var test=document.getElementById('_ctl0_usr_BOLNumber');
  		var list=citiesList.split('~');  // there could be multiple city names for one zip code
  		var cityText=document.getElementById(cityTextBoxID);
  		
  		if(cityTextBoxID =="_ctl0_usr_ShipperCity")
  		{
  			document.getElementById('_ctl0_usr_PUPickupDate').options.selectedIndex = 0;
  		}
  		
  		var hiddenState=document.getElementById(hiddenStateID);
  		cityText.value=list[0];
  		var state=document.getElementsByName(stateListID);
  		var listBoxElements=document.getElementsByName(listID);   // this is done because FireFox and Netscape
  		
		// set state in state dropdown list  /////////////////////////////
		var index=0;
		for(var i=0;i<state[0].length;i++)
		{
			if(state[0].options[i].value==stateAbrev)
				index=i;
		}
		state[0].options[index].selected=true;
		hiddenState.value=stateAbrev;
		
		//////////////////////////////////////////////////////////////////
	
		var listBox =listBoxElements[0];
  		for(var k=0;k<=listBox.length;k++)
  		{
  			listBox.remove(k);
  		}
  		
  		//populate List Box with data from server if there are more cities returned
  		if(list.length>2)
  		{
  			for(var i=0;i<list.length-1;i++)
			{
				if(i==0)
				{
					listBox.remove(0);
					listBox.options[listBox.options.length] = new Option(list[i],list[i],listBox.options.length);
				}
				else
				{
					if(list[i]!="")
						listBox.options[listBox.options.length] = new Option(list[i],list[i], listBox.options.length);
				}
			}
			
			for(var i=0;i<list.length-1;i++)
			{
				listBox.options[i].selected=false;
			}
			
			document.getElementById(divID).style.display="";
			document.getElementById(extraRowID).style.display="";
			
		}
		else			// if there is just one city returned there is no need for list box
		{
			listBox.remove(0);
			document.getElementById(divID).style.display="none";
		}

  	}
  }
}


 
 
