if(typeof _veilCover!="object"){include(JS_PATH+"/veil.js")}__currentModal=null;__modalsOrder=[];__modalsCache=[];__modalsOptions={};if(typeof Element.setOpacity!="function"){include(JS_PATH+"/effects/builder.js");include(JS_PATH+"/effects/effects.js");include(JS_PATH+"/effects/dragdrop.js");include(JS_PATH+"/dimension.js")}
var ModalWin=Class.create();
ModalWin.open = function(url, title, params) {
var w = new ModalWin(url, title, params) ;
}

ModalWin.window=Dimension.window.getDimensions();ModalWin.__createdModals=0;ModalWin.prototype={name:"",initialised:false,options:{width:null,height:null,evalScripts:true,draggable:true,allowHTMLTitle:true,buttonClose:true,buttonMax:false,buttonMin:false,cacheURLs:false,onBeforeOpen:Prototype.emptyFunction,onOpen:Prototype.emptyFunction,onAfterOpen:Prototype.emptyFunction,onBeforeLoad:Prototype.emptyFunction,onLoad:Prototype.emptyFunction,onAfterLoad:Prototype.emptyFunction,onBeforeClose:Prototype.emptyFunction,onClose:Prototype.emptyFunction,onAfterClose:Prototype.emptyFunction,onBeforeMinimize:Prototype.emptyFunction,onMinimize:Prototype.emptyFunction,onAfterMinimize:Prototype.emptyFunction,onBeforeMaximize:Prototype.emptyFunction,onMaximize:Prototype.emptyFunction,onAfterMaximize:Prototype.emptyFunction,onFocus:Prototype.emptyFunction,onBlur:Prototype.emptyFunction,titleOnDblClick:null,showVeil:true},container:null,windowState:"closed",title:null,body:null,veil:null,controlls:null,classNamePrefix:"ModalContainer",_autoSize:false,initialize:function(D,E,A){this.veil=_veilCover.create();this.name="ModalWin"+ModalWin.__createdModals;this.setButtons=typeof $(this.name)=="undefined";this.tabIndexes=[];this.tabbableTags=["A","BUTTON","TEXTAREA","INPUT","IFRAME","SELECT"];this.__id=ModalWin.__createdModals;this.zIndex=10000+ModalWin.__createdModals;__modalsCache.push(this);var B=document.getElementsByTagName("BODY")[0]||document.getElementsByTagName("HEAD")[0]||document;this.container=$((!this.setButtons)?this.name:document.createElement("DIV"));if(this.setButtons){this.container.id=this.name;this.container.className=this.classNamePrefix;this.container.setStyle({zIndex:this.zIndex,position:"absolute"})}if(this.setButtons){this.title=document.createElement("DIV");this.title.id=this.name+"Title";this.title.className=this.classNamePrefix+"Title";this.title.innerHTML="&nbsp;";Element.setStyle(this.title,{zIndex:this.zIndex,position:"relative"});this.container.appendChild(this.title)}else{this.title=$(this.name+"Title")}if(this.setButtons){this.body=$(document.createElement("DIV"));this.body.id=this.name+"Body";this.body.className=this.classNamePrefix+"Body";Element.setStyle(this.title,{zIndex:this.zIndex,position:"relative"});this.body.makeClipping();this.body.innerHTML="Loading ...";this.container.appendChild(this.body)}else{this.body=$(this.name+"Body")}Element.hide(this.container);if(this.setButtons){B.appendChild(this.container);Position.absolutize(this.container)}var C=this.options.titleOnDblClick||Prototype.emptyFunction;switch(C){case"close":C=(function(){this.close()}).bind(this);break;case"toggleState":case"minimize":case"maximize":C=(function(){if(this.windowState=="minimized"){this.maximize()}else{this.minimize()}}).bind(this);break;default:break}this.title.ondblclick=C;ModalWin.__createdModals++;this.initialised=true;if(D&&E){this.open(D,E,A)}},open:function(B,C,A){this.setOptions(Object.extend(__modalsOptions,A));this._autoSize=this.options.width<=0&&this.options.height<=0;if(!this.initialised){this.initialize()}if(this.options.onBeforeOpen.apply(this,arguments)!==false){if(this.options.showVeil){this.veil.show()}this.setContent(B);this.show();this.setTitle(this.titleText=C||"")}this.options.onAfterOpen.apply(this,arguments)},close:function(){var A=this.onClose.apply(this,arguments);if(A!==false){if(this.loadingUrl&&this.transport&&this.transport.readyState>0){this.transport.options.onSuccess=this.transport.options.onFailure=this.transport.options.onComplete=Prototype.emptyFunction;this.transport.transport.abort()}Element.hide(this.container);__modalsCache.splice(this.__id,1);ModalWin.__createdModals--;if(ModalWin.__createdModals<0){ModalWin.__createdModals=0}if(!(__currentModal=((__modalsCache.length)?__modalsCache[this.__id-1]:null))||!__currentModal.container.visible()){this.container=this.container.parentNode.removeChild(this.container);Event.stopObserving(window,"resize",onResizeForWindow,false);Event.stopObserving(window,"scroll",onScrollForWindow,false);onScrollForWindow=onResizeForWindow=null;if(this.options.showVeil){setTimeout(this.veil.hide.bind(this.veil),0)}}this.options.onAfterClose.apply(this,arguments)}},minimize:function(){if(this.windowState=="minimized"){return }var C=this.onMinimize.apply(this,arguments);if(C!==false){Element.makeClipping(this.container);this.lastHeight=this.container.offsetHeight;Element.hide(this.body);if(this.options.showVeil){this.veil.hide()}this.lastPos=Position.find(this.container);var B,A=$(this.name+"Close");if(A){B=(A.offsetTop+A.offsetHeight)}else{B=(Element.getHeight(this.title))}Element.setStyle(this.container,{height:B,minHeight:B});this.container.style.left="0px";this.container.style.top=(parseInt(Dimension.window.height,10)-parseInt((B),10))+"px";this.windowState="minimized";this.options.onAfterMinimize.apply(this,arguments)}},maximize:function(){if(this.windowState=="opened"){return }var A=this.onMaximize.apply(this,arguments);if(A!==false){Element.setStyle(this.container,{height:this.lastHeight+"px",minHeight:this.options.height+"px",top:this.lastPos.top+"px",left:this.lastPos.left+"px",position:"absolute"});Element.removeClipping(this.container);Element.show(this.body);if(this.options.showVeil){this.veil.show()}__currentModal=this;this.windowState="opened";this.options.onAfterMaximize.apply(this,arguments)}},setContent:function(B){if(!this.initialised){this.init()}B=(B||"&nbsp;").toString();if((this.loadingUrl=/((f|ht)tp([s]{0,1}):\/\/|\.\/)([\d\w_.])/.test(B))&&!__modalsCache[B]){Element.update(this.body,"<span>Loading ...</span>");var C=Object.extend({evalScripts:this.options.evalScripts},this.options);var A=C.onComplete||Prototype.emptyFunction;C.onComplete=(function(E,D,F){if(this.options.cacheURLs){__modalsCache[B]=E.responseText}this.onLoad.apply(this,arguments);this.setWidth();A(E,D,F)}).bind(this);this.transport=new Ajax.Updater(this.body.id,B,C)}else{this.body.innerHTML="<span>"+(__modalsCache[B]||B)+"</span>";this.setWidth()}},setTitle:function(J){if(!this.initialised){this.initialize()}if(!this.setButtons){return }var B=[".jpg","jpeg",".bmp",".png",".gif"];Element.update(this.title,this.titleText=(J||"").toString());if(!this.options.allowHTMLTitle){Element.update(this.title,(J||"").toString().escapeHTML())}if(this.options.width&&this.options.height&&this.setButtons&&(this.options.buttonClose||this.options.buttonMax||this.options.buttonMin)){this.title.update(this.title.innerHTML+"<span style=\"text-align: right; width:100%;\">"+((!this.options.buttonMin)?"":"<span id=\""+this.name+"Minimize\" class=\"ModalWinMin "+this.classNamePrefix+"Button\" title=\"minimize\">_</span>")+((!this.options.buttonMax)?"":"<span id=\""+this.name+"Maximize\" class=\"ModalWinMax "+this.classNamePrefix+"Button\" title=\"maximize\">[]</span>")+((!this.options.buttonClose)?"":"<span id=\""+this.name+"Close\" class=\"ModalWinClose "+this.classNamePrefix+"Button\" title=\"close\">X</span>")+"</span>");var D=Number((Element.getStyle(this.title,"padding-right")||"0").replace(/[^\d]+/i,""))+Number((Element.getStyle(this.container,"padding-right")||"0").replace(/[^\d]+/i,""))+Number((Element.getStyle(this.title,"border-right-width")||"0").replace(/[^\d]+/i,""))+Number((Element.getStyle(this.container,"border-right-width")||"0").replace(/[^\d]+/i,""));D=this.options.width-D;var K=$(this.name+"Close");var I=$(this.name+"Maximize");var E=$(this.name+"Minimize");var A=K||I||E;var H=Element.getStyle(K,"top")||(Number((Element.getStyle(this.title,"padding-top")||"0").replace(/[^\d]+/i,""))+Number((Element.getStyle(this.container,"padding-top")||"0").replace(/[^\d]+/i,""))+Number((Element.getStyle(this.title,"border-top-width")||"0").replace(/[^\d]+/i,""))+Number((Element.getStyle(this.container,"border-top-width")||"0").replace(/[^\d]+/i,"")))-(Number((Element.getStyle(A,"top")||"0").replace(/[^\d]+/i,""))+Number((Element.getStyle(A,"border-top")||"0").replace(/[^\d]+/i,""))+Number((Element.getStyle(A,"padding-top")||"0").replace(/[^\d]+/i,""))+Number((Element.getStyle(A,"border-bottom")||"0").replace(/[^\d]+/i,""))+Number((Element.getStyle(A,"padding-bottom")||"0").replace(/[^\d]+/i,"")))+"px";var C=BrowserDetect.OS=="Mac"&&BrowserDetect.browser=="Safari"?15:0;if(K){var G="";if((G=Element.getStyle(K,"background-image"))!="none"&&(G=G.match(/http(s?):\/\/[^\s\)]{1,}/gim)[0]||false)){var F=new Image();F.src=G;F.onload=(function(){Element.setStyle(this,{backgroundColor:"white"});Element.update(this,"&nbsp;")}).bind(K)}G=new String(this.options.buttonClose);if(B.indexOf(G.substr(G.lastIndexOf("."),4))!=-1){K.update("<img src=\""+G+"\">")}Element.setStyle(K,{position:"absolute",left:(D-=Number((K.getStyle("width")||"0").replace(/[^\d]+/i,"")))+"px",top:H});D-=15;Event.listen(K,"mouseover",function(){K.addClassName("ModalContainerButtonHover")},false);Event.listen(K,"mouseout",function(){K.removeClassName("ModalContainerButtonHover")},false);Event.listen(K,"mousedown",function(){K.addClassName("ModalContainerButtonPress")},false);Event.listen(K,"mouseup",function(){K.removeClassName("ModalContainerButtonPress");__currentModal.close()},false)}if(I){if(window.console){D=D-C}Element.setStyle(I,{position:"absolute",left:(D-=Number((Element.getStyle(I,"width")||"0").replace(/[^\d]+/i,"")))+"px",top:H});D-=5;Event.listen(I,"mouseover",function(){Element.addClassName(I,"ModalContainerButtonHover")});Event.listen(I,"mouseout",function(){Element.removeClassName(I,"ModalContainerButtonHover")});Event.listen(I,"mousedown",function(){Element.addClassName(I,"ModalContainerButtonPress")});Event.listen(I,"mouseup",function(){Element.removeClassName(I,"ModalContainerButtonPress");__currentModal.maximize()});var G="";if((G=Element.getStyle(K,"background-image"))!="none"&&(G=G.match(/http(s?):\/\/[^\s\)]{1,}/gim)[0]||false)){var F=new Image();F.src=G;F.onload=(function(){Element.setStyle(this,{backgroundColor:"white"});Element.update(this,"&nbsp;")}).bind(I)}G=new String(this.options.buttonMax);if(B.indexOf(G.substr(G.lastIndexOf("."),4))!=-1){Element.update(I,"<img src=\""+G+"\">")}}if(E){if(window.console){D=D-C}Element.setStyle(E,{position:"absolute",left:(D-=Number((Element.getStyle(E,"width")||"0").replace(/[^\d]+/i,"")))+"px",top:H});Event.listen(E,"mouseover",function(){Element.addClassName(E,"ModalContainerButtonHover")});Event.listen(E,"mouseout",function(){Element.removeClassName(E,"ModalContainerButtonHover")});Event.listen(E,"mousedown",function(){Element.addClassName(E,"ModalContainerButtonPress")});Event.listen(E,"mouseup",function(){Element.removeClassName(E,"ModalContainerButtonPress");__currentModal.minimize()});var G="";if((G=Element.getStyle(K,"background-image"))!="none"&&(G=G.match(/http(s?):\/\/[^\s\)]{1,}/gim)[0]||false)){var F=new Image();F.src=G;F.onload=(function(){Element.setStyle(this,{backgroundColor:"white"});Element.update(this,"&nbsp;")}).bind(E)}G=new String(this.options.buttonMin);if(B.indexOf(G.substr(G.lastIndexOf("."),4))!=-1){Element.update(E,"<img src=\""+G+"\">")}}}},setOptions:function(A){Object.extend(this.options,(typeof A=="object")?A:{})},show:function(){__currentModal=this;if(this.setButtons){this.onLoad=(this.options.onLoad).bind(this);this.onOpen=(this.options.onOpen).bind(this);this.onMaximize=(this.options.onMaximize).bind(this);this.onMinimize=(this.options.onMinimize).bind(this);this.onClose=(this.options.onClose).bind(this);this.onFocus=(this.options.onFocus).bind(this);this.onBlur=(this.options.onBlur).bind(this);Element.addClassName(this.container,this.classNamePrefix);Element.addClassName(this.title,this.classNamePrefix+"Title");if(this.options.draggable){this.title.style.cursor="move";new Draggable(this.container,{zindex:this.zIndex,handle:this.title,endeffect:Prototype.emptyFunction})}Event.listen(this.title,"mousedown",(function(){if(this!=__currentModal){this._oldZIndex=this.zIndex;this.zIndex=10000+ModalWin.__createdModals+1;this._oldCurrent=__currentModal;this.container.setStyle({zIndex:this.zIndex});this.body.setStyle({zIndex:this.zIndex});this.title.setStyle({zIndex:this.zIndex});Event.listen(this.title,"mouseup",(function(){this.zIndex=this._oldZIndex;this.container.setStyle({zIndex:this.zIndex});this.body.setStyle({zIndex:this.zIndex});this.title.setStyle({zIndex:this.zIndex});__currentModal=this._oldCurrent;this._oldZIndex=null;this._oldCurrent=null}).bind(this));__currentModal=this}}).bind(this),false)}this.focus();this.onOpen.apply(this,arguments);this.windowState="opened"},focus:function(){if(this.setButtons){Event.listen(document,"keydown",(onEscapeForDocument=(this.hideOnEscape).bind(this)),false);Event.listen(window,"resize",(onResizeForWindow=(this.updatePosDim).bind(this)),false);Event.listen(window,"scroll",(onScrollForWindow=(this.updatePosDim).bind(this)),false)}this.onFocus()},blur:function(){alert("BLURRED")},updatePosDim:function(A){if(this.windowState!="opened"){}if(!A){var A=window.event}switch(A.type){case"scroll":this.centerWin();break;case"resize":this.centerWin();break}},setWidth:function(){if(this.options.showVeil){this.veil.show()}this.container.show();this._autoSizeW=this._autoSizeY=false;if(this.options.width==null||isNaN(this.options.width)){this._autoSizeW=true;this.options.width=this.container.offsetWidth}if(this.options.height==null||isNaN(this.options.height)){this._autoSizeY=true;this.options.height=this.container.offsetHeight}if(this.loadingUrl&&this.transport&&this.transport.transport.readyState<4){if(typeof centered=="undefined"){this.centerWin();centered=true}return }var M=0,H=0,C,N;if(typeof centered!="undefined"){delete (centered)}this.container.style.width=(C=Math.max(((isNaN(this.options.width))?0:this.options.width),M))+"px";this.container.style.height=(N=Math.max(((isNaN(this.options.height))?0:this.options.height),H))+"px";var F=0,A=0,G=0,J=0,I=[this.container,this.body,this.title];I.each(function(O){if(!isNaN(O._bord=parseInt((O.getStyle("border-left-width")||"").replace(/[^\d]/gim,"")))&&O._bord>F){F=O._bord}if(!isNaN(O._bord=parseInt((O.getStyle("border-right-width")||"").replace(/[^\d]/gim,"")))&&O._bord>A){A=O._bord}if(!isNaN(O._bord=parseInt((O.getStyle("border-top-width")||"").replace(/[^\d]/gim,"")))&&O._bord>G){G=O._bord}if(!isNaN(O._bord=parseInt((O.getStyle("border-bottom-width")||"").replace(/[^\d]/gim,"")))&&O._bord>J){J=O._bord}if(O._bord){O._bord=null}});C-=F+A;N-=G+J;this.title.style.minWidth=this.body.style.minWidth=C+"px";this.body.style.verticalAlign="bottom";if(this.cover){this.cover.style.height=(this.container.offsetHeight-5)+"px";this.cover.style.width=(this.container.offsetWidth-5)+"px";this.cover.style.left=this.body.offsetLeft+"px";this.cover.style.zIndex=this.body.style.zIndex-1;this.cover.style.display="block"}else{this.body.style.height=(N-this.title.offsetHeight-G-J)+"px"}var B=this.__findMaxDims(),E,D=["table","div"];if((this._autoSizeW||this._autoSizeY)&&B){if(B.x!=this.body.offsetWidth){if(this._autoSizeW){M=Math.min(B.x,ModalWin.window.width);this.container.style.width=(this.options.width=M)+"px";this.container.style.overflowX="hidden"}else{this.body.style.overflowX="auto"}}if(B.y!=this.body.offsetHeight){if(this._autoSizeY){H=Math.min(B.y,ModalWin.window.height);this.body.style.height=H+"px";this.container.style.height=(this.options.height=(H+this.title.offsetHeight+G+J))+"px";if(B.y>ModalWin.window.height){var K=1000;var L=ModalWin.window.height-20;this.container.style.height=(L)+"px";this.body.style.height=(this.container.offsetHeight-this.title.offsetHeight-J-G)+"px";this.container.style.overflowY="hidden";this.body.style.overflowY="auto";this.body.scrollTop=0}}else{this.body.style.overflowY="auto";this.body.scrollTop=0}}}else{this.body.style.overflow="auto"}if(this.container.offsetHeight>=ModalWin.window.height){this.container.style.height=(this.options.height=(ModalWin.window.height-30))+"px";this.body.style.height=((ModalWin.window.height-40)-this.title.offsetHeight-J-G)+"px"}if(this.container.offsetWidth>=ModalWin.window.width){this.container.style.width=(this.options.width=(ModalWin.window.width-30))+"px";this.body.style.width=((ModalWin.window.width-40)-F-A)+"px"}this.setTitle(this.titleText);this.container.hide();this.centerWin()},__findMaxDims:function(E,B){var B=B||{x:this.options.width||0,y:this.options.width||0},E=E||this.body,D=["table","div","form","p"];try{for(var A=0;A<D.length;A++){for(var C=0,G=E.getElementsByTagName(D[A]);C<G.length;C++){if(G[C].offsetWidth||G[C].offsetHeight){B.x=Math.max(B.x,G[C].offsetWidth);B.y=Math.max(B.y,G[C].offsetHeight)}B=this.__findMaxDims(G[C],B)}}}catch(F){if(DEBUG_MODE){alert("ModalWin.__findMaxDims:"+F.message)}return B}return B},centerWin:function(){if((this.options.width&&this.options.height)||this.container.style.display!="none"){width=this.options.width;height=this.options.height;if(width==null||isNaN(width)){this.options.width=width=this.container.offsetWidth}if(height==null||isNaN(height)){this.options.height=height=this.container.offsetHeight}var F=Dimension.window.getDimensions();var C=F["y"];var G=F["x"];var D=(document.documentElement||document.body);var A=parseInt(D.scrollTop,10);var B=parseInt(D.scrollLeft,10);var E=parseInt(this.title.offsetHeight);if(this.container.offsetHeight>=F.height){this.container.style.height=(height=(F.height-30))+"px";this.body.style.height=((F.height-40)-this.title.offsetHeight)+"px"}if(this.container.offsetWidth>=F.width){this.container.style.width=(width=(F.width-30))+"px";this.body.style.width=((F.width-40))+"px"}this.container.style.top=(A+(this.options.y||((C-(height+E))/2)))+"px";this.container.style.left=(B+(this.options.x||((G-width)/2)))+"px";this.container.show();if(this._autoSizeW||this._autoSizeY){if(this._autoSizeW){this.options.width=null}if(this._autoSizeY){this.options.height=null}}}},hideOnEscape:function(B){Event.getEvent((B=B||window.event));var A=Event.key(B);if(A.code==Event["KEY_ESC"]&&__currentModal==this){this.close();if(__modalsCache.length==0){Event.stopListen(document,"keydown",onEscapeForDocument,false);onEscapeForDocument=null}}},disableTabIndexes:function(){if(!this.options.showVeil){return }var C=0;for(var B=0;B<this.tabbableTags.length;B++){var D=document.getElementsByTagName(this.tabbableTags[B]);for(var A=0;A<D.length;A++){if(typeof this.tabIndexes[C]=="undefined"){this.tabIndexes[C]=D[A].tabIndex}D[A].tabIndex="-1";C++}}},restoreTabIndexes:function(){if(!this.options.showVeil){return }var C=0;for(var B=0;B<this.tabbableTags.length;B++){var D=document.getElementsByTagName(this.tabbableTags[B]);for(var A=0;A<D.length;A++){D[A].tabIndex=this.tabIndexes[C];D[A].tabEnabled=true;C++}}}};var ModalAlert=function(){var A=window.alert.apply;window.alert.apply=this;ModalWin.open(arguments[0],arguments[1]||"Alert",Object.extend({draggable:true},(typeof arguments[2]=="object"?arguments[2]:{})));window.alert.apply=A};var ModalConfirm=function(D,C,A){A=Object.extend({draggable:true,butYes:"Yes",butNo:"No",buttonMax:0,buttonMin:0,onConfirm:Prototype.emptyFunction},(typeof arguments[2]=="object"?arguments[2]:{}));returnStatus=false;A.onClose=function(){var E=arguments[0]||false;if(E){A.onConfirm.apply(window,$A(arguments))}};var B="<div style=\"width:100%;height:100%;vertical-align:bottom;\" align=\"center\">"+D.toString()+"<br>    <input type=\"button\" value=\""+A.butYes+"\" onclick=\"__currentModal.close(true);\">&nbsp;    <input type=\"button\" value=\""+A.butNo+"\" onclick=\"__currentModal.close(false);\"></div>";ModalWin.open(B,C||"Confirm",A)}