
function checkAuswahl(uName) {
    
    eval('locAnzahl = document.' + uName + 'form.' + uName + '.length');
    for(i=0; i < locAnzahl; i++) {
        eval('locSelect = document.' + uName + 'form.' + uName + '.options[i].selected');
        if(locSelect == true) {
            eval('locValue = document.' + uName + 'form.' + uName + '.options[i].value');
            if (locValue != "") {
                locTarget = locValue.split("|");
                if(locTarget.length > 1)
                {
                 if(locTarget[0] != "")
                 {
                  Fenster1 = window.open(locTarget[0], "Seite");
                 }
                }
                else
                {
                 location.href = locValue;
                }
            }
        }
    }
}
function openPopup(uHREF, uName, uWidth, uHeight, uScrollbars, uResizable) {
    
    
    locParams =
        "width="      + uWidth                     + "," +
        "height="     + uHeight                    + "," +
        "scrollbars=" + ((uScrollbars)?"yes":"no") + "," +
        "resizable="  + ((uResizable)?"yes":"no")  + "," +
        "caption=no," +
        "menubar=no," +
        "toolbar=no," +
        "status=yes," +
        "location=no";
    locWindow = window.open(uHREF, uName, locParams);
    //locWindow.focus();
    
}
function openDetailPopUp(uId, uImage, uText) {
    
    openPopup("/web/cms/static/js/91.jsp?image="+ uImage + "&text=" + uText, "detailpopup", 330, 380, false, false);
}
function openDetailPopUpWithPath(uId, uImage, uText, uPath) {
    
    openPopup("/web/cms/static/js/91.jsp?image="+ uImage + "&text=" + uText + "&menuepath=" + escape(uPath), "detailpopup", 330, 380, false, false);
}
function openPIP(uEventNr)
{
    
    openPopup("/web/cms/de/modules/pip/de.premiere.modules.tvguide.pip.standard.jsp?eventNr=" + uEventNr, "tvpremieren", 475, 350, false, false);
}
 
function OpenPopUp_KontoauszugEbene3(strLink, strEntryNo, uName, uWidth, uHeight, uScrollbars, uResizable) 
{ 
    
    
    openPopup(strLink+"?entryNo="+strEntryNo, uName, uWidth, uHeight, uScrollbars, uResizable);
}

function Blotter()
{
    this.blotterTab = [];
    this.blotterRegister = [];
    this.startTab = "";
    this.startRegister = "";
    this.setStartTab = function(tab, register) {
        this.startTab = tab;
        this.startRegister = register;
    }
    this.showStartTab = function(tab, register) {
        this.closeAllTabs();
        this.setStartTab(tab, register);
        document.getElementById(this.startTab).className = "active";
        document.getElementById(this.startRegister).style.display = "block";
    }
    this.addTab = function(tab, register) {
        this.blotterTab.push(tab);
        this.blotterRegister.push(register);
    }
    this.showTab = function(tab, register) {
        this.closeAllTabs()
        document.getElementById(tab).className = "active";
        document.getElementById(register).style.display = "block";
    }
    this.closeAllTabs = function() {
        var blotterRegisterCount = this.blotterRegister.length;
        for (var i = 0; i < blotterRegisterCount; i++) {
            document.getElementById(this.blotterRegister[i]).className = "";
        }
        var blotterTabCount = this.blotterTab.length;
        for (var i = 0; i < blotterTabCount; i++) {
            document.getElementById(this.blotterTab[i]).style.display = "none";;
        }
    }
}

function singleSubmit(formName,formField){
 if(document.forms[formName].elements[formField].value == "0"){
  document.forms[formName].elements[formField].value = "1";
  return true;
 } else {
  return false;
 }
}
function singleSubmitDisable(form, flagName, submitButtonName) {
 if (form.elements[flagName].value == "0") {
  form.elements[flagName].value = "1";
  form.elements[submitButtonName].disabled = true;
  return true;
 } else {
  return false;
 }
}
 
//Setzen der ordahl für adTags
ord=Math.random()*100000000000;
function startMerklistenRequest(request, sessionId) {
    $.ajax({
        type: "POST",
        url: "/web/watchlist.servlet;jsessionid=" + sessionId,
        cache: false,
        dataType: "xml",
        processData: false,
        contentType:"text/xml",
        success: function(data, textStatus) {
            fillMerkliste(data);
        },
        complete: function(data, textStatus) {
            //alert(data.responseText);
        },    
        data: encodeURIComponent(request)
    });
}

function fillMerkliste(data) {
    code = $(data).find("code").length > 0 ? $(data).find("code").text()  : "20001"; 
    if(code == "0") {
        $("#merklisteInhalt").html("");
        $("#merklisteFehler").hide();
        $("#merklisteKeinEintrag").hide();
        var merklistenInhalt = "<h2>Ihre vorgemerkten Programmhighlights:</h2>";
         
        $(data).find("watchlist").each(function(merkIndex) {
            if(merkIndex < 5) {
                var ausstrahlungId = $(this).attr("ausstrahlungId");
                var broadcastDate = $(this).attr("broadcastDate");
                var broadcastTime = $(this).attr("broadcastTime");
                var senderLayerUrl = $(this).attr("senderLayerUrl");
                var siEventtitel = $(this).attr("siEventtitel");
                var stationName = $(this).attr("stationName");
                var stationUrl = $(this).attr("stationUrl");
                var watchlistId = $(this).attr("watchlistId");
                var deleteAction = "setDeleteParam('"+watchlistId+"','delete','merkliste.boundary.addMemoryEntrysForm');";
                var detailSeite = "/web/cms/de/modules/pip/de.premiere.modules.tvguide.pip.jsp?ausstrahlungsID=" + ausstrahlungId;
                merklistenInhalt += "\n<!-- START Merklisten-Eintrag -->\n";
                merklistenInhalt += "<div class=\"merkliste_eintrag";
                merklistenInhalt += "\">\n";
                    merklistenInhalt += "<h3><a href=\"" + detailSeite + "&TB_iframe=true&height=570&width=600\" class=\"thickbox\">" + siEventtitel + "</a></h3>\n";
                    merklistenInhalt +=  broadcastDate + ", " + broadcastTime + " Uhr<br />\n";
                    if (stationUrl != "") {
                        merklistenInhalt += "<a href=\"" + stationUrl + "\">" + stationName + "</a>\n";
                    }
                    else {
                        merklistenInhalt += stationName;
                    }
                    merklistenInhalt += "<br />\n";
                    merklistenInhalt += "<input type=\"checkbox\" id=\"merk_chekbox" + merkIndex + "\" name=\"selectedEventEntrys\" value=\"" + watchlistId + "\" style=\"display:none;\" />\n";
                    merklistenInhalt += "<input type=\"hidden\" name=\"hdnTellFriends\" value=\"0\" />\n";
                    merklistenInhalt += "<a class=\"merkliste_delete\" title=\"Merklisteneintrag l&ouml;schen\" href=\"#\" onclick=\"" + deleteAction + "\"><span>Merklisteneintrag löschen</span></a>\n";
                    merklistenInhalt += "<a class=\"merkliste_recommend\" title=\"Weitersagen\" href=\"#\" onclick=\"javascript:submitForm('1','" + merkIndex + "')\"><span>Weitersagen</span></a>\n";
                    merklistenInhalt += "<a class=\"merkliste_alert\" title=\"Erinnern\" href=\"#\" onclick=\"javascript:submitForm('0','" + merkIndex + "')\"><span>Erinnern</span></a>\n";
                merklistenInhalt += "</div>\n";
            }
       });
        merklistenInhalt += "<div class=\"clearer\"></div><a href=\"/web/cms/de/kundencenter-meinsky-merkliste.jsp\" class=\"weiter\">Vollständige Merkliste</a>";
        $("#merklisteInhalt").append(merklistenInhalt);
        tb_init('#merklisteInhalt a.thickbox');
        alert("Die Sendung wurde in die Merkliste eingetragen.");
    }
    else if (code == "2") {
        alert("Der Ausstrahlungszeitpunkt dieser Sendung ist bereits verstrichen. Die Sendung wurde nicht in die Merkliste eingetragen.");
    }
    else if (code == "3") {
        alert("Die Sendung befindet sich bereits in der Merkliste.");
    }    
    else if ((code*1) > 10000) {
        alert("Bei der Verarbeitung der Merkliste ist ein Fehler aufgetreten: Fehlercode " + code);
    }    
}

function openLayer(url, width, height) {
    thisUrl = url.indexOf("?") == -1 ? url+"?TB_iframe=true&width="+width+"&height="+height : url+"&TB_iframe=true&width="+width+"&height="+height;
    tb_show(null,thisUrl, false);
}    
$(document).ready(function() {
    if(typeof document.body.style.maxHeight === "undefined")
        $(".SubNav li, #quickdone li, #quickdone2 li").each(function() { 
        
            that = $(this);
            $(that).bind("mouseenter", function() {
                $(this).addClass("sfhover");
            });
            $(that).bind("mouseleave", function() {
                $(this).removeClass("sfhover");
            });
        });    
    $("#tvGuideCalendarToggle").bind("mouseenter", function(event) {
        $("#tvGuideZeitDropdown").hide(); 
        $("#tvGuideCalendar").show().bind("mouseleave", function(event) {
            $("#tvGuideCalendar").hide();
            $("#tvGuideZeitDropdown").show();
        });
    });
    $("#tvGuideFilterToggle").bind("mouseenter", function(event) {
    $("#tvGuideZeitDropdown").hide();
        $("#tvGuideFilter").show().bind("mouseleave", function(event) {
            $("#tvGuideFilter").hide();
            $("#tvGuideZeitDropdown").show();
            
        });
    });
// Einblenden des Kundelogins und einem Layer und Ausblenden durch Klick außerhalb des Logins

    var loginHtml = $("#rightLogin").html();
    $("#rightLogin").remove();
    $("#helpLogin").append("<div id='rightLogin' style='display:none;'>" + loginHtml + "</div>");
    if ($("span#KNRToolTip").length > 0 ) {
        $("span#KNRToolTip").tooltip({
            track: true,
            delay: 0,
            showURL: false,
            showBody: "|"
        });
    }
    if ($("span#PINToolTip").length > 0 ) {
        $("span#PINToolTip").tooltip({
            track: true,
            delay: 0,
            showURL: false,
            showBody: "|"
        });
    }
    $("a.merkliste").bind("mouseenter",function() {
        if($("#merklisteInhalt .merkliste_eintrag").length > 1) {
            $("#tvGuideZeitDropdown").hide();
        }
        $("#but_merkliste").show();
        $("#but_merkliste").bind("mouseleave",function() {
            $("#tvGuideZeitDropdown").show();
            $("#but_merkliste").hide();
        });
    });
    $("body").bind("click", function() {$("#rightLogin").hide();});
    $("#rightLogin input[name='login'], #rightLogin input[name='password']").bind("click", function(e) {e.stopPropagation()});
    $(".kundenlogin a").bind("mouseenter",function() {
        $("#rightLogin").show();
    });    
    if (typeof(mySelectedFilter) != "undefined") {
        $("#tvGuideFilter a").each(function() {
            if ($(this).html() == mySelectedFilter || $(this).text() == mySelectedFilter) {
                $(this).css({color: "#fff", backgroundColor:"#c2c2c2", fontWeight: "bold"});
                $("#tvGuideFilterToggle span").html(mySelectedFilter);
            }
        });
    }

});