﻿function CallPageMethod(methodName, location, onSuccess, onFail) 
{
    var args = '';
    var l = arguments.length;
    
    if (l > 4) 
    {
        for (var i = 4; i < l - 1; i += 2) 
            {
            if (args.length != 0) args += ',';
                args += '"' + arguments[i] + '":"' + arguments[i + 1] + '"';
            }
    }
    var loc;
    if(location==""){
    loc = window.location.href;
    loc = (loc.substr(loc.length - 1, 1) == "/") ? loc + "default.aspx" : loc;
    }else loc=location; 
    $.ajax({
    type: "POST",
    url: loc + "/" + methodName,
    data: "{" + args + "}",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: onSuccess,
    fail: onFail
    });
}


function jqCreateATC(ctrlid, prodid, wmsid, upcid, availibledate, qoh, isspec)
{
    CallPageMethod("CreateBuyButton", "../cart/controls/CartServices.aspx", ATCReturn, ATCFail, "ctrlId", ctrlid, "prodId", prodid, "AvailibleDate", availibledate, "QOH", qoh, "isSpecOrder", isspec, "WMS", wmsid, "UPC", upcid);
}
function jqFootPrintClick(indx, sUrl, sTarget) {
    alert('hello');
    CallPageMethod("FootPrintClick", "../Controls/GlobalPageMethods.aspx", FootPrintReturn, FootPrintFail, "sIndx", indx);
    jump(sUrl, sTarget);
}
function jump(sUrl, sTarget) {
    if (sTarget == "") sTarget = "_self";
    window.open(sUrl, sTarget);
    return;
}
function ATCReturn(msg) 
{
    var ctlid=msg.d.split('|')[0];
    document.getElementById(ctlid).innerHTML=msg.d.split('|')[1];
    if(document.getElementById("MiniCart"))
    {
        UpdateMiniCart();
    }
}
function ATCFail(msg)
{
    //alert("error");
}
function FootPrintReturn(msg) {
    document.getElementById("divFootPrint").innerHTML = msg.d;
}
function FootPrintFail(msg) {
    //alert("error");
}

function checkSessionForCart() {
    CallPageMethod("CheckSession", "../cart/controls/CartServices.aspx", CartCheckSessionRet, CartCheckSessionErr);
}

function CartCheckSessionRet(msg) {
    if (msg.d == "false" && $find("ctl00_TheBody_AcStepsNav_AccordionExtender") != null) {
        alert("Your Session Has Timed Out.  This Screen Will Refresh After Clicking OK.");
        __doPostBack('', '');

    }
}
function CartCheckSessionErr(msg) {
    checkSessionRet('false');
} 
