

function envia_resultat(valor) {
	var f = document.resultat;
	
	if(f.competicio.value != 0) {
		document.location.href = valor+f.competicio.value;
	}
}



function nuevoAjax()
{ 
	/* Crea el objeto AJAX. Esta funcion es generica para cualquier utilidad de este tipo, por
	lo que se puede copiar tal como esta aqui */
	var xmlhttp=false;
	try
	{
		// Creacion del objeto AJAX para navegadores no IE
		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			// Creacion del objet AJAX para IE
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(E)
		{
			if (!xmlhttp && typeof XMLHttpRequest!='undefined') xmlhttp=new XMLHttpRequest();
		}
	}
	return xmlhttp; 
}

function canviSexeTerritorial(){
	var selectGenere = document.getElementById("genere");
	var selectTerritorial = document.getElementById("territorial");
	
	if (selectGenere.selectedIndex != 0 && selectTerritorial.selectedIndex != 0  ){
		carregaCategories();
		resetCompeticions();
	}else{
		resetCategories();
		resetCompeticions();
	}
}

function resetCompeticions () {
	selectActual = document.getElementById("competicio");
	selectActual.length=0;	
	var nuevaOpcion=document.createElement("option"); 
	nuevaOpcion.value=0; 
	nuevaOpcion.innerHTML="Escull gènere i/o territorial";
	selectActual.appendChild(nuevaOpcion);	
	//selectActual.disabled=true;
}

function resetCategories () {
	selectActual = document.getElementById("categoria");
	selectActual.length=0;	
	var nuevaOpcion=document.createElement("option"); 
	nuevaOpcion.value=0; 
	nuevaOpcion.innerHTML="Escull gènere i/o territorial";
	selectActual.appendChild(nuevaOpcion);	
	//selectActual.disabled=true;
}

function carregaCategories() {
	var selectGenere = document.getElementById("genere");
	var selectGenereOpcio = selectGenere.options[selectGenere.selectedIndex].value;
	
	var selectTerritorial = document.getElementById("territorial");
	var selectTerritorialOpcio = selectTerritorial.options[selectTerritorial.selectedIndex].value;
	
	modificaCategories(selectGenereOpcio, selectTerritorialOpcio, 0);
	
}


function carregaCom () {
	var selectGenere = document.getElementById("genere");
	var selectGenereOpcio = selectGenere.options[selectGenere.selectedIndex].value;
	
	var selectTerritorial = document.getElementById("territorial");
	var selectTerritorialOpcio = selectTerritorial.options[selectTerritorial.selectedIndex].value;
	
	var selectCategoria = document.getElementById("categoria");
	var selectCategoriaOpcio = selectCategoria.options[selectCategoria.selectedIndex].value;
	
	modificaCompeticions(selectGenereOpcio, selectTerritorialOpcio, selectCategoriaOpcio);
	
	
}

function modificaCompeticions (selectGenereOpcio, selectTerritorialOpcio, selectCategoriaOpcio) {
	var selectDestino=document.getElementById("competicio");
	var ajax=nuevoAjax();
	
	ajax.open("POST", "/ajax/combo-competicions/"+selectCategoriaOpcio+"/"+selectGenereOpcio+"/"+selectTerritorialOpcio, true);
	ajax.onreadystatechange = function() { 
		if (ajax.readyState == 1) {
			selectDestino.length = 0;
			var nuevaOpcion=document.createElement("option"); 
			nuevaOpcion.value=0; 
			nuevaOpcion.innerHTML="Carregant...";
			selectDestino.appendChild(nuevaOpcion); 
			//selectDestino.disabled=true;
		}
		if (ajax.readyState == 4) {
			if(selectDestino.parentNode!=null){
				selectDestino.parentNode.innerHTML = ajax.responseText;
			}
		} 
	}
	ajax.send(null);
}



function modificaCategories (selectGenereOpcio, selectTerritorialOpcio) {
	var selectDestino=document.getElementById("categoria");
	var ajax=nuevoAjax();
	
	ajax.open("POST", "/ajax/combo-categories/"+selectGenereOpcio+"/"+selectTerritorialOpcio, true);
	ajax.onreadystatechange = function() { 
		if (ajax.readyState == 1) {
			selectDestino.length = 0;
			var nuevaOpcion=document.createElement("option"); 
			nuevaOpcion.value=0; 
			nuevaOpcion.innerHTML="Carregant...";
			selectDestino.appendChild(nuevaOpcion); 
		//	selectDestino.disabled=true;
		}
		if (ajax.readyState == 4) {
			if(selectDestino.parentNode!=null){
				selectDestino.parentNode.innerHTML = ajax.responseText;
			}
		} 
	}
	ajax.send(null);
}

function tancarPublicitat(){
	document.getElementById("container").style.visibility = 'visible'; 
	document.getElementById("publicitat").style.visibility = 'hidden'; 
	 
	
}
