Xinha.Dialog=function(D,C,B){this.id={};this.r_id={};this.editor=D;this.document=document;this.rootElem=document.createElement("div");this.rootElem.className="dialog";this.rootElem.style.position="absolute";this.rootElem.style.display="none";this.editor._framework.ed_cell.insertBefore(this.rootElem,this.editor._framework.ed_cell.firstChild);this.rootElem.style.width=this.width=this.editor._framework.ed_cell.offsetWidth+"px";this.rootElem.style.height=this.height=this.editor._framework.ed_cell.offsetHeight+"px";var A=this;if(typeof B=="function"){this._lc=B}else{if(B){this._lc=function(E){return Xinha._lc(E,B)}}else{this._lc=function(E){return E}}}C=C.replace(/\[([a-z0-9_]+)\]/ig,function(E,F){if(typeof A.id[F]=="undefined"){A.id[F]=Xinha.uniq("Dialog");A.r_id[A.id[F]]=F}return A.id[F]}).replace(/<l10n>(.*?)<\/l10n>/ig,function(E,F){return A._lc(F)}).replace(/="_\((.*?)\)"/g,function(F,E){return'="'+A._lc(E)+'"'});this.rootElem.innerHTML=C;this.editor.notifyOn("resize",function(F,E){A.rootElem.style.width=A.width=A.editor._framework.ed_cell.offsetWidth+"px";A.rootElem.style.height=A.height=A.editor._framework.ed_cell.offsetHeight+"px";A.onresize()})};Xinha.Dialog.prototype.onresize=function(){return true};Xinha.Dialog.prototype.show=function(A){if(Xinha.is_ie){this._lastRange=this.editor._createRange(this.editor._getSelection())}if(typeof A!="undefined"){this.setValues(A)}this._restoreTo=[this.editor._textArea.style.display,this.editor._iframe.style.visibility,this.editor.hidePanels()];this.editor._textArea.style.display="none";this.editor._iframe.style.visibility="hidden";this.rootElem.style.display=""};Xinha.Dialog.prototype.hide=function(){this.rootElem.style.display="none";this.editor._textArea.style.display=this._restoreTo[0];this.editor._iframe.style.visibility=this._restoreTo[1];this.editor.showPanels(this._restoreTo[2]);if(Xinha.is_ie){this._lastRange.select()}this.editor.updateToolbar();return this.getValues()};Xinha.Dialog.prototype.toggle=function(){if(this.rootElem.style.display=="none"){this.show()}else{this.hide()}};Xinha.Dialog.prototype.setValues=function(G){for(var D in G){var F=this.getElementsByName(D);if(!F){continue}for(var A=0;A<F.length;A++){var E=F[A];switch(E.tagName.toLowerCase()){case"select":for(var C=0;C<E.options.length;C++){if(typeof G[D]=="object"){for(var B=0;B<G[D].length;B++){if(G[D][B]==E.options[C].value){E.options[C].selected=true}}}else{if(G[D]==E.options[C].value){E.options[C].selected=true}}}break;case"textarea":case"input":switch(E.getAttribute("type")){case"radio":if(E.value==G[D]){E.checked=true}break;case"checkbox":if(typeof G[D]=="object"){for(var C in G[D]){if(G[D][C]==E.value){E.checked=true}}}else{if(G[D]==E.value){E.checked=true}}break;default:E.value=G[D]}break;default:break}}}};Xinha.Dialog.prototype.getValues=function(){var E=[];var C=Xinha.collectionToArray(this.rootElem.getElementsByTagName("input")).append(Xinha.collectionToArray(this.rootElem.getElementsByTagName("textarea"))).append(Xinha.collectionToArray(this.rootElem.getElementsByTagName("select")));for(var A=0;A<C.length;A++){var F=C[A];if(!(F.name&&this.r_id[F.name])){continue}if(typeof E[this.r_id[F.name]]=="undefined"){E[this.r_id[F.name]]=null}var B=E[this.r_id[F.name]];switch(F.tagName.toLowerCase()){case"select":if(F.multiple){if(!B.push){if(B!=null){B=[B]}else{B=new Array()}}for(var D=0;D<F.options.length;D++){if(F.options[D].selected){B.push(F.options[D].value)}}}else{if(F.selectedIndex>=0){B=F.options[F.selectedIndex]}}break;case"textarea":case"input":default:switch(F.type.toLowerCase()){case"radio":if(F.checked){B=F.value;break}case"checkbox":if(B==null){if(this.getElementsByName(this.r_id[F.name]).length>1){B=new Array()}}if(F.checked){if(B!=null&&typeof B=="object"&&B.push){B.push(F.value)}else{B=F.value}}break;default:B=F.value;break}}E[this.r_id[F.name]]=B}return E};Xinha.Dialog.prototype.getElementById=function(A){return this.document.getElementById(this.id[A]?this.id[A]:A)};Xinha.Dialog.prototype.getElementsByName=function(A){return this.document.getElementsByName(this.id[A]?this.id[A]:A)};