﻿// WebServiceMultipleCallers.js

// This function calls a Web service method 
// passing simple type parameters and the user context.  
function AddWithContext(a, b, userContext) {
    Samples.AspNet.WebService.Add(a, b,
    SucceededCallbackWithContext, FailedCallback, userContext, null);
}


// This function calls the Web service method 
// passing the method name.  
function AddWithMethod(a, b) {
    Samples.AspNet.WebService.Add(a, b,
    SucceededCallbackWithContext, FailedCallback);
}

function AddToCart(val) {
    document.getElementById('ctl00_lblCart').innerText = 'Shopping Cart (' + val + ')';
    document.getElementById('ctl00_lblCart').textContent = 'Shopping Cart (' + val + ')';
}

function ServerAddToCart(DomainID, DomainName) {
    WS.GetDomain.Shopping.AddDomainToCart(DomainID, DomainName, SucceededCallbackWithContext, FailedCallback);
}

// This is the callback function called if the
// Web service succeeded. It accepts the result
// object, the user context, and the method name as
// parameters.
function SucceededCallbackWithContext(result, userContext, methodName) {
    // It holds feedback message.
    var output = "";
    var cartcount = '0';
    var res_split = result.toString().split(';');
    cartcount = res_split[1];
    AddToCart(cartcount);
    // Page element to display the feedback message.    
    var RsltElem =
        document.getElementById("divDomain" + res_split[0]);
    RsltElem.style.display = 'block';
    //    if (userContext) {
    //        output += "The user context is : " + userContext + "<br/>";
    //        RsltElem.innerHTML = output;
    //        return;
    //    }

    //    if (methodName)
    //        output += "The method name is : " + methodName + "<br/>";

    //    RsltElem.innerHTML = output;

}

// This is the callback function called if the
// Web service failed. It accepts the error object
// as a parameter.
function FailedCallback(error) {
    // Display the error.    
    var RsltElem =
        document.getElementById("Results");
    RsltElem.innerHTML =
        "Service Error: " + error.get_message();
}

if (typeof (Sys) !== "undefined") Sys.Application.notifyScriptLoaded();