function validate(E,F,D,B){jQuery(E).parent().removeClass("failed").removeClass("validated");var C=true;if(E!=null){var A=jQuery(E).attr("id");}else{jQuery(".errors").hide("fast");}$.each(F.items,function(H,M){if(E==null||M.id==A){var G=false;if(jQuery("#"+M.id).attr("type")=="checkbox"||jQuery("#"+M.id).attr("type")=="radio"){M.type="check";}if(typeof (M.optional)!="undefined"&&M.optional==true){if(jQuery("#"+M.id).val().length!=0||jQuery("#"+M.id).val()!=""){G=true;}else{G=false;}}else{G=true;}if(G==true){switch(M.type){case"string":if(jQuery("#"+M.id).val().length<M.val){C=false;jQuery("#warn_"+M.id).show("fast");jQuery("#"+M.id).parent().addClass("failed");}break;case"date":var L=/^(?=\d)(?:(?:(?:(?:(?:0?[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0?[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})|(?:0?2(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))|(?:(?:0?[1-9])|(?:1[0-2]))(\/|-|\.)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2}))($|\ (?=\d)))?(((0?[1-9]|1[012])(:[0-5]\d){0,2}(\ [AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})?$/;if((jQuery("#"+M.id).val().match(L))&&(jQuery("#"+M.id).val()!="")){}else{C=false;jQuery("#warn_"+M.id).show("fast");}break;case"nstring":if(jQuery("#"+M.id).val().toString().search(/^-?[0-9]+$/)==0&&jQuery("#"+M.id).val()>=M.val){}else{C=false;jQuery("#warn_"+M.id).show("fast");jQuery("#"+M.id).parent().addClass("failed");}break;case"check":case"radio":var I=false;var H=0;var J=false;while(jQuery("#"+M.id.replace("[]","")+"_"+H).length==1&&J==false){if(jQuery("#"+M.id.replace("[]","")+"_"+H).attr("checked")){I=true;J=true;}H++;}if(I==false){C=false;jQuery("#warn_"+M.id.replace("[]","")).show("fast");jQuery("#"+M.id.replace("[]","")+"_0").parent().addClass("failed");}break;case"email":var L=/[\w]+@[\w]+.[\w]{2,4}/;if(jQuery("#"+M.id).val().match(L)&&jQuery("#"+M.id).val()!=""){}else{C=false;jQuery("#warn_"+M.id).show("fast");jQuery("#"+M.id).parent().addClass("failed");}break;case"phone":var K=phonefmt(jQuery("#"+M.id).val());if(K==false){C=false;jQuery("#warn_"+M.id).show("fast");jQuery("#"+M.id).parent().addClass("failed");}else{jQuery("#"+M.id).val(K);}break;default:if(jQuery("#"+M.id).val().length==0||jQuery("#"+M.id).val().toString()==""){C=false;jQuery("#warn_"+M.id).show("fast");jQuery("#"+M.id).parent().addClass("failed");}break;}}}});if(typeof (B)=="boolean"){if(B==true){return C;}}if(C==false){return C;}else{if(E!=null){jQuery(E).parent().addClass("validated");jQuery(E).parent().find(".errors").hide("fast");}else{return processForm(D);}}}function phonefmt(B,D){PH_Null="allow";var C=D;var A=B;if((!A)&&(PH_Null=="allow")){return"";}if(!C){C="   ";}PH_Dash="-";A=A.replace(/[ABC]/g,"2");A=A.replace(/[DEF]/g,"3");A=A.replace(/[GHI]/g,"4");A=A.replace(/[JKL]/g,"5");A=A.replace(/[MNO]/g,"6");A=A.replace(/[PRS]/g,"7");A=A.replace(/[TUV]/g,"8");A=A.replace(/[WXY]/g,"9");A=A.replace(/Q/g,"1");A=A.replace(/Z/g,"0");A=A.replace(/[\ -\*]/g,"");A=A.replace(/[\,-\/]/g,"");A=A.replace(/[\:-\@]/g,"");A=A.replace(/[\[-\`]/g,"");A=A.replace(/[\{-\~]/g,"");if((A.substring(0,1)=="+")&&(A.substring(0,2)!="+1")){return A;}PH_Work="";PH_Ext="";if((PH_ix1=A.indexOf("x"))>-1){PH_Ext=A.substring(PH_ix1);A=A.substring(0,PH_ix1);}PH_L1=A.length;PH_N1=10-PH_L1;A=C.substring(0,PH_N1)+A;A=A.replace(/\ /g,"");if(A.match(/^[2-9][0-9]{6}$/)){PH_Work="   "+A;}if(A.match(/^[2-9][0-9]{2}[2-9][0-9]{6}$/)){PH_Work=""+A;}if(A.match(/^1[2-9][0-9]{2}[2-9][0-9]{6}$/)){PH_Work=""+A.substring(1);}if(A.match(/^\+1[2-9][0-9]{2}[2-9][0-9]{6}$/)){PH_Work=""+A.substring(2);}if(PH_Work==""){return false;}PH_Out="";PH_Out="("+PH_Work.substring(0,3)+") "+PH_Work.substring(3,6)+PH_Dash+PH_Work.substring(6,10);PH_Out=PH_Out+PH_Ext;return PH_Out;}function format_number(A){var B=phonefmt(A.value);if(B!=false){A.value=B;}}
