function unsavedChangesRoot(){return window.addEventListener||window.attachEvent?window:document.addEventListener?document:null;}
function unsavedChangesOnbeforeunload(warning){unsavedChangesRoot().onbeforeunload=function(){return warning;}}
function UnsavedChangesStandard(formId,filters){this.formId=(typeof(formId)=='undefined')?null:formId;this.filters=(typeof(filters)=='undefined')?new Array():filters;this.container=new Object();this.isCheck=true;this.isReady=false;this.init();}
UnsavedChangesStandard.prototype.defaultAdditionalProcessingForm=function(){}
UnsavedChangesStandard.prototype.userAdditionalProcessingForm=function(){}
UnsavedChangesStandard.prototype.additionalProcessingForm=function(){this.defaultAdditionalProcessingForm();this.userAdditionalProcessingForm();}
UnsavedChangesStandard.prototype.setWarning=function(warning){this.container['warning']=warning;}
UnsavedChangesStandard.prototype.getWarning=function(){return this.container['warning'];}
UnsavedChangesStandard.prototype.getCurrentValues=function(){var values=new Object();var valueId;var filter='';$.each(this.filters,function(key,val){filter+=':'+val;});var form=$(this.formId+' :input'+filter);$.each(form,function(){valueId=($(this).attr('id')!='')?$(this).attr('id'):$(this).attr('name');if(valueId!=''&&($(this).attr('type')!='radio'||$(this).attr('checked'))){values[valueId]=($(this).attr('type')=='checkbox')?$(this).attr('checked'):$(this).val();}});return values;}
UnsavedChangesStandard.prototype.setDefaultValues=function(){this.additionalProcessingForm();this.enableCheck();this.container['defaultValues']=this.getCurrentValues();}
UnsavedChangesStandard.prototype.getDefaultValues=function(){return this.container['defaultValues'];}
UnsavedChangesStandard.prototype.check=function(){var result=false;if(this.isCheck&&this.userCheck()){var defaultValues=this.getDefaultValues();var currentValues=this.getCurrentValues();if(this.getObjectSize(defaultValues)!=this.getObjectSize(currentValues)){return true;}
$.each(currentValues,function(key,val){if(defaultValues[key]!=val){result=true;return true;}});}
return result;}
UnsavedChangesStandard.prototype.disableCheck=function(){this.isCheck=false;}
UnsavedChangesStandard.prototype.enableCheck=function(){this.isCheck=true;}
UnsavedChangesStandard.prototype.getRoot=function(){return unsavedChangesRoot();}
UnsavedChangesStandard.prototype.getObjectSize=function(obj){var size=0;$.each(obj,function(){size++;});return size;}
UnsavedChangesStandard.prototype.onbeforeunload=function(){var unsavedChanges=this;this.getRoot().onbeforeunload=function(){if(unsavedChanges.isReady){unsavedChanges.additionalProcessingForm();if(unsavedChanges.check()){return unsavedChanges.getWarning();}}}}
UnsavedChangesStandard.prototype.initCommon=function(){this.isReady=true;this.setWarning('Warning! You have unsaved changes. Click OK TO LEAVE the page or click CANCEL TO STAY on the current page.');this.setDefaultValues();}
UnsavedChangesStandard.prototype.init=function(formId){if((typeof(formId)!='undefined')){this.formId=formId;}
if(this.formId!==null){this.initCommon();}}
UnsavedChangesStandard.prototype.userCheck=function(){return true;}
var editorInitObj=null;function editorInitObject(obj){if(typeof(obj)!='undefined'){editorInitObj=obj;}
if(oEditor.DOMReady){editorInitObj.initCommon();}else if(editorInitObj.editorInitCount<10){editorInitObj.editorInitCount++;setTimeout('editorInitObject()',1000);}}
function UnsavedChangesEditor(formId,filters){var parent=new UnsavedChangesStandard(formId,filters);parent.editorInitCount=0;parent.defaultAdditionalProcessingForm=function(){oEditor.saveHTML();oEditor.cleanText();}
parent.init=function(formId){if((typeof(formId)!='undefined')){this.formId=formId;}
if(this.formId!==null){editorInitObject(this);}}
parent.init();return parent;}
function UnsavedChanges(formId,filters){if(typeof(oEditor)=='undefined'){return new UnsavedChangesStandard(formId,filters);}
return new UnsavedChangesEditor(formId,filters);}

