/* Create a new XMLHttpRequest object to talk to the Web server */
var xmlHttp = false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
  try {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (e2) {
    xmlHttp = false;
  }
}
@end @*/

if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
  xmlHttp = new XMLHttpRequest();
}

function menuFix() {
    var sfEls = document.getElementById("tree").getElementsByTagName("li");
    for (var i=0; i<sfEls.length; i++) {
        sfEls[i].onmouseover=function() {
			this.className += " over";
        }        
        sfEls[i].onmouseout=function() {
			this.className=this.className.replace(" over", "");
        }
    }
}

function checkAll(myform) {
	for(var i=0; i<myform.elements.length; i++) {
		if (myform.elements[i].type == "checkbox")		
		  myform.elements[i].checked = true;
	}
}
function uncheckAll(myform) {
  for(var i=0; i<myform.elements.length; i++) {
		if (myform.elements[i].type == "checkbox")		
		  myform.elements[i].checked = false;
	}
}


function unicode(s){ 
var len=s.length; 
var rs=""; 
for(var i=0;i<len;i++){ 
var k=s.substring(i,i+1); 
rs+="&#"+s.charCodeAt(i)+";"; 
} 
return rs; 
} 

function runicode(s){ 
var k=s.split(";"); 
var rs=""; 
for(i=0;i<k.length;i++){ 
var m=k.replace(/&#/,""); 
rs+=String.fromCharCode(m); 
} 
return rs; 
} 


function postComment(id,blogId){
	
	var button = document.getElementById("SaveComment");
	var commenter = document.getElementById("edtCommenter").value;
	var content = document.getElementById("edtContent").value;
	var url = document.getElementById("edtUrl").value;
	var poststr = "postcontent=" + content + "&username=" + commenter + "&blogId=" + blogId + "&url=" + url;
	var urlAction = document.getElementById("urlAction").value;
	var urlDomain = document.getElementById("urlDomain").value;
	
	if (commenter.length == 0)
	{
		alert("用户名不能为空");
		return false;
	}
	var size = Getlength(content);
	
	if (size < 3)
	{
		alert("留言内容字数不能少于三个字节");
		return false;
	}
	else if (size > 600)
	{
		alert("留言内容字数不能多于600个字节，目前的字数为" + size + "字节");
		return false;
	}
	
	
	var url = urlAction + "?Action=PostComment&BlogPostId=" + id;
	
	button.disabled= 1;
	xmlHttp.open("POST", url, true);
	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {
			alert("留言成功！");
   			if (id > 0)
  				document.location.href = urlDomain + "doc/" + id.toString() + ".aspx";
  			else
   				document.location.href = urlDomain + "guestbook.aspx"; 
   		}
	}
	
	xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded;');
	
	//alert(poststr);
	xmlHttp.send(poststr);
	
}

function PostBlogComment(id,blogId) {
	var button = document.getElementById("SaveComment");
	var commenter = document.getElementById("edtCommenter").value;
	var content = document.getElementById("edtContent").value;
	var url = document.getElementById("edtUrl").value;
	var poststr = "postcontent=" + content + "&username=" + commenter + "&blogId=" + blogId + "&url=" + url;
	var urlAction = document.getElementById("urlAction").value;
	var urlDomain = document.getElementById("urlDomain").value;
	
	if (commenter.length == 0)
	{
		alert("用户名不能为空");
		return false;
	}
	if (content.length < 3)
	{
		alert("留言内容字数不能少于三个字节");
		return false;
	}
	else if (content.length > 598)
	{
		alert("留言内容字数不能多于600个字节，目前的字数为" + content.length + "字节");
		return false;
	}
	
	
	var url = urlAction + "?Action=PostComment&BlogPostId=" + id + "&" + poststr;
	
	button.disabled= 1;
	
	$.getJSON(url, {
			Status: status
		},
		function(json) {
			if (!empty(json.status)) {
				if (json.status=='1') {
					if (status ==1)
						alert('ok');
					else
						alert('操作失败,请检查您是否有此操作权限。');
					
				}
				else {
					alert('操作失败,请检查您是否有此操作权限。');
				}
			}			
		}
	);
}

function postSearch()
{
	var btnSearch = document.getElementById("btnSearch");
	var keyword = document.getElementById("edtKeyword").value;
	
	if (keyword.length < 3)
	{
		alert("关键字必须大于三个字节");
		return false;
	}
	else
	{
		btnSearch.disabled = 1;
		//document.location.href = "http://localhost/nbren.Web/marcozh/blog.aspx?Action=Search&Keyword=" + keyword;
	}
}

function updatePage() {
  if (xmlHttp.readyState == 4) 
  {
	if (id > 0)
  		document.location.href = "http://localhost/nbren.Web/marcozh/doc/" + id.toString() + ".aspx";
  	else
  		document.location.href = "http://localhost/nbren.Web/marcozh/guestbook.aspx"; 		
  }
  
}



