function get_est_values(tabview,opcion,formato_fecha)
{
    // if ( ( tabview == 1 ) && ( opcion == 1 ) ) 
	if (opcion == 1 )
    {
	  // var EstacionList = document.frmWeb.sel_est_origen;
	  var EstacionList = tabview.sel_est_origen;
      cur_est = EstacionList[EstacionList.selectedIndex].value;	
	  // var cur_fec = document.frmWeb.txt_fe_origen.value;	
	  var cur_fec = tabview.txt_fe_origen.value;	
	}
	// else if ( ( tabview == 1 ) && ( opcion == 2 ) )
	else if ( opcion == 2 )
	{
	  // var EstacionList = document.frmWeb.sel_est_destino;
	  var EstacionList = tabview.sel_est_destino;
      cur_est = EstacionList[EstacionList.selectedIndex].value;	
	  // var cur_fec = document.frmWeb.txt_fe_destino.value;	
	  var cur_fec = tabview.txt_fe_destino.value;	
	}
	
	// alert(cur_est + " " + cur_fec);
	
	request = new ajaxRequest();
	request.open("POST","horas_est.php",true);
	request.onreadystatechange=function()
	{
	  if (this.readyState == 4)
	  {
         if (this.status == 200)
		 {
		    if (this.responseXML != null )
			{
			  hora_inicio = this.responseXML.getElementsByTagName("inicio")[0].firstChild.data;
			  hora_fin = this.responseXML.getElementsByTagName("final")[0].firstChild.data;
			  procesa_respuesta_horas(tabview,opcion,hora_inicio,hora_fin);
			}
		 }
		 else
		 {
		   alert("Ajax error: " + this.statusText);
		 }
	  }

	}
	
	request.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	params = 'estacion=' + cur_est + '&fecha=' + cur_fec + '&forfecha=' + formato_fecha;
	request.send(params);
	
  
  
}


function ajaxRequest()
{

  try
  {
    request = new XMLHttpRequest();
  }
  catch(e1)
  {
    try
	{
	  request = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e2)
	{
	   try
	   {
	     request = new ActiveXObject("Microsoft.XMLHTTP");
	   }
	   catch(e3)
	   {
	     request = false;
	   }
	}
  }
  
  return request;

}


function procesa_respuesta_horas(tabview,opcion,hora_inicio,hora_fin)
{
  //alert(tabview + " " + opcion + hora_inicio + hora_fin);
  
  selidx = 0;
  
  // if ( ( tabview == 1 ) && ( opcion == 1 ) )
  if ( opcion == 1 )
  {
    // var HorasList = document.frmWeb.sel_hora_origen;
	var HorasList = tabview.sel_hora_origen;
	// var hora_default = document.getElementById('hdn_hora_origen').value;
	
  }
  // if ( ( tabview == 1 ) && ( opcion == 2 ) )
  if ( opcion == 2 )
  {
    // var HorasList = document.frmWeb.sel_hora_destino; 
	var HorasList = tabview.sel_hora_destino; 
    // var hora_default = document.getElementById('hdn_hora_destino').value;
  }
  
  hora_default = HorasList[HorasList.selectedIndex].value; 
  
  // alert(hora_default);
	
  ClearOptions(HorasList);
  
  if ( hora_inicio.substr(0,1) == "0" )
  {
    horai = parseInt(hora_inicio.substr(1,1));
  }
  else
  {
    horai = parseInt(hora_inicio.substr(0,2));
  }
  minutosi = hora_inicio.substr(3,2);
  
  
  if ( hora_fin.substr(0,1) == "0" )
  {
    horaf = parseInt(hora_fin.substr(1,1));
  }
  else
  {
    horaf = parseInt(hora_fin.substr(0,2));
  }  
  minutosf = hora_fin.substr(3,2);
  

  do
  {
    
	if ( horai > 12 )
	{
	  minutos_lbl = minutosi;
	  lbl_ampm = "PM";
	  
	  lbl_value = (horai) + ":" + minutos_lbl;
	  lbl_label = (horai < 22 ? "0" : "" ) + (horai - 12) + ":" + minutos_lbl + " " + lbl_ampm;
	  
	}
	else
	{
	  minutos_lbl = minutosi;
	  
	  lbl_ampm = ( horai < 12) ? "AM" : "PM";
	  
	  if ( horai < 10 )
	  {
	    lbl_value = "0" + horai + ":" + minutos_lbl;
		lbl_label = "0" + horai + ":" + minutos_lbl + " " + lbl_ampm;
	  }
	  else
	  {
	    lbl_value = horai + ":" + minutos_lbl;
		lbl_label = horai + ":" + minutos_lbl + " " + lbl_ampm;
	  }
	  
	}
	
	
	if ( minutosi == "00" ) 
	{
	  minutosi = "30";
	}
	else
	{
	  horai++;
	  minutosi = "00";
	}
	
	
	idx = AddToOptionList(HorasList, lbl_value, lbl_label);
	
	if (lbl_value == hora_default )
	{
	  selidx = idx;
	}
	
	// alert(lbl_value + " " + lbl_label);
	
  }  while (!(( horai == horaf ) && ( minutosi == minutosf)))
  
  HorasList.selectedIndex = selidx;
}

function ClearOptions(OptionList) 
{ 

// Always clear an option list from the last entry to the first
  for (x = OptionList.length; x >= 0; x = x - 1) 
  {
    OptionList[x] = null;
  }
}

function AddToOptionList(OptionList, OptionValue, OptionText) 
{
  // Add option to the bottom of the list
  idx = OptionList.length;
  OptionList[OptionList.length] = new Option(OptionText, OptionValue);
  return idx;
  
}


