function formJump(url)
{
	if (url != '')
		self.location = url;
}

function changeButtonClass(b)
{
	if (b.style.color=='#000000')
		b.style.color='#008000';
	else
	{
		b.style.color='#000000';
		b.style.cursor='hand';
	}
}

function openCalendar(url)
{
  var params="menubar=no,toolbar=no,location=no,directories=no,status=yes,scrollbars=no,resizable=no,dependent,top=0,left=0,width=680,height=210";
  popupWin = window.open(url, 'calendar',params);
  popupWin.focus();
}

function createDropdown(b,e,s)
{
	for (i=b; i<=e; i++)
	{
		if (i==s)
			document.write('<option value="'+i+'" selected="selected">'+i+'</option>');
		else
			document.write('<option value="'+i+'">'+i+'</option>');
	}
}

function showRooms(r, c)
{
	kids=document.form.kidsage.value;
	if (kids=='') kidspace=0;
	else kidspace=31;
	for (i=2; i<=5; i++)
	{
		document.getElementById('otherRooms'+i).style.display = 'none';
	}
	if (r>1)
	{
		for (i=2; i<=r; i++)
		{
			document.getElementById('otherRooms'+i).style.display = 'block';
		}
		if (c==1)
		{
			if (document.getElementById('advancedSearch').style.display=='block')
				moveOffers(110 + kidspace + (21 * (r - 1)));
			else
				moveOffers(kidspace + (21 * (r - 1)));
		}
	}
	else
	{
		if (c==1)
		{
			if (document.getElementById('advancedSearch').style.display=='block')
				moveOffers(110+kidspace);
			else
				moveOffers(kidspace);
		}
	}
}

function setGuests(br)
{
	f = document.form;
	adults = 0;
	children = 0;
	m = f.rooms.options[f.rooms.selectedIndex].value;
	lb = "";
	if (br==1)
		lb = "<br>";
	for (i=1; i<=m; i++)
	{
		if ((f['roomtype'+i].options[f['roomtype'+i].selectedIndex].value=='doubleroom')||(f['roomtype'+i].options[f['roomtype'+i].selectedIndex].value=='twin'))
			adults = adults + 2;
		if (f['roomtype'+i].options[f['roomtype'+i].selectedIndex].value=='single')
			adults = adults + 1;
		if (f['roomtype'+i].options[f['roomtype'+i].selectedIndex].value=='triple')
			adults = adults + 3;
		if (f['roomtype'+i].options[f['roomtype'+i].selectedIndex].value=='family1')
		{
			adults = adults + 2;
			children = children + 1;
		}
		if (f['roomtype'+i].options[f['roomtype'+i].selectedIndex].value=='family2')
		{
			adults = adults + 2;
			children = children + 2;
		}
	}

//	if (br!=2)
//	{
//		if ((children==0)&&(adults>0))
//			document.getElementById('guestText').innerHTML = adults + ' Adults';
//		else if (adults>0)
//			document.getElementById('guestText').innerHTML = adults + ' Adults, ' + lb + children + ' Children (age:' + f.kidsage.value + ')';
//		else
//			document.getElementById('guestText').innerHTML = '';
//	}
	f.adults.value = adults;
	f.children.value = children;
}

function setGuestsFree()
{
	f = document.form;
	adults = 0;
	children = 0;

	if (f.family1.selectedIndex>0)
	{
		adults = adults + (2 * f.family1.selectedIndex);
		children = children + (1 * f.family1.selectedIndex);
	}
	if (f.family2.selectedIndex>0)
	{
		adults = adults + (2 * f.family2.selectedIndex);
		children = children + (2 * f.family2.selectedIndex);
	}
	f.adults.value = adults;
	f.children.value = children;
}

function blankOtherCities()
{
	f = document.form;
	c = f.city.length;
	for (i=0; i<c; i++)
	{
		if (f.city[i].checked==true)
			f.other_city.selectedIndex = 0;
	}
}

function blankCities()
{
	f = document.form;
	c = f.city.length;
	if (f.other_city.selectedIndex!=0)
	{
		for (i=0; i<c; i++)
		{
			f.city[i].checked = false;
		}
	}
}

function showAdvanced(c)
{
	f = document.form;
	s = document.getElementById('advancedSearch');
	l = document.getElementById('advancedLink');
	r = document.form.rooms.options[document.form.rooms.selectedIndex].value;
	kids=document.form.kidsage.value;
	if (kids=='') kidspace=0;
	else kidspace=31;

	if ((s.style.display=='')||(s.style.display=='none'))
	{
		s.style.display = 'block';
		l.className = 'black8';
		if (c==1)
		{
			if (r>1)
				moveOffers(110 + kidspace + (21 * (r - 1)));
			else
				moveOffers(110 + kidspace);
		}
	}
	else
	{
		s.style.display = 'none';
		l.className = 'green8';
		f.price.selectedIndex = 0;
		f.category.selectedIndex = 0;
		f.location.selectedIndex = 0;
		f.hotelname.selectedIndex = 0;
		f.facilities.selectedIndex = 0;
		if (c==1)
		{
			if (r>1)
				moveOffers(kidspace + (21 * (r - 1)));
			else
				moveOffers(kidspace);
		}
	}
}

function blankAdvanced(a)
{
	f = document.form;
	i = a.selectedIndex;
	n = a.name;

	f.price.selectedIndex = 0;
	f.category.selectedIndex = 0;
	f.location.selectedIndex = 0;
	f.hotelname.selectedIndex = 0;
	f.facilities.selectedIndex = 0;

	f[n].selectedIndex = i;
}

function moveOffers(p)
{
	document.getElementById('offer2').style.paddingTop = p + 'px';
	document.getElementById('offer3').style.paddingTop = p + 'px';
	document.getElementById('offer4').style.paddingTop = p + 'px';
}

function showGallery(image, n , m)
{
	mainImage.src = 'http://www.hoteldirect.co.uk/images/' + image;
	for (i=1; i<=m; i++)
	{
		document.getElementById('thumb'+i).style.filter = 'alpha(opacity=50)';
		document.getElementById('thumbLink'+i).className = 'green8';
	}
	document.getElementById('thumb'+n).style.filter = 'alpha(opacity=100)';
	document.getElementById('thumbLink'+n).className = 'black8_noline';
	document.getElementById('galleryText').innerHTML = document.getElementById('thumbLink'+n).innerText;
}

function numbersOnly(field)
{
	var valid = "0123456789"
	ok = 1;
	var temp;
	for (var i=0; i<field.value.length; i++)
	{
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1")
			ok = 0;
	}
	if (ok==0)
	{
		alert("Please only enter numbers in this field!");
		field.focus();
		field.select();
	}
}

function sameAddress()
{
	f = document.form;
	if (f.copy_address.checked==true)
	{
		f.ccaddress.value = f.address.value;
		f.cccity.value = f.custcity.value;
		f.ccstate.value = f.county.value;
		f.ccpostcode.value = f.postcode.value;
		f.cccountry.selectedIndex = f.country.selectedIndex;
	}
	else
	{
		f.ccaddress.value = '';
		f.cccity.value = '';
		f.ccstate.value = '';
		f.ccpostcode.value = '';
	}
}

function setKids(t)
{
        showKidsAge();
/*
	f=document.form;
	if (((t.options[t.selectedIndex].value=='family1')||(t.options[t.selectedIndex].value=='family2'))&&(f.kidsage.value==''))
	{
		openWindow('http://www.hoteldirect.co.uk/kidsage.htm',365,180,'no');
	}
*/
}

function showKidsAge()
{

	f = document.form;
	s = document.getElementById('kidsagediv');
	r1 = document.form.roomtype1.options[document.form.roomtype1.selectedIndex].value;
	r2 = document.form.roomtype2.options[document.form.roomtype2.selectedIndex].value;
	r3 = document.form.roomtype3.options[document.form.roomtype3.selectedIndex].value;
	r4 = document.form.roomtype4.options[document.form.roomtype4.selectedIndex].value;
	r5 = document.form.roomtype5.options[document.form.roomtype5.selectedIndex].value;
	r = document.form.rooms.options[document.form.rooms.selectedIndex].value;

	if ((r1.indexOf('family')>-1) || (r2.indexOf('family')>-1) || (r3.indexOf('family')>-1) || (r4.indexOf('family')>-1) || (r5.indexOf('family')>-1))
	{
		s.style.display = 'block';
		kidspace=31;
	}
	else
	{
		s.style.display = 'none';
		kidspace=0;
	}
	if (document.getElementById('advancedSearch').style.display=='block')
	 	moveOffers(110 + kidspace + (21 * (r - 1)));
	else
		moveOffers(kidspace + (21 * (r - 1)));
}

function showKidsAge2()
{

	f = document.form;
	s = document.getElementById('kidsagediv');
	r1 = document.form.roomtype1.options[document.form.roomtype1.selectedIndex].value;
	r2 = document.form.roomtype2.options[document.form.roomtype2.selectedIndex].value;
	r3 = document.form.roomtype3.options[document.form.roomtype3.selectedIndex].value;
	r4 = document.form.roomtype4.options[document.form.roomtype4.selectedIndex].value;
	r5 = document.form.roomtype5.options[document.form.roomtype5.selectedIndex].value;

	if ((r1.indexOf('family')>-1) || (r2.indexOf('family')>-1) || (r3.indexOf('family')>-1) || (r4.indexOf('family')>-1) || (r5.indexOf('family')>-1))
	{
		s.style.display = 'block';
	}
	else
	{
		s.style.display = 'none';
	}
}


function openWindow(url, w, h, s)
{
	var params="menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars="+s+",resizable=yes,dependent,top=0,left=0,width="+w+",height="+h;
	popupWin = window.open(url, 'popup',params);
	popupWin.focus();
}

function openMap(url, w, h)
{
	var params="menubar=yes,toolbar=yes,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,dependent,top=0,left=0,width="+w+",height="+h;
	popupWin = window.open(url, 'popup',params);
	popupWin.focus();
}

function ageOnly(field)
{
	var valid = "0123456789,"
	ok = 1;
	var temp;
	for (var i=0; i<field.value.length; i++)
	{
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1")
			ok = 0;
	}
	if (ok==0)
	{
		alert("Please only enter numbers in this field!");
		field.focus();
		field.select();
	}
}

function setAge()
{
	w=window.opener.document.form;
	f=document.form;

	if (f.kidsage.value=='')
	{
		alert('Please enter the age of the child/children');
	}
	errors="";
	errorcheck=0;
	stripNumber(f.kidsage.value,w.maxage.value);
	if (errorcheck==1)
		alert(errors);
	else
	{
		w.kidsage.value=f.kidsage.value;
		window.close();
	}
}

function stripNumber(number,maxage)
{
	age = 0;
	max = parseInt(maxage);
	var comma = number.indexOf(',');
	if (comma!=-1)
	{
		age = number.substring(0,comma);
		if (age>max)
		{
			errors = errors + 'The age '+age+' is too old for a child at this hotel. Maximum age: '+maxage+'\n\n';
			errorcheck = 1;
		}
		var newnumber = number.substring(comma+1);
		stripNumber(newnumber,max);
	}
	if (comma==-1)
	{
		age = number;
		if (age>max)
		{
			errors = errors + 'The age '+age+' is too old for a child at this hotel. Maximum age: '+maxage+'\n\n';
			errorcheck = 1;
		}
	}
}

function setCurrency(c)
{
	document.cookie = "currency=" + c;
	url = document.URL;
	if (url.indexOf('?')>-1)
	{
		if (url.indexOf('currency=')>-1)
			document.location = url.substring(0, url.indexOf('currency=')) + "currency=" + c;
		else
			document.location = url + "&currency=" + c;
	}
	else
	{
		if (url.indexOf('currency=')>-1)
			document.location = url.substring(0, url.indexOf('currency=')) + "currency=" + c;
		else
		{
		  lastchar=url.length;
		  if (url[lastchar-1]=='/')
			document.location = url + "index_" + c+".htm";
		  else
		  {
		    if (url.indexOf('index_'))
		    {
			if (c=='gbp')
			{
			   pos=url.indexOf('index_');
			   document.location = url.substring(0,pos);		  	   
			}
			else
		  	{
			   pos=url.indexOf('index_');
	  	  	   document.location = url.substring(0,pos)+ "index_" + c+".htm";  
			}
		    }
		    else
			document.location = url + "?currency=" + c;
		  }
		}
	}
}

function getCurrency()
{
	cookie = document.cookie;
	broken_cookie = cookie.split(";");
	m = broken_cookie.length;

	for (i=0; i<m; i++)
	{
		broken_cookie[i] = trimCookie(broken_cookie[i]);
		if (broken_cookie[i]=='currency=usd')
			document.getElementById('usd').className = document.getElementById('usd').className + " sel";
		else if (broken_cookie[i]=='currency=euro')
			document.getElementById('euro').className = document.getElementById('euro').className + " sel";
		else
			document.getElementById('gbp').className = document.getElementById('gbp').className + " sel";
	}
}

function trimCookie(str)
{
	return str.replace(/^\s+/,"").replace(/\s+$/,"").replace(/\s+/g," ");
}

function resetAdvancedSearch()
{
	f = document.form;
	f.price.selectedIndex = 0;
	f.category.selectedIndex = 0;
	f.location.selectedIndex = 0;
	f.hotelname.selectedIndex = 0;
	f.facilities.selectedIndex = 0;
}

function selectAll()
{
 f=document.compareform;
 max=f.total.value;

 for (i=1; i<=max; i++)
 {
   if (document.newform.selectall.checked)
   {
     f['hotel'+i].checked=true;
   }
   else 
   {
     f['hotel'+i].checked=false;
   }
 }
}

function checkCompareForm()
{
 f=document.compareform;
 max=f.total.value;
 found=false;
 i=1;
 while (!found && i<=max)
 {
  if (f['hotel'+i].checked==true) found=true;
  else i++;
 }
 if (!found)
 {
   window.alert('Please select at least one hotel');
   return false;
 }
 else f.submit();
}

