$.validator.addMethod('address',function(value){return/^([0-9a-zA-Z-]+\s[0-9a-zA-Z-\s#.,]+)$/.test(value);},'Please enter a valid address.');var beforeSubmit=function(){};var submitDelay=0;var _config={rules:{email:{required:true,email:true,maxlength:50},incentiveId:{required:true,digits:true},optIn:{required:true},firstName:{required:true,maxlength:50},lastName:{required:true,maxlength:50},street:{required:true,maxlength:50},city:{required:true,maxlength:50},postalCode:{required:true,digits:true,rangelength:[5,5]},state:{required:true},birthYear:{required:true,maxlength:4,digits:true},gender:{required:true,maxlength:50},homeAreaCode:{required:true,digits:true,rangelength:[3,3]},homePrefix:{required:true,digits:true,rangelength:[3,3]},homeSuffix:{required:true,digits:true,rangelength:[4,4]},validPhone:{required:false,min:1},password:{required:true,maxlength:50},confirmPassword:{equalTo:"#password"}},messages:{email:{required:"Please enter your email.",maxlength:jQuery.format("The length of email address cannot exceed {0} characters.")},incentiveId:{required:"Please select an incentive.",digits:"Incentive id should be number only."},optIn:{required:"You must agree to the terms to continue."},firstName:{required:"Please enter your first name.",maxlength:jQuery.format("Please enter no more than {0} characters for first name.")},lastName:{required:"Please enter your last name.",maxlength:jQuery.format("Please enter no more than {0} characters for last name.")},street:{required:"Please enter street.",maxlength:jQuery.format("Please enter no more than {0} characters street.")},city:{required:"Please enter city.",maxlength:jQuery.format("Please enter no more than {0} characters city.")},postalCode:{required:"Please enter zipcode.",digits:"Zipcode should be number only.",rangelength:jQuery.format("Zipcode should be {0} digits.")},state:{required:"Pleaase enter state."},birthYear:{required:"Please select your birth year.",maxlength:jQuery.format("The length of birth year cannot exceed {0} digits."),digits:"Birth year should be number only."},gender:{required:"Please select your gender.",maxlength:""},homeAreaCode:{required:"Please enter home phone area code.",digits:"Home phone area code should be number only.",rangelength:jQuery.format("The length of home phone area code must be {0} digits.")},homePrefix:{required:"Please enter home phone prefix.",digits:"Home phone prefix should be number only.",rangelength:jQuery.format("The length of home phone prefix must be {0} digits.")},homeSuffix:{required:"Please enter home phone suffix.",digits:"Home phone suffix should be number only.",rangelength:jQuery.format("The length of home phone suffix must be {0} digits.")},validPhone:{min:"Please enter a valid phone number."},password:{required:"Please enter your password.",maxlength:jQuery.format("The length of password cannot exceed {0} characters.")},confirmPassword:{equalTo:"Please enter the same password again."}},submitHandler:function(form){$(window).unbind('unload');beforeSubmit();function handleFormSubmit(){form.submit();};if(submitDelay>0){window.setTimeout(handleFormSubmit,submitDelay);}else{form.submit();}}}
$.fn.selectOptions=function(value,clear)
{var v=value;var vT=typeof(value);var c=clear||false;if(vT!="string"&&vT!="function"&&vT!="object")return this;this.each(function()
{if(this.nodeName.toLowerCase()!="select")return this;var o=this.options;var oL=o.length;for(var i=0;i<oL;i++)
{if(v.constructor==RegExp)
{if(o[i].value.match(v))
{o[i].selected=true;}
else if(c)
{o[i].selected=false;}}
else
{if(o[i].value==v)
{o[i].selected=true;}
else if(c)
{o[i].selected=false;}}}});return this;};function postalCodeLookup(o){$("#city").attr({value:o.city});$("#state").selectOptions(o.state,true);}
function updateValidPhone(o){$("#validPhone").attr({value:o.value});}
function initValidPhone()
{$.ajax({dataType:'jsonp',jsonp:'jsonp_callback',url:'http://scr.'+_siteUrl+'/phone/validate_US.php',success:function(){}});}
function checkPhoneAreaCodeAndPrefix(event)
{var homeAreaCode=$('#homeAreaCode').val();var homePrefix=$('#homePrefix').val();if(homeAreaCode.length==3&&parseInt(homeAreaCode)!="NaN"&&homePrefix.length==3&&parseInt(homePrefix)!="NaN")
{$.ajax({dataType:'jsonp',jsonp:'jsonp_callback',url:'http://scr.'+_siteUrl+'/phone/validate_US.php?area_code='+homeAreaCode+'&prefix='+homePrefix,success:function(){}});}}
$(document).ready(function(){if(_templateClass=="PROFILE"){$("#postalCode").attr({maxlength:"5"});$("#homeAreaCode").attr({maxlength:"3"});$("#homePrefix").attr({maxlength:"3"});$("#homeSuffix").attr({maxlength:"4"});$('#homeAreaCode').autotab({target:'homePrefix',format:'numeric'});$('#homePrefix').autotab({target:'homeSuffix',format:'numeric'});}
if((_campaignId=="694"||_campaignId=="539"||_campaignId=="540")&&_templateClass=="PROFILE")
{_config.rules.street.address=true;_config.messages.street.address="Please enter a valid address.";$("#commandBean").append('<input type="hidden" id="validPhone" name="validPhone" value="1">');initValidPhone();$('#homeAreaCode').keyup(checkPhoneAreaCodeAndPrefix);$('#homePrefix').keyup(checkPhoneAreaCodeAndPrefix);}
$("#commandBean").validate(_config);$("#postalCode").keyup(function(event){var usZip=new RegExp(/(^\d{5}$)|(^\d{5}-\d{4}$)/);var value=$("#postalCode").attr("value");if(usZip.test(value)){$.ajax({dataType:'jsonp',data:'pc='+value,jsonp:'jsonp_callback',url:'http://scr.'+_siteUrl+'/postalCode/lookup_US.php',success:function(){}});}
event.preventDefault();});});
