//###################################################################################
// pop ups
//###################################################################################
function PopUp(url, nome, largura, altura, sroll)
{
	var esq     = (screen.width - largura) / 2;
	var top    = (screen.height - altura) / 2;
	var janela = window.open(''+ url +'',''+ nome +'','width=' + largura + ',height=' + altura + ',top=' + top + ',left=' + esq + ',scrollbars='+ sroll +'');
	if (janela == null)
	{
		window.alert('POPUP BLOQUEADA.\n\nIdentificamos que você possui um bloqueador de popup, configure-o\npara aceitar popups do sistema.\n\nObrigado!');
	}
	else
	{
		janela.focus();
	}
}
//###################################################################################
// locais
//###################################################################################
function setLocal(msg, n)
{
	if (n == 1)
		document.getElementById("pSecao").innerHTML = msg;
	else
		document.getElementById("pDesc").innerHTML = msg;
}
//###################################################################################
// limpa campo para nova digitação
//###################################################################################
function fncLimpaValue(objTexto, sString) {

	if (sString == objTexto.value) {

		objTexto.value = '';
	}

}
//###################################################################################
// validar login
//###################################################################################
function validarLogin(f) {
   
    if (f.usuario.value.length == 0) {
        alert("Por favor, informe o usu\xE1rio !");
		f.usuario.className = "textreq";
        f.usuario.focus();
        return false;
    }

    if (f.acao.checked == false) {
        if (f.senha.value.length == 0) {
            alert("Por favor, informe a senha !");
			f.senha.className = "textreq";
            f.senha.focus();
            return false;
        }
  }
}
//###################################################################################
// Mascara Moeda
//###################################################################################
function mascaraMoeda(campo, sepMilesimo, sepDecimal, e) // onKeyPress="javascript:return mascaraMoeda(this,'.',',',event);"
{
	var strCheck = '0123456789';
	var tecla = (window.Event) ? e.which : e.keyCode;
	if ( tecla == 8 || tecla == 9 || tecla == 13 || tecla == 0 ) { return true; }
	var key = String.fromCharCode(tecla);
	if ( strCheck.indexOf(key) == -1 ) { return false; }
	var len = campo.value.length;
	if (len >= 16) { return false; }
	for( var i = 0; i < len; i++ )
	{
		if ( (campo.value.charAt(i) != '0') && (campo.value.charAt(i) != sepDecimal) ) break;
	}
	var aux = '';
	for(; i < len; i++)
		if (strCheck.indexOf(campo.value.charAt(i))!=-1) aux += campo.value.charAt(i);
	aux += key;
	len = aux.length;
	if (len == 0) campo.value = '';
	if (len == 1) campo.value = '0'+ sepDecimal + '0' + aux;
	if (len == 2) campo.value = '0'+ sepDecimal + aux;
	if (len > 2) {
		var aux2 = '';
		for (var j = 0, i = len - 3; i >= 0; i--) {
			if (j == 3) {
				aux2 += sepMilesimo;
				j = 0;
			}
			aux2 += aux.charAt(i);
			j++;
		}
		var valor = ''
		var len2 = aux2.length;
		for (i = len2 - 1; i >= 0; i--)
		valor += aux2.charAt(i);
		valor += sepDecimal + aux.substr(len - 2, len);
		campo.value = valor;
	}
	return false;
}
//###################################################################################
// bloqueia enter
//###################################################################################
function bloquearEnter(campo, e) // onKeyPress="javascript:return bloquearEnter(this,event);"
{
	var tecla = (window.Event) ? e.which : e.keyCode;
	if ( tecla == 13 ) { return false; }
}
//###################################################################################
// Excluir
//###################################################################################
function excluir(id)
{
	if (window.confirm("Você realmente deseja excluir o registro?"))
	{
		window.location.href += "&acao=excluir&id="+ id +"";
	}
}

//***********************************************************************************************
// validar CNPJ
//***********************************************************************************************
function valida_CNPJ(s)
{
	var i;
	s = limpa_string(s);
	var c = s.substr(0,12);
	var dv = s.substr(12,2);
	var d1 = 0;
	for (i = 0; i < 12; i++)
	{
		d1 += c.charAt(11-i)*(2+(i % 8));
	}
        if (d1 == 0) return false;
        d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(0) != d1)
	{
		return false;
	}

	d1 *= 2;
	for (i = 0; i < 12; i++)
	{
		d1 += c.charAt(11-i)*(2+((i+1) % 8));
	}
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(1) != d1)
	{
		return false;
	}
        return true;
}
//***********************************************************************************************
// validar cpf
//***********************************************************************************************
function validarCPF(cpf)
{
	var soma;
	var valor;
	var digito_verificador;

	var aux;
	var validos = '0123456789'
	var numero = '';
	for (var i = 0; i < cpf.length; i++)
	{
		aux = validos.indexOf(cpf.substring(i, i+1));
		if (aux >= 0) { numero += aux }
	}

	if(numero.length != 11)
	{
		return false;
	}

	// Cálculo do Primeiro dígito do CPF
	soma = 0;
	for (var i = 0; i < 9; i++)
	{
		soma += (10-i) * parseInt(numero.charAt(i));
	}
	digito_verificador = 11 - (soma % 11);
	if ((soma % 11) < 2) digito_verificador = 0;

	if (parseInt(numero.charAt(9)) != digito_verificador)
	{
		return false;
	}

	// Cálculo do Segundo dígito do CPF
	soma = 0;
	for (var i = 0; i < 10; i++)
	{
		soma += (11-i) * parseInt(numero.charAt(i));
	}
	digito_verificador = 11 - (soma % 11);
	if ((soma % 11) < 2) digito_verificador = 0;

	if (parseInt(numero.charAt(10)) != digito_verificador)
	{
		return false;
	}

	return true;
}
//***********************************************************************************************
// limpar string deixando só números
//***********************************************************************************************
function limpa_string(S){ 
// Deixa so' os digitos no numero 
var Digitos = "0123456789"; 
var temp = ""; 
var digito = ""; 

for (var i=0; i<S.length; i++) { 
digito = S.charAt(i); 
if (Digitos.indexOf(digito)>=0) { 
temp=temp+digito } 
} //for 

return temp 
} 

//###################################################################################
// Validar Participantes
//###################################################################################
function validarParticipante(f)
{
	if (f.data_cadastro.value == '')
	{
		window.alert("Por favor, informe a data de cadastro.");
		f.data_cadastro.className = "textreq";
		f.data_cadastro.focus();
		return false;
	}
	if (f.nome.value == '')
	{
		window.alert("Por favor, digite o Nome do Participante.");
		f.nome.className = "textreq";
		f.nome.focus();
		return false;
	}
	var cpf1 = limpa_string(f.cpf.value);
	if (validarCPF(cpf1) == false)
	{
		window.alert("Por favor, informe o CPF v\xE1lido.");
		//window.alert('Por favor, informe um CPF v\xElido.');
		f.cpf.className = "textreq";
		f.cpf.focus();
		return false;
	}
	if (f.nascimento.value.length < 10)
	{
		window.alert("Por favor, digite a Data de Nascimento corretamente.");
		f.nascimento.className = "textreq";
		f.nascimento.focus();
		return false;
	}
	if (f.empresa.value == '')
	{
		window.alert("Por favor, digite o nome da empresa do Participante.");
		f.empresa.className = "textreq";
		f.empresa.focus();
		return false;
	}
	if (f.tel_comercial.value == '')
	{
		window.alert("Por favor, digite o telefone comercial do Participante.");
		f.tel_comercial.className = "textreq";
		f.tel_comercial.focus();
		return false;
	}
	if (f.tel_residencial.value == '')
	{
		window.alert("Por favor, digite o telefone residencial do Participante.");
		f.tel_residencial.className = "textreq";
		f.tel_residencial.focus();
		return false;
	}
	if (f.email_trabalho.value == '')
	{
		window.alert("Por favor, digite seu email de trabalho Participante.");
		f.email_trabalho.className = "textreq";
		f.email_trabalho.focus();
		return false;
	}
    if (f.email_trabalho.value != '') {
        if (f.email_trabalho.value.indexOf('@', 0) == -1 || f.email_trabalho.value.indexOf('.', 0) == -1) {
        alert("Por favor, preencha corretamente o campo e-mail de trabalho.");
		f.email_trabalho.className = 'textreq';
        f.email_trabalho.focus();
        return false;
        }
  }
  if (f.email_pessoal.value == '')
	{
		window.alert("Por favor, digite seu email pessoal Participante.");
		f.email_pessoal.className = "textreq";
		f.email_pessoal.focus();
		return false;
	}
	if (f.email_pessoal.value != '') {
        if (f.email_pessoal.value.indexOf('@', 0) == -1 || f.email_pessoal.value.indexOf('.', 0) == -1) {
        alert("Por favor, preencha corretamente o campo e-mail pessoal.");
		f.email_pessoal.className = 'textreq';
        f.email_pessoal.focus();
        return false;
        }
  }
  if ((f.refer1.checked == false) && (f.refer2.checked == false) && (f.refer3.checked == false) && (f.refer4.checked == false))
	{
		window.alert('Por favor, selecione pelo menu 1 veículo');
		return false;
	}
  if ((f.refer1.checked == true) && (f.marca_modelo.value == ''))
	{
		window.alert('Por favor, informe a marca e o modelo do veículo 1');
		f.marca_modelo.className = "textreq";
		f.marca_modelo.focus();
		return false;
	}
	if ((f.refer1.checked == true) && (f.ano_modelo.value == ''))
	{
		window.alert('Por favor, informe ano/modelo do veículo 1');
		f.ano_modelo.className = "textreq";
		f.ano_modelo.focus();
		return false;
	}
	if ((f.refer1.checked == true) && (f.placas.value == ''))
	{
		window.alert('Por favor, informe a placa do veículo 1');
		f.placas.className = "textreq";
		f.placas.focus();
		return false;
	}
	
	if ((f.refer1.checked == true) && (f.seguro[0].checked==false) && (f.seguro[1].checked==false))
	{
		window.alert('Por favor, informe informe se o veículo 1 possui seguro ou não');
		return false;
	}
	if ((f.refer1.checked == true) && (f.proponente[0].checked==false) && (f.proponente[1].checked==false)&& (f.proponente[2].checked==false)&& (f.proponente[3].checked==false))
	{
		window.alert('Por favor, informe informe quem será o proponente do seguro do veículo 1');
		return false;
	}
	if ((f.refer1.checked == true) && (f.seguro[0].checked==true) && (f.seguradora.value == ''))
	{
		window.alert('Por favor, informe a seguradora atual do veículo 1');
		f.seguradora.className = "textreq";
		f.seguradora.focus();
		return false;
	}
	
	if ((f.refer1.checked == true) && (f.seguro[0].checked==true) && (f.vencimento_apolice.value == ''))
	{
		window.alert('Por favor, informe a data de vencimento da apólice atual do veículo 1');
		f.vencimento_apolice.className = "textreq";
		f.vencimento_apolice.focus();
		return false;
	}
	if ((f.refer1.checked == true) && (f.seguro[0].checked==true) && (f.corretora_atual.value == ''))
	{
		window.alert('Por favor, informe a corretora da apólice atual do veículo 1');
		f.corretora_atual.className = "textreq";
		f.corretora_atual.focus();
		return false;
	}
	if ((f.refer1.checked == true) && (f.diponibilizar_apolice[0].checked==false) && (f.diponibilizar_apolice[1].checked==false))
	{
		window.alert('Por favor, selecione a informação sobre disponibilização da apólice para sorteios do veículo 1');
		return false;
	}
	
	
	
	if ((f.refer2.checked == true) && (f.marca_modelo2.value == ''))
	{
		window.alert('Por favor, informe a marca e o modelo do veículo 2');
		f.marca_modelo2.className = "textreq";
		f.marca_modelo2.focus();
		return false;
	}
	if ((f.refer2.checked == true) && (f.ano_modelo2.value == ''))
	{
		window.alert('Por favor, informe ano/modelo do veículo 2');
		f.ano_modelo2.className = "textreq";
		f.ano_modelo2.focus();
		return false;
	}
	if ((f.refer2.checked == true) && (f.placas2.value == ''))
	{
		window.alert('Por favor, informe a placa do veículo 2');
		f.placas2.className = "textreq";
		f.placas2.focus();
		return false;
	}
	
	if ((f.refer2.checked == true) && (f.seguro2[0].checked==false) && (f.seguro2[1].checked==false))
	{
		window.alert('Por favor, informe informe se o veículo 2 possui seguro ou não');
		return false;
	}
	if ((f.refer2.checked == true) && (f.proponente2[0].checked==false) && (f.proponente2[1].checked==false)&& (f.proponente2[2].checked==false)&& (f.proponente2[3].checked==false))
	{
		window.alert('Por favor, informe informe quem será o proponente do seguro do veículo 2');
		return false;
	}
	if ((f.refer2.checked == true) && (f.seguro2[0].checked==true) && (f.seguradora2.value == ''))
	{
		window.alert('Por favor, informe a seguradora atual do veículo 2');
		f.seguradora2.className = "textreq";
		f.seguradora2.focus();
		return false;
	}
	if ((f.refer2.checked == true) && (f.seguro2[0].checked==true) && (f.vencimento_apolice2.value == ''))
	{
		window.alert('Por favor, informe a data de vencimento da apólice atual do veículo 2');
		f.vencimento_apolice2.className = "textreq";
		f.vencimento_apolice2.focus();
		return false;
	}
	if ((f.refer2.checked == true) && (f.seguro2[0].checked==true) && (f.corretora_atual2.value == ''))
	{
		window.alert('Por favor, informe a corretora da apólice atual do veículo 2');
		f.corretora_atual2.className = "textreq";
		f.corretora_atual2.focus();
		return false;
	}
	if ((f.refer2.checked == true) && (f.diponibilizar_apolice2[0].checked==false) && (f.diponibilizar_apolice2[1].checked==false))
	{
		window.alert('Por favor, selecione a informação sobre disponibilização da apólice para sorteios do veículo 2');
		return false;
	}
	
	
	
	if ((f.refer3.checked == true) && (f.marca_modelo3.value == ''))
	{
		window.alert('Por favor, informe a marca e o modelo do veículo 3');
		f.marca_modelo3.className = "textreq";
		f.marca_modelo3.focus();
		return false;
	}
	if ((f.refer3.checked == true) && (f.ano_modelo3.value == ''))
	{
		window.alert('Por favor, informe ano/modelo do veículo 3');
		f.ano_modelo3.className = "textreq";
		f.ano_modelo3.focus();
		return false;
	}
	if ((f.refer3.checked == true) && (f.placas3.value == ''))
	{
		window.alert('Por favor, informe a placa do veículo 3');
		f.placas3.className = "textreq";
		f.placas3.focus();
		return false;
	}
	if ((f.refer3.checked == true) && (f.seguro3[0].checked==false) && (f.seguro3[1].checked==false))
	{
		window.alert('Por favor, informe informe se o veículo 3 possui seguro ou não');
		return false;
	}
	if ((f.refer3.checked == true) && (f.proponente3[0].checked==false) && (f.proponente3[1].checked==false)&& (f.proponente3[2].checked==false)&& (f.proponente3[3].checked==false))
	{
		window.alert('Por favor, informe informe quem será o proponente do seguro do veículo 3');
		return false;
	}
	if ((f.refer3.checked == true) && (f.seguro3[0].checked==true) && (f.seguradora3.value == ''))
	{
		window.alert('Por favor, informe a seguradora atual do veículo 3');
		f.seguradora3.className = "textreq";
		f.seguradora3.focus();
		return false;
	}
	if ((f.refer3.checked == true) && (f.seguro3[0].checked==true) && (f.vencimento_apolice3.value == ''))
	{
		window.alert('Por favor, informe a data de vencimento da apólice atual do veículo 3');
		f.vencimento_apolice3.className = "textreq";
		f.vencimento_apolice3.focus();
		return false;
	}
	if ((f.refer3.checked == true) && (f.seguro3[0].checked==true) && (f.corretora_atual3.value == ''))
	{
		window.alert('Por favor, informe a corretora da apólice atual do veículo 3');
		f.corretora_atual3.className = "textreq";
		f.corretora_atual3.focus();
		return false;
	}
	if ((f.refer3.checked == true) && (f.diponibilizar_apolice3[0].checked==false) && (f.diponibilizar_apolice3[1].checked==false))
	{
		window.alert('Por favor, selecione a informação sobre disponibilização da apólice para sorteios do veículo 3');
		return false;
	}
	
	if ((f.refer4.checked == true) && (f.marca_modelo4.value == ''))
	{
		window.alert('Por favor, informe a marca e o modelo do veículo 4');
		f.marca_modelo4.className = "textreq";
		f.marca_modelo4.focus();
		return false;
	}
	if ((f.refer4.checked == true) && (f.ano_modelo4.value == ''))
	{
		window.alert('Por favor, informe ano/modelo do veículo 4');
		f.ano_modelo4.className = "textreq";
		f.ano_modelo4.focus();
		return false;
	}
	if ((f.refer4.checked == true) && (f.placas4.value == ''))
	{
		window.alert('Por favor, informe a placa do veículo 4');
		f.placas4.className = "textreq";
		f.placas4.focus();
		return false;
	}
	if ((f.refer4.checked == true) && (f.seguro4[0].checked==false) && (f.seguro4[1].checked==false))
	{
		window.alert('Por favor, informe informe se o veículo 4 possui seguro ou não');
		return false;
	}
	if ((f.refer4.checked == true) && (f.proponente4[0].checked==false) && (f.proponente4[1].checked==false)&& (f.proponente4[2].checked==false)&& (f.proponente4[3].checked==false))
	{
		window.alert('Por favor, informe informe quem será o proponente do seguro do veículo 4');
		return false;
	}
	if ((f.refer4.checked == true) && (f.seguro4[0].checked==true) && (f.seguradora4.value == ''))
	{
		window.alert('Por favor, informe a seguradora atual do veículo 4');
		f.seguradora4.className = "textreq";
		f.seguradora4.focus();
		return false;
	}
	if ((f.refer4.checked == true) && (f.seguro4[0].checked==true) && (f.vencimento_apolice4.value == ''))
	{
		window.alert('Por favor, informe a data de vencimento da apólice atual do veículo 4');
		f.vencimento_apolice4.className = "textreq";
		f.vencimento_apolice4.focus();
		return false;
	}
	if ((f.refer4.checked == true) && (f.seguro4[0].checked==true) && (f.corretora_atual.value == ''))
	{
		window.alert('Por favor, informe a corretora da apólice atual do veículo 4');
		f.corretora_atual4.className = "textreq";
		f.corretora_atual4.focus();
		return false;
	}
	if ((f.refer4.checked == true) && (f.diponibilizar_apolice4[0].checked==false) && (f.diponibilizar_apolice4[1].checked==false))
	{
		window.alert('Por favor, selecione a informação sobre disponibilização da apólice para sorteios do veículo 4');
		return false;
	}
}

//###################################################################################
// validar senha
//###################################################################################
function valida_senha(f) {

    var i;
    var num = 0, carac = 0;
    
    if (f.senha.value.length == 0) {
        alert("Por favor, defina a senha administrativa!");
		f.senha.className = "textreq";
        f.senha.focus();
        return false;
    }
    
    for (i = 0; i < f.senha.value.length; i++) {
        var c = f.senha.value.charAt(i);
        // ha um numero
        if (((c >= "0") && (c <= "9"))) {
            num++;
        }
        if (((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z"))) {
            carac++;
        }
        if (c == "'" || c == "`" || c == "~" || c == '"' || c == '^') {
			
            alert("Campo com caracteres inválido!!");
			f.senha.className = "textreq";
            f.senha.focus();
            return false;
        }
    }
    
    if (num < 2 || carac == 0) {
        alert("Senha deve conter letras e números ( mínimo 2 números ) !!");
		f.senha.className = "textreq";
        f.senha.focus();
        return false;
    }

    if (f.senha.value.length == 0 || f.senha2.value.length == 0) {
        alert("As senhas administrativas são obrigatórias !");
		f.senha.className = "textreq";
        f.senha.focus();
        return false;
    }

    if (f.senha.value.length < 6) {
        alert("A senha administrativa deve ter no mínimo 6 caracteres !");
		f.senha.className = "textreq";
        f.senha.focus();
        return false;
    }

    if (f.senha.value.length > 14) {
        alert("A senha administrativa deve ter no máximo 14 caracteres !");
		f.senha.className = "textreq";
        f.senha.focus();
        return false;
    }

    if (f.senha.value != f.senha2.value) {
        alert("As senhas administrativas não são iguais !");
		f.senha.className = "textreq";
        f.senha.focus();
        return false;
    }
    
    var s;
    s = f.senha.value
    hoje = new Date()
    ano = hoje.getYear()
    for (f=-2; f<=2; f++){
        n = s.indexOf(ano + f,0)
        if (n > -1){
            alert("Não é permitido colocar o ano como senha.");
			f.senha.className = "textreq";
            f.senha.focus();
            return false;
        }
    }

    return true;

}
//###################################################################################
// validar imagens
//###################################################################################
function validarImagem(img)
{
	img = img.toLowerCase();
	var arrExt = new Array();
	arrExt     = img.split(".");
	var ext    = arrExt[ arrExt.length - 1 ]
	if ((ext != 'jpg') && (ext != 'jpeg') && (ext != 'gif'))
	{
		return false;
	}
	else
	{
		return true;
	}
}

//###################################################################################
// apagar usuario admin
//###################################################################################
function confirma_apagar() {
    var resposta;
    resposta = confirm("Tem certeza que deseja apagar ?");
    if (resposta == true) 
        return true;
    else
        return false;
}


//###################################################################################
// validar cadastro administradores
//###################################################################################
function validarAdm(f)
{
	if (f.nome.value == '')
	{
		window.alert('Por favor, digite o Nome do Usuário.');
		f.nome.className = "textreq";
		f.nome.focus();
		return false;
	}
	if (f.login.value == '')
	{
	    window.alert('Por favor, digite o Login do Usuário.');
		f.login.className = 'textreq';
		f.login.focus();
		return false;
	}
	padrao = /^[a-zA-Z0-9]+$/;

    campoValue = f.login.value;
    
    var campoVerify = campoValue.indexOf(" ");

    if (campoVerify>=0) {

        var campoArray = campoValue.split(" ");
        
        for(part_num=0;part_num<campoArray.length;part_num++){
        
            OK = padrao.exec(campoArray[part_num]);
            if (!OK){
                window.alert ("Por favor, preencha corretamente o nome do Usuário. Não são aceito caracteres especiais.");
                return false;
                break;
            }
        
        }
    
    }else{
    
        OK = padrao.exec(campoValue);
        if (!OK){
            window.alert ("Por favor, preencha corretamente o nome do Usuário. Não são aceito caracteres especiais.");
            return false;
        }

    }
	if (f.email.value == '')
	{
		window.alert('Por favor, digite o email do Usuário.');
		f.email.className = 'textreq';
		f.email.focus();
		return false;
	}
	if (f.email.value.indexOf('@', 0) == -1 || f.email.value.indexOf('.', 0) == -1) {
        alert("Por favor, preencha corretamente o campo e-mail.");
		f.email.className = 'textreq';
        f.email.focus();
        return false;
    }
	if (f.telefone.value == '')
	{
		
		window.alert('Por favor, digite o telefone do Usuário.');
		f.telefone.className = 'textreq';
		f.telefone.focus();
		return false;
	}
}
//###################################################################################
// validar validar campo
//###################################################################################
function valida_campo(campo,fr) {

    for(a=0;a<fr.elements.length;a++){
        if(fr.elements[a].name == campo){
            return true;
            break;
        }
    }

	return false;
}
//###################################################################################
// validar cadastro administradores
//###################################################################################
function validarAdmAlterar(f)
{
	if (f.nome.value == '')
	{
		window.alert('Por favor, digite o Nome do Usuário.');
		f.nome.className = "textreq";
		f.nome.focus();
		return false;
	}
	if (f.login.value == '')
	{
	    window.alert('Por favor, digite o Login do Usuário.');
		f.login.className = 'textreq';
		f.login.focus();
		return false;
	}
	padrao = /^[a-zA-Z0-9]+$/;

    campoValue = f.login.value;
    
    var campoVerify = campoValue.indexOf(" ");

    if (campoVerify>=0) {

        var campoArray = campoValue.split(" ");
        
        for(part_num=0;part_num<campoArray.length;part_num++){
        
            OK = padrao.exec(campoArray[part_num]);
            if (!OK){
                window.alert ("Por favor, preencha corretamente o nome do Usuário. Não são aceito caracteres especiais.");
                return false;
                break;
            }
        
        }
    
    }else{
    
        OK = padrao.exec(campoValue);
        if (!OK){
            window.alert ("Por favor, preencha corretamente o nome do Usuário. Não são aceito caracteres especiais.");
            return false;
        }

    }
	if (f.email.value == '')
	{
		window.alert('Por favor, digite o email do Usuário.');
		f.email.className = 'textreq';
		f.email.focus();
		return false;
	}
	if (f.email.value.indexOf('@', 0) == -1 || f.email.value.indexOf('.', 0) == -1) {
        alert("Por favor, preencha corretamente o campo e-mail.");
		f.email.className = 'textreq';
        f.email.focus();
        return false;
    }
	if (f.telefone.value == '')
	{
		
		window.alert('Por favor, digite o telefone do Usuário.');
		f.telefone.className = 'textreq';
		f.telefone.focus();
		return false;
	}
	if (valida_campo("ativasenha",f)) {
		if (f.ativasenha.checked == true) {

			var i;
			var num = 0, carac = 0;
			
			if (f.senha_atual.value.length == 0 || f.nova_senha.value.length == 0 || f.confima_nova_senha.value.length == 0) {
				alert("As senhas administrativas são obrigatórias !");
				f.senha_atual.className = 'textreq';
				f.senha_atual.focus();
				return false;
			}
			
			for (i = 0; i < f.nova_senha.value.length; i++) {
				var c = f.nova_senha.value.charAt(i);
				// ha um numero
				if (((c >= "0") && (c <= "9"))) {
					num++;
				}
				if (((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z"))) {
					carac++;
				}
				if (c == "'" || c == "`" || c == "~" || c == '"' || c == '^') {
					alert("Campo com caracteres inválido!!");
					f.nova_senha.className = 'textreq';
				    f.nova_senha.focus();
					return false;
				}
			}
			
			if (num < 2 || carac == 0) {
				alert("Senha deve conter letras e números ( mínimo 2 números ) !!");
				f.nova_senha.className = 'textreq';
				f.nova_senha.focus();
				return false;
			}

			if (f.nova_senha.value.length < 6) {
				alert("A senha administrativa deve ter no mínimo 6 caracteres !");
				f.nova_senha.className = 'textreq';
				f.nova_senha.focus();
				return false;
			}

			if (f.nova_senha.value.length > 14) {
				alert("A senha administrativa deve ter no máximo 14 caracteres !");
				f.nova_senha.className = 'textreq';
				f.nova_senha.focus();
				return false;
			}

			if (f.nova_senha.value != f.confima_nova_senha.value) {
				alert("As senhas administrativas não são iguais !");
				f.nova_senha.className = 'textreq';
				f.nova_senha.focus();
				return false;
			}
			
			var s;
			s = f.nova_senha.value
			hoje = new Date()
			ano = hoje.getYear()
			for (f=-2; f<=2; f++){
				n = s.indexOf(ano + f,0)
				if (n > -1){
					alert("Não é permitido colocar o ano como senha.");
					f.nova_senha.className = 'textreq';
					f.nova_senha.focus();
					return false;
				}
			}

		}
	}
}
//###################################################################################
// validar locais
//###################################################################################
function validarLocais(valor)
{
	vr = valor.split("|");
	document.formulario.vlistageral[0].disabled = (vr[0] != 'sim');
	document.formulario.vlistageral[1].disabled = (vr[0] != 'sim');
	document.formulario.vloja[0].disabled       = (vr[1] != 'sim');
	document.formulario.vloja[1].disabled       = (vr[1] != 'sim');
}
//###################################################################################
// só n umeros
//###################################################################################
function soNumero(nro)
{
	var valid    = "0123456789";
	var numerook = "";
	var temp;
	for(var i = 0; i < nro.length; i++)
	{
		temp = nro.substr(i, 1);
		if (valid.indexOf(temp) != -1)
			numerook = numerook + temp;
	}
	return(numerook);
}
//###################################################################################
// mascarar valores
//###################################################################################
function mascaraValor(objeto, e, tammax, decimais)
{
	var tecla  = (window.Event) ? e.which : e.keyCode;
	var tamObj = objeto.value.length;

	if ((tecla == 8) && (tamObj == tammax))
		tamObj = tamObj - 1;

	vr = soNumero(objeto.value);
	tam = vr.length;

	if (((tecla == 8) || (tecla >= 48 && tecla <= 57) || (tecla >= 96 && tecla <= 105)) && (parseInt(tamObj) + 1 <= parseInt(tammax)))
	{
		if ((tam < tammax) && (tecla != 8))
			tam = vr.length + 1;
		if ((tecla == 8) && (tam > 1))
			tam = tam - 1;

		if (tam <= decimais)
			objeto.value = ("0," + vr);
		if ((tam == (decimais + 1)) && (tecla == 8))
			objeto.value = vr.substr(0, (tam - decimais)) + "," + vr.substr((tam - decimais), tam);
		if ((tam > (decimais + 1)) && (tam <= (decimais + 3)) && (vr.substr(0,1) == "0"))
			objeto.value = vr.substr(1, (tam - (decimais+1))) + "," + vr.substr(tam - (decimais), tam);
		if ((tam > (decimais + 1)) && (tam <= (decimais + 3)) && (vr.substr(0,1) != "0"))
			objeto.value = vr.substr(0, (tam - decimais)) + "," + vr.substr(tam - decimais, tam);
		if ((tam >= (decimais + 4)) && (tam <= (decimais + 6)))
			objeto.value = vr.substr(0, tam - (decimais + 3)) + "." + vr.substr(tam - (decimais + 3), 3) + "," + vr.substr(tam - decimais, tam);
		if ((tam >= (decimais + 7)) && (tam <= (decimais + 9)))
			objeto.value = vr.substr(0, tam - (decimais + 6)) + "." + vr.substr(tam - (decimais + 6), 3) + "." + vr.substr(tam - (decimais + 3), 3) + "," + vr.substr(tam - decimais, tam);
		if ((tam >= (decimais + 10)) && (tam <= (decimais + 12)))
			objeto.value = vr.substr(0, tam - (decimais + 9)) + "." + vr.substr(tam - (decimais + 9), 3) + "." + vr.substr(tam - (decimais + 6), 3) + "." + vr.substr(tam - (decimais + 3), 3) + "," + vr.substr(tam - decimais, tam);
		if ((tam >= (decimais + 13)) && (tam <= (decimais + 15)))
			objeto.value = vr.substr(0, tam - (decimais + 12)) + "." + vr.substr(tam - (decimais + 12), 3) + "." + vr.substr(tam - (decimais + 9), 3) + "." + vr.substr(tam - (decimais + 6), 3) + "." + vr.substr(tam - (decimais + 3), 3) + "," + vr.substr(tam - decimais, tam);
	}
	else if((tecla != 8) && (tecla != 9) && (tecla != 13) && (tecla != 18) && (tecla != 35) && (tecla != 36) && (tecla != 37) && (tecla != 39))
	{
		return false;
	}
}
//###################################################################################
// mascarar entradas (CEP, data, telefone, cpf, etc
//###################################################################################
function mascaraEntrada(objeto, sMask, evtKeyPress) // onkeypress="javascript:return mascaraEntrada(this,'99999-999',event);"
{
	var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;

	if (document.all)         { nTecla = evtKeyPress.keyCode; }
	else if (document.layers) { nTecla = evtKeyPress.which; }
	else                      { nTecla = evtKeyPress.which; if (nTecla == 8) { return true; } }

	sValue = objeto.value;

	sValue = sValue.toString().replace( "-", "" );
	sValue = sValue.toString().replace( "-", "" );
	sValue = sValue.toString().replace( ".", "" );
	sValue = sValue.toString().replace( ".", "" );
	sValue = sValue.toString().replace( "/", "" );
	sValue = sValue.toString().replace( "/", "" );
	sValue = sValue.toString().replace( ":", "" );
	sValue = sValue.toString().replace( ":", "" );
	sValue = sValue.toString().replace( "(", "" );
	sValue = sValue.toString().replace( "(", "" );
	sValue = sValue.toString().replace( ")", "" );
	sValue = sValue.toString().replace( ")", "" );
	sValue = sValue.toString().replace( " ", "" );
	sValue = sValue.toString().replace( " ", "" );
	fldLen = sValue.length;
	mskLen = sMask.length;

	i = 0;
	nCount = 0;
	sCod = "";
	mskLen = fldLen;

	while (i <= mskLen)
	{
		bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/") || (sMask.charAt(i) == ":"))
		bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))
		if (bolMask)
		{
			sCod += sMask.charAt(i);
			mskLen++;
		}
		else
		{
			sCod += sValue.charAt(nCount);
			nCount++;
		}
		i++;
	}

	objeto.value = sCod;

	if (nTecla != 8)
	{
		if (sMask.charAt(i-1) == "9")
		{
			return ((nTecla > 47) && (nTecla < 58));
		}
		else { return true; }
	}
	else { return true; }
}

//###################################################################################
// verifica se o valor é numérico
//###################################################################################
function isNumber(caracter) // onKeyPress="javascript:return isNumber(event);"
{
	var tecla = (window.Event) ? caracter.which : caracter.keyCode;
	if (tecla > 47 && tecla < 58)
	{
		return true;
	}
	else
	{
		if (tecla != 8 && tecla != 13)
		{
			return false;
		}
		else
		{
			return true;
		}
	}
}

//###################################################################################
// validar configurações do site
//###################################################################################
function validarConfig(f)
{
	if (f.tituloBrowser.value == '')
	{
		window.alert("Por favor, preencha o campo 'Título Browser'.");
		f.tituloBrowser.className = "textreq";
		f.tituloBrowser.focus();
		return false;
	}
	
	if (f.urlSite.value == '')
	{
		window.alert("Por favor, preencha o campo 'URL do Site'.");
		f.urlSite.className = "textreq";
		f.urlSite.focus();
		return false;
	}
	if (f.emailSite.value == '')
	{
		window.alert("Por favor, preencha o campo 'E-mail'.");
		f.emailLoja.className = "textreq";
		f.emailLoja.focus();
		return false;
	}
	if (f.emailSite.value.indexOf('@', 0) == -1 || f.email.value.indexOf('.', 0) == -1) {
        alert("Por favor, preencha corretamente o campo e-mail.");
		f.emailLoja.className = 'textreq';
        f.emailLoja.focus();
        return false;
    }
	
	if (f.keywords.value == '')
	{
		window.alert("Por favor, preencha o campo 'Keywords' com palavras chaves dosite.");
		f.keywords.className = "textreq";
		f.keywords.focus();
		return false;
	}
	if (f.description.value == '')
	{
		window.alert("Por favor, preencha o campo 'Description' com a descrição do site.");
		f.description.className = "textreq";
		f.description.focus();
		return false;
	}
}

//###################################################################################
// ativar troca de senhas
//###################################################################################
function ativa_trocasenha() {

	Form = document.formulario;

    if (Form.ativasenha.checked == true) {
		Form.senha_atual.disabled = false;
        Form.nova_senha.disabled = false;
        Form.confima_nova_senha.disabled = false;
        document.getElementById("linhasenha").disabled = false;
	} else {
        Form.senha_atual.disabled = true;
        Form.nova_senha.disabled = true;
        Form.confima_nova_senha.disabled = true;
        document.getElementById("linhasenha").disabled = true;
    }
}
//###################################################################################
// perfil administradores
//###################################################################################
function perfil_usuarioadm(nome) {
    var fr = document.formulario;
    var ativo = false;
    if (fr.perfil_admin.checked == true) {
        ativo = true;
    }

    for(a=0;a<fr.elements.length;a++){
        if(fr.elements[a].name == nome){
            if(ativo == true){
                fr.elements[a].checked = true;
                fr.elements[a].disabled = true;
            }else{
                fr.elements[a].checked = false;
                fr.elements[a].disabled = false;
            }
        }
    }
}

//###################################################################################
// mostra help
//###################################################################################
function mostrahelp(linha,img) {
var linha = document.getElementById(linha);
  if (linha.style.display=='none') {
   linha.style.display='';
   if(img != null) {
      img.src='imagens/ball_glass_redS.gif';
   }
  } else {
   linha.style.display='none';
   if(img != null) {
      img.src='imagens/duvida.gif';
   }
  }
}
//###################################################################################
// validar incluir membros newsletter
//###################################################################################
function validarCadNewsletter(f)
{
	if (f.nome.value == '')
	{
		window.alert("Por favor, digite o nome do participante.");
		f.nome.className = "textreq";
		f.nome.focus();
		return false;
	}
	if (f.email.value == '')
	{
		window.alert("Por favor, preencha o campo 'E-mail'.");
		f.email.className = "textreq";
		f.email.focus();
		return false;
	}
	if (f.email.value.indexOf('@', 0) == -1 || f.email.value.indexOf('.', 0) == -1) {
        alert("Por favor, preencha corretamente o campo e-mail.");
		f.email.className = 'textreq';
        f.email.focus();
        return false;
    }
	if (f.grupo.value == '')
	{
		window.alert("Por favor, selecione o grupo do participante.");
		f.grupo.className = "textreq";
		f.grupo.focus();
		return false;
}
}
//###################################################################################
// validar alterar membros newsletter
//###################################################################################
function validarAltNewsletter(f)
{
	if (f.nome.value == '')
	{
		window.alert("Por favor, digite o nome do participante.");
		f.nome.className = "textreq";
		f.nome.focus();
		return false;
	}
	if (f.email.value == '')
	{
		window.alert("Por favor, preencha o campo 'E-mail'.");
		f.email.className = "textreq";
		f.email.focus();
		return false;
	}
	if (f.email.value.indexOf('@', 0) == -1 || f.email.value.indexOf('.', 0) == -1) {
        alert("Por favor, preencha corretamente o campo e-mail.");
		f.email.className = 'textreq';
        f.email.focus();
        return false;
    }
	if (f.grupo.value == '')
	{
		window.alert("Por favor, selecione o grupo do participante.");
		f.grupo.className = "textreq";
		f.grupo.focus();
		return false;
}
}
//###################################################################################
// validar cadastrar grupos newsletter
//###################################################################################
function validarCadastrarGrupo(f)
{
	if (f.nome.value == '')
	{
		window.alert("Por favor, digite o nome do grupo.");
		f.nome.className = "textreq";
		f.nome.focus();
		return false;
	}
}
//###################################################################################
// validar alterar grupos newsletter
//###################################################################################
function validarAltGrupo(f)
{
	if (f.nome.value == '')
	{
		window.alert("Por favor, digite o nome do grupo.");
		f.nome.className = "textreq";
		f.nome.focus();
		return false;
	}
}

//###################################################################################
// validar data
//###################################################################################
function validaData(data)
{
	var aData = data.split('/');
	var dia = aData[0];
	var mes = aData[1];
	var ano = aData[2];

	var dataAux = dia + mes + ano
	for (var i = 0; i < dataAux.length; i++)
	{
		caracter = dataAux.substring(i,i+1);
		if ((("0123456789").indexOf(caracter) == -1))
		{
			return false;
		}
	}

	if ((dia > 31) || (dia.length != 2)) { return false; }
	if ((mes > 12) || (mes.length != 2)) { return false; }
	if ((ano < 1900) || (ano > 2100) || (ano.length != 4)) { return false; }
}
//###################################################################################
// validar horas
//###################################################################################
function validaHora(horario)
{
	var aHora = horario.split(':');
	var hora = aHora[0];
	var minuto = aHora[1];

	var horaAux = hora + minuto;
	for (var i = 0; i < horaAux.length; i++)
	{
		caracter = horaAux.substring(i,i+1);
		if ((("0123456789").indexOf(caracter) == -1))
		{
			return false;
		}
	}

	if ((hora > 24) || (hora.length != 2)) { return false; }
	if ((minuto > 59) || (minuto.length != 2)) { return false; }
	if ((hora >= 24) && (minuto >= 01)) { return false; }
}
//###################################################################################
// Dados veículo 1
//###################################################################################
function veiculo1()
 {
  if (document.formulario.refer1.checked)
	{
		document.getElementById("veiculo_1").style.display  = "";
		document.getElementById("veiculo_21").style.display  = "";
		document.formulario.refer2.checked = false;
		document.formulario.refer3.checked = false;
		document.formulario.refer4.checked = false;
		document.formulario.refer2.disabled = false;
		document.formulario.refer3.disabled = true;
		document.formulario.refer4.disabled = true;
	}
	else
	{
		document.getElementById("veiculo_1").style.display = "none";
		document.getElementById("veiculo_2").style.display  = "none";
		document.getElementById("veiculo_3").style.display  = "none";
		document.getElementById("veiculo_4").style.display  = "none";
		document.getElementById("veiculo_21").style.display  = "none";
		document.getElementById("veiculo_31").style.display  = "none";
		document.getElementById("veiculo_41").style.display  = "none";
		document.formulario.refer2.disabled = true;
		document.formulario.refer3.disabled = true;
		document.formulario.refer4.disabled = true;
		
	}
 }
//###################################################################################
// Dados veículo 2
//###################################################################################
function veiculo2()
 {
  if (document.formulario.refer2.checked)
	{
		document.getElementById("veiculo_2").style.display  = "";
		document.getElementById("veiculo_31").style.display  = "";
		document.getElementById("veiculo_3").style.display  = "none";
		document.formulario.refer3.checked = false;
		document.formulario.refer4.checked = false;
		document.formulario.refer3.disabled = false;
		document.formulario.refer4.disabled = true;
	}
	else
	{
		document.getElementById("veiculo_2").style.display = "none";
		document.getElementById("veiculo_3").style.display  = "none";
		document.getElementById("veiculo_31").style.display  = "none";
		document.getElementById("veiculo_4").style.display  = "none";
		document.getElementById("veiculo_41").style.display  = "none";
		document.formulario.refer3.disabled = true;
		document.formulario.refer4.disabled = true;
		
	}
 }
//###################################################################################
// Dados veículo 3
//###################################################################################
function veiculo3()
 {
  if (document.formulario.refer3.checked)
	{
		document.getElementById("veiculo_3").style.display  = "";
		document.getElementById("veiculo_41").style.display  = "";
		document.getElementById("veiculo_4").style.display  = "none";
		document.formulario.refer4.checked = false;
		document.formulario.refer4.disabled = false;
		
	}
	else
	{
		document.getElementById("veiculo_3").style.display = "none";
		document.getElementById("veiculo_41").style.display  = "none";
		document.getElementById("veiculo_4").style.display  = "none";
		document.formulario.refer4.checked = false;
		document.formulario.refer4.disabled = true;
		
	}
 }
//###################################################################################
// Dados veículo 3
//###################################################################################
function veiculo4()
 {
  if (document.formulario.refer4.checked)
	{
		document.getElementById("veiculo_4").style.display  = "";
	}
	else
	{
		document.getElementById("veiculo_4").style.display = "none";
	}
 }
