warranty_request_form = function() {
	
	return {
	
		submit : function(region) {
			var firstName = $("#wrf_FirstName").val();
			var lastName = $("#wrf_LastName").val();
			var email = $("#wrf_Email").val();
			var phone1 = $("#wrf_Phone1").val();
			var phone1Type = $("#wrf_Phone1_Type").val();
			var phone2 = $("#wrf_Phone2").val();
			var phone2Type = $("#wrf_Phone2_Type").val();
			var community = $("#wrf_Community").val();
			var closeDate = $("#wrf_CloseDate").val();
			var address = $("#wrf_Address").val();
			var item1 = $("#wrf_Item1").val();
			var item2 = $("#wrf_Item2").val();
			var item3 = $("#wrf_Item3").val();
			var item4 = $("#wrf_Item4").val();
			var item5 = $("#wrf_Item5").val();
			var item6 = $("#wrf_Item6").val();
			
			var errorMsg = new Array();
			
			if (firstName == "") { errorMsg.push("First Name is a required value"); }
			if (lastName == "") { errorMsg.push("Last Name is a required value"); }
			
			// Tested
			if (email == "") { errorMsg.push("Email is a required value"); }
			else if (!fieldstone.validation.isValidEmail(email)) { errorMsg.push("Bad email address"); }
			
			// Tested
			if (phone1 == "") { errorMsg.push("Missing Primary Phone Number"); }
			else if (!fieldstone.validation.isValidPhone(phone1)) { errorMsg.push("Bad Primary Phone Number"); }
			
			// Tested
			if (phone2 != '' && !fieldstone.validation.isValidPhone(phone2)) { errorMsg.push("Bad Alternate Phone Number"); }
			
			// Tested
			if (community == '0') { errorMsg.push("Community is a required value"); }
			
			// Tested
			if (errorMsg.length > 0) {
				$("#wrf_Error").html(errorMsg.join('<br />')).show();
				return;
			}
			
			var data = {Region:region, FirstName:firstName, LastName:lastName, Email:email, Phone1:phone1, Phone1Type:phone1Type, 
				Phone2:phone2, Phone2Type:phone2Type, Community:community, CloseDate:closeDate, Address:address, Item1:item1, Item2:item2, 
				Item3:item3, Item4:item4, Item5:item5, Item6:item6};
			warranty_request_form.send(region, data);
		},
		
		send : function(region, 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/warranty_request_submit.php';
			
			$.ajax({
				cache: false,
				data: data,
				error: function() {
					// Tested
					$("<div title='Warranty Request Status'>Error (1). Unable to process your warranty 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='Warranty Request Status'>Warranty request processed.</div>").dialog({buttons: {"OK": function() {$(this).dialog("close");$.nyroModalRemove();}}});
					} else {
						// Tested
						$("<div title='Warranty Request Status'>Error (2). Unable to process your warranty request. Please try again or use our phone in the mean time.</div>").dialog({buttons: {"OK": function() {$(this).dialog("close");}}});
					}
				},
				type: 'POST',
				url: url
			});
		}				
	}
}();