

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("get", "/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("get", "/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("mainPage").style.visibility = 'visible';
	document.getElementById("container").style.background = '#DDD7CB';
	document.getElementById("publicitat").style.visibility = 'hidden'; 
}

function switchVisibilitatDiv(div){
	if(document.getElementById(div).style.display=='block'){
		amagarDiv(div);		
	}else {	
		mostrarDiv(div);
	}	
}
function amagarDiv(div){
	document.getElementById(div).style.display ='none';
}
function mostrarDiv(div){
	document.getElementById(div).style.display ='block';
}

function deshabilitarInput(div){
	document.getElementById(div).disabled=true;
}

function habilitarInput(div){
	document.getElementById(div).disabled=false;
}

function switchDiv(div,divs){
	var divobert;
	divobert=tancarDivs(divs);

	if(divobert==null){
		mostrarDiv(div);
	}else{
		if(divobert==div){
			amagarDiv(divobert);
		}else{
			mostrarDiv(div);
		}
	}
	
}
function tancarDivs(divs){
	var x=0;
	var returnvalue;

	for (x = 0; x < divs.length; x++){
		if(document.getElementById(divs[x]).style.display=='block'){
			returnvalue=divs[x];
		}		
		amagarDiv(divs[x]);
	  }
	return returnvalue;
}

function switchVisibilitat(div,divs){
	invisiblesDivs(divs);
	if(div!=null){
		document.getElementById(div).style.visibility = 'visible';
	}
}

function invisiblesDivs(divs){
	for (x = 0; x < divs.length; x++){
		document.getElementById(divs[x]).style.visibility = 'hidden';
	}
}

function cercador_poblacions(lletra) {
	switchVisibilitatDiv('infoCamps');
	var selectDestino=document.getElementById("cercadorPoblacions");
	var ajax=nuevoAjax();
	ajax.open("get", "/ajax/cercador_poblacions/"+lletra, true);
	
	ajax.onreadystatechange = function() { 
		if (ajax.readyState == 1) {
			
		}
		if (ajax.readyState == 4) {			
			selectDestino.innerHTML = ajax.responseText;
		} 
	}
	ajax.send(null);
}

function cercador_camps(poblacio) {
	var selectDestino=document.getElementById("infoCamps");
	var ajax=nuevoAjax();
	ajax.open("get", "/ajax/cercador_camps/"+poblacio, true);
	ajax.onreadystatechange = function() { 
		if (ajax.readyState == 1) {

		}
		if (ajax.readyState == 4) {
			selectDestino.innerHTML = ajax.responseText;
		} 
	}
	ajax.send(null);
}

function cercador_partitsxcamp(id_camp){
	var selectDestino=document.getElementById("infoCamps");
	var ajax=nuevoAjax();
	ajax.open("get", "/ajax/cercador_partitsxcamp/"+id_camp, true);
	ajax.onreadystatechange = function() { 
		if (ajax.readyState == 1) {

		}
		if (ajax.readyState == 4) {
			selectDestino.innerHTML = ajax.responseText;
		} 
	}
	ajax.send(null);
}

function mostrarPartits(id_camp,indicador){
	var selectDestino=document.getElementById("indicador"+id_camp);
	var ajax=nuevoAjax();
	ajax.open("get", "/ajax/indicador_partits/"+id_camp+"/"+indicador, true);
	ajax.onreadystatechange = function() { 
		if (ajax.readyState == 1) {

		}
		if (ajax.readyState == 4) {
			selectDestino.innerHTML = ajax.responseText;
		} 
	}
	ajax.send(null);
}

function tancarSessioArbitres(){
	document.location.href= urlbase + "/canal_arbitre/tancar_sessio_arbitres";
}


