﻿// JScript 文件

//首先我们创建一个XMLHttpRequest对象

var xmlHttp;

function createXmlHttpRequest()
{
    if(window.XMLHttpRequest)
    {
        xmlHttp=new XMLHttpRequest();
    
        if(xmlHttp.overrideMimeType)
        {
            xmlHttp.overrideMimeType("text/xml");
        }
    }
    else if(window.ActiveXObject)
    {
        try
        {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");   
        }
        catch(e)
        {
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");   
        }
    }
    if(!xmlHttp)
    {
        window.alert("你的浏览器不支持创建XMLhttpRequest对象");
    }
    return xmlHttp;
}

//创建CheckUserName
    
function GoodOrBad(articleid,isGood)
{ 
    var spanUp = document.getElementById("spanUp");
    var spanDown = document.getElementById("spanDown");
    
    var upValue = "";
    var downValue = "";
    
    if(document.all)
    {//IE代码
        upValue = spanUp.outerText;
        downValue = spanDown.outerText;
    }
    else
    {//其他
        upValue = spanUp.textContent;
        downValue = spanDown.textContent;
    }
     
    createXmlHttpRequest();
    var url = "";
    if(isGood == true)
    {
        //顶加1，踩不变
        upValue = upValue.replace("顶(","");
        upValue = upValue.replace(")","");
        spanUp.innerText = "顶(" + (parseInt(upValue) + 1) + ")";
        spanDown.innerText = downValue;
        
        url="updown.aspx?narticleid=" + articleid + "&nupordown=1";
    }
    else
    {
        spanUp.innerText = upValue;
        downValue = downValue.replace("踩(","");
        downValue = downValue.replace(")","");
        spanDown.innerText = "踩(" + (parseInt(downValue) + 1) + ")";
        
        url="updown.aspx?narticleid=" + articleid + "&nupordown=0";
    }
    xmlHttp.open("post",url,true);
    
    xmlHttp.onreadystatechange=GetGoodBadResult;

    xmlHttp.send(null);
}

//创建用户检测的回调函数

function GetGoodBadResult()
{
    if(xmlHttp.readyState==4)//服务器响应状态
    {

        if(xmlHttp.status==200)//代码执行状态
        {
            
        }
    }
}



//
// patch of innerText for firefox
//
(function (bool) {
    function setInnerText(o, s) {
        while (o.childNodes.length != 0) {
            o.removeChild(o.childNodes[0]);
        }

        o.appendChild(document.createTextNode(s));
    }

    function getInnerText(o) {
        var sRet = "";

        for (var i = 0; i < o.childNodes.length; i ++) {
            if (o.childNodes[i].childNodes.length != 0) {
                sRet += getInnerText(o.childNodes[i]);
            }

            if (o.childNodes[i].nodeValue) {
                if (o.currentStyle.display == "block") {
                    sRet += o.childNodes[i].nodeValue + "\n";
                } else {
                    sRet += o.childNodes[i].nodeValue;
                }
            }
        }

        return sRet;
    }

    if (bool) {
        HTMLElement.prototype.__defineGetter__("currentStyle", function () {
            return this.ownerDocument.defaultView.getComputedStyle(this, null);
        });

        HTMLElement.prototype.__defineGetter__("innerText", function () {
            return getInnerText(this);
        })

        HTMLElement.prototype.__defineSetter__("innerText", function(s) {
            setInnerText(this, s);
        })
    }
})( /Firefox/.test(window.navigator.userAgent) );
