var bSlotsInitialized=false;var availableSlots=10;var slots;var commonOfferWindowFeatures='toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes,alwaysraised=true';var currentSlotIndex=0;var bSingleMode=false;var currentOfferIndex=null;var openPopups=null;function Slot(lx,ly,lw,lh){this.x=lx;this.y=ly;this.w=lw;this.h=lh}function initSlots(){var nW=525;var nH=460;var nXI=24;var nYI=24;var nX=205;var nY=5;if(screen.width>=1024){nW=970;nH=600;nXI=80;nYI=40}else if(screen.width>=800){nW=780;nH=500;nXI=60;nYI=30}slots=new Object();for(var i=0;i<availableSlots;i++){slots[i]=new Slot(nX,nY,nW,nH);nX=nX+nXI;nY=nY+nYI}bSlotsInitialized=true}function getNextSlot(){if(!bSlotsInitialized){initSlots()}if(currentSlotIndex>(availableSlots-2)){currentSlotIndex=0}return slots[currentSlotIndex++]}function displayOffers(){try{if(bSingleMode){popNextOfferWindow(currentOfferIndex)}else{popAllOfferWindows()}}catch(e){resetPopupMode()}return false}function changeToSinglePopupMode(){if(!bSingleMode){bSingleMode=true;window.focus();$("#checkOffersImg").attr({src:"/s/img/check-next-offer.png",width:"144"});var quickCheckMessageArea=$("#quickCheckMessageArea");quickCheckMessageArea.attr("innerHTML","Pop-up blocker detected!<br/>Click <strong>Check Next Offer</strong> to open the next offer in a separate window.");quickCheckMessageArea.highlightFade();quickCheckMessageArea.css({border:"1px solid rgb(238, 202, 110)","text-align":"center"})}}function resetPopupMode(){if(bSingleMode){bSingleMode=false;currentOfferIndex=null}}function popAllOfferWindows(){var numChecked=0;var offerCheckboxes=document.getElementsByName("offerQuickCheckCheckbox");for(var i=0;i<offerCheckboxes.length;i++){var offerCheckbox=offerCheckboxes[i];if(offerCheckbox.checked){numChecked++;var popup=popWindow(offerCheckbox.id,offerCheckbox.value);if(popup!=null){rememberPopup(popup)}else{changeToSinglePopupMode();currentOfferIndex=i;break}}}if(!bSingleMode){forgetPopups()}if(offerCheckboxes.length>0&&numChecked==0){alert("Please select at least one merchant from the list.");return false}return true}function popNextOfferWindow(startingIndex){var offerCheckboxes=document.getElementsByName("offerQuickCheckCheckbox");var popup=null;if(startingIndex==null){startingIndex=0}for(var i=startingIndex;i<offerCheckboxes.length;i++){var offerCheckbox=offerCheckboxes[i];if(offerCheckbox.checked){if(popup==null){currentOfferIndex=i+1;popup=popWindow(offerCheckbox.id,offerCheckbox.value)}else{rememberPopup(popup);window.focus();return}}}focusPopups();resetPopupMode()}function rememberPopup(popup){if(openPopups==null){openPopups=new Array()}openPopups.push(popup)}function focusPopups(){if(openPopups!=null){for(var i=openPopups.length;i>=1;){try{openPopups[--i].focus()}catch(e){}}forgetPopups()}}function forgetPopups(){openPopups=null}function popWindow(windowName,url){var bReturn=false;var newWindow=null;try{var slot=getNextSlot();var offerWindowFeatures=commonOfferWindowFeatures+',screenX='+slot.x+',screenY='+slot.y+',left='+slot.x+',top='+slot.y+',height='+slot.h+',width='+slot.w;newWindow=window.open(url,windowName,offerWindowFeatures)}catch(e){}return newWindow}function backToTop(){var x1=x2=x3=0;var y1=y2=y3=0;if(document.documentElement){x1=document.documentElement.scrollLeft||0;y1=document.documentElement.scrollTop||0}if(document.body){x2=document.body.scrollLeft||0;y2=document.body.scrollTop||0}x3=window.scrollX||0;y3=window.scrollY||0;var x=Math.max(x1,Math.max(x2,x3));var y=Math.max(y1,Math.max(y2,y3));window.scrollTo(Math.floor(x/2),Math.floor(y/2));if(x>0||y>0){window.setTimeout("backToTop()",25)}}
