﻿Type.registerNamespace("JBR.Framework.Web.UI.WebControls");

var exitFrameUrl = '';
var initialAlertMessage = '';
var finalAlertMessage = '';
var hasExitFrameOpened = false;

JBR.Framework.Web.UI.WebControls.ExitFrameAjaxExtender = function(element) {
    JBR.Framework.Web.UI.WebControls.ExitFrameAjaxExtender.initializeBase(this, [element]);
    this._ExitFrameUrl = null;
    this._InitialAlertMessage = null;
    this._FinalAlertMessage = null;
};

JBR.Framework.Web.UI.WebControls.ExitFrameAjaxExtender.prototype = {
    initialize: function() {
        JBR.Framework.Web.UI.WebControls.ExitFrameAjaxExtender.callBaseMethod(this, "initialize");
    },
    dispose: function() {
        JBR.Framework.Web.UI.WebControls.ExitFrameAjaxExtender.callBaseMethod(this, "dispose");
    },

    get_ExitFrameUrl: function() {
        exitFrameUrl = this._ExitFrameUrl;
        return this._ExitFrameUrl;
    },
    set_ExitFrameUrl: function(v) {
        exitFrameUrl = v;
        this._ExitFrameUrl = v;
    },
    get_InitialAlertMessage: function() {
        initialAlertMessage = this._InitialAlertMessage;
        return this._InitialAlertMessage;
    },
    set_InitialAlertMessage: function(v) {
        initialAlertMessage = v;
        this._InitialAlertMessage = v;
    },
    get_FinalAlertMessage: function() {
        finalAlertMessage = this._FinalAlertMessage;
        return this._FinalAlertMessage;
    },
    set_FinalAlertMessage: function(v) {
        finalAlertMessage = v;
        this._FinalAlertMessage = v;
    }
};

JBR.Framework.Web.UI.WebControls.ExitFrameAjaxExtender.registerClass("JBR.Framework.Web.UI.WebControls.ExitFrameAjaxExtender", Sys.UI.Behavior);

/*

*/

window.onbeforeunload = function() {
    if (!hasExitFrameOpened) {
        return HandleExitFrame();
    }
    else {
        return;
    }
}

function HandleExitFrame() {
    hasExitFrameOpened = true;

    if (exitFrameUrl.length > 0) {
        document.body.innerHTML = '<iframe src="' + exitFrameUrl + '" id="lastchance" name="lastchance" width="100%" height="1500" scroll="noscroll"></iframe>';

        alert(initialAlertMessage);

        return finalAlertMessage;
    }
    else {
        return;
    }
}


if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();