$(document).ready(function(){
	$("#contact_form_v2_submit2").click(function(){
		$(".error").hide();
		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		var phoneReg = /^(\d{3}\-\d{3}\-\d{4})?$/;
		var nameReg = /^[a-zA-Z\s]+$/;
		
		var emailVal = $("#email").val();
		if(emailVal == '' || !emailReg.test(emailVal)) {
			hasError = true;
		}  	

		var nameVal = $("#full_name").val();
		if(nameVal == '' || !nameReg.test(nameVal)) {
			hasError = true;
		} 
		
		var phoneVal = $("#phone").val(); 
		if(phoneVal == '' || !phoneReg.test(phoneVal)) {
			hasError = true;
		} 

		var scVal = $("#contact_captcha_home").val(); 
		if(scVal == '') {
			hasError = true;
		} 
 		
		var contact_methodVal = $("#contact_method").val();  
		if(hasError == false) {
			$(this).hide();
			$("#contact_form_v2 #contact_message").html('<img src="/images/loading.gif" alt="Sending" id="loading" />'); 

			var q1 = $('#question1').val();
			var q2 = $('#question2').val();
			
			$.post("/process.php",
					{ email: emailVal, full_name: nameVal, phone: phoneVal, question1: q1, question2: q2, contact_method: contact_methodVal, position: "homepage", action: "contact" }, 
					function(data){ 						 
						if (data == "1") 
						{
							$("#contact_message").html('Your requset has been sent. We will contact you as soon as possible.');	
							$("#full_name").val("");
							$("#phone").val("");
							$("#email").val("");
							$('#question1').val("$0.00 ~ $7,500.00");
							$('#question2').val("$0.00 ~ $100,000.00");
							$("#contact_method").val("Morning");
						}
						else
						{
							$("#contact_message").html('Please try to send your request again.'); 
							$("#full_name").val("");
							$("#phone").val("");
							$("#email").val("");
							$('#question1').val("$0.00 ~ $7,500.00");
							$('#question2').val("$0.00 ~ $100,000.00");
							$("#contact_method").val("Morning");
						}
					}
			); 

			$(this).show(); 
		}
		else
		{
			$('#form_error').html('Please enter infromation in correct format to all the required(*) fields.');
			$('#form_error').show();
		}

		return false;
	});	
});
  
 
