
	var comment = 0;
	
	function listComments(id){		
		//if(comment!=0) hideComments(comment);
		comment = id;
		document.getElementById("post_" + comment).innerHTML = "<div class=loading>"+loading+"</div>";
		document.getElementById("post_" + comment).style.display = "block";		
		var url = URL_ROOT + "/packages/blog/pages/comments.tpl.php?id=" + id;
		call_remote(url, "showComment");
	}
	
	function showComment(data){
		var pos = data.indexOf(":");
		var id = data.substring(0, pos);
		var text = data.substring(pos+1);
		document.getElementById("post_" + id).innerHTML = text;
		var url = URL_ROOT + "/packages/blog/pages/comments_count.ajax.php?id=" + id;
		call_remote(url, "countComment");
	}
	
	function insertComment(id){
		if(article) document.location = URL_ROOT + "/packages/blog/pages/index.tpl.php?post=" + id + "&comment#" + id;
		else {
			if(comment!=0) hideForm(comment);
			comment = id;
			document.getElementById("form_" + comment).style.display = "block";
			document.location = "#" + comment;
		}
	}
	
	function afterAction(data){
		document.getElementById("form_" + comment).style.display = "none";
		resetForm(comment);
		listComments(comment);
	}
	
	function countComment(data){
		document.getElementById("number_" + comment).innerHTML = data;
	}
	
	function resetForm(id){
		var form = document.getElementById("form" + id);
		form.text.value = "";
		document.getElementById("sendButton_" + id).disabled = false;
	}
	
	function sendCommentForm(form, id){
		comment = id;
		document.getElementById("result_" + id).innerHTML = '<img align=absmiddle border=0 src="'+URL_ROOT+'/images/loading.gif">&nbsp;' + SENDING_MESSAGE + "...";
		document.getElementById("sendButton_" + id).disabled = true;
		sendForm(form);
	}
	
	function hideResults(){
		document.getElementById("result_" + comment).innerHTML = "&nbsp;";
	}
	
	function enableSend(){
		try {
			document.getElementById("result_" + id).innerHTML = "&nbsp;";
			document.getElementById("sendButton_" + comment).disabled = false;
		} catch (e){}
	}

	function sendFormError(){
		enableSend();
	}	

	function hideComments(id){
		comment = id;
		try {
			document.getElementById("post_" + comment).style.display = "none";
		} catch (e){}
	}

	function hideForm(id){
		comment = id;
		document.getElementById("form_" + comment).style.display = "none";
	}
	
	function calculate(form){
			var a = new Number(form.captcha0.value);
			var b = new Number(form.captcha1.value);
			form.answer.value = (a+b);			
	}

	function searchContent(){
		var value = document.getElementById('key').value;
		if(value.length < 3) alert("Digite pelo menos 3 letras");
		else getContent(URL_ROOT + '/packages/blog/pages/search.tpl.php?key=' + escape(value));
	}			
	