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

$(function(){
			$('.submitControlMatching').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;
															}
														}

														if  ($('input[name~="matching_form_url"]').length)
												   		{
															var formURL	= $('input[name~="matching_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(),
																				price_range_min				: $('#price_range_min').val(),
																				price_range_max				: $('#price_range_max').val(),
																				my_time_frame				: $('#my_time_frame').val(),
																				min_bed_rooms				: $('#min_bed_rooms').val(),
																				pool						: $('#pool').val(),
																				family_room					: $('#family_room').val(),
																				garage						: $('#garage').val(),
																				property_type				: $('#property_type').val(),
																				loc_area					: $('#loc_area').val(),
																				home_style					: $('#home_style').val(),
																				bathrooms					: $('#bathrooms').val(),
																				heating_type				: $('#heating_type').val(),
																				finished_basement			: $('#finished_basement').val(),
																				lot_size					: $('#lot_size').val(),
																				my_comments					: $('#my_comments').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~="matching_thank_you_url"]').val();
																									
																		 });
														}
													});
	   });
