﻿
var SearchRequest = null;

// This function calls the Web service method and
// passes the event callback function.

function GetSearchResults(query) {
    if (typeof (Tenba) != "undefined") {

       SearchRequest = Tenba.SearchService._staticInstance.GetResults(query,
       SucceededSearchCallbackWithContext, function(exception) {
           if (!SearchRequest.get_executor().get_aborted()) {
               var RsltElem = document.getElementById("SearchResultId");

               if (RsltElem) {
                   RsltElem.innerHTML = exception.get_message(); //"Unknown service error";
               }
           }
       });
    }
}

function GetCart() {
    if (typeof (Tenba) != "undefined") {
        Tenba.SimilarItemsService.GetCart(SucceededCallback);
    }    
}

function GetBanners(url) {
    if (typeof (Tenba) != "undefined") {
        Tenba.BannerService.GetBanners(url, SucceededCallbackWithContext, FailedCallback);
    }
}

function GetLinks() {
    if (typeof (Tenba) != "undefined") {
        Tenba.BannerService.GetLinks(SucceededCallback);
    }
}

// This is the callback function invoked if the Web service
// succeeded.
// It accepts the result object, the user context, and the 
// calling method name as parameters.
function SucceededCallbackWithContext(result, userContext, methodName) {

    var RsltElem = document.getElementById("ResultId");

    if (RsltElem) {
        RsltElem.innerHTML = result;
    }
}

// This is the callback function invoked if the Web service
// succeeded.
// It accepts the result object as a parameter.
function SucceededSearchCallbackWithContext(result, userContext, methodName) {
    // Page element to display feedback.
    var RsltElem = document.getElementById("SearchResultId");
    var Spinner = document.getElementById("spinner"); 
    
    if (RsltElem) {
        RsltElem.innerHTML = result;
    }

    if (Spinner) {
        Spinner.style.visibility = "hidden";
    }
}

// This is the callback function invoked if the Web service
// succeeded.
// It accepts the result object as a parameter.
function SucceededCallback(result, eventArgs) {
    // Page element to display feedback.
    var RsltElem = document.getElementById("ResultId");

    if (RsltElem) {
        RsltElem.innerHTML = result;
    }    
}


// This is the callback function invoked if the Web service
// failed.
// It accepts the error object as a parameter.
function FailedCallback(error) {

    // Display the error.
    var RsltElem = document.getElementById("ResultId");

    if (RsltElem) {
        RsltElem.innerHTML = error.get_message(); //"Unknown service error";
    }   
    // "Service Error: " + error.get_message();
}

if (typeof (Sys) !== "undefined") Sys.Application.notifyScriptLoaded();
