var xmlHttp;
var auxXmlHttp;
var filas = null;
var which_canal = "";
function fill_select(canal)
{ 
which_canal = canal;
xmlHttp=makeHttpRequestObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }        
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET","canales_data.xml",true);
if (!window.ActiveXObject)
	xmlHttp.overrideMimeType('text/xml');
xmlHttp.send(null);
}

function stateChanged() 
{ 
if (xmlHttp.readyState==4)
  {		
		  var xmlDoc = null;
		  
		  if (window.ActiveXObject)
				{
					
					try
					{
					auxXmlHttp=new ActiveXObject("Msxml2.DOMDocument.3.0");
					}
				  catch (e)
					{
					auxXmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
					}
					auxXmlHttp.async = false;
					auxXmlHttp.loadXML(xmlHttp.responseText);
					
					filas = auxXmlHttp.childNodes[1].getElementsByTagName("Fila");

				}
			else
				{
					xmlDoc=xmlHttp.responseXML.documentElement;
					filas = xmlDoc.getElementsByTagName("Fila");
				}

		  var sel = document.getElementById("sel_box");
		  
			for(var i=1;i<filas.length;i++)
			  {
				
				var ciudad = filas[i].childNodes[calcu(3)].childNodes[0].data;
				
				if( !ciudad_listada(ciudad) )
				  { 
					var opcion = document.createElement("option");
					opcion.setAttribute("value",ciudad);
					opcion.innerHTML= ciudad;
					sel.appendChild(opcion);
				  }
			   }
	
	
  }
}

function ciudad_listada(ciudad)
{
	  var sel = document.getElementById("sel_box");
	  
	  for(var i=0;i<sel.options.length;i++)
		if(sel.options[i].value == ciudad) return true;

	  return false;
}

function makeHttpRequestObject()
{
		xmlHttp=null;
	try
	  {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	  }
	catch (e)
	  {
	  // Internet Explorer
	  try
		{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
	  catch (e)
		{
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	  }
	return xmlHttp;
}


function refresh_table()
{

	 var tabla = document.createElement("table");
	 var filas_xml = filas;

	 var int_aux=0;
	 
	 for(var i=0; i<filas_xml.length;i++)
	  {
		
		if(ciudad_seleccionada(filas_xml[i].childNodes[calcu(3)].childNodes[0].data) || i==0)
		  { var j=0;
			
			var fila = document.createElement("tr");

			if(int_aux%2==0)
				fila.setAttribute("bgcolor","#ECEEF1");
			int_aux++;

			while(filas_xml[i].childNodes[calcu(j)])			
			  {
				
				var celda = document.createElement(i==0?"th":"td");
				
				/*if(i==0){
						if(j==0 )celda.setAttribute("width","154");
						if(j==1 )celda.setAttribute("width","121");
						if(j==2 )celda.setAttribute("width","80");
						if(j==3 )celda.setAttribute("width","95");
				}*/

				if(filas_xml[i].childNodes[calcu(j)].childNodes[0])
					celda.innerHTML = filas_xml[i].childNodes[calcu(j)].childNodes[0].data;
				else
					celda.innerHTML = "&nbsp;";

				fila.appendChild(celda);
				
				j++;
			  }
			 tabla.appendChild(fila);
		  }
	  }
		
      
	  document.getElementById("td_canales").innerHTML = "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"data-table-1\" summary=\""+ which_canal +"\" width=\"100%\"><caption><em>"+which_canal+"</em></caption>" + tabla.innerHTML +"</table>";
	  
}

function ciudad_seleccionada(ciudad)
{
	 var sel = document.getElementById("sel_box");
	  
	  for(var i=0;i<sel.options.length;i++)
		if(sel.options[i].value == ciudad && sel.options[i].selected) return true;

	  return false;
}

function calcu(n)
{
 if (window.ActiveXObject)
	 return n;
 return 2*n+1;
}

//Desarrollado por RIB