  var $ = function(element) {
      return document.getElementById(element);
  }

// "다시검색하기"
function _ReSearch_Check()
{
	this.OnChangeYn = "N";
}

function ChangeDuration()
{
	ffrm = document.aspnetForm;
	
	//2006-07-10 추가
	_ReSearch_Check.OnChangeYn = "Y";
	//2006-07-10 추가

	ffrm.Duration.value = ffrm.ddlDuration.options[ffrm.ddlDuration.selectedIndex].value;
	if (ffrm.txtCheckInDateShow.value.length > 0)
	{		
		Duration_change();
	}
	else
	{
		ffrm.txtCheckOutDate.value = '';
	}
}

function Duration_change()
{
	var f = document.aspnetForm;
	
	var strCheckInDate			// 체크인 일자 YYYY-MM-DD
	var dtCheckOut			

	var strCheckInYYYY
	var strCheckInMM
	var strCheckInDD
	
	var strCheckOutYYYY
	var strCheckOutMM
	var strCheckOutDD
	var strCheckOut	
		
	var strRet
	var iAddDays = parseInt(f.ddlDuration[f.ddlDuration.selectedIndex].value,10);
	
	//f.PirceSearch.value = "N";
	
	strCheckInDate	= f.txtCheckInDate.value.substring(0,10)
	ArrCheckDate	= f.txtCheckInDate.value.split('-');
	strCheckInYYYY	= ArrCheckDate[0];
	strCheckInMM	= ArrCheckDate[1];
	strCheckInDD	= ArrCheckDate[2];

	
	dtCheckOut =  new Date(strCheckInYYYY,strCheckInMM - 1, parseInt(strCheckInDD,10) + iAddDays)
	
	strCheckOutYYYY = dtCheckOut.getFullYear();
	
	var NMonth = parseInt(dtCheckOut.getMonth()) + 1;	
	if(NMonth < 10)
	{
		strCheckOutMM = "0"+ parseInt(dtCheckOut.getMonth()+ 1) ;		
	}
	else
		strCheckOutMM = dtCheckOut.getMonth() + 1;
	
	
	if(dtCheckOut.getDate().toString().length < 2)
		strCheckOutDD = "0"+dtCheckOut.getDate();
	else
		strCheckOutDD = dtCheckOut.getDate();
		
	strCheckOut = strCheckOutYYYY + "-" + strCheckOutMM + "-" + strCheckOutDD	
	
	var tempSolar = strCheckOut.split("-");
	dtCheckOut =  new Date(tempSolar[0],Number(tempSolar[1])-1,tempSolar[2])
	var checkDay;

	switch(dtCheckOut.getDay())
	{
		case 0:
		{
			checkDay = "(일)";
			break;
		}
		case 1:
		{
			checkDay = "(월)";		
			break;
		}		
		case 2:
		{
			checkDay = "(화)";				
			break;
		}		
		case 3:
		{
			checkDay = "(수)";				
			break;
		}		
		case 4:
		{
			checkDay = "(목)";					
			break;
		}		
		case 5:
		{
			checkDay = "(금)";							
			break;
		}		
		case 6:
		{
			checkDay = "(토)";			
			break;
		}		
	}
	
	if(strCheckOut.length>0 && f.ddlDuration[f.ddlDuration.selectedIndex].value !="")
	{
		f.txtCheckOutDate.value = strCheckOut;
		f.txtCheckOutDateShow.value = strCheckOut + checkDay;
	}
	if(f.ddlDuration[f.ddlDuration.selectedIndex].value =="")
	{
		f.txtCheckOutDate.value = "";
		f.txtCheckOutDateShow.value = "";
	}	
}

function ChangeRoomCount(obj)
{
	ffrm = document.aspnetForm;
	
	var roomCnt = 0;

	var single = ffrm.SingleRoomCount.options[ffrm.SingleRoomCount.selectedIndex].value;
	var double = ffrm.DoubleRoomCount.options[ffrm.DoubleRoomCount.selectedIndex].value;
	var twin   = ffrm.TwinRoomCount.options[ffrm.TwinRoomCount.selectedIndex].value;
	var triple = ffrm.TripleRoomCount.options[ffrm.TripleRoomCount.selectedIndex].value;
	
	roomCnt = parseInt(single) + parseInt(double) + parseInt(twin) + parseInt(triple);

	//2011-06-15 3개에서 5개로 변경
	if( roomCnt > 5)
	{
		alert("객실 수는 모두 합하여 5개까지입니다. ");
		eval(obj).selectedIndex = 0;
		return false;
	}
	else
	{
		ffrm.txtClickType.value = 'A';
	}
}


function ClickSearchList()
{
	ffrm = document.aspnetForm;

	if (ffrm.txtCityCode.value == "")
	{
		alert("\n도시코드를 입력하세요.");
		ffrm.txtCityCode.focus();
		return;
	}
	if (ffrm.txtCheckInDateShow.value == "")
	{
		alert("\n체크인 날짜를 입력해 주세요.");
		ffrm.txtCheckInDateShow.focus();
		return;
	}
	if (ffrm.txtCheckOutDateShow.value == "")
	{
		alert("\n체크아웃 날짜를 입력해 주세요.");
		ffrm.txtCheckOutDateShow.focus();
		return;
	}

	if (ffrm.CityCode.value == "")		
	{
		alert("도시검색을 다시 선택하세요");
		ffrm.txtCityCode.focus();
		return;
	}

	var single = ffrm.SingleRoomCount.value;
	var double = ffrm.DoubleRoomCount.value;
	var twin   = ffrm.TwinRoomCount.value;
	var triple = ffrm.TripleRoomCount.value;

	if ( (single=='0')&&(double=='0')&&(twin=='0')&&(triple=='0') )
	{
		alert("\n1개이상의 객실타입 선택은 필수입니다.");
		ffrm.SingleRoomCount.focus();
		return;
	}

	if ( (single!='0')&&(double!='0')&&(twin!='0')&&(triple!='0') )
	{
		alert("\n호텔 검색 시 객실 타입은 3가지만 선택 가능합니다.\n3가지 객실 타입만 다시 선택하신 후 검색 해 주세요.");
		ffrm.SingleRoomCount.focus();
		return;
	}

	ffrm.txtClickType.value = 'B';

	var Duration = ffrm.ddlDuration.options[ffrm.ddlDuration.selectedIndex].value;

	single = ffrm.SingleRoomCount.options[ffrm.SingleRoomCount.selectedIndex].value;
	double = ffrm.DoubleRoomCount.options[ffrm.DoubleRoomCount.selectedIndex].value;
	twin   = ffrm.TwinRoomCount.options[ffrm.TwinRoomCount.selectedIndex].value;
	triple = ffrm.TripleRoomCount.options[ffrm.TripleRoomCount.selectedIndex].value;

	var BedTypeCode1 = '';
	var BedTypeCode2 = ''; 
	var BedTypeCode3 = '';
	var RoomCount1 = 0;
	var RoomCount2 = 0;
	var RoomCount3 = 0;

	if(single != '0') //싱글 있다면
	{
		BedTypeCode1 = 'BED01';
		RoomCount1 = single;
		if(double != '0') //더블 있다면
		{
			BedTypeCode2 = 'BED03';
			RoomCount2 = double;

			if(twin != '0') //싱글있고 더블있고 트윈 있다면
			{
				BedTypeCode3 = 'BED02';
				RoomCount3 = twin;
			}
			else if(triple != '0')
			{
				BedTypeCode3 = 'BED04';
				RoomCount3 = triple;
			}
		}
		else if(twin != '0') //싱글있고 더블없고 트윈 있다면
		{
			BedTypeCode2 = 'BED02';
			RoomCount2 = twin;

			if(triple != '0')	//싱글/더블있고 트리플 있다면
			{
				BedTypeCode3 = 'BED04';
				RoomCount3 = triple;
			}
		}
		else if(triple != '0') //싱글있고 더블/트윈없고 트리플 있다면
		{
			BedTypeCode2 = 'BED04';
			RoomCount2 = triple;				
		}
	}

	else if(double != '0') //싱글없고 더블있다면
	{
		BedTypeCode1 = 'BED03';
		RoomCount1 = double;
		if(twin != '0')		//싱글없고 더블있고 트윈있다면
		{
			BedTypeCode2 = 'BED02';
			RoomCount2 = twin;
			if(triple != '0')	//싱글없고 더블/트윈있고 트리플 있다면
			{
				BedTypeCode3 = 'BED04';
				RoomCount3 = triple;				
			}
		}
		else if(triple != '0')	//싱글없고 더블있고 트윈없고 트리플 있다면
		{
			BedTypeCode2 = 'BED04';
			RoomCount2 = triple;				
		}
	}
	else if(twin != '0') //싱글/더블없고 트윈있다면
	{
		BedTypeCode1 = 'BED02';
		RoomCount1 = twin;
		if(triple != '0')	//싱글/더블없고 트윈있고 트리플 있다면
		{
			BedTypeCode2 = 'BED04';
			RoomCount2 = triple;				
		}
	}
	else if(triple != '0')  //싱글/더블/트윈 없고 트리플 있다면
	{
		BedTypeCode1 = 'BED04';
		RoomCount1 = triple;				
	}

	var ChildAge1 = "0";
	var ChildAge2 = "0";
	var ChildAge3 = "0";


	var CityCode		 = ffrm.CityCode.value;
	var CheckInDate		 = ffrm.txtCheckInDate.value;
	var CheckInDateShow  = ffrm.txtCheckInDateShow.value;
	var CheckOutDateShow = ffrm.txtCheckOutDateShow.value;
	var CheckOutDate	 = ffrm.txtCheckOutDate.value;
	
	
	/* 2008-04-07 다시 추가 */
	var HotelName = parent.ffrm.txtHotelName.value;
	/*
	var HotelName = '';
	var StarRating = '';
	var LocationCode = '';
	*/

	//Google flash event 추적
	pageTracker._trackPageview('/HotelSearchBox/MainPage');
	
	//location.href = "/ASPX/Common/Loading.aspx?page=HotelProducts/HotelSearchResult.aspx&LoadingMsgID=HotelSearchMsg&CityCode=" + CityCode + "&ItemName=" + HotelName + "&StarRating=&LocationCode=&BedTypeCode1=" + BedTypeCode1 + "&RoomCount1=" + RoomCount1 + "&ChildAge1=" + ChildAge1 + "&BedTypeCode2=" + BedTypeCode2 + "&RoomCount2=" + RoomCount2 + "&ChildAge2=" + ChildAge2 + "&BedTypeCode3=" + BedTypeCode3 + "&RoomCount3=" + RoomCount3 + "&ChildAge3=" + ChildAge3 + "&Duration=" + Duration + "&CheckInDate=" + CheckInDate + "&CheckInDateShow=" + escape(CheckInDateShow) + "&CheckOutDate=" + CheckOutDate + "&CheckOutDateShow=" + escape(CheckOutDateShow);
	location.href = "/Common/Loading.aspx?page=Hotel/HotelSearchResult.aspx&LoadingMsgID=HotelSearchMsg&CityCode=" + CityCode + "&ItemName=" + HotelName + "&StarRating=&LocationCode=&BedTypeCode1=" + BedTypeCode1 + "&RoomCount1=" + RoomCount1 + "&ChildAge1=" + ChildAge1 + "&BedTypeCode2=" + BedTypeCode2 + "&RoomCount2=" + RoomCount2 + "&ChildAge2=" + ChildAge2 + "&BedTypeCode3=" + BedTypeCode3 + "&RoomCount3=" + RoomCount3 + "&ChildAge3=" + ChildAge3 + "&Duration=" + Duration + "&CheckInDate=" + CheckInDate + "&CheckInDateShow=" + escape(CheckInDateShow) + "&CheckOutDate=" + CheckOutDate + "&CheckOutDateShow=" + escape(CheckOutDateShow) + "&txtCityCode=" + encodeURI(ffrm.txtCityCode_Value.value);
}



function IMG_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
//mouseout
function IMG_swapImgRestore()
{ //v3.0
  var i,x,a=document.MM_sr; 
  for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) 
  {
	if(x.value != "1" )
	  {
		x.src=x.oSrc;
	  }
  }
}

function IMG_findObj(n, d) { //v4.01
  var p,i,x;  
  if(!d) d=document; 
  if((p=n.indexOf("?"))>0&&parent.frames.length)
  {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
  }
  
  if(!(x=d[n])&&d.all) 
	x=d.all[n];

  for (i=0;!x&&i<d.forms.length;i++) 
	x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) 
	x=IMG_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) 
	x=d.getElementById(n); return x;
}

function IMG_swapImage() { //v3.0
  var i,j=0,x,a=IMG_swapImage.arguments; 
  document.MM_sr=new Array; 

  for(i=0;i<(a.length-2);i+=3)
  {
   if ((x=IMG_findObj(a[i]))!=null)
   {
		document.MM_sr[j++]=x; 
		if(!x.oSrc) 
			x.oSrc=x.src; 
		x.src=a[i+2];
	}
   }
}

function Select_IMG_BestEurail(obj)
{
	var x,arrBestEurail = new Array('pass','ptp');
	for (i=0; i<arrBestEurail.length; i++)
	{
		if((x=$('BestEurail_' + arrBestEurail[i]))!=null)
		{
			x.src = "/_images/Common/" + x.id + "_off.gif";
			x.value="0";
			$('div_BestEurail_'+arrBestEurail[i]).style.display="none";
		}
	}

	if((x=$(obj.id))!=null)
	{
		x.src = "/_images/Common/" +obj.id +"_on.gif";
		x.value="1"; 
		$('div_'+obj.id).style.display="block";
	}
}


function Select_IMG_BestHotel(obj)
{
	var x,arrBestHotel = new Array('jp', 'ch', 'as', 'eu', 'us', 'oa');
	for (i=0; i<arrBestHotel.length; i++)
	{
		if((x=$('BestHotel_' + arrBestHotel[i]))!=null)
		{
			x.src = "/_images/Common/" + x.id + "_off.gif";
			x.value="0";
			$("div_LowpriceHotel_"+arrBestHotel[i]).style.display = "none";
			$("div_SpecialHotel_"+arrBestHotel[i]).style.display = "none";
		}
	}

	if((x=$(obj.id))!=null)
	{
		x.src = "/_images/Common/" +obj.id +"_on.gif"; 
		x.value="1"; 
		$("div_LowpriceHotel_"+obj.id.split('_')[1]).style.display = "block";
	}
}

function Select_IMG_SubHotel(obj)
{
	var subName = obj.id.split('_');
	
	$("div_LowpriceHotel_"+subName[2]).style.display = ((subName[1]=="LowpriceHotel") ? "block" : "none");
	$("div_SpecialHotel_"+subName[2]).style.display = ((subName[1]=="SpecialHotel") ? "block" : "none");

}

function Select_IMG_RecommendHotel(obj)
{
	var arrRecommendHotel = new Array('Asia','Usa','Europe','Oceania','China','Japan');
    
	for (i=0; i<arrRecommendHotel.length; i++)
	{
		$("rdo" + arrRecommendHotel[i]).style.display = "none";
	}

	var top = getAbsTopPostMap($("shbox"));
	var left = getAbsLeftPostMap($("shbox"));


	$("topimg").src="/_images/Common/recomm_searchtitle_"+obj+".gif";
						

	var rdo = $("rdo" + obj);
	var box = $("seach_box");

	rdo.style.display = "block";
	box.style.display = "block"
	box.style.left = left - 500 + "px";
	box.style.top = top + 50 + "px";
}

function ClickClose()
{
	$('seach_box').style.display='none';
}
function rdoSearch(CityCode)
{
	$("CityCode").value = CityCode;
}

function sltBedType(BedTypeCode)
{
	$("BedTypeCode1").value = BedTypeCode;
}

function ClickSearch_Main()
{
	var CityCode = $("CityCode").value;
	var ContinentCode = $("ContinentCode").value;
	var RecommendType = $("RecommendType").value;
	var BedTypeCode1 = $("ddlBedTypeCode1_picks").value;
	var CheckInDate = $("txtCheckInDate_picks").value;
	var CheckInDateShow = $("txtCheckInDateShow_picks").value;
	var CheckOutDate = $("txtCheckOutDate_picks").value;
	var CheckOutDateShow = $("txtCheckOutDateShow_picks").value;
	var Sort = "1";

	//location.href = "/ASPX/Common/Loading.aspx?page=" + "HotelProducts/RecommendHotelList.aspx&LoadingMsgID=HotelSearchMsg&CityCode=" + CityCode + "&RecommendType=" + RecommendType + "&ContinentCode=" + ContinentCode + "&BedTypeCode1=" + BedTypeCode1 + "&RoomCount1=1&ChildAge1=&BedTypeCode2=&RoomCount2=&ChildAge2=&BedTypeCode3=&RoomCount3=&ChildAge3=&Duration=1&CheckInDate=" + CheckInDate + "&CheckInDateShow=" + escape(CheckInDateShow) + "&CheckOutDate=" + CheckOutDate + "&CheckOutDateShow=" + escape(CheckOutDateShow) + "&ReCommendOnly=false&AvailableOnly=false&Sort=" + Sort;
	location.href = "/Common/Loading.aspx?page=" + "Hotel/RecommendHotelList.aspx&LoadingMsgID=HotelSearchMsg&CityCode=" + CityCode + "&RecommendType=" + RecommendType + "&ContinentCode=" + ContinentCode + "&BedTypeCode1=" + BedTypeCode1 + "&RoomCount1=1&ChildAge1=&BedTypeCode2=&RoomCount2=&ChildAge2=&BedTypeCode3=&RoomCount3=&ChildAge3=&Duration=1&CheckInDate=" + CheckInDate + "&CheckInDateShow=" + escape(CheckInDateShow) + "&CheckOutDate=" + CheckOutDate + "&CheckOutDateShow=" + escape(CheckOutDateShow) + "&ReCommendOnly=false&AvailableOnly=false&Sort=" + Sort;
}


function getAbsLeftPostMap(obj) 
{
	return (obj.offsetParent==null)? 0:obj.offsetLeft + getAbsLeftPostMap(obj.offsetParent);
}
function getAbsTopPostMap(obj) 
{
	return (obj.offsetParent==null)? 0:obj.offsetTop + getAbsTopPostMap(obj.offsetParent);
}


// 추천호텔로 이동
function GoRecommendHotel(ItemCode, CityCode)
{
	// 2008-12-16 Layer Open으로 변경
	
	location.href  = "/Common/Loading.aspx?page=Hotel/HotelInformation.aspx&ItemCode=" + ItemCode + "&CityCode=" + CityCode + "&ItemNo=0&CheckInDate=&SearchType=URL_SEARCH&LoadingMsgID=SmallLoadingMsg;	//&IframeUseYN=Y";
	//var Url = "/Common/Loading.aspx?page=Hotel/HotelInformation.aspx&ItemCode=" + ItemCode + "&CityCode=" + CityCode + "&ItemNo=0&CheckInDate=&SearchType=URL_SEARCH&LoadingMsgID=SmallLoadingMsg&IframeUseYN=Y";	

	//Layer.Open(div_layer, Url);					//	레이어 오픈
}


function DocumentWrite(src) {
    document.write(src);
}

function MakeFlashString(source, id, width, height, name, wmode, ScriptAccess, otherParam) {
    return "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,22,0\" width=" + width + " height=" + height + " id=" + id + " name=" + name + "><param name=wmode value=" + wmode + " /><param name=movie value=" + source + " /><param name=quality value=high />" + otherParam + "<embed src=" + source + " quality=high wmode=" + wmode + " allowScriptAccess=" + ScriptAccess + " type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?p1_prod_version=shockwaveflash\" width=" + width + " height=" + height + "></embed></object>";
}


function MainBanner(strSWF, width, height) {
    DocumentWrite(MakeFlashString('/_Images/Main/' + strSWF + '.swf', 'banner', width, height, 'banner', 'transparent', 'always', '<param name=FlashVars VALUE="move_on=1&xpos=-100&ypos=-100"/><param name="allowScriptAccess" value="always" />'));

    //var aa = '';
    //aa += '<img src="/_Images/banner/banner.gif" align="absmiddle" border="0">';
    //document.write(aa);
}

function FlashBanner(strSWF, width, height) {
    DocumentWrite(MakeFlashString('/_Flash/Banner/' + strSWF + '.swf', 'banner', width, height, 'banner', 'transparent', 'always', '<param name=FlashVars VALUE="move_on=1&xpos=-100&ypos=-100"/><param name="allowScriptAccess" value="always" />'));
}

function MainEventBenner(url) {
    //alert(url);
    location.href = url;
}

function LayerPopClose()
{

	var pop = document.getElementById("LayPop");
	pop.style.display = "none";

}

