estimateForm.js

$(document).ready(function() { $("#btnSubmit").click(function(e) { e.preventDefault(); funSubmitQuote(); }); try { $('#loadingDiv').hide(); // hide the loading initially $("#dialog-message").hide(); $("#dialog-required-fields").hide(); //$("#dialog-message").dialog("close"); } catch (err) { } }); //// Alon Note: This function is not in use - moved to code behind function funValidateZipCode() { var allowedStates = ["06", "07", "08", "10", "11", "12", "13", "14", "90", "91", "92", "93", "94", "95", "96", "00544", "00501", "06390"]; // 2 first digits of the zip codes of CT, NJ, NY, CA var zipObj = $("#txtFrom_Zip"); var zip = zipObj.val(); if (zip != null && zip.length > 0) { zip = zip.length > 1 ? zip.substring(0, 2) : zip; for (var i = 0; i < allowedStates.length; i++) { if (allowedStates[i].indexOf(zip) == 0) // if allowedStates starts with zip ==> zip is valid return true; } // alert "We are moving only from the following states: CA, NY, NJ, CT" var dialogZipcodeMsg = $("#dialog-message"); $(".ui-dialog-title").html("Sorry!"); dialogZipcodeMsg.attr("title", "Sorry!"); dialogZipcodeMsg.find("#zipcodeDialogMsg").html("<div style='margin-top:8px; font-size:13px;'>We are serving only CA, NY, NJ and CT<div>"); dialogZipcodeMsg.find("#checkzipCodeMsg").html(""); dialogZipcodeMsg.dialog({ modal: true, buttons: { Continue: function() { $(this).dialog("close"); } } }); // remove the invalid zip zipObj.val(""); return false; } return true; } function funValidateEmail(email) { var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; return re.test(email); } function funValidateFields() { var validationFailedStyle = "2px solid red"; var fullName = $("#txtFirstName").val(); var phone = $("#txtTelephone").val(); var email = $("#txtEmail").val(); var moveDate = $("#txtMove_Week").val(); var jobSizeCode = $("#txtMove_Size").val(); var zipCodeFrom = $("#txtFrom_Zip").val(); var stateTo = $("#txtTo_State").val(); var errorMsg = ""; $("input").css("border", "none"); $("#txtMove_Size").parent().find(".jcf-select").css("border", "none"); $("#txtTo_State").parent().find(".jcf-select").css("border", "none"); if (email != null && email.length > 0 && funValidateEmail(email) == false) { errorMsg = "Invalid Email Address"; $("#txtEmail").css("border", validationFailedStyle); return errorMsg; } if (fullName == null || fullName.length == 0) { errorMsg += "Full Name<br />"; $("#txtFirstName").css("border", validationFailedStyle); } if (phone == null || phone.length < 10) { errorMsg += "Phone Number<br />"; $("#txtTelephone").css("border", validationFailedStyle); } if (email == null || email.length == 0) { errorMsg += "Email Address<br />"; $("#txtEmail").css("border", validationFailedStyle); } if (zipCodeFrom == null || zipCodeFrom.length == 0) { errorMsg += "From Zip<br />"; $("#txtFrom_Zip").css("border", validationFailedStyle); } if (stateTo == null || stateTo.length == 0) { errorMsg += "To State<br />"; $("#txtTo_State").parent().find(".jcf-select").css("border", validationFailedStyle); } if (jobSizeCode == null || jobSizeCode.length == 0) { errorMsg += "Move Size<br />"; $("#txtMove_Size").parent().find(".jcf-select").css("border", validationFailedStyle); } if (moveDate == null || moveDate.length < 8) { errorMsg += "Move Date<br />"; $("#txtMove_Week").css("border", validationFailedStyle); } return errorMsg; } // This function saves the raw (unprocessed) quote into the Leads table function funSubmitQuote() { disableSendQuoteBtn(true); // First validate the fields var validateFields = funValidateFields(); if (validateFields.length > 0) { if (validateFields.indexOf("Invalid Email") > -1) { $(".ui-dialog-title").html("Invalid Email Address"); $("#dialog-required-fields").attr("title", "Invalid Email Address"); $("#quoteErrorMsg").html(""); } else { //// Removed by Alon Dec/16/2016 since we alread validate the required fields marked with red border //$(".ui-dialog-title").html("The following fields are missing:"); //$("#dialog-required-fields").attr("title", "The following fields are missing:"); //$("#quoteErrorMsg").html(validateFields); } //// Removed by Alon Dec/16/2016 since we alread validate the required fields marked with red border // $("#dialog-required-fields").dialog({ // modal: true, // buttons: { // Continue: function() { // $(this).dialog("close"); // } // } // }); // enable the "send a quote" button disableSendQuoteBtn(false); return false; } // save the lead and redirect to the correct thank you page based on leadType = "NR"/"R" funSaveLead(); return false; // So that the form will not get submitted to /est_form_act.asp since it is no longer in use!!! } function funSaveLead() { var browser = ""; //funDetectBrowser(); var fullName = $("#txtFirstName").val(); var email = $("#txtEmail").val(); var phone = $("#txtTelephone").val(); var moveDate = $("#txtMove_Week").val(); var jobSizeDesc = $("#txtMove_Size").val(); var zipCodeFrom = $("#txtFrom_Zip").val(); var stateTo = $("#txtTo_State").val(); var remarks = $("#txtComments").val(); //remarks = remarks.replace(/\r/g, " ").replace(/\n/g, " "); // clean line breaks var wsUrl = "http://www.moveeast.com/leadsWebService/Service1.asmx/InsertLead"; $('#loadingDiv').show().html('<div id="overlay"><img src="/imgs/loading.gif" class="loading_circle" alt="loading" /></div>'); $.ajax({ url: wsUrl, data: "{'fullName': '" + fullName + "'," + "'email': '" + email + "'," + "'phone': '" + phone + "'," + "'zipCodeFrom': '" + zipCodeFrom + "'," + "'cityFrom': ''," + "'stateFrom': ''," + "'cityTo': ''," + "'stateTo': '" + stateTo + "'," + "'jobSizeDesc': '" + jobSizeDesc + "'," + "'moveDate': '" + moveDate + "'," + "'remarks': '" + remarks + "'," + "'browser': '" + browser + "'" + "}", type: "POST", contentType: "application/json; charset=utf-8", dataType: "json", // "xml", "json", "jsonp" timeout: 30000, //async: false, //jsonpCallback: 'jsonpCallback', //crossDomain: 'true', success: function(data) { var leadData = $.parseJSON(data.d); // NOTE: NEED TO UNCOMMENT THIS. IT WAS COMMENTED OUT FOR TESTING !!! if (leadData.LeadType == "NR") { var dialogZipcodeMsg = $("#dialog-message"); if (leadData.CityFrom == "N/A") { // ==> the zipcode does not exists $(".ui-dialog-title").html("Unidentified Zip Code"); dialogZipcodeMsg.attr("title", "Unidentified Zip Code"); dialogZipcodeMsg.find("#zipcodeDialogMsg").html(""); dialogZipcodeMsg.find("#checkzipCodeMsg").html("Please check your zip code and try again"); dialogZipcodeMsg.dialog({ modal: true, buttons: { Continue: function() { $(this).dialog("close"); } } }); } else { // ==> the zipcode exists but distance is more then 200 miles from closest branch $(".ui-dialog-title").html("Sorry!"); dialogZipcodeMsg.attr("title", "Sorry!"); dialogZipcodeMsg.find("#zipcodeDialogMsg").html("<div style='margin-top:8px; font-size:13px;'>Currently, we do not serve your area.</div>"); dialogZipcodeMsg.find("#checkzipCodeMsg").html(""); dialogZipcodeMsg.dialog({ modal: true, buttons: { Continue: function() { $(this).dialog("close"); } } }); } } else document.location.href = '/mobile/thankyou.asp'; // enable the "send a quote" button disableSendQuoteBtn(false); $('#loadingDiv').hide(); }, error: function(jqXHR, textStatus, ex) { alert("Failed to send a quote. Please try again. \n" + textStatus + "," + ex + "," + jqXHR.responseText); // disable the "send a quote" button disableSendQuoteBtn(false); $('#loadingDiv').hide(); } }); } // Calling this function to pass the lead to Van Lines only if lead is NR function funSendLeadToVanLines(customerName, email, phone, zipFrom, stateTo, jobSize, moveDate, remarks, callback) { var wsUrl = "http://www.vanlines.com/XML/XML_Receive.asp"; var leadData = "<?xml version='1.0'?><XMLmoveeast><ContactDetails><FirstName>@First_Name</FirstName><LastName>@Last_Name</LastName><Email>@Email</Email><HomePhone>@Evening_Phone</HomePhone></ContactDetails><MovingFrom><ZipFrom>@Zip_From</ZipFrom></MovingFrom><MovingTo><CityTo>@City_To</CityTo><StateTo>@State_To</StateTo></MovingTo><MoveDetails><MoveSize>@Weight</MoveSize><MoveDateMonth>@Move_Date_Month</MoveDateMonth><MoveDateDay>@Move_Date_Day</MoveDateDay><Remarks>@Comments</Remarks></MoveDetails></XMLmoveeast>"; var moveDateDay = funGetDayOfWeek(moveDate); leadData = leadData.replace("@First_Name", customerName.FirstName); leadData = leadData.replace("@Last_Name", customerName.LastName) leadData = leadData.replace("@Email", email) leadData = leadData.replace("@Evening_Phone", phone) leadData = leadData.replace("@Zip_From", zipFrom) leadData = leadData.replace("@City_To", "") leadData = leadData.replace("@State_To", stateTo) leadData = leadData.replace("@Weight", jobSize) leadData = leadData.replace("@Move_Date_Month", moveDate) leadData = leadData.replace("@Move_Date_Day", moveDateDay) leadData = leadData.replace("@Comments", remarks); $.ajax({ url: wsUrl, data: leadData, type: "POST", contentType: "text/xml", dataType: "text", timeout: 5000, success: function(data) { callback(); }, error: function(jqXHR, textStatus, ex) { //alert(textStatus + "," + ex + "," + jqXHR.responseText); callback(); } }); } function funDetectBrowser() { var browser = ""; $.each($.browser, function(attr, val) { browser += attr + " : " + val + " , "; }); if (browser.lastIndexOf(",") == browser.length - 2) browser = browser.substring(0, browser.length - 2); return browser; } function disableSendQuoteBtn(disable) { if (disable) { // disable the "send a quote" button $("#btnSubmit").attr('disabled', 'disabled').val('Sending...'); } else { // enable the "send a quote" button $("#btnSubmit").removeAttr('disabled').val('Send me a Quote'); } } function funGetDayOfWeek(moveDate) { var d = new Date(moveDate); var weekday = new Array(7); weekday[0] = "Sunday"; weekday[1] = "Monday"; weekday[2] = "Tuesday"; weekday[3] = "Wednesday"; weekday[4] = "Thursday"; weekday[5] = "Friday"; weekday[6] = "Saturday"; var n = weekday[d.getDay()]; return n; }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.