
function createHotel(country,code,name,submitForm,mode)
{
	var o = new Object();
	o.country = country;
	o.code = code;
	o.name = name;
	o.submitForm = submitForm;
	o.mode = mode;
	
	return o;
}

var hotels = new Array();
hotels[0] = createHotel("United Kingdom","LGWUK","Crowne Plaza Gatwick-Crawley","LGWUKForm","ICH");
hotels[1] = createHotel("Portugal","CRHGA","The Hotel Garbe","HBNForm","HBN");
hotels[2] = createHotel("Dubai","CRCTD","Chelsea Tower","HBNForm","HBN");
hotels[3] = createHotel("Portugal","CRHCA","Hotel Carvoeiro Sol","HBNForm","HBN");
hotels[4] = createHotel("United Kingdom","CRQHH","Quality Hotel Heathrow","HBNForm","HBN");
hotels[5] = createHotel("United Kingdom","CRCLHR","Comfort Hotel Heathrow","HBNForm","HBN");
hotels[6] = createHotel("United Kingdom","CRCHH","Comfort Hotel Harrow","HBNForm","HBN");
hotels[7] = createHotel("United Kingdom","XWOWK","Holiday Inn Woking","XWOWKForm","ICH");
hotels[8] = createHotel("Dubai","CGAHD","Chelsea Gardens Hotel Apartments","HBNForm","HBN");

function UpdateHotels()
{
	var cboCountries = document.getElementById('cboCountry');
	var cboHotels = document.getElementById('cboHotel');
	
	if(cboCountries==null || cboHotels==null){
		alert('Unable to update hotel list. Please visit the hotel you are interested in and try the quick reservation form from there');
		return;
	}
	
	for(var i=cboHotels.options.length-1; i>= 0; i--)
		cboHotels.remove(0);
		
	var country = cboCountries.options[cboCountries.selectedIndex].value;
	
	var newOption = document.createElement('option');
	newOption.setAttribute("value","");
	newOption.setAttribute("selected","true");
	newOption.appendChild(document.createTextNode("Select Hotel"));
	cboHotels.appendChild( newOption );	
	
	for(var i=0;i<hotels.length;i++)
	{
		if(hotels[i].country==country){
			var newOption = document.createElement('option');
			newOption.setAttribute("value",hotels[i].code);
			newOption.appendChild(document.createTextNode(hotels[i].name));
			cboHotels.appendChild( newOption );	
		}
	}
}

function Book()
{
	var cboCountries = document.getElementById('cboCountry');
	var cboHotels = document.getElementById('cboHotel');
	
	if(cboCountries==null || cboHotels==null){
		alert('Unable to get selected hotel. Please visit the hotel you are interested in and try the quick reservation form from there');
		return;
	}
	
	var hotelCode = cboHotels.options[cboHotels.selectedIndex].value;
	
	if(hotelCode=='')
	{
		alert('Please select a hotel');
		return;
	}
	
	for(var i=0;i<hotels.length;i++)
	{
		if(hotels[i].code==hotelCode)
		{
			switch(hotels[i].mode)
			{
				case 'ICH':
					ICHBook( hotels[i].submitForm );
				break;
				case 'HBN':
					HBNBook( hotels[i].submitForm , hotels[i].code);
				break;
				default:
					alert('Invalid Hotel Booking Mode On Group Website.\n\nSystem Error 101, Please call 01753 684001 and report website error');
					break;
			}
			
			return;
		}
	}
}

function HBNSetArrivalDate(form)
{
	//look for select boxes
	var valSet = 0;
	var elem = form.elements;
	var arvDt = new Array(2);
	for(var i = 0; i < elem.length; i++)
	{
		if(elem[i].type == 'select-one')
		{
			switch(elem[i].name)
			{
				case 'dtDay': if(elem[i].value==""){ LanguageAlert( 2 );return false;}else{ arvDt[0]=elem[i].value;valSet+=1;}break;
				case 'dtMonth': if(elem[i].value==""){ LanguageAlert( 3 );return false;}else{ arvDt[1]=elem[i].value;valSet+=1;}break;
				default:var selectName = elem[i].name; if(selectName.indexOf('dtYear')!=-1){arvDt[2]=elem[i].value;valSet+=1;}break;
			}
		}
	} 

	//set arrival date
	form.ArrivalDate.value = arvDt[0].toString() + '/' + arvDt[1].toString() + '/' + arvDt[2].toString();
	
	if(valSet>=3) return true; else return false;
}

function HBNBook(submitForm,hotelCode)
{
	var theform;
	var subForm;
	if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) 
	{
		theform = document.frmMain;
		subForm = document.forms[submitForm];
	}
	else 
	{
		theform = document.forms["frmMain"];
		subForm = document.forms[submitForm];
	}
	
	if(theform==null){
		LanguageAlert( 0 );
		return;
	}
	
	if(!HBNSetArrivalDate( theform ))
	{
		LanguageAlert( 1 );
		return;
	}
	
	subForm.ArrivalDate.value = theform.ArrivalDate.value;
	subForm.Nights.value = theform.Nights.value;
	subForm.Rooms.value = theform.Rooms.value;
	subForm.Adults.value = theform.Adults.value;
	subForm.Children.value = theform.Children.value;
	subForm.HCODE.value = hotelCode;
	
	subForm.target = "_blank";
	subForm.action = "https://www.hbnonline.co.uk/booking/loadDiv.aspx";
	subForm.method = "post";
	subForm.submit();
}

//SetArrivalDate - Validates Date Fields and add to ArrivalDate hidden field
function ICHSetArrivalDate(form)
{
	//look for select boxes
	var valSet = 0;
	var elem = form.elements;
	var arvDt = new Array(2);
	for(var i = 0; i < elem.length; i++)
	{
		if(elem[i].type == 'select-one')
		{
			switch(elem[i].name)
			{
				case 'dtDay': if(elem[i].value==""){ LanguageAlert( 2 );return false;}else{ arvDt[0]=elem[i].value;valSet+=1;}break;
				case 'dtMonth': if(elem[i].value==""){ LanguageAlert( 3 );return false;}else{ arvDt[1]=elem[i].value;valSet+=1;}break;
				default:var selectName = elem[i].name; if(selectName.indexOf('dtYear')!=-1){arvDt[2]=elem[i].value;valSet+=1;}break;
			}
		}
	} 

	//set arrival date
	//form.ArrivalDate.value = arvDt[0].toString() + '/' + arvDt[1].toString() + '/' + arvDt[2].toString();
	form.checkInDate.value = arvDt[0].toString();
	form.checkInMonthYear.value = (arvDt[1]-1).toString() + arvDt[2];
	
	//set checkout Date 
	var dtCheckOut;
	var dtCheckIn = new Date();
	
	dtCheckIn.setFullYear( arvDt[2] , arvDt[1]-1 , arvDt[0] );
		
	dtCheckOut = new Date(dtCheckIn.getTime() + (86400000 * form.Nights.value));
	
	form.checkOutDate.value = dtCheckOut.getDate().toString();
	form.checkOutMonthYear.value = dtCheckOut.getMonth().toString() + dtCheckOut.getFullYear().toString();
	
	if(valSet>=3) return true; else return false;
}

function ICHBook(submitForm)
{
	var theform;
	var subForm;
	if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) 
	{
		theform = document.frmMain;
		subForm = document.forms[submitForm];
	}
	else 
	{
		theform = document.forms["frmMain"];
		subForm = document.forms[submitForm];
	}
	
	if(theform==null){
		LanguageAlert( 0 );
		return;
	}
	
	if(!ICHSetArrivalDate( theform ))
	{
		LanguageAlert( 1 );
		return;
	}
	
	//subForm.ArrivalDate.value = theform.ArrivalDate.value;
	subForm.numOfNights.value = theform.Nights.value;
	subForm.rooms.value = theform.Rooms.value;
	subForm.adults.value = theform.Adults.value;
	subForm.children.value = theform.Children.value;
	subForm.checkInDate.value = theform.checkInDate.value;
	subForm.checkInMonthYear.value = theform.checkInMonthYear.value;
	subForm.checkOutDate.value = theform.checkOutDate.value;
	subForm.checkOutMonthYear.value = theform.checkOutMonthYear.value;
	
	/*
	alert("Check In " + subForm.checkInDate.value + " " + subForm.checkInMonthYear.value);
	alert("Check Out " + subForm.checkOutDate.value + " " + subForm.checkOutMonthYear.value);
	*/
	
	subForm.target = "_blank";
	subForm.method = "post";
	subForm.submit();
}


function encodeHtml(stringVal) 
{
     encodedHtml = escape(stringVal);
     encodedHtml = encodedHtml.replace(/\//g,"%2F");
     encodedHtml = encodedHtml.replace(/\?/g,"%3F");
     encodedHtml = encodedHtml.replace(/=/g,"%3D");
     encodedHtml = encodedHtml.replace(/&/g,"%26");
     encodedHtml = encodedHtml.replace(/@/g,"%40");
     return encodedHtml;
} 

function LanguageAlert( id )
{
	var langTxt = new Array();
		
	langTxt[0] = "Unable to show reservation window at this time. Please call our reservations department for more information.";
	langTxt[1] = "Unable to show reservation window at this time. Please check you have supplied a valid date of arrival and try again.";
	langTxt[2] = "Please provide day of arrival";
	langTxt[3] = "Please provide month of arrival";
	
	alert( langTxt[id] );
}

function Signup()
{
	var theform;
	if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) 
	{
		theform = document.frmSignup;
	}
	else 
	{
		theform = document.forms["frmSignup"];
	}
	
	theform.submit();
	
	//close window
	CloseSignup();
	return;
}

function CloseSignup()
{
	document.getElementById('frmDiv').style.width="0px";
	document.getElementById('frmDiv').style.height="0px";
	document.getElementById('frmDiv').style.visibility="visible";
	document.getElementById('frmDiv').style.position="fixed";
	document.getElementById('frmDiv').style.zIndex="0";
	document.getElementById('frmDiv').style.top="-10000px";
	document.getElementById('frmDiv').style.left="-10000px";
	document.getElementById('frmDiv').style.backgroundColor = "white";
	
	document.getElementById('freezeDiv').style.width  ="0%";
	document.getElementById('freezeDiv').style.height="0%";
	document.getElementById('freezeDiv').style.visibility="visible";
	document.getElementById('freezeDiv').style.position="fixed";
	document.getElementById('freezeDiv').style.zIndex="0";
	document.getElementById('freezeDiv').style.top="-10000px";
	document.getElementById('freezeDiv').style.left="-10000px";
	document.getElementById('freezeDiv').style.backgroundColor = "black";
	
	var theform;
	if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) 
	{
		theform = document.frmMain;
	}
	else 
	{
		theform = document.forms["frmMain"];
	}
	
	for (i=0;i<theform.elements.length;i++) {
		el = theform.elements[i];
		
		if(el)
			el.disabled=false;
	}
	
	//reset signupFormValue = 106;
	signupFormValue = 106;
	
	return;
}

var signupFormValue = 106;

function openEClubForm() {
	signupFormValue = 105;
	openSignupForm();
}

function openSignupForm() {
	document.getElementById('freezeDiv').style.width  ="100%";
	document.getElementById('freezeDiv').style.height="100%";
	document.getElementById('freezeDiv').style.visibility="visible";
	document.getElementById('freezeDiv').style.position="fixed";
	document.getElementById('freezeDiv').style.zIndex="99";
	document.getElementById('freezeDiv').style.top="0px";
	document.getElementById('freezeDiv').style.left="0px";
	document.getElementById('freezeDiv').style.backgroundColor = "black";
	
	document.getElementById('frmDiv').style.width="450px";
	document.getElementById('frmDiv').style.height="450px";
	document.getElementById('frmDiv').style.visibility="visible";
	document.getElementById('frmDiv').style.position="fixed";
	document.getElementById('frmDiv').style.zIndex="9999";
	
	var top, left, width, height; 
	width = pageWidth();
	height = pageHeight();
	
	left = (width-450)/2;
	top = (height-450)/2;
	
	document.getElementById('frmDiv').style.top=top.toString()+"px";
	document.getElementById('frmDiv').style.left=left.toString()+"px";
	document.getElementById('frmDiv').style.backgroundColor = "white";
	
	
	var theform,submitForm;
	if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) 
	{
		theform = document.frmMain;
		submitForm = document.frmSignup;
	}
	else 
	{
		theform = document.forms["frmMain"];
		submitForm = document.forms["frmSignup"];
	}

	submitForm.NG.value = signupFormValue;
	
	for (i=0;i<theform.elements.length;i++) {
		el = theform.elements[i];
		
		if(el)
			el.disabled=true;
	}
	/*
	myLinks = document.getElementsByTagName("a");

	for (j=0;j<myLinks.length;j++) {
		myLinks[j].href="";
	}
	*/
}

// Browser Window Size and Position
// copyright Stephen Chapman, 3rd Jan 2005, 8th Dec 2005
// you may copy these functions but please keep the copyright notice as well
function pageWidth() 
{
	return window.innerWidth != null? window.innerWidth : document.documentElement && document.documentElement.clientWidth ?       document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
} 

function pageHeight() 
{
	return  window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ?  document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;
} 

function posLeft() 
{
	return typeof window.pageXOffset != 'undefined' ? window.pageXOffset :document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;
} 

function posTop() 
{
	return typeof window.pageYOffset != 'undefined' ?  window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
} 

function posRight() 
{
	return posLeft()+pageWidth();
} 

function posBottom() 
{
	return posTop()+pageHeight();
}
                    