﻿
(function()
{if(typeof window.top.Cuke==='undefined')window.top.Cuke={};if(typeof window.top.Cuke.Window==='undefined')init();if(window!=window.top)Cuke.Window=window.top.Cuke.Window;function init()
{window.top.Cuke.Window={};var _zIndex=3000;var _resizeConfigured=false;function _u()
{for(var i=0;i<arguments.length;i++)
if(typeof arguments[i]!='undefined')return false;return true;};function _nextZ()
{return _zIndex++;};function _viewport()
{var d=document.documentElement,b=document.body,w=window;return jQuery.extend(jQuery.browser.msie?{left:b.scrollLeft||d.scrollLeft,top:b.scrollTop||d.scrollTop}:{left:w.pageXOffset,top:w.pageYOffset},!_u(w.innerWidth)?{width:w.innerWidth,height:w.innerHeight}:(!_u(d)&&!_u(d.clientWidth)&&d.clientWidth!=0?{width:d.clientWidth,height:d.clientHeight}:{width:b.clientWidth,height:b.clientHeight}));};function _centerElement(el,cont)
{var container=cont||jQuery(window);var w=container.width();var h=container.height();var t=h/2-el.height()/2;var l=w/2-el.width()/2;if(t<0)t=0;if(l<0)l=0;el.css('top',t).css('left',l);};Cuke.apply(window.top.Cuke.Window,{defaults:{title:"",skin:"std",closeable:true,draggable:true,resizable:true,clone:false,center:true,show:true,modal:false,fixed:true,size:null,prefSize:[600,300],closeText:'',unloadOnHide:false,iframeOverlay:false,behaviours:Cuke.emptyFunction,afterDrop:Cuke.emptyFunction,afterShow:Cuke.emptyFunction,afterHide:Cuke.emptyFunction,beforeUnload:Cuke.emptyFunction,dragStart:Cuke.emptyFunction,dragStop:Cuke.emptyFunction,onClose:Cuke.emptyFunction,minContentWidth:150,minContentHeight:75,template:"<div class='wrap'><div class='window-title'><span class='title'></span></div>"+"<div class='window-inner'></div>"+"<div class='window-foot'></div></div>"},loadiframe:function(url,options,onload)
{options=options||{};var iframe=jQuery('<iframe src="'+url+'" frameborder="no" style="width:300px; height:1px;"></iframe>');var w=new Window(iframe,options);w.wrap.css('visibility','hidden');Cuke.Util.bindLoadEvent(iframe[0],function()
{if(onload)onload(w);var title,size;w.wrap.show();try
{var doc=iframe[0].contentDocument?iframe[0].contentDocument:iframe[0].contentWindow.document;if(w.userOptions&&w.userOptions.title)title=w.userOptions.title;else
{title=doc.title;}
if(w.userOptions&&w.userOptions.prefSize)size=w.userOptions.prefSize;else
{size=scrollSize(doc);}}
catch(e)
{title=w.options.title;size=w.options.prefSize;}
w.setTitle(title);w.wrap.css('visibility','visible');iframe.css('width','100%').css('height','100%');if(w.options.size!=null)size=w.options.size;if(w.options.show)w.show(size[0],size[1]);function scrollSize(doc)
{var width,height;width=doc.documentElement.scrollWidth;height=doc.documentElement.scrollHeight+20;if(Cuke.BrowserInfo.isIE)
{width=doc.body.scrollWidth;height=doc.body.scrollHeight;}
return[width,height];};});return w;},loadajax:function(url,options,onload)
{options=options||{};var w=new Window('<div></div>',options);var ajax={url:url,type:'GET',dataType:'html',cache:false,success:function(html)
{html=jQuery(html);w.setContent(html);if(onload)onload(w);if(w.options.show)w.show();}};jQuery.each(['type','cache'],function()
{if(this in options)
{ajax[this]=options[this];delete options[this];}});jQuery.ajax(ajax);return w;},loadhtml:function(content,options)
{options=options||{};var win=new Window(content,options);return win;},get:function(ele)
{var p=jQuery(ele).parents('.window-wrapper');return p.length?jQuery.data(p[0],'Window'):null;},alert:function(message,callback,options)
{return Cuke.Window.ask(message,['OK'],callback,options);},confirm:function(message,callback,options)
{return Cuke.Window.ask(message,['OK','Cancel'],function(response)
{if(response=='OK')callback();},options);},ask:function(message,answers,callback,options)
{options=jQuery.extend({modal:true,closeable:false,resizable:false},options||{},{show:true,unloadOnHide:true});var body=jQuery('<div></div>').append(jQuery('<div class="question"></div>').html(message));var map={},answerStrings=[];if(answers instanceof Array)
{for(var i=0;i<answers.length;i++)
{map[answers[i]]=answers[i];answerStrings.push(answers[i]);}}else
{for(var k in answers)
{map[answers[k]]=k;answerStrings.push(answers[k]);}}
var buttons=jQuery('<div class="answers"></div>');buttons.html(jQuery.map(answerStrings,function(v)
{return"<input type='button' value='"+v+"' />";}).join(' '));jQuery('input[type=button]',buttons).click(function()
{var clicked=this;Cuke.Window.get(this).hide(function()
{if(callback)callback(map[clicked.value]);});});if(!options.size&&!options.prefSize)options.size=[300,100];var w=new Window(body,options);w.show();if(jQuery('.window-foot',w.wrap).length>0)
{jQuery('.window-foot',w.wrap).append(buttons)}
else
{body.append(buttons);}}});var Static=Cuke.Window;function Window(element,options)
{var self=this;var _hasOverlay=false;var _dragConfigured=false;var _dragging=null;var _resizing=null;var _hiddenObjects=null;var _getBoundsForResize=function(width,height)
{var csize=self.getContentSize();var delta=[width-csize[0],height-csize[1]];var p=self.getPosition();return[Math.max(p[0]-delta[0]/2,0),Math.max(p[1]-delta[1]/2,0),width,height];};var _iframeOverlayRefresh=function()
{if(self.iframeOverlay)
{var size=self.getSize();self.iframeOverlay.css('width',size[0]).css('height',size[1]);}}
var _setupTitleBar=function()
{var tb=jQuery(".window-title",self.wrap);function hideIframe()
{$j('.window-content > iframe',self.wrap).css('visibility','hidden');};function showIframe()
{$j('.window-content > iframe',self.wrap).css('visibility','visible');};self.setTitle(self.options.title);if(self.options.closeable)
{tb.prepend(jQuery("<a href='' onclick='return false;' class='close'></a>").html(self.options.closeText));}
if(self.options.resizable||self.options.draggable)
{if(!self._dragConfigured)
{jQuery(document).mousemove(function(evt)
{var d;if(d=self._dragging)
{d[3]=evt.pageX-d[1];d[4]=evt.pageY-d[2];if(d[4]<0)d[4]=0;d[0].wrap.css({left:d[3],top:d[4]});}
if(d=self._resizing)
{d[3]=evt.pageX-d[1];d[4]=evt.pageY-d[2];if(d[3]<self.options.minContentWidth)d[3]=self.options.minContentWidth;if(d[4]<self.options.minContentHeight)d[4]=self.options.minContentHeight;d[0].getContent().css({width:d[3],height:d[4]});if(jQuery.browser.msie)
{_iframeOverlayRefresh();}}});jQuery(document).mouseup(function(evt)
{if(self._dragging)
{if(self.iframeContent)
{self.getContent().css({width:self.getContent().width()+1});self.getContent().css({width:self.getContent().width()-1});}
showIframe();self._dragging=null;jQuery(tb).removeClass('dragging');self.dispatchEvent('afterDrop');self.dispatchEvent('dragStop');}
if(self._resizing)
{if(self.iframeContent)
{self.getContent().css({width:self.getContent().width()+1});self.getContent().css({width:self.getContent().width()-1});}
showIframe();self._resizing=null;}});self._dragConfigured=true;}}
if(self.options.draggable)
{tb[0].onselectstart=function(){return false;}
tb[0].unselectable='on';tb[0].style.MozUserSelect='none';tb.mousedown(function(evt)
{hideIframe();self.bringToFront();self._dragging=[self,evt.pageX-self.wrap[0].offsetLeft,evt.pageY-self.wrap[0].offsetTop,0,0];jQuery(self).addClass('dragging');_clearSelection();self.dispatchEvent('dragStart');});}
if(self.options.resizable)
{self.wrap.append('<div class="window-resize"><div class="handle"></div></div>');jQuery('.window-resize .handle',self.wrap).mousedown(function(evt)
{evt.preventDefault();self.bringToFront();hideIframe();_clearSelection();self._resizing=[self,evt.pageX-self.getContent().width(),evt.pageY-self.getContent().height(),0,0];})}
_setupDefaultBehaviours(tb);};var _setupDefaultBehaviours=function(root)
{root.click(function(){self.bringToFront();});jQuery('.close',root).click(function()
{self.hide();self.dispatchEvent("onClose");return false;}).mousedown(function(evt){evt.stopPropagation();});};var _ensureSize=function(width,height)
{var wSize=self.getSize();var cSize=self.getContentSize();var size=[width,height];var v=_viewport();if(width>v.width)size[0]=v.width-(wSize[0]-cSize[0])-20;if(height>v.height)size[1]=v.height-(wSize[1]-cSize[1]);if(width<self.options.minContentWidth)size[0]=self.options.minContentWidth;if(width<self.options.minContentHeight)size[1]=self.options.minContentHeight;return size;};var _clearSelection=function()
{if(document.selection&&document.selection.empty)
{document.selection.empty();}else if(window.getSelection)
{var sel=window.getSelection();sel.removeAllRanges();}};var _getLoaderClass=function()
{return'window-loader-'+self.options.skin;}
var _getWrapperClass=function()
{return'window-wrapper-'+self.options.skin;}
var _getOverlayClass=function()
{return'window-modal-overlay-'+self.options.skin;}
var _handleResize=function(evt)
{var d=jQuery(document);jQuery('.'+_getOverlayClass()).css('display','none').css({width:d.width(),height:d.height()}).css('display','block');_centerElement(self.wrap);};var restoreTroubleshootingNodes=function()
{_hiddenObjects.css('visibility','visible');};var hideTroubleshootingNodes=function()
{var iframeContent;iframeContent=jQuery('iframe').contents().filter(function()
{try
{return(this.documentElement!=null||this.contentDocument!=null||(this.contentWindow!=null&&this.contentWindow.document!=null));}
catch(e)
{return false;}});var toHide=jQuery('embed').add('object');var iframeEmbed=jQuery('embed',iframeContent);var iframeObject=jQuery('object',iframeContent);toHide=toHide.add(iframeEmbed).add(iframeObject);toHide=toHide.not(jQuery('embed',self.wrap)).not(jQuery('object',self.wrap));toHide=toHide.filter(function(idx)
{if($j(this).attr('wmode')=='window'||$j(this).attr('wmode')=='Window')return true;return false;});if(jQuery.browser.msie&&Cuke.Text.startsWith(jQuery.browser.version,"6"))
{toHide=toHide.add('select').add(jQuery('select',iframeContent)).not(jQuery('select',self.wrap));}
toHide=toHide.filter(function(idx)
{if($j(this).css('visibility')=='hidden')return false;return true;});_hiddenObjects=toHide.css('visibility','hidden');};this.estimateSize=function()
{this.wrap.css({visibility:'hidden',display:'block'});var dims=this.getSize();this.wrap.css('display','none').css('visibility','visible');return dims;};this.getSize=function()
{return[this.wrap.width(),this.wrap.height()];};this.getContentSize=function()
{var c=this.getContent();return[c.width(),c.height()];};this.getPosition=function()
{var b=this.wrap[0];return[b.offsetLeft,b.offsetTop];};this.getCenter=function()
{var p=this.getPosition();var s=this.getSize();return[Math.floor(p[0]+s[0]/2),Math.floor(p[1]+s[1]/2)];};this.getInner=function()
{return jQuery('.window-inner',this.wrap);};this.getContent=function()
{return jQuery('.window-content',this.wrap);};this.setContent=function(newContent)
{if(!newContent)newContent="<div></div>";newContent=jQuery(newContent);if(this.options.clone)newContent=newContent.clone(true);var wrap=jQuery("<div class='window-content' style='display:block;'></div>");this.getContent().remove();this.getInner().append(wrap.append(newContent));_setupDefaultBehaviours(newContent);this.options.behaviours.call(this,newContent);return this;};this.move=function(x,y)
{if(x)this.wrap.css('left',x);if(y)this.wrap.css('top',y);return this;};this.centerAt=function(x,y)
{var s=this[this.visible?'getSize':'estimateSize']();if(typeof x=='number')this.move(x-s[0]/2,null);if(typeof y=='number')this.move(null,y-s[1]/2);return this;};this.centerAtX=function(x)
{return this.centerAt(x,null);};this.centerAtY=function(y)
{return this.centerAt(null,y);};this.center=function(axis)
{var v=_viewport();var o=this.options.fixed?[0,0]:[v.left,v.top];if(!axis||axis=='x')this.centerAt(o[0]+v.width/2,null);if(!axis||axis=='y')this.centerAt(null,o[1]+v.height/2);return this;};this.resize=function(width,height,after)
{if(!this.visible)return;var bounds=_getBoundsForResize(width,height);var size=_ensureSize(bounds[2],bounds[3]);this.wrap.css({left:bounds[0],top:bounds[1]});this.getContent().css({width:size[0],height:size[1]});this.getContent().css('overflow','hidden').css('overflow','auto');_centerElement(this.wrap);if(jQuery.browser.msie)_iframeOverlayRefresh();if(after)after(this);return this;};this.isModalVisible=function()
{return jQuery('.'+_getOverlayClass()).length>0;};this.showLoader=function()
{var loader=jQuery('<div class="'+_getLoaderClass()+'"><span class="window-msg">'+Cuke.getString('Cuke.Loading')+'</span></div>').css('z-index',_nextZ()).appendTo(document.body);if(this.options.fixed)loader.css('position','fixed');else loader.css('position','absolute');_centerElement(loader);return self;};this.hideLoader=function()
{jQuery('.'+_getLoaderClass()).remove();return self;};this.isLoaderVisible=function()
{return jQuery('.'+_getLoaderClass()).length>0;};this.tween=function(width,height,after)
{if(!this.visible)return;var self=this;var bounds=_getBoundsForResize(width,height);this.wrap.stop().animate({left:bounds[0],top:bounds[1]});this.getContent().stop().animate({width:bounds[2],height:bounds[3]},function()
{if(after)after(self);});return this;};this.isVisible=function()
{return this.visible;},this.setOverlay=function()
{if(!_hasOverlay)
{if(!_resizeConfigured)
{_resizeConfigured=true;jQuery(window).resize(function(){_handleResize();});}
this.modalOverlay=jQuery('<div class="'+_getOverlayClass()+'"></div>').css('position','absolute').css('top',0).css('left',0).css('z-index',_nextZ()).css('opacity',0.3).css('width',jQuery(document).width()).css('height',jQuery(document).height());if(false)
{this.modalOverlay.append(jQuery('<iframe frameborder="no" style="display: block; position: absolute; top: 0pt; left: 0pt; width: 100%; height: 100%; z-index: 0;"/>'));this.modalOverlay.append(jQuery('<div style="background-color:black; display: block; position: absolute; top: 0pt; left: 0pt; width: 100%; height: 100%; z-index: 1;"/>'));this.modalOverlay[0].onselectstart=function(){return false;};}
jQuery(document.body).append(this.modalOverlay);hideTroubleshootingNodes();_hasOverlay=true;}};this.preshow=function()
{var self=this;if(this.visible)return;if(this.options.modal)
{self.setOverlay();self.showLoader();}};this.show=function(width,height)
{var self=this;if(this.visible)return;if(this.options.modal)this.setOverlay();if(self.isLoaderVisible())self.hideLoader();this.bringToFront();if(this.options.closeable)
{jQuery(document.body).bind('keypress.window',function(evt)
{var key=evt.which||evt.keyCode;if(key==27)
{self.hide();jQuery(document.body).unbind('keypress.window');}});}
if(!width||!height)
{if(self.options.size)
{width=self.options.size[0];height=self.options.size[1];}
else if(self.options.prefSize)
{width=self.options.prefSize[0];height=self.options.prefSize[1];}
else
{width=400;height=250;}}
this.wrap.show();this.visible=true;self.resize(width,height);this.dispatchEvent('afterShow');return this;};this.hide=function(after)
{if(!this.visible)return;var self=this;if(this.options.modal)
{jQuery(document.body).unbind('keypress.window');self.modalOverlay.remove();_hasOverlay=false;restoreTroubleshootingNodes();}
self.wrap.css({display:'none'});self.visible=false;self.dispatchEvent('afterHide');if(after)after(self);if(self.options.unloadOnHide)self.unload();return this;};this.toggle=function()
{this[this.visible?'hide':'show']();return this;};this.hideAndUnload=function(after)
{this.options.unloadOnHide=true;this.hide(after);return this;};this.unload=function()
{this.dispatchEvent('beforeUnload');this.wrap.remove();};this.bringToFront=function()
{this.wrap.css({zIndex:_nextZ()});return this;};this.getTitle=function()
{return jQuery('.window-title .title',this.wrap).html();};this.setTitle=function(t)
{jQuery('.window-title .title',this.wrap).html(t);return this;};this.dispatchEvent=function(event)
{var e=this.options[event];if(e)e.call(this);};this.visible=false;this.userOptions=options;this.options=jQuery.extend({},Static.defaults,options||{});this.iframeContent=jQuery('iframe',jQuery(element)).length>0;this.wrap=jQuery("<div class='"+_getWrapperClass()+" window-wrapper'>"+this.options.template+"</div>");jQuery.data(this.wrap[0],'Window',this);this.setContent(element);_setupTitleBar();this.wrap.css('display','none').appendTo(document.body);this.bringToFront();if(this.options.fixed)
{if(jQuery.browser.msie&&jQuery.browser.version<7)
{this.options.fixed=false;this.wrap.css('position','absolute');}
else
{this.wrap.css('position','fixed');}}
if(this.options.center&&_u(this.options.x,this.options.y))
{this.center();}
else
{this.move(_u(this.options.x)?this.options.x:Static.DEFAULT_X,_u(this.options.y)?this.options.y:Static.DEFAULT_Y);}
if(this.options.show)this.preshow();};};})();
