﻿// JScript 文件
//以下创建的XMLHttpRequest对象在IE、FireFox下兼容！
var xmlHttp = window.XMLHttpRequest?(new XMLHttpRequest()):(new ActiveXObject("Microsoft.XMLHTTP"));

function requestinfo(topicid)
{
    var url = "/zhekou/ajaxinfo.aspx?op=1&sid="+topicid;
    xmlHttp.open("GET", url, true);
    xmlHttp.onreadystatechange = resultinfo;
    xmlHttp.send(null);
    
    return false;
}

function resultinfo()
{
    if (xmlHttp.readyState == 4 && xmlHttp.status==200)
    {
        var text= xmlHttp.responseText;
        var array = text.split(',');
        
        document.getElementById("support").innerHTML=array[0];
        document.getElementById("unsupport").innerHTML=array[1];
        //document.getElementById("views").innerHTML=array[2];

        if(array[3] == "True")
        {
            document.getElementById("hcheck").style.display = "block";
            document.getElementById("check").innerHTML= "该线报已被MP编辑认可";
        }
        
        if(array[4].length > 0)
        {
            var link = array[4];
            link = link.toLowerCase();
            if(link.indexOf('http://') == -1)
                link = '/zhekou/' + link;
            document.getElementById("edit").innerHTML = "该线报已被MP编辑引用 引用链接地址: <a href=\"" + link + "\" target=\"_blank\">" + link + "</a>";
        }
    }
}

// support
function support(id)
{
    var hsupport = document.getElementById("hsupport");
    if(hsupport.value == 1)
    {
        alert('您已经进行了投票');
        return false;
    }
    
    hsupport.value = 1;
    var url = "/zhekou/ajaxinfo.aspx?op=2&sid="+id;
    xmlHttp.open("GET", url, true);
    xmlHttp.onreadystatechange = supportresult;
    xmlHttp.send(null);
    
    return false; 
}

function supportresult()
{
    if (xmlHttp.readyState == 4 && xmlHttp.status==200)
    {
        var text= xmlHttp.responseText;
        var support = document.getElementById("support");
        support.innerHTML = text;
    }
}

// unsupport
function unsupport(id)
{
    var hunsupport = document.getElementById("hunsupport");
    if(hunsupport.value == 1)
    {
        alert('您已经进行了投票');
        return false;
    }
    
    hunsupport.value = 1;
    var url = "/zhekou/ajaxinfo.aspx?op=3&sid="+id;
    xmlHttp.open("GET", url, true);
    xmlHttp.onreadystatechange = unsupportresult;
    xmlHttp.send(null);
    
    return false; 
}

function unsupportresult()
{
    if (xmlHttp.readyState == 4 && xmlHttp.status==200)
    {
        var text= xmlHttp.responseText;
        var unupport = document.getElementById("unsupport");
        unupport.innerHTML = text;
               
    }
}