﻿function createFlashControl(DivID, movie, width, height) {
    var d = document.getElementById(DivID);
    d.innerHTML = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="' + width + '" height="' + height + '" id="Shell" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="' + movie + '" /><param name="quality" value="high"/><embed src="' + movie + '" quality="high" width="' + width + '" height="' + height + '" name="Shell" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"/></object>';
}
function createFlashControl2(DivID, movie, width, height, base, gotoFrame) {
    var d = document.getElementById(DivID);
    d.innerHTML = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" ' + 'width="' + width + '" height="' + height + '" id="Shell" align="middle"><PARAM NAME="BASE" VALUE="' + base + '" /><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="' + movie + '" /><param name="quality" value="high"/><embed src="' + movie + '" quality="high" width="' + width + '" height="' + height + '" name="Shell" align="middle" base="' + base + '" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"/></object>';

    if (gotoFrame != 0) {
        setFlashFrame(gotoFrame);
    }

    //if(gotoFrame<0){
    //setTimeout("setFlashFrame(" + gotoFrame + ")",100); //added short delay for firefox
    //setFlashFrame(gotoFrame);
    //}
}

//negative gotoFrame = set frame at gotoFrames from the end of the video
function setFlashFrame(gotoFrame) {

    var movie = window.document.Shell;
    if (movie != null) {
        while (!(movie.PercentLoaded() > 0)) {
            //movie is not loaded wait and try again
            setTimeout("setFlashFrame(" + gotoFrame + ")", 100);
            return;
        }
        var totalFrames;
        try {
            totalFrames = movie.TotalFrames(); //firefox
        }
        catch (e) {
            totalFrames = parseInt(movie.TotalFrames); //microsoft
        }
        if (gotoFrame < 0) {
            gotoFrame = totalFrames + gotoFrame;
        }
        if (gotoFrame > 0 && gotoFrame <= totalFrames) {
            movie.StopPlay();
            var needLoaded = gotoFrame / totalFrames;
            while ((needLoaded * 100) < movie.PercentLoaded() && movie.PercentLoaded() < 100) {
                //movie is not loaded wait and try again
                setTimeout("setFlashFrame(" + gotoFrame + ")", 100);
                return;
            }
            movie.GotoFrame(gotoFrame);
            movie.Play();
        }
    }
}
function createQuicktimeControl(DivID, movie, width, height) {
    var d = document.getElementById(DivID);
    d.innerHTML = '<object CLASSID="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" width=' + width + ' height=' + height + 'CODEBASE="http://www.apple.com/qtactivex/qtplugin.cab"><param name="src" value="' + movie + '><param name="autoplay" value="true"><param name="loop" value="false"><param name="controller" value="true"><embed src="' + movie + ' width="' + width + '" height="' + height + ' autoplay="true" loop="false" controller="true" pluginspage="http://www.apple.com/quicktime/"></embed></object>';
}
function createMediaPlayer(DivID, movie, width, height) {
    var d = document.getElementById(DivID);
    d.InnerHTML = '<object width=' + width + ' height=' + height + ' classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" id="mediaplayer1" viewastext><param name="Filename" value=' + movie + '><param name="AutoStart" value="True"><param name="ShowControls" value="True"><param name="ShowStatusBar" value="True"><param name="ShowDisplay" value="False"><param name="AutoRewind" value="True"><embed type="application/x-mplayer2" width=' + width + ' height=' + height + ' pluginspage="http://www.microsoft.com/windows/windowsmedia/download/default.asp" src=' + movie + ' autostart="True" filename=' + movie + ' showcontrols="True" showstatusbar="True" showdisplay="False" autorewind="True"></embed></object>';
}
function openWindow(url, height, width) {
    var theURL = url;
    var window_top = (screen.height - height) / 2;
    var window_left = (screen.width - width) / 2;
    var newfeatures = 'scrollbars=yes,resizable=yes,toolbar=no,location=no,status=no,menubar=no, width=' + width + ',height=' + height + ',top=' + window_top + ',left=' + window_left;
    var newWindow = window.open(theURL, 'Popup', newfeatures);
    newWindow.focus();
}
function openNewWindow(url, height, width) {
    var theURL = url;
    var window_top = (screen.height - height) / 2;
    var window_left = (screen.width - width) / 2;
    var newfeatures = 'scrollbars=yes,resizable=yes,toolbar=no,location=no,status=no,menubar=no, width=' + width + ',height=' + height + ',top=' + window_top + ',left=' + window_left;
    var newWindow = window.open(theURL, '_blank', newfeatures);
    newWindow.focus();
}
function openDialog(url, height, width) {
    var theURL = url;
    var window_top = (screen.height - height) / 2;
    var window_left = (screen.width - width) / 2;
    var newfeatures = 'dialogWidth:' + width + ',dialogHeight:' + height + ',dialogTop"' + window_top + ',dialogLeft:' + window_left;
    window.showModalDialog(theURL, '', newfeatures);
}
function saveClick() {
    __doPostBack('Save', '');
}
function launchwin(winurl) {
    var window_width = 840;
    var window_height = 640;
    var window_top = (screen.height - window_height) / 2;
    var window_left = (screen.width - window_width) / 2;
    var newfeatures = 'scrollbars=yes,resizable=yes,toolbar=no,location=no,status=no,menubar=no width=' + window_width + ',height=' + window_height + ',top=' + window_top + ',left=' + window_left;
    var newWindow = window.open(winurl, 'Popup', newfeatures);
    newWindow.focus();
}
function getElementbyClass(rootobj, classname) {
    var temparray = new Array()
    var inc = 0
    var rootlength = rootobj.length
    for (i = 0; i < rootlength; i++) {
        if (rootobj[i].className == classname)
            temparray[inc++] = rootobj[i]
    }
    return temparray
}

function sweeptoggle(ec) {
    var thestate = (ec == "expand") ? "block" : "none"
    var inc = 0
    while (ccollect[inc]) {
        ccollect[inc].style.display = thestate
        inc++
    }
    revivestatus()
}


function contractcontent(omit) {
    var inc = 0
    while (ccollect[inc]) {
        if (ccollect[inc].id != omit)
            ccollect[inc].style.display = "none"
        inc++
    }
}

function expandcontent(curobj, cid) {
    var spantags = curobj.getElementsByTagName("SPAN")
    var showstateobj = getElementbyClass(spantags, "showstate")
    if (ccollect.length > 0) {
        if (collapseprevious == "yes")
            contractcontent(cid)
        document.getElementById(cid).style.display = (document.getElementById(cid).style.display != "block") ? "block" : "none"
        if (showstateobj.length > 0) { //if "showstate" span exists in header
            if (collapseprevious == "no")
                showstateobj[0].innerHTML = (document.getElementById(cid).style.display == "block") ? contractsymbol : expandsymbol
            else
                revivestatus()
        }
    }
}

function revivecontent() {
    contractcontent("omitnothing")
    selectedItem = getselectedItem()
    selectedComponents = selectedItem.split("|")
    for (i = 0; i < selectedComponents.length - 1; i++)
        document.getElementById(selectedComponents[i]).style.display = "block"
}

function revivestatus() {
    var inc = 0
    while (statecollect[inc]) {
        if (ccollect[inc].style.display == "block")
            statecollect[inc].innerHTML = contractsymbol
        else
            statecollect[inc].innerHTML = expandsymbol
        inc++
    }
}

function get_cookie(Name) {
    var search = Name + "="
    var returnvalue = "";
    if (document.cookie.length > 0) {
        offset = document.cookie.indexOf(search)
        if (offset != -1) {
            offset += search.length
            end = document.cookie.indexOf(";", offset);
            if (end == -1) end = document.cookie.length;
            returnvalue = unescape(document.cookie.substring(offset, end))
        }
    }
    return returnvalue;
}

function getselectedItem() {
    if (get_cookie(window.location.pathname) != "") {
        selectedItem = get_cookie(window.location.pathname)
        return selectedItem
    }
    else
        return ""
}

function saveswitchstate() {
    var inc = 0, selectedItem = ""
    while (ccollect[inc]) {
        if (ccollect[inc].style.display == "block")
            selectedItem += ccollect[inc].id + "|"
        inc++
    }
    document.cookie = window.location.pathname + "=" + selectedItem
}

function do_onload() {
    uniqueidn = window.location.pathname + "firsttimeload"
    var alltags = document.all ? document.all : document.getElementsByTagName("*")
    ccollect = getElementbyClass(alltags, "switchcontent")
    statecollect = getElementbyClass(alltags, "showstate")
    if (enablepersist == "on" && ccollect.length > 0) {
        document.cookie = (get_cookie(uniqueidn) == "") ? uniqueidn + "=1" : uniqueidn + "=0"
        firsttimeload = (get_cookie(uniqueidn) == 1) ? 1 : 0 //check if this is 1st page load
        if (!firsttimeload)
            revivecontent()
    }
    if (ccollect.length > 0 && statecollect.length > 0)
        revivestatus()
}

function checkForCookies() {
    // CHECK IF COOKIES ARE ENABLED 

    var exp = new Date();
    exp.setTime(exp.getTime() + 1800000);

    // first write a test cookie 

    setCookie("cookies", "cookies", exp, false, false, false);
    if (document.cookie.indexOf('cookies') == -1) {
        alert('Your browser does not have cookies enabled.  Certain features on this site require cookies.  Please enable cookies in your browser preferences before continuing.');
    }

    // now delete the test cookie 

    exp = new Date();
    exp.setTime(exp.getTime() - 1800000);
    setCookie("cookies", "cookies", exp, false, false, false);
}
function setCookie(name, value, expires, path, domain, secure) {
    var curCookie = name + "=" + escape(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
    document.cookie = curCookie;
}

function CheckFrame() {
    var tempcontrol;
    var tempframecontrol;
    tempcontrol = document.getElementById('ctl00_MainContent_IsComplete');
    tempframecontrol = document.getElementById('ctl00_MainContent_LastFrame');
    var movie = window.document.Shell;
    if (movie != null) {
        var totalFrames;
        try {
            totalFrames = movie.TotalFrames(); //firefox
        }
        catch (e) {
            totalFrames = parseInt(movie.TotalFrames); //microsoft
        }
        tempframecontrol.value = movie.CurrentFrame();
        if (movie.PercentLoaded() > 0 && movie.CurrentFrame() >= totalFrames - 30) {
            tempcontrol.value = 1;
        }
        else
            setTimeout('CheckFrame()', '500');
    }
}


function CheckNextButton(currentClass, completeClass) {
    var tempnextbutton
    tempcontrol = document.getElementById('ctl00_MainContent_IsComplete');
    tempnextbutton = document.getElementById('ctl00_MainContent_NextButton');
    var tempContainerAsElementControl = document.getElementById('ctl00_MainContent_hiddenContainerAsElement');

    if (tempContainerAsElementControl != null) {
        if (tempContainerAsElementControl.value == 1) {
            return;
        }
    }

    if (tempcontrol != null) {
        if (tempcontrol.value == 1) {
            tempnextbutton.className = completeClass;
        }
        else {
            tempnextbutton.className = currentClass;
            setTimeout('CheckNextButton("' + currentClass + '","' + completeClass + '")', '500');
        }
    }
}


function SimulateNextButton() {
    var tempcontrol;
    tempcontrol = document.getElementById('ctl00_MainContent_IsComplete');
    tempcontrol.value = 1;
    __doPostBack('ctl00$MainContent$NextButton', '')
}

function SimulateBackButton() {
    __doPostBack('ctl00$MainContent$BackButton', '')
}

function PauseCourse() {
    //flash
    var movie = window.document.Shell;
    if (movie != null) {
        movie.StopPlay();
    }

    //windows media
    var movie = window.document.WMP;
    if (movie != null) {
        movie.controls.pause();
    }

    SetPauseButtonClass("CourseVideoPlayButton");
}

function SwapCourseState() {
    //flash
    var movie = window.document.Shell;
    if (movie != null) {
        if (movie.IsPlaying()) {
            movie.StopPlay();
            SetPauseButtonClass("CourseVideoPlayButton");
        }
        else {
            movie.Play();
            SetPauseButtonClass("CourseVideoPauseButton");
        }
    }

}

function MoveCourseFrames(frames) {
    //flash
    var movie = window.document.Shell;
    if (movie != null) {
        var totalFrames;
        var currentFrame;
        var gotoFrame;
        var totalFrames;
        try {
            totalFrames = movie.TotalFrames(); //firefox
        }
        catch (e) {
            totalFrames = parseInt(movie.TotalFrames); //microsoft
        }
        currentFrame = movie.CurrentFrame();
        gotoFrame = currentFrame + frames;

        if (gotoFrame > 0) {
            if (gotoFrame >= totalFrames - 5 && currentFrame < totalFrames - 5)
                gotoFrame = totalFrames - 5;

            var needLoaded = gotoFrame / totalFrames;
            if ((needLoaded * 100) <= movie.PercentLoaded()) {
                movie.GotoFrame(gotoFrame);
                movie.Play();
                SetPauseButtonClass("CourseVideoPauseButton");
            }
        }
        else {
            if (gotoFrame <= 0) {
                //check container as element
                var tempContainerAsElementControl = document.getElementById('ctl00_MainContent_hiddenContainerAsElement');

                if (tempContainerAsElementControl != null) {
                    if (tempContainerAsElementControl.value == 1) {
                        var tempElementPrevIdControl = document.getElementById('ctl00_MainContent_hiddenContainerPrevCourseId');
                        if (tempElementPrevIdControl.value > 0) {
                            CallContainerAsElementPrev();
                        }
                    }
                }
            }
        }
    }
}


function ResumeCourse() {
    //flash
    var movie = window.document.Shell;
    if (movie != null) {
        movie.Play();
    }

    //windows media
    var movie = window.document.WMP;
    if (movie != null) {
        movie.controls.play();
    }

    SetPauseButtonClass("CourseVideoPauseButton");
}

function SetPauseButtonClass(className) {
    var pauseButton = document.getElementById("ctl00_MainContent_VideoPauseButton");
    if (pauseButton != null)
        pauseButton.className = className;
}

function pauseParentCourse() {

    try {
        window.opener.PauseCourse();
    }
    catch (ex) {

    }
}

function RefreshNotebook() {
    try {
        window.opener.SimulateRefresh();
    }
    catch (ex) {

    }
}

function SelectCourse(courseId) {
    var tempcontrol;
    tempcontrol = document.getElementById('ctl00_MainContent_SelectMenuCourseId');
    tempcontrol.value = courseId;
    __doPostBack('ctl00$MainContent$HiddenMenuButton', '')
}

function SelectNotebookCourse(courseId) {
    var tempcontrol;
    tempcontrol = document.getElementById('ctl00_MainContent_SelectedCourseId');
    tempcontrol.value = courseId;
    __doPostBack('ctl00$MainContent$RefreshLink', '');
}

function EditNote(courseId) {
    var tempcontrol;
    tempcontrol = document.getElementById('ctl00_MainContent_EditCourseId');
    tempcontrol.value = courseId;
    __doPostBack('ctl00$MainContent$EditLink', '');
}

//waittime in seconds
function StartContainerAsElementCheck(waitForComplete, waitTime, currentClass, completeClass) {

    if (waitForComplete == true) {
        ContainerAsElementWaitForComplete(currentClass, completeClass);
    }
    else {
        setTimeout('CallContainerAsElementNext("' + currentClass + '","' + completeClass + '")', waitTime * 1000);
    }
}

function ContainerAsElementWaitForComplete(currentClass, completeClass) {

    var tempcontrol;
    tempcontrol = document.getElementById('ctl00_MainContent_IsComplete');
    if (tempcontrol.value > 0) {
        CallContainerAsElementNext(currentClass, completeClass)
    }
    else {
        setTimeout('ContainerAsElementWaitForComplete("' + currentClass + '","' + completeClass + '")', '500');
    }
}

function CallContainerAsElementNext(currentClass, completeClass) {
    var tempCourseIdControl = document.getElementById('ctl00_MainContent_hiddenCourseId');
    var tempElementNextIdControl = document.getElementById('ctl00_MainContent_hiddenContainerNextCourseId');
    if (tempCourseIdControl.value != tempElementNextIdControl.value)
        __doPostBack('ctl00$MainContent$HiddenContainerAsElementButton', '');
    else {
        //flash the next button
        var tempnextbutton
        tempnextbutton = document.getElementById('ctl00_MainContent_NextButton');
        tempnextbutton.className = completeClass;
    }
}

function CallContainerAsElementPrev() {
    var tempElementPrevIdControl = document.getElementById('ctl00_MainContent_hiddenContainerNextCourseId');

    if (tempElementPrevIdControl.value > 0)
        __doPostBack('ctl00$MainContent$HiddenContainerAsElementButtonPrev', '');

}

function SwapCartDescriptionClass(descriptionid, hideclass, showclass) {
    var descriptionControl
    descriptionControl = document.getElementById(descriptionid);
    if (descriptionControl.className == hideclass) {
        descriptionControl.className = showclass;
    }
    else {
        descriptionControl.className = hideclass;
    }
}

function disabletestbutton() {
    //cancel all remaining clicks
    window.document.getElementById('ctl00_MainContent_ButtonBeginTest').onclick = nomoreclicks;
    //let this click go through
    return true;
}

function nomoreclicks() {
    return false;
}