﻿//this variable is accessed in fancybox script 
var fancyBoxOpen = false;
var docheck = true;
var lastSig = null;
var currenturl;
function checkApprovalStatus(url) {
    currenturl = url;
    //approvalSig();
}
function approvalSig() {
    $.ajax({
        type: "POST",
        url: "/WebMethod.aspx/GetApprovalSignature",
        data: "{'url': '" + currenturl + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        error: function(xhr, statusText, errorThrown) {
            //alert('Failed to call web method deletePage(), please report this issue to Creative Lynx Tech Support.\nError info\nStatus = ' + xhr.status + "\nReponse text = " + xhr.responseText);
        },
        success: function(msg) {
            if (lastSig != null && lastSig != msg.d && !fancyBoxOpen) {
                clearCache("/CLynxAdminComponents/ResetCache.aspx");
                docheck = false;
                window.location.reload(true);
            } else if (lastSig != null && lastSig != msg.d && fancyBoxOpen) {
                //do nothing (important dont update lastSig

            } else {

                lastSig = msg.d;
            }
        }
    });
    dowait();

}
function clearCache(clearCachePage) {
    $.get(clearCachePage, function(data) {
        alert("Data Loaded: " + data);
    });
}

function dowait() {
    if (docheck) {
        //setTimeout('approvalSig()', 5000);
    }
}


