function ValidarEmail(mail){
	var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
	if(typeof(mail) == "string"){
		if(er.test(mail))
		{ 
			return true;
		}
	}
	else if(typeof(mail) == "object"){
		if(er.test(mail.value)){ 
			return true; 
		}
	}
	else{
		return false;
	}
}

function EnviarComentario(Nome, Email, Comentario, Arquivo){
	var campos = "";
	if(document.getElementById(Nome).value == ""){
		campos = campos + " - Nome é obrigatório.\n";
	}
	if(document.getElementById(Email).value == ""){
		campos = campos + " - E-mail é obrigatório.\n";
	}
	else if(document.getElementById(Email).value != ""){
		if(!ValidarEmail(document.getElementById(Email).value)){
			campos = campos + " - E-mail é inválido.\n";
		}
	}
	if(document.getElementById(Comentario).value == ""){
		campos = campos + " - Comentário é obrigatório.\n";
	}
	
	if(campos == ""){
		document.getElementById("frmComentario").action = "Index.asp?Ir=Arquivo&Arquivo=" + Arquivo;
		document.getElementById("frmComentario").submit();
	}
	else{
		mensagem = "Alguns campos são obrigatórios:\n";
		alert(mensagem + campos);
	}
}

function EnviarContato(Nome, Email, Mensagem){
	var campos = "";
	if(document.getElementById(Nome).value == "" || document.getElementById(Nome).alt == "F"){
		campos = campos + " - Nome é obrigatório.\n";
	}
	if(document.getElementById(Email).value == "" || document.getElementById(Email).alt == "F"){
		campos = campos + " - E-mail é obrigatório.\n";
	}
	else if(document.getElementById(Email).value != ""){
		if(!ValidarEmail(document.getElementById(Email).value)){
			campos = campos + " - E-mail é inválido.\n";
		}
	}
	if(document.getElementById(Mensagem).value == "" || document.getElementById(Mensagem).title == "F"){
		campos = campos + " - Mensagem é obrigatório.\n";
	}
	
	if(campos == ""){
		document.getElementById("frmContato").action = "Index.asp?Pg=Contato";
		document.getElementById("frmContato").submit();
	}
	else{
		mensagem = "Alguns campos são obrigatórios:\n";
		alert(mensagem + campos);
	}
}

function MudarStatus(Campo){
	var ValorCampo = document.getElementById(Campo).value;
	
	if(ValorCampo != ""){
		document.getElementById(Campo).alt = "T";
	}
	else{
		document.getElementById(Campo).alt = "F";
	}
}

function MudarStatusTA(Campo){
	var ValorCampo = document.getElementById(Campo).value;
	
	if(ValorCampo != ""){
		document.getElementById(Campo).title = "T";
	}
	else{
		document.getElementById(Campo).title = "F";
	}
}

function TrocarValor(Campo, Tirar, Valor){
	var ValorCampo = Campo.value;
	
	if(ValorCampo == "" && Tirar == "False" && Campo.alt == "F")
	{
		Campo.value = Valor;
	}
	else
	{
		if(Campo.alt != "T"){
			Campo.value = "";
		}
	}
}

function TrocarValorTA(Campo, Tirar, Valor){
	var ValorCampo = Campo.value;
	
	if(ValorCampo == "" && Tirar == "False" && Campo.title == "F")
	{
		Campo.value = Valor;
	}
	else
	{
		if(Campo.title != "T"){
			Campo.value = "";
		}
	}
}

function LimitaTextArea(campo, count, limite) {
	text = document.getElementById(campo);
	contador = document.getElementById(count);
	if (text.value.length > limite){ // if too long...trim it!
		text.value = text.value.substring(0, limite);
	// otherwise, update 'characters left' counter
	}
	else{
		contador.innerHTML = limite - text.value.length;
	}
}
