//============ FUNCIONES DE PROXIMAS SALIDAS ================
var aMes = new Array("Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre");

var hoy = fechaActual();

function Right(str, num)
{
     //alert(str + " , " + num);
     return str.substring(str.length-num);
}

function fechaActual() {
  //------- fecha de hoy ------------
  Stamp = new Date();
  dia=Right("00" + Stamp.getDate(),2);
  mes=Right("00" + (Stamp.getMonth() + 1),2);
  anio=Right("0000" + Stamp.getYear(),4);
  return "" + (anio) +"-"+ (mes) + "-" + (dia);
}

function verSalidaSiguiente() {

 var txt ="";

 //document.writeln("Fecha actual: " + hoy + "<br>");
 //document.writeln("" + (a.length - 1)/4 + " filas de datos:<br>");

 var SalidaHoy=0;
 var SalidaSiguiente=0;

 for (i=0;i<a.length-1;i=i+4) {

   //document.writeln(a[i] + " " + a[i+1] + " " + a[i+2] + " " + a[i+3] + "<br>");

   if (a[i] == (hoy)) {
	SalidaHoy=1;
	break;
   }
   if (a[i] > (hoy)) {
	SalidaSiguiente=1;
	break;
   }
   
 };

 //document.writeln("Se sale en i=" + i + " con SalidaHoy=" + SalidaHoy + ", SalidaSiguiente=" + SalidaSiguiente + "<br>");

 txt = txt + "<div align='center'>";
 txt = txt + "<table border=0 bgcolor='#FFFFE6'><tr><td><a href='salidas.html'><img src='img/calendario.gif' border=0 ALT='Salidas'></a></td><td><font color='red'><small>";

 if (SalidaHoy==1) {
 	txt = txt + "<img src='img/nuevop.gif'><b>Salida para hoy:</b></FONT><br>";
	txt = txt + a[i+1] + " (" + a[i+2] + "). Horario: " + a[i+3] + "";
 };	
 if (SalidaSiguiente==1) {
	txt = txt + "<b>Próxima salida:</b></FONT><br>";
	txt = txt + "Día " + eval(a[i].substring(8,10)) + " de " + aMes[eval(a[i].substring(5,7))-1] + " en " +
		a[i+1] + " (" + a[i+2] + ").<br>Horario: " + a[i+3] + "";
 };
 txt = txt + "<br><div align=right><b><a href='salidas.html'>Ver más salidas...</a></b></div>";
 txt = txt + "</td></tr></table></div>";

 return txt;
};

function verListaDeSalidas() {

 var mesAnterior="";
 document.writeln("<table>");

 for (i=0;i<a.length-1;i=i+4) {
    if (a[i] >= (hoy)) {

	//------ Cabecera Lista ---------
	mes=aMes[eval(a[i].substring(5,7))-1];
	anio=a[i].substring(0,4);
	if (mes != mesAnterior) {
		cabeceraLista(mes + " " + anio);
		mesAnterior = mes;
	};

	//------ Detalle Lista ---------
 	//document.writeln(a[i] + " " + a[i+1] + " " + a[i+2] + " " + a[i+3] + "<br>");
	detalleLista(a[i],a[i+1],a[i+2],a[i+3]);


    }; //if
 }; //for


 document.writeln("</table></center>");

};

function cabeceraLista(x) {

 document.writeln("</table></center>");

 document.writeln("<h4>" + x + "</h4>");
 document.writeln("<center>");
 document.writeln("<table border=1>");
 document.writeln(" <tr>");
 document.writeln(" <td align=center bgcolor='#FFCCCC'><font color='#000080'><b>DÍA</b></font></td>");
 document.writeln(" <td align=center bgcolor='#FFCCCC'><font color='#000080'><b>LOCALIDAD/CENTRO</b></font></td>");
 document.writeln(" <td align=center bgcolor='#FFCCCC'><font color='#000080'><b>LUGAR DE EXTRACCIÓN</b></font></td>");
 document.writeln(" <td align=center bgcolor='#FFCCCC'><font color='#000080'><b>HORA</font></td>");
 document.writeln(" </tr>");

};

function detalleLista(a,b,c,d) {

 document.writeln(" <tr>");
 document.writeln(" <td align=center>" + eval(a.substring(8,10)) + "</td>");
 document.writeln(" <td>" + b + "</td>");
 document.writeln(" <td>" + c + "</td>");
 document.writeln(" <td nowrap>" + d + "</td>");
 document.writeln(" </tr>");

};
