var identity=(typeof identity=="undefined")?{}:identity;identity.forms=function(){var C={},F,D,A,B,E=[];C.Validator=function(){this.checks=[];this.validationGroups=[]};C.Validator.prototype.addCheck=function(G){this.checks[this.checks.length]=G};C.Validator.prototype.addValidationGroup=function(H,G){this.validationGroups[this.validationGroups.length]=new identity.forms.ValidationGroup(H,G)};C.Validator.prototype.parseChecksObject=function(L){var Q,K,N,T,R,U,P,V;for(N in L){T=L[N];for(Q in T.tests){K=T.tests[Q];if(K.type){R=K.type}else{continue}if(K.test||R=="notempty"||R=="email"||R=="numeric"){P=K.test?K.test:""}else{continue}if(K.events){if(typeof K.events=="object"){V=K.events}else{if(typeof K.events=="string"){V=[K.events]}else{continue}}}else{continue}var J=K.id?K.id:"";var G=T.container?T.container:"";var I=K.failureMessage?K.failureMessage:"";var O=T.successMessage?T.successMessage:"";var M=T.defaultMessage?T.defaultMessage:"";var H=T.messageContainer?T.messageContainer:"";var S=K.conditions?K.conditions:[];var W=T.revalidateOnSuccess?T.revalidateOnSuccess:[];this.addCheck(new identity.forms.ValidationCheck(N,R,P,V,{id:J,conditions:S,container:G,failureMessage:I,successMessage:O,defaultMessage:M,messageContainer:H,revalidateOnSuccess:W}))}if(!T.validationGroups){continue}for(U in T.validationGroups){this.addValidationGroup(N,T.validationGroups[U])}}};C.Validator.prototype.importChecksObject=function(H){var G=this;F.net.get(H,{onLoad:function(I){G.parseChecksObject(I.json(false))}})};C.Validator.prototype.validate=function(J,G){if(typeof (J)=="undefined"){return false}if(typeof G=="undefined"){G={}}if(G.id&&typeof G.id=="string"){G.id=[G.id]}if(typeof G.id!="object"){G.id=[]}var T=this;var S={};S.opts=G;S.event=J;S.success=true;S.fields={};S.validationResult={};S.passedChecks=[];S.revalidateIds=[];S.tests=0;var I=[];var L,Q,K,P,O,H,N,R,V,U,M;if(!this.checks.length){S.success=false}else{for(Q in this.checks){L=this.checks[Q];if(S.opts.id.length){M=false;for(K in S.opts.id){if(S.opts.id[K]==L.field){M=true;break}}if(!M){continue}}M=false;for(P in L.events){if(L.events[P]==S.event){M=true;break}}if(!M){continue}I[I.length]=L}S.tests=I.length;for(Q in I){L=I[Q];if(!(L.field in S.validationResult)){S.validationResult[L.field]={};S.validationResult[L.field]._valid=false;S.validationResult[L.field]._error=false}(function(W){W.doTest(S,{callback:function(X){T.validate_pt2(S,W,X)},validator:T})})(L)}}};C.Validator.prototype.validate_pt2=function(H,G,I){if(!((G.field in H.fields)&&!H.fields[G.field])){if(I===0){H.success=false;H.fields[G.field]=false;H.validationResult[G.field]._valid=false;H.validationResult[G.field]._error=true;H.validationResult[G.field].message=G.failureMessage}else{if(I===1&&!H.validationResult[G.field]._valid){H.fields[G.field]=true;H.validationResult[G.field]._valid=false;H.validationResult[G.field]._error=false;H.validationResult[G.field].message=G.defaultMessage}else{if(I===2){H.fields[G.field]=true;H.validationResult[G.field]._error=false;H.passedChecks[H.passedChecks.length]=G.id;this.testValidationGroups(H,G)}}}H.validationResult[G.field].container=G.container;H.validationResult[G.field].messageContainer=G.messageContainer}H.tests--;this.validate_pt3(H)};C.Validator.prototype.validate_pt3=function(G){if(G.tests!==0){return }if(!G.opts.preserveDOM){this.processValidationResult(G.validationResult)}if(G.success){if(G.revalidateIds.length){this.validate(G.event,{id:G.revalidateIds,onFailure:G.opts.onFailure})}if(G.opts.onSuccess){G.opts.onSuccess()}}else{if(G.opts.onFailure){G.opts.onFailure()}}};C.Validator.prototype.testValidationGroups=function(Q,J){var N,P,I,S,K,G;var O=false;for(N in this.validationGroups){var L=this.validationGroups[N];if(L.field==J.field){var H=true;for(P in L.ids){var M=false;for(I in Q.passedChecks){if(Q.passedChecks[I]==L.ids[P]){M=true}}if(!M){H=false;break}}if(!H){continue}else{O=true;break}}}if(O){Q.validationResult[J.field]._valid=true;Q.validationResult[J.field].message=J.successMessage;if(J.revalidateOnSuccess.length){for(S in J.revalidateOnSuccess){S=J.revalidateOnSuccess[S];var R=true;for(K in Q.opts.id){if(Q.opts.id[K]==S){R=false}}for(G in Q.revalidateIds){if(Q.revalidateIds[G]==S){R=false}}if(R){Q.revalidateIds[Q.revalidateIds.length]=S}}}}else{Q.validationResult[J.field]._valid=false;Q.validationResult[J.field].message=J.defaultMessage}};C.Validator.prototype.processValidationResult=function(I){var H,G;for(G in I){H=I[G];if(G!="_valid"&&G!="_error"){if(H.message){D(H.messageContainer).html(H.message)}D(H.container).removeClass("error").removeClass("valid").removeClass("working");if(H._valid){D(H.container).addClass("valid")}else{if(H._error){D(H.container).addClass("error")}}}}};C.Validator.prototype.stopAll=function(){var H,G,I,J;for(G in this.checks){H=this.checks[G];if(H.type=="ajax"){for(J in H.requests){I=H.requests[J];I.abort()}}}};C.Validator.prototype.setGlowForm=function(G){this.glowForm=G};C.Validator.prototype.setGlowFormValidationListener=function(G){B(this.validationListenerId);this.validationListenerId=A(this.glowForm,"validate",G)};C.Validator.prototype.glowValidate=function(H,G){if(!this.glowForm){return false}if(typeof G=="function"){this.setGlowFormValidationListener(G)}this.glowForm.validate(H)};C.Validator.prototype.processGlowResults=function(H){var G;for(G in H.fields){var I=H.fields[G]}};C.ValidationCheck=function(J,H,K,G,I){this.field=J;this.type=H;this.test=K;this.events=G;this.id=I.id?I.id:"";this.conditions=I.conditions?I.conditions:[];this.container=I.container?I.container:false;this.failureMessage=I.failureMessage?I.failureMessage:"";this.successMessage=I.successMessage?I.successMessage:"";this.defaultMessage=I.defaultMessage?I.defaultMessage:"";this.messageContainer=I.messageContainer?I.messageContainer:false;this.revalidateOnSuccess=I.revalidateOnSuccess?I.revalidateOnSuccess:[];this.requests=[]};C.ValidationCheck.prototype.doTest=function(P,G){var Q=this;var H=G.validator;if(this.conditions.length){var J=false,O,K,N,I;this.conditionCounter=this.conditions.length;for(O in this.conditions){K=this.conditions[O];if("exceptions" in K){I=false;for(N in K.exceptions){if(K.exceptions[N]==P.event){I=true;break}}if(I){this.doTest_pt2(true,G);return }}if("events" in K){I=false;for(N in K.events){if(K.events[N]==P.event){I=true;break}}if(!I){this.doTest_pt2(false,G);return }}K.id=K.id?K.id:this.field;var R=D(["#",K.id].join(""));if(F.env.ie){R=R.filter(function(){return this.id==K.id})}var L=R.val();if((K.type=="regex"&&L.match(K.test))||(K.type=="lt"&&L<K.test)||(K.type=="lte"&&L<=K.test)||(K.type=="eq"&&L==K.test)||(K.type=="eqv"&&L===K.test)||(K.type=="gte"&&L>=K.test)||(K.type=="gt"&&L>K.test)||(K.type=="neq"&&L!=K.test)||(K.type=="neqv"&&L!==K.test)||(K.type=="match"&&L==D(K.test)[0].value)||(K.type=="function"&&K.test.call({glow:F},L))||(K.type=="checked"&&R.attr("type")=="checkbox"&&((R.attr("checked")=="checked"&&K.test===true)||(R.attr("checked")!="checked"&&K.test===false)))||(K.type=="email"&&L.match(/^[A-Za-z0-9](([+_\.\-]*[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$/))||(K.type=="numeric"&&L.match(/^[0-9]*$/))||(K.type=="notempty"&&L.match(/^.+$/))){this.doTest_pt2(true,G)}else{if(K.type=="ajax"){if(K.test.substring(0,5)!="https"){var M=D(this.container).addClass("working");(function(){var S=Q.requests.length;Q.requests[S]=F.net.get([K.test,L].join(""),{onLoad:function(T){M.removeClass("working");if(T.text().replace(/^[\s]+/g,"").replace(/[\s]+$/g,"")==="1"){Q.doTest_pt2(true,G)}else{Q.doTest_pt2(false,G)}},onError:function(T){if(T.status==408){G.callback(1)}},timeout:5})})()}}else{if(K.type=="valid"){if(K.id&&H){H.validate(P.event,{id:K.id,onFailure:function(){Q.doTest_pt2(false,G)},onSuccess:function(){Q.doTest_pt2(true,G)}})}else{this.doTest_pt2(false,G)}}else{this.doTest_pt2(false,G)}}}}}else{this.doTest_pt3(G)}};C.ValidationCheck.prototype.doTest_pt2=function(H,G){if(H){this.conditionCounter--;if(this.conditionCounter===0){this.doTest_pt3(G)}}else{G.callback(1)}};C.ValidationCheck.prototype.doTest_pt3=function(H){var I=D(["#",this.field].join(""));var G=this;if(F.env.ie){I=D(["input#",this.field,",textarea#",this.field,",select#",this.field].join(""))}var L=I.val();if((this.type=="regex"&&L.match(this.test))||(this.type=="lt"&&L<this.test)||(this.type=="lte"&&L<=this.test)||(this.type=="eq"&&L==this.test)||(this.type=="eqv"&&L===this.test)||(this.type=="gte"&&L>=this.test)||(this.type=="gt"&&L>this.test)||(this.type=="neq"&&L!=this.test)||(this.type=="neqv"&&L!==this.test)||(this.type=="match"&&L==D(this.test).val())||(this.type=="function"&&this.test.call({glow:F},L))||(this.type=="checked"&&I.attr("type")=="checkbox"&&((L==I.attr("value")&&this.test===true)||(L==""&&this.test===false)))||(this.type=="email"&&L.match(/^[A-Za-z0-9](([+_\.\-]*[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$/))||(this.type=="numeric"&&L.match(/^[0-9]*$/))||(this.type=="notempty"&&L.match(/^.+$/))){H.callback(2)}else{if(this.type=="ajax"){if(this.test.substring(0,5)!="https"){var K=G.requests.length;var J=D(this.container);J.addClass("working");G.requests[K]=F.net.get([this.test,L].join(""),{onLoad:function(M){J.removeClass("working");if(M.text().replace(/^[\s]+/g,"").replace(/[\s]+$/g,"")==="1"){H.callback(2)}else{H.callback(0)}},onError:function(M){if(M.status==408){H.callback(1)}},timeout:5})}return }else{H.callback(0)}}};C.ValidationGroup=function(H,G){this.field=H;this.ids=G};C.ValidationGroup.prototype.contains=function(H){var G;for(G in this.ids){if(H==this.ids[G]){return true}}return false};C.SecureForm=function(I,H){this.form=D(I);if(H.secureUrl){this.secureUrl=H.secureUrl}else{var G=this.form.attr("action");if(G.substr(0,5)=="https"){this.secureUrl=G}else{if(G.substr(0,4)=="http"){this.secureUrl=["https",G.substr(4)].join("")}else{return false}}}this.handleResult=H.handleResult?H.handleResult:function(){};this.arrayId=E.length;E[this.arrayId]=this};C.SecureForm.prototype.submit=function(N){D("#id-secureform").remove();this.iframe=F.dom.create('<iframe src="javascript:false" id="id-secureform" name="id-secureform"></iframe>');this.iframe.css("visibility","hidden").css("position","absolute").css("left","-9999px").css("top","-9999px");D("body").append(this.iframe);var J=F.dom.create("<div></div>");var I=97;this.fieldNames={};var G=this;this.form.get("input, select, textarea").each(function(){var O=D(this);if(O.attr("name")!="cancel"){if(O.is("input")&&O.attr("type")=="checkbox"&&O.val()!=O.attr("value")){return }var P=F.dom.create(["<input type='hidden' name='",O.attr("name"),"' />"].join("")).attr("value",O[0].value);J.append(P);if(O.attr("name")!="register"){P=F.dom.create(["<input type='hidden' name='",String.fromCharCode(I),"' />"].join("")).attr("value",O.attr("name"));J.append(P)}G.fieldNames[String.fromCharCode(I++)]=O.attr("name")}});var K,M,H=identity.util.random(6);if(F.env.opera){K=window.frames[0].document}else{M=D("#id-secureform")[0];if(M.contentDocument){K=M.contentDocument}else{if(M.contentWindow){K=M.contentWindow.document}else{if(M.document){K=M.document}}}}K.open();K.write("<html><head></head><body>");K.write(['<form id="id-secureform" name="id-secureform" action="',this.secureUrl,'" method="post">'].join(""));K.write(['<input type="hidden" name="secureform_id" value="',this.arrayId,'" />'].join(""));K.write(['<input type="hidden" name="salt" value="',H,'" />'].join(""));K.write(J[0].innerHTML);K.write("</form></body></html>");K.close();this.iframeForm=D(K).get("form");identity.util.deleteCookie("IDENTITY-ERRORS");this.iframeForm[0].submit();var L=setInterval(function(){var Q=unescape(identity.util.getCookie("IDENTITY-ERRORS"));var R=Q.split("*");var P={id:R[0],salt:R[1],value:R[2]};if((P.salt==H)||(!P.salt&&P.value&&P.value.length==1)){var O=N(P.value,G.fieldNames);G.handleResult(O);D("#id-secureform").remove();clearInterval(L);identity.util.deleteCookie("IDENTITY-ERRORS")}},100)};C.init=function(G){F=G;D=F.dom.get;A=F.events.addListener;B=F.events.removeListener};return C}();