var string = '';
var badChars = "%^()+=[]\\\';{}|\":<>?";
var badCharsreg = /\%|\^|\*|\(|\)|\+|\=|\[|\]|\\\|\'|\{|\}|\"|\:|\<|\>|\?/g;
var jsmaxlength ='Maximum Length allowed';
var jsbadcharacters='Characters NOT Allowed :';
var goodChars = "._#*@&,/- ";
var goodCharsreg = / ._@#*&,\/-/g;
//-------------------------
//Validate Member Application
function MemberValidate(theForm) {
valcheck=true;
if (!JSFNvalidTxtfld(theForm.username,'username',1,'Please check the username entered.',badCharsreg)){return false;}
if (!JSFNvalidTxtfld(theForm.password,'password',1,'Please check the password entered.',badCharsreg)){return false;}
if (theForm.password.value != theForm.password2.value) {alert('Your passwords do not match - Please reenter them.');theForm.password.focus(); return false;}
if (fieldexists ("securityanswer")){
var secquestion = theForm.securityquestion.options[theForm.securityquestion.selectedIndex].value;
var secquestioncustom = theForm.securityquestioncustom.value;
if (secquestion.length ==0 && secquestioncustom.length==0){alert('Please Select a Security Question.');return false;}
if (!JSFNvalidTxtfld(theForm.securityanswer,'string',,'Please enter a security answer.',badCharsreg)){return false;}
}
if (!JSFNvalidTxtfld(theForm.emailaddress,'email',,'Please check your Email Address',badCharsreg)){return false;}
if (theForm.emailaddress.value != theForm.emailaddress2.value) {alert('your Email Address do not appear to match - Please reenter them.');theForm.emailaddress.focus();return false;}
if (!JSFNvalidTxtfld(theForm.firstname,'alphanumeric',,'Please check your first name',badCharsreg)) {return false;}
if (!JSFNvalidTxtfld(theForm.lastname,'alphanumeric',,'Please check your last name',badCharsreg)) {return false;}
if (!JSFNvalidTxtfld(theForm.companyname,'alphanumeric',,'please check the Company name',badCharsreg)) {return false;}
if (!JSFNvalidTxtfld(theForm.phone,'phone',,'Please check the Phone number',badCharsreg)) {return false;}
if (!JSFNvalidTxtfld(theForm.cellphone,'phone',,'Please check the Cell phone value entered.',badCharsreg)) {return false;}
if (!JSFNvalidTxtfld(theForm.imname,'alphanumeric',,'Please enter Your MSN username',badCharsreg)) {return false;}
if (!JSFNvalidTxtfld(theForm.skypename,'alphanumeric',,'Please enter your Skype Username',badCharsreg)) {return false;}
if (!JSFNvalidTxtfld(theForm.address1,'alphanumeric',,'Please check the Street Address',badCharsreg)) {return false;}
if (!JSFNvalidTxtfld(theForm.address2,'alphanumeric',,'Please enter your City.',badCharsreg)) {return false;}
if (!JSFNvalidTxtfld(theForm.zip,'alphanumeric',,'Please check the Zip/ Postal code',badCharsreg)) {return false;}
if (!JSFNvalidTxtfld(theForm.country,'select-one',,'Please enter your Country.',badCharsreg)) {return false;}
if (!JSFNvalidTxtfld(theForm.siteurl,'website',,'Please check your website URL','')) {return false;}
if (!JSFNvalidTxtfld(theForm.category,'select-one',,'jsselectcategory','')) {return false;}
if (!JSFNvalidTxtfld(theForm.targetmarket,'select-one',,'Select an option that best describes your Primary Target Market.','')) {return false;}
if (!JSFNvalidTxtfld(theForm.preflangid,'numeric',,'jsselectpreflanguage','')) {return false;}
if (!JSFNvalidTxtfld(theForm.prefcontact,'string',,'jsselectprefcontact','')) {return false;}
if (!JSFNvalidTxtfld(theForm.hearaboutus,'select-one',,'jsselecthowyouheard','')) {return false;}
if (!ValidatepaymentOptions(theForm)) return false;
if (!validTick(theForm.agree,"agree",'You must agree to the Terms and conditions to Join the Program.')) {return false; }
if (fieldexists ("agree2")){if (!validTick(theForm.agree2,"agree2",'You must agree to the Terms and conditions to Join the Program.')) return false;}
return true;
}
var appendmessage = '';
var passwordstrengthlevel = '';
var passwordlength = '';
function JSFNvalidTxtfld(formField,fieldtype,fieldstatusid,Message,stripbadchar) {
var result = true;
if (fieldstatusid == "1") { fieldstatus=true;} else { fieldstatus=false;}
if (isObject(formField)) {
switch(formField.type.toLowerCase()) {
case 'text':
rawstr=formField.value;
result = JSfieldtypvalidation(fieldtype,rawstr,formField,fieldstatus )
if (!result){alert(Message + appendmessage);}
break;
case 'password':
rawstr=formField.value;
result = JSfieldtypvalidation(fieldtype,rawstr,formField,fieldstatus)
if (!result){alert(Message + appendmessage);}
break;
case 'textarea':
rawstr=formField.value;
result = JSfieldtypvalidation(fieldtype,rawstr,formField,fieldstatus )
if (!result){alert(Message + appendmessage);}
break;
case 'checkbox':
if (!formField.checked){alert(Message + appendmessage);formField.focus();result = false;}
break;
case 'select-one':
if (formField.selectedIndex==-1){alert(Message + appendmessage);formField.focus();result = false;}
break;
}
}
appendmessage='';
return result;
}
function JSfieldtypvalidation(fieldtype,fieldvalue,formField,fieldstatus ) {
result = true;
if (fieldtype.toLowerCase()!='website') {
if (fieldvalue.match(badCharsreg)) {
alert(jsbadcharacters + ' ' + fieldvalue + ' ');
str = fieldvalue.replace(badCharsreg,"");
formField.value = str;formField.focus();
result = false;
}
}
if( result) {
switch(fieldtype.toLowerCase()) {
case 'username':
result = isString(fieldvalue);
break;
case 'password':
result = isPassword(fieldvalue);
break;
case 'string':
result = isString(fieldvalue);
break;
case 'alpha':
result = isAlpha(fieldvalue);
break;
case 'alphanumeric':
result = isAlphanumeric(fieldvalue);
break;
case 'numeric':
result = JSFNvalidateInteger(fieldvalue);
break;
case 'phone':
result = isPhone(fieldvalue);
break;
case 'email':
result = isEmail(fieldvalue);
break;
case 'website':
result = isWebsite(fieldvalue);
break;
}
}
if (fieldstatus) {
if (result){if (formField.value == ""){result = false;}}
}
if (!result){ formField.focus();}
return result;
}
function JSFNvalidHTTP(formfield,Message) {
result = true;
if (JSFNfieldexists(formfield)){
var wholeurl = formfield.value;
var urlprefix = wholeurl.substring(0, 7);
if (urlprefix.toLowerCase()=="http://") {result = true;}
else {if (urlprefix.toLowerCase()=="https://") {result = true;}else {alert(Message);formfield.focus();result = false;};};
}
return result;
}
function validTick (formfield,fieldLabel,Message){
result = true;
if (JSFNfieldexists(fieldLabel)){
var result = formfield.checked ;
if (!result){alert(Message);}
}
return result;
}
function JSFNemailvalidate(formField,alertmessage,stripbadchar) {
str = formField.value;
var at="@";
var dot=".";
var lat=str.indexOf(at);
var lstr=str.length;
var ldot=str.indexOf(dot);
if (stripbadchar.length>0){ str = str.replace(stripbadchar,""); formField.value = str;}
if (str.indexOf(at)==-1){ alert(alertmessage);formField.focus(); return false;}
else if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){ alert(alertmessage);formField.focus(); return false;}
else if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){alert(alertmessage);formField.focus(); return false;}
else if (str.indexOf(at,(lat+1))!=-1){alert(alertmessage);formField.focus(); return false; }
else if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){ alert(alertmessage);formField.focus(); return false; }
else if (str.indexOf(dot,(lat+2))==-1){alert(alertmessage);formField.focus(); return false;}
else if (str.indexOf(" ")!=-1){alert(alertmessage);formField.focus(); return false; }
return true;
}
function JSFNbadcharcheck (iChars, fieldvalue) {
for (var i = 0; i < fieldvalue.length; i++) {if (iChars.indexOf(fieldvalue.charAt(i)) != -1) {return true;}}
return false;
}
function JSFNvalidCustomfld(formField,isrequired, maxlength,valuetype,Message,stripbadchar) {
var result = true;
if (isObject(formField)){
switch(formField.type.toLowerCase()) {
case 'text':
if (!isrequired && formField.value == ""){return true;}
rawstr=formField.value;
if (valuetype=='number'){if(!JSFNvalidateInteger(rawstr)){alert(Message);formField.focus();result = false;}}
if (rawstr.length > maxlength ){alert( jsmaxlength + ' ' + maxlength + '. ' + Message);formField.focus();result = false;}
if (isFunction(stripbadchar)){if (rawstr.match(stripbadchar)){alert(badChars + ' ' + jsbadcharacters + ' ' + Message);str = rawstr.replace(stripbadchar,""); formField.value = str;formField.focus();result = false;}}
if (isrequired==true){ if (result){if (formField.value == ""){alert(Message);formField.focus();result = false;}} }
break;
case 'textarea':
if (!isrequired && formField.value == ""){return true;}
rawstr=formField.value;
if (valuetype=='number'){if(!JSFNvalidateInteger(rawstr)){alert(Message);formField.focus();result = false;}}
if (rawstr.length > maxlength ){alert( jsmaxlength + ' ' + maxlength + '. ' + Message);formField.focus();result = false;}
if (isFunction(stripbadchar)){if (rawstr.match(stripbadchar)){alert(badChars + ' ' + jsbadcharacters + ' ' + Message);str = rawstr.replace(stripbadchar,""); formField.value = str;formField.focus();result = false;}}
if (isrequired==true){if (result){if (formField.value == ""){alert(Message);formField.focus();result = false;}} }
break;
case 'checkbox':
if (!isrequired){return true;}
if (!formField.checked){alert(Message);formField.focus();result = false;}
break;
case 'select-one':
if (!isrequired){return true;}
if (formField.selectedIndex==-1){alert(Message);formField.focus();result = false;}
break;
}
}
return result;
}
function JSFNvalidateInteger( strValue ) { var objRegExp = /(^-?\d\d*$)/; return objRegExp.test(strValue);}
function isset(varname){ return(typeof(varname)!='undefined');}
function isFunction(o) {return 'function' == typeof o;}
function isObject(o) {return 'object' == typeof o;}
function JSFNfieldexists (fieldname) {
var result = false;
if (document.layers){fieldcheck = document.layers[fieldname];}
else if (document.getElementById){fieldcheck = document.getElementById(fieldname);}
else if (document.all){ fieldcheck = document.all[fieldname];}
if (fieldcheck!=null){ result = true;}
return result;
}
function isString(strValue) {
if ((strValue == "" ) || (strValue.match(/^[a-zA-Z0-9 ._@#*&,\/-]+$/))) {
return true;
} else {
appendmessage = " (Allowed : a-zA-Z0-9 ._@#*&,\/-)";
return false;
}
}
function isPassword(strValue) {
if (passwordlength>0){
if (strValue.length < passwordlength){
appendmessage = 'The Password is too short - it must be at lease [passwordlength] characters long.';
appendmessage = appendmessage.replace('[passwordlength]',passwordlength);
return false;
}
}
if (passwordstrengthlevel>0) {
var checkstrength = testPassword(strValue);
if (passwordstrengthlevel> (checkstrength+1)){ // not strong enough
appendmessage = 'The Password is too weak - try using both upper and lower case letters, numbers and include Characters like !@#$_~';
return false;
} else{
return true;
}
} else {
if ((strValue == "" ) || (strValue.match(/^[a-zA-Z0-9 ._@#*&,\/-]+$/))) {
return true;
} else {
appendmessage = " (Allowed : a-zA-Z0-9 ._@#*&,\/-)";
return false;
}
}
}
function isAlphanumeric(strValue) {
if ((strValue == "" ) || (strValue.match(/^(.*)+$/))) {
return true;
} else {
appendmessage = " (Allowed : all special characters)";
return false;
}
}
function isAlpha(strValue) { if ((strValue == "" ) || (strValue.match(/^[ a-zA-Z]+$/))){return true;}else{ appendmessage = " (Allowed : a-z)"; return false;} }
function isPhone(strValue){ if ((strValue == "" ) || (strValue.match(/^[ .+()0-9-]+$/))){return true;}else{ return false;} }
function isWebsite (strValue) {
//result = true;
//var wholeurl = strValue;var urlprefix = wholeurl.substring(0, 7);
//if (urlprefix.toLowerCase()=="http://") {result = true;}
//else {if (urlprefix.toLowerCase()=="https:/") {result = true;}else {result = false;};};
//return result;
//if ((strValue == "" ) || (strValue.match(/^((https?|ftp):\/\/)?([\w\d-~]+|([\w\d-~]+\.))\.[0-9a-z]{2,6}\/?([^\s<>\#%"\,\{\}\\|\\\^\[\]`]+)?$/i))){return true;}else{ return false;}
var v = new RegExp();
v.compile("^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$");
if (!v.test(strValue)) {
return false;
}
else{
return true;
}
}
function isEmail(strValue) {
str = strValue;
var at="@";
var dot=".";
var lat=str.indexOf(at);
var lstr=str.length;
var ldot=str.indexOf(dot);
if (str.indexOf(at)==-1){ return false;}
else if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){return false;}
else if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){return false;}
else if (str.indexOf(at,(lat+1))!=-1){return false; }
else if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){ return false; }
else if (str.indexOf(dot,(lat+2))==-1){return false;}
else if (str.indexOf(" ")!=-1){return false; }
return true;
}
function testPassword(passwd) {
var description = new Array();
description[0] = "
";
description[1] = "";
description[2] = "";
description[3] = "";
description[4] = "";
description[5] = "";
var intScore = 0;var strVerdict = 0;
if (passwd.length==0 || !passwd.length) {intScore = -1;}
else if (passwd.length>0 && passwd.length<5){intScore = (intScore+3);}
else if (passwd.length>4 && passwd.length<8){intScore = (intScore+6);}
else if (passwd.length>7 && passwd.length<12){intScore = (intScore+12);}
else if (passwd.length>11){intScore = (intScore+18);}
if (passwd.match(/[a-z]/)){intScore = (intScore+1);}
if (passwd.match(/[A-Z]/)){intScore = (intScore+5);}
if (passwd.match(/\d+/)){intScore = (intScore+5);}
if (passwd.match(/(.*[0-9].*[0-9].*[0-9])/)){intScore = (intScore+5);}
if (passwd.match(/.[!,@,#,$,%,^,&,*,?,_,~]/)){intScore = (intScore+5);}
if (passwd.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/)){intScore = (intScore+5);}
if (passwd.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/)){intScore = (intScore+2);}
if (passwd.match(/(\d.*\D)|(\D.*\d)/)){intScore = (intScore+2);}
if (passwd.match(/([a-zA-Z0-9].*[!,@,#,$,%,^,&,*,?,_,~])|([!,@,#,$,%,^,&,*,?,_,~].*[a-zA-Z0-9])/)){intScore = (intScore+2);}
if(intScore == -1){strVerdict = description[5];
}else if(intScore > -1 && intScore < 16){strVerdict = 0; //description[0];
}else if (intScore > 15 && intScore < 25){strVerdict = 1; // description[1];
}else if (intScore > 24 && intScore < 35){strVerdict = 2; // description[2];
}else if (intScore > 34 && intScore < 45){strVerdict = 3; // description[3];
}else{strVerdict = 4;} // description[4];}
document.getElementById("passtestindicator").innerHTML= (description[strVerdict]);
return strVerdict;
}
function disableautocomp(){
if (JSFNfieldexists('password') && JSFNfieldexists('password2')){
document.getElementById('password').value=document.getElementById('password2').value;
}
}