function querySessions(query) {
  var xmlhttp;
  
  if (window.XMLHttpRequest) {
    // code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
  }
  else if (window.ActiveXObject) {
    // code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  else {
    alert("Your browser does not support AJAX!");
  }
  xmlhttp.onreadystatechange=function() {
    if(xmlhttp.readyState==4) {
      if(xmlhttp.status!=200) {
        alert("Problem retrieving XML data");
        return;
      }
      x=xmlhttp.responseXML.documentElement.getElementsByTagName("QUERY");
      mySessions = new Array();
      for (i=0;i<x.length;i++) {
        xx = x[i].getElementsByTagName("ID");
        tmpID = xx[0].firstChild.nodeValue;
        xx = x[i].getElementsByTagName("DESCRIPTION");
        tmpDESC = xx[0].firstChild.nodeValue;
        xx = x[i].getElementsByTagName("ADVANCED");
        tmpADV = xx[0].firstChild.nodeValue;
        xx = x[i].getElementsByTagName("DATA_LAN");
        if(xx[0].firstChild) {
          tmpLAN = xx[0].firstChild.nodeValue;
        } else {
          tmpLAN = 0;
        }
        xx = x[i].getElementsByTagName("DATA_KOMMUN");
        if(xx[0].firstChild) {
          tmpKOM = xx[0].firstChild.nodeValue;
        } else {
          tmpKOM = 0;
        }
        xx = x[i].getElementsByTagName("DATA_POSTNR");
        if(xx[0].firstChild) {
          tmpPNR = xx[0].firstChild.nodeValue;
        } else {
          tmpPNR = '';
        }
        xx = x[i].getElementsByTagName("DATA_CNAMN");
        if(xx[0].firstChild) {
          tmpCNAM = xx[0].firstChild.nodeValue;
        } else {
          tmpCNAM = '';
        }
        xx = x[i].getElementsByTagName("DATA_WPT");
        if(xx[0].firstChild) {
          tmpWPT = xx[0].firstChild.nodeValue;
        } else {
          tmpWPT = '';
        }
        xx = x[i].getElementsByTagName("FILTER_FOUND");
        if(xx[0].firstChild) {
          tmpFND = xx[0].firstChild.nodeValue;
        } else {
          tmpFND = '';
        }
        xx = x[i].getElementsByTagName("FILTER_NFOUND");
        if(xx[0].firstChild) {
          tmpNFND = xx[0].firstChild.nodeValue;
        } else {
          tmpNFND = '';
        }
        xx = x[i].getElementsByTagName("FILTER_HIDDEN");
        if(xx[0].firstChild) {
          tmpHID = xx[0].firstChild.nodeValue;
        } else {
          tmpHID = '';
        }
        xx = x[i].getElementsByTagName("FILTER_NHIDDEN");
        if(xx[0].firstChild) {
          tmpNHID = xx[0].firstChild.nodeValue;
        } else {
          tmpNHID = '';
        }
        xx = x[i].getElementsByTagName("FILTER_FILTER");
        tmpFILT = xx[0].firstChild.nodeValue;
        xx = x[i].getElementsByTagName("FILTER_FEMFEM");
        tmpFEM = xx[0].firstChild.nodeValue;
        xx = x[i].getElementsByTagName("FILTER_TB");
        tmpTB = xx[0].firstChild.nodeValue;
        xx = x[i].getElementsByTagName("FILTER_FTF");
        tmpFTF = xx[0].firstChild.nodeValue;
        xx = x[i].getElementsByTagName("FILTER_ACTIVE");
        tmpACT = xx[0].firstChild.nodeValue;
        xx = x[i].getElementsByTagName("FILTER_INACTIVE");
        tmpNACT = xx[0].firstChild.nodeValue;
        xx = x[i].getElementsByTagName("FILTER_ARCHIVED");
        tmpARCH = xx[0].firstChild.nodeValue;
        xx = x[i].getElementsByTagName("FILTER_BEFORE");
        if(xx[0].firstChild) {
          tmpBEFO = xx[0].firstChild.nodeValue;
        } else {
          tmpBEFO = '';
        }
        xx = x[i].getElementsByTagName("FILTER_AFTER");
        if(xx[0].firstChild) {
          tmpAFTE = xx[0].firstChild.nodeValue;
        } else {
          tmpAFTE = '';
        }
        mySessions[i] = new SavedSession(tmpID, tmpDESC, tmpADV, tmpLAN, tmpKOM, tmpPNR, tmpCNAM, tmpWPT, tmpFND, tmpNFND, tmpHID, tmpNHID, tmpFILT, tmpFEM, tmpTB, tmpFTF, tmpACT, tmpNACT, tmpARCH, tmpBEFO, tmpAFTE);
      }
      sessionsFetched();
      return;
    }
  }
  xmlhttp.open("GET",query,true);
  //xmlhttp.open("GET","servertest.php?k="+query,true);
  xmlhttp.send(null);
}

function queryCaches(query) {
  var xmlhttp;

  if (window.XMLHttpRequest) {
    // code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
  }
  else if (window.ActiveXObject) {
    // code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  else {
    alert("Your browser does not support AJAX!");
  }
  xmlhttp.onreadystatechange=function() {
    if(xmlhttp.readyState==4) {
      if(xmlhttp.status!=200) {
        alert("Problem retrieving XML data");
        return;
      }
      x=xmlhttp.responseXML.documentElement.getElementsByTagName("CACHE");
      myCaches = new Array();
      myPoints = new Array();
      for (i=0;i<x.length;i++) {
        xx = x[i].getElementsByTagName("ID");
        tmpID = xx[0].firstChild.nodeValue;
        xx = x[i].getElementsByTagName("WPT");
        tmpWPT = xx[0].firstChild.nodeValue;
        xx = x[i].getElementsByTagName("NAME");
        tmpNAME = xx[0].firstChild.nodeValue;
        xx = x[i].getElementsByTagName("URL");
        tmpURL = xx[0].firstChild.nodeValue;
        xx = x[i].getElementsByTagName("LAT");
        tmpLAT = xx[0].firstChild.nodeValue;
        xx = x[i].getElementsByTagName("LON");
        tmpLON = xx[0].firstChild.nodeValue;
        xx = x[i].getElementsByTagName("TYPE");
        tmpTYPE = xx[0].firstChild.nodeValue;
        xx = x[i].getElementsByTagName("OWNER");
        tmpOWNER = xx[0].firstChild.nodeValue;
        xx = x[i].getElementsByTagName("DIFFICULTY");
        tmpDIFF = xx[0].firstChild.nodeValue;
        xx = x[i].getElementsByTagName("TERRAIN");
        tmpTERRAIN = xx[0].firstChild.nodeValue;
        myCaches[i] = new Cache(tmpID, tmpWPT, tmpNAME, tmpURL, tmpLAT, tmpLON, tmpTYPE, tmpOWNER, tmpDIFF, tmpTERRAIN);
      }
      cachesFetched();
      return;
    }
  }
  xmlhttp.open("GET",query,true);
  //xmlhttp.open("GET","servertest.php?k="+query,true);
  xmlhttp.send(null);
}
