var bg;
var dig;
var msg;
var pnl;

var btn;
var gTitleID;
function send(val)
{
    gTitleID = val;
    var c = document.getElementById("txtContent");
    var chk = document.getElementById("txtchk");
    
    if(c.value == "" || chk.value == "")
    {
        bgOpen("内容与验证码必须输入!!!",true);
        return;
    }
    bgOpen("正在提交,请稍后。。。",false);
    Emit_Review.Send(val,c.value,chk.value,window.location.href,send_callback);
}
function send_callback(res)
{
    if(res == null)
        return;
    msg.innerHTML = res.value;
    pnl.appendChild(btn);
    dig.appendChild(pnl);
    btn.focus();
    getComments(gTitleID);
    if (res.value == "发表成功！！！") {
        document.getElementById("txtContent").value = "";
        document.getElementById("txtchk").value = "";
        rvc();
    }
}

function bgOpen(val,isbtn)
{
    bg = document.createElement("div");
    dig = document.createElement("div");
    msg = document.createElement("div");
    pnl = document.createElement("div");
    btn = document.createElement("input");
    bg.style.cssText = "Z-INDEX: 9; POSITION: absolute;display:block;background-color:#cccccc; width: 100%; height:"+document.body.offsetHeight+"px;filter : progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=50,finishOpacity=50);opacity: 0.80;  left: 0px; top: 0px;";
    dig.style.cssText = "position:absolute;margin-top:"+(150+document.documentElement.scrollTop)+"px;top:0px;left:500px;width:400px;height:200px;z-index:10;overflow:hidden; border:0px white solid;width:400px; height:200px;background:url(/images/bg.jpg);";
    msg.innerHTML= val;
    msg.style.cssText = "padding:30 30 30 30;color:red;";
    btn.type = "button";
    btn.value = "确定";
    
    btn.onclick = function(){bgClose();}
    pnl.style.cssText = "text-align:center;padding:30 0 0 0;";
    
    document.body.onscroll = function(){
    dig.style.cssText = "position:absolute;top:0px;left:500px;width:400px;height:200px;z-index:10;overflow:hidden; border:1px white solid;margin-top:" + (150 + document.documentElement.scrollTop) + "px;width:400px; height:200px;background:url(/images/bg.jpg);";
    }
    dig.appendChild(msg);
    if(isbtn!=false)
    {
    
    pnl.appendChild(btn);
    dig.appendChild(pnl);
    }
    
    document.body.appendChild(dig);
    document.body.appendChild(bg);
    if(isbtn!=false) btn.focus();
    
}
function isLogin()
{
   
    Emit_Review.GetIsLogin(window.location.href,GetIsLogin_CallBack);
}
function GetIsLogin_CallBack(res)
{
    if(res.value == null||res.value == "")
        return;
    bgOpen(res.value,true);
}
function bgClose()
{
    document.body.removeChild(dig);
    document.body.removeChild(bg);
//    dig.removeNode(true);
//    bg.removeNode(true);
}
function rvc()
{
    //alert(document.getElementById('verificationcode').src);
    document.getElementById('verificationcode').src='/VerificationCode.aspx?'+Math.random();
}

function getComments(val)
{ 
    Emit_Review.GetComment(val,comments_callback);
}
function comments_callback(res)
{
    if(res.value == null)
        return;
    var ds = res.value;
    html = "<h1>其他读者评论</h1>";
    
    for(var i=0;i<ds.Tables[0].Rows.length;i++)
    {
        var dt = new Date(ds.Tables[0].Rows[i].Create_Date);
        html += "<li class=\"li1\"><a href='" + System.Configuration.ConfigurationManager.AppSettings["SpaceDomain"] + "/" + ds.Tables[0].Rows[i].userdomain + "'>" + ds.Tables[0].Rows[i].Author + "</a> 于" + dt.getYear() + "-" + dt.getMonth() + "-" + dt.getDay() + " " + dt.getHours() + ":" + dt.getMinutes() + ":" + dt.getSeconds() + " 发表</li>";
        html += "<li class=\"li2\">"+ds.Tables[0].Rows[i].Content+"</li>";
    }
    var pnl = document.getElementById("pnlComment");
    pnl.innerHTML = "";
    pnl.innerHTML = html;
}