﻿/// <reference path="jquery-1.2.5-intellisense.js" />
$(document).ready(function() {

//人气
function getfeedback(careid)
{
$.ajax({
    type: "post",
    url: "http://tvshow.smgbb.cn/ws2/inforq.ashx",
    dataType:"xml",
    data: "id="+careid,
    beforeSend: function(XMLHttpRequest){
    },
    success: function(data){
        var myallength = renqilength.length;
        
        var myal = new Array(myallength);
        
        $(data).find("phome_ecms_smgbb_info").each(
        function(i){ 
            myal[i] = $(this).children("onclick").text();
        });
        
        myallength = 0;
        $("span.ddddd").each(function() { 
            $(this).html(myal[myallength]);
            myallength++;
        });

    },
    complete: function(XMLHttpRequest, textStatus){
    },
    error: function(){
    }
    });
}

//增加人气
function addclick(careid)
{
$.ajax({
    type: "post",
    url: "http://tvshow.smgbb.cn/ws2/inforqadd.ashx",
    dataType:"xml",
    data: "id="+careid,
    beforeSend: function(XMLHttpRequest){
    },
    success: function(data){
        $(data).find("state").each(
        function(i){ 
            status = $(this).text();
            if(status!="0")
            {
                //alert("成功");
            }
            else
            {
                //alert("失败");
            }
        });
    },
    complete: function(XMLHttpRequest, textStatus){
    },
    error: function(){
    }
    });
}

//增加 tv 栏目 人气
function tv_addclick(careid)
{
$.ajax({
    type: "post",
    url: "http://tvshow.smgbb.cn/ws2/tvrqadd.ashx",
    dataType:"xml",
    data: "id="+careid,
    beforeSend: function(XMLHttpRequest){
    },
    success: function(data){
        var state = 0;
        
        $(data).find("state").each(
        function(i){ 
            state = $(this).text();
        });
        
        $("#tvgrade").html(state);
        
    },
    complete: function(XMLHttpRequest, textStatus){
    },
    error: function(){
    }
    });
}

//评分
function grade(careid, points)
{
var temp1 = "id="+careid;
if(points!=0)
{
    temp1 = "id="+careid+"&fs="+points;
}

$.ajax({
    type: "post",
    url: "http://tvshow.smgbb.cn/ws2/infotpcl.ashx",
    dataType:"xml",
    data: temp1,
    beforeSend: function(XMLHttpRequest){
    },
    success: function(data){
        var avgpoint = 0.0;
        var count = 0;
        
        $(data).find("state").each(
        function(i){ 
            avgpoint = $(this).children("avgpoint").text();
            count = $(this).children("count").text();
        });
        
        $("#avgpoint").html(avgpoint);
        $("#allcount").html(count);
        
        if(points!=0)
        {
            gradeflag = 1;
            alert('谢谢关注');
        }
    },
    complete: function(XMLHttpRequest, textStatus){
    },
    error: function(){
    }
    });
}

//tv top 10
function tvhotlist()
{
$.ajax({
    type: "post",
    url: "http://tvshow.smgbb.cn/ws2/tvhotlist.ashx",
    dataType:"xml",
    data: "",
    beforeSend: function(XMLHttpRequest){
    },
    success: function(data){
        
        var classpath = new Array(10);
        var titlepic = new Array(10);
        var onclick = new Array(10);
        var title = new Array(10);
        var intro = new Array(10);
        
        $(data).find("empirecms_tv").each(
        function(i){ 
            classpath[i] = $(this).children("classpath").text();
            titlepic[i] = $(this).children("titlepic").text();
            onclick[i] = $(this).children("onclick").text();
            title[i] = $(this).children("title").text();
            intro[i] = $(this).children("intro").text();
        });
        
        var mycount = 0;
        $("span.tv_onclick").each(function() { 
            $(this).html(onclick[mycount]);
            mycount++;
        });
        
        mycount = 0;
        $("span.tv_title").each(function() { 
            $(this).html(title[mycount]);
            mycount++;
        });
        
        mycount = 0;
        $("span.tv_hotlistintro").each(function() { 
            $(this).html("<a href=\""+ classpath[mycount] +"\" target=\"_blank\">"+intro[mycount]+"</a>");
            mycount++;
        });

    },
    complete: function(XMLHttpRequest, textStatus){
    },
    error: function(){
    }
    });
}

//tv top 10
function hotlist(careid)
{
$.ajax({
    type: "post",
    url: "http://tvshow.smgbb.cn/ws2/tvtop10list.ashx",
    dataType:"xml",
    data: "id="+careid,
    beforeSend: function(XMLHttpRequest){
    },
    success: function(data){
        
        var classpath = new Array(10);
        var titlepic = new Array(10);
        var onclick = new Array(10);
        var title8 = new Array(10);
        var smalltext = new Array(10);
        
        $(data).find("empirecms_info").each(
        function(i){ 
            classpath[i] = $(this).children("classpath").text();
            titlepic[i] = $(this).children("titlepic").text();
            onclick[i] = $(this).children("onclick").text();
            title8[i] = $(this).children("title").text();            
            if($(this).children("title").text().length>10)
            {
                title8[i] = title8[i].substr(0,10);
            }

            smalltext[i] = $(this).children("smalltext").text();
        });
        
        var mycount = 0;
        $("span.onclick").each(function() { 
            $(this).html(onclick[mycount]);
            mycount++;
        });
        
        mycount = 0;
        $("span.title8").each(function() { 
            $(this).html(title8[mycount]);
            mycount++;
        });
        
        mycount = 0;
        $("span.hotlistpic").each(function() { 
            $(this).html("<a href=\""+ classpath[mycount] +"\" target=_blank ><img width=66 height=66 src=\""+ titlepic[mycount] +"\" alt=\""+ title8[mycount] +"\" /></a>");
            mycount++;
        });
        
        mycount = 0;
        $("span.hotlistintro").each(function() { 
            $(this).html("&nbsp;&nbsp<a href=\""+ classpath[mycount] +"\" target=_blank >"+smalltext[mycount]+"</a>");
            mycount++;
        });

    },
    complete: function(XMLHttpRequest, textStatus){
    },
    error: function(){
    }
    });
}

//tv_top10
var classidlist = $("#classidlist").html();
if(classidlist!=null)
{
    hotlist(classidlist);
}

//增加人气
var myadd = $("#addonclick").attr("bbbbb");
if(myadd!=null)
{
    addclick(myadd);
}

//获取人气
var renqilength = $("span.ddddd");
if(renqilength.length>0)
{
    var renqi = "";
    $("span.ddddd").each(function() { 
        renqi += $(this).attr("bbbbb") + "|";
    });
    getfeedback(renqi);
}

//获取评分
var myavgpoint = $("#star1").attr("bbbbb");
if(myavgpoint!=null)
{
    grade($("#star1").attr("bbbbb"), 0);
}

//增加评分
var gradeflag = 0;

$("#star1").click(function() { 
    if(gradeflag == 0)
    {
        grade($("#star1").attr("bbbbb"), 1);
    }
});

$("#star2").click(function() { 
    if(gradeflag == 0)
    {
        grade($("#star2").attr("bbbbb"), 2);
    }
});

$("#star3").click(function() { 
    if(gradeflag == 0)
    {
        grade($("#star3").attr("bbbbb"), 3);
    }
});

$("#star4").click(function() { 
    if(gradeflag == 0)
    {
        grade($("#star4").attr("bbbbb"), 4);
    }
});

$("#star5").click(function() { 
    if(gradeflag == 0)
    {
        grade($("#star5").attr("bbbbb"), 5);
    }
});

//tv_top10
var tv_hotlist = $("#tv_hotlist").html();
if(tv_hotlist!=null)
{
    tvhotlist();
}

//tv_grade
var tv_grade = $("#tvgrade").attr("bbbbb");
if(tv_grade!=null)
{
   tv_addclick($("#tvgrade").attr("bbbbb"));
}

var abbbb = $("span.dzhongwen");
if(abbbb.length>0)
{
    $("span.dzhongwen").each(function() { 
        $ddtest=$(this).attr("ccccc");
        $ddtest1=encodeURIComponent($ddtest);
       
        $ddtest="<a href=http://info.smgbb.cn/ws2/infolist.aspx?classid=117&tag="+$ddtest1+"&index=1 target=_blank>"+$ddtest+"</a>";
     
        $(this).html($ddtest);
    });
}

});