// index.js
// Author: Jean Dannemann Carone
// Creation date: 02/25/2010

var tipoDaPesquisa;

function trim(value) {
	value = value.replace(/((\s*\S+)*)\s*/, '$1');
	value = value.replace(/\s*((\S+\s*)*)/, '$1');
	return value;
}

function setTipoPesquisa(tipoPesquisa) {
	tipoDaPesquisa = tipoPesquisa;
}

function verificaBusca() {
	if (tipoDaPesquisa == "" || tipoDaPesquisa == undefined || tipoDaPesquisa == "undefined") {
		alert("Escolha acima, se a pesquisa será feita por título ou conteúdo do texto.");
		return false;
	}

	var valorInputPesuqisa = trim(document.getElementById("s").value);

	if (valorInputPesuqisa == "" || valorInputPesuqisa == undefined || valorInputPesuqisa == "undefined") {
		alert("Digite o conteúdo da pesquisa.");
		return false;
	} else if (valorInputPesuqisa.length < 5) {
		alert("Informe um conteúdo para pesquisa com no mínimo 5 caracteres.");
		return false;
	}

	document.getElementById("ccc").value = tipoDaPesquisa;
	document.getElementById("searchform").submit();
}

function ficarEmNegrito(id) {
	document.getElementById("tit").style.fontWeight = "normal";
	document.getElementById("tex").style.fontWeight = "normal";
	document.getElementById(id).style.fontWeight = "bold";
}

function checkCommentsData() {
	if (trim(document.getElementById("nome").value) == "") {
		document.getElementById("nome").focus();
		alert("Informe seu nome.");
		return false;
	} else if (trim(document.getElementById("email").value) == "") {
		document.getElementById("email").focus();
		alert("Informe seu e-mail (só será publicado caso você deseje).");
		return false;
	} else if (trim(document.getElementById("email").value) != "") {
		if (!checkMail(trim(document.getElementById("email").value))) {
			document.getElementById("email").focus();
			alert("Informe um e-mail válido.");
			return false;
		}
	} else if (trim(document.getElementById("comment").value) == "") {
		document.getElementById("comment").focus();
		alert("Faça seu comentário sobre o texto.");
		return false;
	}

	document.getElementById("commentform").submit();
}

function checkContactData() {
	if (trim(document.getElementById("contactName").value) == "") {
		document.getElementById("contactName").focus();
		alert("Informe seu nome.");
		return false;
	} else if (trim(document.getElementById("contactEmail").value) == "") {
		document.getElementById("contactEmail").focus();
		alert("Informe seu e-mail.");
		return false;
	} else if ((trim(document.getElementById("contactEmail").value) != "") && (!checkMail(trim(document.getElementById("contactEmail").value)))) {
		document.getElementById("contactEmail").focus();
		alert("Informe um e-mail válido.");
		return false;
	} else if (document.getElementById("contactMotivo").value == "") {
		document.getElementById("contactMotivo").focus();
		alert("Informe o motivo do contato.");
		return false;
	} else if (trim(document.getElementById("contactMessage").value) == "") {
		document.getElementById("contactMessage").focus();
		alert("Escreva sua mensagem ao efecade.com.br:)");
		return false;
	} else if (trim(document.getElementById("contactMessage").value).length >= 999) {
		document.getElementById("contactMessage").focus();
		alert("Mensagem deve conter menos de 1000 caracteres.");
		return false;
	}

	document.getElementById("contactMessageform").submit();
}
