function openRegistro(){ 
  var Settings
  var winX = (screen.availWidth - 800) / 2;
  var winY = (screen.availHeight - 500) / 2;
  Settings='left='+winX+',top='+winY+',width=800,height=500,scrollbars=yes,menubar=no,toolbar=no,location=no,directories=no,status=yes,resizable=no';
  var w = window.open('Registro.aspx', 'wRegistro', Settings);
  w.focus();
}

function FormataAmbos(campo, teclapres){
  var Campo = document.getElementById(campo); 
  var vr = new String(Campo.value);
  vr = vr.replace(".", "");
  vr = vr.replace(".", "");
  vr = vr.replace("/", "");
  vr = vr.replace("-", "");
  tam = vr.length + 1 ;
  if(tam<=11)
     FormataCPF(campo, teclapres);
  else
     FormataCNPJ(campo, teclapres);    
}

function FormataCNPJ(campo, teclapres){
   var Campo = document.getElementById(campo); 
   var tecla = teclapres.keyCode;
   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);
   }
}
function FormataCPF(campo, teclapres){
   var Campo = document.getElementById(campo); 
   var tecla = teclapres.keyCode;
   var vr = new String(Campo.value);
   vr = vr.replace("-", "");
   vr = vr.replace(".", "");
   vr = vr.replace(".", "");
   vr = vr.replace("/", "");
   
   tam = vr.length + 1 ;

   if (tam < 11 && tecla != 8) { 
       tam = vr.length + 1; 
   }
   
   if (tecla == 8 ) { 
       tam = tam - 1 ; 
   }
   
   if ( tecla == 8 || tecla == 88 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
       if ( tam <= 2 ){
          Campo.value = vr;
       }
       if (tam > 2 && tam <= 11) {
          vr = vr.substr(0, tam - 2) + '-' + vr.substr(tam - 2, tam);
       }
       if (tam == 11){
          vr = vr.substr(0, tam - 8) + '.' + vr.substr(tam - 8, 3) + '.' + vr.substr(tam - 5, tam);
       }
       Campo.value = vr;
   }
}


