function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  }
return false;
}


function updateInfo() {

try {
var requester = new XMLHttpRequest();
}
catch (error) {
try {
var requester = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (error) {
var requester = null;
}
}


//alert("ffs");

if(requester != null) {

requester.open('GET', '/prices.php?searchType=' + document.getElementById("searchType").value, true);

requester.onreadystatechange = function() {

if (requester.readyState < 4) { // if the ajax app is loading
//alert(requester.readyState);
/*
//var updateMinPrice = document.getElementById("minPrice");
var updateMaxPrice = document.getElementById("maxPrice");

while (updateMaxPrice.firstChild) {
updateMaxPrice.removeChild(updateMaxPrice.firstChild);
}

var newMaxSelectOption = document.createElement("option");
newMaxSelectOption.setAttribute("value", "0");
newMaxSelectOption.appendChild(document.createTextNode("loading prices"));

updateMaxPrice.appendChild(newMaxSelectOption);
*/
//alert(requester.readyState);
} // if (requester.readyState < 4) {


if (requester.readyState == 4) {
//alert(requester.readyState);
if (requester.status == 200 || requester.status == 304) {


var updateMaxPrice = document.getElementById("maxPrice");

while (updateMaxPrice.firstChild) {
updateMaxPrice.removeChild(updateMaxPrice.firstChild);
}

var newMaxSelectOption = document.createElement("option");
newMaxSelectOption.setAttribute("value", "0");
newMaxSelectOption.appendChild(document.createTextNode("loading prices"));

updateMaxPrice.appendChild(newMaxSelectOption);


writeUpdate(requester.responseXML);

} else {
alert("unable to contact server");
}

}

};


requester.send(null);

}

}



writeUpdate = function(responseXML) {

var priceList = "";
var i;


var updateMaxPrice = document.getElementById("maxPrice");
while (updateMaxPrice.firstChild) {
updateMaxPrice.removeChild(updateMaxPrice.firstChild);
}


// get the maximum prices
for(i = 0; i < responseXML.getElementsByTagName("maxPrices")[0].getElementsByTagName("price").length; i++) {

var price = responseXML.getElementsByTagName("maxPrices")[0].getElementsByTagName("price")[i];
var thisPrice = price.firstChild;
var priceList = priceList + thisPrice.nodeValue + "\n";

// populate the maxPrice dropdown
var updateHTML = document.getElementById("maxPrice");
var newSelectOption = document.createElement("option");
var attributes = responseXML.getElementsByTagName("maxPrices")[0].getElementsByTagName("price")[i].attributes;
var theValue = attributes.getNamedItem("value");
newSelectOption.setAttribute("value", theValue.nodeValue);

if(i == getQueryVariable("maxPrice")) {
newSelectOption.setAttribute("selected", "selected");
} else {
if(i == responseXML.getElementsByTagName("maxPrices")[0].getElementsByTagName("price").length - 1) {
newSelectOption.setAttribute("selected", "selected");
}
}
newSelectOption.appendChild(document.createTextNode(thisPrice.nodeValue));
updateHTML.appendChild(newSelectOption);

}



//alert(priceList);



} // writeUpdate: function(responseXML)
