﻿// CallWebService.js


// This function calls the used to 
// passing the callback function. 
function setVideoWatchedHTML(videoId,thePath) {
    theWebservice.videoLesson.setVideoViewedHTML(categoryId, thePath, SucceededWatchedHTML);
    
}

// This is the callback function invoked if the Web service for category content
// succeeded.
// It accepts the result object as a parameter.
function SucceededWatchedHTML(result, eventArgs) {
    // Do nothing, just for result call.

}


// This function calls the used to 
// passing the callback function. 
function setVideoViews(videoId) {
    theWebservice.videoLesson.getSelectedVideoViews(videoId, SucceededCallbackView);
}

// This is the callback function invoked if the Web service for category content
// succeeded.
// It accepts the result object as a parameter.
function SucceededCallbackView(result, eventArgs) {
    // Page element to display feedback.
    var RsltElem = document.getElementById("video_views");
    RsltElem.innerHTML = result;
}




// This function calls the Web service method without 
// passing the callback function. 
function getCategoryLessons(categoryId) {
    theWebservice.videoLesson.getCategoryLessons(categoryId,SucceededCallback);
}

// This is the callback function invoked if the Web service for category content
// succeeded.
// It accepts the result object as a parameter.
function SucceededCallback(result, eventArgs) {
    // Page element to display feedback.
    var RsltElem = document.getElementById("By_Section_Content_Main");
    RsltElem.innerHTML = result;
}



// This function calls the Web service method for SEARCH 
// passing the callback function. 
function getSearchResults(theSearchString) {
    theWebservice.videoLesson.searchPageResults(theSearchString, SucceededSearch);
}

// This is the callback function invoked if the Web service for SEARCH content
// succeeded.
// It accepts the result object as a parameter.
function SucceededSearch(result, eventArgs) {
    // Page element to display feedback.
    var RsltElem = document.getElementById("theSearchResults");
    RsltElem.innerHTML = result;
}

// This function calls the Web service method for COMMERCIAL BANNER/VIDEO
// passing the callback function. 
function getCommercialBanner() {
    theWebservice.videoLesson.getCommercialBanner(SucceededCommercial);
}

// This is the callback function invoked if the Web service for COMMERCIAL BANNER/VIDEO content
// succeeded.
// It accepts the result object as a parameter.
function SucceededCommercial(result, eventArgs) {
    // Page element to display feedback.
    var RsltElem = document.getElementById("theCommercialBanner");
    RsltElem.innerHTML = result;
}




//This function calls the webservice to update the player
function playTheVideo(source) {
    scrollTo(0, 200);
    theWebservice.videoLesson.setThePlayer(source, SucceededVideoPlay);
    theWebservice.videoLesson.setTheBanners(source);
}

//This is the call function invoked if the web service for the player succeeded.
function SucceededVideoPlay(result, eventArgs) {
    // Page element to display feedback.
    var RsltElem1 = document.getElementById("theVideoPlayer");
    var RsltElem2 = document.getElementById("theCommercialBanner");
    var stringLength = 0;
    var stringBackNumber = 0;
    var videoPlayer;
    var commercialBanner;

    stringLength = result.length;
    stringBackNumber = result.indexOf("<br><br>");
    videoPlayer = result.substring(0, stringBackNumber);
    stringBackNumber = stringBackNumber + 8;
    commercialBanner = result.substring(stringBackNumber,stringLength);

    RsltElem1.innerHTML = videoPlayer;
    RsltElem2.innerHTML = commercialBanner; //"The String Lenght:" + stringLength + " The StringBackNumber: " + stringBackNumber;

}

//This function calls the webservice to update the player
function setTheBanner(source) {
    theWebservice.videoLesson.setTheBanners(source,SucceededBanner);
}

//This is the call function invoked if the web service for the player succeeded.
function SucceededBanner(result, eventArgs) {
    // Page element to display feedback.
    var RsltElem = document.getElementById("videoBanners");
    RsltElem.innerHTML = result;

}

//This function calls the webservice to update the teacher cart
function setTheCart(source) {
    theWebservice.videoLesson.setTheCart(source, SucceededCart);
}

//This is the call function invoked if the web service for the player succeeded.
function SucceededCart(result, eventArgs) {
    // Page element to display feedback.
    var RsltElem = document.getElementById("theCartItems");
    var RsltElem2 = document.getElementById("teacherCartButton");
    //var RsltElem = document.getElementById("theTeacherCart");
    var stringLength = 0;
    var stringBackNumber = 0;
    var theCartButton = "";
    var theCartList = "";
    stringLength = result.length;
    stringBackNumber = result.indexOf("theCart");
    stringBackNumber = stringBackNumber + 7;
    theCartList = result.substring(0, stringBackNumber-7)
    theCartButton = result.substring(stringBackNumber, stringLength);
    if ((result == "") || (result == null)) {
        RsltElem.innerHTML = "Art Supply List Not Available.";
        RsltElem2.innerHTML = "";
    } else {
        RsltElem.innerHTML = theCartList;
        RsltElem2.innerHTML = theCartButton;
    }   
   

}

//This function calls the webservice to update the demo graphic
function setTheDemoImage(source, theTitle, theURL) {
    var RsltElem7 = document.getElementById("nowPlayingTitle");
    RsltElem7.innerHTML = theTitle;
    theWebservice.videoLesson.setTheDemoImage(source,theTitle,theURL, SucceededDemoImage);
}

//This is the call function invoked if the web service for the player succeeded.
function SucceededDemoImage(result, eventArgs) {
    // Page element to display feedback.
    var RsltElem = document.getElementById("theCartItems");
   // var RsltElem = document.getElementById("theTeacherCart");
    RsltElem.innerHTML = result;

}

//This function calls the webservice to update the teacher cart
function setTheDVDList(source,name) {
    theWebservice.videoLesson.setTheDVDList(name,source, SucceededDVDList);
}

//This is the call function invoked if the web service for the player succeeded.
function SucceededDVDList(result, eventArgs) {
    // Page element to display feedback.
     var RsltElem = document.getElementById("theDVDItems");
   // var RsltElem = document.getElementById("theDVD");
    RsltElem.innerHTML = result;

}


//This function calls the webservice to update the player
function theVideoTitleDesc(theVideoId) {
    theWebservice.videoLesson.getSelectedVideoTitleDesc(theVideoId, SucceededVideoTitleDesc);

}

//This is the call function invoked if the web service for the player succeeded.
function SucceededVideoTitleDesc(result, eventArgs) {
    // Page element to display feedback.
    var RsltElem1 = document.getElementById("nowPlayingDesc");
    var RsltElem2 = document.getElementById("nowPlayingTitle");
    var stringLength = 0;
    var stringBackNumber = 0;
    var theDesc;
    var theTitle;
    stringLength = result.length;
    stringBackNumber = result.indexOf("</a>");
    stringBackNumber = stringBackNumber + 8;
    theDesc = result.substring(0, stringBackNumber)
    theTitle = result.substring(stringBackNumber, stringLength);
    RsltElem1.innerHTML = theDesc;
    RsltElem2.innerHTML = theTitle;

}


//This function calls the webservice to update the player
function theDemoTitleDesc(theVideoId) {
    theWebservice.videoLesson.getSelectedDemoTitleDesc(theVideoId, SucceededDemoTitleDesc);

}

//This is the call function invoked if the web service for the player succeeded.
function SucceededDemoTitleDesc(result, eventArgs) {
    // Page element to display feedback.
    //var RsltElem1 = document.getElementById("theVideoDesc");
    var RsltElem1 = document.getElementById("nowPlayingDesc");
    //var RsltElem2 = document.getElementById("nowPlayingTitle");
    var stringLength = 0;
    var stringBackNumber = 0;
    var theDesc;
    var theTitle;
   // stringLength = result.length;
    //stringBackNumber = result.indexOf("</a>");
    //stringBackNumber = stringBackNumber + 8;
    theDesc = result;
    //theTitle = result.substring(stringBackNumber, stringLength);
    RsltElem1.innerHTML = theDesc;
    //RsltElem2.innerHTML = theTitle;

}



// This function calls the Web service method and 
// passes the event callback function.  
function GetTime() {
    Samples.AspNet.WebService.GetServerTime(
    SucceededCallback);

}


// This function calls the Web service method 
// passing simple type parameters and the 
// callback function  
function Add(a, b) {
    Samples.AspNet.WebService.Add(a, b,
    SucceededCallback);
}

// This function calls the Web service method 
// that returns an XmlDocument type.  
function GetXmlDocument() {
    Samples.AspNet.WebService.GetXmlDocument(
        SucceededCallbackWithContext, FailedCallback,
        "XmlDocument")
}

// This function calls a Web service method that uses
// GET to make the Web request.
function MakeGetRequest() {

    Samples.AspNet.WebService.EchoStringAndDate(
        new Date("1/1/2007"), " Happy",
        SucceededCallback,
        FailedCallback, "HappyNewYear");

}

// 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 output;

    // Page element to display feedback.
    var RsltElem = document.getElementById("ResultId");

    var readResult;
    if (userContext == "XmlDocument") {

        if (document.all)
            readResult =
		        result.documentElement.firstChild.text;
        else
        // Firefox
            readResult =
		        result.documentElement.firstChild.textContent;

        RsltElem.innerHTML = "XmlDocument content: " + readResult;
    }

}


// 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");
    RsltElem.innerHTML =
    "Service Error: " + error.get_message();
}

if (typeof (Sys) !== "undefined") Sys.Application.notifyScriptLoaded();

