// JavaScript Document
	 var xmlHttp; 
	 var xmlHttp2; 
	 var req; 
	 var req2; 
    var requestURL = getURI()+'/getstates.aspx?c='; 
    var requestURL2 = getURI()+'/getcities.aspx?s='; 
    var requestURL3 = getURI()+'/getregions.aspx?s='; 
	 var controltochange;
	 var controltochange2;
	 
	 function resetID() {
		 document.getElementById('esrEscapes_txtEscapeID').value = '';
	 }
	 
	 function getURI() {
		var URLTemp = window.location.href
		var regexS = "(http://.*)/.*";
		var regex = new RegExp( regexS );
		var results = regex.exec( URLTemp );
		if( results == null ) {
			regex5 = "(https://.*)/.*";
			results = regex.exec(URLTemp);
			if (results == null)
				return "";
			else
				return results[1];
		} else
			return results[1];
	 }

	function NewCountry(intCountry) {
		 if (intCountry > -1) {
			 controltochange = 'divState';
			 var url = requestURL+intCountry;
			 GetXmlHttpObject(stateChangeHandler,url);
		 }
	 }
	 
	 
	 function NewState(intState) {
		 if (intState > -1) {
			 controltochange = 'divCity';
			 var url = requestURL2+intState;
			 GetXmlHttpObject(stateChangeHandler,url);
			 controltochange2 = 'divRegion';
			 var url = requestURL3+intState;
			 GetXmlHttpObject2(stateChangeHandler2,url);
		 }
	 }

	 function NewStateRegion(intState) {
		 if (intState > -1) {
			 controltochange = 'divCity';
			 var url = requestURL2+intState;
			 GetXmlHttpObject(stateChangeHandler,url);
		 }
	 }

	 function NewStateCity(intState) {
		 if (intState > -1) {
			 controltochange2 = 'divRegion';
			 var url = requestURL3+intState;
			 GetXmlHttpObject2(stateChangeHandler2,url);
		 }
	 }

    //stateChangeHandler will fire when the state has changed, i.e. data is received back 
    // This is non-blocking (asynchronous) 
    function stateChangeHandler() 
    { 
        //readyState of 4 or 'complete' represents that data has been returned 
        if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete'){ 
            //Gather the results from the callback 
            var str = xmlHttp.responseText; 

            //Populate the innerHTML of the drp with the results
				if (controltochange=='divState') {
	            document.getElementById('divState').innerHTML = '<select name="drpStateID" id="drpStateID" OnChange="NewState(this.options[this.selectedIndex].value);resetID();" class="SearchDropBox">'+str+'</select>'; 
					NewState(0);
				} else {
	            document.getElementById('divCity').innerHTML = '<select name="drpCityID" id="drpCityID" class="SearchDropBox">'+str+'</select>'; 
				}
		} 
    } 

    function stateChangeHandler2() 
    { 
        //readyState of 4 or 'complete' represents that data has been returned 
        if (xmlHttp2.readyState == 4 || xmlHttp2.readyState == 'complete'){ 
            //Gather the results from the callback 
            var str = xmlHttp2.responseText; 

            //Populate the innerHTML of the drp with the results
			document.getElementById('divRegion').innerHTML = '<select name="drpRegionID" id="drpRegionID" class="SearchDropBox">'+str+'</select>'; 
		} 
    } 


    function GetXmlHttpObject(handler,url) { 
		xmlHttp=false;
		/*@cc_on @*/
		/*@if (@_jscript_version >= 5)

		 try {
		  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		 } catch (e) {
		  try {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		  } catch (E) {
			xmlHttp = false;
		  }
		 }
		@end @*/
		if (!xmlHttp && typeof XMLHttpRequest!='undefined') {
			try {
				xmlHttp = new XMLHttpRequest();
			} catch (e) {
				xmlHttp=false;
			}
		}
		if (!xmlHttp && window.createRequest) {
			try {
				xmlHttp = window.createRequest();
			} catch (e) {
				xmlHttp=false;
			}
		}
		if(xmlHttp) {
			sndReq(handler,url);
		}
        
    } 
	 
	function sndReq(handleResponse,url) {
		 var randNum = Math.round(100*Math.random());
		 xmlHttp.open("GET", url+'&randomStuff=' + randNum, true);
		 /* Prevent Memory Leak on IE */
		 xmlHttp.onreadystatechange = function() {};
		 xmlHttp.onreadystatechange = handleResponse;
		 xmlHttp.send(null);
	}

    function GetXmlHttpObject2(handler,url) { 
		xmlHttp2=false;
		/*@cc_on @*/
		/*@if (@_jscript_version >= 5)

		 try {
		  xmlHttp2 = new ActiveXObject("Msxml2.XMLHTTP");
		 } catch (e) {
		  try {
			xmlHttp2 = new ActiveXObject("Microsoft.XMLHTTP");
		  } catch (E) {
			xmlHttp2 = false;
		  }
		 }
		@end @*/
		if (!xmlHttp2 && typeof XMLHttpRequest!='undefined') {
			try {
				xmlHttp2 = new XMLHttpRequest();
			} catch (e) {
				xmlHttp2=false;
			}
		}
		if (!xmlHttp2 && window.createRequest) {
			try {
				xmlHttp2 = window.createRequest();
			} catch (e) {
				xmlHttp2=false;
			}
		}
		if(xmlHttp2) {
			sndReq2(handler,url);
		}
        
    } 
	 
	function sndReq2(handleResponse,url) {
		 var randNum = Math.round(100*Math.random());
		 xmlHttp2.open("GET", url+'&randomStuff=' + randNum, true);
		 /* Prevent Memory Leak on IE */
		 xmlHttp2.onreadystatechange = function() {};
		 xmlHttp2.onreadystatechange = handleResponse;
		 xmlHttp2.send(null);
	}
