
var ajaxCore=new nineAJAX("ajaxCore");


function OnHotelDetailAndSearch(destvalue, hbindex, hotelname, detailindex)
{
	location="http://www.hoteljava.co.kr/Search/HotelInfoView.asp?PageType=0&Page=1&HBIndex="+hbindex;
	//OnSearchOneHotelCore(null, destvalue, hbindex, hotelname, detailindex);
}

function OnSearchOneHotelCore(SearchResultIndex, destvalue, hbindex, hotelname, detailindex)
{
	OnSearchHotelCoreForHotelDetail(SearchResultIndex
	, "ct"
	, destvalue
	, "0"
	, "<ROOMTYPES><ROOM CODE=\"SGL\" COUNT=\"1\" /></ROOMTYPES>"
	, "2012-02-21"
	, "2012-02-22"
	,hbindex
	,""
	,"N"
	,""
	,detailindex);
}
function OnSearchOneHotelCoreConfirmOnly(SearchResultIndex, destvalue, hbindex, hotelname, detailindex)
{
	OnSearchHotelCoreForHotelDetail(SearchResultIndex
	, "ct"
	, destvalue
	, "0"
	, "<ROOMTYPES><ROOM CODE=\"SGL\" COUNT=\"1\" /></ROOMTYPES>"
	, "2012-02-21"
	, "2012-02-22"
	,hbindex
	,""
	,"N"
	,""
	,detailindex);
}
function OnSearchLandmarkCore(landmarkrelindex, cityindex)
{
	OnSearchHotelCore(null
	, "lm"
	, landmarkrelindex
	, cityindex
	, "<ROOMTYPES><ROOM CODE=\"SGL\" COUNT=\"1\" /></ROOMTYPES>"
	, "2012-02-21"
	, "2012-02-22"
	,"0"
	,""
	,"N"
	,""
	);
}
function OnSearchHotelCoreForHotelDetail(SearchResultIndex, desttype, destvalue, destloc, roomTypeQuery, checkin, checkout, hbindex, hotelname, confirmonly, callbackfunc, detailindex)
{
	if(callbackfunc=="")
		callbackfunc="OnSearchingEndCore";
	var turl=PrepareSearchCore(SearchResultIndex, desttype
	,destvalue
	,destloc
	,roomTypeQuery
	,checkin
	,checkout
	,hbindex);
	var toption = new Object();
	toption.searchKey="";
	//toption.targeURL="/xhtml/search/search_page.asp";
	toption.targeURL="/search/search_page_n4.asp";
	if(hbindex!="0" && hbindex!="")
	{
		//toption.targeURL="/xhtml/Search/search_page_for_hotel.asp";
		toption.targeURL="/Search/search_page_for_hotel.asp";
	}
	toption.confirmonly = confirmonly;
	toption.hotelname = hotelname;
	toption.curindex = 0;
	toption.SupplierCodeList = new Array();
	toption.SupplierCodeList[toption.SupplierCodeList.length]="TRO";
	toption.detailindex=detailindex;
	retval=ajaxCore.SendXmlhttp(turl, 1, "", null);
	//alert(retval);
	var oXmlDoc = ajaxCore.GetDOMFromXMLText(retval);
	if(oXmlDoc!=null)
	{
		var olist		=	oXmlDoc.getElementsByTagName("SEARCHPREPARE");
		if(olist.length==1)
		{
			if(olist.item(0).getAttribute("ERRORCODE")=="OK")
			{
				toption.searchKey=olist.item(0).getAttribute("KEY");
				//gMsgLayer.ShowLayer(true);
				try{
					OpenBigLoading("");
				}catch(e)
				{
				}
				turl="/HJCoreService/SearchHotels.aspx?";
				turl+="&searchKey=";
				turl+=toption.searchKey;
				turl+="&SCODE=";
				turl+=toption.SupplierCodeList[0];
				ajaxCore.ModuleReset();
				retval=ajaxCore.SendXmlhttp(turl, 1, callbackfunc, toption);
			}
		}
	}
	//ajaxCore
	//HotelSearchForm.submit();
}
function OnSearchHotelCore(SearchResultIndex, desttype, destvalue, destloc, roomTypeQuery, checkin, checkout, hbindex, hotelname, confirmonly, callbackfunc)
{
	
	OnSearchHotelCoreForHotelDetail(SearchResultIndex, desttype, destvalue, destloc, roomTypeQuery, checkin, checkout, hbindex, hotelname, confirmonly, callbackfunc, '');

}

function OnSearchingEndCore(tsuccess, retval, terrorcode, tcustparam)
{
	var oXmlDoc = ajaxCore.GetDOMFromXMLText(retval);
	var remaining=0;
	if(oXmlDoc!=null)
	{
		var olist		=	oXmlDoc.getElementsByTagName("startdate");
		var sDate = "";
		var eDate = "";
		if(olist.length>0)
			sDate = ajaxCore.GetNodeText(olist.item(0));
		olist		=	oXmlDoc.getElementsByTagName("enddate");
		if(olist.length>0)
			eDate = ajaxCore.GetNodeText(olist.item(0));
			
		olist		=	oXmlDoc.getElementsByTagName("SEARCHSTEP");
		if(olist.length>0)
			remaining = parseInt(olist.item(0).getAttribute("REMAINING"));
		//alert(remaining);
		//alert(tcustparam.SupplierCodeList[tcustparam.curindex]+" end ("+sDate+" ~ "+eDate+")");
	
	}
	tcustparam.curindex++;
	
	location.href=tcustparam.targeURL+"?searchKey="+tcustparam.searchKey+"&DetailIndex="+tcustparam.detailindex+"&OnlyConfirm="+tcustparam.confirmonly+"&searchOnlyConfirm="+tcustparam.confirmonly+"&opthotelname="+escape(tcustparam.hotelname);
	
}


function PrepareSearchCore(SearchResultIndex, desttype, destvalue, destloc, roomTypeQuery, checkin, checkout, hbindex)
{
	var turl="/common/AJAXLib/AJAX_SearchHotelPrepare.asp?";
	turl+=("QCheckInDate="+checkin);
	turl+=("&QCheckOutDate="+checkout);
	turl+=("&QRoomTypeQuery="+escape(roomTypeQuery));
	if(desttype=="ct")
	{
		turl+=("&QBaseIndex="+destvalue);
		turl+=("&QLocationIndex="+destloc);
	}
	else
	{
		turl+=("&QLandmarkIndex="+destvalue);
		turl+=("&QDestIndexForLandmark="+destloc);
	}
	
	if(hbindex!="")
		turl+=("&QHBIndex="+hbindex);
	if(SearchResultIndex!=null)
		turl+=("&SearchResultIndex="+SearchResultIndex);
	
		
	return turl;
}
