/*
//Open the specified slide in the iframe on the page
//Parameter: CAID of the slide to view in the iFRAME on the page. The iFrame must be called "CURSUMIFRAME" (default iframe name in CURSUM)
gotoSlideIframe(CAID)

//Open the specified url in the CURSUM iFrame on the page
//Parameters: 
//inURL: http://xxxx of the website to display in the iframe
//IframeID: Specify an Iframe, if left blank, the Iframe will be CURSUMIFRAME
gotoURLIframe(inURL, IframeId)

//Get the Download item with the specified ID
//Parameter: Download ID of the item to download - can be found in the download admin
gotoDownload(intID)

//Get the Dictionary item with the specified ID
//Parameters:
//inID = Dictionary ID of the Dictionary item to show in the popup window- can be found in the Dictionary admin
//inWidth = width of the popup window in pixels
//inHeight = height of the popup window in pixels
//scroll = either 'yes' or 'no' value indicating if the popup window should have scrollbars
openDic(inID,inWidth, inHeight, scroll)

//Open a popup window with a slide with specified CAID
//Parameters:
//CAID = CAID of the slide to show in the popup window- can be found in the content explorer
//inWidth = width of the popup window in pixels
//inHeight = height of the popup window in pixels
//scroll = either 'yes' or 'no' value indicating if the popup window should have scrollbars
openSlide(CAID, inWidth, inHeight, scroll)

//Open a fullscreen window with a slide with the specified CAID - this only works in MS IE 5+
//CAID = CAID of the slide to show in the popup window- can be found in the content explorer
openSlideFullScreen(CAID)

//Go to the specified slide (CAID)
//Parameters:
//gotoCAID = CAID of the slide to goto- can be found in the content explorer
//target values:
//0="Main Frame"
//1="IFrame"
//2="New Window"
//3="Pop-up Window 400x300"
//4="Pop-up Window 600x400"
//5="Pop-up Window 800x600"
//6="Pop-up Window 1000x760"
//7="Pop-up Full Screen Window - Only IE"
//8="Parent Window (From IFrame)"
gotoSlideFromMenu(gotoCAID, target)

//Go to the specified slide with the specified CAID
//Parameters:
//CAID = CAID of the slide to goto- can be found in the content explorer
gotoSlide(CAID)

//DOM id of a html element which should swap visibility (hidden/visible)
SwapSpan(divid)

//Open a popup window the specified URL
//Parameters:
//URL = URL of the web page to show in the popup window (eg. http://www.dr.dk)
//inWidth = width of the popup window in pixels
//inHeight = height of the popup window in pixels
//scroll = either 'yes' or 'no' value indicating if the popup window should have scrollbars
openWinNoName(URL,inWidth, inHeight, scroll)

//Change the users active course to the course with the specified Course ID
//Parameters: 
//CourseID = ID of the course to switch to. Can be found in the domain admin
//target = frame name of the target to open the new course in, default = '' => parent frame
ChangeActiveCourse(courseid,target)

//Open the user Preferences editor in a new window
openUserPrefs()

//open the ask instructor editor in a new window
OpenAskInstructorEditor()
*/
var cursumrootpath = "";
function show(object, x, xs, y, ys, w, ws, h, hs, PixName) {
    if (document.layers && document.layers[object] != null) {
        if (xs == '%')
        { x = Math.round(x * window.innerWidth) / 100; }
        if (ys == '%')
        { y = Math.round(y * window.innerHeight) / 100; }
        if (ws == '%')
        { w = Math.round(w * window.innerWidth) / 100; }
        if (hs == '%')
        { h = Math.round(h * window.innerHeight) / 100; }
        document.layers[object].left = x;
        document.layers[object].top = y;
        document.layers[object].resizeTo(w, h);
        document.layers[object].document.images[PixName].width = Math.round(w - 30);
    }
}

function gotoSlideIframe(inID, inHeaderMode, ifrmDomID, urlparam) {
    var strGOTO = cursumrootpath + "/client/default.aspx?CAID=" + inID;
    if (inHeaderMode != "" && inHeaderMode != "undefined" && inHeaderMode != null) {
        strGOTO += "&HeaderMode=" + inHeaderMode;
    }
    if (urlparam != null)
        strGOTO += urlparam;

    if (!IsAdmin) {
        if (ifrmDomID != null)
            document.getElementById(ifrmDomID).src = strGOTO;
        else
            window.CURSUMIFRAME.location = strGOTO;
    }
}
function gotoSlideIframeParent(inID, inHeaderMode, ifrmDomID) {
    var strGOTO = cursumrootpath + "/client/default.aspx?CAID=" + inID;
    if (inHeaderMode != "" && inHeaderMode != "undefined" && inHeaderMode != null) {
        strGOTO = strGOTO + "&HeaderMode=" + inHeaderMode;
    }
    if (!IsAdmin) {
        if (ifrmDomID != null)
            document.getElementById(ifrmDomID).src = strGOTO;
        else
            window.parent.document.all.CURSUMIFRAME.src = strGOTO;
    }
}

function gotoGUCAIDSlideIframe(inID, inHeaderMode, ifrmDomID) {
    var strGOTO = cursumrootpath + "/client/default.aspx?GUCAID=" + inID;
    if (inHeaderMode != "" && inHeaderMode != "undefined" && inHeaderMode != null) {
        strGOTO = strGOTO + "&HeaderMode=" + inHeaderMode;
    }
    if (!IsAdmin) {
        if (ifrmDomID != null)
            document.getElementById(ifrmDomID).src = strGOTO;
        else
            window.CURSUMIFRAME.location = strGOTO;
    }
}

function gotoURLIframe(inURL, ifrmDomID) {
    if (!IsAdmin) {
        if (ifrmDomID != null)
            document.getElementById(ifrmDomID).src = inURL;
        else
            window.CURSUMIFRAME.location = inURL;
    }

}


function gotoCustomSlideIframe(inID, inHeaderMode, ifrmDomID) {
    var strGOTO = cursumrootpath + "/client/default.aspx?CAID=" + inID;
    if (inHeaderMode != "" && inHeaderMode != "undefined" && inHeaderMode != null) {
        strGOTO = strGOTO + "&HeaderMode=" + inHeaderMode;
    }
    if (!IsAdmin) {
        if (ifrmDomID != null)
            parent.window.document.getElementById(ifrmDomID).src = strGOTO;
        else
            window.CURSUMIFRAME.location = strGOTO;
    }
}

function gotoDownload(intID) {
    if (!IsAdmin)
        document.location.href = cursumrootpath + '/client/utils/DownloadItem.aspx?DownloadID=' + intID;
}



function openDic(inID, inWidth, inHeight, scroll) {
    inID = replace(inID, "lookup.asp?ID=", "");
    if (scroll == "")
        scroll = "no";
    xPos = screen.availHeight / 2 - (inHeight / 2);
    yPos = screen.availWidth / 2 - (inWidth / 2);
    strFeatures = 'width=' + inWidth + ',height=' + inHeight + ',top=' + xPos + ',left=' + yPos + ',statusbar=no,menubar=no,toolbar=no,resizable=yes,scrollbars=' + scroll + ',hotkeys=no';
    if (!IsAdmin)
        window.open(cursumrootpath + "/client/utils/DictionaryViewer.aspx?DictionaryID=" + inID, 'DictionaryWindow', strFeatures);
}

function openSlide(inID, inWidth, inHeight, scroll, ilocation, urlparam) {
    if (scroll == "") {
        scroll = "no";
    }
    if (inWidth == "") {
        inWidth = "750";
    }
    if (inHeight == "") {
        inHeight = "550";
    }
    if (ilocation == null || ilocation == "" || ilocation == 0) {
        xPos = screen.availWidth / 2 - (inWidth / 2);
        yPos = screen.availHeight / 2 - (inHeight / 2);
    } else {
        switch (parseInt(ilocation)) {
            case 1: //top left
                xPos = screen.availWidth / 4 - (inWidth / 2);
                yPos = screen.availHeight / 4 - (inHeight / 2);
                break;
            case 2: //middle left
                xPos = screen.availWidth / 4 - (inWidth / 2);
                yPos = screen.availHeight / 2 - (inHeight / 2);
                break;
            case 3: //bottom left
                xPos = screen.availWidth / 4 - (inWidth / 2);
                yPos = (screen.availHeight / 4 - (inHeight / 4)) * 3;
                break;
            case 4: //top right
                xPos = (screen.availWidth / 4) * 3 - (inWidth / 2);
                yPos = screen.availHeight / 4 - (inHeight / 4);
                break;
            case 5: //middle right
                xPos = (screen.availWidth / 4) * 3 - (inWidth / 2);
                yPos = screen.availHeight / 2 - (inHeight / 2);
                break;
            case 6: //bottom right
                xPos = (screen.availWidth / 4) * 3 - (inWidth / 2);
                yPos = (screen.availHeight / 4 - (inHeight / 4)) * 3;
                break;
        }
    }

    var strURL = cursumrootpath + "/client/default.aspx?CAID=" + inID;
    if (urlparam != null)
        strURL += urlparam;

    strFeatures = 'width=' + inWidth + ',height=' + inHeight + ',top=' + yPos + ',left=' + xPos + ',statusbar=0,menubar=no,toolbar=no,resizable=yes,scrollbars=' + scroll + ',hotkeys=no';

    if (!IsAdmin)
        window.open(strURL, '', strFeatures);
}

function NewWindow(CAID, myname, posX, posY, w, h, scroll) {
    var strURL = cursumrootpath + "/client/default.aspx?CAID=" + CAID;
    var winl = posX;
    var wint = posY;
    winprops = 'height=' + h + ',width=' + w + ',top=' + wint + ',left=' + winl + ',scrollbars=' + scroll + ',resizable,toolbar=no,menubar=no'
    win = window.open(strURL, myname, winprops)
    if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function openSingleForumPost(url) {
    window.showModalDialog(cursumrootpath + "/webcontrols/asset/conference/ConferencePrintThread.aspx?" + url, "", "dialogHeight:400px; dialogWidth:700px");
}

function openGUCAIDSlide(inID, inWidth, inHeight, scroll, ilocation) {
    if (scroll == "") {
        scroll = "no";
    }
    if (inWidth == "") {
        inWidth = "750";
    }
    if (inHeight == "") {
        inHeight = "550";
    }
    if (ilocation == null || ilocation == "" || ilocation == 0) {
        xPos = screen.availWidth / 2 - (inWidth / 2);
        yPos = screen.availHeight / 2 - (inHeight / 2);
    } else {
        switch (parseInt(ilocation)) {
            case 1: //top left
                xPos = screen.availWidth / 4 - (inWidth / 2);
                yPos = screen.availHeight / 4 - (inHeight / 2);
                break;
            case 2: //middle left
                xPos = screen.availWidth / 4 - (inWidth / 2);
                yPos = screen.availHeight / 2 - (inHeight / 2);
                break;
            case 3: //bottom left
                xPos = screen.availWidth / 4 - (inWidth / 2);
                yPos = (screen.availHeight / 4 - (inHeight / 4)) * 3;
                break;
            case 4: //top right
                xPos = (screen.availWidth / 4) * 3 - (inWidth / 2);
                yPos = screen.availHeight / 4 - (inHeight / 4);
                break;
            case 5: //middle right
                xPos = (screen.availWidth / 4) * 3 - (inWidth / 2);
                yPos = screen.availHeight / 2 - (inHeight / 2);
                break;
            case 6: //bottom right
                xPos = (screen.availWidth / 4) * 3 - (inWidth / 2);
                yPos = (screen.availHeight / 4 - (inHeight / 4)) * 3;
                break;
        }
    }


    var strURL = cursumrootpath + "/client/default.aspx?GUCAID=" + inID;
    strFeatures = 'width=' + inWidth + ',height=' + inHeight + ',top=' + yPos + ',left=' + xPos + ',statusbar=0,menubar=no,toolbar=no,resizable=yes,scrollbars=' + scroll + ',hotkeys=no';

    if (!IsAdmin)
        window.open(strURL, '', strFeatures);
}
function openSlideFullScreen(CAID) {
    var strURL = cursumrootpath + "/client/default.aspx?CAID=" + CAID;
    strFeatures = 'fullscreen=yes';

    if (!IsAdmin)
        window.open(strURL, '', strFeatures);
}
function openGUCAIDSlideFullScreen(CAID) {
    var strURL = cursumrootpath + "/client/default.aspx?GUCAID=" + CAID;
    strFeatures = 'fullscreen=yes';

    if (!IsAdmin)
        window.open(strURL, '', strFeatures);
}

function gotoSlideFromMenu(gotoCAID, target) {
    if (gotoCAID == "")
        gotoCAID = 0;
    target = parseInt(target);
    if (!IsAdmin && parseInt(gotoCAID) > 0) {
        switch (target) {
            case 0:
                gotoSlide(gotoCAID);
                break;
            case 1:
                gotoSlideIframe(gotoCAID);
                break;
            case 2:
                window.open(cursumrootpath + "/client/default.aspx?CAID=" + gotoCAID);
                break;
            case 3:
                openSlide(gotoCAID, 400, 300, 'yes');
                break;
            case 4:
                openSlide(gotoCAID, 600, 400, 'yes');
                break;
            case 5:
                openSlide(gotoCAID, 800, 600, 'yes');
                break;
            case 6:
                openSlide(gotoCAID, 1000, 760, 'yes');
                break;
            case 7:
                openSlideFullScreen(gotoCAID);
                break;
            case 8:
                if (window.parent)
                    window.parent.location.href = cursumrootpath + "/client/default.aspx?CAID=" + gotoCAID;
                else
                    gotoSlide(gotoCAID);
                break;
            case 9:
                openSlide(gotoCAID, 400, 300, 'yes', 1);
                break;
            case 10:
                openSlide(gotoCAID, 400, 300, 'yes', 2);
                break;
            case 11:
                openSlide(gotoCAID, 264, 131, 'yes', 3);
                break;
            case 12:
                openSlide(gotoCAID, 264, 131, 'yes', 4);
                break;
            case 13:
                openSlide(gotoCAID, 264, 131, 'yes', 5);
                break;
            case 14:
                openSlide(gotoCAID, 264, 131, 'no', 6);
                break;
            default:
                gotoSlide(gotoCAID);
                break;

        }
    }
}
function gotoSlideFromSearch(gotoCAID, target) {
    if (gotoCAID == "")
        gotoCAID = 0;
    if (!IsAdmin && parseInt(gotoCAID) > 0) {
        switch (target) {
            case 0:
                gotoGUCAIDSlide(gotoCAID);
                break;
            case 1:
                gotoGUCAIDSlideIframe(gotoCAID);
                break;
            case 2:
                window.open(cursumrootpath + "/client/default.aspx?GUCAID=" + gotoCAID);
                break;
            case 3:
                openGUCAIDSlide(gotoCAID, 400, 300, 'yes');
                break;
            case 4:
                openGUCAIDSlide(gotoCAID, 600, 400, 'yes');
                break;
            case 5:
                openGUCAIDSlide(gotoCAID, 800, 600, 'yes');
                break;
            case 6:
                openGUCAIDSlide(gotoCAID, 1000, 760, 'yes');
                break;
            case 7:
                openGUCAIDSlideFullScreen(gotoCAID);
                break;
            case 8:
                if (window.parent)
                    window.parent.location.href = cursumrootpath + "/client/default.aspx?GUCAID=" + gotoCAID;
                else
                    gotoGUCAIDSlide(gotoCAID);
                break;
            case 9:
                openGUCAIDSlide(gotoCAID, 400, 300, 'yes', 1);
                break;
            case 10:
                openGUCAIDSlide(gotoCAID, 400, 300, 'yes', 2);
                break;
            case 11:
                openGUCAIDSlide(gotoCAID, 400, 300, 'yes', 3);
                break;
            case 12:
                openGUCAIDSlide(gotoCAID, 400, 300, 'yes', 4);
                break;
            case 13:
                openGUCAIDSlide(gotoCAID, 400, 300, 'yes', 5);
                break;
            case 14:
                openGUCAIDSlide(gotoCAID, 400, 300, 'yes', 6);
                break;
        }
    }
}
function gotoSlide(inID, inHeader, urlparam) {
    var strGOTO = cursumrootpath + "/client/default.aspx?CAID=" + inID;
    if (inHeader != "" && inHeader != "undefined" && inHeader != null) {
        strGOTO = strGOTO + "&HeaderMode=" + inHeader;
    }
    if (urlparam != null)
        strGOTO += urlparam;
    //if(!IsAdmin)
    window.location.assign(strGOTO);
}

function gotoNextSlide() {
    if (nextCAID != null && nextCAID > 0)
        gotoSlide(nextCAID);
}
function gotoPrevSlide() {
    if (prevCAID != null && prevCAID > 0)
        gotoSlide(prevCAID);
}
function gotoGUCAIDSlide(inID, inHeader, urlparam) {
    var strGOTO = cursumrootpath + "/client/default.aspx?GUCAID=" + inID;
    if (inHeader != "" && inHeader != "undefined" && inHeader != null) {
        strGOTO = strGOTO + "&HeaderMode=" + inHeader;
    }
    if (urlparam != null)
        strGOTO += urlparam;
    if (!IsAdmin)
        window.location = strGOTO;
}
function mOvr(src) {
    if (!src.contains(event.fromElement)) {
        src.style.cursor = 'hand';
    }
}
function mOut(src) {
    if (!src.contains(event.toElement)) {
        src.style.cursor = 'default';
    }
}
function mClk(src) {
    if (event.srcElement.tagName == 'TD' || event.srcElement.tagName == 'IMG')
        src.children.tags('A')[0].click();
}


function OnMarkerClicked(marker) {
    document.CursumMSMediaPlayer.controls.currentMarker = marker;
    document.CursumMSMediaPlayer.controls.play();
}


function SwapDivDisplay(divid, imgItem) {
    var strRoot = getRoot(imgItem.src, "/");
    var o = document.getElementById(divid);
    if (o.style.display == 'none') {
        o.style.display = 'block';
        o.style.zIndex = 999;
        imgItem.src = strRoot + '/opened_btn.gif';
    }
    else {
        o.style.display = 'none';
        o.style.zIndex = 1;
        imgItem.src = strRoot + '/closed_btn.gif';
    }
}

function SwapSpan(divid) {
    var o = document.getElementById(divid);
    if (o != null) {
        if (o.style.display == 'none')
            o.style.display = 'block';
        else
            o.style.display = 'none';
    }
}


function getRoot(string, chr) {
    var IsDone = false;
    for (var i = string.length - 1; i > -1 && !IsDone; i--)
        if (string.substring(i, i + 1) == chr) IsDone = true;
    if (IsDone) return string.substring(0, i + 2);
    else return string;
}

function openWin(inURL, inWidth, inHeight, scroll) {

    if (scroll == "")
        scroll = "no";

    xPos = screen.availHeight / 2 - (inHeight / 2);
    yPos = screen.availWidth / 2 - (inWidth / 2);

    strFeatures = 'width=' + inWidth + ',height=' + inHeight + ',top=' + xPos + ',left=' + yPos + ',statusbar=no,menubar=no,toolbar=no,resizable=yes,scrollbars=' + scroll + ',hotkeys=no';



    var oPopUpWindow = window.open(inURL, 'openCursum', strFeatures);
    if (oPopUpWindow != null)
        oPopUpWindow.focus();

}
function openAndReturnWindow(inURL, inWidth, inHeight, scroll) {

    if (scroll == "")
        scroll = "no";

    xPos = screen.availHeight / 2 - (inHeight / 2);
    yPos = screen.availWidth / 2 - (inWidth / 2);

    strFeatures = 'width=' + inWidth + ',height=' + inHeight + ',top=' + xPos + ',left=' + yPos + ',statusbar=no,menubar=no,toolbar=no,resizable=yes,scrollbars=' + scroll + ',hotkeys=no';



    var oPopUpWindow = window.open(inURL, 'openCursum', strFeatures);
    if (oPopUpWindow != null)
        oPopUpWindow.focus();

    return oPopUpWindow;

}
function openAndReturnWindowWithName(inURL, inWidth, inHeight, scroll, windowname, includeTools) {

    if (scroll == "")
        scroll = "no";

    xPos = screen.availHeight / 2 - (inHeight / 2);
    yPos = screen.availWidth / 2 - (inWidth / 2);

    if (includeTools)
        strFeatures = 'width=' + inWidth + ',height=' + inHeight + ',top=' + xPos + ',left=' + yPos + ',statusbar=yes,menubar=yes,toolbar=yes,resizable=yes,scrollbars=' + scroll + ',hotkeys=no';
    else
        strFeatures = 'width=' + inWidth + ',height=' + inHeight + ',top=' + xPos + ',left=' + yPos + ',statusbar=no,menubar=no,toolbar=no,resizable=yes,scrollbars=' + scroll + ',hotkeys=no';

    //	alert(strFeatures);

    var oPopUpWindow = window.open(inURL, windowname, strFeatures);
    if (oPopUpWindow != null)
        oPopUpWindow.focus();

    return oPopUpWindow;

}

function openFullScreenWindow(s) {

    strFeatures = 'fullscreen=yes';

    if (!IsAdmin)
        window.open(s, '', strFeatures);
}

function openWinNoName(inURL, inWidth, inHeight, scroll) {

    if (scroll == "")
        scroll = "no";

    xPos = screen.availHeight / 2 - (inHeight / 2);
    yPos = screen.availWidth / 2 - (inWidth / 2);

    strFeatures = 'width=' + inWidth + ',height=' + inHeight + ',top=' + xPos + ',left=' + yPos + ',statusbar=no,menubar=no,toolbar=no,resizable=yes,scrollbars=' + scroll + ',hotkeys=no';


    var oPopUpWindow = window.open(inURL, '', strFeatures);
    if (oPopUpWindow != null)
        oPopUpWindow.focus();

    //return oPopUpWindow;

}

function openWinNoNameAndPrint(inURL, inWidth, inHeight, scroll) {

    if (scroll == "" || scroll == null)
        scroll = "yes";

    xPos = screen.availHeight / 2 - (inHeight / 2);
    yPos = screen.availWidth / 2 - (inWidth / 2);

    strFeatures = 'width=' + inWidth + ',height=' + inHeight + ',top=' + xPos + ',left=' + yPos + ',statusbar=no,menubar=no,toolbar=no,resizable=yes,scrollbars=' + scroll + ',hotkeys=no';


    var oPopUpWindow = window.open(inURL, '', strFeatures);
    if (oPopUpWindow != null) {
        oPopUpWindow.focus();
        oPopUpWindow.print();
    }

    //return oPopUpWindow;

}
function openWinNoNameWithReturn(inURL, inWidth, inHeight, scroll) {

    if (scroll == "")
        scroll = "no";

    xPos = screen.availHeight / 2 - (inHeight / 2);
    yPos = screen.availWidth / 2 - (inWidth / 2);

    strFeatures = 'width=' + inWidth + ',height=' + inHeight + ',top=' + xPos + ',left=' + yPos + ',statusbar=no,menubar=no,toolbar=no,resizable=yes,scrollbars=' + scroll + ',hotkeys=no';


    window.open(inURL, '', strFeatures);

    return false;

}
function button_over(eButton) {
    eButton.style.backgroundColor = "#B5BDD6";
    eButton.style.borderColor = "darkblue darkblue darkblue darkblue";
}
function button_out(eButton) {
    eButton.style.backgroundColor = "threedface";
    eButton.style.borderColor = "threedface";
}
function button_outColor(eButton, c, bordercolor) {
    eButton.style.backgroundColor = c;
    eButton.style.borderColor = c;
    if (bordercolor != null)
        eButton.style.borderColor = bordercolor;
}
function button_down(eButton) {
    eButton.style.backgroundColor = "#8494B5";
    eButton.style.borderColor = "darkblue darkblue darkblue darkblue";
}
function button_up(eButton) {
    eButton.style.backgroundColor = "#B5BDD6";
    eButton.style.borderColor = "darkblue darkblue darkblue darkblue";
    eButton = null;
}

function replace(string, text, by) {
    // Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0, txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0, i) + by;

    if (i + txtLength < strLength)
        newstr += replace(string.substring(i + txtLength, strLength), text, by);

    return newstr;
}
function windowFocus() {
    window.focus();
}
function resizemeprint(img, parentid) {
    if (document.all) {
        var x = window.parent.document.getElementById(parentid);
        if (x != null) {
            var pos = findPosition(img);
            x.style.height = pos[0] + 60;
            if (parseInt(x.style.width) < parseInt(pos[1]))
                x.style.width = pos[1] + 20;
        }
    }
}
function printMultipage(coll) {
    win = openAndReturnWindow('utils/printer.aspx?CAIDColletion=' + coll, 900, 750, 'yes');
    win.print();
}
function winStatus(text) {
    window.status = text;
    return true;
}

function winCloser() {
    if (opener != null)
        opener.location.href = opener.location.href;
    window.top.close();
}

function winCloserRel(path) {
    opener.location.href = path;
    this.close();
}


function InputLengthChk(inputElement, length) {
    if (inputElement.value.length > length)
        alert('Max number of charecters allowed ' + length + '\n\nPlease only use max ' + length + ' charecters');
}

function MinInputLengthChk(inputElement, length) {
    if (inputElement.value.length < length)
        alert('Minimum ' + length + ' characters is required\n\nPlease use at least ' + length + ' charecters');
}
function swapImgRestore() { //v3.0
    var i, x, a = document.sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}

function preloadImages() { //v3.0
    var d = document; if (d.images) {
        if (!d.p) d.p = new Array();
        var i, j = d.p.length, a = preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.p[j] = new Image; d.p[j++].src = a[i]; }
    }
}

function findObj(n, d) { //v4.0
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = findObj(n, d.layers[i].document);
    if (!x && document.all) x = document.all(n); return x;
}

function swapImage() { //v3.0
    var i, j = 0, x, a = swapImage.arguments; document.sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
        if ((x = findObj(a[i])) != null) { document.sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
}
function openOnlineMessage(Action) {
    openWinNoName(cursumrootpath + '/client/AssetViewer.aspx?AssetID=-1&AssetMediaTypeID=27&Action=' + Action, 900, 700, 'yes');
    return false;
}
function openOnlineMessageEditor(UserGUID) {
    openWinNoName(cursumrootpath + '/client/AssetViewer.aspx?AssetID=-1&AssetMediaTypeID=27&Action=CreateNewMessage&ReceiverUserGUID=' + UserGUID, 900, 700, 'yes');
    return false;
}
function openUserPrefs() {
    openWinNoName(cursumrootpath + '/client/AssetViewer.aspx?AssetID=-1&AssetMediaTypeID=29', 740, 555, 'yes');
    return false;
}
function StopWMP() {
    if (document.CursumMSMediaPlayer)
        document.CursumMSMediaPlayer.controls.stop();
}
function OpenAskInstructorEditor() {
    openWinNoName('AssetViewer.aspx?AssetID=-1&AssetMediaTypeID=32', 700, 500);
}

function SwapMySurveyElements(id) {
    var eid1 = 'SurveyOptionSeperatorHTML_' + id;
    SwapSpan(eid1)
    var eid2 = 'SurveyOption_' + id;
    SwapSpan(eid2)
}
function ChangeActiveCourseFromMenu(courseid, target, ifrmDomID) {
    if (!IsAdmin && parseInt(courseid) > 0) {
        openCourseUrl(cursumrootpath + '/client/CursumTransferer.aspx?Action=ChangeActiveCourse&ReturnToAdmin=false&ActiveCourseID=' + courseid, target, ifrmDomID);
    }
}
function openCourseUrl(courseurl, target) {
    switch (parseInt(target)) {
        case 0:
            window.parent.location.href = courseurl;
            break;
        case 1:
            if (ifrmDomID != null)
                document.getElementById(ifrmDomID).src = courseurl;
            else
                window.CURSUMIFRAME.location = courseurl;
            break;
        case 2:
            window.open(courseurl);
            break;
        case 3:
            openWinNoName(courseurl, 400, 300, 'yes');
            break;
        case 4:
            openWinNoName(courseurl, 600, 400, 'yes');
            break;
        case 5:
            openWinNoName(courseurl, 800, 600, 'yes');
            break;
        case 6:
            openWinNoName(courseurl, 1000, 760, 'yes');
            break;
        case 7:
            window.open(courseurl, '', 'fullscreen=yes');
            break;
        case 8:
            window.parent.location.href = courseurl;
            break;
        default:
            window.parent.location.href = courseurl;
            break;

    }
}
function ChangeActiveCourse(courseid, target) {
    if (!IsAdmin) {
        if (target != null) {
            var targetWindow = eval("window.top." + target);
            if (targetWindow != null)
                targetWindow.location.href = cursumrootpath + '/client/CursumTransferer.aspx?Action=ChangeActiveCourse&ReturnToAdmin=false&ActiveCourseID=' + courseid;
            else
                window.parent.location.href = cursumrootpath + '/client/CursumTransferer.aspx?Action=ChangeActiveCourse&ReturnToAdmin=false&ActiveCourseID=' + courseid;

        }
        else
            window.parent.location.href = cursumrootpath + '/client/CursumTransferer.aspx?Action=ChangeActiveCourse&ReturnToAdmin=false&ActiveCourseID=' + courseid;
    }
}

function ChangeActiveCourseByAncestorID(courseid, target, ifrmDomID) {
    if (!IsAdmin && parseInt(courseid) > 0) {
        openCourseUrl(cursumrootpath + '/client/CursumTransferer.aspx?Action=ChangeActiveCourseByAncestorID&ReturnToAdmin=false&ActiveCourseID=' + courseid, target, ifrmDomID);
    }
}

function OpenPersonalFileExplorer(sPath) {
    if (sPath != '');
    openWinNoName(cursumrootpath + '/admin/slidetools/SiteExplorer.aspx?ExpandLevel=2&HeaderText=PersonalExplorer&BaseFolder=' + sPath, 800, 600, 'yes');
    return false;
}
function DisplayOptionText(o, sID) {
    var ddl = document.getElementById(sID);
    if (ddl && o.selectedIndex > -1)
        ddl.innerHTML = o[o.selectedIndex].text;
}


function fnPrintElementContent(elem, convertTextBoxes, addAdminCss) {
    convertTextBoxes = true;
    var oContent = document.getElementById(elem);
    var whatToPrint = "";
    var Iframecontent = "";
    var iFrameSrc = "";
    if (oContent != null) {
        if (oContent.innerHTML.toLowerCase().indexOf('iframe') > -1) {
            var myColls = oContent.getElementsByTagName('iframe');
            if (myColls.length > 0) {

                for (i = 0; i < myColls.length; i++) {
                    if (myColls[i].id != "") {
                        if (convertTextBoxes == true) {
                            var output = document.getElementById(myColls[i].id).contentWindow.document.body.cloneNode(true);
                            var tags = output.getElementsByTagName('TextArea');
                            for (p = 0; p < tags.length; p++) {
                                tags[p].value = tags[p].value.replace(/\n/gi, "cursumbreak");
                            }
                            Iframecontent += output.innerHTML;

                        }
                        //Iframecontent += output.document.body.innerHTML.replace(/<textarea/gi,'<span').replace(/<\/texarea>/gi,'</span>').replace(/cursumbreak/gi,"<br>");
                    }
                    else {
                        Iframecontent += document.getElementById(myColls[i].id).contentWindow.document.body.innerHTML + "<!-- Element -->";
                    }
                }
                Iframecontent = Iframecontent.replace(/<textarea/gi, '<span').replace(/<\/textarea>/gi, '</span>').replace(/cursumbreak/gi, "<br>");
            }
            else {
                for (i = 0; i < document.getElementsByTagName('link').length; i++)
                    Iframecontent += document.getElementsByTagName('link')[i].outerHTML;
                for (i = 0; i < document.getElementsByTagName('SCRIPT').length; i++) {
                    if (document.getElementsByTagName('SCRIPT')[i].src != null && document.getElementsByTagName('SCRIPT')[i].src.length > 0) {
                        Iframecontent += document.getElementsByTagName('SCRIPT')[i].outerHTML;
                    }
                }

                if (myColls[0].contentWindow != null) {
                    Iframecontent += myColls[0].contentWindow.document.body.innerHTML;
                }
                else {
                    Iframecontent += myColls[0].document.body.innerHTML;
                }
            }
        }

        if (Iframecontent != "") {
            whatToPrint = Iframecontent;
        }
        else {
            if (convertTextBoxes == true) {
                var output = oContent.cloneNode(true);

                var tagsoforig = oContent.getElementsByTagName('select');
                var tagsofclone = output.getElementsByTagName('select');

                for (pO = 0; pO < tagsoforig.length; pO++) {
                    tagsofclone[pO].selectedIndex = tagsoforig[pO].selectedIndex;
                }
                
                var tags = output.getElementsByTagName('TextArea');
                for (p = 0; p < tags.length; p++) {
                    tags[p].value = tags[p].value.replace(/\n/gi, "cursumbreak");
                }
                
                output = output.innerHTML.replace(/<textarea/gi, '<span').replace(/<\/texarea>/gi, '</span>').replace(/cursumbreak/gi, "<br>");
            }
            else
                output = oContent.innerHTML;
            whatToPrint = output;
        }
        if (iFrameSrc != "") {
            win01 = window.open(iFrameSrc);
            win01.print();
        }
        else {
            winprintMessage = window.open('', 'newwin');
            with (winprintMessage.document) {
                if (addAdminCss != null && addAdminCss == true)
                    write('<LINK href="' + cursumrootpath + '/css/cursumAdminSiteStyles.css" type="text/css" rel="stylesheet"><body onLoad="window.focus();window.print()">' + whatToPrint + '<\/body>');
                write('<body onLoad="window.focus();window.print()">' + whatToPrint + '<\/body>');
                close();
            }
        }
    }
}

//Play a sound
function PlaySound(soundobj) {

    var thissound = document.getElementById(soundobj);

    thissound.Play();

}

//Stop a sound
function StopSound(soundobj) {

    var thissound = document.getElementById(soundobj);

    thissound.Stop();

}

function printThisAsset(elm) {
    var elmcurrent = elm;
    var itemFound = false;
    while (elmcurrent.parentNode != null && itemFound == false) {
        if (elmcurrent.attributes["IsAssetContainer"] != null) {
            oAttrColl = elmcurrent.attributes;
            for (i = 0; i < oAttrColl.length; i++) {
                oAttr = oAttrColl.item(i);
                if (oAttr.nodeValue == 'true') {
                    fnPrintElementContent(elmcurrent.id);
                    itemFound = true;
                }
            }
        }
        elmcurrent = elmcurrent.parentNode;
    }
    return false;
}

function findPosition(oLink) {
    if (oLink.offsetParent) {
        for (var posX = 0, posY = 0; oLink.offsetParent; oLink = oLink.offsetParent) {
            posX += oLink.offsetLeft;
            posY += oLink.offsetTop;
        }
        return [posY, posX];
    } else {
        return [oLink.y, oLink.x];
    }
}

function CursumResizePage(img) {
    if (document.all) {
        var x = window.parent.document.getElementById('ConferenceForumFrame');
        if (x != null) {
            var pos = findPosition(img);
            //alert(pos[1]);
            x.style.height = pos[0] + 60;
            if (parseInt(x.style.width) < parseInt(pos[1]))
                x.style.width = pos[1] + 20;
        }
    }
}




function IDInfo() {

    if (window.event.srcElement.tagName != null) {
        ststag.innerText = "<" + window.event.srcElement.tagName
+ ">";

    }

    else {

        ststag.innerText = "";

    }

    if (window.event.srcElement.id != null) {

        stsid.innerText = window.event.srcElement.id;

    }

    else {
        stsid.innerText = "";

    }

    /* if (window.event.srcElement.name != null)
 
     {
 
         stsname.innerText = window.event.srcElement.name;
 
     }
 
     else
 
     {
 
         stsname.innerText = "";
 
     }
    */
    if (window.event.srcElement != null) {

        var currElem = window.event.srcElement;

        var classTree = '';

        do {

            if (currElem.className != null && currElem.className != '') {

                if (classTree != '') {

                    classTree = currElem.className + "->" + classTree;

                }

                else {

                    classTree = currElem.className;

                }

            }



            currElem = currElem.parentElement;

        } while (currElem != null);

        stsclass.innerText = classTree;

    }

    else {

        stsclass.innerText = "";

    }

}


function Search(e) {
    var s = document.getElementById('search_forums');
    s.style.pixelLeft = tempX - 0;
    s.style.pixelTop = tempY + 15;
    if (s.style.display == "none")
        s.style.display = "block";
    else
        s.style.display = "none";
}

var tempX, tempY;
function getMouseXY(e) {
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
}

function CheckForCompletion() {
    myWin.document.close();
    myWin.document.open();
    myWin.document.write('Lukker om ' + i + ' sekunder');
    i--;
    if (i == 0) {
        myWin.close();
        myWin = null;
        clearInterval(timerID);
    }
}
var myWin;
var timerID;
var i = 10;
function SpawnReport(path, winName, props, closeWinOnComplete) {
    myWin = window.open(path);
    //myWin.document.write("<table width=200 border=0><tr><td><div id=dv></div></tr></td></table>");
    //myWin.document.onload = timerID = setInterval('CheckForCompletion()',1000);
}

function ShowPrintWindowAndTranslateTextBoxes() {

}
function fnIndexerGoto(iType, iCAID, iTarget, sRedirect_Value, iTemplateID) {
    if (overrideLinkTarget != null && overrideLinkTarget > -1)
        iTarget = overrideLinkTarget;
    switch (iType) {
        case 7:
            gotoSlideFromMenu(sRedirect_Value, iTarget);
            break;
        case 8:
            window.top.location.href = '../logout.aspx';
            break;
        case 9:
            if (sRedirect_Value != "")
                eval(sRedirect_Value);
            break;
        default:
            if (iTemplateID > 0) {
                gotoSlideFromMenu(iCAID, iTarget);
            }
            break;
    }
}
function HandleOnClose() {

}

function HandleOnLoad() {
}



function EmbedCursumFlash(path, width, height, fp_ver, param) {
    if (fp_ver == null)
        fp_ver = '6';

    document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + fp_ver + ',0,0,0" ID="bridge" WIDTH=' + width + ' HEIGHT=' + height + '>');
    document.write('     <PARAM NAME=allowScriptAccess value=sameDomain>');
    document.write('     <PARAM NAME=movie VALUE="' + path + '">');
    document.write('     <PARAM NAME=quality VALUE=high>');
    document.write(param);
    document.write('<EMBED src="' + path + '" quality=high bgcolor=#CCCCC WIDTH=' + width + ' HEIGHT=' + height + ' swLiveConnect=true NAME="bridge" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">');
    document.write('</EMBED>');
    document.write('</OBJECT>');
}
function fnNLCSetCookie(cookieName, cookieValue) {
    document.cookie = cookieName + "=" + cookieValue + ";";
}
function fnNLCGetCookie(Name) {
    var search = Name + "="
    var returnvalue = null;
    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;
}

// Michael Candelaria ( 01/25/2008 ) Masking functionalities [ start ]

// simple RegEx patterns to make life easy.

var reOneOrMoreDigits = /[\d+]/;
var reNoDigits = /[^\d]/gi;

function doMask(textBox) {
    var keyCode = event.which ? event.which : event.keyCode;
    // enter, backspace, delete and tab keys are allowed thru
    if (keyCode == 13 || keyCode == 8 || keyCode == 9 || keyCode == 46)
        return true;
    // get character from keyCode....dealing with the "Numeric KeyPad" 
    // keyCodes so that it can be used
    var keyCharacter = cleanKeyCode(keyCode);
    // grab the textBox value and the mask
    var val = textBox.value;
    var mask = textBox.mask;
    // simple Regex to check if key is a digit
    if (reOneOrMoreDigits.test(keyCharacter) == false)
        return false;
    // get value minus any masking by removing all non-numerics
    val = val.replace(reNoDigits, '');
    // add current keystroke
    val += keyCharacter;
    // mask it...val holds the existing TextBox.value + the current keystroke
    textBox.value = val.maskValue(mask);
    setCaretAtEnd(textBox);
    return false;
}

// puts starting chars in field
function onFocusMask(textBox) {
    var val = textBox.value;
    var mask = textBox.mask;
    if (val.length == 0 || val == null) {
        var i = mask.indexOf('#');
        textBox.value = mask.substring(0, i);
    }
    setCaretAtEnd(textBox);
    // set just in case.
    textBox.maxlength = mask.length;
}

// blank field if no digits entered
function onBlurMask(textBox) {
    var val = textBox.value;
    // if no digits....nada entered.....blank it.
    if (reOneOrMoreDigits.test(val) == false) {
        textBox.value = '';
    }
}

String.prototype.maskValue = function(mask) {
    var retVal = mask;
    var val = this;
    //loop thru mask and replace #'s with current value one at a time
    // better way of doing this ???
    for (var i = 0; i < val.length; i++) {

        retVal = retVal.replace(/#/i, val.charAt(i));

    }

    // get rid of rest of #'s
    retVal = retVal.replace(/#/gi, "");
    return retVal;
}

// The Numeric KeyPad returns keyCodes that ain't all that workable.
// ie: KeyPad '1' returns keyCode 97 which String.fromCharCode converts to an 'a'.
// This cheesy way allows the Numeric KeyPad to be used

function cleanKeyCode(key) {
    switch (key) {
        case 96: return "0"; break;
        case 97: return "1"; break;
        case 98: return "2"; break;
        case 99: return "3"; break;
        case 100: return "4"; break;
        case 101: return "5"; break;
        case 102: return "6"; break;
        case 103: return "7"; break;
        case 104: return "8"; break;
        case 105: return "9"; break;
        default: return String.fromCharCode(key); break;
    }
}

function setCaretAtEnd(field) {
    if (field.createTextRange) {
        var r = field.createTextRange();
        r.moveStart('character', field.value.length);
        r.collapse();
        r.select();
    }
}
function GetRadWindow() {
    var oWindow = null;
    if (window.radWindow) oWindow = window.radWindow; //Will work in Moz in all cases, including classic dialog
    else if (window.frameElement && window.frameElement.radWindow) oWindow = window.frameElement.radWindow; //IE (and Moz as well)
    else oWindow = window.opener;
    return oWindow;
}
function GetRadBrowserWindow() {
    var oWindow = null;
    if (window.radWindow) oWindow = window.radWindow.BrowserWindow; //Will work in Moz in all cases, including classic dialog
    else if (window.frameElement && window.frameElement.radWindow) oWindow = window.frameElement.radWindow.BrowserWindow; //IE (and Moz as well)
    else oWindow = window.opener;
    return oWindow;
}
// Michael Candelaria ( 01/25/2008 ) Masking functionalities [ end ]


//Add script to check errors for Silverlight Component
//Begin

function onSilverlightError(sender, args) {

    var appSource = "";
    if (sender != null && sender != 0) {
        appSource = sender.getHost().Source;
    }
    var errorType = args.ErrorType;
    var iErrorCode = args.ErrorCode;

    var errMsg = "Unhandled Error in Silverlight 2 Application " + appSource + "\n";

    errMsg += "Code: " + iErrorCode + "    \n";
    errMsg += "Category: " + errorType + "       \n";
    errMsg += "Message: " + args.ErrorMessage + "     \n";

    if (errorType == "ParserError") {
        errMsg += "File: " + args.xamlFile + "     \n";
        errMsg += "Line: " + args.lineNumber + "     \n";
        errMsg += "Position: " + args.charPosition + "     \n";
    }
    else if (errorType == "RuntimeError") {
        if (args.lineNumber != 0) {
            errMsg += "Line: " + args.lineNumber + "     \n";
            errMsg += "Position: " + args.charPosition + "     \n";
        }
        errMsg += "MethodName: " + args.methodName + "     \n";
    }

    throw new Error(errMsg);
}


function isCtrlPressed() {
    var key;
    var isCtrl = false;

    if (window.event) {
        key = window.event.keyCode; //IE
        if (window.event.ctrlKey)
            isCtrl = true;
        else
            isCtrl = false;
    }

    return isCtrl;
}

function setIframeHeight(iframeElement) {
    //var iframeWin = window.frames[iframeName];
    var iframeEl = document.getElementById ? document.getElementById(iframeElement) : document.all ? document.all[iframeElement] : null;
    if (iframeEl) {
        iframeEl.style.height = "auto"; // helps resize (for some) if new doc shorter than previous
        //var docHt = getDocHeight(iframeWin.document);
        // need to add to height to be sure it will all show
        var h = getHeightSize();
        var new_h = (h - 148);
        iframeEl.style.height = new_h + "px";
        //getHeightSize();
    }
}

function getHeightSize() {
    var myHeight = 0;
    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        myHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        myHeight = document.body.clientHeight;
    }
    //window.alert( 'Height = ' + myHeight );
    return myHeight;
}


function UserFieldValidate(source, arguments, myarray) {
    IsValid = true
    switch (myarray[0]) {
        case "FixedLength":
            IsValid = (arguments.Value.length == parseInt(myarray[1]));
            arguments.IsValid = IsValid
            break;
        case "MaxLength":
            IsValid = (arguments.Value.length < parseInt(myarray[1]));
            arguments.IsValid = IsValid
            break;
        case "EndsWith":
            for (x = 1; x <= myarray[1].length; x++) {
                if (arguments.Value.charAt(arguments.Value.length - x) != myarray[1].charAt(myarray[1].length - x)) {
                    IsValid = false
                    break;
                }
            }
            arguments.IsValid = IsValid
            break;
        case "StartsWith":
            for (x = 0; x < myarray[1].length; x++) {
                if (arguments.Value.charAt(x) != myarray[1].charAt(x)) {
                    IsValid = false
                    break;
                }
            }
            arguments.IsValid = IsValid
            break;
        case "None":
            arguments.IsValid = true
            break;
        case "Contains":
            if (arguments.Value.indexOf(myarray[1]) == -1) {
                arguments.IsValid = false
            }
            else {
                arguments.IsValid = true
            }
            break;
    }
} 