﻿window.onbeforeunload = function cms_handleOnBeforeUnload() {

	if (typeof(ShowContentSavingBusyMessage) == "undefined")
		return;

    if (g_bWarnBeforeLeave && browseris.ie6up) {
        g_recentCallBackResult = "";
        ShowContentSavingBusyMessage(true);
        __theFormPostData = "";
        _spSuppressFormOnSubmitWrapper = true;
        try {
            WebForm_OnSubmit();
            event.returnValue = undefined;
        }
        finally {
            _spSuppressFormOnSubmitWrapper = false;
        }
        WebForm_InitCallback();
        WebForm_DoCallback('ctl00$ctl00$ctl02$sbn1', '', SBN_CallBackHandler, null, null, false);
        var count = 0;
        while (g_recentCallBackResult == "" && count < 5) {
            count++;
            WaitForCallback(100);
        }
        ShowContentSavingBusyMessage(false);
        if (g_recentCallBackResult != "save succeeded") {
            g_bWarnBeforeLeave = true; if (g_recentCallBackResult != "") {
                var validationString = g_recentCallBackResult;
                return validationString;
            }
            else {
                return 'If you press OK the content will be saved.';
            }
        }
        var saveComplete = document.forms['aspnetForm'].MSO_PageAlreadySaved;
        if (saveComplete != null) {
            saveComplete.value = "1";
        }
    }
    g_bWarnBeforeLeave = false;
}
