var EC_Validate={isValid:true,rules:{},errors:[],elements:false,errorMsg:"",error_id:1,phone_format:"($1) $2-$3 x$4",zip_format:"$1-$2",requiredText:"Required Field",prefix:"",tlds:[".com",".net",".org",".biz",".coop",".info",".museum",".name",".pro",".edu",".gov",".int",".mil",".ac",".ad",".ae",".af",".ag",".ai",".al",".am",".an",".ao",".aq",".ar",".as",".at",".au",".aw",".az",".ba",".bb",".bd",".be",".bf",".bg",".bh",".bi",".bj",".bm",".bn",".bo",".br",".bs",".bt",".bv",".bw",".by",".bz",".ca",".cc",".cd",".cf",".cg",".ch",".ci",".ck",".cl",".cm",".cn",".co",".cr",".cu",".cv",".cx",".cy",".cz",".de",".dj",".dk",".dm",".do",".dz",".ec",".ee",".eg",".eh",".er",".es",".et",".fi",".fj",".fk",".fm",".fo",".fr",".ga",".gd",".ge",".gf",".gg",".gh",".gi",".gl",".gm",".gn",".gp",".gq",".gr",".gs",".gt",".gu",".gv",".gy",".hk",".hm",".hn",".hr",".ht",".hu",".id",".ie",".il",".im",".in",".io",".iq",".ir",".is",".it",".je",".jm",".jo",".jp",".ke",".kg",".kh",".ki",".km",".kn",".kp",".kr",".kw",".ky",".kz",".la",".lb",".lc",".li",".lk",".lr",".ls",".lt",".lu",".lv",".ly",".ma",".mc",".md",".mg",".mh",".mk",".ml",".mm",".mn",".mo",".mp",".mq",".mr",".ms",".mt",".mu",".mv",".mw",".mx",".my",".mz",".na",".nc",".ne",".nf",".ng",".ni",".nl",".no",".np",".nr",".nu",".nz",".om",".pa",".pe",".pf",".pg",".ph",".pk",".pl",".pm",".pn",".pr",".ps",".pt",".pw",".py",".qa",".re",".ro",".rw",".ru",".sa",".sb",".sc",".sd",".se",".sg",".sh",".si",".sj",".sk",".sl",".sm",".sn",".so",".sr",".st",".sv",".sy",".sz",".tc",".td",".tf",".tg",".th",".tj",".tk",".tm",".tn",".to",".tp",".tr",".tt",".tv",".tw",".tz",".ua",".ug",".uk",".um",".us",".uy",".uz",".va",".vc",".ve",".vg",".vi",".vn",".vu",".ws",".wf",".ye",".yt",".yu",".za",".zm",".zw"],setupRules:function(c){if(c==null){c="";}if($("validation_rules")){this.rules=JSON.decode($("validation_rules").value);this.errors=this.rules.errors;for(var d in this.rules.formatters){if(EC_Validate[d]){var a=this.rules.formatters[d];for(var b in a){EC_Validate.init_formatter(c+b,d);}}}}if($("requiredText")){this.requiredText=$("requiredText").value;}this.prefix=c;},init_formatter:function(a,b){if($(a)){$(a).addEvent("blur",function(c){EC_Validate[b](c);});}},format_zip:function(b,d){if(b!=""){var b=new Event(b);var a=b.target;}else{var a=d;}var c=a.value.replace(/[^0-9]/g,"");if(c.length>5){a.value=c.replace(/(\d{5})(\d+)/,this.zip_format);}else{a.value=c;}},format_phone:function(b,d){if(b!=""){var b=new Event(b);var a=b.target;}else{var a=d;}var c=a.value.replace(/[^0-9]/g,"");if(c.substring(0,1)==1){c=c.substring(1,c.length);}c=c.replace(/(\d{3})(\d{3})(\d{4})(.*)/,this.phone_format);if(c.substring(c.length-1)=="x"){c=c.substring(0,c.length-2);}a.value=c;},format_taxrate:function(c,d){if(c!=""){var c=new Event(c);var b=c.target;}else{var b=d;}var a=b.value;a=a.replace(/[^.0-9]/gi,"");if(a==""){b.value="";return;}a=(Math.round(a*100))/100;a=(a==Math.floor(a))?a+".00":((a*10==Math.floor(a*10))?a+"0":a);b.value=a+"%";},validate:function(d){for(var f in EC_Validate.rules.formatters){if(EC_Validate[f]){var a=EC_Validate.rules.formatters[f];for(var b in a){if($(b)){EC_Validate[f]("",$(b));}}}}EC_Validate.isValid=true;this.hideErrors(d);this.elements=new Hash();for(var f in this.rules.validators){if(EC_Validate[f]){var a=this.rules.validators[f];for(var b in a){if(!EC_Validate.elements.has(b)||EC_Validate.elements.get(b)==true){if(d[EC_Validate.prefix+b]){var e=$(EC_Validate.prefix+b);if(e.id==""){e=d[EC_Validate.prefix+b];}var c=EC_Validate[f](e,a[b],EC_Validate.prefix);EC_Validate.elements.set(b,c);if(!c){EC_Validate.isValid=false;}}}}}}if(EC_Validate.isValid==false&&this.errorMsg!=""){alert(this.errorMsg);}if($("post_vals")){$("post_vals").value=d.toQueryString();}if(EC_Validate.isValid==false){EC_Validate.showErrorPopup();}return EC_Validate.isValid;},validate_required:function(a){if(a.value==""||($(a.id+"_is_checkbox")&&a.getProperty("checked")==false)){return this.showError("required",a,"");}this.clearError(a);return true;},validate_matches:function(b,a){if(!$(a)){a=this.prefix+a;}if(!$(a)){return true;}if(b.value!=$(a).value){return this.showError("matches",$(a),$(b.id+"_label").text);}this.clearError(b);return true;},validate_min_length:function(b,a){if(b.value.length<a){return this.showError("min_length",b,a);}this.clearError(b);return true;},validate_max_length:function(b,a){if(b.value.length>a){return this.showError("max_length",b,a);}this.clearError(b);return true;},validate_exact_length:function(b,a){if(b.value.length!=a){return this.showError("exact_length",b,a);}this.clearError(b);return true;},validate_alpha:function(a){if(a.value!=a.value.replace(/^[a-zA-Z]+$/,"")){return this.showError("alpha",a,"");}this.clearError(a);return true;},validate_alpha_numeric:function(a){if(a.value.match(/^[0-9a-zA-Z]+$/)){this.clearError(a);return true;}return this.showError("alpha_numeric",a,"");},validate_alpha_dash:function(a){if(a.value!=a.value.replace(/[^a-zA-Z0-9-_]/g,"")){return this.showError("alpha_dash",a,"");}this.clearError(a);return true;},validate_numeric:function(a){if(a.value.match(/^[0-9]+$/)){this.clearError(a);return true;}return this.showError("numeric",a,"");},validate_valid_email:function(a){if(a.value.match(/^[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/)){this.clearError(a);return true;}return this.showError("valid_email",a,"");},validate_valid_ip:function(a){if(a.value.match(/\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/)){this.clearError(a);return true;}return this.showError("valid_ip",a,"");},validate_zip:function(b,a,c){if($(c+"country_code")&&$(c+"country_code").value=="US"){if(b.value.match(/^(\d{5})$/)||b.value.match(/^(\d{5})-(\d+)$/)){this.clearError(b);return true;}return this.showError("zip",b,"");}return true;},validate_phone:function(b,a,c){if($(c+"country_code")&&$(c+"country_code").value=="US"){if(b.value.match(/^\([2-9]\d{2}\)\s?\d{3}\-\d{4}?\s*(\w*)$/)){this.clearError(b);return true;}return this.showError("phone",b,"");}return true;},validate_strong_password:function(a){if(a.value.match(/^(?=.*\d)(?=.*[a-zA-Z])(?!.*\s).*$/)){this.clearError(a);return true;}return this.showError("strong_password",a,"");},validate_domain:function(b){this.clearError(b);if(b){var l=true;var d=b.value.toLowerCase();if(d==""){return true;}d=d.replace(/www\./g,"");d=d.replace(/http:/g,"");d=d.replace(/https:/g,"");d=d.replace(/\//g,"");b.value=d;var a=d.lastIndexOf(".");var f=d.substring(0,a);var c=d.substring(a,d.length);if(f.length>2&&f.length<57){for(var h=0;h<this.tlds.length;h++){if(c==this.tlds[h]){l=true;break;}else{l=false;}}if(l==false){return this.showError("domain_extension",b);}else{for(var g=0;g<f.length;g++){var k=f.charAt(g);var e=k.charCodeAt(0);if((e>47&&e<59)||(e>64&&e<91)||(e>96&&e<123)||e==45||e==46){if((g==0||g==f.length-1)&&e==45){return this.showError("domain_hyphen",b);}}else{return this.showError("domain_special",b);}}return true;}}else{if(f.length<3){return this.showError("domain_short",b);}if(f.length>56){return this.showError("domain_long",b);}return false;}}else{return true;}},validate_credit_card:function(c,e,p){var a=c.value;var t,m,k;if($(p+"cc_type")){t=$(p+"cc_type").value;}if($(p+"cc_month")){m=$(p+"cc_month").value;}if($(p+"cc_year")){k=$(p+"cc_year").value;}if(t==""){return this.showError("cc_length",c,"");}if($(c.id+"_label")){$(c.id+"_label").removeClass("error");}if($("cc_month_label")){$("cc_month_label").removeClass("error");}var f=[];f.amex=[];f.disc=[];f.mstr=[];f.visa=[];f.amex["len"]="15";f.disc["len"]="16";f.mstr["len"]="16";f.visa["len"]="13,16";f.amex["hd"]="34,37";f.disc["hd"]="6011";f.mstr["hd"]="51,52,53,54,55";f.visa["hd"]="4";a=a.replace(/([^0-9]+)/,"");$(c).value=a;var b=f[t]["len"].split(",");var g=false;for(var q=0;q<b.length;q++){if(a.length==b[q]){g=true;}}if(g==false){return this.showError("cc_length",c,"");}if($(c.id+"_label")){$(c.id+"_label").removeClass("error");}var o=f[t]["hd"].split(",");var g=false;for(var q=0;q<o.length;q++){var h=a.substring(0,o[q].toString().length);if(h==o[q]){g=true;}}if(g==false){return this.showError("cc_incorrect",c,"");}var j=a.length&1;var d=0;for(var q=0;q<a.length;q++){var n=parseInt(a.charAt(q));if(!((q&1)^j)){n*=2;if(n>9){n-=9;}}d+=n;}if((d%10)!=0){return this.showError("cc_incorrect",c,"");}var r=new Date();var s=r.getMonth()+1;var l=r.getFullYear();if(k<l){return this.showError("cc_expired",$(p+"cc_exp"));}if(k==l){if(m<s){return this.showError("cc_expired",$(p+"cc_exp"));}}return true;},getErrorString:function(c,d,a){if(a==null){a="";}var b="";if($(d+"_label")){b=$(d+"_label").text;}if(b==""||b==undefined){b=$(d+"_label").innerText;}if(b==""||b==undefined){return"This field is not valid.";}if(this.errors[c]){return sprintf(this.errors[c],b,a);}return sprintf("The %s field is not valid.",b);},showError:function(c,b,a){b.addClass("input_error");if($(b.id+"_label")){$(b.id+"_label").addClass("label_error");}if($(b.id+"_tag")){$(b.id+"_tag").set("text",this.getErrorString(c,b.id,a));}return false;},clearError:function(a){a.removeClass("input_error");if($(a.id+"_label")){$(a.id+"_label").removeClass("label_error");}if($(a.id+"_tag")){$(a.id+"_tag").set("text",this.requiredText);}},hideErrors:function(a){a.getChildren().each(function(b){if(b.hasClass("input_error")){EC_Validate.clearError(b);}});},showErrorPopup:function(){if($("error_popup")){var f=Window.getScrollLeft();var e=Window.getScrollTop();var c=Window.getWidth();var a=Window.getHeight();e=((a+e)/2)-150;if($("container")){var g=$("container").getCoordinates();f=g.width/2-150-f;}else{c=(c/2)-150-f;}var b=$("error_popup");b.setStyles({top:e+"px",left:f+"px"});b.setStyle("opacity",0);b.setStyle("display","");var d=new Fx.Styles("error_popup",{duration:500});d.start({opacity:[0,0.9]});(function(){EC_Validate.hideErrorPopup();}).delay(3500);}},hideErrorPopup:function(){var a=new Fx.Styles("error_popup",{duration:500});a.start({opacity:[0.9,0]});(function(){$("error_popup").setStyle("display","none");}).delay(600);}};