function ValidarFormulario(Formulario){
	var ListaDeErrores='';
	for (i=0;i<Formulario.elements.length;i++)
		{switch (Formulario.elements[i].type)
			{case 'select-one':
				if ((Formulario.elements[i].title!='')&&(Formulario.elements[i].value==0))
					ListaDeErrores+=' - '+Formulario.elements[i].title+'\n';
				break;
			case 'password':
				if ((Formulario.elements[i].title!='')&&(Formulario.elements[i].value==''))
					ListaDeErrores+=' - '+Formulario.elements[i].title+'\n';
				break;
			case 'text':
				if (Formulario.elements[i].alt.toLowerCase()=='email')
					{if ((Formulario.elements[i].accept!='')&&(Formulario.elements[i].value==''))
						ListaDeErrores+=' - '+Formulario.elements[i].accept+'\n';
					var Mensaje=CheckEmailFormat(Formulario.elements[i],true);
					if (Mensaje!='')
						ListaDeErrores+=' - '+Formulario.elements[i].title+'\n';}
				else
					{var LongitudMinima=(Formulario.elements[i].alt==''?0:parseInt(Formulario.elements[i].alt));
					if ((Formulario.elements[i].title!='')&&((Formulario.elements[i].value=='')||(Formulario.elements[i].value.length<=LongitudMinima)))
						ListaDeErrores+=' - '+Formulario.elements[i].title+'\n';};
				break;};}
	if (ListaDeErrores!='')
		{alert('The following error(s) have occurred:\n'+ListaDeErrores);
		return false;}
	return true;
}

function FOE_NumberCheck(TurboEvento){
	var CodigoDeTecla=(window.event)?event.keyCode:TurboEvento.which;
	if ((CodigoDeTecla<48||CodigoDeTecla>57)&&(CodigoDeTecla!=8)&&(CodigoDeTecla!=0)) return false;
	return true;
}

function FOE_DecimalNumberCheck(TurboEvento){
	var CodigoDeTecla=(window.event)?event.keyCode:TurboEvento.which;
	if (CodigoDeTecla<48||CodigoDeTecla>57)
		if (CodigoDeTecla!=46)
			return false;
	return true;
}

function CheckEmailFormat(TextControl,CouldBeEmpty){
	var Message='';
	if ((TextControl.value=='')&&(CouldBeEmpty==true))
		return '';
	else
		{if ((TextControl.value!='')||(CouldBeEmpty==true))
			{var AtPosition=TextControl.value.indexOf('@');
			if (AtPosition>0)
				{var DotPosition=TextControl.value.indexOf('.',AtPosition);
				if (DotPosition>AtPosition+1)
					{if (DotPosition==TextControl.value.length-1) Message='You are missing the part after the . symbol';}
				else Message=(DotPosition==AtPosition+1?'You are missing the part between the @ symbol and the . symbol':'You are missing the . symbol after the @ symbol');}
			else Message=(AtPosition==0?'You are missing the part before the @ symbol':'You are missing the @ symbol');}
		else Message='You have to specify the email';
		if (Message=='')
			{var i;
			var EmailPattern=/^(.+)@(.+)$/;
			var EmailStructure=TextControl.value.match(EmailPattern);
			var EmailUser=EmailStructure[1];
			var EmailDomain=EmailStructure[2];
			var InvalidCharactersFound='';
			var ActualChar;
			for (i=0;i<EmailUser.length;i++)
				{ActualChar=EmailUser.charCodeAt(i);
				if ((ActualChar!=43)&&(ActualChar!=45)&&(ActualChar!=46)&&(ActualChar!=95)&&((ActualChar<65)||(ActualChar>90))&&((ActualChar<97)||(ActualChar>122))&&((ActualChar<48)||(ActualChar>57)))
					InvalidCharactersFound+=EmailUser.charAt(i)+', ';}
			if (InvalidCharactersFound=='')
				{for (i=0;i<EmailDomain.length;i++)
					{ActualChar=EmailDomain.charCodeAt(i);
					if ((ActualChar!=43)&&(ActualChar!=45)&&(ActualChar!=46)&&(ActualChar!=95)&&((ActualChar<65)||(ActualChar>90))&&((ActualChar<97)||(ActualChar>122))&&((ActualChar<48)||(ActualChar>57)))
						InvalidCharactersFound+=EmailDomain.charAt(i)+', ';}
					if (InvalidCharactersFound!='')
						Message='The wrong characters '+InvalidCharactersFound+'have been found in the email domain';}
			else Message='The wrong characters '+InvalidCharactersFound+'have been found in the email user';};}
	return Message;
}

function CheckNumberFormat(TextControl,SkipWhites){
	if (isNaN(TextControl.value))
		{TextControl.focus();}
	if (SkipWhites==true) return;
	if (TextControl.value=='')
		TextControl.value='0';
}
		
function CheckToSearch(FormName){
	document.SearchForm.HotelRecId.value = document.hotel.hotelrecid.value;
	if (document.SearchForm.rooms.value==0)
		{alert('You must enter the number of rooms requested');
		return false;}
	if (document.SearchForm.firstname.value=='')
		{alert('Please enter your first name');
		return false;}
	if (document.SearchForm.surname.value=='')
		{alert('Please enter your surname');
		return false;}
	if (document.SearchForm.email.value=='')
		{alert('Please enter your email address');
		return false;}
	if (document.SearchForm.telephone.value=='')
		{alert('Please enter your phone number');
		return false;}
		
	var Answer=ValidarFormulario(FormName);
	if (Answer)
		{var TodayDate=new Date();
		TodayDate.setHours(0,0,0,0);
		DateDifference=(StartDate-TodayDate)/1000/60/60/24;
		if (DateDifference<0)
			{alert('Your arrival date cannot be in the past!');
			return false;}
		if (DateDifference<2)
			{alert('If you want to make a reservation arriving less than 2 days before now, please contact us directly');
			return false;}
		var StartDateValue=document.SearchForm.StartDateRange.value;
		var StartDate=new Date(eval(StartDateValue.substring(6,10)),eval(StartDateValue.substring(3,5))-1,eval(StartDateValue.substring(0,2)),0,0,0,0);
		var EndDateValue=document.SearchForm.EndDateRange.value;
		var EndDate=new Date(eval(EndDateValue.substring(6,10)),eval(EndDateValue.substring(3,5))-1,eval(EndDateValue.substring(0,2)),0,0,0,0);
		var DateDifference=(EndDate-StartDate)/1000/60/60/24;
		if (DateDifference<1)
			{alert('Your departure date must be greater than your arrival date');
			return false;}
		if (DateDifference>14)
			{alert('The maximum allowed period is 15 days');
			return false;}
		var GuestNo=eval(document.SearchForm.adults.value)+eval(document.SearchForm.children.value);
		if (GuestNo==0)
			{alert('You must select how many adults and children would stay');
			return false;}
		if (GuestNo>2)
			{alert('The number of guests per room cannot be more than two');
			return false;}
		return true;}
	return false;
}

function EstablecerFechaFinal(FechaInicio,FechaFin){
	var ArregloFechaInicio=FechaInicio.value.split('/');
	NuevaFecha=new Date(ArregloFechaInicio[2],ArregloFechaInicio[1]-1,ArregloFechaInicio[0]);
	NuevaFecha=new Date(NuevaFecha.getTime()+7*86400000);//7*1000*60*60*24=7dias*milisegundos*segundos*minutos*horas del dia
	var Dia='00'+NuevaFecha.getDate();
	Dia=Dia.substring(Dia.length-2,Dia.length);
	var Mes=NuevaFecha.getMonth()+1;
	Mes='00'+Mes;
	Mes=Mes.substring(Mes.length-2,Mes.length);
	FechaFin.value=Dia+'/'+Mes+'/'+NuevaFecha.getYear();
}
		
function bookingCode(){
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request");
		return;
	} 
	var url="makebooking.cfm?grabcode=true";
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged ;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateChanged() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
		document.getElementById("bookingform").innerHTML = xmlHttp.responseText;
	}
} 

function GetXmlHttpObject(){ 
	var objXMLHttp=null;
	if (window.XMLHttpRequest){
		objXMLHttp=new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	return objXMLHttp;
} 

function makeBooking(){
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request");
		return;
	} 
	var fields = "HotelRecId=" + document.hotel.hotelrecid.value;
	//alert(document.hotel.hotelrecid.value);
	fields += "&FirstName=" + document.SearchForm.firstname.value;
	fields += "&Surname=" + document.SearchForm.surname.value;
	fields += "&Email=" + document.SearchForm.email.value;
	fields += "&Arrival=" + document.SearchForm.StartDateRange.value;
	fields += "&Departure=" + document.SearchForm.EndDateRange.value;
	fields += "&AdultsPerRoom=" + document.SearchForm.adults.value;
	fields += "&ChildrenPerRoom=" + document.SearchForm.children.value;
	fields += "&Rooms=" + document.SearchForm.rooms.value;
	fields += "&RoomDescription=" + document.SearchForm.roomtype.value;
	fields += "&Telephone=" + document.SearchForm.telephone.value;
	var url="makebooking.cfm?makebooking=true";
	//alert(fields);
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;  charset=UTF-8');
	xmlHttp.onreadystatechange=stateChangedBooking ;
	xmlHttp.send(fields);
}

function stateChangedBooking() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
		document.getElementById("bookingform").innerHTML = xmlHttp.responseText;
	}
} 



			var months = new Array("January","February","March","April","May","June","July","August","September","October","November","December")
			var totalDays = new Array(31,28,31,30,31,30,31,31,30,31,30,31)
			
			function openCalWin_StartDateRange() { 
				stats='toolbar=no,location=no,directories=no,status=no,menubar=no,'
				stats += 'width=300,height=250'
				CalWin = window.open ("","Calendar",stats)
				
				var calMonth = 3
				var calYear = 2007
				theDate = new Date(calYear, (calMonth - 1), 1)
			
				if(document.SearchForm.StartDateRange.value!='') {
					theDate.setMonth(document.SearchForm.StartDateRange.value.substr(3,2) - 1);
					theDate.setYear(document.SearchForm.StartDateRange.value.substr(6,4)); 
				}
				buildCal_StartDateRange(theDate)
			}
			
			function buildCal_StartDateRange(theDate) {
				var startDay = theDate.getDay();
				var printDays = false;
				var currDay = 1;
				var rowsNeeded = 5;
			
				var Temp=theDate.getYear()%4
				if (Temp==0)
					totalDays[1]=29
				else
					totalDays[1]=28
				
				if (startDay + totalDays[theDate.getMonth()] > 35)
					rowsNeeded++
				
				CalWin.focus()
				CalWin.document.write('<html><head><Title>Select a Date</title>')
				CalWin.document.write('<STYLE TYPE="text/css">')
				CalWin.document.write('A { color: #000000; font-family:Arial,Helvetica;font-size:14pt; font-weight: bold; text-decoration: none}')
				CalWin.document.write('A:hover { color: #FF0000; }')
				CalWin.document.write('</STYLE></head>')
				CalWin.document.write('<body bgcolor="#FFFFFF"><a name="this"></a>')
				CalWin.document.write('<table align=center height=100% width=100% border=2 bordercolor=#000000 cellpadding=0 cellspacing=0>')
				CalWin.document.write('<th bgcolor=#013176 colspan=6><font face=Arial color=#FFFFFF>' + months[theDate.getMonth()] + ' ' + theDate.getFullYear() + '</font></th><th bgcolor=#FFFFFF colspan="1"><input type="Button" size="2" name="Today" value="Now" onClick="opener.getNewCal_StartDateRange(2)"></th></tr>')
				CalWin.document.write('<tr bgcolor="#6699CC"><th><font face=Arial color=#FFFFFF>Su</font></th><th><font face=Arial color=#FFFFFF>Mo</font></th><th><font face=Arial color=#FFFFFF>Tu</font></th><th><font face=Arial color=#FFFFFF>We</font></th><th><font face=Arial color=#FFFFFF>Th</font></th><th><font face=Arial color=#FFFFFF>Fr</font></th><th><font face=Arial color=#FFFFFF>Sa</font></th></tr>')
				for (x=1; x<=rowsNeeded; x++){
					CalWin.document.write('<tr>')
					for (y=0; y<=6; y++){
						if (currDay == 1 && !printDays && startDay == y)
							printDays = true
						CalWin.document.write('<td align="center" width=14.28%>')
						if (printDays){
							CalWin.document.write('<a href="javascript:opener.placeDate_StartDateRange(' + theDate.getMonth() + ',' +  currDay + ',' + theDate.getFullYear() + ')">' + currDay++ + '</a></td>')
							if (currDay > totalDays[theDate.getMonth()])
								printDays = false
						}
						else
							CalWin.document.write('&nbsp;</td>')
					}		
					CalWin.document.write('</tr>')
				}	
				CalWin.document.write('<form name="Cal"><tr bgcolor="#6699CC"><td align="center"><input type="Button" size="2" name="Back" value="<<" onClick="opener.getNewCal_StartDateRange(-1)"></td>')
				CalWin.document.write('<td colspan="5" align="center"><select name="SelectMonth" onChange="opener.getNewCal_StartDateRange(0)"><option value="0">January</option><option value="1">February</option><option value="2">March</option><option value="3">April</option><option value="4">May</option><option value="5">June</option><option value="6">July</option><option value="7">August</option><option value="8">September</option><option value="9">October</option><option value="10">November</option><option value="11">December</option></select>&nbsp;&nbsp;')
				CalWin.document.write('<select name="SelectYear" onChange="opener.getNewCal_StartDateRange(0)"><option value="1995">1995</option><option value="1996">1996</option><option value="1997">1997</option><option value="1998">1998</option><option value="1999">1999</option><option value="2000">2000</option><option value="2001">2001</option><option value="2002">2002</option><option value="2003">2003</option><option value="2004">2004</option><option value="2005">2005</option><option value="2006">2006</option><option value="2007">2007</option><option value="2008">2008</option><option value="2009">2009</option><option value="2010">2010</option></select></td><td align="center"><input type="Button" size="2" name="Forward" value=">>" onClick="opener.getNewCal_StartDateRange(1)"></td></tr></form>')
				CalWin.document.write('</table></body></html>')
				CalWin.document.Cal.SelectMonth.selectedIndex=theDate.getMonth();
				if (theDate.getFullYear()<=1995) {
					CalWin.document.Cal.SelectYear[1995-CalWin.document.Cal.SelectYear[0].value].selected=true;
				}
				else if (theDate.getFullYear()>=2010) {
					CalWin.document.Cal.SelectYear[2010-CalWin.document.Cal.SelectYear[0].value].selected=true;
				}
				else {
					CalWin.document.Cal.SelectYear[theDate.getFullYear()-CalWin.document.Cal.SelectYear[0].value].selected=true;
				}
				CalWin.document.close()
			}
			
			function getNewCal_StartDateRange(newDir) {
				if (newDir == 2) { // 'Now' button
					theDate=new Date();
					theDate.setDate(1);
				}
				else if (newDir == -1){ // '<<' button
					theDate.setMonth(theDate.getMonth() - 1)
					if (theDate.getMonth() == 0){
						theDate.setMonth(12)
						theDate.setYear(theDate.getYear() - 1)
					}
				}
				else if (newDir == 1){ //'>>' button
					theDate.setMonth(theDate.getMonth() + 1)
					if (theDate.getMonth() == 13){
						theDate.setMonth(1)
						theDate.setYear(theDate.getYear() + 1)
					}
				}
				else if (newDir == 0) {
					theDate.setMonth(CalWin.document.Cal.SelectMonth.options[CalWin.document.Cal.SelectMonth.selectedIndex].value);
					theDate.setFullYear(CalWin.document.Cal.SelectYear.options[CalWin.document.Cal.SelectYear.selectedIndex].value);
				}
				CalWin.document.clear();
				buildCal_StartDateRange(theDate);
			}
			
			function placeDate_StartDateRange(monthNum, dayNum, yearNum) {
				
					var dateString = formatDates(dayNum) + '/' + formatDates(monthNum + 1) + '/' + yearNum;
				
				document.SearchForm.StartDateRange.value = dateString;
				EstablecerFechaFinal(document.SearchForm.StartDateRange,document.SearchForm.EndDateRange)
				CalWin.close();
			}
			
			function formatDates(x) {
			  if (x<10) return '0'+x;
			  else return x;
			}
			
			var months = new Array("January","February","March","April","May","June","July","August","September","October","November","December")
			var totalDays = new Array(31,28,31,30,31,30,31,31,30,31,30,31)
			
			function openCalWin_EndDateRange() { 
				stats='toolbar=no,location=no,directories=no,status=no,menubar=no,'
				stats += 'width=300,height=250'
				CalWin = window.open ("","Calendar",stats)
				
				var calMonth = 3
				var calYear = 2007
				theDate = new Date(calYear, (calMonth - 1), 1)
			
				if(document.SearchForm.EndDateRange.value!='') {
					theDate.setMonth(document.SearchForm.EndDateRange.value.substr(3,2) - 1);
					theDate.setYear(document.SearchForm.EndDateRange.value.substr(6,4)); 
				}
				buildCal_EndDateRange(theDate)
			}
			
			function buildCal_EndDateRange(theDate) {
				var startDay = theDate.getDay();
				var printDays = false;
				var currDay = 1;
				var rowsNeeded = 5;
			
				var Temp=theDate.getYear()%4
				if (Temp==0)
					totalDays[1]=29
				else
					totalDays[1]=28
				
				if (startDay + totalDays[theDate.getMonth()] > 35)
					rowsNeeded++
				
				CalWin.focus()
				CalWin.document.write('<html><head><Title>Select a Date</title>')
				CalWin.document.write('<STYLE TYPE="text/css">')
				CalWin.document.write('A { color: #000000; font-family:Arial,Helvetica;font-size:14pt; font-weight: bold; text-decoration: none}')
				CalWin.document.write('A:hover { color: #FF0000; }')
				CalWin.document.write('</STYLE></head>')
				CalWin.document.write('<body bgcolor="#FFFFFF"><a name="this"></a>')
				CalWin.document.write('<table align=center height=100% width=100% border=2 bordercolor=#000000 cellpadding=0 cellspacing=0>')
				CalWin.document.write('<th bgcolor=#013176 colspan=6><font face=Arial color=#FFFFFF>' + months[theDate.getMonth()] + ' ' + theDate.getFullYear() + '</font></th><th bgcolor=#FFFFFF colspan="1"><input type="Button" size="2" name="Today" value="Now" onClick="opener.getNewCal_EndDateRange(2)"></th></tr>')
				CalWin.document.write('<tr bgcolor="#6699CC"><th><font face=Arial color=#FFFFFF>Su</font></th><th><font face=Arial color=#FFFFFF>Mo</font></th><th><font face=Arial color=#FFFFFF>Tu</font></th><th><font face=Arial color=#FFFFFF>We</font></th><th><font face=Arial color=#FFFFFF>Th</font></th><th><font face=Arial color=#FFFFFF>Fr</font></th><th><font face=Arial color=#FFFFFF>Sa</font></th></tr>')
				for (x=1; x<=rowsNeeded; x++){
					CalWin.document.write('<tr>')
					for (y=0; y<=6; y++){
						if (currDay == 1 && !printDays && startDay == y)
							printDays = true
						CalWin.document.write('<td align="center" width=14.28%>')
						if (printDays){
							CalWin.document.write('<a href="javascript:opener.placeDate_EndDateRange(' + theDate.getMonth() + ',' +  currDay + ',' + theDate.getFullYear() + ')">' + currDay++ + '</a></td>')
							if (currDay > totalDays[theDate.getMonth()])
								printDays = false
						}
						else
							CalWin.document.write('&nbsp;</td>')
					}		
					CalWin.document.write('</tr>')
				}	
				CalWin.document.write('<form name="Cal"><tr bgcolor="#6699CC"><td align="center"><input type="Button" size="2" name="Back" value="<<" onClick="opener.getNewCal_EndDateRange(-1)"></td>')
				CalWin.document.write('<td colspan="5" align="center"><select name="SelectMonth" onChange="opener.getNewCal_EndDateRange(0)"><option value="0">January</option><option value="1">February</option><option value="2">March</option><option value="3">April</option><option value="4">May</option><option value="5">June</option><option value="6">July</option><option value="7">August</option><option value="8">September</option><option value="9">October</option><option value="10">November</option><option value="11">December</option></select>&nbsp;&nbsp;')
				CalWin.document.write('<select name="SelectYear" onChange="opener.getNewCal_EndDateRange(0)"><option value="1995">1995</option><option value="1996">1996</option><option value="1997">1997</option><option value="1998">1998</option><option value="1999">1999</option><option value="2000">2000</option><option value="2001">2001</option><option value="2002">2002</option><option value="2003">2003</option><option value="2004">2004</option><option value="2005">2005</option><option value="2006">2006</option><option value="2007">2007</option><option value="2008">2008</option><option value="2009">2009</option><option value="2010">2010</option></select></td><td align="center"><input type="Button" size="2" name="Forward" value=">>" onClick="opener.getNewCal_EndDateRange(1)"></td></tr></form>')
				CalWin.document.write('</table></body></html>')
				CalWin.document.Cal.SelectMonth.selectedIndex=theDate.getMonth();
				if (theDate.getFullYear()<=1995) {
					CalWin.document.Cal.SelectYear[1995-CalWin.document.Cal.SelectYear[0].value].selected=true;
				}
				else if (theDate.getFullYear()>=2010) {
					CalWin.document.Cal.SelectYear[2010-CalWin.document.Cal.SelectYear[0].value].selected=true;
				}
				else {
					CalWin.document.Cal.SelectYear[theDate.getFullYear()-CalWin.document.Cal.SelectYear[0].value].selected=true;
				}
				CalWin.document.close()
			}
			
			function getNewCal_EndDateRange(newDir) {
				if (newDir == 2) { // 'Now' button
					theDate=new Date();
					theDate.setDate(1);
				}
				else if (newDir == -1){ // '<<' button
					theDate.setMonth(theDate.getMonth() - 1)
					if (theDate.getMonth() == 0){
						theDate.setMonth(12)
						theDate.setYear(theDate.getYear() - 1)
					}
				}
				else if (newDir == 1){ //'>>' button
					theDate.setMonth(theDate.getMonth() + 1)
					if (theDate.getMonth() == 13){
						theDate.setMonth(1)
						theDate.setYear(theDate.getYear() + 1)
					}
				}
				else if (newDir == 0) {
					theDate.setMonth(CalWin.document.Cal.SelectMonth.options[CalWin.document.Cal.SelectMonth.selectedIndex].value);
					theDate.setFullYear(CalWin.document.Cal.SelectYear.options[CalWin.document.Cal.SelectYear.selectedIndex].value);
				}
				CalWin.document.clear();
				buildCal_EndDateRange(theDate);
			}
			
			function placeDate_EndDateRange(monthNum, dayNum, yearNum) {
				
					var dateString = formatDates(dayNum) + '/' + formatDates(monthNum + 1) + '/' + yearNum;
				
				document.SearchForm.EndDateRange.value = dateString;
				
				CalWin.close();
			}
			
			function formatDates(x) {
			  if (x<10) return '0'+x;
			  else return x;
			}			
			




