/* 
 * Java script function to set up Index Page
 */
function AjustarIndex_Page()
{
	CrearMainMenu("oIndexMenu");
	CrearCopyrights("oIndexCopyRigth");

	return;
}


/* 
 * Java script function to set up Quienes Somos Page
 */
function AjustarQuienes_Page()
{
   var xmlMiembros= load_Xml(xmlMiembros, "../xml/Miembros.xml");

	CrearMainMenu("oQuienesMenu");
	CrearCopyrights("oQuienesCopyRigth");
   load_Miembros(xmlMiembros);

	return;
}



/* 
 * Java script function to set up Novedades Page
 */
function AjustarNovedades_Page(p_Xml)
{
   var xmlPCompete= load_Xml(xmlPCompete, "../xml/PCompete.xml");

	CrearMainMenu("oNovedadesMenu");
	CrearCopyrights("oNovedadesCopyRigth");
   load_PCompete("tblPCompete", xmlPCompete);

	return;
}


/* 
 * Java script function to set up Entrenamientos Page
 */
function AjustarEntrenamientos_Page()
{
   var xmlPEntrena= load_Xml(xmlPEntrena, "../xml/PEntrena.xml");

	CrearMainMenu("oEntrenamientosMenu");
	CrearCopyrights("oEntrenamientosCopyRigth");
   load_PEntrena("tblPEntrena", xmlPEntrena);

	return;
}


/* 
 * Java script function to set up Contactanos Page
 */
function AjustarContactanos_Page()
{
	CrearMainMenu("oContactanosMenu");
	CrearCopyrights("oContactanosCopyRigth");

	return;
}


/* 
 * Java script function to set up Especiales Page
 */
function AjustarEspeciales_Page()
{
	CrearMainMenu("oEspecialesMenu");
	CrearCopyrights("oEspecialesCopyRigth");

	return;
}


/* 
 * Java script function to set up Enlaces Page
 */
function AjustarVinculos_Page()
{
	CrearMainMenu("oEnlacesMenu");
	CrearCopyrights("oEnlacesCopyRigth");

	return;
}


/* 
 * Java script function to set up Herramientas Page
 */
function AjustarHerramientas_Page()
{
	CrearMainMenu("oHerramientasMenu");
	CrearCopyrights("oHerramientasCopyRigth");

	return;
}


/* 
 * Java script function to Calculate Estimated Pace
 */
function CalcPaso(p_Name)
{
   var oTime= window.document.getElementsByName(p_Name);
   var aTime= Array(8);

   for(var i=0; i<5; i++)
   {
      aTime[i]= parseFloat(oTime[i].value);
      if(isNaN(aTime[i]))
         aTime[i]= 0;
   }
   aTime[5]= Math.round((aTime[0]*3600+aTime[1]*60+aTime[2])/aTime[4])/60;
   aTime[6]= Math.floor(aTime[5]);
   aTime[7]= Math.round((aTime[5]-Math.floor(aTime[5]))*60);
   for(var i=0; i<3; i++)
   {
      oTime[i].value= aTime[i]<10 ? "0"+aTime[i] : aTime[i];
   }
   oTime[6].value= (aTime[6]<10 ? "0"+aTime[6] : aTime[6]) + ":" + (aTime[7]<10 ? "0"+aTime[7] : aTime[7]);
   oTime[8].value= "";
	return;
}


/* 
 * Java script function to set Distace value
 */
function setDistance(p_Name)
{
   var oTime= window.document.getElementsByName(p_Name);

   oTime[4].value= oTime[3].value;
	return;
}


/* 
 * Java script function to Calculate Estimated Marathon Performance
 
 * Estimate Time: T2 = T1 x (D2/D1)1.06, where
 * T1: last race time
 * D2: 26.2 miles (Marathon Distance)
 * D1: last race distance

 * Estimate Pace: T2/D2
 
 */
function CalcEstimado(p_Name)
{
   var oTime= window.document.getElementsByName(p_Name);
   var aTime= Array(9);

   for(var i=0; i<5; i++)
   {
      aTime[i]= parseFloat(oTime[i].value);
      if(isNaN(aTime[i]))
         aTime[i]= 0;
   }

   aTime[5]= ((aTime[0]*3600+aTime[1]*60+aTime[2]) * (42.195 / aTime[4]) * 1.18) / 3600;

   /* Hours   */
   aTime[6]= Math.floor(aTime[5]);
   /* Minutes */
   aTime[5]= (aTime[5]-Math.floor(aTime[5]))*60;
   aTime[7]= Math.floor(aTime[5]);
   /* Seconds */
   aTime[8]= Math.round((aTime[5]-Math.floor(aTime[5]))*60);
   for(var i=0; i<3; i++)
   {
      oTime[i].value= aTime[i]<10 ? "0"+aTime[i] : aTime[i];
   }
   oTime[8].value= (aTime[6]<10 ? "0"+aTime[6] : aTime[6]) + ":" + (aTime[7]<10 ? "0"+aTime[7] : aTime[7]) + ":" + (aTime[8]<10 ? "0"+aTime[8] : aTime[8]);

   aTime[5]= Math.round((aTime[6]*3600+aTime[7]*60+aTime[8])/42.195)/60;
   aTime[6]= Math.floor(aTime[5]);
   aTime[7]= Math.round((aTime[5]-Math.floor(aTime[5]))*60);
   oTime[6].value= (aTime[6]<10 ? "0"+aTime[6] : aTime[6]) + ":" + (aTime[7]<10 ? "0"+aTime[7] : aTime[7]);

	return;
}


/* 
 * Java script function to set up Main Menu
 */
function CrearMainMenu(p_Container)
{
   var oConta= window.document.getElementById(p_Container);
	var oTable= window.document.createElement("table");
   var oTBody= window.document.createElement("tbody");
   var oRow, oCell;
   var aTable= Array(18);
   var aPath= Array(2);
   var nPath= 0;

   aPath[0]= "";
   aPath[1]= "../";

   if(p_Container != "oIndexMenu")
   {
      nPath= 1;
   }

   aTable[ 0]= "<img src=\""+aPath[nPath]+"img/animated/Runner_animated01.gif\" width=\"76\" height=\"47\" border=\"0\" alt=\"Club Mentor Express\"/>";
   aTable[ 1]= "<a href=\""+aPath[nPath]+"index.html\"><img class=\"Mnu_Button\" src=\""+aPath[nPath]+"img/buttons/Inicio_button.gif\"    width=\"120\" height=\"20\" border=\"0\" alt=\"Inicio\"></a>";
   aTable[ 2]= "<p class=\"Titulo_Button\">Bienvenida</p>";
   aTable[ 3]= "<a href=\""+aPath[nPath]+"html/QuienesSomos.html\"><img class=\"Mnu_Button\" src=\""+aPath[nPath]+"img/buttons/aboutus_button.gif\"   width=\"120\" height=\"20\" border=\"0\" alt=\"Nosotros\"></a>";
   aTable[ 4]= "<p class=\"Titulo_Button\">Quienes Somos?</p>";
   aTable[ 5]= "<a href=\""+aPath[nPath]+"html/Novedades.html\"><img class=\"Mnu_Button\" src=\""+aPath[nPath]+"img/buttons/whatsnew_button.gif\"  width=\"120\" height=\"20\" border=\"0\" alt=\"Novedades\"></a>";
   aTable[ 6]= "<p class=\"Titulo_Button\">Pr&#243;ximos Eventos</p>";
   aTable[ 7]= "<a href=\""+aPath[nPath]+"html/Entrenamientos.html\"><img class=\"Mnu_Button\" src=\""+aPath[nPath]+"img/buttons/services_button.gif\"  width=\"120\" height=\"20\" border=\"0\" alt=\"Servicios\"></a>";
   aTable[ 8]= "<p class=\"Titulo_Button\">Entrenamiento</p>";
   aTable[ 9]= "<a href=\""+aPath[nPath]+"html/Contactanos.html\"><img class=\"Mnu_Button\" src=\""+aPath[nPath]+"img/buttons/contactus_button.gif\" width=\"120\" height=\"20\" border=\"0\" alt=\"Cont&#225;ctanos\"></a>";
   aTable[10]= "<p class=\"Titulo_Button\">Cont&#225;ctanos</p>";
   aTable[11]= "<a href=\""+aPath[nPath]+"html/Carreras10k.html\"><img class=\"Mnu_Button\" src=\""+aPath[nPath]+"img/buttons/specials_button.gif\"  width=\"120\" height=\"20\" border=\"0\" alt=\"Especiales\"></a>";
   aTable[12]= "<p class=\"Titulo_Button\">Carrera 10k</p>";
   aTable[13]= "<a href=\""+aPath[nPath]+"html/LinksInteres.html\"><img class=\"Mnu_Button\" src=\""+aPath[nPath]+"img/buttons/vinculos_button.gif\"  width=\"120\" height=\"20\" border=\"0\" alt=\"V&#237;nculos\"></a>";
   aTable[14]= "<p class=\"Titulo_Button\">Enlaces de Interes</p>";
   aTable[15]= "<a href=\""+aPath[nPath]+"html/Herramientas.html\"><img class=\"Mnu_Button\" src=\""+aPath[nPath]+"img/buttons/Tools_button.gif\"  width=\"120\" height=\"20\" border=\"0\" alt=\"V&#237;nculos\"></a>";
   aTable[16]= "<p class=\"Titulo_Button\">Herramientas</p>";
   aTable[17]= "<img src=\""+aPath[nPath]+"img/animated/Runner_animated02.gif\" width=\"51\" height=\"51\" border=\"0\" alt=\"Club Mentor Express\"/>";
   aTable[18]= "<img src=\""+aPath[nPath]+"img/Nike10k2007Personal.jpg\" width=\"125\" height=\"120\" border=\"0\" alt=\"Nike 10k\"/>";

   oTable.id= "TMenu";
   oTable.border= 0;
   oTBody.id= "TBodyMenu";

   // Insert the created element into oTable.
   oTable.appendChild(oTBody);

   // Insert the created element into oConta.
   oConta.appendChild(oTable);

   for(var i= 0; i<aTable.length; i++)
   {
      oRow = window.document.createElement("tr");
      oCell = window.document.createElement("th");
      oCell.innerHTML= aTable[i];
      oRow.appendChild(oCell);

      oTBody.appendChild(oRow);
   }

	return;
}


/* 
 * Java script function to set up CopyRight
 */
function CrearCopyrights(p_Container)
{
   var oConta= window.document.getElementById(p_Container);
	var oTable= window.document.createElement("table");
   var oTBody= window.document.createElement("tbody");
   var oRow, oCell;
   var aTable= Array(1);

   aTable[ 0]= "<p class=\"CopyRights\"><br><br>Club Mentor Express<br><a href=\"mailto:Copyright 2003\">Copyright 2003</a><br>Todos los derechos reservados</p>";

   oTable.id= "TCopy";
   oTable.border= 0;
   oTBody.id= "TBodyCopy";

   // Insert the created element into oTable.
   oTable.appendChild(oTBody);

   // Insert the created element into oConta.
   oConta.appendChild(oTable);

   for(var i= 0; i<aTable.length; i++)
   {
      oRow = window.document.createElement("tr");
      oCell = window.document.createElement("th");
      oCell.innerHTML= aTable[i];
      oRow.appendChild(oCell);

      oTBody.appendChild(oRow);
   }

   return;
}


/* 
 * Java script function to Print Up Training
 */
function  PrintLigth(p_Table)
{
   var v_Win, x;

   //Display Windows
   v_Win= window.open("", "", "resizable=no, toolbar=no, menubar=yes, status=no, location=no, scrollbar=yes");
   
   v_Win.document.writeln("<table border='0'>");
    for (var i=0; i < p_Table.rows.length; i++)
    {
      if((x= p_Table.rows(i).innerHTML.indexOf("img"))<0)
      {
         v_Win.document.writeln("<tr>");
         v_Win.document.writeln(p_Table.rows(i).innerHTML);
         v_Win.document.writeln("</tr>");
      }
    }
   v_Win.document.writeln("</table>");
   return;
}
