function getXmlNodeValue(obj){
	if (typeof(obj.innerText) != "undefined"){ return obj.innerText; } //should be safari and ie, but not working
	else if (typeof(obj.textContent) != "undefined"){ return obj.textContent; } //ff
	else { return obj.childNodes[0].nodeValue; }  //safari and ie, something weird
}

function updateTimes(){
	$('time').enable();
	var opt=$('time').options.length
	for (var i=opt; i >= 0 ; i--) {
		$('time').options[i] = null;
	}

	new Ajax.Request("../util/updateTimes.php?location="+$('location').value, {
	method: 'get',
	onSuccess: function(transport) {
		var newTimes = transport.responseXML.documentElement;
		var hasSlots = false;
		$('time').options[0] = new Option('Select...','Select...');
		for(var i=0;i<newTimes.childNodes.length;i++){
			var slot = newTimes.childNodes[i];
			var slotsRemaining = (parseInt(getXmlNodeValue(slot.childNodes[2]))) - 
									(parseInt(getXmlNodeValue(slot.childNodes[1])));	
			if(slotsRemaining > 0){
				$('time').options[i+1] = new Option(getXmlNodeValue(slot.childNodes[0])+
				' ----- '+slotsRemaining+' slots remaining',getXmlNodeValue(slot.childNodes[0])) ;

				hasSlots = true;
			}
		}
		if(!hasSlots){
			$('time').options[1] = new Option("No slots available. Please select another location.","");
		}
  	},
	onFailure: function() {
		$('time').options[0] = new Option('Error: could not retrieve times from database','error');
		$('time').disable();
	}
	});
	return;
}