﻿// JScript File


//执行代码
//第一个 bug 第一行执行函数.
function blank()
{
    //
}

function AddRow(sName, sContent)
{
    var sRow = "";
    var myDate = new Date(); 
    var dObj = document.getElementById("drList");
    if(sName == "") { sName = "匿名"; }
    sRow = "<div class=drtittle><div class=left><img src=\"/images/dr-ico.gif\" /> </div>";
    sRow += "<div class=\"lh2\">[<font color=red>待审核</font>] " + sName + " 发表于 " + myDate.toLocaleTimeString() + "</div></div>";
    sRow += "<div class=drnr>" + HtmlText(sContent) + "</div>";
    dObj.innerHTML += sRow;
}

function sendReview(infoId, checkCode, domain)
{
    var url;
    var postContent;
    var name = ReplaceText(document.getElementById("fPostName").value);
    var content = ReplaceText(document.getElementById("fPostContent").value);
    url = "/work/addReview.aspx";
    postContent = "id=" + infoId + "&c=" + checkCode + "&name=" + name + "&content=" + content;
    runXmlHttp(url, postContent);
    //AddRow(name, content);
}

function HtmlText(sText)
{
    var sTextCurrent;
    sTextCurrent =  sText;
    sTextCurrent = sTextCurrent.replace("\n", "<br>");
    sTextCurrent = sTextCurrent.replace("\u0020", "&nbsp;");
    sTextCurrent = sTextCurrent.replace(" ", "&nbsp;");
    return sTextCurrent; 
}

function ReplaceText(sText)
{
    var sTextCurrent;
    sTextCurrent =  sText;
    sTextCurrent = sTextCurrent.replace("<", "&lt;");
    sTextCurrent = sTextCurrent.replace(">", "&gt;");
    sTextCurrent = sTextCurrent.replace("\"", "&#39;");
    sTextCurrent = sTextCurrent.replace("'", "&quot;");
    return sTextCurrent;
}

var httpSearch;

function runXmlHttp(url, postContent)
{
    //document.write(url);
    httpSearch = null;
    if(window.XMLHttpRequest) {
        try 
        { 
            httpSearch = new XMLHttpRequest();
        } 
        catch(e) { httpSearch = false; }
    } 
    else if(window.ActiveXObject) {
        try 
        { 
            httpSearch = new ActiveXObject('Msxml2.XMLHTTP');
        } 
        catch(e) 
        {
            try 
            { 
                httpSearch = new ActiveXObject('Microsoft.XMLHTTP');
            } 
            catch(e) { httpSearch = false; }
        } 
     }
    if(httpSearch) {
        httpSearch.onreadystatechange = SetReturnTips;
        httpSearch.open('POST', url, false);
        httpSearch.setRequestHeader("Content-Length",postContent.length); 
        httpSearch.setRequestHeader("CONTENT-TYPE","application/x-www-form-urlencoded"); 
        httpSearch.send(postContent);
    }
    else
    {
        document.getElementById("lblTips").innerHTML = "网络繁忙，请刷新后再试";
    }
}

function SetReturnTips()
{
    if (httpSearch.readyState == 4 && httpSearch.status == 200 ) 
    {   
    
        var sReturn = httpSearch.responseText;
        if(sReturn == null | sReturn == "")
        {
            document.getElementById("lblTips").innerHTML = "您的评论已发布成功，须等候我们的审核！";
        }
        else
        {
            document.getElementById("lblTips").innerHTML = "<font color=red>" + sReturn + "</font>";   
        }
    }
    else
    {
        document.getElementById("lblTips").innerHTML = "系统繁忙中，请刷新后再试";
    }
}


function setBlankTips(o)
{
    document.getElementById(o).innerHTML = '<font color=red>&#35831;&#36755;&#20837;&#20869;&#23481;&#33;</font>';
}

function setFocusText(o)
{
    document.getElementById(o).innerHTML="<font color=#306BA4>&#24744;&#27491;&#22312;&#36755;&#20837;&#20013;&#46;&#46;&#46;</font>"; //出现乱码 改 编码 为 gb2312后.net又不正常了.
}
        
function setInitText(o)
{
    document.getElementById(o).innerHTML="<font color=green>欢迎您就本文发表评论!</font>";
    }
    
function setWarnText(o)
{
    document.getElementById(o).innerHTML="<font color=red>&#31995;&#32479;&#25552;&#31034;&#58;&#35831;&#19981;&#35201;&#37325;&#22797;&#21457;&#35328;&#46;</font>";
    }
    
function UpdateBoard(sContent)
{
    document.getElementById("dBoard").innerHTML += sContent;
    }
    
function textCounter(field, countfield, maxlimit)
{
  // 定义函数，传入3个参数，分别为表单区的名字，表单域元素名，字符限制；
  if (field.value.length > maxlimit)
    //如果元素区字符数大于最大字符数，按照最大字符数截断；
    field.value = field.value.substring(0, maxlimit);
  else
  //在记数区文本框内显示剩余的字符数；
  countfield.value = maxlimit - field.value.length;
}

//document.getElementById("dBoard").scrollTop = document.getElementById("dBoard").scrollHeight + 1500000;
//无法达到效果.

function VagueWin()
{
    window.focus();   
    window.blur(); 
}

function CheckForm(infoId, checkCode, domain)
{
    if(document.getElementById("fPostContent").value == "")
    {
        setBlankTips('lblTips');    // ie ff 通用的最简洁方法.
        return false;
    }
    else
    {
        document.getElementById("lblTips").innerHTML = '<font color=green>评论正在发送中...</font>';
        sendReview(infoId, checkCode, domain);
    }
    return true;
}

function CloseWindow()
{
	window.opener = null; 
        window.close(); 
}

function SetInputInit()
{
    document.form1.tbContent.value = "";
    document.getElementById("lblCount").value = '500';
    document.getElementById('fPostContent').focus();
    setInitText('lblTips')
}