var http;// = getHTTPObject();
var countryobj;
var stateobj;
var state_name
function handleHttpResponse2() 
{ 
	//alert(state_name);
	//alert(http.readyState);
	if (http.readyState == 4) 
	{	
      	isWorking = false;
    	if (http.responseText.indexOf('invalid') == -1) 
		{
			var xmlDocument = http.responseXML; 
			var no = xmlDocument.getElementsByTagName('id').length;
			//var Prod_Obj=document.getElementById('vState');
			var Prod_Obj=stateobj;
			//alert(Prod_Obj.name);
			//alert(state_name);
			if(parseInt(no)>0)
			{			
				Prod_Obj.length=parseInt(no)+1;
				for(j=0,i=1;i<Prod_Obj.length;i++,j++)
				{
		   			var iPId = xmlDocument.getElementsByTagName('id').item(j).firstChild.data;
	   		   		var PName =xmlDocument.getElementsByTagName('text').item(j).firstChild.data;
					var SelVal = (state_name == iPId)? true : false ;
	   				Prod_Obj[i].value	= iPId;
	   				Prod_Obj[i].text 	= PName;
					Prod_Obj[i].selected=SelVal;
					//alert(Prod_Obj.innerHTML)
   					isWorking = false;
  				}
    		}
			else
			{
				Prod_Obj.length=2;
				var SelVal = (state_name == 'Other')? true : false ;
				Prod_Obj[1].value	= 'Other';
   				Prod_Obj[1].text 	= 'Other';
				Prod_Obj[1].selected=SelVal;
				isWorking = false;
			}
			if(document.getElementById('fShippingPrice')  &&  Prod_Obj.name == 'vShipState')
			{
				updateShippings();
				updateTaxAmount();
			}			
		}
  	}
}
function getStateName(country,state,displayPopup) 
{
	countryobj=country;
	stateobj=state;
	
	var url = admin_url+"getState.php?Code=";
	var isWorking = false;
	if (!isWorking)
	{
		catID = country.value;
		isWorking = true;
		url += catID;
		if (window.XMLHttpRequest)
	  	{
	  		http=new XMLHttpRequest()
	  		http.open("GET",url, true);
		  	http.onreadystatechange=handleHttpResponse2
		  	http.send(null)
	  	}
		// code for IE
		else if (window.ActiveXObject)
	  	{
	  		http=new ActiveXObject("Microsoft.XMLHTTP")
	    	if (http)
	    	{
	    		http.open("GET",url, true);
	    		http.onreadystatechange=handleHttpResponse2
	    		http.send()
	    	}
	  	}
  	}
	//if(!displayPopup)	closeLoadingWindow(winObj);
}
