//FUNÇÃO MOSTRAR/OCULTAR DIV
function showHide(PegaID){
		var numericID = document.getElementById(PegaID).id.replace(/[^\d]/g,'');
		var obj = document.getElementById('a' + numericID);
		if(obj.style.display=='block'){
			obj.style.display='none';
		}else{
			obj.style.display='block';
		}		
}

//FUNÇÃO PARA ATIVAR AJAX E VERIFICAR SE O USUÁRIO JÁ EXISTE NO BANCO DE DADOS
 function envia(url, metodo, modo, tipo)
{
    var login = document.getElementById('cadastro').login.value;
    remoto  = new ajax();
    xmlhttp = remoto.enviar(url + "?login=" + login, metodo, modo );
    if(xmlhttp=='1') {
       document.getElementById('alerta').className = 'user_existe';
       document.getElementById("alerta").innerHTML = '<img src="./images/img_msg_erro.png" /> Este usuário já está sendo usado. Escolha outro.';
    } else {
       document.getElementById('alerta').className = 'user_nao_existe';
       document.getElementById("alerta").innerHTML = '<img src="./images/img_msg_ok.png" /> Usuário liberado para uso.';
    }    
}

// VALIDAR FORM DE CADASTRO
function ValidaCadastro(theForm){
	if (theForm.nome.value == ""){
	    alert("Por favor informe seu nome.");
    	theForm.nome.focus();
    	return (false);
  	}
	if (theForm.email.value == ""){
	    alert("Por favor informe seu e-mail.");
    	theForm.email.focus();
    	return (false);
  	}
	if (theForm.senha.value == ""){
	    alert("Por favor informe sua senha.");
    	theForm.senha.focus();
    	return (false);
  	}
	
}

//MÁSCARA DE VALORES

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;
    }
  }
  
 // FUNÇÃO PARA MARCAR/DESMARCAR CHECKBOX
function selectall(obj) {
var checkBoxes = document.getElementsByTagName('input');
for (i = 0; i < checkBoxes.length; i++) {
if (obj.checked == true) {
checkBoxes[i].checked = true; // this checks all the boxes
} else {
checkBoxes[i].checked = false; // this unchecks all the boxes
}
}
}

