/* 
Javascript Document
www.electricaltrainingcourse.co.uk
Copyright 2009 PASS Ltd
$Id: main.js 144 2009-07-20 16:28:56Z john.miller $
*/

/*
# SuckerFish ie6 Hover Fix
#
# sfhover class used to attatch a classname to 
# items on hover, this allows us to track hovers 
# on elements in IE6.
*/
sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}	
	}
} 

/*
# scrollToId function
#
# performs smooth page scroll to required element id
*/
function scrollToId(id) {
	var target = $('#' + id);
	var targetOffset = target.offset().top;
	$('html, body').animate({scrollTop: targetOffset}, 300);
}

/*
#Postcode format validation
#
# validates postcode format
*/
function isPostcode(value) {
  	return /\b([A-PR-UWYZ][A-HK-Y0-9][A-HJKSTUW0-9]?[ABEHMNPRVWXY0-9]?)*[0-9][ABD-HJLN-UW-Z]{2}\b/.test(value);
}

/*
#
*/
$(document).ready(function() {	
	
	/*
	# init SuckerFish Fix
	*/
	sfHover();
	
	/*
	# watcher function to remove/reinstate search 
	# box label
	*/
	var strSearchLabel = 'Search...';
	
	$('#searchbox').blur(function(event){
		if(this.value.length<1)this.value=strSearchLabel;
	});
	
	$('#searchbox').click(function(event){
		if(this.value == strSearchLabel)this.value='';
	});
});