var jFormsJQ={_forms:{},tForm:null,frmElt:null,declareForm:function(aForm){this._forms[aForm.name]=aForm;$('#'+aForm.name).bind('submit',function(ev){$(ev.target).trigger('jFormsUpdateFields');return jFormsJQ.verifyForm(ev.target)})},getForm:function(name){return this._forms[name]},verifyForm:function(frmElt){this.tForm=this._forms[frmElt.attributes.getNamedItem("id").value];this.frmElt=frmElt;var msg='';var valid=true;this.tForm.errorDecorator.start();for(var i=0;i<this.tForm.controls.length;i++){var c=this.tForm.controls[i];var elt=frmElt.elements[c.name];if(!elt)continue;var val=this.getValue(elt);if(val==''){if(c.required){this.tForm.errorDecorator.addError(c,1);valid=false}}else{if(!c.check(val,this)){this.tForm.errorDecorator.addError(c,2);valid=false}}}if(!valid)this.tForm.errorDecorator.end();return valid},getValue:function(elt){var value='';if(elt.nodeType){switch(elt.nodeName.toLowerCase()){case"input":switch(elt.getAttribute("type")){case"checkbox":case"radio":if(elt.checked)value='true';else value='false';break;default:value=elt.value;break}break;case"textarea":value=elt.value;break;case"select":if(!elt.multiple){value=elt.value;break}var options=elt.getElementsByTagName("option");value=[];for(var i=0;i<options.length;i++){if(options[i].selected){value.push(options[i].value)}}break}}else if(elt.item){value=[];for(var i=0;i<elt.length;i++){var radio=elt.item(i);if(radio.checked){value.push(radio.value)}}}return value},showHelp:function(aFormName,aControlName){var frm=this._forms[aFormName];var ctrls=frm.controls;var ctrl=null;for(var i=0;i<ctrls.length;i++){if(ctrls[i].name==aControlName){ctrl=ctrls[i];break}if(ctrls[i].confirmField&&ctrls[i].confirmField.name==aControlName){ctrl=ctrls[i].confirmField;break}}if(ctrl){frm.helpDecorator.show(ctrl.help)}},hasClass:function(elt,clss){return elt.className.match(new RegExp('(\\s|^)'+clss+'(\\s|$)'))},addClass:function(elt,clss){if(this.isCollection(elt)){for(var j=0;j<elt.length;j++){if(!this.hasClass(elt[j],clss)){elt[j].className+=" "+clss}}}else{if(!this.hasClass(elt,clss)){elt.className+=" "+clss}}},removeClass:function(elt,clss){if(this.isCollection(elt)){for(var j=0;j<elt.length;j++){if(this.hasClass(elt[j],clss)){elt[j].className=elt[j].className.replace(new RegExp('(\\s|^)'+clss+'(\\s|$)'),' ')}}}else{if(this.hasClass(elt,clss)){elt.className=elt.className.replace(new RegExp('(\\s|^)'+clss+'(\\s|$)'),' ')}}},setAttribute:function(elt,name,value){if(this.isCollection(elt)){for(var j=0;j<elt.length;j++){elt[j].setAttribute(name,value)}}else{elt.setAttribute(name,value)}},removeAttribute:function(elt,name){if(this.isCollection(elt)){for(var j=0;j<elt.length;j++){elt[j].removeAttribute(name)}}else{elt.removeAttribute(name)}},isCollection:function(elt){if(elt instanceof NodeList||elt instanceof HTMLCollection||elt instanceof Array)return true;if(elt.length!=undefined&&!(elt.localName!=undefined&&(elt.localName!='SELECT'||elt.localName!='select')))return true;return false}};function jFormsJQForm(name){this.name=name;this.controls=[];this.errorDecorator=new jFormsJQErrorDecoratorAlert();this.helpDecorator=new jFormsJQHelpDecoratorAlert()};jFormsJQForm.prototype={addControl:function(ctrl){this.controls.push(ctrl);ctrl.formName=this.name},setErrorDecorator:function(decorator){this.errorDecorator=decorator},setHelpDecorator:function(decorator){this.helpDecorator=decorator},getControl:function(aControlName){var ctrls=this.controls;for(var i=0;i<ctrls.length;i++){if(ctrls[i].name==aControlName){return ctrls[i]}}return null}};function jFormsJQControlString(name,label){this.name=name;this.label=label;this.required=false;this.errInvalid='';this.errRequired='';this.help='';this.isConfirmField=false;this.confirmFieldOf='';this.minLength=-1;this.maxLength=-1};jFormsJQControlString.prototype.check=function(val,jfrm){if(this.minLength!=-1&&val.length<this.minLength)return false;if(this.maxLength!=-1&&val.length>this.maxLength)return false;return true};function jFormsJQControlSecret(name,label){this.name=name;this.label=label;this.required=false;this.errInvalid='';this.errRequired='';this.help='';this.confirmField=null;this.minLength=-1;this.maxLength=-1};jFormsJQControlSecret.prototype.check=function(val,jfrm){if(this.minLength!=-1&&val.length<this.minLength)return false;if(this.maxLength!=-1&&val.length>this.maxLength)return false;if(this.confirmField){var val2=jfrm.getValue(jfrm.frmElt.elements[this.confirmField.name]);if(val!=val2){jfrm.tForm.errorDecorator.addError(this.confirmField,2);return false}}return true};function jFormsJQControlSecretConfirm(name,label){this.name=name;this.label=label;this.errInvalid='';this.errRequired='';this.help='';this.minLength=-1;this.maxLength=-1};function jFormsJQControlBoolean(name,label){this.name=name;this.label=label;this.required=false;this.errInvalid='';this.errRequired='';this.help=''};jFormsJQControlBoolean.prototype.check=function(val,jfrm){return(val=='true'||val=='false')};function jFormsJQControlDecimal(name,label){this.name=name;this.label=label;this.required=false;this.errInvalid='';this.errRequired='';this.help=''};jFormsJQControlDecimal.prototype.check=function(val,jfrm){return(-1!=val.search(/^\s*[\+\-]?\d+(\.\d+)?\s*$/))};function jFormsJQControlInteger(name,label){this.name=name;this.label=label;this.required=false;this.errInvalid='';this.errRequired='';this.help=''};jFormsJQControlInteger.prototype.check=function(val,jfrm){return(-1!=val.search(/^\s*[\+\-]?\d+\s*$/))};function jFormsJQControlHexadecimal(name,label){this.name=name;this.label=label;this.required=false;this.errInvalid='';this.errRequired='';this.help=''};jFormsJQControlHexadecimal.prototype.check=function(val,jfrm){return(val.search(/^0x[a-f0-9A-F]+$/)!=-1)};function jFormsJQControlDatetime(name,label){this.name=name;this.label=label;this.required=false;this.errInvalid='';this.errRequired='';this.help=''};jFormsJQControlDatetime.prototype.check=function(val,jfrm){
