if(!window.Modalbox)
var Modalbox=new Object();Modalbox.Methods={currFocused:0,focusableElements:new Array,initialized:false,active:true,options:{title:"ModalBox Window",overlayClose:true,width:500,height:190,overlayOpacity:.80,overlayDuration:.25,resizeDuration:.25,loadingString:"Please wait. Loading...",closeString:"Close window",params:{},method:'get',autoFocusing:true},_hideObjects:[],_options:new Object,setOptions:function(options){Object.extend(this.options,options||{});},_init:function(options){Object.extend(this._options,this.options);this.setOptions(options);this.MBoverlay=new Element("div",{id:"MB_overlay",opacity:"0"});this.MBwindow=new Element("div",{id:"MB_window",style:"display: none"}).update(this.MBframe=new Element("div",{id:"MB_frame"}).update(this.MBheader=new Element("div",{id:"MB_header"}).update(this.MBcaption=new Element("div",{id:"MB_caption"}))));this.MBhidden=new Element("div",{id:"MB_hidden",style:"display: none"});this.MBclose=new Element("a",{id:"MB_close",title:this.options.closeString,href:"#"});this.MBheader.insert({'bottom':this.MBclose});this.MBcontent=new Element("div",{id:"MB_content"}).update(this.MBloading=new Element("div",{id:"MB_loading"}).update(this.options.loadingString));this.MBframe.insert({'bottom':this.MBcontent});this.MBframe.insert({'bottom':this.MBhidden});this._hideObjects=[];var embeds=document.getElementsByTagName('embed');for(var i=0;i<embeds.length;i++){var wMode=embeds[i].getAttribute('wmode');if(embeds[i].id&&(wMode=='window'||!wMode)&&embeds[i].visible()){this._hideObjects.push(embeds[i]);embeds[i].style.visibility='hidden';}}
var objects=document.getElementsByTagName('object');for(var i=0;i<objects.length;i++){if(objects[i].wmode){if(objects[i].wmode.toLowerCase()=='window'){this._hideObjects.push(objects[i]);objects[i].style.visibility='hidden';}}}
var injectToEl=$(document.body);injectToEl.insert({'top':this.MBwindow});injectToEl.insert({'top':this.MBoverlay});this.hideObserver=this._hide.bindAsEventListener(this);this.kbdObserver=this._kbdHandler.bindAsEventListener(this);this._initObservers();this.initialized=true;},show:function(content,options){if(!this.initialized)this._init(options);this.content=content;this.setOptions(options);if(this.options.title)
$(this.MBcaption).update(this.options.title);else{$(this.MBheader).hide();$(this.MBcaption).hide();}
if(this.MBwindow.style.display=="none"){this._appear();this.event("onShow");}else{this._update();this.event("onUpdate");}},setTitle:function(caption){this.options.title=caption;$(this.MBcaption).update(this.options.title);},hide:function(options){if(this.initialized){if(options&&typeof options.element!='function')Object.extend(this.options,options);this.event("beforeHide");Effect.Fade(this.MBwindow,{duration:this.options.overlayDuration,transition:Effect.Transitions.sinoidal,afterFinish:this._deinit.bind(this)});}else throw("Modalbox is not initialized.");},_hide:function(event){event.stop();if(event.element().id=='MB_overlay'&&!this.options.overlayClose)return false;this.hide();},alert:function(message){var html='<div class="MB_alert"><p>'+message+'</p><input type="button" onclick="Modalbox.hide()" value="OK" /></div>';Modalbox.show(html,{title:'Alert: '+document.title,width:300});},_appear:function(){this._setSize();this._setPosition();$(this.MBoverlay).setStyle({opacity:0});new Effect.Fade(this.MBoverlay,{from:0,to:this.options.overlayOpacity,duration:this.options.overlayDuration,afterFinish:function(){new Effect.Appear(this.MBwindow,{duration:this.options.overlayDuration,transition:Effect.Transitions.sinoidal,afterFinish:function(){this._setPosition();this.loadContent();}.bind(this)});}.bind(this)});this._setPosition=this._setPosition.bindAsEventListener(this);Event.observe(window,"resize",this._setPosition);},_getPageSize:function(){var xScroll,yScroll;if(window.innerHeight&&window.scrollMaxY){xScroll=window.innerWidth+window.scrollMaxX;yScroll=window.innerHeight+window.scrollMaxY;}else if(document.body.scrollHeight>document.body.offsetHeight){xScroll=document.body.scrollWidth;yScroll=document.body.scrollHeight;}else{xScroll=document.body.offsetWidth;yScroll=document.body.offsetHeight;}
var windowWidth,windowHeight;if(self.innerHeight){if(document.documentElement.clientWidth){windowWidth=document.documentElement.clientWidth;}else{windowWidth=self.innerWidth;}
windowHeight=self.innerHeight;}else if(document.documentElement&&document.documentElement.clientHeight){windowWidth=document.documentElement.clientWidth;windowHeight=document.documentElement.clientHeight;}else if(document.body){windowWidth=document.body.clientWidth;windowHeight=document.body.clientHeight;}
if(yScroll<windowHeight){pageHeight=windowHeight;}else{pageHeight=yScroll;}
if(xScroll<windowWidth){pageWidth=xScroll;}else{pageWidth=windowWidth;}
return[pageWidth,pageHeight];},resize:function(byWidth,byHeight,options){var byWidth=byWidth+parseInt($(this.MBcontent).getStyle('padding-left'))+parseInt($(this.MBcontent).getStyle('padding-right'))+parseInt($(this.MBcontent).getStyle('margin-left'))+parseInt($(this.MBcontent).getStyle('margin-right'));var byHeight=byHeight+parseInt($(this.MBcontent).getStyle('padding-top'))+parseInt($(this.MBcontent).getStyle('padding-bottom'))+parseInt($(this.MBcontent).getStyle('margin-top'))+parseInt($(this.MBcontent).getStyle('margin-bottom'));var currentWidth=$(this.MBcontent).getWidth();var currentHeight=$(this.MBheader).getHeight()+$(this.MBcontent).getHeight();var newWidth=currentWidth+byWidth;var newHeight=$(this.MBheader).getHeight()+byHeight;if(options){if(options.title){this.setTitle(options.title);}
this.setOptions(options);}
new Effect.ScaleBy(this.MBwindow,byWidth,newHeight,{duration:this.options.resizeDuration,scaleFromTop:false,afterFinish:function(){this.event("_afterResize");this.event("afterResize");}.bind(this)});},resizeToContent:function(options){var newHeight=$(this.MBcontent).offsetHeight;if(newHeight!=0){Modalbox.resize(this.options.width,newHeight,options);}},resizeTo:function(width,height,options){var byHeight=height-this.MBwindow.offsetHeight;var byWidth=width-this.MBwindow.offsetWidth;Modalbox.resize(byWidth,byHeight,options);},resizeToInclude:function(element,options){var el=$(element);var elHeight=el.getHeight();var elWidth=el.getWidth();Modalbox.resizeTo(elWidth,elHeight,options);},_update:function(){$(this.MBcontent).update("");this.MBcontent.appendChild(this.MBloading);$(this.MBloading).update(this.options.loadingString);Modalbox.resizeTo(this.options.width,this.options.height,{_afterResize:this._loadAfterResize.bind(this)});},setStatus:function(status){if(status=='loading'){var oldContent=this.MBcontent.innerHTML;this.MBcontent.update('');this.MBcontent.appendChild(this.MBloading);this.MBhidden.update(oldContent);$(this.MBloading).update(this.options.loadingString);}else if(this.MBhidden.innerHTML){var oldContent=this.MBhidden.innerHTML;this.MBcontent.update(oldContent);this.MBhidden.update('');}},loadContent:function(){if(this.event("beforeLoad")!=false){if(typeof this.content=='string'){var htmlRegExp=new RegExp(/<\/?[^>]+>/gi);if(htmlRegExp.test(this.content)){this._insertContent(this.content.stripScripts());this._putContent(function(){this.content.extractScripts().map(function(script){return eval(script.replace("<!--","").replace("// -->",""));}.bind(window));}.bind(this));}else
new Ajax.Request(this.content,{method:this.options.method.toLowerCase(),parameters:this.options.params,onSuccess:function(transport){var response=new String(transport.responseText);this._insertContent(transport.responseText.stripScripts());this._putContent(function(){response.extractScripts().map(function(script){return eval(script.replace("<!--","").replace("// -->",""));}.bind(window));});}.bind(this),onException:function(instance,exception){Modalbox.hide();throw('Modalbox Loading Error: '+exception);}});}else if(typeof this.content=='object'){this._insertContent(this.content);this._putContent();}else{Modalbox.hide();throw('Modalbox Parameters Error: Please specify correct URL or HTML element (plain HTML or object)');}}},_insertContent:function(content){$(this.MBcontent).hide().update("");if(typeof content=='string'){setTimeout(function(){this.MBcontent.update(content);}.bind(this),1);}else if(typeof content=='object'){var _htmlObj=content.cloneNode(true);if(content.id)content.id="MB_"+content.id;$(content).select('*[id]').each(function(el){el.id="MB_"+el.id;});this.MBcontent.appendChild(_htmlObj);this.MBcontent.down().show();if(Prototype.Browser.IE)
$$("#MB_content select").invoke('setStyle',{'visibility':''});}},_putContent:function(callback){if(this.options.height!=this._options.height||this.options.width!=this._options.width){var newHeight=this.options.height;var newWidth=this.options.width;setTimeout(function(){Modalbox.resizeTo(newWidth,newHeight,{afterResize:function(){this.MBcontent.show().makePositioned();this.focusableElements=this._findFocusableElements();this._setFocus();setTimeout(function(){if(callback!=undefined)
callback();this.event("afterLoad");}.bind(this),1);}.bind(this)});}.bind(this),1);}else{this.MBcontent.show();setTimeout(function(){if(callback!=undefined)
callback();this.event("afterLoad");}.bind(this),1);}},activate:function(options){this.setOptions(options);this.active=true;$(this.MBclose).observe("click",this.hideObserver);if(this.options.overlayClose)
$(this.MBoverlay).observe("click",this.hideObserver);$(this.MBclose).show();new Effect.Appear(this.MBwindow,{duration:this.options.overlayDuration});},deactivate:function(options){this.setOptions(options);this.active=false;$(this.MBclose).stopObserving("click",this.hideObserver);if(this.options.overlayClose)
$(this.MBoverlay).stopObserving("click",this.hideObserver);$(this.MBclose).hide();new Effect.Fade(this.MBwindow,{duration:this.options.overlayDuration,to:.75});},_initObservers:function(){$(this.MBclose).observe("click",this.hideObserver);if(this.options.overlayClose)
$(this.MBoverlay).observe("click",this.hideObserver);if(Prototype.Browser.IE)
Event.observe(document,"keydown",this.kbdObserver);else
Event.observe(document,"keypress",this.kbdObserver);},_removeObservers:function(){$(this.MBclose).stopObserving("click",this.hideObserver);if(this.options.overlayClose)
$(this.MBoverlay).stopObserving("click",this.hideObserver);if(Prototype.Browser.IE)
Event.stopObserving(document,"keydown",this.kbdObserver);else
Event.stopObserving(document,"keypress",this.kbdObserver);},_loadAfterResize:function(){this._setSize();this._setPosition();this.loadContent();},_setFocus:function(){if(this.focusableElements.length>0&&this.options.autoFocusing==true){var firstEl=this.focusableElements.find(function(el){return el.tabIndex==1;})||this.focusableElements.first();this.currFocused=this.focusableElements.toArray().indexOf(firstEl);firstEl.focus();}else if($(this.MBheader).visible()&&$(this.MBclose).visible()){$(this.MBclose).focus();}},_findFocusableElements:function(){this.MBcontent.select('input:not([type~=hidden]), select, textarea, button, a[href]').invoke('addClassName','MB_focusable');return this.MBcontent.select('.MB_focusable');},_kbdHandler:function(event){var node=event.element();switch(event.keyCode){case Event.KEY_TAB:event.stop();if(node!=this.focusableElements[this.currFocused])
this.currFocused=this.focusableElements.toArray().indexOf(node);if(!event.shiftKey){if(this.currFocused==this.focusableElements.length-1){this.focusableElements.first().focus();this.currFocused=0;}else{this.currFocused++;this.focusableElements[this.currFocused].focus();}}else{if(this.currFocused==0){this.focusableElements.last().focus();this.currFocused=this.focusableElements.length-1;}else{this.currFocused--;this.focusableElements[this.currFocused].focus();}}
break;case Event.KEY_ESC:if(this.active)this._hide(event);break;case Event.KEY_UP:case Event.KEY_DOWN:case Event.KEY_PAGEDOWN:case Event.KEY_PAGEUP:case Event.KEY_HOME:case Event.KEY_END:if(Prototype.Browser.WebKit&&!["textarea","select"].include(node.tagName.toLowerCase()))
event.stop();else if((node.tagName.toLowerCase()=="input"&&["submit","button"].include(node.type))||(node.tagName.toLowerCase()=="a"))
event.stop();break;}},_deinit:function(){for(var i=0;i<this._hideObjects.length;i++){this._hideObjects[i].style.visibility='visible';}
this._removeObservers();Event.stopObserving(window,"resize",this._setPosition);Effect.toggle(this.MBoverlay,'appear',{duration:this.options.overlayDuration,afterFinish:this._removeElements.bind(this)});$(this.MBcontent).setStyle({overflow:'',height:''});},_removeElements:function(){$(this.MBoverlay).remove();$(this.MBwindow).remove();if(typeof this.content=='object'){if(this.content.id&&this.content.id.match(/MB_/)){this.content.id=this.content.id.replace(/MB_/,"");}
this.content.select('*[id]').each(function(el){el.id=el.id.replace(/MB_/,"");});}
this.initialized=false;this.event("afterHide");this.setOptions(this._options);},_setSize:function(){var newWidth=parseInt(this.options.width)+parseInt($(this.MBcontent).getStyle('padding-left'))+parseInt($(this.MBcontent).getStyle('padding-right'))+parseInt($(this.MBcontent).getStyle('margin-left'))+parseInt($(this.MBcontent).getStyle('margin-right'));var newHeight=parseInt(this.options.height)+parseInt($(this.MBheader).getHeight())+parseInt($(this.MBcontent).getStyle('padding-top'))+parseInt($(this.MBcontent).getStyle('padding-bottom'))+parseInt($(this.MBcontent).getStyle('margin-top'))+parseInt($(this.MBcontent).getStyle('margin-bottom'));$(this.MBwindow).setStyle({width:newWidth+"px",height:newHeight+"px"});},_setPosition:function(){var arrayPageSize=this._getPageSize();this.MBoverlay.setStyle({width:arrayPageSize[0]+'px',height:arrayPageSize[1]+'px'});var arrayPageScroll=document.viewport.getScrollOffsets();var top=Math.round((document.viewport.getHeight()-$(this.MBwindow).getHeight())/2)+arrayPageScroll[1];var left=Math.round((Element.getWidth(document.body)-Element.getWidth(this.MBwindow))/2);$(this.MBwindow).setStyle({top:top+"px",left:left+"px"});},event:function(eventName){if(this.options[eventName]){var returnValue=this.options[eventName]();this.options[eventName]=null;if(returnValue!=undefined)
return returnValue;else
return true;}
return true;}};Object.extend(Modalbox,Modalbox.Methods);Effect.ScaleBy=Class.create();Object.extend(Object.extend(Effect.ScaleBy.prototype,Effect.Base.prototype),{initialize:function(element,byWidth,byHeight,options){this.element=$(element)
var options=Object.extend({scaleFromTop:true,scaleMode:'box',scaleByWidth:byWidth,scaleByHeight:byHeight},arguments[3]||{});this.start(options);},setup:function(){this.elementPositioning=this.element.getStyle('position');this.originalTop=this.element.offsetTop;this.originalLeft=this.element.offsetLeft;this.dims=null;if(this.options.scaleMode=='box')
this.dims=[this.element.offsetHeight,this.element.offsetWidth];if(/^content/.test(this.options.scaleMode))
this.dims=[this.element.scrollHeight,this.element.scrollWidth];if(!this.dims)
this.dims=[this.options.scaleMode.originalHeight,this.options.scaleMode.originalWidth];this.deltaY=this.options.scaleByHeight;this.deltaX=this.options.scaleByWidth;},update:function(position){var currentHeight=this.dims[0]+(this.deltaY*position);var currentWidth=this.dims[1]+(this.deltaX*position);currentHeight=(currentHeight>0)?currentHeight:0;currentWidth=(currentWidth>0)?currentWidth:0;this.setDimensions(currentHeight,currentWidth);},setDimensions:function(height,width){var d={};d.width=width+'px';d.height=height+'px';var topd=Math.round((height-this.dims[0])/2);var leftd=Math.round((width-this.dims[1])/2);if(this.elementPositioning=='absolute'||this.elementPositioning=='fixed'){if(!this.options.scaleFromTop)d.top=this.originalTop-topd+'px';d.left=this.originalLeft-leftd+'px';}else{if(!this.options.scaleFromTop)d.top=-topd+'px';d.left=-leftd+'px';}
this.element.setStyle(d);}});
