//Funções para o FaceBox
function abrir(strMensagem)
{
    $(document).ready(function(){
         jQuery.facebox(strMensagem);
    })
}

//FUN��O PARA NUMEROS NO CAMPO, COM ELA SOMENTE NUMEROS PODER�O SER DIGITADOS onKeyPress="return SoNumero(event)"
function SoNumero(evtKeyPress) {
	var nTecla;
	nTecla = (evtKeyPress.which) ? evtKeyPress.which : evtKeyPress.keyCode;
	if(nTecla > 47 && nTecla < 58){
		return true;
	} else {
		if (nTecla != 8){ // backspace
		//return false;
		}else{
			return true;
		}
	}
	return false;
}

//MASCARAS
function Mascara (formato, keypress, objeto){
campo = eval (objeto);

// cep onkeypress="Mascara('cep', event.keyCode, 'document.cadastro.cep');" 
if (formato=='cep'){
separador = '-';
conjunto1 = 5;
if (campo.value.length == conjunto1){
campo.value = campo.value + separador;}
}

// cpf onkeypress="Mascara('cpf', event.keyCode, 'document.cadastro.cpf');" 
if (formato=='cpf'){
separador1 = '.';
separador2 = '-';
conjunto1 = 3;
conjunto2 = 7;
conjunto3 = 11;
if (campo.value.length == conjunto1)
  {
  campo.value = campo.value + separador1;
  }
if (campo.value.length == conjunto2)
  {
  campo.value = campo.value + separador1;
  }
if (campo.value.length == conjunto3)
  {
  campo.value = campo.value + separador2;
  }
}

// nascimento onkeypress="Mascara('nascimento', event.keyCode, 'document.cadastro.nascimento');" 
if (formato=='nascimento'){
separador = '/';
conjunto1 = 2;
conjunto2 = 5;
if (campo.value.length == conjunto1)
  {
  campo.value = campo.value + separador;
  }
if (campo.value.length == conjunto2)
  {
  campo.value = campo.value + separador;
  }
}

// telefone onkeypress="Mascara('telefone', event.keyCode, 'document.cadastro.telefone');"
if (formato=='telefone'){
separador1 = '(';
separador2 = ')';
separador3 = '-';
conjunto1 = 0;
conjunto2 = 3;
conjunto3 = 8;
if (campo.value.length == conjunto1){
campo.value = campo.value + separador1;
}
if (campo.value.length == conjunto2){
campo.value = campo.value + separador2;
}
if (campo.value.length == conjunto3){
campo.value = campo.value + separador3;
}
}

}

//MÁSCARA CNPJ CHAMADA LOGO ABAIXO..
//onKeyPress="FormataCNPJ(this, event);

function FormataCNPJ(Campo, teclapres){

   if(window.event){
    var tecla = teclapres.keyCode;
   }else  tecla = teclapres.which;

   var vr = new String(Campo.value);
   vr = vr.replace(".", "");
   vr = vr.replace(".", "");
   vr = vr.replace("/", "");
   vr = vr.replace("-", "");

   tam = vr.length + 1;

  
   if (tecla != 9 && tecla != 8){
      if (tam > 2 && tam < 6)
         Campo.value = vr.substr(0, 2) + '.' + vr.substr(2, tam);
      if (tam >= 6 && tam < 9)
         Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,tam-5);
      if (tam >= 9 && tam < 13)
         Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,tam-8);
      if (tam >= 13 && tam < 15)
         Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,4)+ '-' + vr.substr(12,tam-12);
      }
}