// JavaScript Document
//
function validateForm() {
	var b_valid = true;
	if (!validate("t",true,$("#fldFirstName").val(),"fldFirstName","lblFirstName")) { b_valid = false; }
	if (!validate("t",true,$("#fldLastName").val(),"fldLastName","lblLastName")) { b_valid = false; }
	if (!validate('z',false,$('#fldZip').val(),'fldZip','lblZip')) { b_valid = false; }
	if (!validate('p',false,$('#fldPhone').val(),'fldPhone','lblPhone')) { b_valid = false; }
	if (!validate('e',true,$('#fldEmail').val(),'fldEmail','lblEmail')) { b_valid = false; }
	if (!validate('t',true,$('#fldComments').val(),'fldComments','lblComments')) { b_valid = false; }
	//
	if (!b_valid) {
		alert("Please review the highlighted fields as they are required to continue.");
	} else {
		// submit the form
		sendForm();
	}
}
//
function sendForm() {
	$("#cntThankYou").css("display", "none");
	$("#cntForm").css("display", "none");
	$("#cntSaving").css("display", "none");
	var data="firstName="+encodeURIComponent($("#fldFirstName").val());
	data+="&lastName="+encodeURIComponent($("#fldLastName").val());
	data+="&address="+encodeURIComponent($("#fldAddress").val());
	data+="&address2="+encodeURIComponent($("#fldAddress2").val());
	data+="&city="+encodeURIComponent($("#fldCity").val());
	data+="&st="+encodeURIComponent($("#fldState").val());
	data+="&zip="+encodeURIComponent($("#fldZip").val());
	data+="&phone="+encodeURIComponent($("#fldPhone").val());
	data+="&email="+encodeURIComponent($("#fldEmail").val());
	data+="&time="+encodeURIComponent($("#fldTime").val());
	data+="&comments="+encodeURIComponent($("#fldComments").val());
	data+="&r="+Math.random();
	var url = "/data/send-contact.aspx";
	$.ajax({
	  url: url,
	  type: "POST",
	  data:data,
	  success: function(msg){
		sendFormSC(msg);
	  }
	});
}
//
function sendFormSC(r) {
	$("#cntSaving").css("display", "none");
	if ($(r).find("status").text() == "success") {
		$("#cntThankYou").css("display", "block");
	} else {
		alert("An error occurred when sending your information. Please try again or contact customer service at (800) 321-0377.");
		$("#cntForm").css("display", "block");
	}	
}
