﻿window.onbeforeunload = null;
var needToConfirm = false;
var callbackevent = null;
var leavingCheckoutmoduelMessage = "You are leaving the Checkout process. All checkout information will be lost.";


function registeLeavingValidation(eventurl) {
    needToConfirm = true;
    callbackevent = eventurl;
    window.onbeforeunload = ValidateLeavingCheckout;
}

function uninstallLeavingValidation() {
    needToConfirm = false;
    window.onbeforeunload = null;
    window.onunload = null;
}

function ValidateLeavingCheckout() {
    if (needToConfirm) {
        window.onunload = clearGuesProfile;
        return leavingCheckoutmoduelMessage;
    }
    
}
function clearGuesProfile() {
            $.ajax({
                type: "Get",
                url: callbackevent,
                data: {"isInCheckoutModule": needToConfirm,"t":Math.random()},
                dataType: "json",
//                success: function () {
//                    alert("clear address message.");
//                },
                error: function () {
                    alert("clear guest checkout infomation error!");
                }
            });
}

