//used to trim whitespace for callback function String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g,""); } function emailValidate(email) { var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/; var address = email; if (reg.test(address) == false) { return false; }else{ return true; } } function checkAddressForm(formtype){ //alert("in checkAddressForm"); //alert(document.step2Form.personid.value); formtype = typeof(formtype) != 'undefined' ? formtype : 'desktop'; /*if (document.step2Form.firstname.value == '' || document.step2Form.firstname.value == document.step2Form.firstname.title){ alert(document.getElementById('req_firstname').innerHTML); document.step2Form.firstname.value = document.step2Form.firstname.title; }else if(document.step2Form.lastname.value == '' || document.step2Form.lastname.value == document.step2Form.lastname.title){ alert(document.getElementById('req_lastname').innerHTML); document.step2Form.lastname.value = document.step2Form.lastname.title; */ if(document.addressForm.address.value == '' || document.addressForm.address.value == document.addressForm.address.placeholder){ alert(document.getElementById('req_address').innerHTML); document.addressForm.address.value = document.addressForm.address.placeholder; }else if(document.addressForm.zip.value == '' || document.addressForm.zip.value == document.addressForm.zip.placeholder){ alert(document.getElementById('req_zip').innerHTML); document.addressForm.state.value = document.addressForm.state.placeholder; }else if(emailValidate(document.addressForm.email.value) == false){ alert(document.getElementById('req_email').innerHTML); document.addressForm.email.value = document.addressForm.email.placeholder; /*}else if(document.addressForm.city.value == '' || document.addressForm.city.value == document.addressForm.city.placeholder){ //alert(document.getElementById('req_city').innerHTML); document.addressForm.city.value = document.addressForm.city.placeholder; */ }else{ if (formtype == "mobile"){ ColdFusion.Ajax.submitForm('addressForm','/campaignAction/letterAjaxSubmitNB.cfm',addressFormCallbackMbl); } else if (formtype == "fb") { document.addressForm.submit(); }else{ ColdFusion.Ajax.submitForm('addressForm', '/campaignAction/letterAjaxSubmitNB.cfm', addressFormCallback); } } //ColdFusion.Ajax.submitForm('step2Form', 'ajaxSubmit.cfm', step2callback); } function addressFormCallback(result,formtype){ formtype = typeof(formtype) != 'undefined' ? formtype : 'desktop'; var goModal = 1; var errorMsg = ''; //alert(result.trim()); switch (result.trim()){ //Zip Code Errors case 'needValidZip': errorMsg = 'There was a problem with the zipcode that you entered. Please make sure to enter either a 5 digit or 5+4 digit zipcode.'; //errorMsg = document.getElementById('err_needValidZip').innerHTML; goModal = 0; break; case 'needValidZip2': errorMsg = 'There was a problem with the zipcode that you entered. Please make sure to enter either a 5 digit or 5+4 digit zipcode.'; //errorMsg = document.getElementById('err_needValidZip2').innerHTML; goModal = 0; break; case 'needValidZip3': errorMsg = 'There was a problem with the zipcode that you entered. Please make sure to enter either a 5 digit or 5+4 digit zipcode.'; //errorMsg = document.getElementById('err_needValidZip3').innerHTML; goModal = 0; break; //MelissaData Error Codes case 'M': errorMsg = 'We found more than one zip code that matched your address, please enter more address information'; //errorMsg = document.getElementById('err_M').innerHTML; goModal = 0; break; case 'N': errorMsg = 'We had trouble finding the street that you entered within the zip code that you entered. Please check your street address'; //errorMsg = document.getElementById('err_N').innerHTML; goModal = 0; break; case 'R': errorMsg = 'We had trouble finding the address number on the street that you provided. Please check your address and re-enter it?'; //errorMsg = document.getElementById('err_R').innerHTML; goModal = 0; break; case 'T': errorMsg = 'Is there more to the street address than you entered? Sometimes it is important to include a directional, such as 100 "E" Main Street, instead of just 100 Main Street.'; //errorMsg = document.getElementById('err_T').innerHTML; goModal = 0; break; case 'U': errorMsg = 'We had trouble finding the street you entered in our database. Please check the spelling and name of the street that you entered?'; //errorMsg = document.getElementById('err_U').innerHTML; goModal = 0; break; case 'X': errorMsg = 'Are you using an industrial site or building address that does not normally receive mail? Please use your home address.'; //errorMsg = document.getElementById('err_X').innerHTML; goModal = 0; break; case 'Z': errorMsg = 'We had trouble finding the zip code that you entered. Please check your zipcode.'; //errorMsg = document.getElementById('err_Z').innerHTML; goModal = 0; break; //OTHER ERRORS case 'notValidStateAddr': errorMsg = 'You must live in NY to participate'; //errorMsg = document.getElementById('err_notValidStateAddr').innerHTML; goModal = 0; break; case 'noservice': errorMsg = 'Please try again.'; //errorMsg = document.getElementById('err_noservice').innerHTML; goModal = 0; break; } if (formtype == 'mobile'){ //alert(result.trim()); //alert("mobile!"); if (errorMsg.length) { //document.getElementById('errorTextMbl').innerHTML = errorMsg alert(errorMsg); }else{ var result2 = result.trim(); goHere = '/petition/step2Mobile.cfm?result=' + result2; //_gaq.push(['_trackEvent', 'SpeakUp', 'Step1']); location.href = goHere; } } if (formtype == 'petition'){ if (errorMsg.length) {alert(errorMsg)} if (goModal){ //alert("thank you!"); document.getElementById('petitionDiv').innerHTML = document.getElementById('thankyouDiv').innerHTML; //alert(document.thankyouForm.campaignName.value); } }else{ if (errorMsg.length) {alert(errorMsg)}; //document.getElementById('errorText').innerHTML = errorMsg if (goModal){ var result2 = result.trim(); goHere = '/campaignAction/letterActions.cfm?mode=step2&result=' + result2; // + '&formLang=' + document.step1Form.formLang.value; //alert(goHere); ColdFusion.navigate(goHere,'letterDiv'); //location.href = goHere; //$.fn.colorbox({innerWidth:880,innerHeight:700,href:goHere,overlayClose:false}); /*if(formtype=='fb') { goHere = 'http://standdev.connectionsmedia.com/petition/step2.cfm?result=' + result2 + '&formLang=' + document.step1Form.formLang.value; alert(goHere); }*/ //_gaq.push(['_trackEvent', 'SpeakUp', 'Step1']); //$.fn.colorbox({width:'942px',height:'auto',href:goHere,overlayClose:true}); }else{ //alert("no go"); } } } function checkLetterForm(campaignName){ if (document.letterForm.firstname.value == '' || document.letterForm.firstname.value == document.letterForm.firstname.title){ alert(document.getElementById('req_firstname').innerHTML); //document.letterForm.firstname.value = document.letterForm.firstname.title; }else if(document.letterForm.lastname.value == '' || document.letterForm.lastname.value == document.letterForm.lastname.title){ alert(document.getElementById('req_lastname').innerHTML); //document.letterForm.lastname.value = document.letterForm.lastname.title; }else if(document.letterForm.address1.value == '' || document.letterForm.address1.value == document.letterForm.address1.placeholder){ alert(document.getElementById('req_address').innerHTML); //document.letterForm.address.value = document.letterForm.address.placeholder; }else if(document.letterForm.city.value == '' || document.letterForm.city.value == document.letterForm.city.placeholder){ alert(document.getElementById('req_city').innerHTML); //document.letterForm.zip5.value = document.letterForm.zip5.placeholder; }else if(document.letterForm.state.value == '' || document.letterForm.state.value == document.letterForm.state.placeholder){ alert(document.getElementById('req_state').innerHTML); //document.letterForm.zip5.value = document.letterForm.zip5.placeholder; }else if(document.letterForm.zip5.value == '' || document.letterForm.zip5.value == document.letterForm.zip5.placeholder){ alert(document.getElementById('req_zip').innerHTML); //document.letterForm.zip5.value = document.letterForm.zip5.placeholder; }else if(emailValidate(document.letterForm.email.value) == false){ alert(document.getElementById('req_email').innerHTML); //document.letterForm.email.value = document.letterForm.email.placeholder; }else{ //alert("go submit"); ColdFusion.Ajax.submitForm('letterForm', '/campaignAction/letterAjaxSubmitNB.cfm', letterFormCallback); _gaq.push(['_trackEvent', 'Letters', 'Thanks', campaignName]); } } function letterFormCallback(result){ document.getElementById('letterDiv').innerHTML = document.getElementById('thankyouDiv').innerHTML; } function checkPetitionForm(campaignName){ if (document.petitionForm.firstname.value == '' || document.petitionForm.firstname.value == document.petitionForm.firstname.title){ alert(document.getElementById('req_firstname').innerHTML); //document.petitionForm.firstname.value = document.petitionForm.firstname.title; }else if(document.petitionForm.lastname.value == '' || document.petitionForm.lastname.value == document.petitionForm.lastname.title){ alert(document.getElementById('req_lastname').innerHTML); //document.petitionForm.lastname.value = document.petitionForm.lastname.title; }else if(document.petitionForm.address.value == '' || document.petitionForm.address.value == document.petitionForm.address.placeholder){ alert(document.getElementById('req_address').innerHTML); //document.petitionForm.address.value = document.petitionForm.address.placeholder; }else if(document.petitionForm.city.value == '' || document.petitionForm.city.value == document.petitionForm.city.placeholder){ alert(document.getElementById('req_city').innerHTML); //document.petitionForm.zip5.value = document.petitionForm.zip5.placeholder; }else if(document.petitionForm.state.value == '' || document.petitionForm.state.value == document.petitionForm.state.placeholder){ alert(document.getElementById('req_state').innerHTML); //document.petitionForm.zip5.value = document.petitionForm.zip5.placeholder; }else if(document.petitionForm.zip.value == '' || document.petitionForm.zip.value == document.petitionForm.zip.placeholder){ alert(document.getElementById('req_zip').innerHTML); //document.petitionForm.zip5.value = document.petitionForm.zip5.placeholder; }else if(emailValidate(document.petitionForm.email.value) == false){ alert(document.getElementById('req_email').innerHTML); //document.petitionForm.email.value = document.petitionForm.email.placeholder; }else{ //alert("go submit"); ColdFusion.Ajax.submitForm('petitionForm', '/campaignAction/petitionAjaxSubmitNB.cfm', petitionFormCallback); _gaq.push(['_trackEvent', 'Petitions', 'Thanks', campaignName]); } //ColdFusion.Ajax.submitForm('petitionForm', '/campaignAction/petitionAjaxSubmit.cfm', petitionFormCallback); } function petitionFormCallback(result){ addressFormCallback(result,'petition'); //document.getElementById('petitionDiv').innerHTML = document.getElementById('thankyouDiv').innerHTML; } function checkHdrForm(){ if(emailValidate(document.hdrForm.email.value) == false){ alert("Please enter a valid email address"); return false; }else if (document.hdrForm.zipcode.value == "" || document.hdrForm.zipcode.value == document.hdrForm.zipcode.placeholder){ alert("Please enter a zip code"); return false; }else{ document.hdrForm.submit(); } } function checkHdrFormMobile(){ if(emailValidate(document.hdrFormMobile.email.value) == false){ alert("Please enter a valid email address"); return false; }else if (document.hdrFormMobile.zipcode.value == "" || document.hdrFormMobile.zipcode.value == document.hdrFormMobile.zipcode.placeholder){ alert("Please enter a zip code"); return false; }else{ document.hdrFormMobile.submit(); } }