var xmlhttp
var cityInfo;
var cities = [];

/**
 * Provides suggestions for city names (USA).
 */

function getCitySuggestions() {

   try {
      var xmlDoc = null;
      //state = document.getElementById("state").value;
      beginCity = document.getElementById("city").value;
      if (window.XMLHttpRequest) {
         xmlDoc = new window.XMLHttpRequest();
      }
      else {
         if (window.ActiveXObject) {
            // IE 5.x and IE 6.x compliant.
            xmlDoc = new ActiveXObject('MSXML2.XMLHTTP.3.0');
         }
      }
      if (beginCity.search(/,/) == -1) {
      //xmlDoc.open("GET","citysuggest.php?state="+state,false);
      xmlDoc.open("GET","citysuggest.php?str="+beginCity,false);
      xmlDoc.onreadystatechange = function(){
         if(xmlDoc.readyState == 4) {
            if(xmlDoc.status == 200) {
               xmlDoc=xmlDoc.responseXML;
               cityInfo=xmlDoc.getElementsByTagName("location");
               cities = [];
               for (i=0; i<cityInfo.length; i++) {
                  cities[i] = cityInfo[i].getElementsByTagName("city")[0].childNodes[0].nodeValue + ", " + cityInfo[i].getElementsByTagName("region")[0].childNodes[0].nodeValue + ", " + cityInfo[i].getElementsByTagName("countrylong")[0].childNodes[0].nodeValue;
               }
            }
         }
      };
      xmlDoc.send(null);
      }
   }
   catch(Error) {
      //alert("Description:"+Error.description);
   }
}

function showGeoKeywordsResults(keyword) {
   xmlhttp=GetXmlHttpObject();
   if (xmlhttp==null) {
      alert ("Your browser does not support XMLHTTP!");
      return;
   }
   var url="searchgeokeywords.php";
   url=url+"?k="+keyword;
   xmlhttp.onreadystatechange=stateChangedGeoKeywords;
   xmlhttp.open("GET",url,true);
   xmlhttp.send(null);
}

function stateChangedGeoKeywords() {
   if (xmlhttp.readyState==4) {
      document.getElementById("geokeywords").innerHTML=xmlhttp.responseText;
   }
}

function doFiltering(keyword) {
   xmlhttp=GetXmlHttpObject();
   if (xmlhttp==null) {
      alert ("Your browser does not support XMLHTTP!");
      return;
   }
   var url="profanity.php";
   url=url+"?status="+keyword;
   xmlhttp.onreadystatechange=stateChangedFiltering;
   xmlhttp.open("GET",url,true);
   xmlhttp.send(null);
}

function stateChangedFiltering() {
   if (xmlhttp.readyState==4) {
      document.getElementById("profanityonoff").innerHTML=xmlhttp.responseText;
      window.location.reload(true);
   }
}

function doLSearch(keyword) {
   xmlhttp=GetXmlHttpObject();
   if (xmlhttp==null) {
      alert ("Your browser does not support XMLHTTP!");
      return;
   }
   var url="lsearch.php";
   url=url+"?l="+keyword;
   xmlhttp.onreadystatechange=stateChangedLSearch;
   xmlhttp.open("GET",url,true);
   xmlhttp.send(null);
}

function stateChangedLSearch() {
   if (xmlhttp.readyState==4) {
      document.getElementById("lsearchonoff").innerHTML=xmlhttp.responseText;
   }
}

function showResults(sv) {
   xmlhttp=GetXmlHttpObject();
   if (xmlhttp==null) {
      alert ("Your browser does not support XMLHTTP!");
      return;
   }
   var url="searchresults.php";
   url=url+"?query="+b.query.value;
   url=url+"&sv="+sv;
   url=url+"&p="+b.oc.value;
   xmlhttp.onreadystatechange=stateChanged;
   xmlhttp.open("GET",url,true);
   xmlhttp.send(null);
}

function stateChanged() {
   if (xmlhttp.readyState==4) {

      document.getElementById("searchresultscontainer").innerHTML=xmlhttp.responseText;
   }
}

function GetXmlHttpObject() {
   if (window.XMLHttpRequest) {
      // code for IE7+, Firefox, Chrome, Opera, Safari
      return new XMLHttpRequest();
   }
   if (window.ActiveXObject) {
      // code for IE6, IE5
      return new ActiveXObject("Microsoft.XMLHTTP");
   }
   return null;
}
