// JavaScript Document
function validaForm(nomeForm){
	var retorno=true;
	if(validaNome(this, nomeForm.nome.value)){
		retorno=false;
	}
	if(validaEmail(this, nomeForm.email.value) && nomeForm.email.value != ""){
		retorno=false;
	}
	if(validaMensagem(this, nomeForm.mensagem.value)){
		retorno=false;
	}
	if(nomeForm.name == "pedido"){
		if(validaTelefone(this, nomeForm.telefone.value) && nomeForm.telefone.value != ""){
			retorno=false;
		}
		if(validaDDD(this, nomeForm.ddd.value) && nomeForm.ddd.value != ""){
			retorno=false;
		}
	}
	if(nomeForm.name == "contatos"){
		if(validaCheckbox(this, nomeForm.gustavo.value)){
			retorno=false;
		}
		if(validaCheckbox(this, nomeForm.souza.value)){
			retorno=false;
		}
		if(validaCheckbox(this, nomeForm.ze.value)){
			retorno=false;
		}
		if(validaCheckbox(this, nomeForm.secretaria.value)){
			retorno=false;
		}
		if(validaCheckbox(this, nomeForm.refugio.value)){
			retorno=false;
		}
		if(validaAssunto(this, nomeForm.assunto.value)){
			retorno=false;
		}
	}
	return retorno;
}

function validaNome(ref, value){
	var tam=value.length;
	var erro=false;
	if(tam<2){
		document.getElementById('nome').style.background='#FFCCCC';
		document.getElementById('nome').style.border='1px solid #FF0000';
		document.getElementById('erroNome').style.display='inline';
		erro=true;
	}
	else{
		document.getElementById('nome').style.background='#FFFFFF';
		document.getElementById('nome').style.border='1px solid #99CC33';
		document.getElementById('erroNome').style.display='none';
	}
	return erro;
}

function validaEmail(ref, value){
	var tam=value.length;
	var erro=false;
	if((value.indexOf("@") == -1) || (value.indexOf(".") == -1) || tam < 8){
		document.getElementById('email').style.background='#FFCCCC';
		document.getElementById('email').style.border='1px solid #FF0000';
		document.getElementById('erroEmail').style.display='inline';
		erro=true;
	}
	else{
		document.getElementById('email').style.background='#FFFFFF';
		document.getElementById('email').style.border='1px solid #99CC33';
		document.getElementById('erroEmail').style.display='none';
	}
	if(tam==0){
		document.getElementById('email').style.background='#FFFFFF';
		document.getElementById('email').style.border='1px solid #99CC33';
		document.getElementById('erroEmail').style.display='none';
	}
	return erro;
}

function validaDDD(ref, value){
	var tam=value.length;
	var erro=false;
	if(isNaN(value) || tam!=2){
		document.getElementById('ddd').style.background='#FFCCCC';
		document.getElementById('ddd').style.border='1px solid #FF0000';
		document.getElementById('erroDDD').style.display='inline';
		erro=true;
	}
	else{
		document.getElementById('ddd').style.background='#FFFFFF';
		document.getElementById('ddd').style.border='1px solid #99CC33';
		document.getElementById('erroDDD').style.display='none';
		
	}
	if(tam==0){
		document.getElementById('ddd').style.background='#FFFFFF';
		document.getElementById('ddd').style.border='1px solid #99CC33';
		document.getElementById('erroDDD').style.display='none';
	}
	return erro;
}

function validaTelefone(ref, value){
	var tam=value.length;
	var erro=false;
	if(isNaN(value) || tam!=8){
		document.getElementById('telefone').style.background='#FFCCCC';
		document.getElementById('telefone').style.border='1px solid #FF0000';
		document.getElementById('erroTelefone').style.display='inline';
		erro=true;
	}
	else{
		document.getElementById('telefone').style.background='#FFFFFF';
		document.getElementById('telefone').style.border='1px solid #99CC33';
		document.getElementById('erroTelefone').style.display='none';
	}
	if(tam==0){
		document.getElementById('telefone').style.background='#FFFFFF';
		document.getElementById('telefone').style.border='1px solid #99CC33';
		document.getElementById('erroTelefone').style.display='none';
	}
	return erro;
}

function validaMensagem(ref, value){
	var erro=false;
	tam=value.length;
	if(tam<10){
    	document.getElementById('erroMensagem').style.display='inline';
		document.getElementById('mensagem').style.background='#FFCCCC';
		document.getElementById('mensagem').style.border='1px solid #FF0000';
		erro=true;
	}
	else{
		document.getElementById('erroMensagem').style.display='none';
		document.getElementById('mensagem').style.background='#FFFFFF';
		document.getElementById('mensagem').style.border='1px solid #99CC33';
	}
	return erro;
}

function validaCheckbox(ref){
	var erro=true;
	todos=document.getElementsByTagName('input');
	for(x=0; x<todos.length; x++){
		if (todos[x].checked){
			erro=false;
		}
	}
	if(erro){
		document.getElementById('check').style.color='#FF0000';
		document.getElementById('erroCheck').style.display='inline';
	}
	else{
		document.getElementById('check').style.color='#003300';
		document.getElementById('erroCheck').style.display='none';
	}
	return erro;
}


function validaAssunto(ref, value){
	var tam=value.length;
	var erro=false;
	if(tam<2){
		document.getElementById('assunto').style.background='#FFCCCC';
		document.getElementById('assunto').style.border='1px solid #FF0000';
		document.getElementById('erroAssunto').style.display='inline';
		erro=true;
	}
	else{
		document.getElementById('assunto').style.background='#FFFFFF';
		document.getElementById('assunto').style.border='1px solid #99CC33';
		document.getElementById('erroAssunto').style.display='none';
	}
	return erro;
}

function limpaCores(num){
	document.getElementById('nome').style.background='#FFFFFF';
	document.getElementById('nome').style.border='1px solid #99CC33';
	document.getElementById('erroNome').style.display='none';
	
	if(num != 3){
		document.getElementById('email').style.background='#FFFFFF';
		document.getElementById('email').style.border='1px solid #99CC33';
		document.getElementById('erroEmail').style.display='none';
		
		document.getElementById('mensagem').style.background='#FFFFFF';
		document.getElementById('mensagem').style.border='1px solid #99CC33';
		document.getElementById('erroMensagem').style.display='none';
	
		if(num==1){
			document.getElementById('ddd').style.background='#FFFFFF';
			document.getElementById('ddd').style.border='1px solid #99CC33';
			document.getElementById('erroDDD').style.display='none';
			
			document.getElementById('telefone').style.background='#FFFFFF';
			document.getElementById('telefone').style.border='1px solid #99CC33';
			document.getElementById('erroTelefone').style.display='none';
		}
		
		if(num==2){
			document.getElementById('check').style.color='#003300';
			document.getElementById('erroCheck').style.display='none';
			
			document.getElementById('assunto').style.background='#FFFFFF';
			document.getElementById('assunto').style.border='1px solid #99CC33';
			document.getElementById('erroAssunto').style.display='none';
		}
	}
	else{
		document.getElementById('testemunho').style.background='#FFFFFF';
		document.getElementById('testemunho').style.border='1px solid #99CC33';
		document.getElementById('erroTestemunhoPequeno').style.display='none';
		document.getElementById('erroTestemunhoLimite').style.display='none';
		
		document.getElementById('resumo').style.background='#FFFFFF';
		document.getElementById('resumo').style.border='1px solid #99CC33';
		document.getElementById('erroResumoPequeno').style.display='none';
		document.getElementById('erroResumoLimite').style.display='none';
		
		document.getElementById('foto').style.background='#FFFFFF';
		document.getElementById('foto').style.border='1px solid #99CC33';
		document.getElementById('erroFoto').style.display='none';		
	}
}

/********** VALIDAÇÃO DO ENVIO DE TESTEMUNHO **********/


function validaFoto(ref, value){
	var tam=value.length;
	var erro=false;
	if((value.indexOf(".jpg") == -1 ) && (value.indexOf(".gif") == -1) && (value.indexOf(".png") == -1)){
		document.getElementById('foto').style.background='#FFCCCC';
		document.getElementById('foto').style.border='1px solid #FF0000';
		document.getElementById('erroFoto').style.display='inline';
		erro=true;
	}
	else{
		document.getElementById('foto').style.background='#FFFFFF';
		document.getElementById('foto').style.border='1px solid #99CC33';
		document.getElementById('erroFoto').style.display='none';
	}
	return erro;
}

function validaResumo(ref, value){
	var tam=value.length;
	var erro=false;
	if(tam<=100){
		document.getElementById('resumo').style.background='#FFCCCC';
		document.getElementById('resumo').style.border='1px solid #FF0000';
		document.getElementById('erroResumoPequeno').style.display='inline';
		erro=true;
	}
	else if(tam>=400){
		document.getElementById('resumo').style.background='#FFCCCC';
		document.getElementById('resumo').style.border='1px solid #FF0000';
		document.getElementById('erroResumoLimite').style.display='inline';
		erro=true;
	}
	else{
		document.getElementById('resumo').style.background='#FFFFFF';
		document.getElementById('resumo').style.border='1px solid #99CC33';
		document.getElementById('erroResumoPequeno').style.display='none';
		document.getElementById('erroResumoLimite').style.display='none';
	}
	return erro;
}

function validaTestemunho(ref, value){
	var tam=value.length;
	var erro=false;
	if(tam<=400){
		document.getElementById('testemunho').style.background='#FFCCCC';
		document.getElementById('testemunho').style.border='1px solid #FF0000';
		document.getElementById('erroTestemunhoPequeno').style.display='inline';
		erro=true;
	}
	else if(tam>=1000){
		document.getElementById('testemunho').style.background='#FFCCCC';
		document.getElementById('testemunho').style.border='1px solid #FF0000';
		document.getElementById('erroTestemunhoLimite').style.display='inline';
		erro=true;
	}
	else{
		document.getElementById('testemunho').style.background='#FFFFFF';
		document.getElementById('testemunho').style.border='1px solid #99CC33';
		document.getElementById('erroTestemunhoPequeno').style.display='none';
		document.getElementById('erroTestemunhoLimite').style.display='none';
	}
	return erro;
}

function validaFormTestemunho(ref){
	retorno=true;
	if(validaNome(this, ref.nome.value)){
		retorno=false;
	}
	if(validaFoto(this, ref.foto.value)){
		retorno = false;
	}
	if(validaResumo(this, ref.resumo.value)){
		retorno = false;
	}
	if(validaTestemunho(this, ref.testemunho.value)){
		retorno = false;
	}
	return retorno;
}
