
// List of functions to run when page loads.
// Comment out any that aren't required.
function init() {
// Call cookieMonster function to set current font size.
	cookieMonster();
	startlist();
//	fixEolas();
	msgStatusAllLinks();
	if (document.form) setFocus();
}

// Function that builds an array of functions to be executed during the onload event of the window. 
// To add new functions, use window.onload.actions.push(functionName);
window.onload = function () {
	for(var ii = 0; arguments.callee.actions.length > ii; ii++)
		arguments.callee.actions[ii]();
};
window.onload.actions = [];

// Call the init() function onload.
window.onload.actions.push(init);

window.onerror = function() {
    window.status = 'Error on page.';
}

// setFocus (clear form text field contents onfocus)
function setFocus(oCtl) {
    if (oCtl.value == oCtl.defaultValue) oCtl.value = '';
}


// Dropdown Submenu
// submenus function in modern browsers via CSS only;
// however, IE5, IE5.5, IE6 require this Javascript in order to function

function startlist() {
	if (document.all&&document.getElementById) {
		if (document.getElementById("nav")) { 
			navRoot = document.getElementById("nav");
			for (i=0; i<navRoot.childNodes.length; i++) { 
				node = navRoot.childNodes[i];
				if (node.nodeName=="LI") { 
					node.onmouseover=function() { 
						this.className+=" hover";			
					}
					node.onmouseout=function() {
						this.className=this.className.replace(" hover", "");
					}
				}
			}
		}
	}
}


function msgStatusAllLinks() {
	for(var i=0; i<document.links.length; i++) {
		if (!document.links[i].onmouseover) {
			document.links[i].onmouseover=msgStatus;
			document.links[i].onmouseout=msgStatusOff;
		} else {
				// Add element's existing onmouseover/out event (if it has one) before adding a new onmouseover/out event 'msgStatus/msgStatusOff'
				// This ensures that any existing onmouseover/out event the element has is still executed, as well as the 'msgStatus/msgStatusOff' event.
				// Check if IE or Netscape and use appropriate syntax accordingly.
				if (navigator.appName == 'Microsoft Internet Explorer') {
					if (document.links[i].onmouseover) {
						// Assign existing onmouseover to a temp event 'tempOnMouseOver' - Later executed in msgStatus function.
						document.links[i].tempOnMouseOver = document.links[i].onmouseover;
					}
					if (document.links[i].onmouseout) {
						// Assign existing onmouseout to a temp event 'tempOnMouseOut' - Later executed in msgStatusOff function.
						document.links[i].tempOnMouseOut = document.links[i].onmouseout;
					}
					// attach new event. This will trigger the rollover.
					document.links[i].onmouseover=msgStatus;
					document.links[i].onmouseout=msgStatusOff;
				}
				else {
					// attach existing blur/focus event.
					document.links[i].addEventListener('mouseover',msgStatus,false);
					document.links[i].addEventListener('mouseout',msgStatusOff,false);
				}		
		}
	}
	for(i=0; i<document.getElementsByTagName('input').length; i++) {
		switch(document.getElementsByTagName('input')[i].type) {
			case 'image': // form button is an <input type="image"> (graphic);
			case 'button': // form button is an <input type="button"> (webtext);
			case 'submit': // form button is an <input type="submit"> (webtext);
			case 'reset': // form button is an <input type="reset"> (webtext);
				document.getElementsByTagName('input')[i].onmouseover=msgStatus;
				document.getElementsByTagName('input')[i].onmouseout=msgStatusOff;
				break;
			case 'text':
			case 'password':
				// Add element's existing blur/focus event (if it has one) before adding a new blur/focus event 'attachBlur/Focus'
				// This ensures that any existing onBlur/onFocus event the element has is still executed, as well as the 'attachBlur/Focus' event.
				// Check if IE or Netscape and use appropriate syntax accordingly.
				if (navigator.appName == 'Microsoft Internet Explorer') {

					if (document.getElementsByTagName('input')[i].onblur) {
						// Assign existing onBlur to a temp event 'tempOnBlur' - Later executed in attachBlur function.
						document.getElementsByTagName('input')[i].tempOnBlur = document.getElementsByTagName('input')[i].onblur;
					}

					if (document.getElementsByTagName('input')[i].onfocus) {
						// Assign existing onBlur to a temp event 'tempOnFocus' - Later executed in attachFocus function.
						document.getElementsByTagName('input')[i].tempOnFocus = document.getElementsByTagName('input')[i].onfocus;
					}

					// attach new event. This will cause the input field colour to change.
					document.getElementsByTagName('input')[i].onfocus=attachFocus;
					document.getElementsByTagName('input')[i].onblur=attachBlur;

				}
				else {
				
					// attach existing blur/focus event.
					document.getElementsByTagName('input')[i].addEventListener('focus',attachFocus,false);
					document.getElementsByTagName('input')[i].addEventListener('blur',attachBlur,false);

				}		
				break;
			default:
				break;
		}
	}
	for(i=0; i<document.getElementsByTagName('textarea').length; i++) {
//		document.getElementsByTagName('textarea')[i].onfocus=attachFocus;
//		document.getElementsByTagName('textarea')[i].onblur=attachBlur;

				// Add element's existing blur/focus event (if it has one) before adding a new blur/focus event 'attachBlur/Focus'
				// This ensures that any existing onBlur/onFocus event the element has is still executed, as well as the 'attachBlur/Focus' event.
				// Check if IE or Netscape and use appropriate syntax accordingly.
				if (navigator.appName == 'Microsoft Internet Explorer') {

					if (document.getElementsByTagName('textarea')[i].onblur) {
						// Assign existing onBlur to a temp event 'tempOnBlur' - Later executed in attachBlur function.
						document.getElementsByTagName('textarea')[i].tempOnBlur = document.getElementsByTagName('textarea')[i].onblur;
					}

					if (document.getElementsByTagName('textarea')[i].onfocus) {
						// Assign existing onBlur to a temp event 'tempOnFocus' - Later executed in attachFocus function.
						document.getElementsByTagName('textarea')[i].tempOnFocus = document.getElementsByTagName('textarea')[i].onfocus;
					}

					// attach new event. This will cause the input field colour to change.
					document.getElementsByTagName('textarea')[i].onfocus=attachFocus;
					document.getElementsByTagName('textarea')[i].onblur=attachBlur;

				}
				else {
				
					// attach existing blur/focus event.
					document.getElementsByTagName('textarea')[i].addEventListener('focus',attachFocus,false);
					document.getElementsByTagName('textarea')[i].addEventListener('blur',attachBlur,false);

				}		


	}
	for(i=0; i<document.getElementsByTagName('select').length; i++) {
//		document.getElementsByTagName('select')[i].onfocus=attachFocus;
//		document.getElementsByTagName('select')[i].onblur=attachBlur;

				// Add element's existing blur/focus event (if it has one) before adding a new blur/focus event 'attachBlur/Focus'
				// This ensures that any existing onBlur/onFocus event the element has is still executed, as well as the 'attachBlur/Focus' event.
				// Check if IE or Netscape and use appropriate syntax accordingly.
				if (navigator.appName == 'Microsoft Internet Explorer') {

					if (document.getElementsByTagName('select')[i].onblur) {
						// Assign existing onBlur to a temp event 'tempOnBlur' - Later executed in attachBlur function.
						document.getElementsByTagName('select')[i].tempOnBlur = document.getElementsByTagName('select')[i].onblur;
					}

					if (document.getElementsByTagName('select')[i].onfocus) {
						// Assign existing onBlur to a temp event 'tempOnFocus' - Later executed in attachFocus function.
						document.getElementsByTagName('select')[i].tempOnFocus = document.getElementsByTagName('select')[i].onfocus;
					}

					// attach new event. This will cause the input field colour to change.
					document.getElementsByTagName('select')[i].onfocus=attachFocus;
					document.getElementsByTagName('select')[i].onblur=attachBlur;

				}
				else {
				
					// attach existing blur/focus event.
					document.getElementsByTagName('select')[i].addEventListener('focus',attachFocus,false);
					document.getElementsByTagName('select')[i].addEventListener('blur',attachBlur,false);

				}		


	}
}

function msgStatus() {
	if (this.tagName=="INPUT") {
		switch(this.type) {
			case 'image': // form button is an <input type="image"> (graphic);
				if (this.getAttribute('src').indexOf('_a.')!=-1) {
					this.src = this.getAttribute('src').replace('_a.','_b.');
					txtStatus=this.getAttribute('alt');
				}
				if (this.getAttribute('src').indexOf('-a.')!=-1) {
					this.src = this.getAttribute('src').replace('-a.','-b.');
					txtStatus=this.getAttribute('alt');
				}
				break;
			case 'button': // form button is an <input type="button"> (webtext);
			case 'submit': // form button is an <input type="submit"> (webtext);
			case 'reset': // form button is an <input type="reset"> (webtext);
			case 'file': // form button is an <input type="file"> (webtext);
				this.className = this.className.replace("bnout","bnover");
				txtStatus=this.getAttribute('value');
				break;
			default:
				break;
		}
	} else {
		if (this.name) {
			for (i=0;i<document.getElementsByName(this.name).length;i++) {
				if (document.getElementsByName(this.name)[i]!=this) {
					if (document.getElementsByName(this.name)[i].tagName=='A') {
						if (document.getElementsByName(this.name)[i].getElementsByTagName('img').length!=0) {
							if (document.getElementsByName(this.name)[i].getElementsByTagName('img')[0].src.indexOf('_a.')!=-1) {
								document.getElementsByName(this.name)[i].getElementsByTagName('img')[0].src = document.getElementsByName(this.name)[i].getElementsByTagName('img')[0].src.replace('_a.','_b.');
							}
							if (document.getElementsByName(this.name)[i].getElementsByTagName('img')[0].src.indexOf('-a.')!=-1) {
								document.getElementsByName(this.name)[i].getElementsByTagName('img')[0].src = document.getElementsByName(this.name)[i].getElementsByTagName('img')[0].src.replace('-a.','-b.');
							}
						} else {
							document.getElementsByName(this.name)[i].className="rollover";
						}
					}
				}
			}
		}
		if (this.innerText) {
			txtStatus=this.innerText;
		} else {
			if (this.text) var txtStatus=this.text;
		}
		if (this.getElementsByTagName('img').length!=0) {
			txtStatus=this.getElementsByTagName('img')[0].getAttribute('alt');
			if (this.getElementsByTagName('img')[0].src.indexOf('_a.')!=-1) {
				this.getElementsByTagName('img')[0].src = this.getElementsByTagName('img')[0].src.replace('_a.','_b.');
			}
			if (this.getElementsByTagName('img')[0].src.indexOf('-a.')!=-1) {
				this.getElementsByTagName('img')[0].src = this.getElementsByTagName('img')[0].src.replace('-a.','-b.');
			}
			if (this.tempOnMouseOver) {
				// call existing onMouseOver event.
				this.tempOnMouseOver();
			}
		} else {
			if (this.tagName=="AREA") {
				if (this.tempOnMouseOver) {
					// call existing onMouseOver event.
					this.tempOnMouseOver();
				}
				txtStatus=this.getAttribute('alt');
			}
		}
	}
	// txtStatus=toTitleCase(txtStatus);
	window.status=toTitleCase(txtStatus); return true;
}

function msgStatusOff() {
	var txtStatus=window.defaultStatus;
	if (this.tagName=="INPUT") {
		switch(this.type) {
			case 'image': // form button is an <input type="image"> (graphic);
				if (this.getAttribute('src').indexOf('_b.')!=-1) {
					this.src = this.getAttribute('src').replace('_b.','_a.');
				}
				if (this.getAttribute('src').indexOf('-b.')!=-1) {
					this.src = this.getAttribute('src').replace('-b.','-a.');
				}
				break;
			case 'button': // form button is an <input type="button"> (webtext);
			case 'submit': // form button is an <input type="submit"> (webtext);
			case 'reset': // form button is an <input type="reset"> (webtext);
				this.className = this.className.replace("bnover","bnout");
				break;
			default:
				break;
		}
	} else {
		if (this.name) {
			for (i=0;i<document.getElementsByName(this.name).length;i++) {
				if (document.getElementsByName(this.name)[i]!=this) {
					if (document.getElementsByName(this.name)[i].tagName=='A') {
						if (document.getElementsByName(this.name)[i].getElementsByTagName('img').length!=0) {
							if (document.getElementsByName(this.name)[i].getElementsByTagName('img')[0].src.indexOf('_b.')!=-1) {
								document.getElementsByName(this.name)[i].getElementsByTagName('img')[0].src = document.getElementsByName(this.name)[i].getElementsByTagName('img')[0].src.replace('_b.','_a.');
							}
							if (document.getElementsByName(this.name)[i].getElementsByTagName('img')[0].src.indexOf('-b.')!=-1) {
								document.getElementsByName(this.name)[i].getElementsByTagName('img')[0].src = document.getElementsByName(this.name)[i].getElementsByTagName('img')[0].src.replace('-b.','-a.');
							}
						} else {
							document.getElementsByName(this.name)[i].className="";
						}
					}
				}
			}
		}
		if (this.tempOnMouseOut) {
			// call existing onMouseOut event.
			this.tempOnMouseOut();
		}
	}
	if (this.getElementsByTagName('img').length!=0 && this.getElementsByTagName('img')[0].src.indexOf('_b.')!=-1 && this.getElementsByTagName('img')[0].name.indexOf('img_')==-1) {
		this.getElementsByTagName('img')[0].src = this.getElementsByTagName('img')[0].src.replace('_b.','_a.');
	}
	if (this.getElementsByTagName('img').length!=0 && this.getElementsByTagName('img')[0].src.indexOf('-b.')!=-1 && this.getElementsByTagName('img')[0].name.indexOf('img_')==-1) {
		this.getElementsByTagName('img')[0].src = this.getElementsByTagName('img')[0].src.replace('-b.','-a.');
	}
	window.status=txtStatus; return true;
}

function attachFocus() {

	if (this.className.indexOf(" focus")<0) {
		this.className = this.className + " focus";
	}

	if (this.tempOnFocus) {
		// call existing onFocus event.
		this.tempOnFocus();
	}

}

function attachBlur() {
	if (this.className.indexOf(" focus") > -1) {
		this.className = this.className.replace(" focus","");
	}

	if (this.tempOnBlur) {
		// call existing onBlur event.
		this.tempOnBlur();
	}

}

// toTitleCase
function toTitleCase(strString) {
	// strString = fnTrim(strString);
	var firstSpace = strString.indexOf(' ');
	var currentWord;
	strString = strString.charAt(0).toUpperCase()+strString.substring(1,strString.length);
	if (firstSpace > -1) strString=strString.substring(0,firstSpace+1) + toTitleCase(strString.substring(firstSpace+1,strString.length));
	return strString;
}


function fontSizeNormal() {
	oHTML = document.getElementsByTagName('HTML')[0];
	oHTML.style.fontSize = "70%";
//	window.status += oHTML.style.fontSize;

	// Update the cookie that holds the font size setting. Do this by calling the cookieMonster function, which
	// looks at the oHTML.style.fontSize; and updates the cookie value accordingly.  If a cookie doesn't exist it creates one.
	updateCookie();
}

function fontSizeLarge() {
	oHTML = document.getElementsByTagName('HTML')[0];
	oHTML.style.fontSize = "100%";
//	window.status += oHTML.style.fontSize;

	// Update the cookie that holds the font size setting. Do this by calling the cookieMonster function, which
	// looks at the oHTML.style.fontSize; and updates the cookie value accordingly.  If a cookie doesn't exist it creates one.
	updateCookie();
}

function cookieMonster() {
	// This function looks at the oHTML.style.fontSize; and updates the cookie value accordingly.  If a cookie doesn't exist it creates one.
	var oHTML = document.getElementsByTagName('HTML')[0];

	// Look for the cookie that holds font size.  If found, set document to that font size, else set cookie to current font size.
	if(readCookie('fontSize')==null) {
		// No cookie found. Create a new cookie that is set to the font size as defined in the HTML tag on the page (70%).
		createCookie('fontSize',parseInt(oHTML.style.fontSize),365);	
	} else {
		// Cookie found.  Set the HTML font size to the value of the cookie.
		// alert(oHTML.style.fontSize);
		oHTML.style.fontSize = readCookie('fontSize')+"%";
//		window.status += readCookie('fontSize');
	}

	//alert('cookieMonster: ' + readCookie('fontSize'));
}

function updateCookie() {
	var oHTML = document.getElementsByTagName('HTML')[0];

	// Check if the cookie exists.  If not, create one.
	if(readCookie('fontSize')==null) {
		// Create a new cookie that is set to the font size as defined in the HTML tag on the page (70%).
		cookieMonster();	
	} else {
		// Cookie exists, so update it's value.  Look at the recently set font size as defined in the HTML tag on the page, which will have been increased/decreased.
		// alert(oHTML.style.fontSize);
		createCookie('fontSize',parseInt(oHTML.style.fontSize),365);
	}
}

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);
}

function searchRegion(oSelectList){
	location = 'htm_gallery.asp?page_id=3&tour_id=' + oSelectList.value;
}

function searchBlogs(oSelectList){
	location = 'htm_blog_list.asp?page_id=6&tour_id=' + oSelectList.value;
}
