jQuery(function($){$(document).ready(function(){

$(".smcorn").corner("5px");
$("#contact .requiredRow input,#Howcanwehelpyou").blur(function(){
	var thval = $(this).attr('value');
	if(thval == ""){
		$(this).next().fadeIn("slow");
	}else{
		var isemail = $(this).attr("id");
		if(isemail == "Email"){
			var email = $(this).val();
			if(isValidEmailAddress(email))
			{
				$(this).next().fadeOut("fast");
				$("#row_submit input").removeAttr("disabled");
			}
			else {
				$(this).next().fadeIn("fast");
				$(this).next().text("must be a valid email");
				$(this).next().fadeIn("fast");
			}

		}else{
		$(this).next().fadeOut("fast");
		}
		
	}
});
$(".cform").submit(function(){
var post = $('.cform').serialize();    
var f_name = $("#FirstName").val();
var f_surn = $("#LastName").val();
var f_emai = $("#Email").val();
var f_mess = $("#Howcanwehelpyou").val();
if(f_name == ""){ $("#FirstName").next().css("font-weight","bold").fadeIn("fast"); return false;}
if(f_surn == ""){ $("#LastName").next().css("font-weight","bold").fadeIn("fast"); return false;}
if(f_emai == ""){ $("#Email").next().css("font-weight","bold"); return false;}
if(f_mess == ""){ $("#Howcanwehelpyou").next().css("font-weight","bold").fadeIn("fast"); return false;}

$.post("http://diydesignandbuild.com/wp-content/themes/bts.theme/mailme.php", post, function(data) { 
	$(".cform").slideUp("slow", function(){
		$("#post_back").text("Your message has been sent. You should hear from us shortly.");
		$("#post_back").fadeIn("slow");
	});
});
return false;
});



	
	function isValidEmailAddress(emailAddress) {
 		var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
 		return pattern.test(emailAddress);
	}


return true;
});});

