function _q(){this.version="2.00.400";this.w3c=(document.getElementById);this.instances=0;this.objects={};this.librarypath="";this.modules=["field","functions","validation"];this.queue={"qForm":{"oninit":[],"onsubmit":[],"onreset":[],"onaddfield":[],"onremovefield":[]},"Field":{"oninit":[],"onclick":[],"onfocus":[],"onblur":[],"ondisabledfocus":[],"onreset":[],"ongetvalue":[],"onsetvalue":[],"oncsschange":[]}};this.packages={};this.validators={};this.containers={};this.errorColor=null;this.styles={"field":{"backgroundColor":"red"},"label":{}};this.$labelsInit=false;this.useErrorColorCoding=(document.all||this.w3c);this.validateAll=false;this.allowSubmitOnError=false;this.customValidators=0;this.resetOnInit=false;this.showStatusMsgs=true;this.coreapi={compatibility:true,field:true,functions:true,groups:true,validation:{doInclude:((!_t(window.$qdoLoadValidationAPI,"undefined"))?window.$doLoadValidationAPI:true),included:false},language:{type:((!_t(window.$language,"undefined"))?window.$language:"en"),included:false}};this.lang={};this.translation={};return true}qFormAPI=new _q();_q.prototype.onUnload=function(){return true};_q.prototype.onThrowError=function(sMsg){return true};_q.prototype.onReset=function(){return true};_q.prototype.setLibraryPath=function(p){if(p.substring(p.length-1)!="/"){p+="/"}this.librarypath=p;if(!this.coreapi.language.included){this.coreapi.language.included=this.languagePack("general")}if(Function.prototype.apply==null){this.include("compatibility")}return true};_q.prototype.include=function(s,p){if(!s){return false}if(!p){var p=this.librarypath+"qforms/"}if(!!this.coreapi[s]){p+="api/"}if(s.substring(s.length-3)!=".js"){s+=".js"}var sPkg=s.substring(0,s.length-3);if(!!this.packages[sPkg]||(!this.coreapi.validation.doInclude&&sPkg=="validation")){return false}var aJS=["<script language=\"JavaScript1.2\" src=\"","\"></script>"];if(this.coreapi.validation.doInclude&&!this.coreapi.validation.included){document.write(aJS[0]+p+"lang/"+this.coreapi.language.type+"/msg.core.validation.js"+aJS[1]);document.write(aJS[0]+p+"api/core.validation.js"+aJS[1]);this.coreapi.validation.included=true}if(sPkg=="*"){for(var i=0;i<this.modules.length;i++){this.include(this.modules[i],p)}}else{document.write(aJS[0]+p+s+aJS[1])}this.packages[sPkg]=true;return true};_q.prototype.languagePack=function(s){return this.include("lang/"+this.coreapi.language.type+"/msg."+s)};_q.prototype.throwError=function(_c){var e=this.getMessage.apply(this,arguments);var r=this.onThrowError(e);return(r==false)?r:this.displayError(e,"throwError")};_q.prototype.displayError=function(e,_y,_b){var t=_param(arguments[1],"").split(":"),b=_param(_b,false,"boolean"),r;if(!b){alert(e);r=false}else{r=confirm(e)}if(t[0]=="is"){setTimeout(this.objects[t[1]][t[2]].pointer+".focus();",1)}return r};_q.prototype.getMessage=function(_c){var a=[],c=_param(_c,"").split(":");if((arguments.length==2)&&_t(arguments[1],"array")){a=arguments[1]}else{if(arguments.length>1){for(var i=1;i<arguments.length;i++){a[a.length]=arguments[i]}}}return(_t(this.lang[c[0]],"undefined")||_t(this.lang[c[0]][c[1]],"undefined"))?"An error has occurred. (Error code: "+c[1]+" ["+c[0]+"])":this.lang[c[0]][c[1]].replaceArgs(a)};_q.prototype.unload=function(){if(!this.onUnload()){return false}var isFramed=false,o=this.objects;for(var k in o){o[k].$status="idle";if(!!o[k].$frame){isFramed=true}}if(isFramed){this.objects={};this.containers={}}return true};_q.prototype.queueAdd=function(t,e,f){if(!!this.queue[t]&&!!this.queue[t][e]){this.queue[t][e].push(f);return true}else{return false}};_q.prototype.queueExec=function(o,e){var t=String(o.constructor);t=t.substring(t.indexOf(" ")+1,t.indexOf("("));var q=qFormAPI.queue[t],r;if(!_t(q,"object")&&!_t(q[e],"array")){return false}for(var i=0;i<q[e].length;i++){r=q[e][i].apply(o);if(_t(r,"boolean")&&!r){break}}if(_t(r,"boolean")){return r}else{return }};_q.prototype.addEventHandler=function(t,e,f){switch(t.toLowerCase()){case"field":t="Field";break;case"qform":case"form":t="qForm";break}return this.queueAdd(t,e,f)};_q.prototype.reset=function(b){if(!this.onReset()){return false}for(var k in this.objects){this.objects[k].reset(b)}return true};_q.prototype.getFields=function(){var o=this.objects,d={};for(var k in o){var x=o[k].getFields();for(var f in x){if(!d[f]){d[f]=x[f]}else{d[f]+=","+x[f]}}}return d};_q.prototype.setFields=function(o,d,a){for(var k in this.objects){this.objects[k].setFields.apply(this.objects[k],arguments)}};_q.prototype.initLabels=function(){if((!document.getElementsByTagName&&!document.all)||this.$labelsInit){return false}var l=(!!document.getElementsByTagName)?document.getElementsByTagName("LABEL"):document.all.tags("LABEL");for(var i=0;i<l.length;i++){if(!_t(l[i].id,"string")||l[i].id.length==0){l[i].setAttribute("id","lbl"+l[i].htmlFor)}}this.$labelsInit=true;return true};_q.prototype.dump=function(){_dump(this.getFields())};function qForm(n,p,f){if(!n){return qFormAPI.throwError("general:100")}qFormAPI.instances++;if(qFormAPI.instances==1){window.onunload=new Function(_fnToString(window.onunload,";qFormAPI.unload();"))}this.$name=n;this.$parent=(!!p)?p:null;this.$frame=(!!f)?f:null;this.$status=null;this.$showError=false;this.$queue={"totalErrors":0,"errors":{},"validation":[]};this.$allowSubmitOnError=qFormAPI.allowSubmitOnError;this.$locked=false;this.$skipValidation=false;qFormAPI.objects[n]=this;this.$pointer="qFormAPI.objects['"+n+"']";this.$init();qFormAPI.initLabels();return true}qForm.prototype.onInit=function(){return true};qForm.prototype.onSubmit=function(){return true};qForm.prototype.onReset=function(){return true};qForm.prototype.onAddField=function(sFieldName){return true};qForm.prototype.onRemoveField=function(sFieldName){return true};qForm.prototype.$init=function(){this.$form="document."+this.$name;if(this.$parent&&document.layers){this.$form=this.$parent+"."+this.$form}if(this.$frame){this.$form=this.$frame+"."+this.$form}this.obj=eval(this.$form);if(!this.obj&&qFormAPI.w3c){var _s=this.$form.replace(new RegExp("document."+this.$name),"document.getElementById('"+this.$name+"')");this.obj=eval(_s);if(this.obj){this.obj.name=this.$name;this.$form=_s}}if(!this.obj){return qFormAPI.throwError("general:101",this.$name)}this.onSubmit=new Function(_fnToString(this.obj.onsubmit,""));var x=this.$pointer+".submitCheck();";if(this.$frame){x="top."+sOnSubmit}this.obj.onsubmit=new Function("return "+x);this._fields=[];this.$pointers={};for(var j=0;j<this.obj.elements.length;j++){this.addField(this.obj.elements[j].name)}this.$status="initialized";if(qFormAPI.resetOnInit){this.reset()}this.onInit();qFormAPI.queueExec(this,"oninit");return true};qForm.prototype.addField=function(n){if(!_t(n,"string")){return false}var r=this.onAddField(n);if(!r){return r}var o=this.obj[n];if(_t(o,"undefined")){return false}if(_t(o.type,"undefined")){o=o[0]}if((!!o.type)&&(_t(this[n],"undefined"))&&(n.length>0)){this[n]=new Field(this,n);this.$pointers[n.toLowerCase()]=this[n];this._fields[this._fields.length]=n}return true};qForm.prototype.removeField=function(n){var r=this.onRemoveField(n);if(!r){return r}if(_t(this[n],"undefined")){return false}this.$queue.validation=[];this.$pointers[n.toLowerCase()].removeValidation();delete this[n];delete this.$pointers[n.toLowerCase()];var f=this._fields;for(var i=0;i<f.length;i++){if(f[i]==n){f.splice(i,1);break}}return true};qForm.prototype.submitCheck=function(){if(this.$status=="submitting"||this.$status=="validating"){return false}this.$status="submitting";var b=(!qFormAPI.packages.validation)?true:this.validate();if(b){var x=this.onSubmit();if(_t(x,"boolean")){b=x}}if(!b){this.$status="idle"}else{_setContainerValues(this)}return b};qForm.prototype.addEvent=function(e,c,a){if(arguments.length<2){return qFormAPI.throwError("general:301.1")}var b=_param(arguments[2],true,"boolean");_addEvent(this.obj,e,c,b);return true};qForm.prototype.submit=function(){var r=this.obj.submit();return(_t(r,"boolean"))?r:true};qForm.prototype.reset=function(b){if(this.$status==null){return false}var f=this._fields;for(var j=0;j<f.length;j++){this[f[j]].setValue(((!!b)?null:this[f[j]].defaultValue),true,false);this[f[j]].applyCSS(false);if(this[f[j]].$queue.dependencies.length>0){this[f[j]].enforceDependency()}}this.onReset();return true};qForm.prototype.disabled=function(b){var bExists=_t(this.obj.disabled,"boolean");if(arguments.length==0){var b=(!this.obj.disabled)}if(!bExists){this.$locked=b}else{this.obj.disabled=b}return true};qForm.prototype.getFields=function(){if(this.$status==null){return false}var d={};for(var j=0;j<this._fields.length;j++){d[this._fields[j]]=this[this._fields[j]].getValue()}return d};qForm.prototype.setFields=function(o,_d,_a){if(this.$status==null){return false}var d=_param(_d,false,"boolean"),a=_param(_a,true,"boolean");if(a){this.reset()}for(var k in o){var x=this.$pointers[k.toLowerCase()];if(x){x.setValue(o[k],true,false);if(d){x.defaultValue=o[k]}}}return true};qForm.prototype.hasChanged=function(){if(this.$status==null){return false}var f=this._fields;for(var j=0;j<f.length;j++){if(this[f[j]].getValue()!=this[f[j]].defaultValue){return true}}return false};qForm.prototype.changedFields=function(){if(this.$status==null){return false}var d={},f=this._fields;for(var j=0;j<f.length;j++){if(this[f[j]].getValue()!=this[f[j]].defaultValue){d[f[j]]=this[f[j]].getValue()}}return d};qForm.prototype.dump=function(){_dump(this.getFields())};function Field(q,f){this.$queue={"dependencies":[],"validation":[]};this.$maxLength={};this.$origStyles={"field":{},"label":{}};this.$skipFocusCheck=false;this.qForm=q;this.name=f;this.path=this.qForm.$form+"['"+f+"']";this.pointer=this.qForm.$pointer+"['"+f+"']";this.obj=q.obj[f];this.locked=false;this.description=f.toLowerCase();this.required=false;this.validate=false;this.container=false;this.type=(!this.obj.type&&!!this.obj[0])?this.obj[0].type:this.obj.type;this.validatorAttached=false;var v=this.getValue();this.defaultValue=v;this.lastValue=v;if(!_t(this.obj.id,"string")||(_t(this.obj.id,"string")&&this.obj.id.length==0)){this.obj.id=f}this.init();return true}Field.prototype.onInit=function(){return true};Field.prototype.onFocus=function(){return true};Field.prototype.onBlur=function(){return true};Field.prototype.onDisabledFocus=function(){return true};Field.prototype.onReset=function(){return true};Field.prototype.onGetValue=function(sValue){return true};Field.prototype.onSetValue=function(sValue){return true};Field.prototype.onCSSChange=function(bOn){return true};Field.prototype.init=function(){var e;if(document.layers&&this.isArray()){e="onclick"}else{e="onfocus"}this.$origStyles.field={};this.$origStyles.label={};this.addEvent(e,"return "+this.pointer+".fireEventHandlers('onFocus');");this.addEvent("onblur","return "+this.pointer+".fireEventHandlers('onBlur');");this.fireEventHandlers("onInit")};Field.prototype.fireEventHandlers=function(sEvent){var sEventLC=sEvent.toLowerCase(),r;if(sEventLC=="onfocus"){r=this.allowFocus()}else{if(sEventLC=="onblur"&&!!this.checkForErrors){r=this.checkForErrors()}}if(r!=false){r=qFormAPI.queueExec(this,sEventLC)}if((r!=false)&&_t(this[sEvent],"function")){r=this[sEvent]()}return r};Field.prototype.getMessage=function(_c){var c=_param(_c,"").split(":"),key=this.pointer+"|";c[0]=key+c[0];if(!_t(qFormAPI.lang[c[0]],"undefined")&&!_t(qFormAPI.lang[c[0]][c[1]],"undefined")){arguments[0]=key+arguments[0]}return qFormAPI.getMessage.apply(qFormAPI,arguments)};Field.prototype.setMessage=function(_c,_m){var c=_param(_c,"").split(":"),key=this.pointer+"|";c[0]=key+c[0];if(_t(qFormAPI.lang[c[0]],"undefined")){qFormAPI.lang[c[0]]={}}qFormAPI.lang[c[0]][c[1]]=_m};Field.prototype.applyCSS=function(_b){var x=this.isCSSEnabled(),b=_param(_b,true,"boolean");if(x){var o=this.obj.style;if(qFormAPI.errorColor==null){if(b){for(var k in qFormAPI.styles.field){if(_t(this.$origStyles.field[k],"undefined")||(o[k]!=qFormAPI.styles.field[k])){this.$origStyles.field[k]=o[k]}o[k]=qFormAPI.styles.field[k];qFormAPI.styles.field[k]=o[k]}}else{for(var k in this.$origStyles.field){o[k]=this.$origStyles.field[k]}}}else{if(b){this.$origStyles={"backgroundColor":o.backgroundColor};o.backgroundColor=qFormAPI.errorColor}else{o.backgroundColor=this.$origStyles.backgroundColor}}}this.applyLabelCSS(b);return x};Field.prototype.isCSSEnabled=function(){return(qFormAPI.useErrorColorCoding&&!!this.obj.style)};Field.prototype.applyLabelCSS=function(_b){var b=_param(_b,true,"boolean");var l=(!!document.getElementById)?document.getElementById("lbl"+this.name):document.all["lbl"+this.name];if(!l){return false}if(b){for(var k in qFormAPI.styles.label){if(_t(this.$origStyles.label[k],"undefined")||(l.style[k]!=qFormAPI.styles.label[k])){this.$origStyles.label[k]=l.style[k]}l.style[k]=qFormAPI.styles.label[k]}}else{for(var k in this.$origStyles.label){l.style[k]=this.$origStyles.label[k]}}this.onCSSChange(b)};Field.prototype.isArray=function(){return("checkbox,radio".listItemExists(this.type)&&!!this.obj[0])};Field.prototype.allowFocus=function(){if(this.$skipFocusCheck==true){return }this.applyCSS(false);this.lastValue=this.getValue();var b=this.checkIfLocked();if((this.getType()=="select")&&!b){this.resetLast()}return b};Field.prototype.addEvent=function(e,c,a){if(arguments.length<2){return qFormAPI.throwError("general:301.1")}var b=_param(arguments[2],true,"boolean");if(this.isArray()){for(var i=0;i<this.obj.length;i++){_addEvent(this.obj[i],e,c,b)}}else{_addEvent(this.obj,e,c,b)}return true};Field.prototype.disabled=function(b){var oField=this.isArray()?this.obj[0]:this.obj;var bExists=_t(oField.disabled,"boolean");if(arguments.length==0){var b=(!oField.disabled)}if(!bExists){this.locked=b}else{if(this.isArray()&&(this.getType()!="select")){for(var i=0;this.obj.length;i++){this.obj[i].disabled=b}}else{this.obj.disabled=b}}return true};Field.prototype.checkIfLocked=function(s){if(this.isLocked()){this.blur();qFormAPI.throwError("general:201");this.onDisabledFocus();return false}return true};Field.prototype.isLocked=function(){return(this.qForm.$locked)?true:this.locked};Field.prototype.isDisabled=function(){if(_t(this.obj.disabled,"boolean")){return(this.qForm.obj.disabled)?true:this.obj.disabled}else{return false}};Field.prototype.focus=function(){if(!!this.obj.focus){this.obj.focus()}};Field.prototype.blur=function(){if(!!this.obj.blur){this.obj.blur()}};Field.prototype.select=function(){this.focus();if(!!this.obj.select){this.obj.select()}};Field.prototype.reset=function(){this.setValue(this.defaultValue,true,false);this.onReset()};Field.prototype.getType=function(){var t=this.type;switch(t){case"select":case"select-one":t="select";break;case"hidden":case"text":case"textarea":case"password":t="text";break}return t};Field.prototype.getValue=function(){var v=[],o=this.obj,t=this.getType();switch(t){case"checkbox":case"radio":if(!!o[0]){for(var i=0;i<o.length;i++){if(o[i].checked){v[v.length]=o[i].value}}}else{if(o.checked){v[v.length]=o.value}}break;case"select":if(this.type=="select-one"&&!this.container){v[v.length]=(o.selectedIndex==-1)?"":o[o.selectedIndex].value}else{for(var i=0;i<o.length;i++){if((o[i].selected||this.container)&&(!this.dummyContainer)){v[v.length]=o[i].value}}}break;default:v[v.length]=o.value;break}v=v.join(",");this.onGetValue(v);return v};Field.prototype.setValue=function(v,r,e){var bReset=_param(r,true,"boolean"),o=this.obj,doEvents=_param(e,true,"boolean"),t=this.getType(),x;this.lastValue=this.getValue();if(v==null){v=""}switch(t){case"checkbox":case"radio":if(!!o[0]&&!o.value){for(var i=0;i<o.length;i++){if(v.listItemExists(o[i].value)){o[i].checked=true}else{if(bReset){o[i].checked=false}}}}else{if(o.value==v){o.checked=true}else{if(bReset){o.checked=false}}}break;case"select":var bSelectOne=(this.type=="select-one");var bKeepLooking=true;if(!this.container){for(var i=0;i<o.length;i++){x=o[i].value;bSelectItem=v.listItemExists(x);if(bSelectItem&&bKeepLooking){o[i].selected=true;if(bSelectOne&&bKeepLooking){bKeepLooking=false}}else{if(bReset||!bKeepLooking){o[i].selected=false}}}if(bSelectOne&&bKeepLooking){if(this.defaultValue==v){if(this.obj.length>0){this.obj[0].selected=true}else{this.setValue(this.defaultValue)}}}}else{x={};for(var i=0;i<this.boundContainers.length;i++){var c=qFormAPI.containers[this.qForm.$name+":"+this.boundContainers[i]];if(!!c){for(var k in c){if(v.listItemExists(k)&&!this.lastValue.listItemExists(k)){x[k]=c[k]}}}}this.populate(x,bReset)}break;default:o.value=(_t(v,"string"))?v:"";break}if(doEvents){this.triggerEvent("onblur");if(this.lastValue!=v){this.triggerEvent("onchange")}}this.onSetValue(v);return true};Field.prototype.triggerEvent=function(e){var o=this.obj,oEvent=o[e];if(this.isArray()){for(var i=0;i<o.length;i++){oEvent=o[i][event];if(_t(oEvent,"function")){oEvent()}}}else{if(_t(oEvent,"function")){oEvent()}}return true};function _dump(o){var x="";for(var k in o){x+=k+" = "+o[k]+"\n"}return alert(x)}function _t(o,v){var t=(typeof o).toLowerCase(),v=String(v).toLowerCase();if(t=="object"){if(instanceOf(o,Array)){t="array"}else{if(instanceOf(o,Date)){t="date"}else{if(instanceOf(o,qForm)){t="qform"}else{if(instanceOf(o,Field)){t="field"}}}}}return(t==v)}function instanceOf(o,c){while(o!=null){if(o.constructor==c){return true}o=o.__proto__}return false}function _param(v,d,t){if(_t(d,"undefined")){d=""}if(_t(t,"undefined")){t="string"}if(t=="number"&&_t(v,"string")){var v=parseFloat(arguments[0])}return(!_t(v,"undefined")&&_t(v,t.toLowerCase()))?v:d}function _addEvent(o,_e,c,_b){if(arguments.length<3){return qFormAPI.throwError("general:301")}var e=_e.toLowerCase(),b=_param(_b,true,"boolean"),x=(o[e])?o[e].toString():"";x=x.substring(x.indexOf("{")+1,x.lastIndexOf("}"));x=((b)?(x+c):(c+x))+"\n";o[e]=(!!window.Event)?new Function("event",x):new Function(x);return true}function _fnToString(fn,c,_b){if(arguments.length<1){return qFormAPI.throwError("general:300")}var b=_param(_b,true,"boolean"),sFn=(!fn)?"":fn.toString();sFn=sFn.substring(sFn.indexOf("{")+1,sFn.lastIndexOf("}"));if((/applewebkit/i).test(navigator.userAgent)){sFn=sFn.replace(/(\/\/[^\n]*\n)/gi,"").replace(/\/\*[^(\*\/)]*\*\//gi,"").replace(/\n/gi," ")}if(c){sFn=(b)?(sFn+c+"\n"):(c+sFn+"\n")}return sFn}function _setContainerValues(obj){var o=obj._fields;for(var i=0;i<o.length;i++){if(obj[o[i]].container&&obj[o[i]].getType()=="select"){for(var x=0;x<obj[o[i]].obj.length;x++){obj[o[i]].obj[x].selected=(!obj[o[i]].dummyContainer)}}}}String.prototype.replaceArgs=function(_a){var a=[],s=this,x="";if(arguments.length==1&&_t(a,"array")){a=_a}else{for(var i=0;i<arguments.length;i++){a[a.length]=arguments[i]}}for(var i=0;i<a.length;i++){x=a[i].toString();if(x.indexOf("[\"")==0){x=x.substring(2,x.length-2)}s=s.replace(new RegExp("\\{"+i+"\\}","gi"),(!qFormAPI.translation[x])?x:qFormAPI.translation[x])}return s};String.prototype.ltrim=function(){return(this.length==0)?"":this.replace(new RegExp("^\\s+","g"),"")};String.prototype.rtrim=function(){return(this.length==0)?"":this.replace(new RegExp("\\s+$","g"),"")};String.prototype.trim=function(){return this.ltrim().rtrim()};String.prototype.toArray=function(_d){var d=_param(_d,",");return this.trim().split(new RegExp("\\s*"+d+"\\s*","i"))};String.prototype.removeSpaces=function(){return(this.length==0)?"":this.replace(new RegExp("\\s+","g"),"")};String.prototype.listItemExists=function(_v,_d){var d=_param(_d,",","string");var l=d+this+d,v=d+_v+d;return(l.indexOf(v)!=-1)};String.prototype.toInt=function(_b){var b=_param(_b,10,"number");return parseInt(this,b)};Array.prototype.itemExists=function(v){return this.join(",").listItemExists(v)}
