
$(document).ready(function() {	
	$("#textSearch").attr({ value: "Search the EcoSmart Website"});
	$("#textSearch").focus(function(){
		$(this).attr({ value: ""});
	});
	$("#textSearch").blur(function(){
		$("#textSearch[value='']").attr({ value: "Search the EcoSmart Website"});
	});
	
	$(".emailLink").click(function(){
		mailto
	});
	
	
	$('#footerSubField').blur(function() {if ($('#footerSubField').val() == "") $('#footerSubField').val("you@youremail.com");})
	$('#footerSubField').focus(function() {
		if ($('#footerSubField').val() == "you@youremail.com") $('#footerSubField').val("");
	})
	
	$("#keepInContact").submit(function(event){
		var EmailToVal = $("#footerSubField").val();
		var EmailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		var submitURL = $("#keepInContact").attr("action");
		
		if (EmailReg.test(EmailToVal) && EmailToVal != "you@youremail.com") {	
			return(true);
		} else {
			event.preventDefault();
			alert("Your Email Address doesn't seem to be Valid");
		}
	});
	
	
});


//IE support for Hover psuedoclass. Used in CSS Drop downs
sfHover = function() {
	var sfEls = document.getElementById("productNav").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"), "");
		}
	}
}

if (window.attachEvent) window.attachEvent("onload", sfHover);

function Trim(nStr){return nStr.replace(/(^\s*)|(\s*$)/g, "");}

function checkSearch($elem){
	$trimmedSearch = Trim($elem.value);
	if (($trimmedSearch.length < 2) || ($trimmedSearch == "")){
		alert("Your search should be atleast 2 letters in length. Try searching for an entire word.");
		$elem.focus();
		return false;
	}
	return true;
}