if (ad_url != '') { var popupintervaldays = 1; //we haven't opened a popup (until we know we have) popupdone = false; //encapsulated event listener function //this won't allow the suppression of default action on click event in Safari //but for these purposes that's fine, because we don't want|need to function attachEventListener(target, eventType, functionRef) { if (typeof target.addEventListener != 'undefined') { target.addEventListener(eventType, functionRef, false); } else if (typeof target.attachEvent != 'undefined') { target.attachEvent('on' + eventType, functionRef); } return true; } //maybe create a popup (depending on whether we have a cookie) function maybeCreatePopup() { //check for existing popup cookie cookiearray = document.cookie.split(/;\s*/); for(entry in cookiearray) { if(cookiearray[entry] == 'SPcookie=1') { popupdone = true; break; } if(cookiearray[entry] == 'SPsub=1') { popupdone = true; break; } } //if we haven't already done a popup if(!popupdone) { //add statistical identifying information //the type is popup because this is a non-specific random popup //the path tells us where in the site it was triggered from var now = new Date(), uid = now.getTime() + '-' + now.getMilliseconds() + '-' + Math.floor(Math.random() * 10000000); var popuphref = './Abod.php?url=' + ad_url; //open the popup popupnewwindow = window.open(popuphref, 'popme', 'width=800, height=600, location=yes, menubar=yes, status=yes, toolbar=yes, scrollbars=yes, resizable=yes, left=0, top=0'); //if we don't have the reference or it got supressed //say that we haven't done a popup if (!popupnewwindow || popupnewwindow.closed) { popupdone = false; } //otherwise set a cookie to say that we have //and then set focus on the popup else { var expire = new Date(); expire.setTime(expire.getTime() + (1800000 * popupintervaldays)); document.cookie = 'SPcookie=1; expires=' + expire.toGMTString() + '; path=/'; popupnewwindow.blur() window.focus(); } } } //test whether we have cookie support var popupcookiesenabled = false; var expire = new Date(); expire.setTime(expire.getTime() + (10000)); document.cookie = 'SPtestcookie=1; expires=' + expire.toGMTString() + '; path=/'; cookiearray = document.cookie.split(/;\s*/); for (entry in cookiearray) { if (cookiearray[entry] == 'SPtestcookie=1') { popupcookiesenabled = true; break; } } //so now then, if we still record cookie support if(popupcookiesenabled) { //bind an encapsulated click handler to the document //to look for clicks on links that are game for triggering a popup //and route them to maybeCreatePopup //this handler needs to be encapsulated, and also handle return values carefully, //in order to play nicely with the new rel-popup scripting attachEventListener(document, 'click', function(e) { //get event target node //(remembering that e is already event in IE because we're using attachEvent) var node = e.target ? e.target : e.srcElement; //if we're not on the front page //and this click isn't inside a relevant input elements //iterate to look for a link reference var havelink = false; if(node.nodeName.toLowerCase() == 'a') { havelink = true; } else { while(node.parentNode) { if(node.nodeName.toLowerCase() == 'a') { havelink = true; break; } else if(node.nodeName.toLowerCase() == 'body') { break; } else { node = node.parentNode; } } } //if we have a link reference if(havelink) { //look for a rel attribute that indicates a custom popup or _blank link //or a target attribute that is _blank (or _new) //and continue only if we don't have any of those things //this is to prevent multiple popups being generated at once //continue on to conditionally creating a regular popup maybeCreatePopup(); } //if we don't have a link reference //continue on to conditionally creating a regular popup else { maybeCreatePopup(); } }); } }