﻿var popped = false;
var PopWidth = 1000;
var PopHeight = 800;
var _parent=null;
function GetWindowHeight() {
    var myHeight = 0;
    if (typeof ( _parent.window.innerHeight) == 'number') {
        myHeight =  _parent.window.innerHeight;
    } else if ( _parent.document.documentElement && _parent.document.documentElement.clientHeight) {
        myHeight =  _parent.document.documentElement.clientHeight;
    } else if ( _parent.document.body && _parent.document.body.clientHeight) {
        myHeight =  _parent.document.body.clientHeight;
    }
    return myHeight;
}
function GetWindowWidth() {
    var myWidth = 0;
    if (typeof (_parent.window.innerWidth) == 'number') {
        myWidth =  _parent.window.innerWidth;
    } else if (_parent.document.documentElement &&  _parent.document.documentElement.clientWidth) {
        myWidth = _parent.document.documentElement.clientWidth;
    } else if (_parent.document.body && _parent.document.body.clientWidth) {
        myWidth = _parent.document.body.clientWidth;
    }
    return myWidth;
}
function GetWindowTop() {
    return (_parent.window.screenTop != undefined) ? _parent.window.screenTop : _parent.window.screenY;
}
function GetWindowLeft() {
    return (_parent.window.screenLeft != undefined) ? _parent.window.screenLeft : _parent.window.screenX;
}
//Source: https://gist.github.com/1021924
(function ($) {
    /* use jQuery as container for more convenience */
    $.popunder = function (sUrl) {
        var pxLeft = 0;
        var pxTop = 0;
        _parent = self;
        var bPopunder = ($.browser.msie && parseInt($.browser.version, 10) < 9);
        if (top != self) {
            try {
                if (top.document.location.toString()) {
                    _parent = top;
                }
            }
            catch (err) { }
        }
        pxLeft = (GetWindowLeft() + (GetWindowWidth() / 2) - (PopWidth / 2));
        pxTop = (GetWindowTop() + (GetWindowHeight() / 2) - (PopHeight / 2));
        /* popunder options */
        var sOptions = 'toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=0,resizable=1,top=' + pxTop + ',left=' + pxLeft + ',width=' + PopWidth + ',height=' + PopHeight;
        sOptions += ',height=' + (screen.availHeight - 122).toString() + ',screenX=0,screenY=0,left=0,top=0';

        /* create pop-up from parent context */
        var popunder = _parent.window.open(sUrl, 'pu_' + Math.floor(89999999 * Math.random() + 10000000), sOptions);
        if (popunder) {
            popunder.blur();
            if (bPopunder) {
                /* classic popunder, used for old ie*/
                window.focus();
                try { opener.window.focus(); }
                catch (err) { }
            }
            else {
                /* popunder for e.g. ff4+, chrome, ie9 */
                popunder.init = function (e) {
                    with (e) {
                        (function () {
                            if (typeof window.mozPaintCount != 'undefined') {
                                var x = window.open('about:blank');
                                x.close();
                            }

                            try { opener.window.focus(); }
                            catch (err) { }
                        })();
                    }
                };
                popunder.params = {
                    url: sUrl
                };
                popunder.init(popunder);
            }
        }

        return this;
    }
})(jQuery);
$('html').click(function () {
    if (!popped && document.cookie.lastIndexOf('dispop') == -1) {
        jQuery.popunder('/scc.aspx?pid=' + document.getElementById('hidPopPID').value);
        popped = true;
    }
});


