﻿
var RingTopics = new Object();

//make row
var currentRingTopicID = "";
var currentRingTopicProgCode = "";
var currentRingTopicItemBreakCount = 10;
var currentRingTopicShowOperation = false;
var mr = function(text, author, ringno, rowIndex,itemCount,picUrl,isRingBox, isLeftProg,progCode)
{

    var makeColorCount;                 //设置颜色的数目，如果是>=10，设置5条，如果>0且<10设置3条,如果==0不做处理
    if(0==itemCount)
        makeColorCount=0;
    else
        makeColorCount= (itemCount>=10?5:3); 
    //var html = "";
    if (rowIndex % currentRingTopicItemBreakCount == 0)
    {
        if (rowIndex > 0)
        {
            document.write("</table></td><td style='width:1px;size:1px' class='prog_break_spliter'>&nbsp;</td>");
        }
        document.write("<td valign='top'><table style='display:inline;' width='100%' cellSpacing='0' cellPadding=0>");
    }

    document.write("<TR class=prog_row>");
    if(currentRingTopicShowOperation)
    {
        document.write('<TD class=prog_ring_checkbox><INPUT ringinfo="'+ text + "|" + author + "|" + ringno + '" id=' + currentRingTopicID + "$" + currentRingTopicProgCode + "$" + rowIndex + ' type=checkbox></TD>');
    }
    else
    {
        document.write("<td style='width:4px'><div class='rankingNO indexBackGround sprite-nombg' style='margin:2px;'>"+(rowIndex+1)+"</div></td>");
    }
    
    if(rowIndex<makeColorCount)
    {
        if(isRingBox)
       { 
//        document.write('<TD align="left"><DIV style="CURSOR: pointer;color:'+MakeColor(rowIndex)+';" class=prog_ring_text title="' + convertToTile(text) + '"onmouseover="this.style.textDecoration=\'underline\'" onmouseout="this.style.textDecoration=\'none\'"   onclick="RingTopics[\'' + currentRingTopicID + "'].playRing('" + ringno + "','0')\"><img src='"+picUrl+"' width='27px' height='13px'/>" + text + "</DIV></TD>");
        document.write('<TD align="left"><DIV style="CURSOR: pointer;width:150px;color:'+MakeColor(rowIndex)+';" class=prog_ring_text title="' + convertToTile(text) + '"onmouseover="this.style.textDecoration=\'underline\'" onmouseout="this.style.textDecoration=\'none\'"   onclick="showRingboxPlayer(\'' + ringno +"','"+progCode+ "')\"><div style='width:20px;height:13px;overflow:hidden;float:left;'><img src='"+picUrl+"'/></div>" + GetShortText(text) + "</DIV></TD>");
       }
       else
       {
        document.write('<TD align="left"><DIV style="CURSOR: pointer;width:150px;color:'+MakeColor(rowIndex)+';" class=prog_ring_text title="' + convertToTile(text) + '"onmouseover="this.style.textDecoration=\'underline\'" onmouseout="this.style.textDecoration=\'none\'"   onclick="RingTopics[\'' + currentRingTopicID + "'].playRing('" + ringno + "','0')\"><div style='width:20px;height:13px;overflow:hidden;float:left;'><img src='"+picUrl+"'/></div>" + GetShortText(text) + "</DIV></TD>");
       } 
    }
    else
    {
        if(isRingBox)
       { 
        document.write('<TD align="left"><DIV style="CURSOR: pointer" class=prog_ring_text title="' + convertToTile(text) + '" onmouseover="this.style.textDecoration=\'underline\'" onmouseout="this.style.textDecoration=\'none\'" onclick="showRingboxPlayer(\'' + ringno +"','"+progCode+ "')\">" + text + "</DIV></TD>");
       }
       else
       {
        document.write('<TD align="left"><DIV style="CURSOR: pointer" class=prog_ring_text title="' + convertToTile(text) + '" onmouseover="this.style.textDecoration=\'underline\'" onmouseout="this.style.textDecoration=\'none\'" onclick="RingTopics[\'' + currentRingTopicID + "'].playRing('" + ringno + "','0')\">" + text + "</DIV></TD>");
       } 
    }
    
    //试听、赠送、点歌按钮
    if(isRingBox)
    {
        document.write('<TD><DIV class=prog_ring_author title="价格：' + convertToTile((author/100).toFixed(2)) + '">' + (author/100).toFixed(2) + '</DIV></TD>')
        document.write( '<TD style="width:20px;" align="left"><DIV class="shiting indexBackGround sprite-shiting"title="试听定购" onclick="ShowRingboxPlayer(\''+ringno+'\',\''+progCode+'\''+')" onmouseover="javascript:showHotPosition(this)"; onmouseout="javascript:showPosition(this);"></DIV></TD>');
        document.write('<TD>&nbsp;&nbsp;</TD>')
    }
    else
    {
        document.write('<TD><DIV onmouseover="this.style.textDecoration=\'underline\'" onmouseout="this.style.textDecoration=\'none\'" onclick="searchAuthorRing(\''+author+'\')"  class=prog_ring_author title="' + convertToTile(author) + '">' + author + '</DIV></TD>');
        document.write( '<TD style="width:20px;" ><DIV class="shiting indexBackGround sprite-shiting" title="试听定购" onclick="RingTopics[\'' + currentRingTopicID + '\'].playRing(\'' + ringno + '\',\'0\')" onmouseover="javascript:showHotPosition(this)"; onmouseout="javascript:showPosition(this);"></DIV></TD>');
        if(isLeftProg)
        {
            document.write('</TR>'); 
        }
        else
        {
        document.write( '<TD style="width:20px;"><DIV class="dinggou indexBackGround sprite-zs" title=赠送 onclick="RingTopics[\'' + currentRingTopicID + '\'].playRing(\'' + ringno + '\',\'2\')" onmouseover="javascript:showHotPosition(this)"; onmouseout="javascript:showPosition(this);"></DIV></TD>');
        document.write( '<TD style="width:20px;"><DIV class="diange indexBackGround sprite-diange" title=点歌 onclick="RingTopics[\'' + currentRingTopicID + '\'].playRing(\'' + ringno + '\',\'3\')" onmouseover="javascript:showHotPosition(this)"; onmouseout="javascript:showPosition(this);"></DIV></TD>');
        document.write('</TR>'); 
        }
    }
    //document.write(html);
}
 
//class ringtopic
function RingTopic(topicID)
{ 
    this.ActiveProgCode = null; 
    
    this.ProgCodes = new Array(); 

    function getProgID(progCode)
    {
        return topicID + "$" + progCode;
    } 
    
    function getSubtitlesID()
    {
        return topicID + "$subtitles";
    }
    
    function getSubtitleID(progCode)
    {
        return topicID + "$subtitles$" + progCode;
    }
    
    function getSubtitle(progCode)
    {
        return document.getElementById(getSubtitleID(progCode));
    }
    
    function getSubtitles()
    {
        return document.getElementById(getSubtitlesID());
    }
    
    function getProg(progCode)
    {
        return document.getElementById(getProgID(progCode));
    } 
    
     
    //取得指定序号的复选框
    this.getCheckbox = function (sn)
    {
        return document.getElementById(topicID+ "$" + this.ActiveProgCode + "$" + sn);
    }
    
    //添加栏目
    this.addProg = function(progCode, propText)
    {
        this.ProgCodes.push(progCode);
        var title = getSubtitles().appendChild(document.createElement("div"));
        title.id = getSubtitleID(progCode);
        title.className = 'tabGray';  
        title.innerHTML = propText;
        title.style.display = 'inline';
        title.style.cursor = "pointer";
        title.title = propText;
        //title.style.width='100px';
        title.progCode = progCode;
        title.onclick = function(){ RingTopics[topicID].activeProg(this.progCode); };
        //getSubtitles().appendChild(title);//.onclick=function(){alert(1)};
    }
    
    //激活资源选项卡
    this.activeProg = function(progCode)
    {
        for(var i = 0; i < this.ProgCodes.length; i++)
        {
            var code = this.ProgCodes[i];
            getProg(code).style.display = 'none';
            getSubtitle(code).className = 'tabGray indexBackGround tab_orange sprite-tab_gray'; 
        }
        
        getProg(progCode).style.display = '';
        getSubtitle(progCode).className = 'tabOrange indexBackGround tab_orange sprite-tab_orange';
        this.ActiveProgCode = progCode;
    }

    //全选
    this.selectAll = function()
    {
        var i = 0;
        var checkbox = this.getCheckbox(i);
        
        while(checkbox)
        {
            checkbox.checked = true;
            i++;
            checkbox = this.getCheckbox(i);
        }
        
    }
    
    //反向选择
    this.invertSelection = function ()
    {
        var i = 0;
        var checkbox = this.getCheckbox(i);
        
        while(checkbox)
        {
            checkbox.checked = !checkbox.checked;
            i++;
            checkbox = this.getCheckbox(i);
        }
    } 
    
    this.playRing = function(ringNo, playerAction)
    {
//        alert(this.ActiveProgCode);
//        return false;
        showPlayer(ringNo, playerAction, this.ActiveProgCode); 
    }
    
    //播放选择
    this.play = function ()
    {
        var queryString = "";
        var i = 0;
        var checkbox = this.getCheckbox(i);
        
        while(checkbox)
        {
            if(checkbox.checked)
            {
                var regdouhao=/,/g;
                
                if((queryString.length+escape(checkbox.ringinfo.replace(regdouhao,"，")).length)>1980)//如果url长度大于1980则不添加
                    break;
                if(queryString.length) queryString += ",";
                queryString += escape(checkbox.ringinfo.replace(regdouhao,"，"));
            }
            i++;
            checkbox = this.getCheckbox(i);
        }  
        
        showPlayerMulti(queryString, this.ActiveProgCode);
        //window.open("OrderRing.aspx?chk_ringId=" + queryString + "&ProgCode=" + this.ActiveProgCode, "player");
    }
    
    //显示更多
    this.showMore = function()
    {
        location.href =  "ProgResourceList.aspx?progcode=" + this.ActiveProgCode;
    }
    this.showMoreRingBox = function()
    {
        location.href =  "RingBoxList.aspx?progcode=" + this.ActiveProgCode;
    }
}

//颜色渐变
//通过G渐加，
function MakeColor(i)
{
    var R = 255;
    var G = 0 + i*50;
    var B = 0;
    
    return 'rgb('+R+','+G+','+B+')';
}

//title中双引号转化为html特殊符号
//quanli 2009-6-17 10:44:38
function convertToTile(text)
{
    var titleString=text;
    if(text !="undefined" && text !=null && text !="")
    {
         titleString=text.replace(/\"/g,'&quot;');
    } 
   
    return  titleString;
}

function GetShortText(text)
{
    if(text.length>8)
    {
        return text.substring(0, 5).concat("...");
    }
    else
    {
        return text;
    }
}




