var xml = loadXml("resellers.xml");
var xsl;

function ListarProvincias()
{
	xsl = loadXsl("resellers.xsl");
	var nodos_provincias = xml.getElementsByTagName("Ciudad");
	var provincias = new Array();
	for ( var i=0; i<nodos_provincias.length; i++ )
	{
		if ( !in_array(nodos_provincias[i].firstChild.nodeValue, provincias) )
		{
			provincias.push( nodos_provincias[i].firstChild.nodeValue );
		}
	}
	var selector = document.getElementById("sel_box");
	for ( i=0; i<provincias.length; i++ )
	{
		var opcion = document.createElement("option");
		opcion.setAttribute("value",provincias[i]);
		opcion.innerHTML= provincias[i];
		selector.appendChild(opcion);
	}
}

function refresh_table()
{
	var selector = document.getElementById("sel_box");
	var provincia = selector.options[selector.selectedIndex].value;
	// code for IE
	if (window.ActiveXObject)
	{
		var xsltThread = new ActiveXObject("Msxml2.XSLTemplate.4.0");
		xsltThread.stylesheet = xsl;
		var xsltProc = xsltThread.createProcessor();
		xsltProc.input = xml;
		//parameters
		xsltProc.addParameter("p_ciudad", provincia);
		xsltProc.transform();

		document.getElementById("td_canales").innerHTML=xsltProc.output;
	}
	// code for Mozilla, Firefox, Opera, etc.
	else if (document.implementation 
	&& document.implementation.createDocument)
	{
		xsltProcessor=new XSLTProcessor();
		xsltProcessor.importStylesheet(xsl);
		xsltProcessor.setParameter(null, "p_ciudad", provincia);
		resultDocument = xsltProcessor.transformToFragment(xml,document);
		document.getElementById("td_canales").innerHTML = "";
		document.getElementById("td_canales").appendChild(resultDocument);
	}
	var filas = document.getElementById("td_canales").childNodes[0].childNodes[1].childNodes;
	var i = 1;
	while ( filas[i] != null )
	{
		if ( i % 2 == 0 )
		{
			filas[i].setAttribute( (window.ActiveXObject ? "className" : "class"), "gris" );
		}
		i++;
	}
}