var xmlHttp;
var ArrHotel = new Array;
function createXMLHttpRequestHotel(){
	if(window.ActiveXObject){
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	} else if(window.XMLHttpRequest){
		xmlHttp = new XMLHttpRequest();
	}
}
function RequestHotel(){
	createXMLHttpRequestHotel();
	xmlHttp.onreadystatechange = handleHotel;
	xmlHttp.open("GET", "/includes/lib/hotellist.inc.php", true);
	xmlHttp.send(null);
}
function handleHotel(){
	if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
		var xmlDoc = xmlHttp.responseXML;
		var obj = xmlDoc.getElementsByTagName("HotelSummary");
		displayHotel(obj);
	}
}
function displayHotel(obj){
	var txt = "";
	ArrHotel = Array();
	var len = obj[0].childNodes.length;
	var x = 1;
	if(len==19){x=2;}
	for(var i=0;i<obj.length;i++){
		//document.getElementById("hotellist").innerHTML += value.nodeName+" : "+value.firstChild.nodeValue+"<br>";
		
		var location = obj[i].childNodes[(4*x-1)].firstChild.nodeValue;
		var n;
		
		if(location=="Bang Tao Bay" || location=="Bangtao Beach"){location="Bang Tao Beach";}
		if(location=="Kata Beach (Hillside)"){location="Kata Beach";}
		if(location=="City Centre"){location="City";}
		
		if(ArrHotel[location]){
			n = ArrHotel[location].length;
		}else{
			n = 0;
			ArrHotel[location] = Array();
		}
		ArrHotel[location][n] = Array();
		ArrHotel[location][n]["id"] = obj[i].childNodes[(1*x-1)].firstChild.nodeValue;
		ArrHotel[location][n]["name"] = obj[i].childNodes[(2*x-1)].firstChild.nodeValue;
		ArrHotel[location][n]["star"] = obj[i].childNodes[(3*x-1)].firstChild.nodeValue;
		ArrHotel[location][n]["location"] = location;
		ArrHotel[location][n]["currency"] = obj[i].childNodes[(8*x-1)].firstChild.nodeValue;
		ArrHotel[location][n]["price"] = obj[i].childNodes[(9*x-1)].firstChild.nodeValue;
		//alert(location+":"+n+":"+ArrHotel[location][n]["name"]);
	}

	var area = "";
	var obj2 = "";
	var str = "";
	var bgc = "";
	var star = "";
	var rating = "";

	for(var i=0;i<ArrArea.length;i++){
		str = ArrArea[i];
		if(ArrHotel[str]){
			area = ArrHotel[str];
			n = area.length;
			document.getElementById(str).innerHTML += " ("+n+")";
			document.getElementById(str+"_t").innerHTML = "";

			txt = "<table cellpadding='2' cellspacing='0' border='1' width='98%' class='table_hotellist'>";

			for(var ii=0;ii<n;ii++){
				obj2 = area[ii];
				
				if(ii%2==0){bgc="hicolor";}else{bgc="locolor";}
				star="";
				rating = obj2["star"];

				while(rating > 0){
					rating--;
					if(rating >= 0 ) { star += "<img src='/images/star.gif'>"; } else { star += "<img src='/images/star2.gif'>"; }
				}
				
				txt += "		<tr class='"+bgc+"' onMouseOver='this.className=\"hilite\"' onMouseOut='this.className=\""+bgc+"\"'>";
				txt += "			<td class='hotellist' width=''>";
				txt += "				<a href='/hotels_resorts.html/detail/"+obj2["id"]+"/' class='resdb8'>"+obj2["name"]+"</a>";
				txt += "			</td>";
				txt += "			<td class='hotellist' width='100'>"+star+"</td>";
				txt += "			<td class='hotellist' width='100' align='right'>"+obj2["price"]+" "+obj2["currency"]+"</td>";
				txt += "		</tr>\n";
			}
			document.getElementById(str+"_t").innerHTML += txt+"</table>";
		}else{
			document.getElementById(str).innerHTML += "(0)";
		}
	}
}