function checkEnter(e){ //e is event object passed from function invocation
	var characterCode; //literal character code will be stored in this variable

	if(e && e.which){ //if which property of event object is supported (NN4)
		e = e;
		characterCode = e.which; //character code is contained in NN4's which property
	} else {
		e = event;
		characterCode = e.keyCode; //character code is contained in IE's keyCode property
	}
	
	if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
		return true;
	} else {
		return false; 
	}

}

//check if enter is pressed in which case submit the login form
function checkEnterAndLogin(event) {
	if (checkEnter(event)){ 
		document.forms.login.submit();
	} 	
}

function login() {
	document.forms.login.submit(); 	
}

function expandAndGoTo(spanName,url) {
	//toggle navs and update cookie
	isGoTo = showhide(spanName,2);
	//move to specified location
	if (isGoTo) {
		self.location.href = url;
	}
}

//Toggle the navs
function toggleNavs(spanName)
{
	//Toggle the nav chosen
	showhide(spanName,2);
}

// Hide or collapse a given section and update the cookies
function showhide(spanName, disp)
{
	var p = this;
	var w = eval( "p.document.all." + spanName + ".style" );

	switch(disp)
	{
		case 2: // toggle current setting
			//w.display = ((w.display=="inline") ? "none" : "inline");
			w.display = "inline";
			update = ((w.display=="inline") ? addNavCookieSetting(spanName) : removeNavCookieSetting(spanName));
			return (w.display=="inline");
			break;
		
		case 0: // Hide
			w.display = "none";
			update = removeNavCookieSetting(spanName);
			return false;
			break;
		
		case 1: // Show
			update = addNavCookieSetting(spanName);
			w.display = "inline";
			return true;
			break;
	}
}

//validate the userform and submit
function validate_userform()
{
	document.forms.userDetails.submit(); 
}

//validate the password reset form and submit
function validate_passwordreset()
{
	document.forms.passwordReset.submit(); 
}

//validate the contactus form and submit
function validate_contactusform()
{
	document.forms.contactus.submit(); 
}

//validate the comment form and submit
function validate_commentform()
{
	document.forms.comment.submit(); 
}

//validate a generic forms event and submit
function validate_form(form, event)
{
	form.event.value = event;
	form.submit(); 
}

//validate a generic list forms event and submit and start position
function validate_list_form(form, event, start)
{
	form.start.value = start;
	validate_form(form, event);
}

//validate the holiday diary and submit
function validate_holidaydiary(statusId)
{
	document.forms.holidayDiary.statusId.value=statusId;
	document.forms.holidayDiary.submit(); 
}

//function to trim leading and trailing spaces from a string
function trim(str)
{  
	while(str.charAt(0) == (" ") )
	{  
		str = str.substring(1);
	}
	while(str.charAt(str.length-1) == " " )
	{  
		str = str.substring(0,str.length-1);
	}
	return str;
}

//function to roll over document element and change the class
function changeClass(objectId, newClass) 
{
	if (navigator.appName == "Microsoft Internet Explorer") {
		document.getElementById(objectId).setAttribute('className',newClass);
	} else {
		document.getElementById(objectId).setAttribute('class',newClass);
	}
}

//function to email data to a friend
function emailAFriend(sectionType,sectionCode)
{
	path = '/pages/general/emailAFriend.php?sectionType=' + sectionType + '&sectionCode=' + sectionCode;
	width='400';
	height='650';
	dimension="width="+width+",height="+height
	window.open(path,"emailAFriend",dimension);
}

//function to send an enquiry to the vendor
function sendEnquiry(sectionType,sectionCode)
{
	path = '/pages/general/sendHolidayEnquiry.php?sectionType=' + sectionType + '&sectionCode=' + sectionCode;
	width='650';
	height='700';
	dimension="scrollbars=1,width="+width+",height="+height
	window.open(path,"sendEnquiry",dimension);
}

//function to make id inline
function makeInline(id) {
	if (document.getElementById(id)!=null) {
		document.getElementById(id).style.display='inline';
	}
}

//SuckerTree Vertical Menu 1.1 (Nov 8th, 06)
//By Dynamic Drive: http://www.dynamicdrive.com/style/

var menuids=["navigation1","navigation2","navigation3"] //Enter id(s) of SuckerTree UL menus, separated by commas

function buildsubmenus(){
for (var i=0; i<menuids.length; i++){
  if (null==document.getElementById(menuids[i])) {
  	break;
  }
  var ultags=document.getElementById(menuids[i]).getElementsByTagName("ul");
    for (var t=0; t<ultags.length; t++){
    ultags[t].parentNode.getElementsByTagName("a")[0].className="subfolderstyle"
		if (ultags[t].parentNode.parentNode.id==menuids[i]) //if this is a first level submenu
			ultags[t].style.left=ultags[t].parentNode.offsetWidth+"px" //dynamically position first level submenus to be width of main menu item
		else //else if this is a sub level submenu (ul)
		  ultags[t].style.left=ultags[t-1].getElementsByTagName("a")[0].offsetWidth+"px" //position menu to the right of menu item that activated it
    ultags[t].parentNode.onmouseover=function(){
    this.getElementsByTagName("ul")[0].style.display="block"
    }
    ultags[t].parentNode.onmouseout=function(){
    this.getElementsByTagName("ul")[0].style.display="none"
    }
    }
		for (var t=ultags.length-1; t>-1; t--){ //loop through all sub menus again, and use "display:none" to hide menus (to prevent possible page scrollbars
		ultags[t].style.visibility="visible"
		ultags[t].style.display="none"
		}
  }
}

if (window.addEventListener)
window.addEventListener("load", buildsubmenus, false)
else if (window.attachEvent)
window.attachEvent("onload", buildsubmenus)

