// JavaScript Document


/*---- FORMULARIO ------------------------------------------------------------------------------------------------------*/
/*PREENCHIMENTO PADRAO*/
	//Entrada do campos
	function padraoIn(id, conteudo) {
		if(document.getElementById(id).value == conteudo) {
			document.getElementById(id).value = '';
			return true;
		}
	}
	
	//Saindo do campos
	function padraoOut(id, conteudo) {
		if(document.getElementById(id).value == '') {
			document.getElementById(id).value = conteudo;
			return true;
		}
	}


/*CAMPOS OBRIGATORIOS*/
	//Funcao para destacar campos
	function camposObrigatorios(form, total) {
		for (var i=1; i<=total; i++) {
			document.getElementById('Obrig'+ form + i).style.color="#EE0000";
		}
	}
	
	//Funcao para ofuscar campos
	function limpaCamposObrig(form, total) {
		for (var i=1; i<=total; i++) {
			document.getElementById('Obrig'+ form + i).style.color="#79204c";
		}
	}

/*CAMPOS RESET*/
	function camposReset(form, total){
		// Chama função ZERA CAMPOS OBRIGATORIOS
		limpaCamposObrig(form, total);
		
		// LIMPA CAMPOS E DEFINE FOCUS
		document.getElementById(form).reset();
		document.getElementById('nome'+form).focus();
	}
	
	// Limpa campos da pagina anterior
		function ParentCamposReset(form, total){
			window.opener.camposReset(form, total);
		}
	
/*VALIDA FORMULARIOS*/

	//Form CADASTRO
	function validaFormCadastro(form, total) {
		
		// Função de validação do campo
			var nome = document.getElementById('nome'+form).value;
			
			if ( nome == null || nome == '' || nome.length<3){
				//Obrigatorios
				limpaCamposObrig(form, total);
				document.getElementById('Obrig'+ form + '1').style.color="#EE0000";
				//Alerta
				alert("Preencha o NOME corretamente");
				document.getElementById('nome'+form).focus();
				
				return false;
			}

		// Função de validação do campo
			var email = document.getElementById('email'+form).value;
			
			parte1 = email.indexOf("@");
			parte2 = email.indexOf(".");
			parte3 = email.length;
			
			if ( email == null || email == '' || !(parte1 >= 3 && parte2 >= 6 && parte3 >= 9)) {
				//Obrigatorios
				limpaCamposObrig(form, total);
				document.getElementById('Obrig'+ form + '2').style.color="#EE0000";
				//Alerta
				alert("Preencha o E-MAIL corretamente");
				document.getElementById('email'+form).focus();
				
				return false;
			}

		// Função de validação do campo
			var telefone = document.getElementById('telefone'+form).value;
			
			if ( telefone == null || telefone == "" || telefone.length<10 || telefone == "ddd . nnnn-nnnn") {
				//Obrigatorios
				limpaCamposObrig(form, total);
				document.getElementById('Obrig'+ form + '3').style.color="#EE0000";
				//Alerta
				alert("Preencha o TELEFONE corretamente.");
				document.getElementById('telefone'+form).focus();
				
				return false;
			}

		// Função de validação do campo
			var cidade = document.getElementById('cidade'+form).value;
			
			if ( cidade == null || cidade == "" || cidade.length<3) {
				//Obrigatorios
				limpaCamposObrig(form, total);
				document.getElementById('Obrig'+ form + '4').style.color="#EE0000";
				//Alerta
				alert("Preencha a CIDADE corretamente.");
				document.getElementById('cidade'+form).focus();
				
				return false;
			}

		// Função de validação do campo
			var cep = document.getElementById('cep'+form).value;
			
			if ( cep == null || cep == "" || cidade.length < 7 || isNaN(cep)) {
				//Obrigatorios
				limpaCamposObrig(form, total);
				document.getElementById('Obrig'+ form + '6').style.color="#EE0000";
				//Alerta
				alert("Preencha o CEP corretamente. Obs.: Somente numeros.");
				document.getElementById('cep'+form).focus();
				
				return false;
			}


		// Função de validação do campo
			var mensagem = document.getElementById('mensagem'+form).value;
			
			if ( mensagem == null || mensagem == "" || mensagem.length<3) {
				//Obrigatorios
				limpaCamposObrig(form, total);
				document.getElementById('Obrig'+ form + '7').style.color="#EE0000";
				//Alerta
				alert("Preencha a MENSAGEM corretamente.");
				document.getElementById('mensagem'+form).focus();
				
				return false;
			}
		
		return true;
	}

	//Form CADASTRO
	function validaFormContato(form, total) {
		
		// Função de validação do campo
			var nome = document.getElementById('nome'+form).value;
			
			if ( nome == null || nome == '' || nome.length<3){
				//Obrigatorios
				limpaCamposObrig(form, total);
				document.getElementById('Obrig'+ form + '1').style.color="#EE0000";
				//Alerta
				alert("Preencha o NOME corretamente");
				document.getElementById('nome'+form).focus();
				
				return false;
			}

		// Função de validação do campo
			var email = document.getElementById('email'+form).value;
			
			parte1 = email.indexOf("@");
			parte2 = email.indexOf(".");
			parte3 = email.length;
			
			if ( email == null || email == '' || !(parte1 >= 3 && parte2 >= 6 && parte3 >= 9)) {
				//Obrigatorios
				limpaCamposObrig(form, total);
				document.getElementById('Obrig'+ form + '2').style.color="#EE0000";
				//Alerta
				alert("Preencha o E-MAIL corretamente");
				document.getElementById('email'+form).focus();
				
				return false;
			}

		// Função de validação do campo
			var telefone = document.getElementById('telefone'+form).value;
			
			if ( telefone == null || telefone == "" || telefone.length<10 || telefone == "ddd . nnnn-nnnn") {
				//Obrigatorios
				limpaCamposObrig(form, total);
				document.getElementById('Obrig'+ form + '3').style.color="#EE0000";
				//Alerta
				alert("Preencha o TELEFONE corretamente.");
				document.getElementById('telefone'+form).focus();
				
				return false;
			}

		// Função de validação do campo
			var mensagem = document.getElementById('mensagem'+form).value;
			
			if ( mensagem == null || mensagem == "" || mensagem.length<3) {
				//Obrigatorios
				limpaCamposObrig(form, total);
				document.getElementById('Obrig'+ form + '4').style.color="#EE0000";
				//Alerta
				alert("Preencha a MENSAGEM corretamente.");
				document.getElementById('mensagem'+form).focus();
				
				return false;
			}
		
		return true;
	}

