﻿<!--

window.addEvent('domready', PageLoad);

function GetLength(str)
{
	return str.replace(/[^\x00-\xff]/g,"**").length;
}

function PageLoad()
{
    $("bumCreat").addEvent("click", CreatComment);
    $("CreatBlogArticle").addEvent("click", CreatBlogArticle);

    window.document.addEvent('keydown', function(event){
        //传入的event已经是一个Event类的示例 
        //Ctrl + Enter 组合键
        if (event.key == 'enter' && event.control) {
            CreatComment();
        }
    });


}

 function TestEmail(strEmail) { 
  var myReg = /^[_a-z0-9]+@([_a-z0-9]+\.)+[a-z0-9]{2,3}$/; 
  if(myReg.test(strEmail)) return true; 
  return false; 
 } 

function GetCommentTopList()
{
    $("CommentList").innerHTML = "Loging...";
    postUrl = "XHRGetCommentList.aspx?num="+$time();
    var req = new Request({
		url: postUrl,
        method: 'get',
		onSuccess: function(txt){$("CommentList").innerHTML = txt;},
		onFailure: function(){alert("发生错误！");}
	});
	req.send();

}


function CreatBlogArticle()
{
    var AuthorName = $("userName").value.trim();
    var BlogUrl = $("BlogUrl").value.trim();
    var ArticleName = $("ArticleName").value.trim();
    var ArticleUrl = $("ArticleUrl").value.trim();
    
    if (AuthorName == "") {
        alert("请输入作者名称");
        return false;
    }
    if (BlogUrl == "") {
        alert("请输入博客地址");
        return false;
    }

    if (ArticleName == "") {
        alert("请输入推荐文章");
        return false;
    }
    if (ArticleUrl == "") {
        alert("请输入文章连接");
        return false;
    }

    postUrl = "XHRCreatBlogArticle.ashx?num="+$time();
    
    var req = new Request({
		url: postUrl,
        data: 'AuthorName='+ AuthorName+'&BlogUrl='+BlogUrl+'&ArticleName='+ArticleName+'&ArticleUrl='+ArticleUrl,
        method: 'post',
		onSuccess: function(txt){
		    if(txt == "0")
		    {
                $("userName").value = "";
                $("BlogUrl").value = "";
                $("ArticleName").value = "";
                $("ArticleUrl").value = "";
                alert("博文发表成功!");
		    }
		},
		onFailure: function(){alert("发生错误！");}
	}); 
	
	req.send();
        
}

function CreatCommentFalse()
{
    $("bumCreat").value = "loading...";
    $("bumCreat").disabled = false;
}

function CreatCommentTrue()
{
    $("bumCreat").value = "提交留言";
    $("bumCreat").enable = true;
}

function CreatComment()
{
    CreatCommentFalse();
    var userName = $("CommentuserName").value.trim();
    var userMemo = $("userMemo").value.trim();
    if (userName == "")
    {
        CreatCommentTrue();
        alert("请输入用户名");
        return false;
    }
    if (userMemo == "")
    {
        CreatCommentTrue();
        alert("请输入评论内容");
        $("userMemo").focus();
        return false;
    }

    postUrl = "XHRCreatComment.ashx?num="+$time();
    
    var req = new Request({

		url: postUrl,
        data: 'userName='+ userName+'&userMemo='+userMemo,
        method: 'post',
		onSuccess: function(txt){
		    if(txt == "0")
		    {
                $("userName").value ="IT168网友";
                $("userMemo").value ="";
                CreatCommentTrue();
                alert("评论发表成功!");
                GetCommentTopList();
		    }
		    else if (txt == "10") {
		        CreatCommentTrue();
		        alert("请输入评论内容!");
		    }
		},
		onFailure: function(){alert("发生错误！");CreatCommentTrue();}

	}); 
	
	req.send();
    	
}


//-->