/**
 * Libero.Dialogs è il modulo che si occupa di creare, aprire e chiudere dei dialogs modali
 * @name		toolbox_dialogs_clear.js
 * @encoding	UTF-8
 * @project		Socialnet - Libero
 * @package		common
 * @author		Giulio D'Ambrosio <giulio.dambrosio@staff.libero.it>, <giulio.dambrosio@poste.it>
 * @creation	27/ago/08
 * @version		Cvs: $Id: toolbox_dialogs.js,v 1.26 2009/12/17 11:51:40 giulio_dambrosio Exp $
 *
 */
Libero.Dialogs=Class.create();Libero.Dialogs.prototype={_iefix:!!(window.attachEvent&&!window.opera),_iever:/MSIE (\d+\.\d+);/.test(navigator.userAgent)?new Number(RegExp.$1):'0',_cssfile:null,_opaqueBackground:null,_mainStruct:null,_contentIFrame:null,_btnClose:null,_isOpen:false,_mdLoadingDiv:null,_mainTable:null,_mainTableCell:null,_mdContentParent:null,_opener:null,mdUrl:'',mdContent:false,mdWidth:600,mdHeight:300,mdClassPrefix:'mdlg_',mdIdPrefix:'mdlg_',mdOffsetTop:0,mdOffsetLeft:0,mdFrameWidth:0,mdBaseUrl:'http://static.post.it/',mdDomain:document.domain,mdCssUrl:'css/mdlg/mdlg_default.css',mdButtonClose:{offset_right:3,offset_top:3},mdCloseBefore:null,mdCloseAfter:null,mdAlwaysCentered:true,zIndex:200000,initialize:function(opener,opts){this.open(opener,opts);},open:function(opener,opts){if(this._isOpen==true){return false;}this._isOpen=true;this._opener=opener;var options=Object.extend({mdUrl:'',mdContent:false,mdWidth:600,mdHeight:300,mdClassPrefix:'mdlg_',mdIdPrefix:'mdlg_',mdOffsetTop:0,mdOffsetLeft:0,mdFrameWidth:0,mdDomain:document.domain,mdBaseUrl:'http://static.post.it/',mdCssUrl:'css/mdlg/mdlg_default.css',mdButtonClose:{offset_right:3,offset_top:3},mdCloseBefore:null,mdCloseAfter:null,mdAlwaysCentered:true,zIndex:200000},opts);Object.extend(this,options);if(this.mdBaseUrl!=''&&this.mdBaseUrl.charAt(this.mdBaseUrl.length-1)!='/'){this.mdBaseUrl+='/';}this._cssfile=document.createElement("link");this._cssfile.rel="stylesheet";this._cssfile.type="text/css";this._cssfile.LiberoDialog=this;this._cssfile.href=this.mdBaseUrl+this.mdCssUrl;if(this._iefix){this._cssfile.onload=this._handleCssLoaded;document.getElementsByTagName("head")[0].appendChild(this._cssfile);return true;}else{document.getElementsByTagName("head")[0].appendChild(this._cssfile);return this.setup();}},_handleCssLoaded:function(e){var evt=typeof(e)!='undefined'?e:window.event?window.event:false;var target=evt===false?false:(typeof(evt.target)=='undefined'?(evt.srcElement?evt.srcElement:(evt.currentTarget?evt.currentTarget:false)):(evt.target.nodeType!=3?evt.target:evt.target.parentNode));var self=target&&typeof(target.LiberoDialog)!='undefined'?target.LiberoDialog:false;self.setup();},setup:function(){var table,tr,td;this._opaqueBackground=document.createElement('div');this._opaqueBackground.id=this.mdIdPrefix+'opaqueBackground';this._opaqueBackground.className=this.mdClassPrefix+'opaqueBackground';this._opaqueBackground.LiberoDialog=this;$s(this._opaqueBackground).display='none';Libero.Utils.prototype.startListening(this._opaqueBackground,'click',this._handleOutOfDialogClick);this._mainStruct=document.createElement('div');this._mainStruct.id=this.mdIdPrefix+'mainStruct';this._mainStruct.className=this.mdClassPrefix+'mainStruct';this._mainStruct.LiberoDialog=this;this._mainTable=document.createElement('table');this._mainTable.id=this.mdIdPrefix+'outer_table';this._mainTable.className=this.mdClassPrefix+'outer_table';this._mainTable.align='center';this._mainTable.valign='center';this._mainTable.cellPadding=this._mainTable.cellSpacing=0;this._mainTable.border=0;if(!this.mdFrameWidth){this._mainTable.width=this.mdWidth;this._mainTable.height=this.mdHeight;tr=this._mainTable.insertRow(0);tr.id=this.mdIdPrefix+'row_m';tr.className=this.mdClassPrefix+'row_m';tr.height=this.mdHeight;td=tr.insertCell(0);td.id=this.mdIdPrefix+'cell_mm';td.className=this.mdClassPrefix+'cell_mm';this._mainTableCell=document.createElement('div');$s(this._mainTableCell).width=this.mdWidth+'px';$s(this._mainTableCell).height=this.mdHeight+'px';td.height=this.mdHeight;td.width=this.mdWidth;td.appendChild(this._mainTableCell);}else{tr=this._mainTable.insertRow(0);tr.id=this.mdIdPrefix+'row_t';tr.className=this.mdClassPrefix+'row_t';tr.height=this.mdFrameWidth;td=tr.insertCell(0);td.id=this.mdIdPrefix+'cell_tl';td.className=this.mdClassPrefix+'cell_tl';td.innerHTML='<div></div>';td.width=this.mdFrameWidth;td=tr.insertCell(1);td.id=this.mdIdPrefix+'cell_tm';td.className=this.mdClassPrefix+'cell_tm';td.width=this.mdWidth;td.innerHTML='<div></div>';td=tr.insertCell(2);td.id=this.mdIdPrefix+'cell_tr';td.className=this.mdClassPrefix+'cell_tr';td.innerHTML='<div></div>';td.width=this.mdFrameWidth;tr=this._mainTable.insertRow(1);tr.id=this.mdIdPrefix+'row_m';tr.className=this.mdClassPrefix+'row_m';tr.height=this.mdHeight;td=tr.insertCell(0);td.id=this.mdIdPrefix+'cell_ml';td.className=this.mdClassPrefix+'cell_ml';td.width=this.mdFrameWidth;td.innerHTML='<div></div>';td=tr.insertCell(1);td.id=this.mdIdPrefix+'cell_mm';td.className=this.mdClassPrefix+'cell_mm';this._mainTableCell=document.createElement('div');$s(this._mainTableCell).width=this.mdWidth+'px';$s(this._mainTableCell).height=this.mdHeight+'px';td.height=this.mdHeight;td.width=this.mdWidth;td.appendChild(this._mainTableCell);td=tr.insertCell(2);td.id=this.mdIdPrefix+'cell_mr';td.className=this.mdClassPrefix+'cell_mr';td.width=this.mdFrameWidth;td.innerHTML='<div></div>';tr=this._mainTable.insertRow(2);tr.id=this.mdIdPrefix+'row_b';tr.className=this.mdClassPrefix+'row_b';tr.height=this.mdFrameWidth;td=tr.insertCell(0);td.id=this.mdIdPrefix+'cell_bl';td.width=this.mdFrameWidth;td.className=this.mdClassPrefix+'cell_bl';td.innerHTML='<div></div>';td=tr.insertCell(1);td.id=this.mdIdPrefix+'cell_bm';td.className=this.mdClassPrefix+'cell_bm';td.width=this.mdWidth;td.innerHTML='<div></div>';td=tr.insertCell(2);td.id=this.mdIdPrefix+'cell_br';td.width=this.mdFrameWidth;td.className=this.mdClassPrefix+'cell_br';td.innerHTML='<div></div>';}if(this._iefix||!this.mdAlwaysCentered){var table=document.createElement('table');tr=table.insertRow(0);tr.valign='middle';td=tr.insertCell(0);td.align='center';td.LiberoDialog=this;Libero.Utils.prototype.startListening(td,'click',this._handleOutOfDialogClick);td.appendChild(this._mainTable);table.align='left';var w=document.documentElement?document.documentElement.clientWidth:document.body.clientWidth,h=document.documentElement?document.documentElement.clientHeight:document.body.clientHeight;td.width=table.width=(w);tr.height=table.height=(h);$s(table).marginTop=(this.mdOffsetTop)+'px';$s(table).marginLeft=(this.mdOffsetLeft)+'px';this._mainStruct.appendChild(table);}else{this._mainStruct.appendChild(this._mainTable);}if(this.mdUrl!=''||this.mdContent===false){this._contentIFrame=document.createElement('iframe');this._contentIFrame.LiberoDialog=this;this._contentIFrame.opener=this._opener;this._contentIFrame.scrollable='no';this._contentIFrame.frameBorder='0';this._contentIFrame.marginWidth='0';this._contentIFrame.marginHeight='0';}if(this.mdButtonClose!=null){this._btnClose=document.createElement('div');this._btnClose.className=this.mdClassPrefix+'btn_close';this._btnClose.LiberoDialog=this;this._btnClose.innerHTML='&nbsp;';this._btnClose.title='Chiudi il dialog';}if(this._contentIFrame){this._mdLoadingDiv=document.createElement('div');this._mdLoadingDiv.className=this.mdClassPrefix+'loading_div';$s(this._mdLoadingDiv).display='block';this._mainTableCell.appendChild(this._contentIFrame);}else{if(typeof(this.mdContent)=='string'){this._mainTableCell.innerHTML=this.mdContent;}else{this._mdContentParent=this.mdContent.parentNode;this._mainTableCell.appendChild(this.mdContent);}}document.body.appendChild(this._opaqueBackground);document.body.appendChild(this._mainStruct);if(this._contentIFrame){var doc=this._contentIFrame.contentWindow?this._contentIFrame.contentWindow:(this._contentIFrame.contentDocument?this._contentIFrame.contentDocument:(this._contentIFrame.document?this._contentIFrame.document:false));if(!doc){throw"Unsupported document";}try{doc.domain=this.mdDomain;}catch(e){alert("cannot change iframe domain");}try{doc.LiberoPopup=this;}catch(e){alert("cannot set LiberoPopup in iframe");}}if(this._mdLoadingDiv){this._mainTableCell.appendChild(this._mdLoadingDiv);}$s(this._opaqueBackground).display='block';$s(this._mainStruct).display='block';this._setStyles();if(this._btnClose){this._mainTableCell.appendChild(this._btnClose);Libero.Utils.prototype.startListening(this._btnClose,'click',this._handleBtnCloseClick);}if(this._contentIFrame){Libero.Utils.prototype.startListening(this._contentIFrame,'load',this._handleContentLoaded);this._contentIFrame.src=this.mdUrl;}try{window.LiberoPopup=this;}catch(e){}return true;},isOpen:function(){return this._isOpen;},close:function(){if(!this._isOpen)return false;if(this.mdCloseBefore&&typeof(this.mdCloseBefore)=='function'&&!this.mdCloseBefore()){return false;}this._isOpen=false;if(this._mdContentParent&&typeof(this.mdContent)=='object'){this._mdContentParent.appendChild(this.mdContent);}if(this._cssfile){this._cssfile.parentNode.removeChild(this._cssfile);}if(this._contentIFrame){Libero.Utils.prototype.stopListening(this._contentIFrame,'load',this._handleContentLoaded);}if(this._btnClose){Libero.Utils.prototype.stopListening(this._btnClose,'click',this._handleBtnCloseClick);}if(this._mainStruct){Libero.Utils.prototype.stopListening(this._mainStruct,'click',this._handleOutOfDialogClick);}if(this._mdLoadingDiv){this._mdLoadingDiv.parentNode.removeChild(this._mdLoadingDiv);this._mdLoadingDiv=null;}if(this._contentIFrame){this._contentIFrame.parentNode.removeChild(this._contentIFrame);this._contentIFrame=null;}if(this._mainStruct){this._mainStruct.parentNode.removeChild(this._mainStruct);this._mainStruct=null;}if(this._opaqueBackground){$s(this._opaqueBackground).display='none';this._opaqueBackground.parentNode.removeChild(this._opaqueBackground);this._opaqueBackground=null;}if(this.mdCloseAfter&&typeof(this.mdCloseAfter)=='function'){this.mdCloseAfter();}return true;},_setStyles:function(){var styles;if(this._btnClose){styles=$s(this._btnClose);styles.zIndex=(this.zIndex+6).toString();}styles=$s(this._mainTableCell);styles.position='relative';styles.left=styles.top=styles.margin=styles.padding='0';if(this._contentIFrame){styles=$s(this._contentIFrame);styles.border='none';styles.cursor='default';styles.width=this.mdWidth+'px';styles.minWidth=this.mdWidth+'px';styles.height=this.mdHeight+'px';styles.minHeight=this.mdHeight+'px';styles.background='#ffffff';styles.overflow='hidden';styles.zIndex=(this.zIndex+4).toString();}if(this._mdLoadingDiv){styles=$s(this._mdLoadingDiv);styles.cursor='wait';styles.position='absolute';styles.left='0px';styles.top='0px';styles.width=(this.mdWidth)+'px';styles.minWidth=(this.mdWidth)+'px';styles.height=this.mdHeight+'px';styles.minHeight=this.mdHeight+'px';styles.zIndex=(this.zIndex+5).toString();styles.backgroundColor='#aaaaaa';styles.opacity='1';}if(this._iefix||!this.mdAlwaysCentered){styles=$s(this._mainStruct);if(this._iever==6||!this.mdAlwaysCentered){styles.position='absolute';styles.left='0px';var dy=((document.documentElement?document.documentElement.scrollTop:document.body.scrollTop));if(!this._iefix){dy+=Math.max(0,((document.documentElement?document.documentElement.clientHeight:document.body.clientHeight)-this.mdHeight)/2);}styles.top=dy+'px';}else{styles.position='fixed';styles.left='0px';styles.top='0px';}styles.cursor='pointer';styles.width='100%';styles.minWidth='100%';styles.height='100%';styles.minHeight='100%';styles.textAlign='center';styles.margin=styles.padding='0';styles.zIndex=(this.zIndex+2).toString();styles=$s(this._opaqueBackground);styles.cursor='pointer';styles.position='absolute';styles.left='0px';styles.top='0px';var h=document.documentElement?document.documentElement.scrollHeight:document.body.scrollHeight;var w=document.documentElement?document.documentElement.scrollWidth:document.body.scrollWidth;if(this._iever==6||!this.mdAlwaysCentered){styles.width=w+'px';styles.minWidth=w+'px';styles.textAlign='center';}else{styles.width='100%';styles.minWidth='100%';}styles.height=h+'px';styles.minHeight=h+'px';styles.zIndex=(this.zIndex+1).toString();}else{styles=$s(this._mainStruct);styles.position='fixed';styles.left=styles.top='50%';styles.marginLeft=(-this.mdWidth/2-this.mdFrameWidth+this.mdOffsetLeft)+'px';styles.marginTop=(-this.mdHeight/2-this.mdFrameWidth+this.mdOffsetTop)+'px';styles.width=(this.mdWidth+this.mdFrameWidth*2)+'px';styles.minWidth=(this.mdWidth+this.mdFrameWidth*2)+'px';styles.height=(this.mdHeight+this.mdFrameWidth*2)+'px';styles.minHeight=(this.mdHeight+this.mdFrameWidth*2)+'px';styles.textAlign='center';styles.padding='0 0 0 0';styles.zIndex=(this.zIndex+2).toString();styles=$s(this._opaqueBackground);styles.cursor='pointer';styles.position='fixed';styles.left='0px';styles.top='0px';styles.width='100%';styles.minWidth='100%';styles.height='100%';styles.minHeight='100%';styles.textAlign='center';styles.zIndex=(this.zIndex+1).toString();}},_handleContentLoaded:function(e){var evt=typeof(e)!='undefined'?e:(window.event?window.event:false);var target;if(evt.srcElement){target=evt.srcElement;}else if(evt.currentTarget){target=evt.currentTarget;}else if(evt.target){if(evt.target.nodeType==3){target=evt.target.parentNode;}else{target=evt.target;}}var self=target&&typeof(target.LiberoDialog)!='undefined'?target.LiberoDialog:false,doc;if(self&&self._mdLoadingDiv!=null){self._mdLoadingDiv.parentNode.removeChild(self._mdLoadingDiv);self._mdLoadingDiv=null;}return true;},_handleBtnCloseClick:function(e){var evt=typeof(e)!='undefined'?e:window.event?window.event:false;var target=evt===false?false:(typeof(evt.target)=='undefined'?(evt.srcElement?evt.srcElement:(evt.currentTarget?evt.currentTarget:false)):(evt.target.nodeType!=3?evt.target:evt.target.parentNode));var self=target&&typeof(target.LiberoDialog)!='undefined'?target.LiberoDialog:false;if(!self){return;}self.close();return false;},_handleOutOfDialogClick:function(e){var evt=typeof(e)!='undefined'?e:window.event?window.event:false;var target=evt===false?false:(typeof(evt.target)=='undefined'?(evt.srcElement?evt.srcElement:(evt.currentTarget?evt.currentTarget:false)):(evt.target.nodeType!=3?evt.target:evt.target.parentNode));var self=target&&typeof(target.LiberoDialog)!='undefined'?target.LiberoDialog:false;if(!self){return;}self.close();return false;}};