/**
 * @author JohnL
 */

function validateEmail(email)
{
	if (email != undefined && email.length > 7) {
		if(email.match("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$") != null)
		{
			return true;
		}
	}
	return false;
}

function readyContactForm()
{
   var formBox = "#contactFormContent";
   var formID = "#InquiriesContactForm";
	var bwrapEl = document.createElement("div");
   	bwrapEl.id = "submitResponse";
	jQuery(formBox).append(bwrapEl);
	jQuery("#submitResponse").hide();
	jQuery("form"+formID).attr("action","javascript:");
	jQuery("form"+formID).submit(function()
	{
		var name = jQuery("form"+formID+" input[name=name]").val();
		var phone = jQuery("form"+formID+" input[name=phone]").val();
		var emailAddress = jQuery("form"+formID+" input[name=email]").val();
		var question = jQuery("form"+formID+" textarea[name=comments]").val();
		if(validateEmail(emailAddress))
		{
			jQuery.post("/contact/comment",{'name':name,'email':emailAddress,'question':question}, 
			function(data)
			{
				jQuery(formBox+" #submitResponse").html(data);
				jQuery(formBox+" #submitResponse").show("slow");
				setTimeout(function()
				{
					jQuery(formBox+" #submitResponse").hide("slow");
				}, 8000);
			});
			jQuery("form"+formID)[0].reset();

			return true;
		}
		jQuery(formBox+" #submitResponse").html("<p class='error'><b>Email Not Valid</b></p>");
				jQuery(formBox+" #submitResponse").show("slow");
				setTimeout(function()
				{
					jQuery(formBox+" #submitResponse").hide("slow");
				}, 3000);
		
		return false;
	});
}
