var safeShit = new Array();
var dPopURL = "http://images.studpay.com/promo/console/";
var dPopWidth = 1000;
var dPopHeight = 912;

safeShit.push("javascript:");
safeShit.push("members");
safeShit.push("studpay");
safeShit.push("youngcs");
safeShit.push("http://www.google.com");

document.cookie = "pud=; expires=Sun, 12 Jul 2009 01:01:01 UTC;";
var g_sPrimeLoc;

function helper()
{

        var aAnchorTags = document.getElementsByTagName("a");
        for (var i = 0; i < aAnchorTags.length ; i++)
        {

                var bSkip = false;

                for(nK in safeShit)
                {
                        if(  aAnchorTags[i].href.indexOf(safeShit[nK]) > -1 )
                        {
                                bSkip = true;
                        }
                }

                if( ! bSkip )
                {
                        aAnchorTags[i].onclick = pUD;
                }
        }
}

function pUD(sPrimeLoc,sPopLoc,nWidth,nHeight)
{
        if( ! sPrimeLoc )       sPrimeLoc = this;
        if( ! sPopLoc )         sPopLoc = dPopURL;

        if( ! nWidth && dPopWidth ) nWidth = dPopWidth;
        if( ! nHeight && dPopHeight ) nHeight = dPopHeight;

        pU(this,dPopURL,nWidth,nHeight);
        return true;
}



// Launch functions

function pU(sPrimeLoc,sPopLoc,nWidth,nHeight)
{

        sPrimeLoc       = "dink.php?url=" + escape(sPrimeLoc);
        sPopLoc         = "dink.php?pud=1&url=" + escape(sPopLoc);

        if( ! nHeight ) nHeight = 0;
        if( ! nWidth ) nWidth = 0;

        if( ! nHeight && ! nWidth )
        {
                if(navigator.appName == "Microsoft Internet Explorer")
                {
                        nHeight = (document.body.clientHeight * 1) - 1;
                        nWidth = (document.body.clientWidth * 1) - 1;
                }
                else
                {
                        nHeight = (document.height * 1) - 1;
                        nWidth = (document.width * 1) - 1;
                }
        }

        var sNewWindowDimensions = "height=" + nHeight + ",width=" + nWidth;

        window.open(sPopLoc,'_blank',"menubar=1,resizable=1,scrollbars=1,status=1,location=0,toolbar=1," + sNewWindowDimensions);
        window.focus();
        g_sPrimeLoc = sPrimeLoc;
        return true;
}






// Destination functions

function RedirectPopunder(sLocation)
{
        document.cookie = "pud=" + escape(sLocation);
}






// Popunder functions

if(location.href.match(/pud=1/))
{
        AlternateLocationPoller();
        setTimeout("TabDetector()",50);
}

function TabDetector()
{
        if(location.search.indexOf('redirected=true') == -1)
        {
                var bIsTab = false;

                try
                {
                        if(navigator.appName == "Microsoft Internet Explorer")
                        {
                                if(document.body.clientHeight == opener.document.body.clientHeight && document.body.clientWidth == opener.document.body.clientWidth)
                                {
                                        bIsTab = true;
                                }
                        }
                        else
                        {
                                if(document.height == opener.document.height && document.width == opener.document.width)
                                {
                                        bIsTab = true;
                                }
                        }
                }
                catch(e) {}

                if(bIsTab)
                {
                        var sSwapLocation = false;

                        try
                        {
                                sSwapLocation = opener.g_sPrimeLoc;
                                opener.location.replace(location.href + (location.href.indexOf('?') > -1 ? '&' : '?') + 'redirected=true');
                        }
                        catch(e) { }

                        if(sSwapLocation)
                                location.replace(sSwapLocation);
                }
                else
                {
                        try
                        {
                                //opener.location.replace(opener.g_sPrimeLoc);
                                opener.location = opener.g_sPrimeLoc;
                        }
                        catch(e) { }
                }
        }
}

function AlternateLocationPoller()
{
        if(document.cookie.indexOf('pud=') > -1)
        {
                document.cookie.match(/pud=([^;]+)/);
                document.cookie = "pud=; expires=Sat, 23 Feb 2008 21:06:12 UTC;";
                location.replace(RegExp.$1 + (RegExp.$1.indexOf('?') > -1 ? '&' : '?') + 'redirected=true');
        }
        else
        {
                setTimeout("AlternateLocationPoller()",100);
        }
}

