// ----------------------------------------------------------------
// Variales globales
// ----------------------------------------------------------------
var SEPARADOR_DECIMAL=".";
function fechaSistema(date)
{
var DiaSis = "" + date.getDate() ;
var MesSis =  date.getMonth() + 1;
MesSis = "" + MesSis;
var AnioSis = date.getYear() ;

if(navigator.appName == "Netscape")
{
	AnioSis += 1900;
}

AnioSis = "" + AnioSis;	
if (DiaSis.length==1)
{
	DiaSis = "0" + DiaSis;
}
	
if (MesSis.length==1)
{
	MesSis = "0" + MesSis;
}

return AnioSis+MesSis+DiaSis;
}
// VALIDAR FECHAS
function checkdate(dia,mes,ano){
DMes=new Array(0,31,28,31,30,31,30,31,31,30,31,30,31);
	
bis1 = ano % 4;
bis2 = ano % 100;
bis3 = ano % 400;
espacio = true;

if(!EsNumero(dia) || !EsNumero(mes) || !EsNumero(ano)) 
{
return false;
}
	
bis = false;
if(bis1==0)
{
	bis=true;
	if( bis2==0 )
	{			
	bis=false;   
	if(bis3 ==0)
	{				
	bis=true;
	}
	else
	{
	bis=false;
	}		
}
else
{
bis=true;
}
}
else
{
	bis=false;
}
if(bis)
{
	DMes[2]=29;
}

if ( dia.length != 2 || dia.indexOf(" ") != -1)
{
	espacio = false;   
		
	}
	
	if ((mes.length != 2 || mes.indexOf(" ") != -1))
	{
		espacio = false;   
	}

	if ((ano.length != 4 || ano.indexOf(" ") != -1))
	{
		espacio = false;   
	}
	
	if ( ano < 1900 || mes > 12 || dia>DMes[parseFloat(mes)] || espacio == false)
	{
		return false;
		
	}
	else
	{
		
		return  true;
	}
}

// formateo de fecha de forma ddmmaaaa siempre
function formatear(dia,mes,ano) {

	if ( dia<10 && dia.substring(0,1) != "0" )
	{
        	dia="0"+dia;
	}
	else
	{
        	dia=""+dia;
        }

        if( mes <10 && mes.substring(0,1) != "0")
        {
        	mes="0"+mes;
	}
	else
	{
		mes=""+mes;

        }
          
	return ano+mes+dia;
}

// ----------------------------------------------------------------
// Comprueba si la 'Cadena' enviada está compuesta sólo por letras
// ----------------------------------------------------------------
function bEsLetra(Cadena)
{
	// Si lo que recibe no es una cadena devuelve falso.
	if (typeof(Cadena) != "string")
	{
		return false;
	}

	var Letras='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzáéíóú';
	
	for (var i=0; i< Cadena.length; i++)
	{
		if (Letras.indexOf(Cadena.charAt(i)) == -1)
          		return false;
	}
	
	return true;
}

// ----------------------------------------------
// Vacia todos los campos (text) de un formulario
// ----------------------------------------------
function borrarCampos(formulario)
{
	for(var i=0; i<formulario.elements.length;i++)
	{
		if(formulario.elements[i].type == "text")
		{
			formulario.elements[i].value = "";
		}
	}
}

// ----------------------------------------------------------------
// Comprueba si Cadena es un número
// ----------------------------------------------------------------
function EsNumero(Cadena)
{
    var ContadorDecimal=0;
	
    // Si lo que recibe no es una cadena devuelve falso.
    if (typeof(Cadena) != "string")
    {
	return false;
    } 
    
    if (Cadena=="")     
    {
	return false;
    }
		

    var CaracteresValidos="0123456789." // + SEPARADOR_DECIMAL;

    for (var i=0; i< Cadena.length; i++)
    {
    	if (CaracteresValidos.indexOf(Cadena.charAt(i)) == -1)
		return false;
    }

/*	
    // Comprobamos que en la cadena solo exista un punto decimal
   for (var i=0; i< Cadena.length; i++)
   {
	 if (Cadena.charAt(i) == SEPARADOR_DECIMAL)
	{
			if (++ContadorDecimal > 1)
				return false;
	}	
    }
*/

    return true;
}

function marcarTodos(form) {
	for(var i=0; i<form.elements.length;i++)
	{
		if(form.elements[i].type == "checkbox")
		{
			form.elements[i].checked = true;
		}
	}


}

// ----------------------------------------------------------------
// Funcion para que funcione la fecha
// ----------------------------------------------------------------

function Item(){
this.length = Item.arguments.length 
for (var i = 0; i < this.length; i++)
  this[i] = Item.arguments[i]
}

// ----------------------------------------------------------------
// Recoge la fecha del sistema
// ----------------------------------------------------------------
function Fecha() {
var ndia = new Item('Domingo','Lunes','Martes','Miércoles','Jueves','Viernes','Sábado')
var nmes = new Item('Enero','Febrero','Marzo','Abril','Mayo','Junio','Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre')
var ahora
var fecha = new Date()
var ano = fecha.getYear()
var mes = fecha.getMonth()
var dia = fecha.getDay()
var aux = "" + fecha

if (ano<10) {
 ano2 = "200" + eval(ano)
}
else if (ano<80) {// ano tiene 2 dígitos 19xx (más de 80)
 ano2 = "20" + ano
} 
else if (ano<=99) {// ano tiene 2 dígitos 20xx (menor de 80)
 ano2 = "19" + ano
}
else if (ano<1000) {// ano tiene 3 dígitos (100 es 2000)
 ano2 = eval(ano) + eval(1900)
}
else {// ano tiene 4 dígitos
 ano2 = ano
}
ahora =eval(aux.substring(7, 10)) + " de " + nmes[mes] + " de " + ano2
return ahora
}



// ----------------------------------------------------------------
// Recoge la hora del sistema
// ----------------------------------------------------------------

function Hora()
{
LaFecha=new Date();
LaHora= LaFecha.getHours();
Minu=LaFecha.getMinutes();
var CadHora=""+((LaHora>12) ? LaHora - 12 : LaHora);
Seg=LaFecha.getSeconds();
var P= ((CadHora<10) ? "0" : "") + CadHora ;
var CadMin=((Minu<10) ? "0" : "")+Minu;
var mer=((LaHora>=12) ? " p.m." : " a.m." );
return P+":"+CadMin+mer
}



//Fecha y Hora
var iNaveg= (document.all) ? 1 : 0;
function myC(lay){  
this.creaSp = creaSp;
this.lay=lay;
this.update = update;
this.writeT = writeT;}
function creaSp(){
var today = new Date(); 
a = today.getSeconds()
if (a<10){
segundo="0"+a}
else{
segundo=today.getSeconds()}
b = today.getMinutes()
if (b<10){
minuto="0"+b}
else{
minuto=today.getMinutes() }
hora = today.getHours()

str_minuto = new String (minuto) 
    if (str_minuto.length == 1) 
       minuto = "0" + minuto 

    str_hora = new String (hora) 
    if (str_hora.length == 1) 
       hora = "0" + hora 

if (hora > 24){
hora = hora - 24;
}
dateStr = hora + ":" + minuto + ":" + segundo;
this.display = dateStr;}
function update(){
this.creaSp();
this.writeT();
window.setTimeout("aClock.update()", 1000);}
function writeT(){
var htmlOut = ""
htmlOut += "<font class='euros1'>" +this.display +"</font>"
if(document.layers) {
this.lay.document.open();
this.lay.document.write(htmlOut);
this.lay.document.close();
} else {
this.lay.innerHTML = htmlOut;}}
function init() {
if(document.layers){
aClock = new myC(document.layers["reloj"])  // Netscape syntax
aClock.update();
} else {
if (document.all)
aClock = new myC(document.all["reloj"])  // IE syntax
else
aClock = new myC(document.getElementById("reloj"))  // IE syntax
aClock.update();}}
var meses = new Array();
meses[1]=" Enero ";
meses[2]=" Febrero ";
meses[3]=" Marzo ";
meses[4]=" Abril ";
meses[5]=" Mayo ";
meses[6]=" Junio ";
meses[7]=" Julio ";
meses[8]=" Agosto ";
meses[9]=" Septiembre ";
meses[10]=" Octubre ";
meses[11]=" Noviembre ";
meses[12]=" Diciembre ";

function getF(sep){
var fecha=new Date();
var dia=fecha.getDate();
var mes=fecha.getMonth()+1;
var mestxt = meses[mes];
var anio=fecha.getFullYear();
var numero=fecha.getDay();
var nom;
switch (numero){
case 1 : nom = "Lunes"; break;
case 2 : nom = "Martes"; break;
case 3 : nom = "Miércoles"; break;
case 4 : nom = "Jueves"; break;
case 5 : nom = "Viernes"; break;
case 6 : nom = "Sábado"; break;
case 0: nom = "Domingo"; break;}
if ( dia<10)
	{
        	dia="0"+dia;
	}
	else
	{
        	dia=""+dia;
        }
var hoy = "Lima" + ", " + dia + " de" + mestxt +"de "+ anio;
return hoy;}

//Fechas
        
  var aFinMes = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); 
  var fecha=new Date();
  var dia=fecha.getDate();
  var mes=fecha.getMonth()+1;
  var anio=fecha.getFullYear();
  if (mes<10)
        {     	
        	mes="0"+mes;
	}
	else
	{
		mes=""+mes;
	}
	if (dia<10)
	{
        	dia="0"+dia;
	}
	else
	{
        	dia=""+dia;
        }
  var hoy = dia +"/"+ mes +"/"+ anio;
  
  function finMes(nMes, nAno){ 
  	return aFinMes[nMes - 1] + (((nMes == 2) && (nAno % 4) == 0)? 1: 0); 
  } 
   function padNmb(nStr, nLen, sChr){ 
    var sRes = String(nStr); 
    for (var i = 0; i < nLen - String(nStr).length; i++) 
     sRes = sChr + sRes; 
    return sRes; 
   } 
   function makeDateFormat(nDay, nMonth, nYear){ 
    var sRes; 
    sRes = padNmb(nDay, 2, "0") + "/" + padNmb(nMonth, 2, "0") + "/" + padNmb(nYear, 4, "0"); 
    return sRes; 
   }   
   
   function incDate(sFec0){ 
   var nDia = parseInt(sFec0.substr(0, 2), 10); 
   var nMes = parseInt(sFec0.substr(3, 2), 10); 
   var nAno = parseInt(sFec0.substr(6, 4), 10); 
   nDia += 1; 
   if (nDia > finMes(nMes, nAno)){ 
    nDia = 1; 
    nMes += 1; 
    if (nMes == 13){ 
     nMes = 1; 
     nAno += 1; 
    } 
   } 
   return makeDateFormat(nDia, nMes, nAno); 
  }   
  function decDate(sFec0){ 
   var nDia = Number(sFec0.substr(0, 2)); 
   var nMes = Number(sFec0.substr(3, 2)); 
   var nAno = Number(sFec0.substr(6, 4)); 
   nDia -= 1; 
   if (nDia == 0){ 
    nMes -= 1; 
    if (nMes == 0){ 
     nMes = 12; 
     nAno -= 1; 
    } 
    nDia = finMes(nMes, nAno); 
   } 
   return makeDateFormat(nDia, nMes, nAno); 
  } 
  function redToDate(sFec0, sInc){ 
   var nInc = Math.abs(parseInt(sInc)); 
   var sRes = sFec0; 
    if (parseInt(sInc) >= 0) 
    for (var i = 0; i < nInc; i++) sRes = incDate(sRes); 
   else 
    for (var i = 0; i < nInc; i++) sRes = decDate(sRes); 
   return sRes; 
  } 
    function recalcF1(param){ 	
	var nueva_fecha = redToDate(hoy, param); 
	return nueva_fecha;  
  }
  
function recalcF2(param){ 	      
       	var nueva_fecha1 = redToDate(hoy, param); 
       	a = nueva_fecha1.substring(0,6);
       	b = nueva_fecha1.substring(8,10);
       	var nueva_fecha2 = a + b;       
	return nueva_fecha2;  
}

// fecha Actual 12:30:00
function segundos() {
  var hours, minutes, seconds;
  var intHours, intMinutes, intSeconds;
  var today;

  today = new Date();

  intHours = today.getHours();
  intMinutes = today.getMinutes();
  intSeconds = today.getSeconds();

  switch(intHours){
       case 0:
           intHours = 12;
           hours = intHours+":";          
           break;
       case 12:
           hours = intHours+":"; 
           break;
       case 24:
           intHours = 24;
           hours = intHours + ":";
           break;
       default:    
           if (intHours > 12)
           {
             hours = intHours + ":";
             break;
           }
           if(intHours < 12)
           {
             hours = intHours + ":";
           }
    }     
          
  if (intMinutes < 10) {
     minutes = "0"+intMinutes+":";
  } else {
     minutes = intMinutes+":";
  }

  if (intSeconds < 10) {
     seconds = "0"+intSeconds+" ";
  } else {
     seconds = intSeconds+" ";
  } 

  timeComplete = hours+minutes+seconds;
  return timeComplete;
}


// fecha Actual 12:30
function minutos() {
  var hour, minute;
  var intHour, intMinute;
  var today1;

  today1 = new Date();

  intHour = today1.getHours();
  intMinute = today1.getMinutes();

  switch(intHour){
       case 0:
           intHour = 12;
           hour = intHour+":";          
           break;
       case 12:
           hour = intHour+":"; 
           break;
       case 24:
           intHour = 24;
           hour = intHour + ":";
           break;
       default:    
           if (intHour > 12)
           {
             hour = intHour + ":";
             break;
           }
           if(intHour < 12)
           {
             hour = intHour + ":";
           }
    }     
          
  if (intMinute < 10) {
     minute = "0"+intMinute;
  } else {
     minute = intMinute;
  }
  
  timeComplete = hour+minute;
  return timeComplete;
}