function WindowDivMgr(id,removeWinDivOnClose,currOverlay){this.id=id;this.winDiv=$('#'+id);this.isWinDivOpen=false;this.removeWinDivOnClose=removeWinDivOnClose||false;this.lastScrollTop=$(window).scrollTop();this.currOverlay=currOverlay;this.centerWin=function(){var winObj=$(window);var winW=winObj.width();var winH=winObj.height();var scrollTop=winObj.scrollTop();var div=this.winDiv;div.css('position','absolute');var divH=div.outerHeight()||div.height()||div.children().outerHeight()||div.children().height();var divW=div.outerWidth()||div.width()||div.children().outerWidth()||div.children().width();var divLeft=(winW/2)-(divW/2);if(divLeft<0)
divLeft=0;var divTop=(winH/2)-(divH/2)+scrollTop;if((divTop<scrollTop)||(divTop>scrollTop+winH))
divTop=scrollTop;div.css({'left':divLeft+'px','top':divTop+'px'});};this.openWin=function(callback){if(this.isWinDivOpen){if(callback)
callback.call();return;}
var that=this;this.centerWin();this.winDiv.fadeIn('fast',function(){if(callback)
callback.call();});this.isWinDivOpen=true;};this.closeWin=function(callback){if(!this.isWinDivOpen){if(callback)
callback.call();return;}
var that=this;this.winDiv.fadeOut('fast',function(){if(that.removeWinDivOnClose)
that.winDiv.remove();that.isWinDivOpen=false;if(callback)
callback.call();});};this.replaceWinHtml=function(html,callback){var that=this;this.winDiv.fadeOut('fast',function(){that.winDiv.html(html);that.centerWin();that.winDiv.fadeIn('fast',function(){if(callback)
callback.call();});});};this.replaceWinDiv=function(id,callback){var that=this;this.winDiv.fadeOut('fast',function(){that.id=id;that.winDiv=$('#'+id);that.centerWin();that.winDiv.fadeIn('fast',function(){if(callback)
callback.call();});});};}
function OverlayDivMgr(){this.isOverlayDivOpen=false;this.overlayZIndex=5000;this.overlayDiv;this.openOverlay=function(callback){if(this.isOverlayDivOpen){this.overlayDiv.css({'filter':'alpha(opacity=50)','opacity':'0.5'});if(callback)
callback.call();return;}
this.overlayDiv=$('<div></div>');this.overlayDiv.css({'display':'none','background-color':'#666666','filter':'alpha(opacity=50)','opacity':'0.5','z-index':this.overlayZIndex,'left':'0px','top':'0px'});if(checkIEVer()==6){this.overlayDiv.css({'position':'absolute','width':$(document).width()*2,'height':$(document).height()*2});}else{this.overlayDiv.css({'position':'fixed','width':'100%','height':'100%'});}
this.overlayDiv.appendTo($('body'));this.overlayDiv.fadeIn('fast',function(){if(callback)
callback.call();});this.isOverlayDivOpen=true;};this.closeOverlay=function(callback){if(!this.isOverlayDivOpen){if(callback)
callback.call();return;}
var that=this;this.overlayDiv.fadeOut('fast',function(){that.overlayDiv.remove();that.isOverlayDivOpen=false;that.overlayDiv=undefined;if(callback)
callback.call();});};}
function _overlayWindow(){this.winStack=[];this.currOverlay=new OverlayDivMgr();this.zIndexUnder=function(){return this.currOverlay.overlayZIndex-1;};this.zIndexOver=function(){return this.currOverlay.overlayZIndex+1;};this.showDiv=function(options,callback){if(options.id==undefined){options['id']='_overlayWindow_'+this.winStack.length;options['removeWinDivOnClose']=true;$('<div id="'+options.id+'"></div>').appendTo($('body'));}
var that=this;var newWin=new WindowDivMgr(options.id,options.removeWinDivOnClose,this.currOverlay);this.currOverlay.openOverlay(function(){if(options.url!=undefined){$.ajax({url:options.url,data:options.data,type:"POST",cache:false,async:false,success:function(msg){newWin.winDiv.html(msg);that.openDiv(newWin,callback);that.currOverlay.openOverlay();},error:function(XMLHttpRequest,textStatus,errorThrown){newWin.winDiv.html('<table width="550" border="0" cellspacing="0" cellpadding="0">'+'<tr><td align="right"><a href="javascript: overlayWindow.closeDiv()"><img src="/resources/valspar/img/btn_viewCloseWin.png"></a></td></tr>'+'<tr><td>'+textStatus+'</td></tr>');that.openDiv(newWin,callback);that.currOverlay.openOverlay();}});}else{that.openDiv(newWin,callback);that.currOverlay.openOverlay();}});};this.replaceDiv=function(options,callback){if(this.winStack.length===0){return;}
var currWin=this.winStack[this.winStack.length-1];if(currWin==undefined){return;}
var that=this;currWin.winDiv.fadeOut('fast',function(){if(options.url!=undefined){$.ajax({url:options.url,data:options.data,type:"POST",cache:false,async:false,success:function(msg){currWin.replaceWinHtml(msg,callback);that.currOverlay.openOverlay();},error:function(XMLHttpRequest,textStatus,errorThrown){currWin.replaceWinHtml('<table width="550" border="0" cellspacing="0" cellpadding="0">'+'<tr><td align="right"><a href="javascript: overlayWindow.closeDiv()"><img src="/resources/valspar/img/btn_viewCloseWin.png"></a></td></tr>'+'<tr><td>'+textStatus+'</td></tr>',callback);that.currOverlay.openOverlay();}});}else if(options.id!=undefined){currWin.replaceWinDiv(options.id,callback);that.currOverlay.openOverlay();}});};this.openDiv=function(newWin,callback){if(this.winStack.length>0){var prevWin=this.winStack[this.winStack.length-1];prevWin.lastScrollTop=$(window).scrollTop();prevWin.winDiv.css('z-index',this.zIndexUnder());}
newWin.winDiv.css('z-index',this.zIndexOver());newWin.openWin(callback);this.winStack.push(newWin);};this.closeDiv=function(callback){var that=this;var currWin=this.winStack.pop();if(currWin!=undefined){currWin.closeWin(function(){if(that.winStack.length===0){that.currOverlay.closeOverlay();}else{var prevWin=that.winStack[that.winStack.length-1];$(window).scrollTop(prevWin.lastScrollTop);prevWin.winDiv.css('z-index',that.zIndexOver());}
if(callback!=undefined)
callback.call();});}};}
var overlayWindow=new _overlayWindow();
