/*
#############################################
## 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 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 tecla = e.keyCode ? e.keyCode : e.which;
    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 tecla = e.keyCode ? e.keyCode : e.which;
    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");
}

function getObjetoAjax() {
    var xmlhttp;
    try {
        xmlhttp = new XMLHttpRequest();
    } catch(e) {
        try {
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch(ee){
            try {
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            } catch(eee)
{
                xmlhttp = false;
            }
        }
    }
    return xmlhttp;
}

function CheckAll(Grupo,vai)
{
    if(vai == true)
    {
        for (i=0;i<document.form1.elements.length;i++)
        {
            if(document.form1.elements[i].id == Grupo)
            {
                document.form1.elements[i].checked=1
            }
        }
    }
    else
    {
        for (i=0;i<document.form1.elements.length;i++)
        {
            if(document.form1.elements[i].id == Grupo)
            {
                document.form1.elements[i].checked=0
            }
        }
    }
}

function show_pf() {
    document.getElementById('pf').style.display='block';
    document.getElementById('pj').style.display='none';
}

function show_pj() {
    document.getElementById('pj').style.display='block';
    document.getElementById('pf').style.display='none';
}

function show_form_bonus() {
    var ck = document.getElementById('show_login_bonus').style.display;

    if(ck == 'none') {
        document.getElementById('show_login_bonus').style.display = 'block';
        document.getElementById('usarbonus').value = 'sim';
    } else {
        document.getElementById('show_login_bonus').style.display = 'none';
        document.getElementById('usarbonus').value = 'nao';
    }

}

