(function(a){a.fn.closeDOMWindow=function(b){if(!b){b={}}var c=function(d){if(b.anchoredClassName){var f=a("."+b.anchoredClassName);f.fadeOut("fast",function(){if(a.fn.draggable){f.draggable("destory").trigger("unload").remove()}else{f.trigger("unload").remove()}});if(b.functionCallOnClose){b.functionCallAfterClose()}}else{var e=a("#DOMWindowOverlay");var g=a("#DOMWindow");e.fadeOut("fast",function(){e.trigger("unload").unbind().remove()});g.fadeOut("fast",function(){if(a.fn.draggable){g.draggable("destroy").trigger("unload").remove()}else{g.trigger("unload").remove()}});a(window).unbind("scroll.DOMWindow");a(window).unbind("resize.DOMWindow");if(a.fn.openDOMWindow.isIE6){a("#DOMWindowIE6FixIframe").remove()}if(b.functionCallOnClose){b.functionCallAfterClose()}}};if(b.eventType){return this.each(function(d){a(this).bind(b.eventType,function(){c(this);return false})})}else{c()}};a.closeDOMWindow=function(b){a.fn.closeDOMWindow(b)};a.fn.openDOMWindow=function(c){var f=a.fn.openDOMWindow;f.defaultsSettings={anchoredClassName:"",anchoredSelector:"",borderColor:"",borderSize:"",draggable:0,eventType:null,fixedWindowY:100,functionCallOnOpen:null,functionCallOnClose:null,height:392,loader:0,loaderHeight:0,loaderImagePath:"",loaderWidth:0,modal:0,overlay:1,overlayColor:"#000",overlayOpacity:"40",positionLeft:0,positionTop:0,positionType:"centered",width:893,windowBGColor:"",windowBGImage:base_url+"assets/public/images/dialog-bg.png",windowHTTPType:"get",windowPadding:0,windowSource:"inline",windowSourceID:"",windowSourceURL:"",windowSourceAttrURL:"href"};var e=a.extend({},a.fn.openDOMWindow.defaultsSettings,c||{});f.viewPortHeight=function(){return self.innerHeight||document.documentElement.clientHeight||document.body.clientHeight};f.viewPortWidth=function(){return self.innerWidth||document.documentElement.clientWidth||document.body.clientWidth};f.scrollOffsetHeight=function(){return self.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop};f.scrollOffsetWidth=function(){return self.pageXOffset||document.documentElement.scrollLeft||document.body.scrollLeft};f.isIE6=typeof document.body.style.maxHeight==="undefined";var j=function(){var n=a("#DOMWindowOverlay");if(f.isIE6){var o=document.documentElement.offsetHeight+document.documentElement.scrollTop-4;var m=document.documentElement.offsetWidth-21;n.css({height:o+"px",width:m+"px"})}else{n.css({height:"100%",width:"100%",position:"fixed"})}};var h=function(){var n=document.documentElement.offsetHeight+document.documentElement.scrollTop-4;var m=document.documentElement.offsetWidth-21;a("#DOMWindowIE6FixIframe").css({height:n+"px",width:m+"px"})};var k=function(){var m=a("#DOMWindow");if(e.height+50>f.viewPortHeight()){m.css("left",Math.round(f.viewPortWidth()/2)+f.scrollOffsetWidth()-Math.round((m.outerWidth())/2))}else{m.css("left",Math.round(f.viewPortWidth()/2)+f.scrollOffsetWidth()-Math.round((m.outerWidth())/2));m.css("top",Math.round(f.viewPortHeight()/2)+f.scrollOffsetHeight()-Math.round((m.outerHeight())/2))}};var b=function(){var m=a("#DOMWindowLoader");if(f.isIE6){m.css({left:Math.round(f.viewPortWidth()/2)+f.scrollOffsetWidth()-Math.round((m.innerWidth())/2),position:"absolute"});m.css({top:Math.round(f.viewPortHeight()/2)+f.scrollOffsetHeight()-Math.round((m.innerHeight())/2),position:"absolute"})}else{m.css({left:"50%",top:"50%",position:"fixed"})}};var l=function(){var m=a("#DOMWindow");m.css("left",e.positionLeft+f.scrollOffsetWidth());m.css("top",+e.positionTop+f.scrollOffsetHeight())};var i=function(m){if(arguments[0]){a("."+m+" #DOMWindowLoader").remove();a("."+m+" #DOMWindowContent").fadeIn("fast",function(){if(e.functionCallOnOpen){e.functionCallOnOpen()}});a("."+m+".closeDOMWindow").click(function(){a.closeDOMWindow();return false})}else{a("#DOMWindowLoader").remove();a("#DOMWindow").fadeIn("fast",function(){if(e.functionCallOnOpen){e.functionCallOnOpen()}});a("#DOMWindow .closeDOMWindow").click(function(){a.closeDOMWindow();return false})}};var g=function(m){var n={};m.replace(/b([^&=]*)=([^&=]*)b/g,function(o,p,q){if(typeof n[p]!="undefined"){n[p]+=","+q}else{n[p]=q}});return n};var d=function(n){e.windowSourceID=a(n).attr("href")||e.windowSourceID;e.windowSourceURL=a(n).attr(e.windowSourceAttrURL)||e.windowSourceURL;e.windowBGImage=e.windowBGImage?"background-image:url("+e.windowBGImage+")":"";var s,q;if(e.positionType=="anchored"){var r=a(e.anchoredSelector).position();var o=r.left+e.positionLeft;var m=r.top+e.positionTop;a("body").append('<div class="'+e.anchoredClassName+'" style="'+e.windowBGImage+";background-repeat:no-repeat;padding:"+e.windowPadding+"px;overflow:auto;position:absolute;top:"+m+"px;left:"+o+"px;height:"+e.height+"px;width:"+e.width+"px;background-color:"+e.windowBGColor+";border:"+e.borderSize+"px solid "+e.borderColor+';z-index:10001"><div id="DOMWindowContent" style="display:none"></div></div>');if(e.loader&&e.loaderImagePath!==""){a("."+e.anchoredClassName).append('<div id="DOMWindowLoader" style="width:'+e.loaderWidth+"px;height:"+e.loaderHeight+'px;"><img src="'+e.loaderImagePath+'" /></div>')}if(a.fn.draggable){if(e.draggable){a("."+e.anchoredClassName).draggable({cursor:"move"})}}switch(e.windowSource){case"inline":a("."+e.anchoredClassName+" #DOMWindowContent").append(a(e.windowSourceID).children());a("."+e.anchoredClassName).unload(function(){a("."+e.windowSourceID).append(a("."+e.anchoredClassName+" #DOMWindowContent").children())});i(e.anchoredClassName);break;case"iframe":a("."+e.anchoredClassName+" #DOMWindowContent").append('<iframe frameborder="0" hspace="0" wspace="0" src="'+e.windowSourceURL+'" name="DOMWindowIframe'+Math.round(Math.random()*1000)+'" style="width:100%;height:100%;border:none;background-color:#fff;" class="'+e.anchoredClassName+'Iframe" ></iframe>');a("."+e.anchoredClassName+"Iframe").load(i(e.anchoredClassName));break;case"ajax":if(e.windowHTTPType=="post"){if(e.windowSourceURL.indexOf("?")!==-1){s=e.windowSourceURL.substr(0,e.windowSourceURL.indexOf("?"));q=g(e.windowSourceURL)}else{s=e.windowSourceURL;q={}}a("."+e.anchoredClassName+" #DOMWindowContent").load(s,q,function(){i(e.anchoredClassName)})}else{if(e.windowSourceURL.indexOf("?")==-1){e.windowSourceURL+="?"}a("."+e.anchoredClassName+" #DOMWindowContent").load(e.windowSourceURL+"&random="+(new Date().getTime()),function(){i(e.anchoredClassName)})}break}}else{if(e.overlay){a("body").append('<div id="DOMWindowOverlay" style="z-index:10000;display:none;position:absolute;top:0;left:0;background-color:'+e.overlayColor+";filter:alpha(opacity="+e.overlayOpacity+");-moz-opacity: 0."+e.overlayOpacity+";opacity: 0."+e.overlayOpacity+';"></div>');if(f.isIE6){a("body").append('<iframe id="DOMWindowIE6FixIframe"  src="blank.html"  style="width:100%;height:100%;z-index:9999;position:absolute;top:0;left:0;filter:alpha(opacity=0);"></iframe>');h()}j();var p=a("#DOMWindowOverlay");p.fadeIn("fast");if(!e.modal){p.click(function(){a.closeDOMWindow()})}}if(e.loader&&e.loaderImagePath!==""){a("body").append('<div id="DOMWindowLoader" style="z-index:10002;width:'+e.loaderWidth+"px;height:"+e.loaderHeight+'px;"><img src="'+e.loaderImagePath+'" /></div>');b()}a("body").append('<div id="DOMWindow" style="background-repeat:no-repeat;'+e.windowBGImage+";overflow:auto;padding:"+e.windowPadding+"px;display:none;height:"+e.height+"px;width:"+e.width+"px;background-color:"+e.windowBGColor+";border:"+e.borderSize+"px solid "+e.borderColor+'; position:absolute;z-index:10001"></div>');var t=a("#DOMWindow");switch(e.positionType){case"centered":k();if(e.height+50>f.viewPortHeight()){t.css("top",(e.fixedWindowY+f.scrollOffsetHeight())+"px")}break;case"absolute":t.css({top:(e.positionTop+f.scrollOffsetHeight())+"px",left:(e.positionLeft+f.scrollOffsetWidth())+"px"});if(a.fn.draggable){if(e.draggable){t.draggable({cursor:"move"})}}break;case"fixed":l();break;case"anchoredSingleWindow":var r=a(e.anchoredSelector).position();var o=r.left+e.positionLeft;var m=r.top+e.positionTop;t.css({top:m+"px",left:o+"px"});break}a(window).bind("scroll.DOMWindow",function(){if(e.overlay){j()}if(f.isIE6){h()}if(e.positionType=="centered"){k()}if(e.positionType=="fixed"){l()}});a(window).bind("resize.DOMWindow",function(){if(f.isIE6){h()}if(e.overlay){j()}if(e.positionType=="centered"){k()}});switch(e.windowSource){case"inline":t.append(a(e.windowSourceID).children());t.unload(function(){a(e.windowSourceID).append(t.children())});i();break;case"iframe":t.append('<iframe frameborder="0" hspace="0" wspace="0" src="'+e.windowSourceURL+'" name="DOMWindowIframe'+Math.round(Math.random()*1000)+'" style="width:100%;height:100%;border:none;background-color:#fff;" id="DOMWindowIframe" ></iframe>');a("#DOMWindowIframe").load(i());break;case"ajax":if(e.windowHTTPType=="post"){if(e.windowSourceURL.indexOf("?")!==-1){s=e.windowSourceURL.substr(0,e.windowSourceURL.indexOf("?"));q=g(e.windowSourceURL)}else{s=e.windowSourceURL;q={}}t.load(s,q,function(){i()})}else{if(e.windowSourceURL.indexOf("?")==-1){e.windowSourceURL+="?"}t.load(e.windowSourceURL+"&random="+(new Date().getTime()),function(){i()})}break}}};if(e.eventType){return this.each(function(m){a(this).bind(e.eventType,function(){d(this);return false})})}else{d()}};a.openDOMWindow=function(b){a.fn.openDOMWindow(b)}})(jQuery);
