/*alert ("informe partido");*/
var gko = navigator.userAgent.toLowerCase();
var nLes=0;
var nAvi=0;
var nNoavi=0;
var nEnsayos=0;
var nGolpes=0;
var nPalos=0;
var nDrops=0;
var nAmarillas=0;
var nRojas=0;

function chequear_sistema(){
	if (gko.indexOf('gecko')==-1){
		alert("Por Favor utilice el explorador FIREFOX, www.firefox.com");
		exit;
		/*history.back();*/
	}
}
function chequear_informe(){
	ventana=confirm("Comprueba los datos, estas seguro??");
	 if (ventana)
		document.form_partidos.submit();
}

function quitar_informe(i){
	idPadre="id";
	pos="pos"+i;
	id=idPadre+i;
	idJug="id_"+idPadre+"_"+i
	idNomJug=idPadre+"_"+i;
	tipo="tipo"+i;
	lista=document.getElementById(tipo).value;
	long_lista=document.getElementById(lista).length;
	document.getElementById(lista).options[long_lista] = new Option();
	document.getElementById(lista).options[long_lista].value = document.getElementById(id).value;
	document.getElementById(lista).options[long_lista].text =  document.getElementById(i).value;
	items=document.getElementById(lista).options;        // los originales 
	opciones=new Array();                                    // sera un doble array: con el texto, y con el valor 
	//ordenaremos 'opciones', despues sobrescribiremos todas las opciones originales con 'opciones' que ya estaran ordenadas 
	//rellenamos 'opciones' 
	for(a=0;a<items.length;a++) 
		opciones[a]=new Array( items[a].text, items[a].value); 
		opciones.sort();    // ordenamos 'opciones'. Se ordenara alfabeticamente opciones[0], y los cambios seran efectivos tambien para opciones[1] 
	for(a=0;a<items.length;a++) {        //sobrescribimos las opciones originales a las ordenadas 
		items[a].text=opciones[a][0]; 
		items[a].value=opciones[a][1]; 
	}
	document.getElementById(i).value="";
	document.getElementById(id).value="";
	document.getElementById(tipo).value="";
	if(pos<16)
		document.getElementById(pos).value="";
	else
		document.getElementById(pos).value=0;
}

//------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------

//------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------
function lista_informe(i,idcat,num_jugadores) {
	chequear_sistema();
	/*	alert ("posicion: "+i.value);
		alert (i.options.selectedIndex);
		alert ("j: "+i.options[i.selectedIndex].text);*/
	radio="div_radio";
	ele=document.getElementById(radio);
	if(ele.childNodes[0].checked==true){
		hecho=0;
		if(idcat!=46 && idcat!=29 && idcat!=28 && idcat!=21){
			for (j=1;j<23;j++){
				if(idcat!=30 || (j!=6 && j!=7)){
					if(document.getElementById(j).value=="" && hecho==0){
						hecho=1;
						document.getElementById(j).value=i.options[i.selectedIndex].text;
						posicion="id"+j;
						document.getElementById(posicion).value=i.value;
						tipo="tipo"+j;
						document.getElementById(tipo).value=i.name;
						if(j>15){
							var pos_suplente=prompt("Posición del 0 al 15","");
							while(pos_suplente<0 || pos_suplente>15 || pos_suplente.search(/\D/)!=-1 || pos_suplente.search(/\W/)!=-1){
								alert("NO ha introducido un número del 0 al 15");
								var pos_suplente=prompt("Posición del 0 al 15","");
							}
							pos="pos"+j;
							document.getElementById(pos).value=pos_suplente;
						}
					}
				}
			}
		}else{
			for (j=1;j<num_jugadores;j++){
				if(document.getElementById(j).value=="" && hecho==0){
					hecho=1;
					document.getElementById(j).value=i.options[i.selectedIndex].text;
					posicion="id"+j;
					document.getElementById(posicion).value=i.value;
					tipo="tipo"+j;
					document.getElementById(tipo).value=i.name;
				}
			}
		}
	}else{
		if(ele.childNodes[3].checked==true){
			numJug=nLes;
			id="les";
			num_tipo=5;
		}else if(ele.childNodes[6].checked==true){
			numJug=nAvi;
			id="avi";
			num_tipo=6;
		}else if(ele.childNodes[9].checked==true){
			numJug=nNoavi;
			id="no_avi";
			num_tipo=7;
		}
		nAbuelo=document.getElementById(id);
		numPadres=nAbuelo.childNodes.length;
		numTotal=document.getElementById("total_num_"+id).value; 
		if(numJug==0){
			for (k=0;k<numPadres;k++){
				if(nAbuelo.childNodes[k].nodeName=="DIV"){
					if(nAbuelo.childNodes[k].style.display=="inline")
						numJug++;
				}
			}
		}
		if (numJug==0){
			nPadre=document.getElementById(id+"1");
			nPadre.style.display="inline";
			iNombre=id+"_1";
			document.getElementById(iNombre).value=i.options[i.selectedIndex].text;
			iId="id_"+id+"_1";
			document.getElementById(iId).value=i.value;
			tipo="tipo_"+id+"_1";
			document.getElementById(tipo).value=i.name;
		}else{
			for(k=0;k<numPadres;k++){
				if(nAbuelo.childNodes[k].nodeName=="DIV"){
					nPadre_id=nAbuelo.childNodes[k].id;
				}
			}
		/*				alert("nPadre: "+nPadre_id);
			nPadre=document.getElementById(nPadre_id);*/
			var nHijo=nPadre.cloneNode(true);
			nAbuelo.appendChild(nHijo);
			nHijo.id=id+numJug;
		/*			alert("nHijo id: "+nHijo.id);*/
			numHijos=nHijo.childNodes.length;
			for(k=0;k<numHijos;k++){
				if(nHijo.childNodes[k].nodeName=="IMG"){
					nHijo.childNodes[k].id=id+"_img_"+numJug;
					opcion2="quitar_tarjetasydemas(\""+id+"\","+numJug+")";
		/*			opcion2="quitar_tarjetasydemas(\""+id+"\","+numJug+")";
					alert("opcion: "+opcion2);*/
					nHijo.childNodes[k].setAttribute('onClick',opcion2);
				}
				if(nHijo.childNodes[k].nodeName=="INPUT"){
					nTexto_input=nHijo.childNodes[k].id.substring(0,2);
					nTexto_iTipo=id.substring(0,2);
					switch (nTexto_input) {
						case "id":
							iId="id_"+id+"_"+numJug;
							nHijo.childNodes[k].id=iId;
							nHijo.childNodes[k].value=i.value;
							break;
						case "ti":
							iId="tipo_"+id+"_"+numJug;
							nHijo.childNodes[k].id=iId;
							nHijo.childNodes[k].value=i.name;
							break;
						case nTexto_iTipo:
							iNombre=id+"_"+numJug;
							nHijo.childNodes[k].id=iNombre;
							nHijo.childNodes[k].value=i.options[i.selectedIndex].text;
							break;
					}
				}
			}
		}
		numTotal=(numTotal*1)+1;
		document.getElementById("total_num_"+id).value=numTotal;
		i.options[i.selectedIndex]=null;
		i.selectedIndex=0;
		numJug++;
		switch(id){
			case "les":
				nLes=numJug;
				break;
			case "avi":
				nAvi=numJug;
				break;
			case "no_avi":
				nNoavi=numJug;
				break;
		}
	}
	i.options[i.selectedIndex]=null;
	i.selectedIndex=0;
}

function fn_partidos_anadir(i) {
	nodeFila=document.getElementById("fila");
	nodeNuevaFila=nodeFila.cloneNode(true);
	nodeNuevaFila.style.visibility="visible";
	alert("Hecho");
}

var iCuenta;
function fn_partidos_posicion_est(num,k) {
	if(document.getElementById("tipo_"+k).value!='Titular' && document.getElementById("tipo_"+k).value!='Suplente'){
		alert("Este jugador no ha sido TITULAR o SUPLENTE");
		num.value=0;
	}else{
		if(document.getElementById("tipo_"+k).value=='Titular' ){
			for(iCuenta=k-1;iCuenta!=0;iCuenta--){
				if(document.getElementById("pos_"+iCuenta).value==num.value){
					alert("Ya existe este NUMERO de posición para un TITULAR");
					num.value=0;
				}
			}
		}
	}
}

function fn_partidos_chequear_num(num,k) {
	if (num.value.search("[a-zA-Z]")!=-1){
		alert("No es numero");
		num.value="0";
	}
	if(document.getElementById("pos_"+k).value==0){
		alert("Este jugador no ha jugado, No tiene ninguna POSICIÓN");
		num.value="0";
	}
	if(document.getElementById("tipo_"+k).value!='Titular' && document.getElementById("tipo_"+k).value!='Suplente'){
		alert("Este jugador no ha sido TITULAR o SUPLENTE");
		num.value="0";
	}
}

function fn_partidos_jugado(i) {
	nombre=i.id;
	valor=i.value;
	long_valor=valor.length;
	no_num=0;
	for(i=0;i<long_valor;i++){
		letra=valor.substring(i,i+1);
		if(letra.search(/\W/)!=-1){
			no_num=1;
		}
		if(letra.search(/\D/)!=-1){
			no_num=1;
		}
	}
	if (no_num==1) {	
		alert("No es un número");
		document.getElementById(nombre).value="0";
	}
	if (document.getElementById(nombre).value!=0){
		long=nombre.length;
		num=nombre.substring(long-1,long);
		document.getElementById("partido"+num).selectedIndex="1";
	}
}


