var httphrefShort = location.href;
httphrefShort = httphrefShort.replace("http://", "");
var arrhttphrefShort = httphrefShort.split("/");
httphrefShort = "http://" + arrhttphrefShort[0];

var pathwebcheckavailabilityShort = httphrefShort + '/reserve/indexShort.php';
var ckAvailStartTdyShort = new Date();
//remove time from Date
ckAvailStartTdyShort = new Date(ckAvailStartTdyShort.getFullYear(),  ckAvailStartTdyShort.getMonth(), ckAvailStartTdyShort.getDate());
var ckAvailStartDateShort = new Date(ckAvailStartTdyShort.getFullYear(),  ckAvailStartTdyShort.getMonth(), ckAvailStartTdyShort.getDate() + 2);

var tmpQuickFormName = "";
function getElcheckavailabilityShort(tmpname) {
	return document.forms[tmpQuickFormName].elements[tmpname];
}

function setElementShort(cElement,cValue)
{
	for(var i=0;i<cElement.length;i++)
	{
		if(cElement.options[i].value==cValue)
		{
			cElement.selectedIndex = i;
			break;
		}
	}
	if(i==cElement.length) {
		if(ddd<=2) setDefDateShort();
		return false;
	}
}

function padZero(num) {
	return (num< 10) ? '0' + num : num ;
}

function createlistYearShort(formname) {
	tmpQuickFormName = formname;
	var cForm = document.forms[formname];
	var a = cForm.elements['checkHotel[sMonth2]'];
	a.length = 0;

	var tmptoday = new Date();
	var sMonth = tmptoday.getMonth() + 1;
	var sYear = tmptoday.getFullYear();
	var i = 0;
	var arrmonth;

	var lang = cForm.elements['checkHotel[LanguageCode]'].value;
	if(lang=="ja") arrmonth = new Array("", "1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月");
	else arrmonth = new Array("", "Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
	for(i=0;i<=17;i++) {
		sYearShow = String(sYear).substring(2,4);
		a.options[i]=new Option(arrmonth[sMonth] +' ' + sYearShow, padZero(sMonth)+'/'+sYear);
		sMonth = sMonth + 1;
		if(sMonth>=13) {
			sMonth = 1;
			sYear = sYear + 1;
		}
	}
}

var ddd = 0;
function setDefDateShort(formname) {
	ddd = ddd + 1;
	setAllDate(ChDatetoStr(ckAvailStartDateShort));
}

function ChDatetoStr(cDate) {
	return padZero(cDate.getDate()) + '/' + padZero(cDate.getMonth() + 1) + '/' + cDate.getFullYear();
}

function ChStrtoDate(cDate) {
	var arrcDate = cDate.split("/");
	return new Date(arrcDate[2], Number(arrcDate[1])-1, Number(arrcDate[0]));
}

function setAllDate(cDate) {
	var arrtmptoday = cDate.split("/");
	var a = getElcheckavailabilityShort('txtCheck_InShort');
	a.value = cDate;
	
	var b = getElcheckavailabilityShort('checkHotel[sMonth2]');
	setElementShort(b, arrtmptoday[1]+'/'+arrtmptoday[2]);
	var b = getElcheckavailabilityShort('checkHotel[sYear]');
	b.value = arrtmptoday[2];
	var b = getElcheckavailabilityShort('checkHotel[sMonth]');
	b.value = arrtmptoday[1];
	var b = getElcheckavailabilityShort('checkHotel[sDay]');
	setElementShort(b, arrtmptoday[0]);

	var tmpnextday = ChStrtoDate(cDate);
	var cElement =  getElcheckavailabilityShort('checkHotel[Nights]');
	var Nights = cElement[cElement.selectedIndex].value;
	tmpnextday.setDate(tmpnextday.getDate()+Number(Nights));
	tmpnextday = ChDatetoStr(tmpnextday);
	var arrtmpnextday = tmpnextday.split("/");

	var a = getElcheckavailabilityShort('txtCheck_OutShort');
	a.value = tmpnextday;
	var b = getElcheckavailabilityShort('checkHotel[eYear]');
	b.value = arrtmpnextday[2];
	var b = getElcheckavailabilityShort('checkHotel[eMonth]');
	b.value = arrtmpnextday[1];
	var b = getElcheckavailabilityShort('checkHotel[eDay]');
	b.value = arrtmpnextday[0];
}

function updateCheckAvailAllShort(column, frommonth)
{
	var cForm = document.forms[tmpQuickFormName];
	var cDate = ckAvailStartTdyShort;
	
	updateCheckAvailDoShort(column,cForm,cDate, frommonth);
	setAllDate(getElcheckavailabilityShort('txtCheck_InShort').value);
}

function getDateShort(cForm,InOut)
{
	var cElement = cForm.elements['checkHotel[sDay]'];
	var sDay = cElement[cElement.selectedIndex].value;
	var cElement = cForm.elements['checkHotel[sMonth2]'];
	var tmpMonth = cElement[cElement.selectedIndex].value;

	tmpMonth = tmpMonth.split("/");
	sMonth = tmpMonth[0];
	sYear = tmpMonth[1];

	var cDate = new Date(sYear, Number(sMonth)-1, Number(sDay));
	return(cDate);
}

function updateCheckAvailDoShort(column,cForm,cDate, frommonth)
{
	var sDate  = getDateShort(cForm,0);
	if(sDate.getTime()<cDate.getTime())
	{
		var nextMonthDate;
		if(typeof(frommonth)=="undefined") {
			nextMonthDate = new Date(sDate.getFullYear(),  sDate.getMonth() + 1, sDate.getDate());
			if(nextMonthDate.getTime()<cDate.getTime()) nextMonthDate = cDate;
		} else {
			nextMonthDate = cDate;
		}
		getElcheckavailabilityShort('txtCheck_InShort').value = ChDatetoStr(nextMonthDate);
	} 
	else
	{
		getElcheckavailabilityShort('txtCheck_InShort').value = ChDatetoStr(sDate);
	}
}


