
//È£ÅÚ °Ë»ö °ü·Ã ÇÔ¼ö ½ÃÀÛ

function search_city()
{
	hotel_hidden_calendar();
	
	if(document.getElementById("div_hotel_city_view").style.display=='block')
	{
		document.getElementById("div_hotel_city_view").style.display = 'none';
		document.getElementById("selGradeCode").style.display = '';
		
		return;
	}

	document.getElementById("div_hotel_city_view").style.display = 'block';
	document.getElementById("selGradeCode").style.display = 'none';
	return;
}

function hotel_hideiframe()
{
	document.getElementById("div_hotel_city_view").style.display = 'none';
	return;
}

function hotel_sendit()
{
	if(document.formSearchHotel.txtDestCityName.value == "")
	{
		alert("\n¼÷¹ÚÇÒ µµ½Ã¸¦ ´Ù½Ã °Ë»öÇÏ¼¼¿ä");
		formSearchHotel.txtDestCityName.focus();
		return;
	}
	if (document.formSearchHotel.city_code.value=="")
	{
		alert("\n¼÷¹ÚÇÒ µµ½Ã¸¦ ¼±ÅÃÇØ ÁÖ¼¼¿ä.");
		document.formSearchHotel.txtDestCityName.focus();
		return;
	}
	if (document.formSearchHotel.SDate.value=="")
	{
		alert("\nÃ¼Å©ÀÎ ³¯Â¥¸¦ ÀÔ·ÂÇØ ÁÖ¼¼¿ä.");
		document.formSearchHotel.SDate.focus();
		return;
	}
	if (document.formSearchHotel.EDate.value=="")
	{
		alert("\nÃ¼Å©¾Æ¿ô ³¯Â¥¸¦ ÀÔ·ÂÇØ ÁÖ¼¼¿ä.");
		document.formSearchHotel.EDate.focus();
		return;
	}
	if (document.formSearchHotel.selBedTypeCode1.value=="")
	{
		alert("\n1°³ÀÌ»óÀÇ °´½ÇÅ¸ÀÔ ¼±ÅÃÀº ÇÊ¼öÀÔ´Ï´Ù.");
		document.formSearchHotel.selBedTypeCode1.focus();
		return;
	}
	if(document.formSearchHotel.selRoomCount1.value != '')
	{
		if (document.formSearchHotel.selRoomCount1.value=="0")
		{
			alert("\n1¹øÂ° °´½ÇÀÇ ¹æ °¹¼ö¸¦ ¼±ÅÃÇÏ¼¼¿ä.");
			document.formSearchHotel.selRoomCount1.focus();
			return;
		}
	}	

	var sReturnUrl;
	
	sReturnUrl = "http://rts.gmarket.co.kr/ASPX/Common/Loading.aspx?page=HotelProducts/HotelSearchResult.aspx&LoadingMsgID=HotelSearchMsg"
	
	sReturnUrl = sReturnUrl + "&CityCode=" + document.formSearchHotel.city_code.value;
	
	sReturnUrl = sReturnUrl + "&ItemName=" + encodeURIComponent(document.formSearchHotel.txtHotelName.value);
	sReturnUrl = sReturnUrl + "&StarRating=" + document.formSearchHotel.selGradeCode.value;
	
	sReturnUrl = sReturnUrl + "&BedTypeCode1=" + document.formSearchHotel.selBedTypeCode1.value;
	sReturnUrl = sReturnUrl + "&RoomCount1=" + document.formSearchHotel.selRoomCount1.value;
//	sReturnUrl = sReturnUrl + "&BedTypeCode2=" + document.formSearchHotel.selBedTypeCode2.value;
//	sReturnUrl = sReturnUrl + "&RoomCount2=" + document.formSearchHotel.selRoomCount2.value;
//	sReturnUrl = sReturnUrl + "&BedTypeCode3=" + document.formSearchHotel.selBedTypeCode3.value;
//	sReturnUrl = sReturnUrl + "&RoomCount3=" + document.formSearchHotel.selRoomCount3.value;
	sReturnUrl = sReturnUrl + "&Duration=" + document.formSearchHotel.selDuration.value;
	sReturnUrl = sReturnUrl + "&CheckInDate=" + document.formSearchHotel.SDate.value;
	sReturnUrl = sReturnUrl + "&CheckOutDate=" + document.formSearchHotel.EDate.value;
	sReturnUrl = sReturnUrl + "&sid=gma01-01";

	document.frmhotel_sendit.returnurl.value = sReturnUrl;
	document.frmhotel_sendit.action = "http://www.gmarket.co.kr/challenge/neo_reservation/hotel_reservation_detail.asp";
	document.frmhotel_sendit.target = "_blank";
	document.frmhotel_sendit.submit();
}

function hotel_hidden_calendar()
{
	document.formSearchHotel.selBedTypeCode1.style.visibility="";
	document.formSearchHotel.selRoomCount1.style.visibility="";
	document.formSearchHotel.selBedTypeCode2.style.visibility="";
	document.formSearchHotel.selBedTypeCode3.style.visibility="";
	document.formSearchHotel.selRoomCount3.style.visibility="";
    
	if(div_hotel_calendar_tab_view.style.display=="")
    {
        div_hotel_calendar_tab_view.style.display = "none";
	}
}
                     
function hotel_setValueOfSelectedDate(sSelectedDate,type)
{
	var endDate = new Date();
	var sDate = sSelectedDate;
	var sAddDay;
	
	document.formSearchHotel.SDate.value = sDate.substring(0, 4) + "-" + sDate.substring(4, 6) + "-" + sDate.substring(6, 8);
	document.getElementById("selGradeCode").style.display = '';
	hotel_chg_duration();
	
    hotel_hidden_calendar();
}

function hotel_div_mov(val)
{   
	document.getElementById("div_hotel_city_view").style.display = 'none';
	
    if (div_hotel_calendar_tab_view.style.display == "none")
    {
		div_hotel_calendar_tab_view.style.display = "";
		
		document.formSearchHotel.selBedTypeCode1.style.visibility="hidden";
		document.formSearchHotel.selRoomCount1.style.visibility="hidden";
		document.formSearchHotel.selBedTypeCode2.style.visibility="hidden";
		//document.formSearchHotel.selRoomCount2.style.visibility="hidden";
		document.formSearchHotel.selBedTypeCode3.style.visibility="hidden";
		document.formSearchHotel.selRoomCount3.style.visibility="hidden";
	}
	else
	{
		div_hotel_calendar_tab_view.style.display = "none";
	  
		document.formSearchHotel.selBedTypeCode1.style.visibility="";
		document.formSearchHotel.selRoomCount1.style.visibility="";
		document.formSearchHotel.selBedTypeCode2.style.visibility="";
		//document.formSearchHotel.selRoomCount2.style.visibility="";
		document.formSearchHotel.selBedTypeCode3.style.visibility="";
		document.formSearchHotel.selRoomCount3.style.visibility="";
	}
	
//	hotel_hideiframe();
	
	return;
}

function hotel_chg_duration()
{
	if( document.formSearchHotel.SDate.value == "" )
	{
		alert("Ã¼Å©ÀÎ ³¯Â¥¸¦ ¼±ÅÃÇØ ÁÖ½Ê½Ã¿À.");
	}
	else
	{		
		var endDate;
		var sDate;
		var sAddDay;
		var sYear, sMonth, sDay;
	
		sDate = document.formSearchHotel.SDate.value;
		
		sAddDay = document.formSearchHotel.selDuration.value;
		
		endDate = addDay(sDate.substring(0, 4), sDate.substring(5, 7), sDate.substring(8, 10), parseInt(sAddDay));
		
		if( endDate.getDate() < sDate.substring(8, 10) ) 
		{
			addMonth(endDate.getFullYear(), endDate.getMonth(), endDate.getDate(), 1);
		}
		
		sYear = endDate.getFullYear();
		sMonth = endDate.getMonth() + 1 ;
		sMonth = (sMonth < 10 ? "0"+sMonth : sMonth);
		sDay = endDate.getDate();
		sDay = (sDay < 10 ? "0"+sDay : sDay);
		
		document.formSearchHotel.EDate.value = sYear + "-" + sMonth + "-" + sDay;
	}
}

//È£ÅÚ °Ë»ö °ü·Ã ÇÔ¼ö ³¡

function addDay(yyyy, mm, dd, pDay) // ³â, ¿ù, ÀÏ, °è»êÇÒ ÀÏÀÚ (³âµµ´Â ¹Ýµå½Ã 4ÀÚ¸®·Î ÀÔ·Â)
{
	var oDate; // ¸®ÅÏÇÒ ³¯Â¥ °´Ã¼ ¼±¾ð

	dd = dd*1 + pDay*1; // ³¯Â¥ °è»ê

	mm--; // ¿ùÀº 0~11 ÀÌ¹Ç·Î ÇÏ³ª »©ÁØ´Ù

	oDate = new Date(yyyy, mm, dd) // °è»êµÈ ³¯Â¥ °´Ã¼ »ý¼º (°´Ã¼¿¡¼­ ÀÚµ¿ °è»ê)

	return oDate;
}

function addMonth(yyyy, mm, dd, pMonth) // ³â, ¿ù, ÀÏ, °è»êÇÒ ¿ù (³âµµ´Â ¹Ýµå½Ã 4ÀÚ¸®·Î ÀÔ·Â)
{
	var cDate; // °è»ê¿¡ »ç¿ëÇÒ ³¯Â¥ °´Ã¼ ¼±¾ð

	var oDate; // ¸®ÅÏÇÒ ³¯Â¥ °´Ã¼ ¼±¾ð

	var cYear, cMonth, cDay // °è»êµÈ ³¯Â¥°ªÀÌ ÇÒ´çµÉ º¯¼ö

	mm = mm*1 + ((pMonth*1)-1); // ¿ùÀº 0~11 ÀÌ¹Ç·Î ÇÏ³ª »©ÁØ´Ù

	cDate = new Date(yyyy, mm, dd) // °è»êµÈ ³¯Â¥ °´Ã¼ »ý¼º (°´Ã¼¿¡¼­ ÀÚµ¿ °è»ê)

	cYear = cDate.getFullYear(); // °è»êµÈ ³âµµ ÇÒ´ç

	cMonth = cDate.getMonth(); // °è»êµÈ ¿ù ÇÒ´ç

	cDay = cDate.getDate(); // °è»êµÈ ÀÏÀÚ ÇÒ´ç

	oDate = (dd == cDay) ? cDate : new Date(cYear, cMonth, 0); // ³Ñ¾î°£ ¿ùÀÇ Ã¹Â¶³¯ ¿¡¼­ ÇÏ·ç¸¦ »« ³¯Â¥ °´Ã¼¸¦ »ý¼ºÇÑ´Ù.

	return oDate;
}

