/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

    var _place_selection = null;
    function GetXmlHttpObject(handler)  
    {  
       var objXMLHttp=null  
       if (window.XMLHttpRequest)  
       {  
           objXMLHttp=new XMLHttpRequest()  
       }  
       else if (window.ActiveXObject)  
       {  
          objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")  
      }  
      return objXMLHttp  
   }  
     
   function stateChanged()  
   {  
      //alert(_place_selection);
     
       
      if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")  
      {  
            

              if(_place_selection=='state'){
                document.getElementById("txtResultState").innerHTML= xmlHttp.responseText; 
                document.getElementById("txtResultStateLable").innerHTML= "State/Province:";
                document.getElementById("txtResultCity").innerHTML= "";
                document.getElementById("txtResultCityLable").innerHTML= "";
               
              }                
              else if(_place_selection=='city'){
               document.getElementById("txtResultCity").innerHTML= xmlHttp.responseText;
               document.getElementById("txtResultCityLable").innerHTML= "City:";
              }
      }  
      else {  
             // alert(xmlHttp.status);  
      }  
   }  
     
   // Will populate data based on input  
   function htmlData(url,qStr,place_selection,selected)  
   {  
      // alert('test htmlData');
      _place_selection = place_selection;
      
      if (url.length==0)  
      {  
//          if(place_selection=='state')
//          document.getElementById("txtResultState").innerHTML="";  
//          else if(place_selection=='city')
//          document.getElementById("txtResultCity").innerHTML=""; 
                
               
          return;  
      }  
      xmlHttp=GetXmlHttpObject()  
      if (xmlHttp==null)  
      {  
          alert ("Browser does not support HTTP Request");  
          return;  
      }  
     
       
      //<?php echo tep_href_link(FILENAME_TESTCITY);?>
//      url=url+"?"+qStr;  
//      url=url+"&sid="+Math.random();  
      url = url+"&"+qStr+"&sid="+Math.random()+"&place_selection="+place_selection+"&selected_state="+selected; 
      
      //   alert("url:"+url);
       
      xmlHttp.onreadystatechange=stateChanged;  
      xmlHttp.open("GET",url,true) ;  
      xmlHttp.send(null);  
   }  
   
   
   
   function loadinfo(urlstate,urlcity,country_id, state_id,city_id){
     // alert(urlstate+",,,,"+urlcity+"..."+country_id+","+state_id+","+city_id);
       
       //for populating state
       var qStr = "&country_id="+country_id+""; 
       htmlData(urlstate,qStr,'state',state_id);

       //for populating city
        qStr= "&country_id="+country_id+"&state_id="+state_id+"&selected_city="+city_id;
       htmlData(urlcity,qStr,'city',0);    
       
   }
   
   
    function loadstate(urlstate,country_id, state_id){
     //alert(urlstate+",,,,..."+country_id+","+state_id+"");
       
       //for populating state
       var qStr = "&country_id="+country_id+""; 
       htmlData(urlstate,qStr,'state',state_id);

       
       
   }
   
     function loadcity(urlcity,country_id, state_id,city_id){
      alert(""+urlcity+"..."+country_id+","+state_id+","+city_id);
       
       //for populating state
       

       //for populating city
       var qStr= "&country_id="+country_id+"&state_id="+state_id+"&selected_city="+city_id;
       htmlData(urlcity,qStr,'city',0);    
       
   }
   
  
   
   
  
     
   



