var xmlHttp;
var ArrHotel = new Array;
var nhotel = 1;
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 gentable(obj, x, i){
	var txt = "";
	var str = "";
	var bgc = "";
	var star = "";
	var rating = "";
	var location = "";
	var price = "";

	location = obj.childNodes[(4*x-1)].firstChild.nodeValue;
	
	if(nhotel%2==0){bgc="hicolor";}else{bgc="locolor";}
	nhotel++;
	star="";
	rating = obj.childNodes[(3*x-1)].firstChild.nodeValue;

	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/"+obj.childNodes[(1*x-1)].firstChild.nodeValue+"/' class='resdb8'>"+obj.childNodes[(2*x-1)].firstChild.nodeValue+"</a>";
	txt += "			</td>";
	txt += "			<td class='hotellist' width='100'>"+star+"</td>";
	price = obj.childNodes[(9*x-1)].firstChild.nodeValue*1;
	txt += "			<td class='hotellist' width='100' align='right'>"+price.toFixed(2)+" "+obj.childNodes[(8*x-1)].firstChild.nodeValue+"</td>";
	txt += "		</tr>\n";
	return txt;
}

function displayHotel(obj){
	var txt = "";
	ArrHotel = Array();
	var len = obj[0].childNodes.length;
	var x = 1;
	var location = "";
	var str = "";
	if(len==19){x=2;}

	if(area == 'other' || area == 'all'){
		var n = 0;
		for(var i=0;i<obj.length;i++){
			location = obj[i].childNodes[(4*x-1)].firstChild.nodeValue;
			if (location == "Airport (Old): Don Muang Int'l"){location = "Don Muang";}
			if (location == "Airport: Suvarnabhumi Int'l"){location = "Suvarnabhumi";}
			if (location == "Siam"){location = "Siam Square";}
			if (location == "Riverside"){location = "Riverfront";}

			if(area == "other"){
				if(location != "Sukhumvit" && location != "Silom" && location != "riverfront" && location != "Don Muang" && location != "Suvarnabhumi"){

					if(ArrHotel[location]){
						n = ArrHotel[location].length;
					}else{
						n = 0;
						ArrHotel[location] = Array();
					}
					ArrHotel[location][n] = obj[i];
				}
			}
		
			if(area == "all"){
				if(ArrHotel[location]){
					n = ArrHotel[location].length;
				}else{
					n = 0;
					ArrHotel[location] = Array();
				}
				ArrHotel[location][n] = obj[i];
			}
		}

		txt = "";//alert(":::"+ArrArea.length);
		for(var i=0;i<ArrArea.length;i++){
			str = ArrArea[i];
			//alert(i+":"+str);
			if(ArrHotel[str]){
				n = ArrHotel[str].length;
				
				document.getElementById(str+"_").innerHTML += " ("+n+")";

				txt = "<table cellpadding='2' cellspacing='0' border='1' width='98%' class='table_hotellist'>";
				nhotel = 1;
				for(var ii=0;ii<n;ii++){
				//alert(i+"-"+ii+"::"+str);
					txt += gentable(ArrHotel[str][ii], x);
				}
				document.getElementById(str+"_t").innerHTML = txt+"</table>";
			}
		}
	}else {

	txt = "<table cellpadding='2' cellspacing='0' border='1' width='98%' class='table_hotellist'>";
		for(var i=0;i<obj.length;i++){
			//alert(i+"::"+obj[i].childNodes[(4*x-1)].firstChild.nodeValue);
			location = obj[i].childNodes[(4*x-1)].firstChild.nodeValue;
			
			if (location == "Airport (Old): Don Muang Int'l"){location = "Airport";}
			if (location == "Airport: Suvarnabhumi Int'l"){location = "Airport";}
			if (location == "Siam"){location = "Siam Square";}
			if (location == "Riverside"){location = "Riverfront";}

			if(location == area){
				txt += gentable(obj[i], x);
			}
		}
	txt += "</table>";
	document.getElementById("hotellist").innerHTML += txt;
	}

}