function GenerateURLCache(url){ if((typeof url)=="string"){ var sep = ""; if(url.indexOf("&")>-1) sep = "&"; else if(url.indexOf("&")>-1) sep = "&"; else if(url.indexOf("?")>-1) sep = "&"; else sep = "?"; return url+sep+"r="+(new Date().getTime()); } else return "r="+(new Date().getTime()); } function TriggerClosePopup(e){ var CloseLink = $('LinkPPBg'); if($defined(CloseLink)) CloseLink.fireEvent('click', e); } function CloseHidePopup(animation, fn){ try{ $('LinkPPBg').removeEvents('click'); $('LinkPPNoTrans').removeEvents('click'); // just to make sure the user doesnt click this again $('DivPPCCFrame').setStyle('visibility','hidden').empty(); $('DivPPCloseBtnContainer').destroy(); var RemoveElements = function(){ $('DivPPCCFrame').destroy(); $('LinkPPBg').destroy(); $('LinkPPNoTrans').destroy(); }; if(animation) new Fx.Tween($('DivPPBg'), { property:'opacity', duration: 500, onComplete: function(){ $('DivPPBg').setStyle('visibility','hidden'); fn(); RemoveElements(); } }).start(0); else { $('DivPPBg').setStyle('visibility','hidden'); fn(); RemoveElements(); } } catch(e){} } function OpenShowPopup(fnStart, page, fnHide, fnAfterLoad, fnWaitTillComplete, popupType){ page = GenerateURLCache(page); if(!$chk(popupType)) popupType = ""; if(!$chk($('DivPPContentContainer'))){ var winsize = window.getSize(); new Element('a', {'id': 'LinkPPNoTrans', 'href':'#'}).inject($('DocumentBody')); new Element('a', {'id': 'LinkPPBg', 'href':'#'}).inject($('DocumentBody')); new Element('div', {'id': 'DivPPBg', 'styles':{'width':'100%', 'height':winsize.y, 'position':'absolute', 'background':'#000', 'top':0, 'left':0, 'visibility':'hidden'}}).inject($('LinkPPBg')); var PPCCFrame = new Element('div', {'id': 'DivPPCCFrame', 'styles':{'position':'absolute', 'width':'270px', 'height':'100px', 'top':'50%', 'left':'50%', 'visibility':'hidden', 'margin':'-58px 0 0 -135px'}}).inject($('DocumentBody')); var PPTopBorder = new Element('div', {'id': 'DivPPTopBorder', 'styles': {'height':'6px', 'width':'100%', 'line-height':'4px', 'background':((popupType=="")?'#fff':'#666'), 'margin':'0 8px', 'position':'relative', 'border-top':'2px solid '+((popupType=="")?'#39f':'#fff')}}).inject(PPCCFrame); new Element('img', {'src':'/img/popup_ajax'+popupType+'/border_corner_1.gif', 'styles':{'width':'8px', 'height':'8px'}}).inject(new Element('div', {'styles': {'width':'8px', 'height':'8px', 'position':'absolute', 'float':'left', 'left':'-8px', 'top':'-2px'}}).inject(PPTopBorder)); new Element('img', {'src':'/img/popup_ajax'+popupType+'/border_corner_2.gif', 'styles':{'width':'8px', 'height':'8px'}}).inject(new Element('div', {'styles': {'width':'8px', 'height':'8px', 'position':'absolute', 'float':'right', 'right':'-8px', 'top':'-2px'}}).inject(PPTopBorder)); new Element('div', {'id': 'DivPPContentContainer'}).inject(PPCCFrame); $('DivPPContentContainer').setStyles({ 'width': '100%', 'height': '100%', 'position': 'relative', 'background': ((popupType=="")?'#fff':'#666'), 'overflow':'hidden', 'padding':'0 6px', 'border':'2px solid '+((popupType=="")?'#39f':'#fff'), 'border-width':'0 2px' }); var PPBottomBorder = new Element('div', {'id': 'DivPPBottomBorder', 'styles': {'height':'6px', 'width':'100%', 'line-height':'4px', 'background':((popupType=="")?'#fff':'#666'), 'margin':'0 8px', 'position':'relative', 'border-bottom':'2px solid '+((popupType=="")?'#39f':'#fff')}}).inject(PPCCFrame); new Element('img', {'src':'/img/popup_ajax'+popupType+'/border_corner_4.gif', 'styles':{'width':'8px', 'height':'8px'}}).inject(new Element('div', {'styles': {'width':'8px', 'height':'8px', 'position':'absolute', 'float':'left', 'left':'-8px'}}).inject(PPBottomBorder)); new Element('img', {'src':'/img/popup_ajax'+popupType+'/border_corner_3.gif', 'styles':{'width':'8px', 'height':'8px'}}).inject(new Element('div', {'styles': {'width':'8px', 'height':'8px', 'position':'absolute', 'float':'right', 'right':'-8px'}}).inject(PPBottomBorder)); } else { $('DivPPContentContainer').empty().setStyle('visibility','visible'); $('DivPPCloseBtnContainer').destroy(); } $('LinkPPBg').removeEvents('click').addEvent('click', function(e){ StopBubblingEvent(e); });; $('LinkPPNoTrans').removeEvents('click').addEvent('click', function(e){ StopBubblingEvent(e); });; var OpacityComplete = function(){ $('DivPPCCFrame').setStyle('visibility','visible'); new Element('img', {'src':'/img/popup_ajax'+popupType+'/loading.gif', 'styles':{'width':'16px', 'height':'16px', 'margin-right':'6px', 'vertical-align':'middle'}}).inject(new Element('div', {'id':'DivPPLoadingContainer', 'html':'Aguarde... Carregando...', 'styles':{ 'position':'absolute', 'width':'200px', 'height':'20px', 'text-align':'center', 'font-weight':'bold', 'top':'50%', 'left':'50%', 'margin':'-6px 0 0 -100px', 'color':((popupType=="")?'#666':'#fff') }}).inject($('DivPPContentContainer')), 'top'); new Request.HTML({url:page, update:$('DivPPContentContainer'), onComplete: function(){ if($defined(fnWaitTillComplete)){ new Element('img', {'src':'/img/popup_ajax'+popupType+'/loading.gif', 'styles':{'width':'16px', 'height':'16px', 'margin-right':'6px', 'vertical-align':'middle'}}).inject(new Element('div', {'id':'DivPPLoadingContainer', 'html':'Aguarde... Carregando...', 'styles':{ 'position':'absolute', 'width':'200px', 'height':'20px', 'text-align':'center', 'font-weight':'bold', 'top':'50%', 'left':'50%', 'margin':'-6px 0 0 -100px', 'color':((popupType=="")?'#666':'#fff') }}).inject($('DivPPContentContainer')), 'top'); fnWaitTillComplete(ResizeWidth); } else ResizeWidth(); }}).get(); fnStart(); }; var ResizeWidth = function(){ if($chk($('DivPPLoadingContainer'))) $('DivPPLoadingContainer').setStyle('visibility','hidden'); new Fx.Morph($('DivPPCCFrame'), {duration:500, onComplete: ResizeHeight}).start({ 'width': $('DivPPContent').getSize().x, 'margin-left': parseInt($('DivPPCCFrame').getStyle('margin-left'))-parseInt(($('DivPPContent').getSize().x-$('DivPPTopBorder').getSize().x)/2) }); }; var ResizeHeight = function(){ new Fx.Morph($('DivPPCCFrame'), {duration:500, onComplete: AppearContent}).start({ 'height': $('DivPPContent').getSize().y, 'margin-top': parseInt($('DivPPCCFrame').getStyle('margin-top'))-parseInt(($('DivPPContent').getSize().y-$('DivPPContentContainer').getSize().y)/2) }); }; var AppearContent = function(){ new Element('img', {'src':'/img/popup_ajax/btn_close.gif', 'styles': {'width':'21px', 'height':'21px'}}).inject(new Element('a', {'href':'#'}).inject(new Element('div', {'id': 'DivPPCloseBtnContainer', 'styles':{'width':'21px', 'height':'21px', 'position':'absolute', 'top':'50%', 'left':'50%', 'margin':(parseInt($('DivPPCCFrame').getStyle('margin-top'))-22)+"px 0 0 "+(-parseInt($('DivPPCCFrame').getStyle('margin-left'))+16)+"px"}}).inject($('DocumentBody'))).addEvent('click', function(e){ TriggerClosePopup(e); })); new Fx.Tween($('DivPPContent'), { property:'opacity', duration: 700, onComplete: function(){ $('LinkPPBg').addEvent('click', function(){ CloseHidePopup(true, fnHide ); }); $('LinkPPNoTrans').addEvent('click', function(){ CloseHidePopup(false, fnHide ); }); fnAfterLoad(); }}).set(0).start(1); }; if($('DivPPBg').getStyle('visibility')=="hidden"){ new Fx.Tween($('DivPPBg'), { property:'opacity', duration: 500, onComplete: function(){ OpacityComplete(); }}).set(0).start(0.7); } else OpacityComplete(); }