﻿var varSite='http://itv.phoenixtv.com/vip';
//发布评论
function addVideoComment()
{
    document.getElementById('btnAddComment').disabled = true;
    try
    {
    var param = 'site=itv&ifAnony=1&ifHideIp=1&docId='+ph.VideoInfo.videoID+'&docName='+encodeURIComponent(ph.VideoInfo.title)+'&docUrl='+encodeURIComponent(varSite + '/play.aspx?id='+ph.VideoInfo.videoID);
    param += '&content='+document.getElementById('content').value;
    var ajax = new net.ContentLoader('/vip/interface/_addvideocomment_.aspx','POST',param,onAddVideoCommentCallback,onAddVideoCommentError,null);
    ajax.loadXMLDoc();
    }
    catch(e)
    {}
}

function onAddVideoCommentCallback()
{
    var result = this.req.responseText;
    switch(result)
    {
        case "0":
            alert('您的评论已经发表成功，请等待审核通过！');
            document.getElementById('content').value="";
            document.getElementById('btnAddComment').disabled = false;
            location.reload();
            break;
        case "1":
            alert('抱歉，此文章暂时不允许评论，感谢您的理解与支持！');
            break;
        case "2":
            alert('抱歉，您的IP已被锁定，请及时联系系统管理员，感谢您的理解与支持！');
            break;
        case "3":
            alert('抱歉，标签最多能够设置5个，感谢您的理解与支持！');
            break;
        case "4":
            alert('抱歉，单个标签长度超出系统设置默认值（10个中文字）！');
            break;
        case "5":
            alert('抱歉，评论内容不能为空，感谢您的理解与支持！');
            break;
        case "6":
            alert('您发表的评论已经超过500个中文字符，请修改后再次提交，感谢您的理解与支持！');
            break;
        case "7":
            alert('您的评论中含有不允许发表的字符，请修改后再次提交，感谢您的理解与支持！');
            break;
        case "8":
            alert('参数错误');
            break;
        default:
            alert('未知错误');
            break;
    }   
}
function onAddVideoCommentError()
{
    alert('服务器忙,请稍后重试');
    return ;
}
// 获取投票数
function getVideoCount(){
    var param = 'site=itv&docId='+ph.VideoInfo.videoID+'&docName='+encodeURIComponent(ph.VideoInfo.title)+'&docUrl='+encodeURIComponent(varSite + '/play.aspx?id='+ph.VideoInfo.videoID);
    var ajax = new net.ContentLoader('/vip/interface/_getvideocount_.aspx','GET',param,onGetVideoCountCallback,onGetVideoCountError,null);
    ajax.loadXMLDoc();
}

function onGetVideoCountCallback(){
    var result = this.req.responseText;
    document.getElementById('spanVideoCount').innerHTML=result;
}

function onGetVideoCountError(){
    document.getElementById('spanVideoCount').innerHTML='0';
}

//投票
function addVideoCount()
{
    var param = 'site=itv&docId='+ph.VideoInfo.videoID+'&docName='+encodeURIComponent(ph.VideoInfo.title)+'&docUrl='+encodeURIComponent(varSite+'/play.aspx?id='+ph.VideoInfo.videoID);
    var ajax = new net.ContentLoader('/vip/interface/_addvideocount_.aspx','GET',param,onAddVideoCountCallback,onAddVideoCountError,null);
    ajax.loadXMLDoc();
}
function onAddVideoCountCallback()
{
       var result = this.req.responseText;
       switch(result)
       {
        case "0":
            var varTemp = document.getElementById('spanVideoCount').innerHTML;
            document.getElementById('spanVideoCount').innerHTML = Number(varTemp)+1;
            document.getElementById('aAddVideoCount').innerHTML ='<a href="http://itv.phoenixtv.com/vip/top.aspx" target="_blank"  class="Awhite">查看</a>';
            break;
        case "1":
            alert('服务器忙,请稍后重试');
            break;
        case "2":
            alert('参数错误');
            break;
        case "3":
            alert('未知错误');
            break;
        default:
            break;
       }
}
function onAddVideoCountError()
{
    alert('服务器忙,请稍后重试');
    return ;
}
//评论
    function selectMood(_mood) {
        var _con = document.getElementById("content");
        _con.focus();
        _con.value = _con.value + "[" + _mood + "]";
        _con.focus();
    }

    function DBClient(id,url,timeout){
        this.id=id;
        this.url=url;
        this.timeout=(timeout==null?5000:timeout);
        this.node=document.createElement('script');
        this.isStop=false;
        this.onComplete=null;
        this.onError=null;
        this.onStop=null;
    }

    DBClient.prototype={
        open:function(){
            this.node['type']='text/javascript';
            this.node['src']=this.url;
            document.body.insertBefore(this.node,null);
            this.isStop=false;
            this.getData();
        },
        getData:function(){
            var t=0;
            var timeout=this.timeout;
            var id=this.id;
            var _=this;
            var eh=setInterval(function(){
                if(t>timeout){
                    clearInterval(eh);
                    if(_.onError!=null){
                        _.onError(_,1);
                }
            }
            if(_.isStop){
                clearInterval(eh);
                if(_.onStop!=null){
                _.onStop(_,2);
                }
            }
            t+=10;
            if(DBClient.pool.contain(id)){
                clearInterval(eh);
                if(_.onComplete!=null){
                    _.onComplete(_,DBClient.pool.get(id));
                }
            }
            },10);
        },
        stop:function(){
            this.isStop=true;
        },
        close:function(){
            try{
                document.body.removeChild(this.node);
                DBClient.pool.remove(this.id)
            }catch(e){}
        }
    }


    DBClient.pool=new Dictionary();
    DBClient.add=function(key,value){
    DBClient.pool.add(key,value);
    }

    V.addListener(window,'load',function(){
    var varIViewUrl='http://cmt.phoenixtv.com/iviewcmts.do?chId=-9999&docId='+ph.VideoInfo.videoID+'&docName='+encodeURIComponent(ph.VideoInfo.title)+'&docUrl='+encodeURIComponent( varSite+'/play.aspx?id='+ph.VideoInfo.videoID);
    var varViewUrl='http://cmt.phoenixtv.com/viewcmts.do?chId=-9999&docId='+ph.VideoInfo.videoID+'&docName='+encodeURIComponent(ph.VideoInfo.title)+'&docUrl='+encodeURIComponent( varSite+'/play.aspx?id='+ph.VideoInfo.videoID);
    var varKey=varSite+'/play.aspx?id='+ph.VideoInfo.videoID;
    var db=new DBClient(varKey,varIViewUrl,10000);
    
    db.onComplete=function(o,d){

    var value = "";
    for (var i=0; i < d.records ; i++)
        {
	        value += '<div class="listItem"><div class="name">'+d.cmts[i].name+'</div><div class="time">'+d.cmts[i].createTime+'</div><div class="detail">'+d.cmts[i].content+'</div></div>';      
        }
    //显示评论数据
    var divo = document.getElementById("cmtItems");
    //更多链接
    var moreCmts='<div class="more" id="moreCmts"><span>—></span><a href="'+varViewUrl+'" target="_blank">更多评论</a></div>';
    value += moreCmts;
    divo.innerHTML = value;

    //评论数
    var cmtCount = document.getElementById("cmtCount");
    varCount = (d.count == 'undefined')? '0' : d.count;
    cmtCount.innerHTML = d.count;
    }
    db.onError=function(o){
        //alert("服务器忙(CMTs),请稍后重试！");
        return;
    }
    db.open();
    }
    );

