/* Start subnav resize functions */

function setSubnavHeight()
{

	// ***********
	// BODY HEIGHT
	// ***********
	windowHeightPX = document.documentElement.clientHeight || document.body.clientHeight;
	innerHeightPX = document.getElementById('inner').offsetHeight;
	
	if (innerHeightPX < windowHeightPX)
	{
		document.getElementById('inner').style.height = windowHeightPX + 'px';
	}
	
	
	// ***********
	// SUBNAV
	// ***********
	
	var colLeftDiv = document.getElementById('subnav');
	var colRightDiv = document.getElementById('colLeft');
	var subnavDiv = document.getElementById('subnavInner');
	var subnavFooter = document.getElementById('subnavFooter');
	
	//check to the see if this page has a subnav
	if(subnavDiv != null){
		if(colLeftDiv != null)
		{
			var colLeftDivHeight = colLeftDiv.offsetHeight;
		}
		if(colRightDiv != null){
		
			var colRightDivHeight = colRightDiv.offsetHeight;
			
		}
		
		//offset to cater for subnav header / footer / padding
		var subnavOffsetHeight = "20";
		var subnavDivHeight = subnavDiv.offsetHeight;
	
		//match height to the tallest div out of colLeft and colRight
		if((colLeftDivHeight > colRightDivHeight) || (colRightDivHeight == null))
		{
			offSetHeight = colLeftDivHeight - subnavDivHeight - subnavOffsetHeight;
			subnavDiv.style.height = subnavDivHeight + offSetHeight + 'px';
		}
		else
		{
			offSetHeight = colRightDivHeight - subnavDivHeight - subnavOffsetHeight;
			subnavDiv.style.height = subnavDivHeight + offSetHeight + 'px';
		}
	}
}

//fire off resize function when DOM is ready
$(document).ready(function(){
	setSubnavHeight();
});

//fire off resize function when text is resized
$(document).bind("fontresize", function (event, data) {
	setSubnavHeight();
});

//fire off resize function when window is resized
$(window).bind("resize", function (event, data) {
	setSubnavHeight();
});

/* End subnav resize functions */




//validate contact form
function CheckContactForm() {
	// The fields are checked for blanks
	if (document.contactForm.name.value   == "" ||
	    document.contactForm.subject.value   == "" ||
		document.contactForm.message.value   == "" ||
	    document.contactForm.email.value  == "") {
	    	alert("You haven't completed the form.\nPlease ensure that all required fields are filled in.");
		}
		
	// check for valid email address
	else if (document.contactForm.email.value.length <= 6 ||
      		 document.contactForm.email.value.indexOf ('@', 0) == -1 ||
      		 document.contactForm.email.value.indexOf ('.', 0) == -1){
				 alert("Sorry, " + document.contactForm.email.value + " is not a valid email address.");  
			 }
  	else { 
 		document.contactForm.submit()
	}
}



//popup
function popUp(URL, w, h)
{
    var day = new Date();
    var id = day.getTime();
    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=no,scrollbars=yes,location=no,statusbar=no,menubar=no,resizable=yes,width=" + w + ",height=" + h + ",left=212,top=184');");
} 
