/* session timeouts timer */
var secs;
var timerID = null;
var timerRunning = false;
var delay = 1000;
function StopTheClock()
{
    if(timerRunning){
      clearTimeout(timerID);
      timerRunning = false;
    }
}
function StartTheTimer()
{
    if (secs===0)
    {
        StopTheClock();
        alert("Your search session has expired. Click the \"OK\" button to search our hotels again to get the latest availability.");
        location = "http://www.hotelshotelshotels.co.uk";
    }
    else
    {
        self.status = secs;
        secs = secs - 1;
        timerRunning = true;
        timerID = self.setTimeout("StartTheTimer()", delay);
    }
}
function InitializeTimer()
{
    // Set the length of the timer, in seconds
    secs = 1800;
    StopTheClock();
    StartTheTimer();
}
/* cookie stuff */
function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else {var expires = "";}
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name)
{
	createCookie(name,"",-1);
}
/* loading windows */
function open0()
{
	var open0 = window.open('http://www.hotelshotelshotels.co.uk/booking/load.html','Wait','status=0,menubar=0,scrollbars=0,resizable=0,width=300,height=300,top=250,left=350');
}
function open1()
{
	var open1 =	window.open('http://www.hotelshotelshotels.co.uk/booking/on-request.html','Wait','status=0,menubar=0,scrollbars=0,resizable=0,width=300,height=250,top=250,left=350');
}
/* form validation */
function FormDance(form) 
{
	if (document.form.country.value == "")
	{
		alert("Please select the country you would like to search for"); return false;
	}
	if (document.form.city.value == "")
	{
		alert("Please select the city/location you would like to search for"); return false;
	}
	if ((document.form.numrooms.value == "1") && (document.form.adtroom1.value == "0") && (document.form.chdroom1.value == "0"))
	{
		alert("There must be at least one person in room 1"); return false;
	}
	if ((document.form.numrooms.value == "2") && (document.form.adtroom1.value == "0") && (document.form.chdroom1.value == "0"))
	{
		alert("There must be at least one person in room 1"); return false;
	}
	if ((document.form.numrooms.value == "2") && (document.form.adtroom2.value == "0") && (document.form.chdroom2.value == "0"))
	{
		alert("There must be at least one person in room 2"); return false;
	}
	if ((document.form.numrooms.value == "3") && (document.form.adtroom1.value == "0") && (document.form.chdroom1.value == "0"))
	{
		alert("There must be at least one person in room 1"); return false;
	}
	if ((document.form.numrooms.value == "3") && (document.form.adtroom2.value == "0") && (document.form.chdroom2.value == "0"))
	{
		alert("There must be at least one person in room 2"); return false;
	}
	if ((document.form.numrooms.value == "3") && (document.form.adtroom3.value == "0") && (document.form.chdroom3.value == "0"))
	{
		alert("There must be at least one person in room 3"); return false;
	}
	if ((document.form.adtroom1.value == 0) && (document.form.chdroom1.value >= 1))
	{
		alert("There must be at least one adult in room 1"); return false;
	}
	if ((document.form.adtroom2.value == 0) && (document.form.chdroom2.value >= 1))
	{
		alert("There must be at least one adult in room 2"); return false;
	}
	if ((document.form.adtroom3.value == 0) && (document.form.chdroom3.value >= 1))
	{
		alert("There must be at least one adult in room 3"); return false;
	}
open0();
}
/* more form setting stuff */
function setMenu()
{
var MenuString = readCookie("menu");
if (MenuString) {
var MenuArray=MenuString.split(":");
ShowMenu(MenuArray[2],'divRoom', 4);
ShowChdAge(MenuArray[4],'chdroom1age', 4);
ShowChdAge(MenuArray[10],'chdroom2age', 4);
ShowChdAge(MenuArray[16],'chdroom3age', 4);
ShowChdAge(MenuArray[22],'chdroom4age', 4);
document.form.fdate.value = MenuArray[0]; 
document.form.tdate.value = MenuArray[1]; 
document.form.numrooms.value = MenuArray[2];
document.form.adtroom1.value = MenuArray[3]; 
document.form.chdroom1.value = MenuArray[4]; 
document.form.chdroom1age1.value = MenuArray[5]; 
document.form.chdroom1age2.value = MenuArray[6]; 
document.form.chdroom1age3.value = MenuArray[7]; 
document.form.chdroom1age4.value = MenuArray[8]; 
document.form.adtroom2.value = MenuArray[9];
document.form.chdroom2.value = MenuArray[10];
document.form.chdroom2age1.value = MenuArray[11];
document.form.chdroom2age2.value = MenuArray[12];
document.form.chdroom2age3.value = MenuArray[13];
document.form.chdroom2age4.value = MenuArray[14];
document.form.adtroom3.value = MenuArray[15];
document.form.chdroom3.value = MenuArray[16];
document.form.chdroom3age1.value = MenuArray[17];
document.form.chdroom3age2.value = MenuArray[18];
document.form.chdroom3age3.value = MenuArray[19];
document.form.chdroom3age4.value = MenuArray[20];
document.form.adtroom4.value = MenuArray[21];
document.form.chdroom4.value = MenuArray[22];
document.form.chdroom4age1.value = MenuArray[23];
document.form.chdroom4age2.value = MenuArray[24];
document.form.chdroom4age3.value = MenuArray[25];
document.form.chdroom4age4.value = MenuArray[26];
document.form.currency.value = MenuArray[33];
}
}
function addZero(vNumber)
{
	return ((vNumber < 10) ? "0" : "") + vNumber 
}
function SetDates(form)
{
	var t = new Date;
	var oneMinute = 60 * 1000  // milliseconds in a minute
	var oneHour = oneMinute * 60
	var oneDay = oneHour * 24
	var oneWeek = oneDay * 7
	var today = new Date()
	var fromdateInMS = today.getTime() + oneDay * 1
	var targetfromDate = new Date(fromdateInMS)
	var todateInMS = today.getTime() + oneDay * 5
	var targettoDate = new Date(todateInMS)
	document.form.fromday.value = addZero(targetfromDate.getDate());
	document.form.frommonth.value = addZero(targetfromDate.getMonth() + 1);
	document.form.fromyear.value = targetfromDate.getFullYear();
	document.form.today.value = addZero(targettoDate.getDate());
	document.form.tomonth.value = addZero(targettoDate.getMonth() + 1);
	document.form.toyear.value = targettoDate.getFullYear();
}
function ChangeMonth(form)
{
	document.form.tomonth.value = document.form.frommonth.value;
}
function ChangeYear(form)
{
	document.form.toyear.value = document.form.fromyear.value;
}
function ShowHomes(ob)
{
	var opt = ob
	var ele = document.getElementById(opt);
	if (document.form.city.value == 'Orlando Area - FL') {
    ele.style.display = 'block';
    createCookie('homesSearch','y',0)
  } else {
    ele.style.display = 'none';
    eraseCookie('homesSearch')
  }
}
function ShowMenu(num, menu, max)
{
	for(i = 1; i <= num; i++){
		var menu2 = menu + i;
		document.getElementById(menu2).style.display = 'block';
	}
	var num2 = num;
	num2++;
	while(num2 <= max){
	var menu3 = menu + num2;
	document.getElementById(menu3).style.display = 'none';
	num2=num2+1;
	}	
	if (document.form.numrooms.value == 6) {
		document.form.submit.style.display = 'none';
		document.all.divRoom1.style.display = 'none';
		document.all.divRoom2.style.display = 'none';
		document.all.divRoom3.style.display = 'none';
		document.all.divRoom4.style.display = 'none';
	}
	if (document.form.numrooms.value < 6) {
		document.form.submit.style.display = 'inline';
	}
	if (document.form.numrooms.value == 1) {
		document.form.adtroom2.value = '0';
		document.form.chdroom2.value = '0';
		document.form.adtroom3.value = '0';
		document.form.chdroom3.value = '0';
		document.form.adtroom4.value = '0';
		document.form.chdroom4.value = '0';
	}
	if (document.form.numrooms.value == 2) {
		document.form.adtroom3.value = '0';
		document.form.chdroom3.value = '0';
		document.form.adtroom4.value = '0';
		document.form.chdroom4.value = '0';
	}
	if (document.form.numrooms.value == 3) {
		document.form.adtroom4.value = '0';
		document.form.chdroom4.value = '0';
	}
}

function ShowChdAge(num, menu, max)
{
	for(i = 1; i <= num; i++){
		var menu2 = menu + i;
		document.getElementById(menu2).style.display = 'inline';
	}
	var num2 = num;
	num2++;
	while(num2 <= max){
	var menu3 = menu + num2;
	document.getElementById(menu3).style.display = 'none';
	num2=num2+1;
	}
}
var monthLength = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
function checkDate1(name)
{
	//var dateExists = true;
	var dateExists = true;
	var x = document.form.elements;
	var day = parseInt(x[name+"day"].options[x[name+"day"].selectedIndex].value);
	var month = parseInt(x[name+"month"].options[x[name+"month"].selectedIndex].value);
	var year = parseInt(x[name+"year"].options[x[name+"year"].selectedIndex].value);
	if (!day || !month || !year)
		return false;
	if (year/4 == parseInt(year/4))
		monthLength[1] = 29;
	if (day > monthLength[month-1])
		return false;
	monthLength[1] = 28;
	if (!dateExists)
	{
		alert('You have entered an invalid date');
		return false;
	}
	var now = new Date();
	now = now.getTime(); //NN3
	var dateToCheck = new Date();
	dateToCheck.setYear(year);
	dateToCheck.setMonth(month-1);
	dateToCheck.setDate(day);
	var checkDate = dateToCheck.getTime();
	var futureDate = (now < checkDate);
	var pastDate = (now > checkDate);
}
function checkDate2(name)
{
	//var dateExists = true;
	var x = document.form.elements;
	var day = parseInt(x[name+"day"].options[x[name+"day"].selectedIndex].value);
	var month = parseInt(x[name+"month"].options[x[name+"month"].selectedIndex].value);
	var year = parseInt(x[name+"year"].options[x[name+"year"].selectedIndex].value);
	if (!day || !month || !year)
		return false;
	if (year/4 == parseInt(year/4))
		monthLength[1] = 29;
	if (day > monthLength[month-1])
		return false;
	monthLength[1] = 28;
	var dateExists = checkDate(to);
	if (!dateExists)
	{
		alert('You have entered an invalid date');
		return false;
	}
	var now = new Date();
	now = now.getTime(); //NN3
	var dateToCheck = new Date();
	dateToCheck.setYear(year);
	dateToCheck.setMonth(month-1);
	dateToCheck.setDate(day);
	var checkDate = dateToCheck.getTime();
	var futureDate = (now < checkDate);
	var pastDate = (now > checkDate);
}
/* bookmark code */
function rem(title, url)
{
	if (document.all)
	window.external.AddFavorite(url, title);
	else if (window.sidebar)
	alert('To Bookmark the Hotels Hotels Hotels website please press Ctrl+D on your keyboard.');
}
/* fancy colours for he search result */
function alternate(id){ 
 if(document.getElementsByTagName){  
   var table = document.getElementById(id);   
   var rows = table.getElementsByTagName("tr");   
   for(i = 0; i < rows.length; i++){           
 //manipulate rows 
     if(i % 2 == 0){ 
       rows[i].className = "even"; 
     }else{ 
       rows[i].className = "odd"; 
     }       
   } 
 } 
}
/* social bookmarks */
function fbs_click() {
  u=location.href;
  t=document.title;
  window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
  return false;
}
function toggle(obj) {
      var el = document.getElementById(obj);
      if (el.style.display != 'block') {
            el.style.display = 'block';
      } else {
            el.style.display = 'none';
      }
}
/* Affiliate tracking code */
var searchString = window.location.search.substring(1);
var Parameters = new Object();
var nameValuePairs = searchString.split(/&/);
var nameValuePair;
var name;
var value;
for (var i = 0; i < nameValuePairs.length; i++) {
nameValuePair = nameValuePairs[i].split(/=/);
name = nameValuePair[0];
value = nameValuePair[1];
name = name.toLowerCase();
if (name == "adnetwork"){
if (typeof(value)!="undefined"){
value = value.toLowerCase();
pathname = location.pathname;
myDomain = pathname.substring(0,pathname.lastIndexOf('/')) +'/';
// set expiry date to 30 days from now.
var largeExpDate = new Date ();
largeExpDate.setTime(largeExpDate.getTime() + (30 * 24 * 3600 *
1000));
SetCookie(name,value,largeExpDate,myDomain);
}
}
}
/* another cookie script for some reason */
function SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
5
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}