function submit(form30) {
	document.form30.submit();
	return true;
}

function login() {
	document.getElementById("frameLogin").style.display = "";
}

function replyFrame(idComment) {
	var reply = "replyFrame_" + idComment;
	document.getElementById(reply).style.display = "";
}

function sendVoteUtil (vote, urlID, commentID, currPage) {
	var redirectTo = "proc.jsp?actionID=10&url_id=" + urlID + "&currPage=" + currPage + "&comment_id=" + commentID;
	if (vote == "yes") {
		if (window.confirm("Deseja votar nesse comentário como útil?")) {
			redirectTo += "&vote=1"; 
			window.location.href = redirectTo;
		}
	} else {
		if (window.confirm("Deseja votar nesse comentário como inútil?")) {
			redirectTo += "&vote=2";
			window.location.href = redirectTo;
		}
	}
}

function showDesc(event, text) {
	var yOffset = -20;
	xOffset = 30;
 
	document.getElementById('id_desc').style.visibility = 'visible';
	document.getElementById('text_desc').innerHTML = text;
	
	var scrollTop = document.documentElement.scrollTop;
	var scrollLeft = document.documentElement.scrollLeft;

	if (scrollTop == 0) {
		scrollTop = document.body.scrollTop;
		scrollLeft = document.body.scrollLeft;
	}

	var newLeft = event.clientX + scrollLeft - xOffset;
	var newTop = event.clientY + scrollTop - yOffset;

	document.getElementById('id_desc').style.left = newLeft + "px";
	document.getElementById('id_desc').style.top = newTop + "px";
}

function hideDesc() {
	document.getElementById('id_desc').style.visibility = 'hidden';
}

function openTd(lineID) {
	//document.getElementById("tdNotesID").style.display = "none";
	document.getElementById(lineID).style.display = "block";
}

function closeTd(lineID) {
	document.getElementById(lineID).style.display = "none";
	//document.getElementById("tdNotesID").style.display = "block";
}

function submitWord(form50) {
if (form50.word.value != "") {
	return true;
} else {
	alert("Você deve informar uma palavra para busca");
	return false;
}
}

function hiddenTable() {
document.getElementById("frame").style.display = "none";
}


function alterFace(name, idImage, valor) {
	var obj = document.getElementById(idImage);
	obj.src = name;
	document.form1.faceRate.value = valor;
}

var votou = false;
function starFix(tagID, state, /*dontCompute,*/ url_id){
	var voted = getCookie("md.forum.text_" + url_id + ".voted");
	
	if (voted != "" && !isNaN(voted)) {
		votou = true;
	}

	var auxVoto = 0;
	if(votou){
		alert("Você já votou!");
		auxVoto = 1;
	} else {
		if (window.confirm("Confirma o voto (" + state +  ") para essa URL? ")) {
			var arrTag = tagID.split("_");
			var rate = parseInt(arrTag[1]);
			var tag;
	
			for(i = 1; i <= 5; i++){
				tag = document.getElementById("starArt_" + i);
				tag.onmouseout = function(){};
				tag.onmouseover = function(){};
	
				tagOther = document.getElementById("star_" + i);
				tagOther.onmouseout = function(){};
				tagOther.onmouseover = function(){};
			}
			
			changeStar("starArt_" + rate, 0, true);
			changeStar("star_" + rate, 0, true);
			
			var hdnVoto = document.getElementById("hdnVoto");
			
			if (hdnVoto) {
				hdnVoto.value = rate;
			}
			
			/*if (!dontCompute) {*/
			getMessageArticle(651, url_id, rate, false);
			/*}*/
			
			setCookie("md.forum.text_" + url_id + ".voted", rate, (1000*60*60*24*30)); /*30 dias*/
			votou = true;
		}
	}
		//document.form1.auxVoto.value = auxVoto;
}

function changeStar(tagID, rate, isActive){
	var laranja = "../images/estrelinhaLaranja.gif";
	var cinza = "../images/estrelinhaCinza.gif";
	var amarela = "../images/estrelinhaAmarela.gif";
	var tag = tagID.split("_");
	var qnty = parseInt(tag[1]);
	
	for(i = qnty; i > 0; i--){
		if(isActive == true){
			document.getElementById(tag[0]+"_"+i).src = laranja;
			document.getElementById(tag[0]+"_"+i).src = laranja;
		} else {
			document.getElementById(tag[0]+"_"+i).src = (i > rate) ? cinza : amarela;
		}
	}
}

function sendForm(form) {
	if (form.comment.value == "" || jQuery.trim(document.getElementById("comment").value) == "") {
		alert("Você deve definir um comentário");
		document.getElementById("comment").value = "";
		document.getElementById("comment").focus();
		return false;
	} else {
		var email=document.getElementById("emailCommentID").value;
		var atPos=email.indexOf("@");
		var dotPos=email.indexOf(".");
		
		if(email != "") {
			if(atPos<1||dotPos<1||dotPos==email.length-1||atPos==email.length-1 ||email.length<6||email.indexOf(' ')!=-1 ||dotPos==atPos+1||dotPos==atPos-1||atPos!=email.lastIndexOf("@")||email.indexOf("..")!=-1) {
				alert("O e-mail que você informou não é válido");
				return false;
			}
		} 
		
		document.getElementById("sendButtonID").disabled =  "";
		return true;
	}
}

function alterFace(name, idImage, valor) {
	var obj = document.getElementById(idImage);
	obj.src = name;
	document.form1.faceRate.value = valor;
}

$(document).ready(function (){
	var autocomplete1 = $("#city1").autocomplete("../classificados/cidades.jsp", {
		minChars: 1,
		max: 15,
		width: 250,
		autoFill: false,
		selectFirst: false,
		scrollHeight: 220,
		
		
		extraParams: {
		   city: function() { return escape($("#city1").val()); }
		}
});

$("#checkNotification").click(function(){
	if (this.checked) {
		$("#emailTable").css("display", "block");
	} else {
		$("#emailTable").css("display", "none");
	}
});

$("#newCommentID").click(function(){
	$("#newCommentID").css("display", "none");
	$("#commentID").css("display", "block");
});

});
