﻿// JScript 文件
function gid(objDom)
{
    return document.getElementById(objDom);
}
function selectArea(areaid)
{
    if(areaid == 0)
    {
        gid("div_jminfo").style.display = "none";
        gid("span_TVchannel").style.display = "none";
        gid("span_TVstation").style.display = "none";
        return;
    }
    gid("span_TVstation").innerHTML = "<img alt='' src='loading.gif'  style='border:0px;' />正在读取电台";
    gid("span_TVchannel").style.display = "none";
    gid("div_jminfo").style.display = "none";
    gid("span_TVstation").style.display = "";
    TVClass.getTVstationDataSet(areaid,cb_selectArea);
}
function cb_selectArea(rel)
{
    
    if(rel == null || rel.value == null)
        return ;
    var table = rel.value;
    var rcount = table.Rows.length;
    if(rcount == 0)
        return;
    var oneRows = null, strHTML = "", tvStationName = "", tvStationID = 0;
    strHTML = "<option value='-1'>请选择电台</option>"
    for(i = 0; i < rcount; i++)
    {
        oneRows = table.Rows[i];
        tvStationID = oneRows.tvStationID;
        tvStationName = oneRows.tvStationName;
        strHTML += "<option value=\"" + tvStationID + "\">" + tvStationName + "</option>";
    }
    gid("span_TVstation").innerHTML = "<select onchange='selectStation(this.value);' id='select_TVstation'>" + strHTML + "</select>";
}
function selectStation(stationID)
{
    if(stationID == -1)
    {
        gid("div_jminfo").style.display = "none";
        gid("span_TVchannel").style.display = "none";
        return;
    }
    gid("span_TVchannel").innerHTML = "<img alt='' src='loading.gif'  style='border:0px;' />正在读取频道";
    gid("div_jminfo").style.display = "none";
    gid("span_TVchannel").style.display = "";
    TVClass.getTVchannelDataSet(stationID,cb_selectStation);
}
function cb_selectStation(rel)
{
    if(rel == null || rel.value == null)
        return ;
    var table = rel.value;
    var rcount = table.Rows.length;
    if(rcount == 0)
        return;
    var oneRows = null, strHTML = "", tvChannel = "", tvChannelID = 0;
    strHTML = "<option value='-1'>请选择频道</option>"
    for(i = 0; i < rcount; i++)
    {
        oneRows = table.Rows[i];
        tvChannelID = oneRows.tvChannelID;
        tvChannel = oneRows.tvChannel;
        strHTML += "<option value=\"" + tvChannelID + "\">" + tvChannel + "</option>";
    }
    gid("span_TVchannel").innerHTML = "<select id='select_channel' onchange='showInfo(this.value);' id='select_TVchannel'>" + strHTML + "</select>";
}
function showInfo(channelID) {
    if(channelID == -1)
    {
        gid("div_jminfo").style.display = "none";
        return;
    }
    gid("tb_Tvchannel").innerHTML = "<img alt='' src='load.gif' style='border:0px;' /> 正在读取节目单...";
    gid("div_jminfo").style.display = "";
    gid("tb_Tvchannel").style.display = "";
    showweek();
    TVClass.getTVprogramDateSet(channelID,DateFormat_3(new Date()),cb_getTVprogramDateSet);
}
function showweek()
{
    TVClass.getWeekTable(cb_showweek);
}
function cb_showweek(rel)
{
    if(rel == null || rel.value == null)
        return ;
    var table = rel.value;
    var rcount = table.Rows.length;
    if(rcount == 0)
        return;
    var oneRows = null, strHTML = "", index = 0, showDate = null, thedate = "";
    for(i = 0; i < rcount; i++)
    {
        oneRows = table.Rows[i];
        index = oneRows.index;
        showDate = oneRows.showDate;
        thedate = oneRows.theDate;
        if(oneRows.curdate)
            strHTML += "<a class='WeekOver' id='span_week" + index + "' onclick='showTVinfo(\"" + showDate + "\"," + index + ");'>" + thedate + "</a>&nbsp;&nbsp;|&nbsp;&nbsp;";
        else
            strHTML += "<a class='WeekOut' id='span_week" + index + "' onclick='showTVinfo(\"" + showDate + "\"," + index + ");'>" + thedate + "</a>&nbsp;&nbsp;|&nbsp;&nbsp;";
    }
    if(strHTML.length != 0) strHTML = strHTML.substring(0, strHTML.length - 25);
    gid("div_week").innerHTML = strHTML;
}
function showTVinfo(date,index)
{
    gid("tb_Tvchannel").innerHTML = "<img alt='' src='load.gif'  style='border:0px;' /> 正在读取节目单...";
    for(i = -1; i < 6; i++)
    {
        if(i == index)
            gid("span_week" + i).className = "WeekOver";
        else
            gid("span_week" + i).className = "WeekOut";
    }
    TVClass.getTVprogramDateSet(gid("select_channel").value,date,cb_getTVprogramDateSet);
}
function cb_getTVprogramDateSet(rel)
{
    if(rel == null || rel.value == null)
        return ;
    var table = rel.value;
    var rcount = table.Rows.length;
    if(rcount == 0)
        return;
    var oneRows = null, strHTML = "", index = 0, showDate = null, thedate = "", playTime = "", tvProgram = "", LTR = "", RTR = "";
    strHTML = "<table cellpadding='0' cellspacing='0'>\
                    <tr>\
                        <td style='padding-right:40px;' align='center'><b>上午</b></td>\
                        <td align='center'><b>下午</b></td>\
                    </tr>\
                    <tr><td valign='top' style='padding-right:40px;'><table>";
    for(i = 0; i < rcount; i++)
    {
        oneRows = table.Rows[i];
        playTime = oneRows.playTime;
        tvProgram = oneRows.tvProgram;
        if(oneRows.meridiem == "AM" || oneRows.meridiem == "-")
            LTR += "<tr><td width='50px;' align='left'>" + playTime + "</td><td align='left'>" + tvProgram + "</td></tr>";
        else
            RTR += "<tr><td width='50px;' align='left'>" + playTime + "</td><td align='left'>" + tvProgram + "</td></tr>";
    }
    strHTML += LTR + "</table></td><td valign='top'><table>" + RTR + "</table></td></tr></table>";
    gid("tb_Tvchannel").innerHTML = strHTML;
}
//yyyy-MM-dd
function DateFormat_3(strDate)
{
    return strDate.getFullYear() + "-" + ((strDate.getMonth() + 1)<10 ? "0" + (strDate.getMonth() + 1) : (strDate.getMonth() + 1)) + "-" + (strDate.getDate()<10?"0"+strDate.getDate():strDate.getDate());
}