// 
// Salomão Design
// Formulário do Solicitação de Orçamento.
//

function valida_formOrca() {
	if (document.fcadastroIE.VarDia.value == "") {
		window.alert("Selecione um DIA no campo Data:");
		document.fcadastroIE.VarDia.focus();
		return false;
	}
	if (document.fcadastroIE.VarMes.value == "") {
		window.alert("Selecione um MES no campo Data:");
		document.fcadastroIE.VarMes.focus();
		return false;
	}
	if (document.fcadastroIE.VarAno.value == "") {
		window.alert("Selecione um ANO no campo Data:");
		document.fcadastroIE.VarAno.focus();
		return false;
	}
	//var DiaDeHoje = new Date() 
	//var DataCompleta = document.fcadastroIE.VarDia.value + "/" + document.fcadastroIE.VarMes.value  + "/" + document.fcadastroIE.VarAno.value
	if (document.fcadastroIE.VarHora.value == "") {
		window.alert("Por favor, preencha campo HORARIO:");
		document.fcadastroIE.VarHora.focus();
		return false;
	}
	if (document.fcadastroIE.VarNome.value == "") {
		window.alert("Por favor, preencha campo NOME:");
		document.fcadastroIE.VarNome.focus();
		return false;
	}
	if (document.fcadastroIE.VarTelResidencial.value == "") {
		window.alert("Por favor, preencha o campo Telefone Residencial:");
		document.fcadastroIE.VarTelResidencial.focus();
		return false;
	}
	if (document.fcadastroIE.VarEmail.value == "") {
		window.alert("Por favor, preencha o campo E-mail:");
		document.fcadastroIE.VarEmail.focus();
		return false;
	} else {
		if (!verificaEmail(document.fcadastroIE.VarEmail.value)) {
			window.alert("E-mail encontra-se com formato invalido!!");
			document.fcadastroIE.VarEmail.focus();
			return false;
		}
	}
	if (document.fcadastroIE.VarTipoEvento.value == "") {
		window.alert("Selecione o Tipo de evento na listagem.");
		document.fcadastroIE.VarTipoEvento.focus();
		return false;
	}	
	if (document.fcadastroIE.VarNumeroConvidados.value == "") {
		window.alert("Por favor, preencha campo Numero de convidados:");
		document.fcadastroIE.VarNumeroConvidados.focus();
		return false;
	}

	return true;
}
// Calendario
function PassagemCalendario (targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

// Criterios do form Cidades selecionadas
function formCidadesUF()
{
	if (document.formCidadeEstadoProcura.CidadeSelecionada.value == "") 
	{
		window.alert("Selecione a cidade onde você reside?");
		document.formCidadeEstadoProcura.CidadeSelecionada.focus();
		return false;
	}
    return true;
}

// Verifica se uma string tem vogais acentuadas
function vogalAcentuada(s) {
	ls = s.toLowerCase();
	if ((ls.indexOf("á")>=0) || (ls.indexOf("à")>=0) || (ls.indexOf("ã")>=0) || (ls.indexOf("â")>=0) || (ls.indexOf("é")>=0) || (ls.indexOf("í")>=0) || (ls.indexOf("ó")>=0) || (ls.indexOf("õ")>=0) || (ls.indexOf("ô")>=0) || (ls.indexOf("ú")>=0) || (ls.indexOf("ü")>=0))
		return true;
}

// Verifica se um email é válido
function verificaEmail(email) {
	var s = new String(email);
	// { } ( ) < > [ ] | \ /
	if ((s.indexOf("{")>=0) || (s.indexOf("}")>=0) || (s.indexOf("(")>=0) || (s.indexOf(")")>=0) || (s.indexOf("<")>=0) || (s.indexOf(">")>=0) || (s.indexOf("[")>=0) || (s.indexOf("]")>=0) || (s.indexOf("|")>=0) || (s.indexOf("\"")>=0) || (s.indexOf("/")>=0) )
		return false;
	if (vogalAcentuada(email))
		return false;
	// & * $ % ? ! ^ ~ ` ' "
	if ((s.indexOf("&")>=0) || (s.indexOf("*")>=0) || (s.indexOf("$")>=0) || (s.indexOf("%")>=0) || (s.indexOf("?")>=0) || (s.indexOf("!")>=0) || (s.indexOf("^")>=0) || (s.indexOf("~")>=0) || (s.indexOf("`")>=0) || (s.indexOf("'")>=0) )
		return false;
	// , ; : = #
	if ((s.indexOf(",")>=0) || (s.indexOf(";")>=0) || (s.indexOf(":")>=0) || (s.indexOf("=")>=0) || (s.indexOf("#")>=0) )
		return false;
	// procura se existe apenas um @
	if ( (s.indexOf("@") < 0) || (s.indexOf("@") != s.lastIndexOf("@")) )
		return false;
	// verifica se tem pelo menos um ponto após o @
	if (s.lastIndexOf(".") < s.indexOf("@"))
		return false;
	return true;
}

// Verifica se um campo é inteiro, inclui dígitos de 0 a 9, vírgula, ponto, espaços e -
function isInteger(s){
	var i;
	if (isEmpty(s))
		return false;
	for (i = 0; i < s.length; i++)
	{
		var c = s.charAt(i);
		if (!isNumber(c)) return false;
	}
	return true;
}

//  Verifica se um CPF é válido
function verificaCPF(cpf)
{
	if(cpf == "") {
		return true;
	}
	var dac = "", inicio = 2, fim = 10, soma, digito, i, j
	for (j=1;j<=2;j++) {
		soma = 0
		for (i=inicio;i<=fim;i++) {
			soma += parseInt(cpf.substring(i-j-1,i-j))*(fim+1+j-i)
		}
		if (j == 2) { soma += 2*digito }
		digito = (10*soma) % 11
		if (digito == 10) { digito = 0 }
		dac += digito
		inicio = 3
		fim = 11
	}
	return (dac == cpf.substring(cpf.length-2,cpf.length))
}

// Mensagem de Erro
function MSG_ERRO(erro) {
	window.alert(erro);
}
