

function txtBoxFormat(strField, sMask, evtKeyPress) {
     var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;

     if(window.event) { // Internet Explorer
       nTecla = evtKeyPress.keyCode; }
     else if(evtKeyPress.which) { // Nestcape / firefox
       nTecla = evtKeyPress.which;
     }
    //se for backspace não faz nada
	
    if (nTecla != 8){
     sValue = document.getElementById(strField).value;
    // alert(sValue);

     // 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( " ", "" );
     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) == "/"))
       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++;
     }

     document.getElementById(strField).value = sCod;

     if (nTecla != 8) { // backspace
       if (sMask.charAt(i-1) == "9") { // apenas números...
         return ((nTecla > 47) && (nTecla < 58)); 
	   } // números de 0 a 9
       else { // qualquer caracter...
         return true;
       }
	 }
     else {
       return true;
     }
    }//fim do if que verifica se é backspace
}
//Fim da Função Máscaras Gerais
/***
* Observação: As máscaras podem ser representadas como os exemplos abaixo:
* CEP -> 99.999-999
* CPF -> 999.999.999-99
* CNPJ -> 99.999.999/9999-99
* Data -> 99/99/9999
* Tel Resid -> (99) 999-9999
* Tel Cel -> (99) 9999-9999
* Processo -> 99.999999999/999-99
* C/C -> 999999-!
* E por aí vai...
***/
//USO:  onkeypress="return txtBoxFormat('id_do_campo', '99999999', event);"


function verificaEquivalencias(strField,strField2){
	if (document.getElementById(strField).value != getElementById(strField2).value)  // Aqui faz a comparação se a senha 1 confere com a senha2 
	{ 
		alert ("As senhas não Conferem"); //Dispara o alerta caso a condição não seja favorável 
		document.getElementById(strField).focus(); // Aqui manda o foco voltar para a senha1
		return false; 
	} 
return true; 
}//Fim da Verifica Equivalencias //USO: verificaEquivalencias(id1,id2)



function MascaraMoeda(objTextBox, SeparadorMilesimo, SeparadorDecimal, e){
	
    var sep = 0;
    var key = '';
    var i = j = 0;
    var len = len2 = 0;
    var strCheck = '0123456789';
    var aux = aux2 = '';
    var whichCode = null;
	
	
	if(window.event) { // Internet Explorer
       whichCode = e.keyCode; }
     else if(e.which) { // Nestcape / firefox
       whichCode = e.which;
     }
	
	
    if ((whichCode == 0) || (whichCode == 8)) return true;
	key = String.fromCharCode(whichCode); // Valor para o código da Chave
	
    if (strCheck.indexOf(key) == -1) return false; // Chave inválida
	
    len = objTextBox.value.length;
    for(i = 0; i < len; i++)
        if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != SeparadorDecimal)) break;
    aux = '';
    for(; i < len; i++)
        if (strCheck.indexOf(objTextBox.value.charAt(i))!=-1) aux += objTextBox.value.charAt(i);
    aux += key;
    len = aux.length;
    if (len == 0) objTextBox.value = '';
    if (len == 1) objTextBox.value = '0'+ SeparadorDecimal + '0' + aux;
    if (len == 2) objTextBox.value = '0'+ SeparadorDecimal + aux;
    if (len > 2) {
        aux2 = '';
        for (j = 0, i = len - 3; i >= 0; i--) {
            if (j == 3) {
                aux2 += SeparadorMilesimo;
                j = 0;
            }
            aux2 += aux.charAt(i);
            j++;
        }
        objTextBox.value = '';
        len2 = aux2.length;
        for (i = len2 - 1; i >= 0; i--)
        objTextBox.value += aux2.charAt(i);
        objTextBox.value += SeparadorDecimal + aux.substr(len - 2, len);
    }
    return false;
}
/*
<form>
Valor R$: <input type="text" name="valor"  onKeyPress="return(MascaraMoeda(this,'.',',',event))">
</form>
*/




cont = 0;
function selecionaTudo(){
if (cont == 0){   
//	var elem = document.getElementById("checar");
//	elem.innerHTML = "Desmarcar todos";
	if (document.formulario.excluir.length > 1){
		for (var i=0;i<document.formulario.excluir.length;i++) {
			document.formulario.excluir[i].checked="checked";
		}
	}else{
		document.formulario.excluir.checked="checked";
	}
cont = 1;
} else {
//	var elem = document.getElementById("checar");
//	elem.innerHTML = "Marcar todos";
	if (document.formulario.excluir.length > 1){
		for (var i=0;i<document.formulario.excluir.length;i++) {
			document.formulario.excluir[i].checked="";
		}	
	}else{
		document.formulario.excluir.checked="";
	}
	cont = 0;
}
}

function CofirmarExcluir(url){
	var infor;
	infor = window.confirm("Tem certeza que deseja excluir este registro?");
	if (infor){
		document.location = url;
	}
}



function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.title; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' precisa conter um endereço.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' precisa conter um numero.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' precisa conter um numero entre '+min+' e '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' nao pode estar vazio.\n'; }
    } if (errors) alert('Os seguintes erro(s) ocorreram:\n'+errors);
    document.MM_returnValue = (errors == '');
} }



function verificaEquivalencias(strField,strField2){
	if (document.getElementById(strField).value != getElementById(strField2).value)  // Aqui faz a comparação se a senha 1 confere com a senha2 
	{ 
		alert ("As senhas não Conferem"); //Dispara o alerta caso a condição não seja favorável 
		document.getElementById(strField).focus(); // Aqui manda o foco voltar para a senha1
		return false; 
	} 
return true; 
}//Fim da Verifica Equivalencias //USO: verificaEquivalencias(id1,id2)


var ativado
function abreDIV(param) {
    if (ativado != null){
   			ativado.style.visibility = "hidden";
			ativado.style.position = "absolute";
	}
  		 document.getElementById(param).style.visibility = "visible"; 
			document.getElementById(param).style.position = "relative";
  			 ativado = document.getElementById(param);  
}
function fechaDIV(param) {
   document.getElementById(param).style.visibility = "hidden"; 
			document.getElementById(param).style.position = "absolute";
   ativado = null;
}
function abre_fechaDIV(param){

   if (ativado != null){
   			ativado.style.visibility = "hidden";
			ativado.style.position = "absolute"
	   if (ativado == document.getElementById(param)){
			ativado = null ;
	   }else{
	   		document.getElementById(param).style.visibility = "visible"; 
			document.getElementById(param).style.position = "relative";
	   		ativado = document.getElementById(param);  
	   }
   }else{
   		document.getElementById(param).style.visibility = "visible"; 
		document.getElementById(param).style.position = "relative";
		ativado = document.getElementById(param);  
   }
}
