﻿//*****************************************************************************
//Objetivo:					Encapsular funcionalidades do Envio de Email
//Autor:					Marcelo Pacheco
//Data:						12/05/2004
//Autor:					Flávio Almeida
//Data Ultima alteração:	16/06/2005
//Motivo:					-
// Alterado por:			Cristiane Habiro (7COMm)
// Data: 					24/04/2006
// Motivo da Alteração: 	Validação do campo e-mail

//*****************************************************************************

//*****************************************************************************
// DECLARAÇÃO DAS VARIÁVEIS
//*****************************************************************************
//============================================================================================
// objetivo........: Valida campos do formulario
// Premissas.......:
// Entradas........: 
// Retorno.........: 
//============================================================================================	
function ValidaForm(objFrm)
{
	try
	{
		var intAux // Variavel utilizada no laço for
		var intIAux // Variavel utilizada no laço for
		var strNameRadio // Nome do objeto radio
		var objRadio	// Objeto radio
		var blnVerifica	// Verifica se o objeto foi marcado	
		
		for(intAux=0;intAux<objFrm.length;intAux++)
		{
			if (objFrm[intAux].type == 'radio') 
			{
				strNameRadio = objFrm[intAux].name
				objRadio = eval('objFrm.'+ strNameRadio)			
				blnVerifica = 0
				for(intIAux=0;intIAux<objRadio.length;intIAux++) 
				{
					if (objRadio[intIAux].checked) {
						blnVerifica = 1;
						break;
					}	
				}
				if (blnVerifica == 0) 
				{
					objFrm[intAux].focus();
					throw ("Escolha uma empresa no quadro.");
				}
			}
			if (objFrm.txtNomeCompleto.value == "")
			{
				objFrm.txtNomeCompleto.focus();
				throw ("O Campo Nome é obrigatório!");
			}
			if (objFrm.txtEmpresa.value == "")
			{
				objFrm.txtEmpresa.focus();
				throw ("O Campo Empresa é obrigatório!");
			}
			if (objFrm.txtCargo.value == "")
			{
				objFrm.txtCargo.focus();
				throw ("O Campo Cargo é obrigatório!");
			}
			if (objFrm.txtProfissao.value == "")
			{
				throw ("O Campo Profissão é obrigatório!");
				objFrm.txtProfissao.focus();
			}				
			if (objFrm.txtID.value == "")
			{
				objFrm.txtID.focus();
				throw ("O Campo CPF/CNPJ é obrigatório!");
			}
			if (objFrm.txtDia.value == "")
			{
				objFrm.txtDia.focus();
				throw ("O Campo Dia é obrigatório!");
			}
			if (objFrm.txtMes.value == "")
			{
				objFrm.txtMes.focus();
				throw ("O Campo Mês é obrigatório!");
			}
			if (objFrm.txtAno.value == "")
			{
				objFrm.txtAno.focus();
				throw ("O Campo Ano é obrigatório!");
			}
			if (objFrm.txtEntrega.value == "")
			{
				objFrm.txtEntrega.focus();
				throw ("O Campo Endereço de Entrega é obrigatório!");
			}
			if (objFrm.txtCidadeA.value == "")
			{
				objFrm.txtCidadeA.focus();
				throw ("O Campo Cidade é obrigatório!");
			}				
			if (objFrm.txtEstadoA.value == "")
			{
				objFrm.txtEstadoA.focus();
				throw ("O Campo Estado é obrigatório!");
			}
			if (objFrm.txtCepA.value == "")
			{
				objFrm.txtCepA.focus();
				throw ("O Campo CEP é obrigatório!");
			}
			if (objFrm.txtDDD.value == "")
			{
				objFrm.txtDDD.focus();
				throw ("O Campo DDD é obrigatório!");
			}
			if (objFrm.txtFone.value == "")
			{
				objFrm.txtFone.focus();
				throw ("O Campo Telefone é obrigatório!");
			}		
			if(ValidarEmail(objFrm.txtEmail.value) != true )
			{
				objFrm.txtEmail.focus();
				throw  objFrm.txtEmail.name.substr(3) + " inválido.";
			}				
			if (objFrm.txtCobranca.value == "")
			{
				objFrm.txtCobranca.focus();
				throw ("O Campo Endereço de cobrança é obrigatório!");
			}
			if (objFrm.txtCidadeB.value == "")
			{
				objFrm.txtCidadeB.focus();
				throw ("O Campo Cidade de cobrança é obrigatório!");
			}
			if (objFrm.txtEstadoB.value == "")
			{
				objFrm.txtEstadoB.focus();
				throw ("O Campo Estado de cobrança é obrigatório!");
			}
			if (objFrm.txtCepB.value == "")
			{
				objFrm.txtCepB.focus();
				throw ("O Campo CEP de cobrança é obrigatório!");
			}
		}
		
		//objFrm.target = '_blank'
		objFrm.submit()	
	}
		catch(objExcep)
	{
		alert(objExcep.toString());
	}
}