function HttpRequest(url, payload, callback, data) {
  var hr;  
  if (window.XMLHttpRequest){
    // If IE7, Mozilla, Safari, etc: Use native object
    hr = new XMLHttpRequest();
  }
  else {
    if (window.ActiveXObject){
      // ...otherwise, use the ActiveX control for IE5.x and IE6
      hr = new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
  
  // Send the request
  if (hr) {
    hr.open((payload) ? "POST" : "GET", url, true);
    hr.onreadystatechange = function () {
      if (hr.readyState == 4) {
        callback(hr, data);
      }
    }
    
    hr.send(payload);
  }
}



function showElement(id) {
  if (document.all) { //IS IE 4 or 5 (or 6 beta)
    eval("document.all." + id + ".style.visibility = 'visible'");
  }
  if (document.layers) { //IS NETSCAPE 4 or below
    document.layers[id].visibility = 'visible';
  }
  if (document.getElementById && !document.all) {
    var divname = document.getElementById(id);
    divname.style.visibility = 'visible';
  }
}
;

function hideElement(id) {
  if (document.all) { //IS IE 4 or 5 (or 6 beta)
    eval("document.all." + id + ".style.visibility = 'hidden'");
  }
  if (document.layers) { //IS NETSCAPE 4 or below
    document.layers[id].visibility = 'hidden';
  }
  if (document.getElementById && !document.all) {
    divname = document.getElementById(id);
    divname.style.visibility = 'hidden';
  }
}
;


function lookupSTA() {
  var urlStr = "/public.ejs?command=PublicLocatableSTALookup";
  HttpRequest(urlStr, null, lookupSTACallback, null);
}

function lookupSTACallback(request, data) {
  if (request.status == 200) {
    var xmlDoc = request.responseXML;
    var staico = document.getElementById('staic-o');
    var statext = document.getElementById('statext');
    var staList = xmlDoc.getElementsByTagName("sta");
    if (staList) {
      var numOfSTA = staList.length;
      if (numOfSTA > 0) {
        var content = "";
        for (var sta = 0; sta < numOfSTA; sta++) {
          var thisSTA = staList.item(sta);
          var county = thisSTA.getElementsByTagName("county").item(0).firstChild.data;
          var date = thisSTA.getElementsByTagName("date").item(0).firstChild.data;
          var location = thisSTA.getElementsByTagName("location").item(0).firstChild.data;
          if (content != "") content = content + '<br/><br/>';
          content = content + '<b>' + date + ' -- ' + county + '</b><br/>';
          content = content + location + '<br/>';
        }
        statext.innerHTML = content;
      }
    }
  }
  else
  {
    alert("There was a problem retrieving travel alert information.\n" + request.statusText);
  }
}

  

