if(typeof(Control)=="undefined"){Control={}}Control.Modal=Class.create();Object.extend(Control.Modal,{closeLinkHtml:'<div style="text-align: right; width: 25px; position: absolute; float: right; right: 5px; top: 5px;"><a style="color:black" href="javascript:Control.Modal.close();"><img style="border:0" src="/portal/resources/Alsa/img_v5/cerrar.naranja.peq.gif"/></a></div>',loaded:false,loading:false,loadingTimeout:false,overlay:false,container:false,current:false,ie:false,effects:{containerFade:false,containerAppear:false,overlayFade:false,overlayAppear:false},targetRegexp:/#(.+)$/,imgRegexp:/\.(jpe?g|gif|png|tiff?)$/i,overlayStyles:{position:"fixed",top:0,left:0,width:"100%",height:"100%",zIndex:9998},overlayIEStyles:{position:"absolute",top:0,left:0,zIndex:9998},disableHoverClose:false,load:function(){if(!Control.Modal.loaded){Control.Modal.loaded=true;Control.Modal.ie=!(typeof document.body.style.maxHeight!="undefined");Control.Modal.overlay=$(document.createElement("div"));Control.Modal.overlay.id="modal_overlay";Object.extend(Control.Modal.overlay.style,Control.Modal["overlay"+(Control.Modal.ie?"IE":"")+"Styles"]);Control.Modal.overlay.hide();Control.Modal.container=$(document.createElement("div"));Control.Modal.container.id="modal_container";Control.Modal.container.hide();Control.Modal.loading=$(document.createElement("div"));Control.Modal.loading.id="modal_loading";Control.Modal.loading.hide();Control.Modal.loading=$(document.createElement("div"));Control.Modal.loading.id="roberContainer";Control.Modal.loading.hide();var b=document.getElementsByTagName("body")[0];b.appendChild(Control.Modal.overlay);b.appendChild(Control.Modal.loading);b.appendChild(Control.Modal.container);Control.Modal.container.observe("mouseout",function(a){if(!Control.Modal.disableHoverClose&&Control.Modal.current&&Control.Modal.current.options.hover&&!Position.within(Control.Modal.container,Event.pointerX(a),Event.pointerY(a))){Control.Modal.close()}})}},open:function(f,d){d=d||{};if(!d.contents){d.contents=f}var e=new Control.Modal(false,d);e.open();return e},close:function(b){if(typeof(b)!="boolean"){b=false}if(Control.Modal.current){Control.Modal.current.close(b)}},attachEvents:function(){Event.observe(window,"load",Control.Modal.load);Event.observe(window,"unload",Event.unloadCache,false)},center:function(h){if(!h._absolutized){h.setStyle({position:"absolute"});h._absolutized=true}var g=h.getDimensions();Position.prepare();var e=(Position.deltaX+Math.floor((Control.Modal.getWindowWidth()-g.width)/2));var f=(Position.deltaY+((Control.Modal.getWindowHeight()>g.height)?Math.floor((Control.Modal.getWindowHeight()-g.height)/2):0));h.setStyle({top:((g.height<=Control.Modal.getDocumentHeight())?((f!=null&&f>0)?f:"0")+"px":0),left:((g.width<=Control.Modal.getDocumentWidth())?((e!=null&&e>0)?e:"0")+"px":0)})},getWindowWidth:function(){return(self.innerWidth||document.documentElement.clientWidth||document.body.clientWidth||0)},getWindowHeight:function(){return(self.innerHeight||document.documentElement.clientHeight||document.body.clientHeight||0)},getDocumentWidth:function(){return Math.min(document.body.scrollWidth,Control.Modal.getWindowWidth())},getDocumentHeight:function(){return Math.max(document.body.scrollHeight,Control.Modal.getWindowHeight())},onKeyDown:function(b){if(b.keyCode==Event.KEY_ESC){Control.Modal.close()}}});Object.extend(Control.Modal.prototype,{mode:"",html:false,href:"",element:false,src:false,imageLoaded:false,ajaxRequest:false,initialize:function(j,k){this.element=$(j);this.options={beforeOpen:Prototype.emptyFunction,afterOpen:Prototype.emptyFunction,beforeClose:Prototype.emptyFunction,afterClose:Prototype.emptyFunction,onSuccess:Prototype.emptyFunction,onFailure:Prototype.emptyFunction,onException:Prototype.emptyFunction,beforeImageLoad:Prototype.emptyFunction,afterImageLoad:Prototype.emptyFunction,autoOpenIfLinked:true,contents:false,loading:false,fade:false,fadeDuration:0.75,image:false,imageCloseOnClick:true,hover:false,iframe:false,iframeTemplate:new Template(Control.Modal.closeLinkHtml+'<iframe src="#{href}" width="100%" height="100%" frameborder="0" id="#{id}"></iframe>'),evalScripts:true,requestOptions:{},overlayDisplay:true,overlayClassName:"",overlayCloseOnClick:true,containerClassName:"",opacity:0.6,zIndex:9998,width:null,height:null,offsetLeft:0,offsetTop:0,position:"absolute"};Object.extend(this.options,k||{});var i=false;var l=false;if(this.element){i=Control.Modal.targetRegexp.exec(this.element.href);l=Control.Modal.imgRegexp.exec(this.element.href)}if(this.options.position=="mouse"){this.options.hover=true}if(this.options.contents){this.mode="contents"}else{if(this.options.image||l){this.mode="image";this.src=this.element.href}else{if(i){this.mode="named";var h=$(i[1]);this.html=h.innerHTML;h.remove();this.href=i[1]}else{this.mode=(this.options.iframe)?"iframe":"ajax";this.href=this.element.href}}}if(this.element){if(this.options.hover){this.element.observe("mouseover",this.open.bind(this));this.element.observe("mouseout",function(a){if(!Position.within(Control.Modal.container,Event.pointerX(a),Event.pointerY(a))){this.close()}}.bindAsEventListener(this))}else{this.element.onclick=function(a){this.open();Event.stop(a);return false}.bindAsEventListener(this)}}var g=Control.Modal.targetRegexp.exec(window.location);this.position=function(b){if(this.options.position=="absolute"){Control.Modal.center(Control.Modal.container)}else{var a=(b&&this.options.position=="mouse"?[Event.pointerX(b),Event.pointerY(b)]:Position.cumulativeOffset(this.element));Control.Modal.container.setStyle({position:"absolute",top:a[1]+(typeof(this.options.offsetTop)=="function"?this.options.offsetTop():this.options.offsetTop)+"px",left:a[0]+(typeof(this.options.offsetLeft)=="function"?this.options.offsetLeft():this.options.offsetLeft)+"px"})}if(Control.Modal.ie){Control.Modal.overlay.setStyle({height:Control.Modal.getDocumentHeight()+"px",width:Control.Modal.getDocumentWidth()+"px"})}}.bind(this);if(this.mode=="named"&&this.options.autoOpenIfLinked&&g&&g[1]&&g[1]==this.href){this.open()}},showLoadingIndicator:function(){if(this.options.loading){Control.Modal.loadingTimeout=window.setTimeout(function(){var b=$("modal_image");if(b){b.hide()}Control.Modal.loading.style.zIndex=this.options.zIndex+1;Control.Modal.loading.update('<img id="modal_loading" src="'+this.options.loading+'"/>');Control.Modal.loading.show();Control.Modal.center(Control.Modal.loading)}.bind(this),250)}},hideLoadingIndicator:function(){if(this.options.loading){if(Control.Modal.loadingTimeout){window.clearTimeout(Control.Modal.loadingTimeout)}var b=$("modal_image");if(b){b.show()}Control.Modal.loading.hide()}},open:function(g){if(!g&&this.notify("beforeOpen")===false){return}if(!Control.Modal.loaded){Control.Modal.load()}Control.Modal.close();if(!this.options.hover){Event.observe($(document.getElementsByTagName("body")[0]),"keydown",Control.Modal.onKeyDown)}Control.Modal.current=this;if(!this.options.hover){Control.Modal.overlay.setStyle({zIndex:this.options.zIndex,opacity:this.options.opacity})}Control.Modal.container.setStyle({zIndex:this.options.zIndex+1,width:(this.options.width?(typeof(this.options.width)=="function"?this.options.width():this.options.width)+"px":null),height:(this.options.height?(typeof(this.options.height)=="function"?this.options.height():this.options.height)+"px":null)});if(Control.Modal.ie&&!this.options.hover){$A(document.getElementsByTagName("select")).each(function(a){a.style.visibility="hidden"})}Control.Modal.overlay.addClassName(this.options.overlayClassName);Control.Modal.container.addClassName(this.options.containerClassName);switch(this.mode){case"image":this.imageLoaded=false;this.notify("beforeImageLoad");this.showLoadingIndicator();var f=document.createElement("div");f.innerHTML=Control.Modal.closeLinkHtml;var e=document.createElement("img");f.appendChild(e);e.onload=function(a){this.hideLoadingIndicator();this.update([f]);if(this.options.imageCloseOnClick){$(a).observe("click",Control.Modal.close)}this.position();this.notify("afterImageLoad");a.onload=null}.bind(this,e);e.src=this.src;e.id="modal_image";break;case"ajax":this.notify("beforeLoad");var h={method:"post",onSuccess:function(a){this.hideLoadingIndicator();this.update(a.responseText);this.notify("onSuccess",a);this.ajaxRequest=false}.bind(this),onFailure:function(){this.notify("onFailure")}.bind(this),onException:function(){this.notify("onException")}.bind(this)};Object.extend(h,this.options.requestOptions);this.showLoadingIndicator();this.ajaxRequest=new Ajax.Request(this.href,h);break;case"iframe":this.update(this.options.iframeTemplate.evaluate({href:this.href,id:"modal_iframe"}));break;case"contents":this.update((typeof(this.options.contents)=="function"?this.options.contents():this.options.contents));break;case"named":this.update(this.html);break}if(!this.options.hover){if(this.options.overlayCloseOnClick&&this.options.overlayDisplay){window.onclick=function(a){Control.Modal.overlay.onclick=Control.Modal.close}}if(this.options.overlayDisplay){if(this.options.fade){if(Control.Modal.effects.overlayFade){Control.Modal.effects.overlayFade.cancel()}Control.Modal.effects.overlayAppear=new Effect.Appear(Control.Modal.overlay,{queue:{position:"front",scope:"Control.Modal"},to:this.options.opacity,duration:this.options.fadeDuration/2})}else{Control.Modal.overlay.show()}}}if(this.options.position=="mouse"){this.mouseHoverListener=this.position.bindAsEventListener(this);this.element.observe("mousemove",this.mouseHoverListener)}this.notify("afterOpen")},update:function(b){if(typeof(b)=="string"){Control.Modal.container.update(b)}else{Control.Modal.container.update("");(b.each)?b.each(function(a){Control.Modal.container.appendChild(a)}):Control.Modal.container.appendChild(node)}if(this.options.fade){if(Control.Modal.effects.containerFade){Control.Modal.effects.containerFade.cancel()}Control.Modal.effects.containerAppear=new Effect.Appear(Control.Modal.container,{queue:{position:"end",scope:"Control.Modal"},to:1,duration:this.options.fadeDuration/2})}else{Control.Modal.container.show()}this.position();Event.observe(window,"resize",this.position,false);Event.observe(window,"scroll",this.position,false)},close:function(d){if(!d&&this.notify("beforeClose")===false){return}if(this.ajaxRequest){this.ajaxRequest.transport.abort()}this.hideLoadingIndicator();if(this.mode=="image"){var c=$("modal_image");if(this.options.imageCloseOnClick&&c){c.stopObserving("click",Control.Modal.close)}}if(Control.Modal.ie&&!this.options.hover){$A(document.getElementsByTagName("select")).each(function(a){a.style.visibility="visible"})}if(!this.options.hover){Event.stopObserving(window,"keyup",Control.Modal.onKeyDown)}Control.Modal.current=false;Event.stopObserving(window,"resize",this.position,false);Event.stopObserving(window,"scroll",this.position,false);if(!this.options.hover){if(this.options.overlayCloseOnClick&&this.options.overlayDisplay){Control.Modal.overlay.stopObserving("click",Control.Modal.close)}if(this.options.overlayDisplay){if(this.options.fade){if(Control.Modal.effects.overlayAppear){Control.Modal.effects.overlayAppear.cancel()}Control.Modal.effects.overlayFade=new Effect.Fade(Control.Modal.overlay,{queue:{position:"end",scope:"Control.Modal"},from:this.options.opacity,to:0,duration:this.options.fadeDuration/2})}else{Control.Modal.overlay.hide()}}}if(this.options.fade){if(Control.Modal.effects.containerAppear){Control.Modal.effects.containerAppear.cancel()}Control.Modal.effects.containerFade=new Effect.Fade(Control.Modal.container,{queue:{position:"front",scope:"Control.Modal"},from:1,to:0,duration:this.options.fadeDuration/2,afterFinish:function(){Control.Modal.container.update("");this.resetClassNameAndStyles()}.bind(this)})}else{Control.Modal.container.hide();Control.Modal.container.update("");this.resetClassNameAndStyles()}if(this.options.position=="mouse"){this.element.stopObserving("mousemove",this.mouseHoverListener)}this.notify("afterClose")},resetClassNameAndStyles:function(){Control.Modal.overlay.removeClassName(this.options.overlayClassName);Control.Modal.container.removeClassName(this.options.containerClassName);Control.Modal.container.setStyle({height:null,width:null,top:null,left:null})},notify:function(c){try{if(this.options[c]){return[this.options[c].apply(this.options[c],$A(arguments).slice(1))]}}catch(d){if(d!=$break){throw d}else{return false}}}});if(typeof(Object.Event)!="undefined"){Object.Event.extend(Control.Modal)}Control.Modal.attachEvents();
