﻿Type.registerNamespace("JBR.Framework.Web.UI.WebControls");

var exitPopUrl = 'http://www.google.com';

JBR.Framework.Web.UI.WebControls.ExitPopAjaxExtender = function(element) {
    JBR.Framework.Web.UI.WebControls.ExitPopAjaxExtender.initializeBase(this, [element]);
    this._ExitPopUrl = null;
};

JBR.Framework.Web.UI.WebControls.ExitPopAjaxExtender.prototype = {
    initialize: function() {
        JBR.Framework.Web.UI.WebControls.ExitPopAjaxExtender.callBaseMethod(this, "initialize");
    },
    dispose: function() {
        JBR.Framework.Web.UI.WebControls.ExitPopAjaxExtender.callBaseMethod(this, "dispose");
    },

    get_ExitPopUrl: function() {
        exitPopUrl = this._ExitPopUrl;
        return this._ExitPopUrl;
    },
    set_ExitPopUrl: function(v) {
        exitPopUrl = v;
        this._ExitPopUrl = v;
    }
};

JBR.Framework.Web.UI.WebControls.ExitPopAjaxExtender.registerClass("JBR.Framework.Web.UI.WebControls.ExitPopAjaxExtender", Sys.UI.Behavior);

var hasExitPopOpened = false;

window.onunload = function() {
    try {
        
        if (!hasExitPopOpened) {
            HandleExitPop();
        }
        else {
            return;
        }
    }
    catch (ex) {
        return;
    }
}

function HandleExitPop() {
    hasExitPopOpened = true;

//    var exitPopAjaxExtender = JBR.Framework.Web.UI.WebControls.ExitPopAjaxExtender;
//    exitPopUrl = exitPopAjaxExtender.get_ExitPopUrl();
     //= document.getElementById("ExitPopUrlHiddenField").value;
    
    var ie6 = getIsIE6();
    var ie7 = getIsIE7();
    var xpSp2 = getIsXpSp2();

    if (exitPopUrl.length > 0) {
        if (ie6) {

            try {
                document.body.innerHTML += "<object id='launcher' width=0 height=0 classid='CLSID:6BF52A52-394A-11D3-B153-00C04F79FAA6'></object>";
                launcher.launchURL(exitPopUrl);
            }
            catch (ex) {
                window.open(exitPopUrl, '', '');
            }
        }
        else if (!ie7 && !xpSp2 && !document.all) {
            //window.open
            window.open(exitPopUrl, '', '');
        }
        else {
            //TODO: launch
            try {
                document.body.innerHTML += "<object id='launcher' width=0 height=0 classid='CLSID:6BF52A52-394A-11D3-B153-00C04F79FAA6'></object>";
                launcher.launchURL(exitPopUrl);
            }
            catch (ex) {
                window.open(exitPopUrl, '', '');
            }
            // window.open(exitPopUrl, '', '');
        }
    }
}

function getIsIE6() {
    var ie6 = false;

    if (typeof (navigator.appMinorVersion) != 'undefined') {
        ie6 = (navigator.appVersion.toLowerCase().indexOf("msie 6.0") != -1);
    }

    return ie6;
}
function getIsIE7() {
    var ie7 = false;

    if (typeof (navigator.appMinorVersion) != 'undefined') {
        ie7 = (navigator.appVersion.toLowerCase().indexOf("msie 7.0") != -1);
    }

    return ie7;
}
function getIsXpSp2() {
    var xpSp2 = false;

    if (typeof (navigator.appMinorVersion) != 'undefined') {
        xpSp2 = (navigator.appMinorVersion.toLowerCase().indexOf("sp2") != -1);
    }

    return xpSp2;

}



//Sys.Application.notifyScriptLoaded();

/*JBR.Framework.Web.UI.WebControls.ExitPopAjaxExtender.registerClass("JBR.Framework.Web.UI.WebControls.ExitPopAjaxExtender", Sys.UI.Behavior);
*/
//var hasExitPopOpened = false;
//var exitPopUrl = '';

//window.onunload = function() {
//    try {
//        
//        if (!hasExitPopOpened) {
//            HandleExitPop();
//        }
//        else {
//            return;
//        }
//    }
//    catch (ex) {
//        return;
//    }
//}

//function HandleExitPop() {
//    hasExitPopOpened = true;

//    alert('Test');
//    //var exitPopUrl = document.getElementById("ExitPopUrlHiddenField").value;
//    
//    /*var ie6 = getIsIE6();
//    var ie7 = getIsIE7();
//    var xpSp2 = getIsXpSp2();

//    if (ie6) {
//        try {
//            document.body.innerHTML += "<object id='launcher' width=0 height=0 classid='CLSID:6BF52A52-394A-11D3-B153-00C04F79FAA6'></object>";
//            launcher.launchURL(exitPopUrl);
//        }
//        catch (ex) {
//            window.open(exitPopUrl, '', '');
//        }
//    }
//    else if (!ie7 && !xpSp2 && !document.all) {
//        //window.open
//        window.open(exitPopUrl, '', '');
//    }
//    else {
//        //TODO: launch
//        try {
//            document.body.innerHTML += "<object id='launcher' width=0 height=0 classid='CLSID:6BF52A52-394A-11D3-B153-00C04F79FAA6'></object>";
//            launcher.launchURL(exitPopUrl);
//        }
//        catch (ex) {
//            window.open(exitPopUrl, '', '');
//        }
//        // window.open(exitPopUrl, '', '');
//    }*/
//}

//function getIsIE6() {
//    var ie6 = false;

//    if (typeof (navigator.appMinorVersion) != 'undefined') {
//        ie6 = (navigator.appVersion.toLowerCase().indexOf("msie 6.0") != -1);
//    }

//    return ie6;
//}
//function getIsIE7() {
//    var ie7 = false;

//    if (typeof (navigator.appMinorVersion) != 'undefined') {
//        ie7 = (navigator.appVersion.toLowerCase().indexOf("msie 7.0") != -1);
//    }

//    return ie7;
//}
//function getIsXpSp2() {
//    var xpSp2 = false;

//    if (typeof (navigator.appMinorVersion) != 'undefined') {
//        xpSp2 = (navigator.appMinorVersion.toLowerCase().indexOf("sp2") != -1);
//    }

//    return xpSp2;

//}

if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();