Created
July 7, 2013 19:54
-
-
Save anonymous/5944682 to your computer and use it in GitHub Desktop.
EEMSignupForm.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//-------------------------------------------------------------------- | |
// You may set the Signup Form Context by passing one of the following | |
// supported values thru the Query String: | |
// * NewSubscriber (Default): Upon submission, addes a new subscriber | |
// with all information supplied on the Signup Form. | |
// * UpdSubscriber: Updates an existing subscriber with the information | |
// supplied thru the Signup Form. | |
// NOTE: Expects SID to be provided thru the Query String. | |
// * Preview: Performs validation of submission without actually adding | |
// a subscriber. | |
//-------------------------------------------------------------------- | |
function SFContextInit(ctrlID) { | |
var hidSFContext; | |
var lblPreview; | |
var sfContext; | |
sfContext = Request.QueryString["SFContext"]; | |
hidSFContext = document.getElementById(ctrlID); | |
if (hidSFContext == null) | |
hidSFContext = document.getElementById('SFContext'); //%% | |
hidSFContext.value = (sfContext != null) ? sfContext : "NewSubscriber"; | |
if (hidSFContext.value == "Preview") { | |
lblPreview = document.getElementById('lblPreview'); | |
if (lblPreview != null) | |
lblPreview.style.display = ''; | |
} | |
return (hidSFContext); | |
} | |
function EEMSFQuestion(ctrl, name, id, type, isReq, text, multiAnswerList) { | |
this.Ctrl = ctrl; | |
this.Name = name; | |
this.ID = id; | |
this.Type = type; | |
this.IsReq = isReq; | |
this.Text = text; | |
this.MultiAnswerList = multiAnswerList; | |
} | |
function EEMSFQuestionAnswer(ctrl, name, questionID, answerID) { | |
this.Ctrl = ctrl; | |
this.Name = name; | |
this.QuestionID = questionID; | |
this.AnswerID = answerID; | |
} | |
function EEMSFQuestionCtrlHandler(ctrl, matches) { | |
var eemSFQuestion; | |
var id; | |
var type; | |
var isReq; | |
var text; | |
id = (matches.length > 0) ? matches[1] : -1; | |
type = ctrl.getAttribute('eemSFQType'); | |
isReq = ctrl.getAttribute('eemSFQIsReq').toLowerCase(); | |
text = ctrl.getAttribute('eemSFQText'); | |
eemSFQuestion = new EEMSFQuestion(ctrl, ctrl.name, id, type, isReq, text, null); | |
return (eemSFQuestion); | |
} | |
function EEMSFQuestionAnswerCtrlHandler(ctrl, matches) { | |
var sfQAnswer; | |
var answerID; | |
var questionID; | |
answerID = (matches.length > 1) ? matches[1] : -1; | |
questionID = (matches.length > 2) ? matches[2] : -1; | |
sfQAnswer = new EEMSFQuestionAnswer(ctrl, ctrl.name, questionID, answerID); | |
return (sfQAnswer); | |
} | |
function SFValidateFields() { | |
var txtSFEmail; | |
var ctrlQuestion; | |
var eemSFQIsReq; | |
var eemSFQuestion; | |
var qIDList; | |
var nIdx; | |
var isAllValid = true; | |
var isReqValid = true; | |
var isReqFieldValid = true; | |
var isValid = true; | |
var errMsg = ""; | |
// Validate Email address. | |
txtSFEmail = document.getElementById('txtSFEmail'); | |
var email = txtSFEmail.value; | |
email = email.replace(new RegExp(/^\s+/), ""); //Remove leading white space | |
email = email.replace(new RegExp(/\s+$/), ""); //Remove trailing white space | |
txtSFEmail.value = email; | |
isValid = SFIsValidEmail(email); | |
if (txtSFEmail.value == "") | |
errMsg += '* You must provide a valid email address;\n (e.g. johndoe@mydomain.com).\n'; | |
else if (!isValid) | |
errMsg += '* "' + txtSFEmail.value + '" does not seem to be a valid email address;\n (e.g. johndoe@mydomain.com).\n'; | |
isAllValid = (isAllValid && isValid); | |
// Get all controls with name matching "eemSFQuestion<#>". | |
qIDList = SFGetFormVarMatches(/eemSFQuestion(\d*)/, 'input,select,div', EEMSFQuestionCtrlHandler); | |
// Validate all required questions. | |
for (nIdx = 0; nIdx < qIDList.length; nIdx++) { | |
eemSFQuestion = qIDList[nIdx]; | |
ctrlQuestion = eemSFQuestion.Ctrl; | |
eemSFQIsReq = ctrlQuestion.getAttribute('eemSFQIsReq').toLowerCase(); | |
if (eemSFQIsReq == null || eemSFQIsReq != 'true') | |
continue; | |
isReqFieldValid = SFValidateRequiredField(eemSFQuestion); | |
if (!isReqFieldValid) | |
errMsg += '* Question, "' + ctrlQuestion.getAttribute('eemSFQText') + '", requires a response.\n' | |
isReqValid = (isReqValid && isReqFieldValid) | |
} | |
isAllValid = (isAllValid && isReqValid); | |
// Validate that Captcha text. | |
txtSFCaptcha = document.getElementById('txtSFCaptcha'); | |
isValid = (txtSFCaptcha.value != ""); | |
if (!isValid) | |
errMsg += "* You must type in the ACCESS CODE displayed within the image.\n"; | |
isAllValid = (isAllValid && isValid); | |
// On errors, popup alert to the user. | |
if (errMsg != "") { | |
errMsg = "Please correct the following errors:\n\n" + errMsg; | |
alert(errMsg); | |
} | |
return ((isAllValid && errMsg == "")); | |
} | |
function SFValidateRequiredField(eemSFQuestion) { | |
var chkBoxList; | |
var hidSFQuestionType; | |
var eemSFQType; | |
var hidSFQuestion; | |
var ctrlQuestion; | |
var questionID; | |
var eemEEMSFQuestionAnswer; | |
var multiIDList; | |
var nIdx; | |
var isValid = true; | |
ctrlQuestion = eemSFQuestion.Ctrl; | |
questionID = eemSFQuestion.ID; | |
eemSFQType = ctrlQuestion.getAttribute('eemSFQType'); | |
if (eemSFQType == null || eemSFQType == '') | |
return (isValid); | |
switch (eemSFQType) { | |
case "1": // Text | |
case "5": // Number | |
case "6": // Date | |
case "7": // Phone | |
if (ctrlQuestion.value == "") | |
isValid = false; | |
break; | |
case "4": // List | |
if (ctrlQuestion.value == "" || ctrlQuestion.value == "-99") | |
isValid = false; | |
break; | |
case "3": // Multi | |
multiIDList = SFGetFormVarMatches(eval('/eemSFAnswer(\\d.*)_Question(' + questionID + ')/'), 'input', EEMSFQuestionAnswerCtrlHandler); | |
eemSFQuestion.MultiAnswerList = multiIDList; //%% | |
isValid = false; | |
for (nIdx = 0; nIdx < multiIDList.length; nIdx++) { | |
eemEEMSFQuestionAnswer = multiIDList[nIdx].Ctrl; | |
if (eemEEMSFQuestionAnswer.type == "checkbox") { | |
isValid = (isValid || eemEEMSFQuestionAnswer.checked); | |
} | |
} | |
break; | |
} | |
return (isValid); | |
} | |
function SFValidateRequiredField_InpField(ctrlQuestion, questionID) { | |
var chkBoxList; | |
var hidSFQuestionType; | |
var hidSFQuestion; | |
var eemEEMSFQuestionAnswer; | |
var multiIDList; | |
var nIdx; | |
var isValid = true; | |
hidSFQuestionType = document.getElementById('hidSFQuestionType' + questionID); | |
if (hidSFQuestionType.value == null || hidSFQuestionType.value == '') | |
return (isValid); | |
switch (hidSFQuestionType.value) { | |
case "1": // Text | |
case "5": // Number | |
case "6": // Date | |
case "7": // Phone | |
if (ctrlQuestion.value == "") | |
isValid = false; | |
break; | |
case "4": // List | |
if (ctrlQuestion.value == "" || ctrlQuestion.value == "-99") | |
isValid = false; | |
break; | |
case "3": // Multi | |
multiIDList = ctrlQuestion.value.split(','); | |
//% alert ('multiIDList = '+multiIDList); | |
isValid = false; | |
if (multiIDList.length > 0) { | |
//% alert ('multiIDList.length = '+multiIDList.length); | |
for (nIdx = 0; nIdx < multiIDList.length - 1; nIdx++) { | |
//%% eemEEMSFQuestionAnswer = document.getElementById ('eemSFQuestion'+questionID+'_Answer'+multiIDList[nIdx]); | |
eemEEMSFQuestionAnswer = document.getElementById('eemSFAnswer' + multiIDList[nIdx] + '_Question' + questionID); | |
if (eemEEMSFQuestionAnswer.type == "checkbox") { | |
//% alert ('eemEEMSFQuestionAnswer.checked = '+eemEEMSFQuestionAnswer.checked); | |
isValid = (isValid || eemEEMSFQuestionAnswer.checked); | |
} | |
} | |
} | |
break; | |
} | |
return (isValid); | |
} | |
//-------------------------------------------------------------------- | |
// You may set the Signup Form Context by passing one of the following | |
// supported values thru the Query String: | |
// * Signup (Default): Indicates user is in the signup stage. | |
// * Completion: Indicates the user has submitted their signup form | |
// information and should see the completion message. | |
//-------------------------------------------------------------------- | |
function SFStageInit(ctrlID) { | |
var tblSFError; | |
var tblSFCompletion; | |
var tblSFMain; | |
var hidSFStage; | |
var sfStage; | |
sfStage = Request.QueryString["SFStage"]; | |
hidSFStage = document.getElementById(ctrlID); | |
hidSFStage.value = (sfStage != null) ? sfStage : "Signup"; | |
tblSFError = document.getElementById('tblSFError'); | |
tblSFCompletion = document.getElementById('tblSFCompletion'); | |
tblSFMain = document.getElementById('tblSFMain'); | |
switch (hidSFStage.value) { | |
case "Completion": | |
tblSFCompletion.style.display = ''; | |
break; | |
case "Signup": | |
default: | |
tblSFCompletion.style.display = 'none'; | |
break; | |
} | |
} | |
function SFErrorInit(tblSFErrorID, tdSFErrorID) { | |
var tblSFError; | |
var tdSFError; | |
var sfErr; | |
sfErr = Request.QueryString["SFError"]; | |
tblSFError = document.getElementById(tblSFErrorID); | |
tdSFError = document.getElementById(tdSFErrorID); | |
if (sfErr == undefined) | |
sfErr = ""; | |
tdSFError.innerHTML = sfErr; | |
tblSFError.style.display = (sfErr == "") ? "none" : ""; | |
} | |
function SFValidateTextField(controlField, bDate, bNumber, bPhone) { | |
var textValue = controlField.value; | |
if (bDate) { | |
if (!SFIsValidDate(textValue)) { | |
window.alert(textValue + " is not a valid date format. Enter date with mm/dd/yyyy format."); | |
controlField.focus(); | |
return false; | |
} | |
} | |
else if (bNumber) { | |
if (!SFIsValidNumber(textValue)) { | |
window.alert(textValue + " is not a valid number."); | |
controlField.focus(); | |
return false; | |
} | |
} | |
else if (bPhone) { | |
var isValidPhone = SFValidatePhoneNumber(textValue); | |
if (!isValidPhone) { | |
window.alert(textValue + " is not a valid phone number. Enter a valid phone number."); | |
controlField.focus(); | |
return false; | |
} | |
} | |
return (true); | |
} | |
function SFIsValidDate(dateStr, format) { | |
if (format == null) | |
{ format = "MDY"; } | |
format = format.toUpperCase(); | |
if (format.length != 3) | |
{ format = "MDY"; } | |
if ((format.indexOf("M") == -1) || (format.indexOf("D") == -1) || (format.indexOf("Y") == -1)) | |
{ format = "MDY"; } | |
if (format.substring(0, 1) == "Y") { // If the year is first | |
var reg1 = /^\d{2}(\-|\/|\.)\d{1,2}\1\d{1,2}$/ | |
var reg2 = /^\d{4}(\-|\/|\.)\d{1,2}\1\d{1,2}$/ | |
} | |
else if (format.substring(1, 2) == "Y") { // If the year is second | |
var reg1 = /^\d{1,2}(\-|\/|\.)\d{2}\1\d{1,2}$/ | |
var reg2 = /^\d{1,2}(\-|\/|\.)\d{4}\1\d{1,2}$/ | |
} | |
else { // The year must be third | |
var reg1 = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{2}$/ | |
var reg2 = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/ | |
} | |
// If it doesn't conform to the right format (with either a 2 digit year or 4 digit year), fail | |
if ((reg1.test(dateStr) == false) && (reg2.test(dateStr) == false)) | |
{ return false; } | |
var parts = dateStr.split(RegExp.$1); // Split into 3 parts based on what the divider was | |
// Check to see if the 3 parts end up making a valid date | |
if (format.substring(0, 1) == "M") | |
{ var mm = parts[0]; } | |
else if (format.substring(1, 2) == "M") | |
{ var mm = parts[1]; } | |
else | |
{ var mm = parts[2]; } | |
if (format.substring(0, 1) == "D") | |
{ var dd = parts[0]; } | |
else if (format.substring(1, 2) == "D") | |
{ var dd = parts[1]; } | |
else | |
{ var dd = parts[2]; } | |
if (format.substring(0, 1) == "Y") | |
{ var yy = parts[0]; } | |
else if (format.substring(1, 2) == "Y") | |
{ var yy = parts[1]; } | |
else | |
{ var yy = parts[2]; } | |
if (parseFloat(yy) <= 50) | |
{ yy = (parseFloat(yy) + 2000).toString(); } | |
if (parseFloat(yy) <= 99) | |
{ yy = (parseFloat(yy) + 1900).toString(); } | |
var dt = new Date(parseFloat(yy), parseFloat(mm) - 1, parseFloat(dd), 0, 0, 0, 0); | |
if (parseFloat(dd) != dt.getDate()) | |
{ return false; } | |
if (parseFloat(mm) - 1 != dt.getMonth()) | |
{ return false; } | |
return true; | |
} | |
function SFIsValidNumber(numberStr) { | |
var objRegExp = /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/; | |
// Check for numeric characters | |
return objRegExp.test(numberStr); | |
} | |
function SFValidatePhoneNumber(numberStr) { | |
//Store all the illegal characters here | |
var illegalChars = ""; | |
//process to remove non-numbers and spaces | |
for (var i = 0; i < numberStr.length; i++) { | |
var character = numberStr.charAt(i); | |
if (isNaN(character) && character != "-" && character != "(" && character != ")" && character != " " | |
&& character != "+" && character != ".") | |
illegalChars += character; | |
} | |
return (illegalChars.length == 0); | |
} | |
function SFValidateEmailField(controlField) { | |
var textValue = controlField.value; | |
if (!SFIsValidEmail(textValue)) { | |
window.alert(textValue + " does not seem to be a valid email address; (e.g. johndoe@mydomain.com)."); | |
controlField.focus(); | |
return false; | |
} | |
return true; | |
} | |
function SFIsValidEmail(emailStr) { | |
var regExEmailBad = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid | |
var regExEmailOK = /^.+\@(\[?)[a-zA-Z0-9_\-\.]+\.([a-zA-Z]{2,6}|[0-9]{1,3})(\]?)$/; // valid | |
return ((!regExEmailBad.test(emailStr) && regExEmailOK.test(emailStr))); | |
//return true; | |
} | |
// e.g. qIDList = SFGetFormVarMatches (/^eemSFQuestion\d*$/, 'input,div'); | |
function SFGetFormVarMatches(regEx, ctrlTypes, formVarMatchHandler) { | |
var ctrlType; | |
var aryCtrlTypes; | |
var aryCtrls1; | |
var aryCtrlsFnd = null; | |
var aryCtrlsMatch; | |
var matches; | |
var userData; | |
var ctrlID; | |
aryCtrlsMatch = new Array(0); | |
aryCtrlTypes = ctrlTypes.split(','); | |
for (nIdx = 0; nIdx < aryCtrlTypes.length; nIdx++) { | |
aryCtrlsFnd = document.getElementsByTagName(aryCtrlTypes[nIdx]); | |
for (nIdx2 = 0; nIdx2 < aryCtrlsFnd.length; nIdx2++) { | |
ctrlID = aryCtrlsFnd[nIdx2].name; | |
matches = regEx.exec(ctrlID); | |
if (matches == null) | |
continue; | |
if (formVarMatchHandler != null) | |
userData = formVarMatchHandler(aryCtrlsFnd[nIdx2], matches); | |
aryCtrlsMatch.push(userData); | |
} | |
} | |
return (aryCtrlsMatch); | |
} | |
//------------------------------------------------------------------------- | |
// Signup Forms Version 2 | |
//------------------------------------------------------------------------- | |
//**************Changes to this also must be made at Subscriber.js!!******* | |
//**************Changes to this also must be made at Subscriber.js!!******* | |
//**************Changes to this also must be made at Subscriber.js!!******* | |
var validate = false; | |
var isInPreview = false; | |
var sid = ""; | |
function SFInit() { | |
try { | |
if (window.location.href.toLowerCase().indexOf("signupform.aspx") > 0) { //preview window | |
isInPreview = true; | |
} | |
} | |
catch (err) { | |
alert(err.message); | |
} | |
var SF2 = document.getElementById("frmEEMSignupForm"); | |
var undefined; | |
if (SF2 == undefined) { //version 1 | |
SFContextInit('hidSFContext'); | |
SFStageInit('hidSFStage'); | |
SFErrorInit('tblSFError', 'tdSFError'); | |
} | |
else { //version 2 | |
SF2_Init(); | |
} | |
} | |
SFInit(); | |
function isVersion(left, oper, right) { | |
if (left) { | |
var pre = /pre/i, | |
replace = /[^\d]+/g, | |
oper = oper || "==", | |
right = right || $().jquery, | |
l = left.replace(replace, ''), | |
r = right.replace(replace, ''), | |
l_len = l.length, r_len = r.length, | |
l_pre = pre.test(left), r_pre = pre.test(right); | |
l = (r_len > l_len ? parseInt(l) * ((r_len - l_len) * 10) : parseInt(l)); | |
r = (l_len > r_len ? parseInt(r) * ((l_len - r_len) * 10) : parseInt(r)); | |
switch (oper) { | |
case "==": | |
{ | |
return (true === (l == r && (l_pre == r_pre))); | |
} | |
case ">=": | |
{ | |
return (true === (l >= r && (!l_pre || l_pre == r_pre))); | |
} | |
case "<=": | |
{ | |
return (true === (l <= r && (!r_pre || r_pre == l_pre))); | |
} | |
case ">": | |
{ | |
return (true === (l > r || (l == r && r_pre))); | |
} | |
case "<": | |
{ | |
return (true === (l < r || (l == r && l_pre))); | |
} | |
} | |
} | |
return false; | |
} | |
function SF2_Init() { | |
try { | |
if (typeof jQuery === "undefined" || isVersion(jQuery.fn.jquery, "<", "1.6.2")) { | |
var script_tag = document.createElement('script'); | |
script_tag.setAttribute("type", "text/javascript"); | |
script_tag.setAttribute("src", "http://app.expressemailmarketing.com/poseidon/scripts/jQuery/jquery-1.6.2-full.min.js") | |
script_tag.onload = SF2_Main; // Run main() once jQuery has loaded | |
script_tag.onreadystatechange = function () { // Same thing but for IE | |
if (this.readyState == 'complete' || this.readyState == 'loaded') SF2_Main(); | |
} | |
document.getElementsByTagName("head")[0].appendChild(script_tag); | |
} else { | |
SF2_Main(); | |
} | |
} | |
catch (err) { | |
//something happened in getting jQuery --> disable submit button since validation won't work | |
document.getElementById("btnSFSubmit").disabled = true; | |
show_error_message(err.message); | |
} | |
} | |
function SF2_Main() { | |
var undefined; | |
jQuery.fn.hinttext = function (options) { | |
var defaults = { text: 'Enter a text ...', hinttextclass: '' }; | |
var options = jQuery.extend(defaults, options); | |
return this.each(function () { | |
jQuery(this).focus(function () { | |
if (jQuery(this).val() == options.text) { | |
jQuery(this).val(''); | |
jQuery(this).removeClass(options.hinttextclass); | |
} | |
}); | |
jQuery(this).blur(function () { | |
if (jQuery(this).val() == '') { | |
jQuery(this).val(options.text); | |
jQuery(this).addClass(options.hinttextclass); | |
} | |
}); | |
jQuery(this).blur(); | |
}); | |
}; | |
try { | |
//force an http at the front of website types | |
jQuery(".eemStyleSFWebsite").change(function () { | |
var textVal = this.value.toLowerCase(); | |
if (textVal != "") { | |
if (!/^http(s)?:\/\//.test(textVal)) { | |
this.value = "http://" + this.value; | |
} | |
} | |
SF2_ValidateTextField(this); | |
}); | |
var date_val = ""; | |
//hint text | |
jQuery(".eemStyleSFValue").each(function () { | |
if (jQuery(this).attr("valuetext") != "" && jQuery(this).attr("valuetext") != "%EEMSF_ANSWERVALUE%") { | |
if (jQuery(this).attr("eemsfqtype") == "6") { //dont do for DDL | |
date_val = jQuery(this).attr("valuetext"); | |
} | |
else if (jQuery(this).attr("eemsfqtype") != "4") { //dont do for DDL | |
jQuery(this).val(jQuery(this).attr("valuetext")); | |
} | |
//don't allow editing email address - it is the key to the subscriber | |
if (jQuery(this).attr("eemsfqtype") == "email") { | |
jQuery(this).attr("disabled", "disabled"); | |
} | |
//due to changes for merc ticket 160171, we have to take these off, so that the UI can put them back on. | |
else if (jQuery(this).attr("eemsfqtype") == "12") { | |
var website = jQuery(this).attr("valuetext"); | |
website = website.replace("http**//", "http://"); | |
website = website.replace("https**//", "https://"); | |
jQuery(this).val(website); | |
} | |
} else { | |
if (jQuery(this).attr("eemsfqtype") != 6) { | |
jQuery(this).hinttext({ text: jQuery(this).attr("hinttext"), hinttextclass: "eemStyleSFHintText" }); | |
} | |
} | |
}); | |
require("starfield/sf.datepicker", function () { | |
jQuery("#frmEEMSignupForm").sfDatePicker({ wireup: true, beforeToday: true, zIndex: 9999 }); | |
jQuery(".sf-datepicker").val(date_val); | |
}); | |
jQuery("#btnSFSubmit").live("click", function () { | |
var nonce = jQuery("#btnSFSubmit").attr("eemnonce"); | |
if (SF2_ValidateFields()) { | |
//remove hint-text | |
validate = false; | |
jQuery(".eemStyleSFValue").each(function () { | |
//don't check email field | |
if (jQuery(this).attr("eemsfqtype") != 6){ | |
//if it is just the hint-text | |
if(jQuery(this).attr("hinttext") == jQuery(this).val()) { | |
//then remove it | |
jQuery(this).val(""); | |
} | |
//nuetralize any javascript or html | |
jQuery(this).val(nuetralize(jQuery(this).val())); | |
} | |
}); | |
validate = true; //just in case | |
sid = getParameterByName("sid"); | |
var postData = "MethodName=ProcessRequest&sid=" + sid + "&nonce=" + nonce + "&" + jQuery("#frmEEMSignupForm").serialize(); | |
if (jQuery("#txtSFEmail").attr("disabled") == "disabled") { | |
postData = postData + "&txtSFEmail=" + jQuery("#txtSFEmail").val(); | |
} | |
jQuery.ajax({ | |
type: "POST", | |
url: jQuery("#frmEEMSignupForm").attr("eemaction"), | |
dataType: "jsonp", | |
data: postData, | |
beforeSend: function () { | |
jQuery("#btnSFSubmit").hide(); | |
jQuery("#eemStyleSFAjaxWaitIcon").show(); | |
} | |
}); | |
} | |
}); | |
validate = true; | |
if (!isInPreview) { | |
if (typeof suf_posted_email === 'undefined' || suf_posted_email == "") { | |
jQuery.ajax({ | |
type: "POST", | |
url: jQuery("#frmEEMSignupForm").attr("eemaction").replace("ProcessSubmit", "Nonce"), | |
dataType: "jsonp", | |
data: "MethodName=ProcessRequest" | |
}); | |
} //check for posted email data | |
else if (suf_posted_email != undefined && suf_posted_email != "") { | |
jQuery("#txtSFEmail").val(suf_posted_email); | |
jQuery("#txtSFEmail").removeClass("eemStyleSFHintText"); | |
//if suf only has email -- submit | |
if (jQuery(".eemStyleSFValue").length == 1) { | |
jQuery("#btnSFSubmit").click(); | |
} | |
//else -- just leave the email field populated | |
} | |
} | |
} | |
catch (err) { | |
//something happened in general page processing | |
show_error_message(err.message); | |
} | |
} | |
function SignupFormReturn(json) { | |
var undefined; | |
jQuery("#eemStyleSFAjaxWaitIcon").hide(); | |
jQuery("#btnSFSubmit").show(); | |
if (json.ErrorMessage != undefined) { //error | |
//show error message | |
show_error_message(json.ErrorMessage); | |
} | |
else { //success | |
jQuery("#tblSFError").hide(); | |
jQuery("#btnSFSubmit").attr("disabled", true); | |
if (json.SignupFormCompletionMessageType == 1) { //show message on this "page" | |
jQuery("#tblSFCompletionText").html(json.SuccessMessage); | |
jQuery("#tblSFCompletion").show(); | |
jQuery("#eemStyleSFCompletionIcon").show(); | |
} | |
else if (json.SignupFormCompletionMessageType == 2) { //show this message on "another page" | |
jQuery("#divMainOuter").hide(); | |
jQuery("#tblSFCompletionTextOtherPage").html(json.SuccessMessage); | |
jQuery("#tblSFCompletionOtherPage").addClass("eemStyleSFMainOuter") | |
jQuery("#tblSFCompletionOtherPage").show(); | |
jQuery("#eemStyleSFCompletionIconOtherPage").show(); | |
} | |
else { //(json.SignupFormCompletionMessageType == 2) --> customURL | |
window.location = json.RedirectURL; | |
} | |
} | |
} | |
function NonceReturn(str) { | |
jQuery("#btnSFSubmit").attr("eemnonce", str); | |
} | |
function show_error_message(msg) { | |
var err_div_inner = document.getElementById("tdSFError"); | |
var err_icon = document.getElementById("eemStyleSFErrorIcon"); | |
var err_div_outer = document.getElementById("tblSFError"); | |
err_div_inner.innerHTML = msg; | |
err_div_inner.style.display = "block"; | |
err_icon.style.display = "block"; | |
err_div_outer.style.display = "block"; | |
} | |
function SF2_IsValidDate(dateStr, format) { | |
if (format == null) | |
{ format = "MDY"; } | |
format = format.toUpperCase(); | |
if (format.length != 3) | |
{ format = "MDY"; } | |
if ((format.indexOf("M") == -1) || (format.indexOf("D") == -1) || (format.indexOf("Y") == -1)) | |
{ format = "MDY"; } | |
if (format.substring(0, 1) == "Y") { // If the year is first | |
var reg1 = /^\d{2}(\-|\/|\.)\d{1,2}\1\d{1,2}$/ | |
var reg2 = /^\d{4}(\-|\/|\.)\d{1,2}\1\d{1,2}$/ | |
} | |
else if (format.substring(1, 2) == "Y") { // If the year is second | |
var reg1 = /^\d{1,2}(\-|\/|\.)\d{2}\1\d{1,2}$/ | |
var reg2 = /^\d{1,2}(\-|\/|\.)\d{4}\1\d{1,2}$/ | |
} | |
else { // The year must be third | |
var reg1 = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{2}$/ | |
var reg2 = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/ | |
} | |
// If it doesn't conform to the right format (with either a 2 digit year or 4 digit year), fail | |
if ((reg1.test(dateStr) == false) && (reg2.test(dateStr) == false)) | |
{ return false; } | |
var parts = dateStr.split(RegExp.$1); // Split into 3 parts based on what the divider was | |
// Check to see if the 3 parts end up making a valid date | |
if (format.substring(0, 1) == "M") | |
{ var mm = parts[0]; } | |
else if (format.substring(1, 2) == "M") | |
{ var mm = parts[1]; } | |
else | |
{ var mm = parts[2]; } | |
if (format.substring(0, 1) == "D") | |
{ var dd = parts[0]; } | |
else if (format.substring(1, 2) == "D") | |
{ var dd = parts[1]; } | |
else | |
{ var dd = parts[2]; } | |
if (format.substring(0, 1) == "Y") | |
{ var yy = parts[0]; } | |
else if (format.substring(1, 2) == "Y") | |
{ var yy = parts[1]; } | |
else | |
{ var yy = parts[2]; } | |
if (parseFloat(yy) <= 50) | |
{ yy = (parseFloat(yy) + 2000).toString(); } | |
if (parseFloat(yy) <= 99) | |
{ yy = (parseFloat(yy) + 1900).toString(); } | |
var dt = new Date(parseFloat(yy), parseFloat(mm) - 1, parseFloat(dd), 0, 0, 0, 0); | |
if (parseFloat(dd) != dt.getDate()) | |
{ return false; } | |
if (parseFloat(mm) - 1 != dt.getMonth()) | |
{ return false; } | |
return true; | |
} | |
function SF2_IsValidNumber(numberStr) { | |
var objRegExp = /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/; | |
// Check for numeric characters | |
return objRegExp.test(numberStr); | |
} | |
function SF2_IsValidPhoneNumber(numberStr) { | |
//Store all the illegal characters here | |
var illegalChars = ""; | |
//process to remove non-numbers and spaces | |
for (var i = 0; i < numberStr.length; i++) { | |
var character = numberStr.charAt(i); | |
if (isNaN(character) && character != "-" && character != "(" && character != ")" && character != " " | |
&& character != "+" && character != ".") | |
illegalChars += character; | |
} | |
return (illegalChars.length == 0); | |
} | |
function SF2_IsValidEmail(emailStr) { | |
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(emailStr); | |
} | |
function SF2_IsValidWebsite(textval) { | |
var urlregex = new RegExp("^(http|https)\://([a-zA-Z0-9\.\-]+(\:[a-zA-Z0-9\.&%\$\-]+)*@)*((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|([a-zA-Z0-9\-]+\.)*[a-zA-Z0-9\-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(\:[0-9]+)*(/($|[a-zA-Z0-9\.\,\?\'\\\+&%\$#\=~_\-]+))*$"); | |
return urlregex.test(textval); | |
} | |
function SF2_ValidateTextField(controlField) { | |
if (validate) { | |
return SF2_Validate_Field(controlField); | |
} | |
} | |
function SF2_ValidateFields() { | |
if (validate) { | |
var formValid = true; | |
//loop over each control | |
jQuery.each(jQuery(".eemStyleSFValue"), function () { | |
if (!SF2_Validate_Field(this) && formValid) { | |
formValid = false; | |
} | |
}); | |
return formValid; | |
} | |
} | |
function SF2_Validate_Field(cntrl) { | |
var cntrlValid = true; | |
try { | |
//set the values for that control | |
var textValue = cntrl.value; | |
var eemsfqisreq = jQuery(cntrl).attr("eemsfqisreq"); | |
var currentID = jQuery(cntrl).attr("eemsfqid"); | |
var questionType = jQuery(cntrl).attr("eemsfqtype"); | |
var cntrlhinttext = jQuery(cntrl).attr("hinttext"); | |
//if required && empty | |
if ((eemsfqisreq == "true" || eemsfqisreq == "True") | |
&& (textValue == "" || textValue == cntrlhinttext)) { | |
errorMessage = jsonSignupFormTranslation.Questionvalidation1; | |
cntrlValid = false; | |
if (questionType == "email") { | |
currentID = "Email"; | |
jQuery("#eemSFQuestionErrorEmail").html(errorMessage); | |
jQuery("#eemSFQuestionErrorEmail").show(); | |
} | |
} //handle lists and multi-lists | |
else if ((eemsfqisreq == "true" || eemsfqisreq == "True") | |
&& (questionType == 3 || questionType == 4)) { | |
if (jQuery("option:selected", cntrl).index() == 0) { | |
errorMessage = jsonSignupFormTranslation.Questionvalidation1; | |
cntrlValid = false; | |
} | |
} | |
else { //checked required above | |
if (questionType == 6 && textValue != "" && textValue != cntrlhinttext) { //date | |
if (!SF2_IsValidDate(textValue)) { | |
errorMessage = jsonSignupFormTranslation.Invalidquestiondatevalidation; | |
cntrlValid = false; | |
} | |
} | |
else if (questionType == 5 && textValue != "" && textValue != cntrlhinttext) { //number | |
if (!SF2_IsValidNumber(textValue)) { | |
errorMessage = jsonSignupFormTranslation.Invalidquestionnumericvalidation; | |
cntrlValid = false; | |
} | |
} | |
else if (questionType == 7 && textValue != "" && textValue != cntrlhinttext) { //phone | |
if (!SF2_IsValidPhoneNumber(textValue)) { | |
errorMessage = jsonSignupFormTranslation.invalidhomephonevalidation; | |
cntrlValid = false; | |
} | |
} | |
else if (questionType == 12 && textValue != "" && textValue != cntrlhinttext) { //website | |
if (!SF2_IsValidWebsite(textValue)) { | |
errorMessage = jsonSignupFormTranslation.invalidwebsitevalidation; | |
cntrlValid = false; | |
} | |
} | |
else if (questionType == "email") { //website --> always required | |
if (!SF2_IsValidEmail(textValue)) { | |
errorMessage = jsonSignupFormTranslation.invalidemailaddressvalidation; | |
jQuery("#eemSFQuestionErrorEmail").html(errorMessage); | |
jQuery("#eemSFQuestionErrorEmail").show(); | |
} | |
else { | |
jQuery("#eemSFQuestionErrorEmail").hide(); | |
} | |
} | |
} | |
//set the validation div accordingly | |
if (questionType != "email") { | |
if (cntrlValid) { | |
jQuery("#eemSFQuestionError" + currentID).hide(); | |
} | |
else { | |
jQuery("#eemSFQuestionError" + currentID).html(errorMessage).show(); | |
} | |
} | |
} | |
catch (err) { | |
show_error_message(err.Message); | |
} | |
return cntrlValid; | |
} | |
function getParameterByName(name) { | |
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]"); | |
var regexS = "[\\?&]" + name + "=([^&#]*)"; | |
var regex = new RegExp(regexS); | |
var results = regex.exec(window.location.search); | |
if (results == null) | |
return ""; | |
else | |
return decodeURIComponent(results[1].replace(/\+/g, " ")); | |
} | |
function nuetralize(str) { | |
str = str.replace(" & ", " & "); | |
str = str.replace(/</g, "<").replace(/>/g, ">"); | |
return str; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment