/*
#############################################
## Desenvolvimento do Script: IlhaWeb Host ##
## http://www.ilhawebhost.com.br           ##
## MSN: atendimento@ilhawebhost.com.br     ##
## Skype: atendimento.ilhaweb              ##  
#############################################
 */

/* FUNÇÕES PARA EXIBIÇÕES DO MENU */
function setDisplayMenu(idName)
{
    if ( idName !=null && idName != '' ) {
        closeMenuDiv();
        openMenuDiv(idName);
    } else {
        closeMenuDiv();
    }
}

function clickOpenMenu(idName)
{
    closeMenuDiv();
    openMenuDiv(idName);
}

function closeMenuDiv()
{
    var aObjDiv = document.getElementsByTagName("div");
    var numDiv = aObjDiv.length;

    for(i=0; i < numDiv; i++)
    {
        var idName = aObjDiv[i].getAttribute("id");
		
        if(idName)
        {
            var isMenu = idName.match(/SubCat/i);
					
            if(isMenu !=null)
            {
                document.getElementById(idName).style.visibility = "hidden";
                document.getElementById(idName).style.position = "absolute";
            }
        }
    }

}

function openMenuDiv(idName)
{
    document.getElementById('SubCat_'+idName).style.visibility = "visible";
    document.getElementById('SubCat_'+idName).style.position = "static";
}

function clickOpenPage(URL,target)
{
    window.open(URL, target);
}

/* FUNÇÕES PARA FORMATAÇÃO DE CAMPOS */

function txtBoxFormat(objeto, sMask, evtKeyPress) {
    var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;


    if(document.all) { // Internet Explorer
        nTecla = evtKeyPress.keyCode;
    } else if(document.layers) { // Nestcape
        nTecla = evtKeyPress.which;
    } else {
        nTecla = evtKeyPress.which;
        if (nTecla == 8) {
            return true;
        }
    }

    sValue = objeto.value;

    // Limpa todos os caracteres de formatação que
    // já estiverem no campo.
    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) { // backspace
        if (sMask.charAt(i-1) == "9") { // apenas números...
            return ((nTecla > 47) && (nTecla < 58));
        }
        else { // qualquer caracter...
            return true;
        }
    }
    else {
        return true;
    }
}
  
/* VALIDAÇÃO DO FORMULÁRIO DE CADASTRO */ 

function validar() {
  
    /* VALIDANDO O CAMPO PRIMEIRO NOME */
    if (document.cad.nome.value == "" || document.cad.nome.value == null) {
        window.alert("Por favor, preencha o campo \"Nome Completo\" \n\nObrigado!");
        document.cad.nome.focus();
        return false;
    }

    /* VALIDANDO O CAMPO CPF */
    if (document.cad.cpf.value == "" || document.cad.cpf.value == null) {
        window.alert("Por favor, preencha o campo \"CPF\"\n\nObrigado!");
        document.cad.cpf.focus();
        return false;
    }

    /* VALIDANDO O CAMPO RG */
    if (document.cad.rg.value == "" || document.cad.rg.value == null) {
        window.alert("Por favor, preencha o campo \"RG\"\n\nObrigado!");
        document.cad.rg.focus();
        return false;
    }
 
    /* VALIDANDO O CAMPO DATA DE NASCIMENTO*/
    if (document.cad.datanasc.value == "" || document.cad.datanasc.value == null) {
        window.alert("Por favor, preencha o campo \"Data de Nasc.\"\n\nObrigado!");
        document.cad.datanasc.focus();
        return false;
    }

    /* VALIDANDO O CAMPO ENDEREÇO*/
    if (document.cad.endereco.value == "" || document.cad.endereco.value == null) {
        window.alert("Por favor, preencha o campo \"Endereço\"\n\nObrigado!");
        document.cad.endereco.focus();
        return false;
    }

    /* VALIDANDO O CAMPO NÚMERO*/
    if (document.cad.numero.value == "" || document.cad.numero.value == null) {
        window.alert("Por favor, preencha o campo \"Número\"\n\nObrigado!");
        document.cad.numero.focus();
        return false;
    }
 
    /* VALIDANDO O CAMPO BAIRRO */
    if (document.cad.bairro.value == "" || document.cad.bairro.value == null) {
        window.alert("Por favor, preencha o campo \"Bairro\"\n\nObrigado!");
        document.cad.bairro.focus();
        return false;
    }
 
    /* VALIDANDO O CAMPO CIDADE */
    if (document.cad.cidade.value == "" || document.cad.cidade.value == null) {
        window.alert("Por favor, preencha o campo \"Cidade\"\n\nObrigado!");
        document.cad.cidade.focus();
        return false;
    }
 
    /* VALIDANDO O CAMPO ESTADO */
    if (document.cad.estado.value == "--") {
        window.alert("Você precisa Selecionar um Estado! \n\n Obrigado!");
        document.cad.estado.focus();
        return false;
    }

    /* VALIDANDO O CAMPO CEP */
    if (document.cad.cep.value == "" || document.cad.cep.value == null) {
        window.alert("Por favor, preencha o campo \"CEP\"\n\nObrigado!");
        document.cad.cep.focus();
        return false;
    }
 
    /* VALIDANDO O CAMPO EMAIL */
    if (document.cad.email.value == "" || document.cad.email.value == null) {
        window.alert("Por favor, preencha o campo \"E-Mail\"\n\nObrigado!");
        document.cad.email.focus();
        return false;
    }
	
    /* VERIFICANDO SE O EMAIL É VÁLIDO */
    if (document.cad.email.value.indexOf('@', 0) == -1){
        alert("Por favor digite um email válido!\n\n Obrigado!");
        document.cad.email.focus();
        return (false);
    }

    /* VENDO SE FORAM DIGITADOS DOIS EMAILS IGUAIS */
    if (document.cad.email.value == document.cad.email2.value ) {
        window.alert("O E-Mail e o E-Mail alternativo precisam ser diferentes!");
        document.cad.email2.focus();
        return false;
    }

    /* VALIDANDO O CAMPO TELEFONE */
    if (document.cad.tel.value == "" || document.cad.tel.value == null) {
        window.alert("Por favor, preencha o campo \"Telefone\"\n\nObrigado!");
        document.cad.tel.focus();
        return false;
    }

    /* VALIDANDO O CAMPO NOME DE USUÁRIO */
    if (document.cad.usuario.value == "" || document.cad.usuario.value == null) {
        window.alert("Por favor, preencha o campo \"Crie Seu Login\"\n\nObrigado!");
        document.cad.usuario.focus();
        return false;
    }
    /* IMPEDINDO QUE O NOME DE USUÁRIO TENHO CARACTERES ESPECIAIS E ACENTUAÇÃO */
    campo = document.cad.usuario.value
    var vartest = /(á|é|í|ó|ú|â|ê|î|ô|û|ã|õ|à|è|ì|ò|ù|ä|ë|ï|ö|ü|ç|[^\w@\.\-\_])/;
    var ok = true;
    tam_campo = campo.length;
					
    for(i=0;i<tam_campo;i++){
				  
        if(eval(vartest).test(campo.substr(i,1))){
					  
            i = tam_campo;
            alert(" No campo \"Crie Seu Login\" NÃO USE: \n\n - Acentuação \n - Caracteres especiais \n - Espaço(s) em branco!\n\n Obrigado!")
            retorno = 0;
            return (false);
            document.cad.usuario.focus();

        }
						
    }

    /* VALIDANDO O CAMPO SENHA */
    if (document.cad.senha1.value == "" || document.cad.senha1.value == null) {
        window.alert("Por favor, preencha o campo \"Senha\"\n\nObrigado!");
        document.cad.senha1.focus();
        return false;
    }

    /* VALIDANDO O CAMPO CONFIRME A SENHA */
    if (document.cad.senha2.value == "" || document.cad.senha2.value == null) {
        window.alert("Por favor, preencha o campo \"Redigite a Senha\"\n\nObrigado!");
        document.cad.senha2.focus();
        return false;
    }
 
    /* VENDO SE AS DUAS SENHAS DIGITADAS SÃO IGUAIS */
    if (document.cad.senha1.value != document.cad.senha2.value ) {
        window.alert("A Senha e a Confirmação de Senha não conferem!");
        document.cad.senha2.focus();
        return false;
    }



    if (document.cad.termos.checked == "") {
        window.alert("Para se cadastrar, você precisa ler e aceitar os Termos constantes no Contrato de Adesão!");
        return false;
    }
    return true;
}

/* VALIDAÇÃO DO FORMULÁRIO DE CONTATO */

function validation() {
    if (document.formcontato.nome.value.length < 2) {
        window.alert("Por favor, digite seu nome!");
        document.formcontato.nome.focus();
        return false;
    }
    if (document.formcontato.email.value.length < 5) {
        window.alert("Por favor, digite seu e-mail!");
        document.formcontato.email.focus();
        return false;
    }
    if (document.formcontato.email.value.indexOf('@', 0) == -1){
        alert("O e-mail digitado é invalido!");
        document.formcontato.email.focus();
        return (false);
    }
    if (document.formcontato.assunto.value.length < 2) {
        window.alert("Por favor, digite um assunto!");
        document.formcontato.assunto.focus();
        return false;
    }
    if (document.formcontato.mensagem.value.length < 2) {
        window.alert("Por favor, digite uma mensagem!");
        document.formcontato.mensagem.focus();
        return false;
    }
    return true;
}

/* SOLICITANDO A CONFIRMAÇÃO DE DADOS */

function confirmacao() {
    if ( confirm("Os Dados Digitados Estão Corretos?") )
    {
        return true;
    } else   {
        return false
    }
}

function confirmacao2() {
    if ( confirm("Tem certeza que deseja realizar esta operação?") )
    {
        return true;
    } else   {
        return false
    }
}


/* SOMENTE NÚMEROS  */
function makenum(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);
}
	
/* SOMENTE NÚMEROS E O SINAL DE MENOS */
function makenum2(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);
}
	
/* FORMATANDO O CAMPO VALOR PARA INSERIR NA BASE DE DADOS */
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 = makenum(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 = vr.substr(0, (tam - decimais)) + "." + 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;
    }
}

/* FORMATANDO O CAMPO VALOR PARA INSERIR NA BASE DE DADOS INCLUINDO O SINAL DE MENOS */
function mascaraValor2(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 = makenum2(objeto.value);
    tam = vr.length;
	
    if (((tecla == 8) || (tecla >= 48 && tecla <= 57) || (tecla == 109) || (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 = vr.substr(0, (tam - decimais)) + "." + 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;
    }
}

// Novo método para o objeto 'String'
String.prototype.reverse = function(){
    return this.split('').reverse().join('');
};

	
function openPopup(largura, altura, pagina) {
    window.open(pagina,'popup','width='+largura+',height='+altura,"scrolling=auto,resizable=no,status=no");
}
