   //// Создаем ссылку
 var xmlHttp = createXmlHttpRequestObject();
 
function set_region()
   {
   

    document.getElementById("select_city").innerHTML = '<option value="">--select city--</option>';
     
     document.getElementById("select_city").outerHTML = '<select id="select_city" name="city"><option value="">--select city--</option></select>';
   
   
   var country=document.getElementById("select_country").value; 
    document.body.style.cursor = "wait"; 
  
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
  { 
    xmlHttp.open("GET", "ajax_registration.php?countryid="+country, true);     
    xmlHttp.onreadystatechange = handleServerResponse_reg;   
    xmlHttp.send(null);
    
    
    
  }
 
 }
 
 function set_city()
   {
   
   var region=document.getElementById("select_region").value; 
 document.body.style.cursor = "wait"; 
  
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
  { 
    xmlHttp.open("GET", "ajax_registration.php?regionid="+region, true);     
    xmlHttp.onreadystatechange = handleServerResponse_city;   
    xmlHttp.send(null);
    
  }
 
 }




/////Создаем обьект аякс
  function createXmlHttpRequestObject() 
 {
   var xmlHttp;
   try
  {
    
    xmlHttp = new XMLHttpRequest();
  }
  catch(e)
  {
       var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
                                    "MSXML2.XMLHTTP.5.0",
                                    "MSXML2.XMLHTTP.4.0",
                                    "MSXML2.XMLHTTP.3.0",
                                    "MSXML2.XMLHTTP",
                                    "Microsoft.XMLHTTP");
   
    for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++) 
    {
      try 
      { 
        
        xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
      } 
      catch (e) {} // ignore potential error
    }
  }
  if (!xmlHttp)
    displayError("Error creating the XMLHttpRequest object.");
  else 
    return xmlHttp;
 }
 
 
 ////отрабатываем ответ  
 function handleServerResponse_reg() 
{

  if (xmlHttp.readyState == 4) 
  {
   
    if (xmlHttp.status == 200) 
    {
     
      txtResponse = xmlHttp.responseText;
   
     document.getElementById("select_region").innerHTML = txtResponse;
     
     document.getElementById("select_region").outerHTML = '<select id="select_region" onchange="set_city()" name="region">'+txtResponse+'</select>';
     
     //document.getElementById("select_city").innerHTML ='<option value="">- empty -</option>';
      document.body.style.cursor = "default"; 
    } 
    else 
    {
      alert("There was a problem accessing the server: " + xmlHttp.statusText);
       document.body.style.cursor = "default";
    }
  }
}


function handleServerResponse_city() 
{

  if (xmlHttp.readyState == 4) 
  {
   
    if (xmlHttp.status == 200) 
    {
    // alert(txtResponse);
      txtResponse = xmlHttp.responseText;
      //document.getElementById("select_city").innerHTML ='';
      document.getElementById("select_city").innerHTML = txtResponse;
      
   
      document.getElementById("select_city").outerHTML = '<select id="select_city"  name="city">'+txtResponse+'</select>';
    
      
      
      document.body.style.cursor = "default";
    } 
    else 
    {
      alert("There was a problem accessing the server: " + xmlHttp.statusText);
       document.body.style.cursor = "default";
    }
  }
}

function displayError(message)
{
  // display error message, with more technical details if debugMode is true
  displayMessage("Error accessing the server! "+
                 (debugMode ? "<br/>" + message : ""));
}
 
 

