/*
 * Hotel Result
 * 
 * Powered By Great Han@2008-11
 * hwlyglove@gmail.com
 *
 */

 /**
 *basic function
 */
 function previousSibling(obj){
	var tempObj = obj;	
	do{
		tempObj = tempObj.previousSibling;
	}while(tempObj.previousSibling&&tempObj.previousSibling.nodeType&&(tempObj.previousSibling.nodeType!=1))
	return tempObj;
}

function nextSibling(obj){
	var tempObj = obj;
	do{
		tempObj = tempObj.nextSibling;
	}
	while(tempObj.nextSibling&&tempObj.nextSibling.nodeType&&(tempObj.nextSibling.nodeType!=1))
	return tempObj;
}

function firstChild(obj){
	var tempObj = obj.firstChild;
	while(tempObj.nodeType&&tempObj.nodeType!=1){
		tempObj = tempObj.nextSibling;
	}
	return tempObj;
}
/**
 *	function show/hide room detail
 */
/**
*	show roomdetail
*	when click the roomtype link,use ajax to get roomdetail and show it on the dom;
*
*/
	function showRoomDetail(obj,id){
		function showcallback(str){
			if(!str||str == 'NULL'){
				firstChild(firstChild(detailDiv)).innerHTML = "暂无房型信息";
				return false;
			}else{
				detailDiv.data = str;
				firstChild(firstChild(detailDiv)).innerHTML = toRoomDetailStr(detailDiv.data);
				return;
			}
		}

		function toRoomDetailStr(str){
			var tempstr = "",
				temparr = str.split('|');
			if(/http:/.test(temparr[0])){
				tempstr += '<a class="link" target = "_blank" href="';
				tempstr += firstChild(firstChild(previousSibling(detailDiv))).href;
				tempstr += '" style="background:url(';
				tempstr += temparr[0];
				tempstr += ') no-repeat;"></a>';
			}
			tempstr += "<ul class=\"searchresult_caplist\">";
			for(var i = 1,j = temparr.length;i<j;i++){
				tempstr += "<li title = \""+temparr[i]+"\">"+temparr[i]+"</li>";
			}
			tempstr += "</ul>";
			return tempstr;
		}

		var detailDiv = nextSibling(obj.parentNode.parentNode);
		detailDiv.style.display = detailDiv.style.display?"":"none";
		if(!detailDiv.data){
			var ajax = $ajax(address.roomdetail.replaceWith([id]),null,showcallback);
		}
	}

function hideRoomDetail(obj){
	var roomdetail = obj.parentNode.parentNode;
	roomdetail.style.display = "none";
}

var delimiter = String.fromCharCode(1),
	sHtml = {
		hidden: 'style="visibility:hidden"',
		none: 'style="display:none"'
	},
	address = {
		detail: '/Domestic/ShowHotelInfo.aspx?hotel={$0}&StartDate={$1}&DepDate={$2}{$3}{$4}',
		picture: '/Domestic/ShowHotelRoomPic.aspx?hotel={$0}{$1}&StartDate={$2}&DepDate={$3}',
		order: '/Domestic/InputNewOrder.aspx',
		delayOrder: '/Domestic/InputDelayOrder.aspx',
		evaluation: '/HtlComment/',
		allRoom: '/Domestic/tool/AjaxHotelPrice.aspx?hotel={$0}&startdate={$1}&depdate={$2}{$3}',
		roomdetail:'/Domestic/tool/AjaxRoomInfo.aspx?room={$0}',
		fltHotel: '/Domestic/InputAirHotel.aspx',
		fltOrder: '/Domestic/InputDeliver.aspx'
	};
var map_num = 0, htlIndex = 0;
if (!HotelQuery) var HotelQuery = { checkIn: '', checkOut: ''};
var HotelList = new MadCat(function(){
	var _this = this;
	var divNotFound;
	this.init = function(){
		divNotFound = $('divNotFound');
	};
	this.set = function(query, result){
		divNotFound.style.display = result.hotelFound ? 'none' : '';
		var bakHtml = divNotFound.$('p')[0].innerHTML;
		if (result.hotelMsg) {
			divNotFound.style.display = result.hotelMsg ? '' : 'none';
			divNotFound.$('p')[0].innerHTML = result.hotelMsg || bakHtml;
		}
		var cpy = fm.v('CorpPayType');
		Hotel.CorpPayType = cpy ? ('&CorpPayType=' + cpy) : '';
		map_num = 0;
		htlIndex = 0;
		var str = result.hotelsInfo,
			dataArr = this.hotels = [], j = 0,
			holder = this.holder = $('htl_list'),
			tmpDiv = $c('div');
		addClass(tmpDiv, 'searchresult_list');
		tmpDiv.setAttribute("cdm", "blk_hotelinfo");
		if (!HotelResult.hotelFound) {
			holder.innerHTML = '';
			return;
		}
		str.split(HotelList.delimiter).each(function(el){
			dataArr.push(new Hotel(el));
		});
		if (this.timer) clearInterval(this.timer);
		holder.innerHTML = '';
		this.timer = setInterval(function(){
			try {
				var div = tmpDiv.cloneNode(false);
				div.innerHTML = dataArr[j++].toString();
				holder.appendChild(div);
				if (!dataArr[j]) clearInterval(_this.timer);
			} catch (e) {
				clearInterval(_this.timer);
				_this.timer = null;
				HotelView.showFailure();
				$trackEvent('hotels.error', 'result', $error(e), $tunaVersion());	
			}
		}, 100);
	};
});
HotelList.delimiter = String.fromCharCode(12);
function Hotel(str){
	this.room_list = str.split(Hotel.delimiter);
	this.room_list.shift().split(delimiter).associate(Hotel.attributes, this);
}
$extend(Hotel, {
	template: '<div class="searchresult_num" {$show_mapNum}>{$map_num}</div><ul class="hotel_grid01 layoutfix"><li class="hotel_unit first"><div class="hotel_whitebg"><a cdm="btn_hoteldetail" style="background-image: url({$icon});" class="searchresult_abbrpic" href="{$href}" title="{$name}"></a><a cdm="btn_hotelimg" target="_blank" class="hotel_realpic" {$eview} title="{$name}实景图" href="{$eview_href}">酒店实景图</a></div><dl class="hotel_whitebg"><dt class="hotel_judge"><a  cdm="btn_customerestimate" target="_blank" class="hotel_value" href="{$evaluation}" title="{$name}点评">{$score}&nbsp;<span>查看点评</span></a><p>({$people_num}人点评)</p></dt><dd class="hotel_showvalue01"><span style="width: {$score_width};"></span></dd><dd><a cdm="btn_customerestimateintr" target="_blank" href="/Domestic/ShowUstarNote.aspx" title="携程用户评级说明">携程用户评级</a><br/><img src="http://pic.ctrip.com/common/pic_alpha.gif" class="{$diamond}"/></dd></dl></li><li class="hotel_unit layoutfix"><div class="layoutfix"><h3 class="searchresult_name{$medal}"><a cdm="btn_hoteldetail" title="{$name}" href="{$href}">{$name}</a><img alt="" src="http://pic.ctrip.com/common/pic_alpha.gif" class="searchresult_numstars{$star}" {$show_star}/></h3></div><div class="searchresult_desc"><p class="searchresult_desc_text">{$desc}</p><p class="layoutfix">{$area_map}<a cdm="btn_emap" {$emap} class="searchresult_emap" title="{$name}电子地图" href="{$emap_click}">电子地图</a></p></div><div class="hotel_special" {$show_prom}>{$prom_text}</div><div>{$roomList}<p  cdm="btn_showallroom" class="hotel_room_showall" onclick="RoomList.showAllRoom(this,{$id})">全部房型 &#9660;</p></div></li></ul>',
	mapTemplate: '<div cdm="blk_emaphotelinfo" style="width:420px;background:#FFF;"><ul class="hotel_grid01 layoutfix"><li class="hotel_unit first" style="padding:0;"><div class="searchresult_abbrpic" style="background-image:url({$icon})"></div></li><li class="hotel_unit layoutfix"><div class="layoutfix"><h3 class="searchresult_name{$medal}"><a cdm="btn_hoteldetail" href="{$href}" title="{$name}">{$name}</a><img class="searchresult_numstars{$star}" src="http://pic.ctrip.com/common/pic_alpha.gif" alt="" /></h3></div><div class="searchresult_desc"><p class="searchresult_desc_text">{$desc}</p></div></li></ul>{$roomList}</div>',
	medal: {G: ' hotel_goldmedal', S: ' hotel_silvermedal'},
	delimiter: String.fromCharCode(11),
	attributes: ('id,name,medal,starlience,star,ctrip_star,score,icon,desc,eview,area,prom,people_num,position,room_list').split(','),
	prom: '<a cdm="btn_promotioninfo" href="{$prom_href}" title="{$prom_info}">{$prom_info}</a>',
	areaMap: {
		'1': '<a cdm="btn_amap" class="searchresult_elocal" title="{$1}酒店预订" href="{$amap_href}">{$5}{$1}</a>',
		'2': '<span {$0} class="searchresult_elocal">{$3}{$1}</span>'
	},
	defaultIcon: 'http://pic.ctrip.com/hotels081118/no_hotel_photo.gif'
});
Hotel.prototype = {
	toString: function(templateType){
		var template = Hotel.template;
		if (templateType == 'map') template = Hotel.mapTemplate;
		var star = this.star,
			ctripStar = this.ctrip_star,
			hasHalfStar = /\./.test(ctripStar),
			ctrip_star = hasHalfStar ? ctripStar.split('.')[0] - (-1) : ctripStar,
			prom = this.prom.split('|') || '',
			visible = {'T': '', 'F': sHtml.hidden},
			area = this.area.split('|'),
			isResultPage = /showHotelList\.aspx/i.test(location.href);
		if (this.position) {
			this.emap = '';
			this.emap_click = 'javascript:EMap.showPop(' + htlIndex +')';
			this.show_mapNum = 'onclick="EMap.pop('+map_num+')" title="酒店位置"';
			this.map_num = ++map_num;
		} else {
			this.show_mapNum = sHtml.hidden;
			this.emap = area[1] ? sHtml.none : sHtml.hidden;
		}
		htlIndex++;
		this.icon = this.icon || Hotel.defaultIcon;
		var fltHotelQuery = 
				HotelQuery.fltSubOrderID > 0 ?
				('&fltSubOrderID='+HotelQuery.fltSubOrderID + '&RoomNum=' + HotelQuery.roomNum + '&isOnlyAirHotel=' + HotelQuery.isOnlyAirHotel) : '';
		this.href = isResultPage ?
			address.detail.replaceWith([
				this.id,
				HotelQuery.checkIn,
				HotelQuery.checkOut,
				Hotel.CorpPayType,
				fltHotelQuery
			]) : '/hotel/' + this.id + '.html';
		this.evaluation = address.evaluation + this.id + '.html';
		this.medal = Hotel.medal[this.medal] || '';
		this.show_star = this.starlience == 'T' && star > 0 ? '' : sHtml.hidden;
		this.star = ' hotel_stars0' + star;
		this.diamond = hasHalfStar ?
			'hotel_halfdiamond0' + ctrip_star :
			'hotel_diamond0' + ctrip_star;
		this.score_width = (this.score / 5) * 102 + '%';
		this.eview = visible[this.eview] || '';
		this.eview_href = address.picture.replaceWith([this.id, '&type=action', HotelQuery.checkIn, HotelQuery.checkOut]);
		var district = area[2] == 'T' ? '商业区：' : '行政区：';
		area[2] = area[2] == 'T' ? 'zone' : 'location';
		this.area_map = area[1] ? area[0] == '-1' || area[2] != 'zone' || !AMap.hash[area[0]] ?
			Hotel.areaMap['2'].replaceWith(area.concat(district)) :
			Hotel.areaMap['1'].replaceWith({amap_href: isResultPage ? 'javascript:AMap.clickArea({$0})' :'/hotel/{$3}{$4}/{$2}{$0}/'}).replaceWith(area.concat(HotelQuery.cityEName, HotelQuery.cityId, district)) :
			Hotel.areaMap['2'].replaceWith([sHtml.hidden, '']);
		this.show_prom = prom[0] ? '' : sHtml.hidden;
		this.prom_text = (prom[1] && prom[2]) ?
			Hotel.prom.replaceWith({
				prom_info: prom[0],
				prom_href: address.detail.replaceWith([this.id, prom[1], prom[2], Hotel.CorpPayType, fltHotelQuery])
			}) : prom[0];
		this.roomList = new RoomList(this.room_list, templateType, this.id);
		return $s2t(template.replaceWith(this));
	}
}

function orderHotel(htlID, roomID, payment, status, minstate, promType, promDate){
	fm.v({
		'Resource': htlID,
		'Room': roomID,
		'Paymentterm': payment,
		'BRev': status,
		'Minstate': minstate,
		'PromoteType': promType,
		'PromoteDate': promDate,
		'StartDate': HotelQuery.checkIn,
		'DepDate': HotelQuery.checkOut
	});
	var fltSubOrderID = HotelQuery.fltSubOrderID,
		promoteDate = promDate ? promDate.split(',') : ['', ''],
		roomNum = $('ddlRoomNum', true);
	if (fltSubOrderID > 0) {
		fm.v({
			'PromoteStartDate': promoteDate[0],
			'PromoteEndDate': promoteDate[1],
			'OrderID': fltSubOrderID,
			'RoomNum': roomNum.value
		});
		if (roomNum.value == 0) {
			$alert(roomNum, Msg.room_num);
			return false;
		}
		var hostName = location.hostname;
		fm.action = 'http://' + hostName.replace(/hotels\./, 'flights.') +  address.fltHotel;
		fm.submit();
		return;
	}
	fm.action = fm.v('operationtype') == 'DELAYORDER' ? address.delayOrder : address.order;
	fm.submit();
}

function commitFltOrder(){
	var hostName = location.hostname;
	fm.action = 'http://' + hostName.replace(/hotels\./, 'flights.') + address.fltOrder;
	fm.submit();
}
function RoomList(roomListData, map, htlID){
	var _ = this;
	this.templateType = map;
	this.hotel = htlID;
	this.id = 'roomList' + htlID;
	this.FGrooms = [];
	this.PProoms = [];
	roomListData.each(function(el, i){
		var payType = el.match(/\x01(FG|PP)\x01/)[1];
		_[{FG: 'FGrooms', PP: 'PProoms'}[payType]].push(new Room(el, map, _.hotel, payType));
	});
}
$extend(RoomList, {
	showAllRoom: function(obj, htl_id){
		var listDiv = obj.parentNode;
		if (listDiv.backHtml) {
			var str = listDiv.backHtml;
			listDiv.backHtml = listDiv.innerHTML;
			listDiv.innerHTML = str;
		} else {
			listDiv.backHtml = listDiv.innerHTML;
			$ajax(address.allRoom.replaceWith([htl_id, HotelQuery.checkIn, HotelQuery.checkOut, HotelQuery.fltSubOrderID > 0 ? '&fltSubOrderID=' + HotelQuery.fltSubOrderID + '&RoomNum=' + HotelQuery.roomNum : '']), null, function(str){
				if (str == 'null' || !str) return;
				str = str.split(Hotel.delimiter);
				listDiv.innerHTML = new RoomList(str, null, htl_id);
				if (obj.flag) {
					obj.innerHTML = $s2t('全部房型 &#9660;');
					obj.flag = false;
				} else {
					obj.innerHTML = $s2t('全部房型 &#9650;');
					obj.flag = true;
				}
				listDiv.appendChild(obj);
			});
		}
	},
	template: '<table width="100%" cellspacing="0" cellpadding="0" border="0" class="hotel_datelist0{$cls}"><tbody><tr><th style="width: 100%;">房型</th><th><div style="width: 78px;">门市价</div></th><th><div style="width: 78px;">首日价</div></th><th><div style="width: 77px;">均价</div></th><th><div style="width: 51px;">早餐</div></th><th><div style="width: 59px;">床型</div></th><th><div style="width: 52px;">宽带</div></th><th><div style="width: 66px;">{$payment}</div></th></tr>{$rooms}</tbody></table>',
	mapTemplate: '<table class="searchresult_googlelist0{$cls}" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><th style="width: 100%;">房型</th><th><div style="width:80px;">均价</div></th><th><div style="width:50px;">早餐</div></th><th><div style="width:52px;"></div></th></tr>{$rooms}</table>',
	mapOneDayTemplate: '<table class="searchresult_googlelist0{$cls}" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><th style="width: 100%;">房型</th><th><div style="width:80px;">{$price_type}</div></th><th><div style="width:50px;">早餐</div></th><th><div style="width:52px;"></div></th></tr>{$rooms}</table>',
	oneDayTemplate: '<table width="100%" cellspacing="0" cellpadding="0" border="0" class="hotel_datelist0{$cls}"><tbody><tr><th style="width: 100%;">房型</th><th><div  style="width:78px">门市价</div></th><th><div style="width:155px">{$price_type}</div></th><th><div style="width:51px">早餐</div></th><th><div style="width:59px">床型</div></th><th><div style="width:52px">宽带</div></th><th><div style="width:66px">{$payment}</div></th></tr>{$rooms}</tbody></table>',
	fltHotelTpl: '<table class="hotel_datelist01" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><th style="width:100%;">房型</th><th><div style="width:59px;">床型</div></th><th><div style="width:51px;">早餐</div></th><th><div style="width:52px;">宽带</div></th><th><div style="width:118px;">机票+{$day}晚酒店优惠价</div></th><th><div style="width:78px;">分开预订价</div></th><th><div style="width:77px;">节省</div></th><th><div style="width:66px;">-</div></th></tr>{$rooms}</table>',
	payment: {FG: '前台现付', PP: '网上预付'}
});
RoomList.prototype = {
	toString: function(){
		var RoomListTemplate = RoomList.template,
			isMap = this.templateType == 'map',
			isFltHotel = HotelQuery.fltSubOrderID > 0;
		Hotel.isOneDay = (HotelQuery.checkOut.isDateTime() - HotelQuery.checkIn.isDateTime()) <= 24*60*60*1000;
		if (isMap) RoomListTemplate = RoomList.mapTemplate;
		if (Hotel.isOneDay) RoomListTemplate = RoomList.oneDayTemplate;
		if (Hotel.isOneDay && isMap) RoomListTemplate = RoomList.mapOneDayTemplate;
		if (isFltHotel) {
			if (isMap) RoomListTemplate = RoomList.mapOneDayTemplate; //map and flight + hotel
			else RoomListTemplate = RoomList.fltHotelTpl; //flight + hotel
		}
		var fgRooms = this.FGrooms,
			ppRooms = this.PProoms;
		if (fgRooms.length)
			fgRooms = RoomListTemplate.replaceWith({
				cls: 1,
				rooms: fgRooms.join(''),
				payment: RoomList.payment.FG,
				price_type: (isFltHotel ? '优惠' : RoomList.payment.FG) + '价',
				day: isFltHotel ? (HotelQuery.checkOut.isDateTime() - HotelQuery.checkIn.isDateTime()) / (24 * 60 * 60 *1000) : ''
			});
		if (ppRooms.length) 
			ppRooms = RoomListTemplate.replaceWith({
				cls: 2,
				rooms: ppRooms.join(''),
				payment: RoomList.payment.PP,
				price_type: RoomList.payment.PP + '价'
			});
		return $s2t(fgRooms + ppRooms);
	}
};
function Room(roomData, map, htlID, pt){
	roomData.split(delimiter).associate(Room.attributes, this);
	this.hotel = htlID;
	this.templateType = map;
	this.payType = pt;
}
$extend(Room, {
	attributes: ('id,name,payment,room_pic,gift,price,currency,breakfast,bed,net,status,lasttime,show_price,show_ppprice,minstate,prom').split(','),
	dailyPriceDecode: function(data){
		var data = data.split('$'),
			day = HotelQuery.checkIn.isDateTime().getDay(),
			rlt = Room.week.slice(day).concat(Room.week.slice(0, day));
		rlt.push('第1周');
		data.each(function(el, i){
			var tmp = el.split(','),
				weeks = i%7?0:i/7
			if (weeks) rlt.push('第' + (weeks+1) +'周');
			rlt.push(tmp[0], Room.breakfast[tmp[1]]);
		});
		return rlt.join('|');
	},
	template: '<tr><td class="hotel_room"><a cdm="btn_roompic" target="_blank" href="{$picture}" title="房间图片" {$room_pic} class="hotel_roompic"></a><a cdm="btn_roomdetail" title="{$name}" href="###" onclick = "showRoomDetail(this,{$id});$stopEvent($fixE(),2);">{$name}</a>{$gift}{$sales}</td><td>{$cur_class} {$list_price}</td><td>{$cur_class} {$first_price}</td><td><a cdm="jpi_price" mod="jmpInfo" mod_jmpInfo_content="{$daily_price}" mod_jmpInfo_position="align-right" mod_jmpInfo_page="hotels_pdPrice081119.asp" id="{$uid}" class="base_price02" href="###">{$cur_class} {$average_price}</a></td><td>{$breakfast}</td><td>{$bed}</td><td>{$net}</td><td><input cdm="btn_subcheck" type="button" class="base_btn0{$btnCls}" onclick="{$orderFn}" PaymentTerm={$payType} value="{$btnTxt}"/></td></tr><tr style = "display:none"><td style="border: medium none ;" colspan="8"><div class="searchresult_caption layoutfix">查询中，请稍候</div><a cdm="btn_roomdetailhide" href="###" class="searchresult_capbtn" onmousedown = "hideRoomDetail(this)">隐藏</a></td></tr>',
	mapTemplate: '<tr><td class="searchresult_room"><a cdm="btn_roompic" target="_blank" href="{$picture}" title="房间图片" class="hotel_roompic" {$room_pic}></a><a cdm="btn_roomdetail" href="###" onclick = "{$orderFn}" title="{$name}" class="searchresult_googleroomtype">{$name}</a>{$gift}{$sales}</td><td><a mod="jmpInfo" mod_jmpInfo_content="{$daily_price}" mod_jmpInfo_page="hotels_pdPrice081119.asp" id="{$uid}" href="###" class="base_price02">{$cur_class} {$average_price}</a></td><td>{$breakfast}</td><td><input cdm="btn_subcheck" type="button" onclick="{$orderFn}" value="{$btnTxt}" class="base_btn0{$btnCls}" PaymentTerm={$payType}/></td></tr>',
	mapOneDayTemplate: '<tr><td class="searchresult_room"><a cdm="btn_roompic" target="_blank" href="{$picture}" title="房间图片" class="hotel_roompic" {$room_pic}></a><a cdm="btn_roomdetail" href="###" onclick = "{$orderFn}" title="{$name}" class="searchresult_googleroomtype">{$name}</a>{$gift}{$sales}</td><td>{$cur_class} {$price}</td><td>{$breakfast}</td><td><input cdm="btn_subcheck" type="button" PaymentTerm={$payType} onclick="{$orderFn}" value="{$btnTxt}" class="base_btn0{$btnCls}"/></td></tr>',
	oneDayTemplate: '<tr><td class="hotel_room"><a cdm="btn_roompic" target="_blank" href="{$picture}" title="房间图片" {$room_pic} class="hotel_roompic"></a><a title="{$name}" cdm="btn_roomdetail" href="###" onclick = "showRoomDetail(this,{$id});$stopEvent($fixE(),2);">{$name}</a>{$gift}{$sales}</td><td>{$cur_class} {$list_price}</td><td>{$cur_class} {$price}</td><td>{$breakfast}</td><td>{$bed}</td><td>{$net}</td><td><input cdm="btn_subcheck" type="button" class="base_btn0{$btnCls}" onclick="{$orderFn}" PaymentTerm={$payType} value="{$btnTxt}"/></td></tr><tr style = "display:none"><td style="border: medium none ;" colspan="8"><div class="searchresult_caption layoutfix">查询中，请稍候</div><a cdm="btn_roomdetailhide" href="###" class="searchresult_capbtn" onmousedown = "hideRoomDetail(this)">隐藏</a></td></tr>',
	ftlHotelTpl: '<tr><td class="hotel_room"><a title="{$name}" cdm="btn_roomdetail" href="###" onclick = "showRoomDetail(this,{$id});$stopEvent($fixE(),2);">{$name}</a>{$gift}{$sales}</td><td>{$bed}</td><td>{$breakfast}</td><td>{$net}</td><td>{$cur_class} {$pref_price}</td><td>{$original_price}</td><td class="base_price01">{$save}</td><td><input  cdm="btn_subcheck" type="button" class="base_btn0{$btnCls}" PaymentTerm={$payType} onclick="{$orderFn}" value="{$btnTxt}"/></td></tr><tr style = "display:none"><td style="border: medium none ;" colspan="8"><div class="searchresult_caption layoutfix">查询中，请稍候</div><a cdm="btn_roomdetailhide" href="###" class="searchresult_capbtn" onmousedown="hideRoomDetail(this)">隐藏</a></td></tr>',
	breakfast: ('无早,单早,双早,三早,四早,五早,六早,七早,八早,每人一份早').split(','),
	week: ('周日,周一,周二,周三,周四,周五,周六').split(','),
	bed: {'TF': '大床', 'FT': '双床', 'TT': '大/双'},
	status: {'N': 1},
	btn: ['查看', '预订'],
	gift: '<span cdm="jpi_gift" mod="jmpInfo" mod_jmpInfo_page="hotels_gift081119.asp"  mod_jmpInfo_content="{$0}" mod_jmpInfo_position="align-left" class="hotel_gift"></span>',
	sales: '<span class="hotel_sales"></span>',
	daily_price: '<a cdm="jpi_price" mod="jmpInfo" mod_jmpInfo_content="{$daily_price}" mod_jmpInfo_position="align-right" mod_jmpInfo_page="hotels_pdPrice081119.asp" id="{$uid}" class="base_price02" href="###">{$cur_class} {$average_price}</a>',
	defaltRoomPicUrl: "http://pic.ctrip.com/hotels081118/temp_abbrpic3.gif"
});
Room.prototype = {
	toString: function(){
		var _this = this;
		var template = Room.template,
			isMap = this.templateType == 'map',
			isFltHotel = HotelQuery.fltSubOrderID > 0;
		if (isMap) template = Room.mapTemplate;
		if (Hotel.isOneDay) template = Room.oneDayTemplate;
		if (Hotel.isOneDay && isMap) template = Room.mapOneDayTemplate;
		if (isFltHotel) {
			if (isMap) template = Room.mapOneDayTemplate;
			else template = Room.ftlHotelTpl;
		}
		var price = this.price.split('|'),
			prom = this.prom ? this.prom.split('|') : '',
			gift = this.gift,
			currency = this.currency.split('|'),
			orderArgs = [
				this.hotel, this.id, this.payment,
				this.status == 'N' ? 0 : 1, this.minstate,
				prom[0] || '', prom[1] ? (prom[1] || '') + ',' + (prom[2] || '') : ''
			].join("','"),
			orderFn = HotelQuery.fltSubOrderID > 0 && this.status == 'N' ? 'void(0)' : "orderHotel('{$0}')".replaceWith([orderArgs]),
			showPrice = 
				((this.show_price == 'F') && (this.payment == 'FG')) ||
				((this.show_ppprice == 'F') && (this.payment == 'PP'));
		this.uid = $getUid();
		this.order = 'javascript:' + orderFn;
		this.orderFn = orderFn;
		this.picture = address.picture.replaceWith([this.hotel, '&room='+this.id, HotelQuery.checkIn, HotelQuery.checkOut]);
		this.room_pic = this.room_pic == 'T' ? '': sHtml.hidden;
		this.gift = gift ? Room.gift.replaceWith([gift]) : '';
		this.sales = prom[0] ? Room.sales : '';
		this.bed = Room.bed[this.bed] || '';
		this.cur_class = showPrice ? '' : (currency[0] || '');
		this.list_price = showPrice ? '***' : (parseFloat(price[0]) > 0 && parseFloat(price[0])>parseFloat(price[1]))? ('<del>'+price[0]+'</del>' || '') : ' --- ';
		if (Hotel.isOneDay && !isFltHotel) this.price = showPrice ? '***' : (price[1] || '');
		else if (isFltHotel) {
			this.price = this.pref_price = price[0];
			this.original_price = price[1] ? (this.cur_class + ' <del>' + price[1] + '</del>') : '-';
			this.save = price[2] ? ('省 ' + this.cur_class + ' ' + price[2]) : '-';
		} else {
			this.first_price = showPrice ? '***' : (price[1] || '');
			this.average_price = showPrice ? '***' : (price[2] || '');
			this.daily_price = showPrice ? '' : (Room.dailyPriceDecode(price[3]) || '');
		}
		this.btnCls = this.status == 'N' ? 1 : 2;
		this.btnTxt = Room.btn[this.btnCls - 1];
		this.breakfast = Room.breakfast[this.breakfast] || '';
		return $s2t(template.replaceWith(this));
	}
};

function showRoomList(data, htlID){
	return new RoomList(data.split(Hotel.delimiter), '', htlID).toString();
}
