function getXMLHTTPObject()
{
  var xmlHttp=null;
  try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp = new XMLHttpRequest();
  }
  catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
  return xmlHttp;   
}

function stateChangedDep()
{
  if (xmlHttp.readyState==4)
  {
    document.getElementById('dep_city').innerHTML = xmlHttp.responseText;
    document.getElementById('dep_city').style.display='block';
  }  
}

function stateChangedRet()
{
  if (xmlHttp.readyState==4)
  {
    document.getElementById('ret_city').innerHTML = xmlHttp.responseText;
    document.getElementById('ret_city').style.display='block';
  }  
}

function _getCity(letters, mode)
{
  if (letters.length>=3)
  {
    xmlHttp = getXMLHTTPObject();
    if (xmlHttp == null)
    {
      alert('Fatal error: Your browser does not support Ajax!');
      return;
    }
    var url = "";
    url = "getcity.php?q="+letters+"&mode="+mode;
    if (mode=="dep")
      xmlHttp.onreadystatechange=stateChangedDep;
    else
      xmlHttp.onreadystatechange=stateChangedRet;
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
  }
}
