var urlpath = '';
var urlpath2 = '';
var xmlHttp=''
var xmlHttp2=''
var xmlHttp3=''
var xmlHttp4=''
var siteurl="http://"+window.location.host+"/";
//alert(siteurl);
//alert(window.location.host);
function change_state()
{
//	document.getElementById("cityDIV").innnerHTML = '<select size="1" name="city" id="city" class="textfield"><option value="-1" selected="selected">--Select City--</option></select>';
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}

	var ID = document.getElementById("country").value;
	urlpath = siteurl+'change_ajax.php?what=state&countryID='+ID;
	//change_city();
//alert(urlpath)
//	alert(document.getElementById("cityDIV").innnerHTML)
	xmlHttp.onreadystatechange=stateChanged ;
	xmlHttp.open("GET",urlpath,true);
	xmlHttp.send(null);
} 

function stateChanged()
{ 
document.getElementById("loadingimage").style.display="";
	if ( xmlHttp.readyState==4 || xmlHttp.readyState=="complete" )
	{ 
//		alert(xmlHttp.responseText)
		if(xmlHttp.status==200){
			document.getElementById("stateDIV").innerHTML=xmlHttp.responseText ;
			document.getElementById("loadingimage").style.display="none";
			change_city();
		}else{
			alert("error: " + xmlHttp.statusText);
		}		
	}
}


function change_state2()
{
	xmlHttp2=GetXmlHttpObject();
	if (xmlHttp2==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var ID = document.step4contact.country.value;
	document.getElementById("cityDIV").innerHTML='<select size="1" name="city" id="city" class="textfield"><option>Select City</option></select>';
	urlpath = siteurl+'change_ajax_second.php?what=state&countryID='+ID;
	xmlHttp2.onreadystatechange=stateChanged2 ;
	xmlHttp2.open("GET",urlpath,true);
	xmlHttp2.send(null);
} 

function stateChanged2()
{ 
document.getElementById("loadingimage").style.display="";
	if ( xmlHttp2.readyState==4 || xmlHttp2.readyState=="complete" )
	{ 
		if(xmlHttp2.status==200){
			document.getElementById("stateDIV").innerHTML=xmlHttp2.responseText ;
			document.getElementById("loadingimage").style.display="none";
		}else{
			alert("error: " + xmlHttp2.statusText);
		}		
	}
}

function change_city(Obj)
{
	
	xmlHttp3=GetXmlHttpObject();
	if (xmlHttp3==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}

	var ID2 = document.getElementById("statesname").value;
	urlpath = siteurl+'change_ajax.php?what=city&stateID='+ID2;
	xmlHttp3.onreadystatechange=cityChanged ;
	xmlHttp3.open("GET",urlpath,true);
	xmlHttp3.send(null);
} 

function cityChanged()
{ 
document.getElementById("loadingimage").style.display="";
	if ( xmlHttp3.readyState==4 || xmlHttp3.readyState=="complete" )
	{ 
		if(xmlHttp3.status==200){
			document.getElementById("cityDIV").innerHTML=xmlHttp3.responseText ;
			document.getElementById("loadingimage").style.display="none";
		}else{
			alert("error: " + xmlHttp3.statusText);
		}		
	}
}

function change_city2(Obj)
{
	xmlHttp4=GetXmlHttpObject();
	if (xmlHttp4==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	
	var ID2 = document.getElementById("statesname").value;
	urlpath = siteurl+'change_ajax_second.php?what=city&stateID='+ID2;
	xmlHttp4.onreadystatechange=cityChanged2 ;
	xmlHttp4.open("GET",urlpath,true);
	xmlHttp4.send(null);
} 

function cityChanged2()
{ 
document.getElementById("loadingimage").style.display="";
	if ( xmlHttp4.readyState==4 || xmlHttp4.readyState=="complete" )
	{ 
		if(xmlHttp4.status==200){
			document.getElementById("cityDIV").innerHTML=xmlHttp4.responseText ;
			document.getElementById("loadingimage").style.display="none";
		}else{
			alert("error: " + xmlHttp4.statusText);
		}		
	}
}


function GetXmlHttpObject()
{ 
	var objXMLHttp=null;
	 if (window.XMLHttpRequest)
	{
		objXMLHttp=new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
	} 
	objXMLHttp=createXMLHttp();
	return objXMLHttp;
} 

function createXMLHttp() {

    if (typeof XMLHttpRequest != "undefined") {
        return new XMLHttpRequest();
    } else if (window.ActiveXObject) {
      var aVersions = [ "MSXML2.XMLHttp.5.0",
        "MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0",
        "MSXML2.XMLHttp","Microsoft.XMLHttp"
      ];

      for (var i = 0; i < aVersions.length; i++) {
        try {
            var oXmlHttp = new ActiveXObject(aVersions[i]);
            return oXmlHttp;
        } catch (oError) {
            //Do nothing
        }
      }
    }
    throw new Error("XMLHttp object could be created.");
}

