// When validating individual fields, keep track of what we have check already, so // we don't validate the same value repeatedly. var checkedFieldValues = []; // When the user clicks submit but we still need to validate fields, use this flag // to help the callback function var formSubmitting = false; // How many times the email field has been validated. var emailChecks = 0; var maxEmailChecks = 3; var bvp = false; //save page url var SUBMITTING_PAGE_URL_ARG = "&submitting_page_url=" + encodeURIComponent(window.location); $(function() { // View more links should display a popup $("a.view-more").click(function(){ alert("Fill out the form above and submit to view additional details"); }); $(".button").removeAttr('disabled'); $(".button").click(checkForm); $("#link_submit_mainForm").click(function(e){ e.preventDefault(); checkForm(); }); /*$("input[type=text], select").blur(function(){ var fieldName = $(this).attr('name'); // If we already checked this with the server, don't do it agian if (checkedFieldValues[fieldName] == this.value) { return; } checkedFieldValues[fieldName] = this.value; var dataString = $("#ajaxable-form").serialize() + "&" + $("#mainForm").serialize(); dataString += '&field=' + fieldName; // Reset all fields/error labels to standard style. $("#r"+fieldName).hide(); $(this).removeClass('errorField'); // If BV is on, the response might take a few seconds. if (fieldName == 'email') { $("#email-loader").show(); emailChecks++; if (emailChecks >= maxEmailChecks) { $("input[name=bv]").val('0'); } } //do ajax call to CI controller, validate form data and then do DHTML as needed based on CID $.ajax({ type: "POST", url: "/ownership/validateField", data: dataString, dataType: 'json', success: validate_callback }); });*/ }); function checkForm() { $(".button").attr('disabled', true); $(".errorMessage").html(' '); formSubmitting = true; checkAllFields(); return false; } function checkAllFields() { var dataString = $("#ajaxable-form").serialize() + "&" + $("#mainForm").serialize() + SUBMITTING_PAGE_URL_ARG; // If BV is on, the response might take a few seconds. if (!$("#email").hasClass('validField')) { $("#email-loader").show(); } $(".errorLabel").hide(); $(".errorField").removeClass('errorField'); $(".validField").removeClass('validField'); $.ajax({ type: "POST", url: "/ownership/validate", data: dataString, dataType: 'json', success: validate_callback, error: function() { $(".button").removeAttr('disabled'); } }); } function validate_callback(data) { ei = data['fields']; if (data['validation'] == true) { for (var field in ei) { $('#'+field).addClass('validField'); if (field == 'pp2' || field == 'pp3') { field = 'pp1'; } $('#r'+field).fadeOut(); // Hide loader gif if we received a response on the email field if (field == 'email') { $("#email-loader").hide(); } } if (formSubmitting == true) { // If the action specified a new URL for us to post to, use that. if($("#addmarket").is(":checked")){ var temp_afid = $("#AFID").val(); $("#AFID").val('264690'); $.getJSON('https://secure.pluginext.com/familyoptin/record?callback=?', $("#mainForm").serialize(), function(data){ if(data == true){ //do something? } $("#AFID").val(temp_afid); $("#mainForm").submit(); }); } else { $("#mainForm").submit(); } //$("#mainForm").submit(); // Don't let the bottom of this function enable the submit button again return; } } else { $("#email-loader").hide(); for (var field in ei) { // If there is no error, it is valid if (ei[field] == '') { $('#'+field).addClass('validField'); } else { $('#'+field).addClass('errorField'); if (field == 'pp2' || field == 'pp3') { $('#rpp1').html(ei[field]).show(); } else { $('#r'+field).html(ei[field]).show(); } } } } $(".button").removeAttr('disabled'); formSubmitting = false; } /** * Singleton to parse the URL path into segments and make them available. * * Usage: urlSegments.AFID returns either 12345 or undefined * urlSegments.get('AFID') returns either 12345 or "" */ var urlSegments = new function() { var bits = location.pathname.substr(1).split('/'); // get rid of first / and split on slashes var controller = ''; var action = ''; for (var i = 0; i= 2) { this.controller = bits[0]; this.action = bits[1]; } this.get = function (key) { if (this[key] == undefined) { return ''; } return this[key]; } }