window.onload = init;

function init() {
	// Call cookieMonster function to set current font size.
	cookieMonster();
	
	if (!document.getElementById('popup')) {
		startlist();
		if (document.getElementById('calendar')) initCalendar();
		//if (document.body.id == 'gallery') numberPhotos();
		if (document.body.id == 'facility-detail') nifty();
		if (document.all) fixSelect();
	}
//	fixEolas();
	msgStatusAllLinks();
}

window.onerror = function() {
    window.status = 'Error on page.';
}


function initCalendar() {
	var calendar = document.getElementById('calendar');
	var dates = calendar.getElementsByTagName('A');
	for (i=0; i<dates.length; i++) {
		dates[i].onclick = showDate;
	}
}

function showDate() {
	var calendar = document.getElementById('calendar');
	var dates = calendar.getElementsByTagName('A');
	for (i=0; i<dates.length; i++) {
		if (document.all) {
			if (document.getElementById('date-'+dates[i].innerText))
				document.getElementById('date-'+dates[i].innerText).style.display="none";
		} else {
			if (document.getElementById('date-'+dates[i].text))
				document.getElementById('date-'+dates[i].text).style.display="none";
		}
	}
	if (document.all) {
		if(document.getElementById('date-'+this.innerText))
			document.getElementById('date-'+this.innerText).style.display="block";
	} else {
		if(document.getElementById('date-'+this.text))
			document.getElementById('date-'+this.text).style.display="block";
	}
}

function nifty() {
	if(!NiftyCheck())
	    return;
	Rounded("h3","all","#FFF","#fc1921","smooth");
	Rounded("#left dt","all","#FFF","#f2f2f2","smooth");
	(document.all)?Rounded("li.even","bl br","#FFF","#f2f2f2","smooth"):Rounded("li.even","all","#FFF","#f2f2f2","smooth");
	Rounded("td#tl","tl","#FFF","#D9D9D9","smooth");
	Rounded("td#bl","bl","#FFF","#D9D9D9","smooth");
	Rounded("td#tr","tr","#FFF","#f2f2f2","smooth");
	Rounded("td#br","br","#FFF","#f2f2f2","smooth");
}

function fixSelect() {
	document.getElementById('outer-body').onscroll = hideSelect;
}

function decrease() {
	oHTML = document.getElementsByTagName('HTML')[0];
	oHTML.style.fontSize = parseInt(oHTML.style.fontSize)-10+"%";
//	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 increase() {
	oHTML = document.getElementsByTagName('HTML')[0];
	oHTML.style.fontSize = parseInt(oHTML.style.fontSize)+10+"%";
//	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.
		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.
		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 hideSelect() {
	for (i=0; i<document.getElementById('sidebar').getElementsByTagName('SELECT').length; i++) {
		oScroll = document.getElementById('outer-body').scrollTop;
//		oSelect = document.getElementById('selLocation');
//		oSelect = document.getElementById('selEnquiry');
		oSelect = document.getElementById('sidebar').getElementsByTagName('SELECT')[i];
		
		oTop = oSelect.offsetTop;
		oParent = oSelect.parentNode.parentNode;
		oParentTop = oParent.offsetTop;
//		window.status = "oScroll: "+ oScroll +" | oTop: "+ oTop +" | oParent["+oParent.tagName+"]: "+ oParentTop +" | oSum: "+ ((oTop + oParentTop) - oScroll) ;
		oSelect.style.display = ((oTop + oParentTop)- oScroll>-2)? 'inline':'none';
	}
}


var temp;
var allPhotos;
var objPopupWindow;

function popup(thisPhoto,allPhotos) {
title = document.title;
	// load variable with new content ready for display.
	var newContent = "";
	newContent += '<table cellspacing="0" cellpadding="12" border="0" width="100%" height="100%" style="font-size:100%;">';
	newContent += '	<tr style="background:#fc1921 url(img\/cnr_find.gif) no-repeat right bottom;">';
	newContent += '		<td height="50" colspan="3" style="color:#ffffff; padding-left:1em;" valign="top">';
	newContent += '			<a href="#" style="float:right; margin:0em 1em; color:#ffffff;" onclick="window.opener.focus(); window.close();">[ close window ]<\/a>';
	newContent += '			<span id="alt">'+thisPhoto.getElementsByTagName('IMG')[0].alt+'<\/span><\/td>';
	newContent += '	<\/tr><tr>';
	newContent += '		<td width="50%">&nbsp;<\/td>';
	newContent += '		<td style="text-align:center;" height="100%" valign="middle"><div class="shadow"><img id="src" src="'+thisPhoto.getElementsByTagName('img')[0].style.backgroundImage.replace(/url\(/i,'').replace(/_th./i,'.').replace(/\)/,'')+'" alt="'+thisPhoto.getElementsByTagName('IMG')[0].alt+'" title=""><img src="img\/image.gif" width="100%" height="100%" alt="'+thisPhoto.getElementsByTagName('IMG')[0].alt+'" title="" style="position:absolute; z-index:100; left:0px; top:0px; width:100%; height:280px;"><\/div><\/td>';
	newContent += '		<td width="50%">&nbsp;<\/td>';
	newContent += '	<\/tr><tr>';
	newContent += '		<td colspan="3" style="text-align:right;" id="navPhotos">';
	for (i=1;i<=numPhotos;i++) {
		 if (thisPhoto.getElementsByTagName('img')[0].style.backgroundImage.replace(/url\(/i,'').replace(/_th./i,'.').replace(/\)/,'') == allPhotos.getElementsByTagName('IMG')[i-1].style.backgroundImage.replace(/url\(/i,'').replace(/_th./i,'.').replace(/\)/,'')) {
			newContent += '<input type="text" id="valPhoto" value="'+i+'">'
		}
	}
	
	// Previous
	newContent += '<a href="#" target="popup" onclick="temp=(document.getElementById(\'valPhoto\').value>1)?parseInt(--document.getElementById(\'valPhoto\').value):1; document.getElementById(\'src\').src=allPhotos.getElementsByTagName(\'IMG\')[temp-1].style.backgroundImage.replace(/url\\(/i,\'\').replace(/_th./i,\'.\').replace(/\\)/,\'\'); document.getElementById(\'src\').alt=allPhotos.getElementsByTagName(\'IMG\')[temp-1].alt; document.getElementById(\'alt\').firstChild.nodeValue=allPhotos.getElementsByTagName(\'IMG\')[temp-1].alt; return false;"><img src="img\/mn_previous.gif" alt="&lt;" width="5" height="8" border="0" title="" hspace="8"> previous <\/a>';
	
	for (i=1; i<=numPhotos; i++) {
		if (i==1) newContent += ' &nbsp; [ ';
		// newContent += '<a href="'+allPhotos.getElementsByTagName('IMG')[i-1].style.backgroundImage.replace(/url\(/i,'').replace(/_th./i,'.').replace(/\)/,'')+'" target="popup" ';
		newContent += '<a href="#" ';
		newContent += 'onclick="document.getElementById(\'valPhoto\').value='+i+'; document.getElementById(\'src\').src=\''+allPhotos.getElementsByTagName('IMG')[i-1].style.backgroundImage.replace(/url\(/i,'').replace(/_th./i,'.').replace(/\)/,'')+'\'; document.getElementById(\'src\').alt=\''+allPhotos.getElementsByTagName('IMG')[i-1].alt+'\'; document.getElementById(\'alt\').firstChild.nodeValue=\''+allPhotos.getElementsByTagName('IMG')[i-1].alt+'\'; return false;" ';
		if (document.all) newContent += 'onmouseover="window.status=\'mouseover\'"';
		if (document.all) newContent += 'onmouseout="window.status=\'\'"';
		newContent += '> '+i+' <\/a>';
		if (i==numPhotos) { newContent += ' ] &nbsp; ' } else { newContent += ' | ' }
	}
	
	// Next
	newContent += ' <a href="#" target="popup" onclick="temp=(document.getElementById(\'valPhoto\').value<numPhotos)?parseInt(++document.getElementById(\'valPhoto\').value):numPhotos; document.getElementById(\'src\').src=allPhotos.getElementsByTagName(\'IMG\')[temp-1].style.backgroundImage.replace(/url\\(/i,\'\').replace(/_th./i,\'.\').replace(/\\)/,\'\'); document.getElementById(\'src\').alt=allPhotos.getElementsByTagName(\'IMG\')[temp-1].alt; document.getElementById(\'alt\').firstChild.nodeValue=allPhotos.getElementsByTagName(\'IMG\')[temp-1].alt; return false;"> next <img src="img\/mn_next.gif" alt="&gt;" width="5" height="8" border="0" title="" hspace="8"><\/a>';
	
	newContent += '		<\/td>';
	newContent += '	<\/tr>';
	newContent += '<\/table>';
	// Open popup window if not already open.
	// Check the window opener and the popup window object variable to determine the state of the popup window.
	// Also, since the user can close the popup window with the 'x' button in the window frame
	// (and there is no way of capturing this event specifically) we have to perform a objPopupWindow.closed check.
	if (objPopupWindow && !objPopupWindow.closed) {
		objPopupWindow.document.body.innerHTML = newContent;
	//	objPopupWindow.close();
	}
	else {
		// popup window isn't open, so launch it.
		//var objPopupWindow;
		objPopupWindow = window.open('','popup','width=660,height=420,scrollbars,status');
		objPopupWindow.document.write('<html>');
		objPopupWindow.document.write('<head>');
		objPopupWindow.document.write('<title>'+title+'<\/title>');
		objPopupWindow.document.write('<meta http-equiv="Content-Type" content="text\/html; charset=UTF-8">')
		objPopupWindow.document.write('<link rel="stylesheet" type="text\/css" href="inc\/style.css">');
		if (!document.all) objPopupWindow.document.write('<scr' + 'ipt language="javascript" type="text\/javascript" src="inc\/functions.js"><\/scr' + 'ipt>');
		objPopupWindow.document.write('<scr' + 'ipt>allPhotos = window.opener.document.getElementById("photos"); numPhotos = allPhotos.getElementsByTagName("IMG").length;<\/scr' + 'ipt>');
		objPopupWindow.document.write('<\/head>');
		objPopupWindow.document.write('<body id="popup" ');
		if (!document.all) objPopupWindow.document.write('onload="msgStatusAllLinks();" ');
		objPopupWindow.document.write('onunload="if(!document.all){ window.opener.focus(); window.close(); }">');
		objPopupWindow.document.write(newContent);
		objPopupWindow.document.write('<\/body>');
		objPopupWindow.document.write('<\/html>');
		objPopupWindow.document.close();
	}
	// focus on open popup window.
	objPopupWindow.focus();
}

function popImage(strURL){
	// Open popup window if not already open.
	// Check the window opener and the popup window object variable to determine the state of the popup window.
	// Also, since the user can close the popup window with the 'x' button in the window frame
	// (and there is no way of capturing this event specifically) we have to perform a objPopupWindow.closed check.
	if (objPopupWindow && !objPopupWindow.closed) {
		// Window is open. Reload it's contents with the new image.focus on it.
		objPopupWindow.focus();
		objPopupWindow.location.href = strURL;
	}
	else {
		// popup window isn't open, so launch it.
		// popup isn't open, so open it centred on screen.
		var xPos;
		var yPos;
		var wndHeight;
		var wndWidth;
		
		// Initialise variables 
		wndHeight = 560;  
		wndWidth = 660;  

		// when the popup window is launched.
		yPos = (screen.availHeight/2) - (wndHeight/2);
		xPos = (screen.availWidth/2) - (wndWidth/2);

		objPopupWindow = window.open (strURL,"Image","width=" + wndWidth + ",height=" + wndHeight + ",scrollbars,status");

	}
	// focus on open popup window.
	objPopupWindow.focus();
}

function attachFocus() {

	if (this.className.indexOf(" focus")<0) {
/*@cc_on
	/*@if (@_jscript_version < 5.5)
		// do nothing //
	@else @*/
		this.className+=" focus";
	/*@end
@*/
	}

	if (this.tempOnFocus) {
		// call existing onFocus event.
		this.tempOnFocus();
	}

}

function attachBlur() {

	if (this.className.indexOf(" focus")>0) {
		this.className = this.className.substring(0,this.className.indexOf(" focus"));
	} else {
		this.className.replace(" focus","");
	}

	if (this.tempOnBlur) {
		// call existing onBlur event.
		this.tempOnBlur();
	}

}

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) 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.');
			}
		} else {
			if (this.tagName=="AREA") {
				txtStatus=this.getAttribute('alt');
			}
		}
		if (this.tempOnMouseOver) {
			// call existing onMouseOver event.
			this.tempOnMouseOver();
		}
	}
	// txtStatus=toTitleCase(txtStatus);
	if (txtStatus.length != 0) {
		window.status=toTitleCase(txtStatus);
	}
	if (this.getElementsByTagName('img')[0]) {
		oHelp = this.getElementsByTagName('img')[0].src.indexOf('icon_font');
//		alert(document.getElementsByTagName('HTML')[0].style.fontSize);
		if (oHelp >= 0) window.status += " (currently "+ (parseInt(document.getElementsByTagName('HTML')[0].style.fontSize) +30) +"%)";
	}
	return true;
}

function msgStatusOff() {
	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 bodyResize() {
	window.location.href = window.location.href;
}

function msgStatusAllLinks() {
	for(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);

				}		


	}
}

// 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;
}


// 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("navlist")) { 
			navRoot = document.getElementById("navlist");
			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", "");
					}
				}
			}
		}
	}
}

// toggleNav (show/hide sublist)
function toggleNav(strID) {

	var oDiv;

	if (oDiv = document.getElementById(strID)) {
		oDiv.style.display = oDiv.style.display == 'none' ? 'block' : 'none';
	}
	
	return false;

}


// toggleListActionSymbol used by 2nd level navigation code to ensure that a 3rd level's parent div has the correct action symbol (e.g. '+' or '-')
function toggleListActionSymbol(strID) {
	var oSideNavSelectedListActionSymbol;
    oSideNavSelectedListActionSymbol = document.getElementById("imgListAction" + strID);
	alert(oSideNavSelectedListActionSymbol.src);
	// Toggle the symbol.
	if (oSideNavSelectedListActionSymbol.src == 'img/bn_expand.gif') {
		oSideNavSelectedListActionSymbol.src = 'img/bn_contract.gif';
	} else {
		oSideNavSelectedListActionSymbol.src = 'img/bn_expand.gif';	
	}
    return false;
}

/*
OLD CODE
// toggleSiteNav used by 2nd level navigation code to display/hide any third level nav elements.
function toggleSiteNav(strID) {

	var oSideNavDiv;
	var oSideNavListActionSymbol;
	var oSideNavSelectedListActionSymbol;
*/	
	/* ***** CODE PROCEDURE *****
	
	1)Set all list symbols (e.g. +, -) to '+'.
	2)Set the list symbol to '-' for the selected div.
	3) Close all other open divs before opening the currently selected one:
	Loop through all divs which have the first part of their ID called 'expandNav'.  The full div names may look like expandNav1, expandNav2, etc... 
	but at this point in the code the actual amount of Divs (expandNav1, expandNav2, etc.) is unknown so we can only refer to them based on the first part of their IDs.

		Step 3.1.  Get a reference to the Div that contains the entire side nav.  It has the basic structure as follows;
		<div id="nav">
		<ul class="mainlist">
			<li>2nd level nav item one</li>
			<div id="expandNav1">third level nav here</div>
			...
		</ul>
		</div>

		Step 3.2.  Once obtaining to the nav ID in Step 1, get all 'div' tag elements (this will effectively reference all the expandable 3rd level nav groups)
		Step 3.3.  Set all 3rd level nav group Div's to be hidden, and set the display of the group Div (defined by the strID value passed into this function) to be 'block'
    
    */

/*
	// 1) Change the appearance of the little + and - symbols appropriately.  Set all symbols to '+'. 
    oSideNavListActionSymbol = document.getElementById("sidenavUL").getElementsByTagName("img");
    for (i=0; i<oSideNavListActionSymbol.length; i++) {		
	    oSideNavListActionSymbol[i].src = 'img/bn_expand.gif';	
    }

	// 2) Set the action symbol to '-' to indicate the list is opened for this particular div.
    oSideNavSelectedListActionSymbol = document.getElementById("imgListAction" + strID);
    oSideNavSelectedListActionSymbol.src = 'img/bn_contract.gif';

    
    // 3)
	oSideNavDiv = document.getElementById("sidenav").getElementsByTagName("div");
	for(var i = 0; i < oSideNavDiv.length; i++){
		// Set all Divs to display 'none' except for the one defined by strID, which should be set to 'block'.
		oSideNavDiv[i].style.display = oSideNavDiv[i].id == 'expandNav' + strID ? 'block' : 'none';				
	}

	return false;

}
*/

// toggleSiteNav used by 2nd level navigation code to display/hide any third level nav elements.
function toggleSiteNav(strID) {

	var oSideNavDiv;

	oSideNavDiv = document.getElementById("nav").getElementsByTagName("div");

	for(var i = 0; i < oSideNavDiv.length; i++){
		// Set all Divs to display 'none' except for the one defined by strID, which should be set to 'block'.
		oSideNavDiv[i].style.display = oSideNavDiv[i].id == 'expandNav' + strID ? 'block' : 'none';				
	}

	return false;

}

//
function findAction(regionType, pageID, regionID){
	var frmAction;

	if(regionType == "region"){
		frmAction = "../htm/htm_facility_listing.asp?page_id="+pageID+"&search_tool=map&region_id="+regionID;
	}else{
		frmAction = "../htm/htm_facility_listing.asp?page_id="+pageID+"&search_tool=search";
	}
	document.frmFind.action =  frmAction;
}

function hideCalendar() {
	document.getElementById('calendar').style.display = 'none';
}
function showCalendar() {
	document.getElementById('calendar').style.display = 'inline';
}

