'use strict';const confirmClose=function(){if(arguments.length>0){for(let i=0;i<arguments.length;i++){this.forms_id.push(arguments[i]);}}};confirmClose.prototype={prompt:'You have unsaved changes.',forms_id:[],forms:[],form_submit:false,getCurrentForms:function(){const eltRef=(e)=>e.id!=undefined&&e.id!=''?e.id:e.name;const formsInPage=this.getForms();this.forms=[];for(let i=0;i<formsInPage.length;i++){const f=formsInPage[i];let tmpForm=[];for(let j=0;j<f.elements.length;j++){const e=this.getFormElementValue(f[j]);if(e!==undefined){tmpForm[eltRef(f[j])]=e;}}
this.forms.push(tmpForm);f.addEventListener('submit',()=>this.form_submit=true);}},compareForms:function(){if(this.forms.length==0){return true;}
const formMatch=(source,obj)=>Object.keys(source).every(key=>obj.hasOwnProperty(key)&&obj[key]===source[key]);const eltRef=(e)=>e.id!=undefined&&e.id!=''?e.id:e.name;const formsInPage=this.getForms();for(let i=0;i<formsInPage.length;i++){const f=formsInPage[i];let tmpForm=[];for(let j=0;j<f.elements.length;j++){const e=this.getFormElementValue(f[j]);if(e!==undefined){tmpForm[eltRef(f[j])]=e;}}
if(!formMatch(tmpForm,this.forms[i])){return false;}}
return true;},getForms:function(){if(!document.getElementsByTagName||!document.getElementById){return[];}
if(this.forms_id.length>0){let res=[];for(let i=0;i<this.forms_id.length;i++){const f=document.getElementById(this.forms_id[i]);if(f!=undefined){res.push(f);}}
return res;}else{return document.getElementsByTagName('form');}
return[];},getFormElementValue:function(e){if((e===undefined)||((e.id===undefined||e.id==='')&&(e.name===undefined||e.name===''))||(e.type!==undefined&&e.type==='button')||(e.type!==undefined&&e.type==='submit')||(e.hasAttribute('readonly'))||(e.classList.contains('meta-helper')||e.classList.contains('checkbox-helper'))){return undefined;}
if(e.type!==undefined&&(e.type==='radio'||e.type==='checkbox')){return(e.checked?e.value:null);}else if(e.type!==undefined&&e.type==='password'){return null;}else if(e.value!==undefined){return e.value;}else{return null;}}};window.addEventListener('load',()=>{const confirm_close=getData('confirm_close');confirmClose.prototype.prompt=confirm_close.prompt;dotclear.confirmClosePage=new confirmClose(...confirm_close.forms);dotclear.confirmClosePage.getCurrentForms();});window.addEventListener('beforeunload',(event)=>{if(event==undefined&&window.event){event=window.event;}
if(dotclear.confirmClosePage!==undefined&&!dotclear.confirmClosePage.form_submit&&!dotclear.confirmClosePage.compareForms()){event.preventDefault();event.returnValue='';}});