/* 设置BaseAjax请求路径 */
function setBaseAjaxUrl(Url){
    ajaxBaseUrl = Url;
}
/*去左右空格*/
function Trim(str){
	str = str.replace( /\s*$/, "");
	str = str.replace( /^\s*/, "");
	return str;
} 
/*将2010-1-6 19:8:2的时间格式转换成2010-01-06 19:08:02的时间格式*/
function getFormat(timeformat){
	if(String(timeformat).length == 1){
		timeformat = "0" + String(timeformat);
	}
	return timeformat;
}
/*获取系统时间*/
function getSysDate(){
	var thetime = new Date();
	return getFormat(thetime.getFullYear()) + "-" + getFormat(thetime.getMonth()+1) + "-" + getFormat(thetime.getDate()) + " " + getFormat(thetime.getHours()) + ":" + getFormat(thetime.getMinutes()) + ":" + getFormat(thetime.getSeconds());
}
/*回复*/
function replycomment(commentID, username){
	$('#parentid').val(commentID);
	$('#replydiv').html("您正在回复 <a href='" + getURL() + "#" + commentID + "' title='查看评论'>" +username + "</a> 的评论（<a href='javascript:cancelcomment();' title='取消回复'>取消回复</a>）");
	location.href = getURL() + "#commentdiv";
}//end function
/*取消留言*/
function cancelcomment(){
	$('#parentid').val();
	$('#replydiv').html("");
	location.href = getURL() + "#comment";
}
/*获取URL*/
function getURL(){
    var pageUrl = window.location.toString();
    if(pageUrl.indexOf("#")){
        pageUrl = pageUrl.split("#")[0];
    }
    return pageUrl;
}
/* ajax提交留言 */
function doComment(){
	var commentname = Trim($('#commentname').val());
	var commentemail = Trim($('#commentemail').val());
	var commenturl = Trim($('#commenturl').val());
	if(commenturl.indexOf("http://")<0){
		commenturl = "http://" + commenturl;
	}
	var blogid = $('#blogid').val();
	var parentid = $('#parentid').val();
	var commentcontent = encodeURIComponent(Trim($('#commentcontent').val()));
	var commenttype = $('#commenttype').val();
	if(commentname == "" || commentemail == "" || commentcontent == ""){
		alert("请填写完整！");
		return false;
	}
	$('#commentbtn').attr("disabled","disabled");
	$('#commentbtn').val("正在提交，请稍后…");
		/* Ajax提交 */
		$.ajax({
		type:"POST",
		url:ajaxBaseUrl + "/Gbook/doComment",
		timeout:30000,
		processData:true,
		error:function(){
			alert("未知错误，请刷新页面后重新提交！");
			$("#commentbtn").attr("disabled","");
			$('#commentbtn').val("填好了，发吧 >>");
			location.reload();
			},
		data: "commentname=" + commentname + "&commentemail=" + commentemail + "&commenturl=" + commenturl + "&commentcontent=" + commentcontent + "&commenttype=" + commenttype + "&blogid=" + blogid + "&parentid=" + parentid,
		success:function(msg){
			if(msg.indexOf("succ")>=0){
				$('#commentcontent').val("");
				$("#commentbtn").attr("disabled","");
				$("#commentdiv").css("display","none");
				$("#comment_title").css("display","none");
				msg = msg.split("_");
				if(getURL().indexOf("Blog")>=0){
					var blogurl = getURL().split("Blog");
					blogurl = blogurl[0] + "Blog/details/id" + blogurl[1] + "/comment/" + msg[0];
					window.location.href = blogurl;
				}else{
					window.location.href = getURL() + "/index/" + msg[0];
				}
			}else{
				alert("未知错误，请刷新页面后重新提交！");
				$('#commentbtn').val("填好了，发吧 >>");
				$('#commentbtn').attr("disabled","");
				location.reload();
			}//end if
		}//end success
		});/*End Ajax提交 */
}//end function