(function($){fe_validator=function(a){var b=this;if(typeof a=='string'&&a.indexOf('#')==-1){a='#'+a};this.form=$(a);this.inputs=this.form.find(':input');this.form.bind('submit',function(e){b.__submitAction(e)})};fe_validator.prototype.__submitAction=function(e){if(!this.validate(this.inputs)){e.preventDefault();this.alertErrors()}};fe_validator.prototype.validate=function(b){var c=this;var i;var j;var l;var d;var e;var f;var g;var h;this.__resetErrors();$.each(b,function(i,a){if(a.disabled){return}e=[];f=a.className.split(' ');for(j=0,l=f.length;j<l;j++){g=f[j];if(__vl.__isValidator(g)){h=__vl[g](a);if(!h.success){if($(a).data('errorMessage')){e.push($(a).data('errorMessage'))}else{e.push(c.__humanizeName(a.name)+' '+h.message)}}}};if(e.length>0){c.__addErrors(e)}});return!this.errors.length>0};fe_validator.prototype.alertErrors=function(){alert(this.errors.join('\n'))};fe_validator.prototype.__addErrors=function(a){this.errors=$.merge(this.errors,a)};fe_validator.prototype.__resetErrors=function(){this.errors=[]};fe_validator.prototype.__humanizeName=function(a){var b;if(b=a.match(/\[(.*)\]/)){b=b[1]}else{b=a};b=b.replace(/_/g,' ');return b.substr(0,1).toUpperCase()+b.substr(1)};validator_library=function(){};validator_library.prototype.__isValidator=function(a){var b=['valid','error'];return a.indexOf('__')!=0&&$.inArray(a,b)==-1&&a in this};validator_library.prototype.__return=function(a,b){if(!b){b=''}return{'success':a,'message':b}};validator_library.prototype.valid=function(){return this.__return(true)};validator_library.prototype.error=function(a){return this.__return(false,a)};validator_library.prototype.basicString=function(a){if(a.value!=''){return this.valid()};return this.error('is required.')};validator_library.prototype.basicInteger=function(a){if(a.value>0){return this.valid()};return this.error('must be a number.')};validator_library.prototype.email=function(a){if(a.value.match(/^[-a-zA-Z0-9!#$%&'*+\/=?^_`{|}~]+(\.[-a-zA-Z0-9!#$%&'*+\/=?^_`{|}~]+)*@(([a-zA-Z0-9]([-a-zA-Z0-9]*[a-zA-Z0-9]+)?){1,63}\.)+([a-zA-Z0-9]([-a-zA-Z0-9]*[a-zA-Z0-9]+)?){2,63}$/)){return this.valid()};return this.error('must be a valid email address.')};validator_library.prototype.phoneThreeFields=function(a){var b=(a.name.indexOf('mobile')!=-1)?'mobile':'phone';var c=$(':input[name=lead_contact_details['+b+'_area_code]]').val();var d=$(':input[name=lead_contact_details['+b+'_prefix]]').val();var e=$(':input[name=lead_contact_details['+b+'_suffix]]').val();var f=$(':input[name=lead_contact_details[country]]');var g=['CA','US',''];if(f.length>0){if($.inArray(f.val(),g)==-1){return this.valid()}};if(a.value!=''&&!a.value.match(/^\d+$/)){return this.error('must contain only numbers.')};if(a.name=='lead_contact_details['+b+'_area_code]'){if(c.indexOf('1')==0){return this.error('cannot start with 1.')}else if(c.length!=3){return this.error('is not three digits.')}}else if(a.name=='lead_contact_details['+b+'_prefix]'){if(d.indexOf('1')==0){return this.error('cannot start with 1.')}else if(d.length!=3){return this.error('is not three digits.')}else if(d=='555'){return this.error('is an invalid phone prefix (555).')}}else if(a.name=='lead_contact_details['+b+'_suffix]'){if(e.length!=4){return this.error('is not four digits.')}};return this.valid()};validator_library.prototype.phoneOneField=function(a){var b=a.value.replace(/\D/g,'');var c=$(':input[name=lead_contact_details[country]]');var d=/([2-9][0-8]\d)([2-9]\d{2})(\d{4})/;var e;var f=['CA','US',''];if(c.length>0){if($.inArray(c.val(),f)==-1){return this.valid()}};if($.inArray(c.val(),f)!=-1){e=b.match(d);if(e){if(b.indexOf('1')==0){return this.error('cannot start with 1.')}else if(e[2]=='555'){return this.error('has an invalid phone prefix (555).')}}};if(e){return this.valid()}else{return this.error('must be a valid phone number.')}};validator_library.prototype.zipCode=function(a){var b=a.value;var c=/^[A-Z]\d[A-Z][ -]?\d[A-Z]\d$/;var d=/^\d{5}([\-]\d{4})?$/;var e=/^[A-Z]{1,2}[0-9][A-Z0-9]?[ -]?[0-9][ABD-HJLNP-UW-Z]{2}$/;var f=$(':input[name=lead_contact_details[country]]');var g;if(f.length>0){if(f.val()=='CA'){g=b.match(c)}else if(f.val()=='UK'||f.val()=='GB'){g=b.match(e)}else{g=b.match(d)}}else{g=b.match(c)||b.match(d)||b.match(e)};if(g){return this.valid()}else{return this.error('must be a valid zip code.')}};validator_library.prototype.ccNumber=function(a){var b=a.value;var l=b.length;var c=0-l;var d=0;var i;var e;var f;if(l<15){return this.error('must be at least sixteen digits.')};if(!b.match(/^\d+$/)){return this.error('must be a number.')};for(i=-1;i>=c;--i){f=l+i;if(i%2==0){e=2*b.substr(f,1);d+=parseInt(e.toString().substr(0,1));if(e.toString().length>1){d+=parseInt(e.toString().substr(1,1))}}else{d+=parseInt(b.substr(f,1))}};if(d%10!=0){return this.error('must be a valid credit card number.')};return this.valid()};validator_library.prototype.ccExp=function(a){var b=$(':input[name=lead_payment_details[cc_year]]').val();var c=$(':input[name=lead_payment_details[cc_month]]').val();var d;var e=new Date();var f=['January','February','March','April','May','June','July','August','September','October','November','December'];if(a.name!='lead_payment_details[cc_year]'&&a.name!='lead_payment_details[cc_month]'){return this.valid()};if(e.getFullYear()>b){if(a.name=='lead_payment_details[cc_year]'){return this.error(' is in the past ('+b+').')}else{return this.valid()}}else if(e.getFullYear()==b&&(e.getMonth()+1)>c){if(a.name=='lead_payment_details[cc_month]'){return this.error(' is in the past ('+c+' - '+f[c-1]+').')}else{return this.valid()}}else{return this.valid()}};validator_library.prototype.ccv2=function(a){var b=a.value;var c=$(':input[name=lead_payment_details[cc_number]]');var d;if(b==''||!b.match(/^\d+$/)){d=false}else if(c.length>0){if(c.val().substr(0,1)=='3'){d=b.length==4}else{d=b.length==3}}else{d=b.length==4||b.length==3};if(d){return this.valid()}else{return this.error('must be a valid ccv2 number.')}};__vl=new validator_library()})(jQuery);