function alertmio(leyen) {
alert(leyen);
document.form1.valido.value = '1';
return;
}
function esfecha (campo,requerido) {
   var sFecha = campo;
 if (sFecha.length == 0 && requerido != 'R') {
     return sFecha;
	 }
	  else
           { if (sFecha.length == 0 && requerido == 'R') {
		         alertmio('Error Fecha Obligatoria');
                  return sFecha; }
		    }		  
    var vFecha = sFecha.split('/');
   
   if (vFecha.length == 1) {
          vFecha = sFecha.split('-');
      }
   if (vFecha.length == 3 )
      { var iDia = vFecha [0];
        var iMes = vFecha [1];
		var iYear = vFecha [2];}
      else {
           if (vFecha.length == 1  && (sFecha.length == 6 || sFecha.length == 8) )             {
                var iDia = sFecha.substr(0,2);
                var iMes = sFecha.substr(2,2);
                var iYear = sFecha.substr(4);
              }
              else
                   { alertmio('Error en Fecha');
                     return sFecha; }
            }

if (iYear.length == 2 && iYear < 50)
   { iYear = '20' + iYear;}
   else {
         if (iYear.length == 2 && iYear >= 50)
            { iYear = '19' + iYear;}
        }
if (iYear.length != 4 )
   { alertmio('Error en Año');
     return sFecha;
   }
if (isNaN (iDia) | isNaN (iMes) | isNaN (iYear)) {
	alertmio('Error en Fecha');
    return sFecha;
    }
 switch (iMes) {
               case '01':
               case '03':
               case '05':
               case '07':
               case '08':
               case '10':
               case '12': {
                  if  ((iDia > 31) || (iDia <= 0))
				      {
                        alertmio('Error en Día');
                        return sFecha;
			    	  }
				   break;
               }
               case '04':
               case '06':
               case '09':
               case '11': {
                     if  ((iDia > 30) || (iDia <= 0))
				      {
                        alertmio('Error en Día');
                        return sFecha;
			    	  }
                     break;
                    }
               case '02': {
                  if ((iDia <= 28) || ((iDia == 29) && (((iYear % 400) == 0) || ((iYear % 4) ==0) && ((iYear % 100) != 0)))){
                      break;
                     }
                      else
                         { alertmio ('Error en Dia');
                           return sFecha;
                          }
                        }
               default: alertmio ('Error en Mes' );
                        return sFecha;

            }
 var resul = iDia + '/' + iMes + '/' + iYear;
 
 return resul;
}
function fecha_base(fechi) {
   if (fechi.length == 0 )
       {
	    return fechi;
		}
  var vFecha = fechi.split ('/');

   
   if (vFecha.length == 3 )
      { var iDia = vFecha [0];
        var iMes = vFecha [1];
		var iYear = vFecha [2];}
    var rfecha = iYear + '/' + iMes + '/' + iDia;
    return rfecha;
}
function cargo(varia, lon)
{
  if (varia.length < lon)
     {
      alertmio('Error: No ingresó la totalidad del campo - min '+lon+' caracteres' );
    }
  return ;
}  
function seleccion(varia)
{
  if (varia.length < 1)
     {
      alertmio('Error: No Seleccionó el Campo ' );
    }
  return ;
}  
function esnumero(valor, longi, minlon)
{
  var lon = longi;
  var mini = minlon;
  var  nume = valor;
 
  if (isNaN (nume))
    { alert('Error: el campo debe ser numerico');
      return nume; }
    else {
  if (nume.length > lon)
     {
      alert('Error: longitud max. ' + lon );
      return nume;
    }
     else { if (nume < mini)
                {
                  alert('Error valor minimo ' + mini)
                  return nume;
                }
          }
return nume;
         }
}
function eschar(valor, longi, minlon)
{
  var lon = longi;
  var mini = minlon;
  var  nume = valor;


  if (nume.length > lon)
     {
      alert('Error: longitud max. ' + lon );
      return nume;
    }
     else { if (nume.length < mini)
                {
                  alert('Error longitud min. ' + mini)
                  return nume;
                }
          }
         return nume;
}


function esHora (campo, requerido) {
   var sFecha = campo;
   if (sFecha.length == 0 && requerido != 'R') {
     return sFecha;
	 }
	  else
           { if (sFecha.length == 0 && requerido == 'R') {
		         alertmio('Error Hora Obligatoria');
                  return sFecha; }
		    }
  
   var vFecha = sFecha.split (':');
 
   if (vFecha.length == 1) {
          vFecha = sFecha.split (' ');
      }
   if (vFecha.length == 2 )
      { var iHora = vFecha [0];
        var iMin = vFecha [1];
	  }	
      else {
           if (vFecha.length == 1  && sFecha.length == 4 )             {
                var iHora = sFecha.substr(0,2);
                var iMin = sFecha.substr(2,2);
              }
              else
                   { alertmio('Error en el Horario');
                     return sFecha; }
            }


if (iHora.length != 2 )
   { alertmio('Error en Hora');
     return sFecha;
   }
if (isNaN (iHora) | isNaN (iMin) ) {
	alertmio('Error en Horario');
    return sFecha;
    }
   if  ((iHora > 24) || (iHora <= 0))
	     {
           alertmio('Error en Hora');
            return sFecha;
	   	  }
     if  ((iMin > 60) || (iMin < 0))
	     {
           alertmio('Error en Minutos');
            return sFecha;
	   	  }		 	   
   var resul = iHora + ':' + iMin ;
 
 return resul;
}
function pregunta(campo,leyen,tabla) {
    if (confirm('¿Confirma BORRAR esta Información ? '+leyen)){ 
  
	   var donde='borra_contable.php?cual='+tabla+'&cod='+campo;
	   window.location.href=donde;
    } 
} 
function voy(donde) {
    	   window.location.href=donde;
    } 

function verifecha(valor)
{
if (valor == 'E')
   {
    ver('fechas');
	}
	else
	   {
	    nover('fechas');
		}
return;
}		
function vertab(cual){

este = document.getElementById(cual);
este.style.display = "block";
estetab = document.getElementById('tab'+cual);
estetab.className = "activo";
return;
}
function novertab(cual){
este = document.getElementById(cual);
este.style.display = "none";
estetab = document.getElementById('tab'+cual);
estetab.className = "inactivo";
return;

}
function ver(cual){
este = document.getElementById(cual);
este.style.display = "block";
return;

}
function nover(cual){
este = document.getElementById(cual);
este.style.display = "none";
return;
}

function verico(cual){
P='P'+cual
este = document.getElementById(P);
este.style.display = "block";
V='V'+cual;
N='N'+cual;
nover(V);
ver(N);
return;

}
function noverico(cual){
P='P'+cual
este = document.getElementById(P);
este.style.display = "none";
V='V'+cual;
N='N'+cual;
nover(N);
ver(V);
return;
}


function ninguno(hasta){
for (i=0; i < hasta; i++)
 {
 cual = 'P'+i;
 V =  'V'+i;
 N =  'N'+i;
este = document.getElementById(cual);
este.style.display = "none";
este = document.getElementById(N);
 este.style.display = "none";
 este = document.getElementById(V);
 este.style.display = "block";
}
este = document.getElementById('NG');
 este.style.display = "none";
 este = document.getElementById('VG');
 este.style.display = "block";
return;

}
function todos(hasta){
for (i=0; i < hasta; i++)
 {
 cual = 'P'+i;
 V =  'V'+i;
 N =  'N'+i;
 este = document.getElementById(cual);
 este.style.display = "block";
 este = document.getElementById(N);
 este.style.display = "block";
 este = document.getElementById(V);
 este.style.display = "none";

}
este = document.getElementById('NG');
 este.style.display = "block";
 este = document.getElementById('VG');
 este.style.display = "none";
return;

}

