// JavaScript Document
var xml = null;
var b;
var OrderStr;
if (window.ActiveXObject){ 
    var xmldoc = new ActiveXObject("Msxml2.DOMDocument"); 
	//xmldoc.async = false;

} 
else if (document.implementation.createDocument){//Mozilla, Firefox, Opera, etc.
  	var xmldoc=document.implementation.createDocument("","",null);
}

function ShowRoom(str,i){
	 for(var m=0;m<parseInt(document.getElementById('hid_count').value);m++){
		if(i==m){
			 var obj = document.getElementById('showroom_'+i+'');
			 if(obj.style.display == "none"){
				 obj.style.display = "block";
				 document.getElementById('font_'+i).innerHTML  = '隐藏房型'; 
			 }else{
				obj.style.display = "none";
				document.getElementById('font_'+i).innerHTML  = '全部房型';
			 }
		} else{  
				var obj = document.getElementById('showroom_'+m+'');
				obj.style.display = "none";
				document.getElementById('font_'+m).innerHTML  = '全部房型';
			 }
	  }
	b = i;
	OrderStr =  str;
	
	if(window.XMLHttpRequest)
		xml = new XMLHttpRequest();
	else if(window.ActiveXObject)
		xml = new ActiveXObject("Microsoft.XMLHTTP");
		xml.onreadystatechange = GetHotelRoom;
	try{
		document.getElementById('showroom_'+b).innerHTML = '<div style="text-align:center"><img src="/Themes/images/icon/ajax-loader.gif" />&nbsp;&nbsp;正在处理中...</div>';
		xml.open("GET","/Hotel/GetHotelRoom.asp?str="+encodeURI(str)+"&nocache="+Math.random(),true);
		xml.send(null);	
	}
	catch(e){}
}

function GetHotelRoom(){
	var showroom = document.getElementById('showroom_'+b);
	
	 if(xml.readyState == 4){
		if(xml.status == 200){
			var html = '<table width="90%" align="center" border="0" cellpadding="0" cellspacing="1"  class="hidTab">';
				html += '<tr>';
				html += '<th width="24%">房型</th>';
				html += '<th width="10%">门市价</th>';
				html += '<th width="10%">首日价</th>';
				html += '<th width="8%">床型</th>';
				html += '<th width="8%">早餐</th>';
				html += '<th width="10%">备注</th>';
				html += '<th width="10%"></th>';
				html += '</tr>';
			var response=xml.responseText;	
			xmldoc.async = false;
		    xmldoc.loadXML(response);
		    //xmldoc.load(response);
			//document.write(response)
			//document.getElementById('showroom_'+b).innerHTML = response;
			//alert(response)
			var lprice,hprice
			
			//IE
			if (window.ActiveXObject){ 
			 //if(xmldoc.readyState==4){
			var node = xmldoc.getElementsByTagName('RoomType');
            //var node = xmldoc.selectNodes("//OTResponse/Data/HotelRoomTypeInfo/RoomTypes/RoomType");
			for(var j=0;j<node.length;j++){				
				var nodev = node[j];
				
				var RoomName = nodev.getElementsByTagName("RoomName")[0].firstChild.data;
				var RoomCode = nodev.getElementsByTagName("RoomCode")[0].firstChild.data;
				var DisplayPrice = nodev.getElementsByTagName("DisplayPrice")[0].firstChild.data;
				var RateAmount = nodev.getElementsByTagName("RateAmount")[0].firstChild.data;
				var BedType = nodev.getElementsByTagName("BedType")[0].firstChild.data;
				var RoomDesc ="";
		        if (nodev.getElementsByTagName("RoomTypeDesc")[0].firstChild!=null)
				{RoomDesc = nodev.getElementsByTagName("RoomTypeDesc")[0].firstChild.data;}
				var MealPlan = nodev.getElementsByTagName("Meal")[0].firstChild.data;



//				var RoomName = nodev.childNodes[1].text;
//				var RoomCode = nodev.childNodes[0].text;
//				//var RoomName=oNodes[j].childNodes[12].nodeName;
//				var DisplayPrice = nodev.childNodes[12].childNodes[0].childNodes[3].text;
//				var RateAmount = nodev.childNodes[12].childNodes[0].childNodes[4].text;
//				var BedType = nodev.childNodes[10].text;
//				var RoomDesc ="";
//		        if (nodev.childNodes[13]!=null)
//				{RoomDesc = nodev.childNodes[13].text;}
//				var MealPlan = nodev.childNodes[12].childNodes[0].childNodes[6].text;

				
				
				if(j==0){ lprice=RateAmount;}
				if(j==node.length-1){ hprice=RateAmount;}
				if(DisplayPrice!='0.0'){
					var tmp = "<del>"+DisplayPrice+"</del>";	
				}else{
					var tmp = '';
				}
				
				var tmp2 = OrderStr.split('^');
				var tmp3 = tmp2[8] + "^" + tmp2[9] + "^" + tmp2[0] + "^" + tmp2[4] + "^" + tmp2[5] + "^" + RoomCode + "^" + tmp2[6] + "^" + tmp2[7] + "^" + MealPlan;
				
				if(RoomDesc!=''){
					var tmp1 = '<a href="javascript:Summary('+j+',\''+tmp2[0]+'\');"  class="blue">房型描述</a>';
				}else{
					var tmp1 = '<u>房型描述</u>';
				}
				
				html += '<tr>';
				html += '<td>'+RoomName+'</td>';
				html += '<td class="org">'+tmp+'</td>';
				html += '<td class="org">'+RateAmount+'</td>';
				html += '<td>'+BedType+'&nbsp;</td>';
				html += '<td>'+GetMeal(MealPlan)+'</td>';
				html += '<td>'+tmp1+'</td>';
				html += '<td><img src="/Themes/images/btn/Booking.jpg" width="36" height="18" style="cursor:pointer;" onclick="OrderRoom(\''+tmp3+'\');" /></td>';
				html += '</tr>';
				html += '<tr id="Summary_'+tmp2[0]+'_'+j+'" style="display:none;">';
				html += '<td colspan="7" class="Summary">房型描述：'+RoomDesc+'</td>';
				html += '</tr>';
				//alert(html + RoomCode +  RoomName + DisplayPrice + RateAmount + BedType + RoomDesc + MealPlan);*/
			}
			
			
			
			
			}
			
			//}
			
			else {
				//Firefox
				alert('Firefox');



			
			var node = xmldoc.getElementsByTagName('RoomType');
			for(var j=0;j<node.length;j++){
				var nodev = node[j];
				
				var RoomName = nodev.getElementsByTagName("RoomName")[0].firstChild.data;
				var RoomCode = nodev.getElementsByTagName("RoomCode")[0].firstChild.data;
				var DisplayPrice = nodev.getElementsByTagName("DisplayPrice")[0].firstChild.data;
				var RateAmount = nodev.getElementsByTagName("RateAmount")[0].firstChild.data;
				var BedType = nodev.getElementsByTagName("BedType")[0].firstChild.data;
				var RoomDesc ="";
		        if (nodev.getElementsByTagName("RoomTypeDesc")[0].firstChild!=null)
				{RoomDesc = nodev.getElementsByTagName("RoomTypeDesc")[0].firstChild.data;}
				//var RoomDesc = nodev.getElementsByTagName("RoomTypeDesc")[0].firstChild.data;
				var MealPlan = nodev.getElementsByTagName("Meal")[0].firstChild.data;
				if(j==0){ lprice=RateAmount;}
				if(j==node.length-1){ hprice=RateAmount;}
				if(DisplayPrice!='0.0'){
					var tmp = "<del>"+DisplayPrice+"</del>";	
				}else{
					var tmp = '';
				}
				
				var tmp2 = OrderStr.split('^');
				var tmp3 = tmp2[8] + "^" + tmp2[9] + "^" + tmp2[0] + "^" + tmp2[4] + "^" + tmp2[5] + "^" + RoomCode + "^" + tmp2[6] + "^" + tmp2[7] + "^" + MealPlan;
				
				if(RoomDesc!=''){
					var tmp1 = '<a href="javascript:Summary('+j+',\''+tmp2[0]+'\');"  class="blue">房型描述</a>';
				}else{
					var tmp1 = '<u>房型描述</u>';
				}
				
				html += '<tr>';
				html += '<td>'+RoomName+'</td>';
				html += '<td class="org">'+tmp+'</td>';
				html += '<td class="org">'+RateAmount+'</td>';
				html += '<td>'+BedType+'&nbsp;</td>';
				html += '<td>'+GetMeal(MealPlan)+'</td>';
				html += '<td>'+tmp1+'</td>';
				html += '<td><img src="/Themes/images/btn/Booking.jpg" width="36" height="18" style="cursor:pointer;" onclick="OrderRoom(\''+tmp3+'\');" /></td>';
				html += '</tr>';
				html += '<tr id="Summary_'+tmp2[0]+'_'+j+'" style="display:none;">';
				html += '<td colspan="7" class="Summary">房型描述：'+RoomDesc+'</td>';
				html += '</tr>';
				//alert(html + RoomCode +  RoomName + DisplayPrice + RateAmount + BedType + RoomDesc + MealPlan);*/
			}



				}
			html += '</table>';
			document.getElementById('desp_count').value = node.length;
			//alert(html)
			//alert(lprice+' '+hprice)
			document.getElementById('showroom_'+b).innerHTML = html;
			
			//alert(11+tmp[2])
			if(window.XMLHttpRequest)
				xml = new XMLHttpRequest();
			else if(window.ActiveXObject)
				xml = new ActiveXObject("Microsoft.XMLHTTP");
				xml.onreadystatechange = GetPriceShow;
			try{
				xml.open("GET","/hotel/GetHotelPrice.asp?lprice="+encodeURI(lprice)+"&hprice="+hprice+"&hotelid="+tmp2[0]+"&nocache="+Math.random(),true);
				xml.send(null);	
			}
			catch(e){}
		
		}
	}
}
function GetPriceShow(){
	 if(xml.readyState == 4){
		if(xml.status == 200){
			var response=xml.responseText;
			if(response!='error') {
				document.getElementById('price_'+b+'').innerHTML = response;
			}
		}
	 }
}

function GetMeal(f){
	if(f=='0'){
		return '无早';
	}else if(f=='1'){
		return '单早';	
	}else if(f=='2'){
		return '双早';
	}
}
