﻿//MyView.aspx
var CheckedChannels = "";

function LoadChannels() {

    CheckedChannels = document.getElementById("OrgChannels").value;

    var CCArr = CheckedChannels.split('|');

    for (i = 0; i < CCArr.length; i++)
        document.getElementById(CCArr[i]).checked = "checked";

    CheckedChannels = "|" + CheckedChannels + "|";

    return true;

}

function PopulateCookie(Checkbox) {

    var CheckboxId = "|" + Checkbox.id + "|";

    if (CheckedChannels.indexOf(CheckboxId) == -1) {
        CheckedChannels += Checkbox.id + "|";
    } else {
        CheckedChannels = CheckedChannels.replace(CheckboxId, "|");
    }

    ajaxGet("savechannels.aspx?c=" + CheckedChannels, SavedChannels)

    return true;
}

function SavedChannels(result) {
    //document.getElementById("test").value = result;
}

function GoToMyListSortButton_onclick() {
    window.location = "myview.aspx";
    return true;
}

//Default.aspx

function ShowProgramDetails(ProgramID) {
    var width = 290;
    var height = 300;
    var left = (screen.width - width) / 2;
    var top = (screen.height - height) / 2;
    var params = 'width=' + width + ', height=' + height;
    params += ', top=' + top + ', left=' + left;
    params += ', directories=no';
    params += ', location=no';
    params += ', menubar=no';
    params += ', resizable=no';
    params += ', scrollbars=no';
    params += ', status=no';
    params += ', toolbar=no';
    newwin = window.open("programdetails.aspx?p=" + ProgramID, 'windowname5', params);
    if (window.focus) { newwin.focus() }
    //return false;

}

//UpdateChannels.aspx
function TriggerUpdate()
{
    document.getElementById("UpdateButton").style.visibility = "hidden";
    
    if(!Continue)
    {
        Continue = true;
        Counter = Counter + 1;
    }
    
    for(var i = Counter; i < ChannelID.length; i++)
    {
        if(document.getElementById("Checkbox" + ChannelID[i]).checked)
            document.getElementById("StatusDiv" + ChannelID[i]).innerHTML = "Waiting";
        else
            document.getElementById("StatusDiv" + ChannelID[i]).innerHTML = "Skipping";
        
    }
    
    StartUpdateChannel();
    
}

function MarkAll(bool)
{
    for(var i = Counter; i < ChannelID.length; i++)
    {
        document.getElementById("Checkbox" + ChannelID[i]).checked = bool;
    }
}

function StartUpdateChannel()
{
    document.getElementById("Checkbox" + ChannelID[Counter]).disabled = true;
    
    if(document.getElementById("Checkbox" + ChannelID[Counter]).checked)
    {
        document.getElementById("StatusDiv" + ChannelID[Counter]).innerHTML = "Updating...";
        ajaxGet("getchannels.aspx?channelid=" + ChannelID[Counter], FinishUpdateChannel);
    }
    else
    {
        if(Counter < ChannelID.length)
        {
            Counter = Counter + 1;
            StartUpdateChannel();
        }
    }
    return true;
}

function FinishUpdateChannel(result)
{
    document.getElementById("StatusDiv" + ChannelID[Counter]).innerHTML = result;
    
    if(Continue)
    {
        if(Counter < ChannelID.length)
        {
            Counter = Counter + 1;
            StartUpdateChannel();
        }
    }
    
    return true;
}

function CacheUser() {
    ajaxGet("updateUser.aspx", cacheCompleted);
}

function cacheCompleted(result) {
    //alert(result);
}
        
