// 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="#000000";

		}

	}

	

	//Funcao para ofuscar campos

	function limpaCamposObrig(form, total) {

		for (var i=1; i<=total; i++) {

			document.getElementById('Obrig'+ form + i).style.color="#F73117";

		}

	}

	//Funcao para ofuscar campos 2

	function limpaCamposObrig2(form, total) {

		for (var i=1; i<=total; i++) {

			document.getElementById('Obrig'+ form + i).style.color="#FFD90E";

		}

	}



/*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="#000000";

				//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="#000000";

				//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="#000000";

				//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="#000000";

				//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="#000000";

				//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="#000000";

				//Alerta

				alert("Preencha a MENSAGEM corretamente.");

				document.getElementById('mensagem'+form).focus();

				

				return false;

			}

		

		return true;

	}



	//Form CONTATO

	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="#000000";

				//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="#000000";

				//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<12 ) {

				//Obrigatorios

				limpaCamposObrig(form, total);

				document.getElementById('Obrig'+ form + '3').style.color="#000000";

				//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 + '5').style.color="#000000";

				//Alerta

				alert("Preencha a CIDADE corretamente.");

				document.getElementById('cidade'+form).focus();

				

				return false;

			}



		// Função de validação do campo

			var bairro = document.getElementById('bairro'+form).value;

			

			if ( bairro == null || bairro == "" || bairro.length<3) {

				//Obrigatorios

				limpaCamposObrig(form, total);

				document.getElementById('Obrig'+ form + '6').style.color="#000000";

				//Alerta

				alert("Preencha a BAIRRO corretamente.");

				document.getElementById('bairro'+form).focus();

				

				return false;

			}

			

		// Função de validação do campo

			var motivo = document.getElementById('motivo'+form).value;

			

			if ( motivo == null || motivo == "") {

				//Obrigatorios

				limpaCamposObrig(form, total);

				document.getElementById('Obrig'+ form + '7').style.color="#000000";

				//Alerta

				alert("Selecione uma das opcoes do MOTIVO DO CONTATO.");

				document.getElementById('motivo'+form).focus();

				

				return false;

			}



		// Função de validação do campo

			var texto = document.getElementById('texto'+form).value;

			

			if ( texto == null || texto == "" || texto.length<3) {

				//Obrigatorios

				limpaCamposObrig(form, total);

				document.getElementById('Obrig'+ form + '8').style.color="#000000";

				//Alerta

				alert("Preencha a TEXTO corretamente.");

				document.getElementById('texto'+form).focus();

				

				return false;

			}

		

		return true;

	}



	//Form CONTATO ENG

	function validaFormContatoEng(form, total) {

		

		// Função de validação do campo

			var name = document.getElementById('name'+form).value;

			

			if ( name == null || name == '' || name.length<3){

				//Obrigatorios

				limpaCamposObrig(form, total);

				document.getElementById('Obrig'+ form + '1').style.color="#000000";

				//Alerta

				alert("Fill in the NAME correctly.");

				document.getElementById('name'+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="#000000";

				//Alerta

				alert("Fill in the E-MAIL correctly.");

				document.getElementById('email'+form).focus();

				

				return false;

			}

			

		// Função de validação do campo

			var company = document.getElementById('company'+form).value;

			

			if ( company == null || company == '' || company.length<3){

				//Obrigatorios

				limpaCamposObrig(form, total);

				document.getElementById('Obrig'+ form + '3').style.color="#000000";

				//Alerta

				alert("Fill in the COMPANY correctly.");

				document.getElementById('company'+form).focus();

				

				return false;

			}

			

		// Função de validação do campo

			var country = document.getElementById('country'+form).value;

			

			if ( country == null || country == '' || country.length<3){

				//Obrigatorios

				limpaCamposObrig(form, total);

				document.getElementById('Obrig'+ form + '4').style.color="#000000";

				//Alerta

				alert("Fill in the COUNTRY correctly.");

				document.getElementById('country'+form).focus();

				

				return false;

			}



		// Função de validação do campo

			var phone = document.getElementById('phone'+form).value;

			

			if ( phone == null || phone == "" || phone.length<8 ) {

				//Obrigatorios

				limpaCamposObrig(form, total);

				document.getElementById('Obrig'+ form + '5').style.color="#000000";

				//Alerta

				alert("Fill in the PHONE correctly.");

				document.getElementById('phone'+form).focus();

				

				return false;

			}





		// Função de validação do campo

			var message = document.getElementById('message'+form).value;

			

			if ( message == null || message == "" || message.length<3) {

				//Obrigatorios

				limpaCamposObrig(form, total);

				document.getElementById('Obrig'+ form + '6').style.color="#000000";

				//Alerta

				alert("Fill in the MESSAGE correctly.");

				document.getElementById('message'+form).focus();

				

				return false;

			}

		

		return true;

	}

	

	

	//Form CONTATO ESP

	function validaFormContatoEsp(form, total) {

		

		// Função de validação do campo

			var nombre = document.getElementById('nombre'+form).value;

			

			if ( nombre == null || nombre == '' || nombre.length<3){

				//Obrigatorios

				limpaCamposObrig(form, total);

				document.getElementById('Obrig'+ form + '1').style.color="#000000";

				//Alerta

				alert("Rellene el NOMBRE correcto.");

				document.getElementById('nombre'+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="#000000";

				//Alerta

				alert("Rellene el E-MAIL correcto.");

				document.getElementById('email'+form).focus();

				

				return false;

			}

			

		// Função de validação do campo

			var empresa = document.getElementById('empresa'+form).value;

			

			if ( empresa == null || empresa == '' || empresa.length<3){

				//Obrigatorios

				limpaCamposObrig(form, total);

				document.getElementById('Obrig'+ form + '3').style.color="#000000";

				//Alerta

				alert("Rellene el EMPRESA correcto.");

				document.getElementById('empresa'+form).focus();

				

				return false;

			}

			

		// Função de validação do campo

			var pais = document.getElementById('pais'+form).value;

			

			if ( pais == null || pais == '' || pais.length<3){

				//Obrigatorios

				limpaCamposObrig(form, total);

				document.getElementById('Obrig'+ form + '4').style.color="#000000";

				//Alerta

				alert("Rellene el PAIS correcto.");

				document.getElementById('pais'+form).focus();

				

				return false;

			}



		// Função de validação do campo

			var phone = document.getElementById('phone'+form).value;

			

			if ( phone == null || phone == "" || phone.length<8 ) {

				//Obrigatorios

				limpaCamposObrig(form, total);

				document.getElementById('Obrig'+ form + '5').style.color="#000000";

				//Alerta

				alert("Rellene el PHONE correcto.");

				document.getElementById('phone'+form).focus();

				

				return false;

			}





		// Função de validação do campo

			var mensaje = document.getElementById('mensaje'+form).value;

			

			if ( mensaje == null || mensaje == "" || mensaje.length<3) {

				//Obrigatorios

				limpaCamposObrig(form, total);

				document.getElementById('Obrig'+ form + '6').style.color="#000000";

				//Alerta

				alert("Fill in the MENSAJE correctly.");

				document.getElementById('mensaje'+form).focus();

				

				return false;

			}

		

		return true;

	}

	//Form LOGIN
	function validaFormLogin(form, total) {
		
		// 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 + '1').style.color="#F73117";
				//Alerta
				alert("Preencha o E-MAIL do Usuario corretamente");
				document.getElementById('email'+form).focus();
				
				return false;
			}

		// Função de validação do campo
			var senha = document.getElementById('senha'+form).value;
			
			if ( senha == null || senha == "" || senha.length<6 ) {
				//Obrigatorios
				limpaCamposObrig2(form, total);
				document.getElementById('Obrig'+ form + '2').style.color="#F73117";
				//Alerta
				alert("Preencha a SENHA corretamente.");
				document.getElementById('senha'+form).focus();
				
				return false;
			}

		return true;
	}
	
	//Form PEDIDO
	function validaFormPedido(form, total) {
		
		// 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 + '1').style.color="#000000";
				//Alerta
				alert("Preencha o E-MAIL corretamente");
				document.getElementById('email'+form).focus();
				
				return false;
			}
			
		
		// Função de validação do campo
			var nrpedido = document.getElementById('nrpedido'+form).value;
			
			if ( nrpedido == null || nrpedido == "" || nrpedido.length<3 ) {
				
				//Obrigatorios
				limpaCamposObrig(form, total);
				document.getElementById('Obrig'+ form + '2').style.color="#000000";
				//Alerta
				alert("Preencha o NUMERO DO PEDIDO corretamente.");
				document.getElementById('nrpedido'+form).focus();
				
				return false;
			}

		
		// Função de validação do campo 
			var cnpj = document.getElementById('cnpj'+form).value;
			
			if ( cnpj == null || cnpj == "" || cnpj.length<12 ) {
				
				//Obrigatorios
				limpaCamposObrig(form, total);
				document.getElementById('Obrig'+ form + '3').style.color="#000000";
				//Alerta
				alert("Preencha o CNPJ corretamente.");
				document.getElementById('cnpj'+form).focus();
				
				return false;
			}
		
		// Função de validação do campo
			var item1Qtd = document.getElementById('item1Qtd'+form).value;
			
			if ( item1Qtd == null || item1Qtd == "" || item1Qtd.length<1 ) {
				//Obrigatorios
				limpaCamposObrig(form, total);
				document.getElementById('Obrig'+ form + '4').style.color="#FFFFFF";
				//Alerta
				alert("Preencha a QUANTIDADE do Item corretamente.");
				document.getElementById('item1Qtd'+form).focus();
				
				return false;
			}
			
		// Função de validação do campo
			var item1Modelo = document.getElementById('item1Modelo'+form).value;
			
			if ( item1Modelo == null || item1Modelo == "" || item1Modelo.length<3 ) {
				//Obrigatorios
				limpaCamposObrig(form, total);
				document.getElementById('Obrig'+ form + '5').style.color="#FFFFFF";
				//Alerta
				alert("Preencha o MODELO do Item corretamente.");
				document.getElementById('item1Modelo'+form).focus();
				
				return false;
			}
			
		// Função de validação do campo
			var item1Tamanho = document.getElementById('item1Tamanho'+form).value;
			
			if ( item1Tamanho == null || item1Tamanho == "") {
				//Obrigatorios
				limpaCamposObrig(form, total);
				document.getElementById('Obrig'+ form + '6').style.color="#FFFFFF";
				//Alerta
				alert("Preencha o TAMANHO do Item corretamente.");
				document.getElementById('item1Tamanho'+form).focus();
				
				return false;
			}
			
		// Função de validação do campo
			var item1Cor = document.getElementById('item1Cor'+form).value;
			
			if ( item1Cor == null || item1Cor == "" || item1Cor.length<3 ) {
				//Obrigatorios
				limpaCamposObrig(form, total);
				document.getElementById('Obrig'+ form + '7').style.color="#FFFFFF";
				//Alerta
				alert("Preencha a COR do Item corretamente.");
				document.getElementById('item1Cor'+form).focus();
				
				return false;
			}


		return true;
	}
	
	//Form RELATORIO
	function validaFormRel(form, total) {
		
		// Função de validação do campo
			var representante = document.getElementById('representante'+form).value;
			
			if ( representante == null || representante == "" || representante.length<3 ) {
				
				//Obrigatorios
				limpaCamposObrig(form, total);
				document.getElementById('Obrig'+ form + '1').style.color="#000000";
				//Alerta
				alert("Preencha o NOME DO REPRESENTANTE corretamente.");
				document.getElementById('representante'+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="#000000";
				//Alerta
				alert("Preencha o E-MAIL corretamente");
				document.getElementById('email'+form).focus();
				
				return false;
			}
		
		// Função de validação do campo
			var cliente = document.getElementById('cliente'+form).value;
			
			if ( cliente == null || cliente == "" || cliente.length<3 ) {
				
				//Obrigatorios
				limpaCamposObrig(form, total);
				document.getElementById('Obrig'+ form + '3').style.color="#000000";
				//Alerta
				alert("Preencha o NOME DO CLIENTE corretamente.");
				document.getElementById('cliente'+form).focus();
				
				return false;
			}
		
		
		// Função de validação do campo 
			var data = document.getElementById('data'+form).value;
			
			if ( data == null || data == "" || data.length<8 ) {
				
				//Obrigatorios
				limpaCamposObrig(form, total);
				document.getElementById('Obrig'+ form + '4').style.color="#000000";
				//Alerta
				alert("Preencha a DATA DA VISITA corretamente.");
				document.getElementById('data'+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 + '5').style.color="#000000";
				//Alerta
				alert("Preencha a CIDADE corretamente.");
				document.getElementById('cidade'+form).focus();
				
				return false;
			}
		
		
		// Função de validação do campo 
			var motivo = document.getElementById('motivo'+form).value;
			
			if ( motivo == null || motivo == "" || motivo.length<3 ) {
				
				//Obrigatorios
				limpaCamposObrig(form, total);
				document.getElementById('Obrig'+ form + '6').style.color="#000000";
				//Alerta
				alert("Preencha a MOTIVO DA COMPRA corretamente.");
				document.getElementById('motivo'+form).focus();
				
				return false;
			}
		
		return true;
	}


/*---- MASCARAS ------------------------------------------------------------------------------------------------------*/	

	function mascaraTelefone() {

		if(document.form.telefoneformCont.value.length == 2) {

			document.form.telefoneformCont.value += ' ';

		}

		if(document.form.telefoneformCont.value.length == 7) {

			document.form.telefoneformCont.value += '-';

		}

	}





/*---- FUNCAO SHOW TOPICOS ------------------------------------------------------------------------------------------------------*/

function showTopicos(quantidade,qual){

	for (var i=1; i<=quantidade; i++){

		$('show'+i).removeClassName('showabre');

	}

	if (qual != '') {

		$('show'+qual).addClassName('showabre');	

	}

}


/*---- Funcao Data ------------------------------------------------------------------------------------------------------*/
function printDate(){
	
	// Today's Date
	var now = new Date();
	var Month = now.getMonth() + 1;
	var dayNr = now.getDate();
	var yearNr=now.getYear();
	var daynow = now.getDay();
	
	//Definindo Ano
	if(yearNr < 2000) Year = 1900 + yearNr;
	else Year = yearNr;
	
	// Coletando informacao e exibindo-as.
	var todaysDate =(dayNr + "/" + Month + "/" + Year);
	document.write(todaysDate);
	
} 

function mascaraData(campoData){
	var data = campoData.value;
	
	if (data.length == 2){
		data = data + '/';
		document.forms[0].Data.value = data;
		return true;              
	}
	
	if (data.length == 5){
		data = data + '/';
		document.forms[0].Data.value = data;
		return true;
	}
}


