//SetArrivalDate - Validates Date Fields and add to ArrivalDate hidden field

function SetArrivalDate(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 Book()
{
	var theform;
	var subForm;
	if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) 
	{
		theform = document.frmMain;
		subForm = document.Form1;
	}
	else 
	{
		theform = document.forms["frmMain"];
		subForm = document.forms["Form1"];
	}
	
	if(theform==null){
		LanguageAlert( 0 );
		return;
	}
	
	if(!SetArrivalDate( 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.target = "_blank";
	subForm.action = "https://www.hbnonline.co.uk/booking/loadDiv.aspx";
	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();
	
	//English (Index 0)
	langTxt[0] = new Array();
	
	langTxt[0][0] = "Unable to show reservation window at this time. Please call our reservations department for more information.";
	langTxt[0][1] = "Unable to show reservation window at this time. Please check you have supplied a valid date of arrival and try again.";
	langTxt[0][2] = "Please provide day of arrival";
	langTxt[0][3] = "Please provide month of arrival";
	
	//German
	langTxt[1] = new Array();
	
	langTxt[1][0] = "DE Unable to show reservation window at this time. Please call our reservations department for more information.";
	langTxt[1][1] = "DE Unable to show reservation window at this time. Please check you have supplied a valid date of arrival and try again.";
	langTxt[1][2] = "DE Please provide day of arrival";
	langTxt[1][3] = "DE Please provide month of arrival";
	
	//portuguese
	langTxt[2] = new Array();
	
	langTxt[2][0] = "De momento não é possivel satisfazer o seu pedido. Por favor contacte o nosso departamento de reservas para mais informações.";
	langTxt[2][1] = "De momento não é possivel satisfazer o seu pedido. Por favor verifique se inseriu correctamente a data de chegada e tente novamente.";
	langTxt[2][2] = "Por favor insira a data prevista de chegada";
	langTxt[2][3] = "Por favor insira o mês pretendido";
	
	//Spanish
	langTxt[3] = new Array();
	
	langTxt[3][0] = "ES Unable to show reservation window at this time. Please call our reservations department for more information.";
	langTxt[3][1] = "ES Unable to show reservation window at this time. Please check you have supplied a valid date of arrival and try again.";
	langTxt[3][2] = "ES Please provide day of arrival";
	langTxt[3][3] = "ES Please provide month of arrival";
	
	//work out from url if we are in another language other than English. Set lang to correct index.
	var lang = 0; //default 0 English
	
	if(window.location.href.indexOf('/german/')>-1)
		lang = 1;
	if(window.location.href.indexOf('/portuguese/')>-1)
		lang = 2;
	if(window.location.href.indexOf('/spanish/')>-1)
		lang = 3;
	
	alert( langTxt[lang][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 = 102;
	signupFormValue = 102;
	
	return;
}

var signupFormValue = 102;

function openEClubForm() {
	signupFormValue = 101;
	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();
}
                    