﻿/* stubs for old functions, so the form needn't be changed much */
function hhotelFormUpdateHotelnames(myForm)
{

}

function hhotelDispoprice(form)
{
	goCheck(form);
}

function hhotelFormCancel(form)
{
	goCancel(form);
}
/* end stubs */

/* new functions */
function zeroPad(i)
{
	i += '';
	if (i.length < 2) 
	{
		i = '0' + i;
	}
	return i;
}

function transformDate(day, month, year)
{
	return year + '-' + zeroPad(month) + '-' + zeroPad(day);
}

function transformHotel(name)
{
	switch (name)
	{
		case 'UKHazlittsh':
			return 'hazlitts-london';
		case 'UKTRookery':
			return 'therookery-london';
		default:
			return 'hazlitts-london';
	}
}

function goCheck(form)
{
	var hotelName = form.HotelList[form.HotelList.selectedIndex].value;
	
	var d = form.fromday[form.fromday.selectedIndex].value;
	var m = form.frommonth[form.frommonth.selectedIndex].value;
	var y = form.fromyear[form.fromyear.selectedIndex].value;
	
	var len = form.nbdays[form.nbdays.selectedIndex].value;

	var url = 'https://reservations.g-rez.com/' + transformHotel(hotelName) + '/en/' + transformDate(d, m, y) + '/' + len;
	
	submitForm(url);
}

function goCancel(form)
{
	var hl = form.HotelList;
	var hotelName = hl[hl.selectedIndex].value;
	submitForm('https://reservations.g-rez.com/amend/' + transformHotel(hotelName) + '/en/');
}

function submitForm(url)
{
	//if (confirm(url)) 
	//{
		window.location.href = url;
		//window.open(url,"search","toolbar=no,width=800,height=550,menubar=no,scrollbars=yes,resizable=yes,alwaysRaised=yes");
	//}
}