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) {
		var result = 0;
		result = pair[1];
		return result;
//      return pair[1];
    }
  }
return false;
}

function updateInfo() {

var selectedMaxOption = false;
var selectedMinOption = false;

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


if(requester != null) {

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

requester.onreadystatechange = function() {

if (requester.readyState == 1) { // if the ajax app is loading



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

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

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

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

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

updateMinPrice.appendChild(newMinSelectOption);
updateMaxPrice.appendChild(newMaxSelectOption);

}


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

writeUpdate(requester.responseXML);

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

}

};


requester.send(null);

}

}



writeUpdate = function(responseXML) {

var priceList = "";
var i;

var updateMinPrice = document.getElementById("minPrice");
while (updateMinPrice.firstChild) {
updateMinPrice.removeChild(updateMinPrice.firstChild);
}

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


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

var minPrice = responseXML.getElementsByTagName("minPrices")[0].getElementsByTagName("price")[i];
var thisMinPrice = minPrice.firstChild;
var minPriceList = minPriceList + thisMinPrice.nodeValue + "\n";

// populate the minPrice dropdown

var updateHTML = document.getElementById("minPrice");
var newSelectOption = document.createElement("option");
var attributes = responseXML.getElementsByTagName("minPrices")[0].getElementsByTagName("price")[i].attributes;
var theValue = attributes.getNamedItem("value");
newSelectOption.setAttribute("value", theValue.nodeValue);
newSelectOption.appendChild(document.createTextNode(thisMinPrice.nodeValue));
updateHTML.appendChild(newSelectOption);


var queryMinPrice = getQueryVariable("minPrice");
queryMinPrice = queryMinPrice-0;
if(theValue.nodeValue == queryMinPrice) {
newSelectOption.setAttribute("selected", "selected");
var selectedMinOption = true;
} else {
if(i == responseXML.getElementsByTagName("minPrices")[0].getElementsByTagName("price").length - 1) {
if(selectedMinOption == true) {
break;
} else {
newSelectOption.setAttribute("selected", "selected");
}
}
}



}


// 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 == responseXML.getElementsByTagName("maxPrices")[0].getElementsByTagName("price").length - 1) {
newSelectOption.setAttribute("selected", "selected");
}
*/

var queryMaxPrice = getQueryVariable("maxPrice");
queryMaxPrice = queryMaxPrice-0;
if(theValue.nodeValue == queryMaxPrice && queryMaxPrice > 0) {
newSelectOption.setAttribute("selected", "selected");
var selectedMaxOption = true;
} else {
if(i == responseXML.getElementsByTagName("maxPrices")[0].getElementsByTagName("price").length - 1) {
if(selectedMaxOption == true) {
break;
} else {
newSelectOption.setAttribute("selected", "selected");
}
}
}

newSelectOption.appendChild(document.createTextNode(thisPrice.nodeValue));
updateHTML.appendChild(newSelectOption);

}



//alert(priceList);



} // writeUpdate: function(responseXML)
