function isInteger(numero){
  var i;
  for (i=0;i<numero.length;i++)
    if (!((numero.charAt(i)>="0")&&(numero.charAt(i)<="9")))
      return false;
  return true;
}

function isValidDate(fr, foque, a, msg, ob ){

  if ((ob=='')&&(a.length==0)) return;

  var err=0;

  if ((a.length != 10)&&(ob=='')) err=1;

  d = a.substring(0, 2);// XX/xx/xxxx
  c = a.substring(2, 3);// '/'
  b = a.substring(3, 5);// xx/XX/xxxx
  e = a.substring(5, 6);// '/'
  f = a.substring(6, 10);// xx/xx/XXXX

  if (!isInteger(d)||!isInteger(b)||!isInteger(f)) err=1;

  if (d<1 || d>31)   err = 1;
  if (e != '/')      err = 1;
  if (b<1 || b>12)   err = 1;
  if (c != '/')      err = 1;
  if (f<0 || f>9999) err = 1;
  if (b==4 || b==6 || b==9 || b==11){
    if (d==31)       err = 1;
  }                                                      
  if (b==2){                                           
    var g=parseInt(f/4);
    if (isNaN(g)) err=1;
    if (d>29)     err=1;
    if (d==29 && ((f/4)!=parseInt(f/4))) err=1;
  }

  if (err==1){
    alert('Campo Data --> ' + msg + '  Inválido, redigite!');
    eval("document."+fr+"." + foque+ ".focus();");
  }
}

function inBarra(fr,foque){

  if (eval("document."+fr+"." + foque+ ".value.length==2")||
      eval("document."+fr+"." + foque+ ".value.length==5"))      
  if (navigator.appName=="Microsoft Internet Explorer")
     // no Navigator esse comando faz o cursor voltar p/ o início do campo texto
     // impedindo o usuário de digitar os próximos números
    eval("document."+fr+"." + foque+ ".value += '/';"); 
    
}

function inBarraf(fr,foque){

  if (eval("document."+fr+"." + foque+ ".value.length==2")||
      eval("document."+fr+"." + foque+ ".value.length==5"))
  if (navigator.appName=="Microsoft Internet Explorer")
     // no Navigator esse comando faz o cursor voltar p/ o início do campo texto
     // impedindo o usuário de digitar os próximos números
    eval("document."+fr+"." + foque+ ".value += '/';");

  if (eval("document."+fr+"." + foque+ ".value.length==10"))
    eval("document."+fr+"." + nextfield + ".focus()");
}

function So_Num()
{  if (event.keyCode < 48 || event.keyCode > 57) 
       event.keyCode=0; 
}

function entra_foco(p){
	p.style.background='#eaeaea' ;
	return true ;
}

function sai_foco(p) {
	p.style.background='white' ;
	return true ;
}


