var xmlHttpAjax; 
    var requestedURL ;
    var is_iex = (navigator.userAgent.indexOf('MSIE') >= 0) ? 1 : 0; 
    var is_iex5 = (navigator.appVersion.indexOf("MSIE 5.5")!=-1) ? 1 : 0; 
    var is_operabrow = ((navigator.userAgent.indexOf("Opera6")!=-1)||(navigator.userAgent.indexOf("Opera/6")!=-1)) ? 1 : 0; 
    //netscape, safari, mozilla behave the same??? 
    var is_netscapeex = (navigator.userAgent.indexOf('Netscape') >= 0) ? 1 : 0; 
    var pincode1;
    	
		
	function loadcountrycode(control1,control2){ 
	//Append the name to search for to the requestURL 
	var  value;
	for(i=0;i<4;i++)
	{	
		if(document.getElementById(control1).options[i].selected==true)
		{
			 value=document.getElementById(control1).options[i].value;
			
		}
	}
	
	requestedURL=document.getElementById('UrlString').value+"?";
            var urlPass = requestedURL+'control1='+control1+'&'+'value='+value+'&'+'control2='+control2; 
	
             
            //Create the xmlHttp object to use in the request 
            //stateChangeHandler will fire when the state has changed, i.e. data is received back 
            // This is non-blocking (asynchronous) 
            xmlHttpAjax = XmlHttpObjectGet(stateChangeHandlerFire); 
             
            //Send the xmlHttp get to the specified url 
            xmlHttp_GetResponse(xmlHttpAjax, urlPass); 
      
       
    } 
	function loadstate(pincode1)
	{
		
		requestedURL=document.getElementById('UrlString').value+"?";
		var urlPass=requestedURL+'pincodestate='+pincode1;
		xmlHttpAjax=XmlHttpObjectGet(stateChangeHandlerforState);
		 xmlHttp_GetResponse(xmlHttpAjax, urlPass); 
	}

    //stateChangeHandler will fire when the state has changed, i.e. data is received back 
    // This is non-blocking (asynchronous) 
    function stateChangeHandlerFire() 
    { 
	
        //readyState of 4 or 'complete' represents that data has been returned 
        if(xmlHttpAjax.readyState == 4)
		{
		
		// To make sure valid response is received from the server, 200 means response received is OK
		if(xmlHttpAjax.status == 200)
			{		
			
			
			setcountrycode(xmlHttpAjax.responseText);
			
			}
		else
			{
			alert("There was a problem retrieving data from the server." );
			}
		}
           
	}
     function stateChangeHandlerforState()
	{
		 //readyState of 4 or 'complete' represents that data has been returned 
        if(xmlHttpAjax.readyState == 4)
		{
		
		// To make sure valid response is received from the server, 200 means response received is OK
		if(xmlHttpAjax.status == 200)
			{		
			loadstatedrop(xmlHttpAjax.responseText);
			}
		else
			{
			alert("There was a problem retrieving data from the server." );
			}
		}
	}
    // XMLHttp send GET request 
    function xmlHttp_GetResponse(xmlhttpAjax, urlPass) { 
		
        xmlhttpAjax.open('GET', urlPass, true); 
        xmlhttpAjax.send(null); 
       
    } 

    function XmlHttpObjectGet(handler) { 
        var objXmlHttp = null;    //Holds the local xmlHTTP object instance 

        //Depending on the browser, try to create the xmlHttp object 
        if (is_iex){ 
            //The object to create depends on version of IE 
            //If it isn't ie5, then default to the Msxml2.XMLHTTP object 
            var strObjName = (is_iex5) ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP'; 
             
            //Attempt to create the object 
            try{ 
                objXmlHttp = new ActiveXObject(strObjName); 
                objXmlHttp.onreadystatechange = handler; 
            } 
            catch(e){ 
            //Object creation errored 
                alert('IE detected, but object could not be created. Verify that active scripting and activeX controls are enabled'); 
                return; 
            } 
        } 
        else if (is_operabrow){ 
            //Opera has some issues with xmlHttp object functionality 
            alert('Opera detected. The page may not behave as expected.'); 
            return; 
        } 
        else{ 
            // Mozilla | Netscape | Safari 
            objXmlHttp = new XMLHttpRequest(); 
            objXmlHttp.onload = handler; 
            objXmlHttp.onerror = handler; 
        } 
        
        //Return the instantiated object 
        return objXmlHttp; 
    } 
    function setcountrycode(st)
	{
	var str=st.split('<br>');
	if(str.length>2)
	{
	
	if(str[1]!='')
	{
	document.getElementById(str[0]).innerHTML=str[1];
	}
	}
	else
	{
	
	document.getElementById(str[0]).innerHTML=' ';
	}
	}
     function loadstatedrop(statecode)
	{
		
		document.getElementById('Registration1_txtLocation').value='';
		var sta=statecode.split('<br>');
		//alert(sta.length);
		var s=document.getElementById('Registration1_DDLstState').options.length;
		if(sta.length>1)
		{
		for (var i=0;i<s;i++)
		{
			if(document.getElementById('Registration1_DDLstState').options[i].value==sta[0])
			{
				document.getElementById('Registration1_DDLstState').options[i].selected=true;
			}
		}	
		if(sta.length>2)
		{
		if(sta[2]!=' ')
		{
		document.getElementById(sta[1]).value=sta[2];
		if(document.getElementById('Registration1_txtDistrictName'))
			document.getElementById('Registration1_txtDistrictName').value=sta[2];
		}
		}
		else
		{
		if(document.getElementById('Registration1_txtDistrictName'))
			document.getElementById('Registration1_txtDistrictName').value=' ';
		document.getElementById(sta[3]).value=' ';
		}
		if(sta.length>5)
		{
		if(sta[4]!=' ')
		{
		document.getElementById('Registration1_txtLocation').value=sta[4];
		}
		}
		else
		{
		document.getElementById('Registration1_txtLocation').value=' ';
		}
		}
	}

