﻿// JScript File


var Addon_Options_Initialized = false;

function Addon_Options_Activate() {
    if (!Addon_Options_Initialized) {
        try {
            Addon_Options_Initialized = true;
        } catch (Ex) { }
    }
}

function Addon_Options_doEvent(aCmd, aValue) {
    if (aCmd == "LANGUAGE") {
        theCookie.set("Language", aValue)
        var newLocation = document.location.toString();
        var newQuerystring = "";

        if (newLocation.indexOf("?") > 0) {
            var q = newLocation.split("?")[1];
            newLocation = newLocation.split("?")[0];
            if (q.indexOf("&") > 0) {
                var vars = q.split("&");
                for (var i = 0; i < vars.length; i++) {
                    if (vars[i].split("=")[0] == "lid") vars[i] = "lid=" + aValue;
                    newQuerystring += vars[i];
                    if (i < vars.length - 1) newQuerystring += "&";
                }
            } else {
                newQuerystring = q;
            }
        }
        document.location = newLocation + "?" + newQuerystring;
    }
    if (aCmd == "BITRATE") {
        //DoDebug("br:"+ theCookie.get("Bitrate") );
        document.getElementById("bitrate_" + theBitrateId + "_Div").className = "cwc_Check";
        theCookie.set("Bitrate", aValue);
        theBitrateId = aValue;
        document.getElementById("bitrate_" + theBitrateId + "_Div").className = "cwc_Check-a";
        DoPlayList();
    }
    if (aCmd == "DOWNLOAD") {
        if (aValue == "PDF") {
            window.open("DownloadHandler.ashx?l=" + FindInDoubleArray(theLanguageId, theLanguages, 1) +
                "&wid=" + theWebcastId + "&t=slides_pdf", "", "scrollbars=no,resizable=no, status=yes,width=100,height=100");
        }
        if (aValue == "MP3") {
            window.open("DownloadHandler.ashx?l=" + FindInDoubleArray(theLanguageId, theLanguages, 1) +
                "&b=" + FindInDoubleArray(theBitrateId, theBitrates, 1) + "&wid=" + theWebcastId + "&t=webcast_mp3", "", "scrollbars=no,resizable=no, status=yes,width=100,height=100");
        }
    }
    if (aCmd == "SENDTOFRIEND") {
        PlayerService_QueueServerEvent("getsendtofriendtext", null, PlayerService_Priority.high, Addon_Options_SendToFriend);
    }
    if (aCmd == "BOOKMARK") {
        try {
            window.external.AddFavorite('http://pulse.companywebcast.nl/Playerv1_0/default.aspx?id=' + theWebcastId, theWebcastTitle);
        } catch (e) { }
    }
}

function Addon_Options_SendToFriend(result) {
    try {
        var myText = eval(result.Values["sendtofriend"]);
        var outp = "";
        outp += '<table cellpadding="0" cellspacing="0" border="0">';
        outp += '<tr><td colspan="2"><b>' + myText[0] + '</b></td></tr>'
        outp += '<tr><td >' + myText[1] + '</td><td><input id="s2f_name" name="s2f_name" type="text"></td></tr>';
        outp += '<tr><td>' + myText[2] + '</td><td><input id="s2f_email" name="s2f_email" type="text"></td></tr>';
        outp += '<tr><td colspan="2"><br><b>' + myText[3] + '</b></td></tr>';
        outp += '<tr><td >' + myText[4] + '</td><td><input id="s2f_name_recep" name="s2f_name_recep" type="text"></td></tr>';
        outp += '<tr><td >' + myText[5] + '</td><td><input id="s2f_email_recep" name="s2f_email_recep" type="text"></td></tr>';
        outp += '<tr><td colspan="2"><br><b>' + myText[6] + '</b></td></tr>';
        outp += '<tr><td></td><td><textarea name="s2f_body" id="s2f_body" style="width:350px;height:120px;"></textarea></td></tr>';
        outp += '<tr><td></td>';
        outp += '<td><input type="button" value="' + myText[7] + '" onclick="Addon_Options_SendToFriend_Submit();">';
        outp += '<input type="button" value="' + myText[8] + '" onclick={theView.HidePopup("sendtofriend");}></td>';
        outp += '</tr></table>';
        theView.ShowPopup(myText[9], outp,"sendtofriend");
    } catch (ex) { }
}

function Addon_Options_SendToFriend_Submit() {
    PlayerService_QueueServerEvent(
        "sendtofriend", {
            "senderName": document.getElementById("s2f_name").value,
            "senderEmail": document.getElementById("s2f_email").value,
            "recieverName": document.getElementById("s2f_name_recep").value,
            "recieverEmail": document.getElementById("s2f_email_recep").value,
            "message": document.getElementById("s2f_body").value
        },
        PlayerService_Priority.high,
        Addon_Options_SendToFriend_Submitted);
    theView.HidePopup("sendtofriend");
}

function Addon_Options_SendToFriend_Submitted(result) {
    alert(result.Values["sendtofriend"].substr(2));
    if (result.Values["sendtofriend"].substr(0, 1) != "0") theView.HidePopup("sendtofriend");
}
