﻿/*#### ---- 转页面 ---- ####*/
function jumpPage(b_id)
{
    window.parent.location.href = 'editBlog.aspx?b_id=' + b_id + '&reURI=' + window.parent.location.href
}


/*#### ---- 删除一篇博客 ---- ####*/
function DeleteBlog(id)
{
    var sure = confirm("confirm?");
    if (sure==true){ 
        Ajax('Ajax/AjaxBlog.aspx?do=D&bi=' + id + '&t=' + Math.random(),
            DeleteBlog_doBack);
        }
}
function DeleteBlog_doBack()
{
    try{
        if (xmlHttp.readyState == 4) {
		    var currBlogId = xmlHttp.responseText;
		    if(currBlogId != "-1"){
		        location.href="blog.aspx";
		    }
	    }
	}
    catch(e){}
}


/*#### ---- 显示添加评论 ---- ####*/
function showAddComment()
{
    $s('comm1').display="block";
    $s('comm2').display="block";
    $s('comm3').display="block";
}

/*#### ---- 隐藏添加评论 ---- ####*/
function hideAddComment()
{
    if($('txtAddComments').value.Trim() == "")
    {
        $s('comm1').display="none";
        $s('comm2').display="none";
        $s('comm3').display="none";
        $('txtAddComments').value="";
    }
}


/*#### ---- 显示所有评论 ---- ####*/
function GetComments(id,pid)
{
    Ajax('Ajax/AjaxBlogComment.aspx?do=G&b_id=' + id + '&pid=' + pid + '&t=' + Math.random(),
        GetComments_doBack);
}
function GetComments_doBack()
{
    try{
        if (xmlHttp.readyState == 4) {
		    var text = xmlHttp.responseText;
		    if(text != "-1"){
		        $('divComments').innerHTML = text;
		    }
	    }
	}
    catch(e){}
}


/*#### ---- 添加评论 ---- ####*/
function AddComments(b,p,n)
{
    Ajax('Ajax/AjaxBlogComment.aspx?do=A&b_id=' + b + '&name=' + encodeURIComponent(n) + '&cont=' +  
        encodeURIComponent($('txtAddComments').value) + '&t=' + Math.random(),
       AddComments_doBack);
    $('txtAddComments').readOnly=true;  //设为可只读
    $s('txtAddComments').background='#eeeeee';
}
function AddComments_doBack()
{
    $('txtAddComments').readOnly=false; //设为可读写
    $s('txtAddComments').background='#ffffff';
    try{
        if (xmlHttp.readyState == 4) {
		    var text = xmlHttp.responseText;
		    if(text != "-1"){
                $('divComments').innerHTML += text;
                $('txtAddComments').value = "";
                $('txtAddComments').onblur();
		    }
	    }
	}
    catch(e){}
}


/*#### ---- 删除一篇评论 ---- ####*/
function DeleteComments(id)
{
    var sure = confirm("confirm?");
    if (sure==true){ 
        $s('c_'+id).background='#eeeeee'; //背景变色
        $s('d_'+id).display='none'; //隐藏删除按钮
        Ajax('Ajax/AjaxBlogComment.aspx?do=R&c_id=' + id + '&t=' + Math.random(),
            DeleteComments_doBack);
        }
}
function DeleteComments_doBack()
{
    try{
        if (xmlHttp.readyState == 4) {
		    var currId = xmlHttp.responseText;
		    if(currId != "-1"){
		        $(currId).innerHTML = "";
		        $s(currId).display = "none";
		    }
	    }
	}
    catch(e){}
}
