mortgage_analysis_form = function() {
	
	return {
	
		submit : function(region) {
			var parameters = {
				FirstName : $("#maf_FirstName").val(),
				LastName : $("#maf_LastName").val(),
				Email : $("#maf_Email").val(),
				Phone : $("#maf_Phone").val(),
				PhoneType : $("#maf_PhoneType").val(),
				BestTimeToCall : $("#maf_BestTimeToCall").val(),
				MoveIn_Month : $("#maf_MoveIn_Month").val(),
				MoveIn_Year : $("#maf_MoveIn_Year").val(),
				QuestionsComments : $("#maf_QuestionsComments").val(),
				Region : region
			}
			
			var errorMsg = new Array();
			
			if (parameters.FirstName == "") { errorMsg.push("First Name is a required value"); }
			if (parameters.LastName == "") { errorMsg.push("Last Name is a required value"); }
			
			// Tested
			if (parameters.Email == "") { errorMsg.push("Email Address is a required value"); }
			else if (!fieldstone.validation.isValidEmail(parameters.Email)) { errorMsg.push("Bad email address"); }
			
			// Tested
			if (parameters.Phone == "") { errorMsg.push("Missing Phone Number"); }
			else if (!fieldstone.validation.isValidPhone(parameters.Phone)) { errorMsg.push("Bad Phone Number"); }
			
			// Tested
			if (parameters.PhoneType == '') { errorMsg.push("Phone Type is a required value"); }
			
			// Tested
			if (parameters.BestTimeToCall == '') { errorMsg.push("Best time to call is a required value"); }
			
			// Tested
			if (errorMsg.length > 0) {
				$("#maf_Error").html(errorMsg.join('<br />')).show();
				return;
			}
			
			mortgage_analysis_form.send(parameters);
		},
		
		send : function(data) {
			// Returns boolean
			
			// Google AdWord tracking 			
			$("<div style='display:inline;'><img height='1' width='1' style='border-style:none;' alt='' src='http://www.googleadservices.com/pagead/conversion/1040454231/?label=DePNCJ_94wEQ16SQ8AM&amp;guid=ON&amp;script=0'/></div>");
			
			var url = '/actions/ajax/mortgage_analysis_submit.php';
			
			$.ajax({
				cache: false,
				data: data,
				error: function() {
					// Tested %%
					$("<div title='Mortgage Analysis Request Status'>Error (1). Unable to process your mortgage analysis request. Please try again or use our phone in the mean time.</div>").dialog({buttons: {"OK": function() {$(this).dialog("close");}}});
				},
				success: function(response) {
					if (response == 'OK') {
						// Tested %%
						$("<div title='Mortgage Analysis Request Status'>Mortgage analysis request processed.</div>").dialog({buttons: {"OK": function() {$(this).dialog("close");$.nyroModalRemove();}}});
					} else {
						// Tested
						$("<div title='Mortgage Analysis Request Status'>Error (2). Unable to process your mortgage analysis request. Please try again or use our phone in the mean time.</div>").dialog({buttons: {"OK": function() {$(this).dialog("close");}}});
					}
				},
				type: 'POST',
				url: url
			});
		}				
	}
}();