this.validate = function(){
	
	var valid;
	var err = "This field is required.";
	var errEmail = "Please provide a valid email address."
	var errPhone = "Phone number is required.";
	
	$("form").submit(function(){
														 
		$(".error",this).remove();
		valid = true;
		
		$(".required",this).each(	function(i) {
			if( $(this).hasClass("email") ){
				checkEmail(this);
			} else if ( $(this).hasClass("phone") ){
				checkPhone(this);
			} else {
				check(this);
			};
		})
	
		return valid;	
	});
	
	
	this.check = function(obj){
		if ($(obj).val() == ""){
			var errormsg = ( $(obj).attr("title") != "" ) ? $(obj).attr("title") : err;
			error(obj,errormsg);
			valid = false;
		};
	};
	this.checkEmail = function(obj){
		var regEx = /^[^@]+@[^@]+.[a-z]{2,}$/;
		var val = $(obj).val();
		if (val.search(regEx) == -1){
			var errormsg = ( $(obj).attr("title") != "" ) ? $(obj).attr("title") : errEmail;
			error(obj,errormsg);
			valid = false;
		};
	};	
	this.checkPhone = function(obj){
                if ($(obj).val() == ""){
			var errormsg = ( $(obj).attr("title") != "" ) ? $(obj).attr("title") : errPhone;
			error(obj,errormsg);
			valid = false;
	// by phil, changed phone validation to ensure not empty.
                //var regEx = /[\d\s_]{6,}/;
	  //	var val = $(obj).val();
		//if(val.search(regEx) == -1){
	//		var errormsg = ( $(obj).attr("title") != "" ) ? $(obj).attr("title") : errPhone;
	//		error(obj,errormsg);
	//		valid = false;
		};
	};	
	this.error = function(obj,errormsg){
		var parent = $(obj).parent();
		parent.append("<span class=\"error\">"+ errormsg +"</span>");
		$("span.error",parent).hide().show("fast");
	};		

};

this.easyPanel = function(){
	$("#easypanel li").each(function(i){
			$("h2", this).hover(
				function(){
					$(this).addClass("over");
					},
				function(){
					$(this).removeClass("over");
					}
			);
			$("h2", this).click(function(){
				show(i+1);
			});
		});	
		this.show = function(i){
			$("#easypanel h2").removeClass("selected");
			$("#easypanel .body").hide();
			$("#easypanel li:nth-child("+ i +") h2").addClass("selected");
			$("#easypanel li:nth-child("+ i +") .body").fadeIn("fast");
		};
		show(1);
};

$(document).ready(function(){	
	$("#keyword").easyFields({useLabel:true});
	easyPanel();
	validate();
});