//Javascript for contact.html
$(document).ready(function() { 
	
	//Setup Form Protection
	$("#form_warning").hide();

    var options = { 
        target:	'#contact_form_area',   // target element(s) to be updated with server response 
        beforeSubmit:	showRequest,  // pre-submit callback 
        success:	showResponse,  // post-submit callback 
 
        resetForm: true        // reset the form after successful submit 

    }; 
 
    // bind form using 'ajaxForm' 
    $('#contact_us_form').ajaxForm(options);
	
}); 
 
// pre-submit callback 
function showRequest(formData, jqForm, options) { 
   
		$(".error").hide();
		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		
		var emailFromVal = $("#contact_form_email_input").val();
		if(emailFromVal == '') {
			$("#contact_form_email_input").after('<p class="error">Opps, we need your email so we can reply</p>');
			hasError = true;
		} else if(!emailReg.test(emailFromVal)) {	
			$("#contact_form_email_input").after('<p class="error">Hang on, there something funny with your email</p>');
			hasError = true;
		}
		
		var emailNameVal = $("#contact_form_name_input").val();
		if(emailNameVal == '') {
			$("#contact_form_name_input").after('<p class="error">Oops, you forgot to enter your name</p>');
			hasError = true;
		}
		
		var messageVal = $("#contact_form_msg").val();
		if(messageVal == '') {
			$("#contact_form_msg").after('<p class="error">Did you want to tell us something?</p>');
			hasError = true;
		}
		
		var phoneVal = $("#contact_form_phone_input").val();
		
		if(hasError){ return false; }
		else{ return true; }
} 
 
// post-submit callback 
function showResponse(responseText, statusText)  { 
    // for normal html responses, the first argument to the success callback 
    // is the XMLHttpRequest object's responseText property 
 
    // if the ajaxForm method was passed an Options Object with the dataType 
    // property set to 'xml' then the first argument to the success callback 
    // is the XMLHttpRequest object's responseXML property 
 
    // if the ajaxForm method was passed an Options Object with the dataType 
    // property set to 'json' then the first argument to the success callback 
    // is the json data object returned by the server 
	
	$("#contact_form_area").html('<center><h4>Success</h4>Your email was sent. <br /><a href="index.html"><div class="blue_div_button"><< Back Home</div></a></center><br /><br>');
	
	return true;
} 


//Thickbox
jQuery(function($){
$("#form_email_input").Watermark("Enter Email Address");
});
