var fsman;function FormState(b){this.formObj=b;this.formObj.onclick=fsmanScan;this.formObj.onkeyup=fsmanScan;this.formObj.onfocus=fsmanScan;this.formObj.onchange=fsmanScan;this.registeredButtons=new Array();this.allElements=new Array(b.elements.length);var a;for(var d=0;d<b.elements.length;d++){a=b.elements[d];var e="";var f=a.getAttribute("noscan");if(f!=null&&f.length>1){this.allElements[d]="noscan"}else{switch(a.type){case ("text"):case ("textarea"):case ("hidden"):case ("password"):e=a.value;break;case ("radio"):case ("checkbox"):e=a.defaultChecked;break;case ("select-one"):e=a.selectedIndex;break;case ("select-multiple"):for(var c=0;c<a.options.length;c++){e+=a.options[c].defaultSelected.toString()}break}this.allElements[d]=e}}}FormState.prototype.hasChanged=function(){var a;var f;var g;var e=false;for(var d=0;d<this.formObj.elements.length;d++){a=this.formObj.elements[d];g=this.allElements[d];var h=a.getAttribute("noscan");if(h!=null&&h.length>1){e=false}else{switch(a.type){case ("text"):case ("textarea"):case ("hidden"):case ("password"):e=(g!=a.value);break;case ("radio"):case ("checkbox"):if((g==false&&a.checked)||(g==true&&!a.checked)){e=true}break;case ("select-one"):e=(g!=a.selectedIndex);break;case ("select-multiple"):var c="";for(var b=0;b<a.options.length;b++){c+=a.options[b].selected.toString()}e=(g!=c)}}if(e){return true}}return e};FormState.prototype.scan=function(){if(this.hasChanged()){this.unlockButtons();return true}else{this.lockButtons();return false}};FormState.prototype.register=function(a){if(a!=null){a.disabled=true;this.registeredButtons[this.registeredButtons.length]=a}};FormState.prototype.unlockButtons=function(){for(var a=0;a<this.registeredButtons.length;a++){this.registeredButtons[a].disabled=false}};FormState.prototype.lockButtons=function(){for(var a=0;a<this.registeredButtons.length;a++){this.registeredButtons[a].disabled=true}};function FormStateManager(a,b){this.initialized=false;this.allForms=null;this.doc=null;this.docString=a;this.registeredButtons=new Array();this.selectFirstField=(b)?true:false;this.forceApplyButtonLockFlag=false;this.noscan=false;this.initialize()}FormStateManager.prototype.initialize=function(){this.initialized=false;this.forceApplyButtonLockFlag=false;this.allForms=new Array();if(this.docString!=null){this.doc=eval(this.docString);if(this.doc!=null&&this.doc.forms.length>0){this.allForms=new Array();var formStateObj;for(var i=0;i<this.doc.forms.length;i++){var formStateObj=new FormState(this.doc.forms[i]);this.registerFormState(formStateObj);if(i==0){this.focusFirst(this.doc.forms[i])}}this.doc.onunload=fsmanInitialize}else{setTimeout("fsmanInitialize()",500);return}}};FormStateManager.prototype.registerFormState=function(a){if(a!=null){this.allForms[this.allForms.length]=a;this.initialized=true}};FormStateManager.prototype.focusFirst=function(b){var a;for(var c=0;c<b.elements.length;c++){a=b.elements[c];if(a.type=="text"||a.type=="textarea"){if(this.selectFirstField){a.select()}else{a.focus()}break}}};FormStateManager.prototype.hasChanged=function(){if(!this.initialized){this.initialize();return false}for(var a=0;a<this.allForms.length;a++){formStateObj=this.allForms[a];if(formStateObj.hasChanged()){return true}}return false};FormStateManager.prototype.scan=function(){if(this.noscan){return}var c=false;var b;for(var a=0;a<this.allForms.length;a++){b=this.allForms[a];if(b.scan()){c=true}}if(c){this.unlockButtons()}else{this.lockButtons()}};FormStateManager.prototype.register=function(a){if(a!=null){a.disabled=true;this.registeredButtons[this.registeredButtons.length]=a}};FormStateManager.prototype.unlockButtons=function(){for(var a=0;a<this.registeredButtons.length;a++){button=this.registeredButtons[a];if(button.name=="mainSubmit"){if(this.forceApplyButtonLockFlag){continue}}button.disabled=false}};FormStateManager.prototype.lockButtons=function(){for(var a=0;a<this.registeredButtons.length;a++){this.registeredButtons[a].disabled=true}};FormStateManager.prototype.lockApplyButton=function(){for(var a=0;a<this.registeredButtons.length;a++){button=this.registeredButtons[a];if(button.name=="mainSubmit"){button.disabled=true}}};FormStateManager.prototype.unlockApplyButton=function(){if(this.forceApplyButtonLockFlag){return}for(var a=0;a<this.registeredButtons.length;a++){button=this.registeredButtons[a];if(button.name=="mainSubmit"){button.disabled=false}}};FormStateManager.prototype.unlockResetButton=function(){for(var a=0;a<this.registeredButtons.length;a++){button=this.registeredButtons[a];if(button.name=="mainReset"){button.disabled=false}}};FormStateManager.prototype.lockResetButton=function(){for(var a=0;a<this.registeredButtons.length;a++){button=this.registeredButtons[a];if(button.name=="mainReset"){button.disabled=true}}};FormStateManager.prototype.forceApplyButtonLock=function(){this.forceApplyButtonLockFlag=true};FormStateManager.prototype.clearApplyButtonLock=function(){this.forceApplyButtonLockFlag=false};FormStateManager.prototype.disableScan=function(){this.noscan=true};FormStateManager.prototype.enableScan=function(){this.noscan=false};function unlockButtons(){if(fsman!=null){setTimeout("fsman.unlockButtons()",50)}}function lockButtons(){if(fsman!=null){setTimeout("fsman.lockButtons()",50)}}function unlockApplyButton(){if(fsman!=null){setTimeout("fsman.unlockApplyButton()",50)}}function lockApplyButton(){if(fsman!=null){setTimeout("fsman.lockApplyButton()",50)}}function unlockResetButton(){if(fsman!=null){setTimeout("fsman.unlockResetButton()",50)}}function lockResetButton(){if(fsman!=null){setTimeout("fsman.lockResetButton()",50)}}function forceApplyButtonLock(){if(fsman!=null){setTimeout("fsman.forceApplyButtonLock()",50)}}function clearApplyButtonLock(){if(fsman!=null){setTimeout("fsman.clearApplyButtonLock()",50)}}function fsmanScan(){setTimeout("fsman.scan()",50)}function fsmanInitialize(){fsman.initialize()};
