var Account = {
	checkHandle:function(){
		Account.checkNick();
		var handle = $("handle").value;
		var isChina = /[\u4e00-\u9fa5]+/;
		var isBig = /[A-Z]+/;
		if(handle == "")
		{
			$("handleErr").className = "wrong";
			$("handleErr").style.left = $("d_gx").offsetWidth + 85 + "px";
			$("handleErr").innerHTML = "<font color='red' size='2'>域名不能为空!</font>";
			$("handle").focus();
			return;
		}else if(isChina.test(handle)){
			$("handleErr").className = "wrong";
			$("handleErr").style.left = $("d_gx").offsetWidth + 85 + "px";
			$("handleErr").innerHTML = "<font color='red' size='2'>域名不支持汉字!</font>";
			$("handle").focus();
			return;
		}else if(isBig.test(handle)){
			$("handleErr").className = "wrong";
			$("handleErr").style.left = $("d_gx").offsetWidth + 85 + "px";
			$("handleErr").innerHTML = "<font color='red' size='2'>域名不支持大写字母!</font>";
			$("handle").focus();
			return;
		}else if(handle.length<4 || handle.length>10){
			$("handleErr").className = "wrong";
			$("handleErr").style.left = $("d_gx").offsetWidth + 85 + "px";
			$("handleErr").innerHTML = "<font color='red' size='2'>长度4-10位!</font>";
			$("handle").focus();
			return;
		}else if(!isNaN(handle)){
			$("handleErr").className = "wrong";
			$("handleErr").style.left = $("d_gx").offsetWidth + 85 + "px";
			$("handleErr").innerHTML = "<font color='red' size='2'>域名不支持纯数字!</font>";
			$("handle").focus();
			return;
		}else{
			var url = uu.urlUtil.encode("/blog/accountAction!checkHandle.uu");
			new Ajax.Request(
				url,
				{
					asynchronous: 'true',
					method:'post',
					postBody:'&handle=' + handle,
					onSuccess:function(transport){
						var resp = transport.responseText || "";
						var json = resp.evalJSON(true);
						if(json.status == 1){
							$("nickErr").innerHTML = "";
							$("handleErr").className = "wrong";
							$("handleErr").style.left = $("d_gx").offsetWidth + 85 + "px";
							$("handleErr").innerHTML = json.mes;
							$("handle").focus();
						}else{
							$("handleErr").className = "right";
							$("handleErr").style.left = $("d_gx").offsetWidth + 85 + "px";
							$("handleErr").innerHTML = "";
						}
					}
				}
			);
		}
	},
	checkNick:function(){
		var nick = $("nick").value;
		if(nick == "")
		{
			$("nickErr").className = "wrong";
			$("nickErr").style.left = $("d_nc").offsetWidth + 85 + "px";
			$("nickErr").innerHTML = "<font color='red' size='2'> 请填写昵称!</font>";
			$("nick").focus();
			return;
		}else{
			if(nick.length<2 || nick.length>10)
			{
				$("nickErr").className = "wrong";
				$("nickErr").style.left = $("d_nc").offsetWidth + 85 + "px";
				$("nickErr").innerHTML = "<font color='red' size='2'>长度2-10位!</font>";
				$("nick").focus();
				return;
			}else{
				$("nickErr").className = "right";
				$("nickErr").style.left = $("d_nc").offsetWidth + 85 + "px";
				$("nickErr").innerHTML = "";
			}
			
		}
	},
	checkForm:function(){
		Account.checkHandle();
		var code = $("code").value;
		if(code == ""){
			$("codeErr").className = "wrong";
			$("codeErr").style.left = $("d_yz").offsetWidth + 85 + "px";
			$("codeErr").innerHTML = "<font color='red' size='2'>请填写验证码!</font>";
			$("code").focus();
			return;
		}else{
			var url = uu.urlUtil.encode("/blog/accountAction!checkForm.uu");
			new Ajax.Request(
				url,
				{
					asynchronous: 'true',
					method:'post',
					postBody:'&code=' + code,
					onSuccess:function(transport)
					{
						var resp = transport.responseText || "";
						var json = resp.evalJSON(true);
						if(json.status == 'code'){
							$("nickErr").innerHTML = "";
							$("handleErr").innerHTML = "";
							$("codeErr").className = "wrong";
							$("codeErr").style.left = $("d_yz").offsetWidth + 85 + "px";
							$("codeErr").innerHTML = json.mes;
							$("code").focus();
						}else if(json.status == 'sub'){
							$("registForm").submit();
						}
					}
				}
			);
		}
	}
};

var Category = {
	getArticles:function(){
		if(arguments[0] == 0)
			window.location.href = "/" + Blog.handle + "/articles.shtml";
		else
			window.location.href = "/" + Blog.handle + "/bloglist_1_" + arguments[0] + "1.shtml";
	}
};

var BlogComment = {
	anyoneC:function(){
		var check = $("anonymity");
		if(check.checked == true)
		{
			$("commentNick").style.display = "none";
			$("commentLogin").style.display = "";
			$("commentUser").value = "uu网友";
		}else{
			$("commentNick").style.display = "";
			$("commentLogin").style.display = "none";
			$("commentUser").value = "";
		}
	},
	yzmFun:function(){
		$("yzmCode").style.display = "";
	},
	userMes:function(){
		$("commentLogin").style.display = "none";;
		$("commentUser").value = "";
		$("anyone").style.display = "";
		ajaxAsynGet("/blog/accountAction!getCommentUser.uu", "commentNick");
	},
	checkForm:function(){
		var commentUser = $("commentUser").value;
		//var anony = $("anonymity").value;
		var context = $("commentCo").value;
		if(context == "")
		{
			alert("请填写评论内容!");
			$("commentCo").focus();
			return;
		}
		var url = uu.urlUtil.encode("/blog/blogAction!addComment.uu");
		var param = "id=" + Article.id + "&user=" + encodeURI(encodeURI(commentUser)) + "&context=" + encodeURI(encodeURI(context));
		new Ajax.Request(
			url,
			{
				asynchronous: 'true',
				method:'post',
				postBody:param,
				onSuccess:function(transport){
					var resp = transport.responseText || "";
					$("commentbox").innerHTML = resp;
				}
			}
		);
		var comCount = parseInt($("blog_review").innerHTML) + 1;
		$("blog_review").innerHTML = comCount;
		$("commentCo").value = "";
	},
	setFont:function(){
		$("article_Body").style.fontSize = arguments[0];
	},
	selectAll:function(){
		var comArr = document.getElementsByName("comment");
		if($("selectAll").checked == true)
		{
			$("deleteAll").disabled = false;
			for(var i=0;i<comArr.length;i++)
			{
				comArr[i].checked = true;
			}
		}else{
			$("deleteAll").disabled = true;
			for(var i=0;i<comArr.length;i++)
			{
				comArr[i].checked = false;
			}
		}
	},
	cansoleSelect:function(element){
		if(element.checked == false)
		{
			
			if(this.getAllcansole())
			{
				$("deleteAll").disabled = true;
			}
			if($("selectAll").checked == true)
				$("selectAll").checked = false;
		}else{
			if($("deleteAll").disabled == true)
				$("deleteAll").disabled = false;
			
			if(this.getAllselect())
			{
				$("selectAll").checked = true;
			}
		}
	},
	getAllselect:function(){
		var flag = true;
		var arr = document.getElementsByName("comment");
		for(var i = 0;i<arr.length;i++)
		{
			if(arr[i].checked == false)
			{
				flag = false;
				break;
			}
		}
		
		return flag;
	},
	getAllcansole:function(){
		var flag = true;
		var arr = document.getElementsByName("comment");
		for(var i=0;i<arr.length;i++)
		{
			if(arr[i].checked == true)
			{
				flag = false;
				break;
			}
		}
		return flag;
	},
	deleteSelect:function(){
		var arr = document.getElementsByName("comment");
		var str = "";
		for(var i=0;i<arr.length;i++)
		{
			if(arr[i].checked == true)
				str += arr[i].value + ":";
		}
		str = str.substring(0,str.length-1);
		var url = uu.urlUtil.encode("/blog/commentAction!removeSelect.uu");
		new Ajax.Request(
			url,
			{
				asynchronous: 'true',
				method:'post',
				postBody:'cidStr=' + str,
				onSuccess:function(){
					window.location.href = "/comment/managerComment.shtml";
					//window.location.href = uu.urlUtil.encode("/blog/controlAction!managerComment.uu?exe=control");
				}
			}
		);
	},
	userReply:function(){
		var rep = $("commentReply");
		if(rep == null)
		{
			var html = "<div id='commentReply'><b>博主回复：</b><br>"
			   		 + "<textarea id='reply_content'></textarea><br>"
			   		 + "<input class='input' value='确 定' onclick='BlogComment.replySub("+arguments[0]+",\"reply_content\");' type='button'/>"
			         + "<input class='input' value='取 消' onclick='BlogComment.replyCansole(\"commentReply\");' type='button'></div>";
			var dis = $("reply_span_" + arguments[0]).innerHTML += html;
		}
	},
	replySub:function(cid,conID){
		var content = $(conID).value;
		if(content == '')
		{
			alert("您没写回复哦!");
			return;
		}
		$("reply_span_" + cid).innerHTML = "<img src='"+blogMes.domain+"/images/load.gif'/>保存中...";
		var url = uu.urlUtil.encode("/blog/commentAction!replySub.uu");
		new Ajax.Request(
			url,
			{
				asynchronous: 'true',
				method:'post',
				postBody:'&id=' + cid + '&text=' + encodeURI(encodeURI(content)),
				onSuccess:function(transport){
					var resp = transport.responseText || "";
					var json = resp.evalJSON(true);
					var html = "<div style='display: block;' class='reply' id='creply_"+json.rid+"'>"
							 + "<b>博主回复：</b><br>"
							 + "<span class='body' id='content_"+json.rid+"'>"+json.text+"</span>"
							 + "<span class='time'>("+json.time+")</span>"
							 + "<span><a href='javascript:void(0);' onclick='BlogComment.showUpdate("+json.rid+","+cid+");'>[修改]</a></span></div>"
					$("reply_span_" + cid).innerHTML = html;
				}
			}
		);
	},
	replyCansole:function(){
		if(typeof(arguments[1]) != 'undefined')
		{
			var dis = $("creply_" + arguments[1]).style.display;
			if(dis == 'none')
			{
				$("creply_" + arguments[1]).style.display = 'block';
			}
		}
		var p = $(arguments[0]).parentNode;
		p.removeChild($(arguments[0]));
	},
	showUpdate:function(id,cid){
	
		var content = $("content_" + id).innerHTML;
		var dis = $("creply_" + id).style.display;
		if(dis == 'block')
		{
			$("creply_" + id).style.display = 'none';
		}
		
		var html = "<div id='commentReply'><b>博主回复：</b><br>"
					   		 + "<textarea id='reply_content'>"+content+"</textarea><br>"
					   		 + "<input class='input' value='确 定' onclick='BlogComment.updateReply("+id+",\"reply_content\","+cid+");' type='button'/>"
					         + "<input class='input' value='取 消' onclick='BlogComment.replyCansole(\"commentReply\","+id+");' type='button'></div>";
		$("reply_span_" + cid).innerHTML += html;
	},
	updateReply:function(id,conID,cid){
		var content = $(conID).value;
		if(content == '')
		{
			alert("写点内容吧!");
			return;
		}
		$("reply_span_" + cid).innerHTML = "<img src='"+blogMes.domain+"/images/load.gif'/>保存中...";
		var url = uu.urlUtil.encode("/blog/commentAction!updateReply.uu");
		new Ajax.Request(
			url,
			{
				asynchronous: 'true',
				method:'post',
				postBody:'id=' + id + '&text=' + encodeURI(encodeURI(content)),
				onSuccess:function(transport){
					var resp = transport.responseText || "";
					var json = resp.evalJSON(true);
					var html = "<div style='display: block;' class='reply' id='creply_"+id+"'>"
							 + "<b>博主回复：</b><br>"
							 + "<span class='body' id='content_"+id+"'>"+json.text+"</span>"
							 + "<span class='time'>("+json.time+")</span>"
							 + "<span><a href='javascript:void(0);' onclick='BlogComment.showUpdate("+id+","+cid+");'>[修改]</a>"
							 + "</span></div>";
					$("reply_span_" + cid).innerHTML = html;
				}
			}
		);
	}
};

