function HideChildElements(ParentElement)
{
	var x = document.getElementById(ParentElement);
	cleanElement(x);
	//x.style.display = 'none';
	
	var y = x.firstChild;
	//y.style.display = 'none';
	do
	{
      	y.style.display  = 'none';
  	}
	while (y = y.nextSibling);
	//x.style.display = 'block';
	
	ShowSelection(ReadCookie('AdventureType'));
}



// removes all #text elements directly attached to the node. This makes firstChild/nextSibling work in FF which counts whitespace as children.
function cleanElement(element)
{		
	if (element == null) return 0;
	var numTextElementsRemoved = 0;
	var node = element.firstChild;
	while (node != null)
	{
		var tmp = node.nextSibling;
		if (node.nodeName == '#text')
		{	
			element.removeChild(node);
			numTextElementsRemoved++;
		}
		node = tmp;
	}
	return numTextElementsRemoved;
}
	
	
	
function ShowSelection(divid){
	var x = document.getElementById('divSelectedItem');
	
	var y = x.firstChild;
	do{
   		if(y.id == divid){
			//y.style.display  = 'block';
			Effect.SlideDown(y.id.toString());
			WriteCookie('AdventureType', divid, 1);
		}
		else{
			y.style.display  = 'none';
		}
	}while (y = y.nextSibling);
	Effect.SlideUp('divGeneralInfo');
	scrollTo(0,0);
}



function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}


function TogglePhoneNumber() {
	strReferrer = document.referrer;
	
	if (strReferrer.indexOf("telegraph.co.uk") >= 0 || ReadCookie('Referrer') == 'telegraph.co.uk' ) {
		document.getElementById('divContactTel522772').style.display = 'none';
		document.getElementById('divContactTel560610').style.display = 'block';
		
		WriteCookie('Referrer', 'telegraph.co.uk', 30);
	}
}


function ToggleMenuList(menulistid){
	
	var menulist = document.getElementById(menulistid);
	if (menulist.className=="menulist showmenulist") {
		menulist.className="menulist hidemenulist";
	} else {
		menulist.className="menulist showmenulist";
		//if(menulistid == 'ulSpecialSub') {
		//	window.location = 'pageview.aspx?pageid=20';
		//}
	}
	
}


function ToggleSendToAFriendForm(){
	
	if (document.getElementById('stafSendToAFriend_divSendToAFriendForm').style.display == 'none') {
		document.getElementById('stafSendToAFriend_divSendToAFriendForm').style.display = 'block';
		document.getElementById('stafSendToAFriend_txtSenderName').value = ReadCookie('FirstName') + ' ' + ReadCookie('LastName');
		document.getElementById('stafSendToAFriend_txtSenderEmail').value = ReadCookie('Email');
	} else {
		document.getElementById('stafSendToAFriend_divSendToAFriendForm').style.display = 'none';	
	}
	
}


function TogglePageHistory(){
	
	if (document.getElementById('phPageHistory_divPageHistory').style.display == 'none') {
		document.getElementById('phPageHistory_divPageHistory').style.display = 'block';
	} else {
		document.getElementById('phPageHistory_divPageHistory').style.display = 'none';	
	}
	
}


function ToggleMoreInfo(){
	
	//if (document.getElementById('divMainContent2').style.display == 'none') {
	//	document.getElementById('divMainContent1').style.display = 'none';
	//	document.getElementById('divMainContent2').style.display = 'block';
	//} else {
	//	document.getElementById('divMainContent1').style.display = 'block';
	//	document.getElementById('divMainContent2').style.display = 'none';	
	//}
	
	//Effect.toggle('divMainContent1', 'blind');
	
	//scroll(0,0);
	
	Effect.toggle('divMainContent2', 'blind');
}


function WriteCookie(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(cookieName) {
 var theCookie=""+document.cookie;
 var ind=theCookie.indexOf(cookieName);
 if (ind==-1 || cookieName=="") return ""; 
 var ind1=theCookie.indexOf(';',ind);
 if (ind1==-1) ind1=theCookie.length; 
 return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}


function ValidateSendToAFriendForm(){
	var SenderEmail		= document.getElementById('txtSenderEmail').value;
	var FriendEmail		= document.getElementById('txtFriendEmail').value;
	var SenderValid		= validateEmail(SenderEmail,1,1);
	var FriendValid		= validateEmail(FriendEmail,1,1);
	var SenderName		= "" + document.getElementById('txtSenderName').value;
	var FriendName		= "" + document.getElementById('txtFriendName').value;

	if (!SenderValid) return false;
	if (!FriendValid) return false;
	if (SenderName.length < 3){ alert('Please enter your name.'); return false; }
	if (FriendName.length < 3){ alert('Please enter your friend\'s name'); return false; }
	
	document.getElementById('hidPageTitle').value = document.title;
	
	return true;
}


// Email Validation Javascript
// copyright 23rd March 2003, by Stephen Chapman, Felgall Pty Ltd

// You have permission to copy and use this javascript provided that
// the content of the script is not changed in any way.

function validateEmail(addr,man,db) {
if (addr == '' && man) {
   if (db) alert('email address is mandatory');
   return false;
}
if (addr == '') return true;
var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
for (i=0; i<invalidChars.length; i++) {
   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
      if (db) alert('email address contains invalid characters');
      return false;
   }
}
for (i=0; i<addr.length; i++) {
   if (addr.charCodeAt(i)>127) {
      if (db) alert("email address contains non ascii characters.");
      return false;
   }
}

var atPos = addr.indexOf('@',0);
if (atPos == -1) {
   if (db) alert('email address must contain an @');
   return false;
}
if (atPos == 0) {
   if (db) alert('email address must not start with @');
   return false;
}
if (addr.indexOf('@', atPos + 1) > - 1) {
   if (db) alert('email address must contain only one @');
   return false;
}
if (addr.indexOf('.', atPos) == -1) {
   if (db) alert('email address must contain a period in the domain name');
   return false;
}
if (addr.indexOf('@.',0) != -1) {
   if (db) alert('period must not immediately follow @ in email address');
   return false;
}
if (addr.indexOf('.@',0) != -1){
   if (db) alert('period must not immediately precede @ in email address');
   return false;
}
if (addr.indexOf('..',0) != -1) {
   if (db) alert('two periods must not be adjacent in email address');
   return false;
}
var suffix = addr.substring(addr.lastIndexOf('.')+1);
if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
   if (db) alert('invalid primary domain in email address');
   return false;
}
return true;
}