//JavaScript Document
function home_evaluation_form(frmObj)
{
	var online_home_evaluation = new Array();
	online_home_evaluation.push("required,my_first_name,Please enter your first name.");		
	online_home_evaluation.push("required,my_last_name,Please enter your last name.");		
	online_home_evaluation.push("required,my_email_address,Please enter your email address.")
	online_home_evaluation.push("valid_email,my_email_address,Please enter valid email address.");
	if (frmObj.verification_code)
		online_home_evaluation.push("required,verification_code,Please enter the verification code in the text box below.");
	return 	validateFields(frmObj,online_home_evaluation);
}

$(function(){
			$('.submitControlEvaluation').click(function (){
														if ($("#my_first_name").length)
														{
															if ($("#my_first_name").val()=='First Name' ||  $.trim($("#my_first_name").val())=='')
															{
																alert ('Please enter your first name.');
																$("#my_first_name").focus();
																return false;
															}
														}

														if ($("#my_last_name").length)
														{
															if ($("#my_last_name").val()=='Last Name' ||  $.trim($("#my_last_name").val())=='')
															{
																alert ('Please enter your last name.');
																$("#my_last_name").focus();
																return false;
															}
														}
														
														if ($("#my_email_address").length)
														{
															if ($("#my_email_address").val()=='Email Address' ||  $.trim($("#my_email_address").val())=='')
															{
																alert ('Please enter your email address.');
																$("#my_email_address").focus();
																return false;
															}
															if(!isValidEmail($.trim($('#my_email_address').val())))
															{
																alert ('Please enter a valid email address.');
																$("#my_email_address").focus();
																return false;
															}
														}
														var selling_refinancing = '';
														$('input[name~="selling_refinancing"]:checked').each(function(i){
															selling_refinancing = $(this).val();
														});
														
														var planning_to_sell = '';
														$('input[name~="planning_to_sell"]:checked').each(function(i){
															planning_to_sell = $(this).val();
														});

														if  ($('input[name~="evaluation_form_url"]').length)
												   		{
															var formURL	= $('input[name~="evaluation_form_url"]').val();
															$.post(
																   formURL, {	my_first_name		: $('#my_first_name').val(),
																				my_last_name		: $('#my_last_name').val(),
																				my_daytime_phone	: $('#my_daytime_phone').val(),
																				my_evening_phone	: $('#my_evening_phone').val(),
																				my_email_address	: $('#my_email_address').val(),
																				my_street_address	: $('#my_street_address').val(),
																				my_city				: $('#my_city').val(),
																				my_state			: $('#my_state').val(),
																				my_zip_code			: $('#my_zip_code').val(),
																				country				: $('#country').val(),
																				selling_refinancing	: selling_refinancing,
																				planning_to_sell	: planning_to_sell,
																				home_street_address	: $('#home_street_address').val(),
																				home_city			: $('#home_city').val(),
																				home_state			: $('#home_state').val(),
																				type_of_home		: $('#type_of_home').val(),
																				lot_size_frontage	: $('#lot_size_frontage').val(),
																				lot_size_depth		: $('#lot_size_depth').val(),
																				type_of_heating		: $('#type_of_heating').val(),
																				no_of_bed			: $('#no_of_bed').val(),
																				no_of_bath			: $('#no_of_bath').val(),
																				fire_place			: $('#fire_place').val(),
																				finish_basement		: $('#finish_basement').val(),
																				apx_sqr_footage		: $('#apx_sqr_footage').val(),
																				location			: $('#location').val(),
																				apx_age_home		: $('#apx_age_home').val(),
																				special_feature		: $('#special_feature').val(),
																				hdn_report_id		: $('#hdn_report_id').val(),
																				hdn_auto_resp_id	: $('#hdn_auto_resp_id').val(),
																				hdn_send_report		: $('#hdn_send_report').val(),
																				report_title		: $('#report_title').val()
																			}, function(data) {	
																								if(data==1)
																									alert ('There is some issue in the form validation. Please recheck your fields.');
																								else if(data==2)
																									alert ('You\'ve already subscribed for this report using the same email address. Please check your email address and enter a new valid email address to continue.');
																								else if(data==3)
																									top.location.href	= $('input[name~="evaluation_thank_you_url"]').val();
																									
																		 });
														}
													});
	   });
