var xmlData=null;
var xmlFich='equipXML.php?rand='+Math.random();
var despUniAbierto=-1;
var tipoJugador=0;
var unidades0=0;
var unidades1=0;
var unidades2=0;
var opcionActiva0=0;
var opcionActiva1=0;
var opcionActiva2=0;
var marcaActiva0=0;
var marcaActiva1=0;
var marcaActiva2=0;
var productos0=new Array(0,0,0);
var productos1=new Array(0,0,0);
var productos2=new Array(0,0,0);
var promos0=new Array(0,0,0);
var promos1=new Array(0,0,0);
var promos2=new Array(0,0,0);
var equipaciones0=0;
var equipaciones1=0;
var equipaciones2=0;
var tNoSerif=null;
var colSerif1=null;
var esperaFoto=0;
var serifData='';
var imgPatro='';
var yaImagenPatro=0;
var tipoIni=-1;
var totalPedido=0;
var gastoReembolso=0;
var gastosEnvio=0;
var envioGratis=0;
var gastosProv=new Array();
var formaPago=1;
var formaRecogida=1;
var famProd=null;
var famAct=0;
var pagAct=0;
var porcCR=0;
var minCR=0;
var maxCR=0;
var minImpEnvioGratis=0;
var provNoGratis=new Array(7,35,38,51,52);

function checkEnvCom()
{
	if(document.fCom.nombre.value=='' ||  document.fCom.mensaje.value=='')
	{
		alert('Por favor, rellena todos los campos del formulario para continuar');
		return;
	}
	document.fCom.submit();
}
function initEquip3()
{
	document.getElementById('transC16').innerHTML=document.getElementById('contEnvia').innerHTML;
	document.getElementById('contEnvia').innerHTML='';
	document.getElementById('transC18').style.top='600px';
}
function checkEnvAm()
{
	if(document.getElementById('envNombre').value=='' ||  document.getElementById('envMsg').value=='' ||  document.getElementById('envEm').value=='')
	{
		alert('Por favor, rellena todos los campos del formulario para continuar');
		return;
	}
	var t=document.getElementById('contButEnvAm');
	t.old=t.innerHTML;
	t.innerHTML="<span class='loading'> Enviando...</span>";
	document.getElementById('fEnv1').submit();
}

function finEnvAmi(v)
{
	var t=document.getElementById('contButEnvAm');
	t.innerHTML=t.old;
	cierrapopEnvia(v);
}
function miDebug()
{
	//var cad="tipoJugador: "+tipoJugador+'<br />uJugador: '+uJugador+'<br />uPortero: '+uPortero+'<br />despUniAbierto: '+despUniAbierto+'<br />marcaActivaJ: '+marcaActivaJ+'<br />opcionActivaJ: '+opcionActivaJ+'<br />marcaActivaP: '+marcaActivaP+'<br />opcionActivaP: '+opcionActivaP+'<br />equipIniciada: '+equipIniciada+'<br />productosJ: '+productosJ+'<br />productosP: '+productosP+'<br />productosJ2: '+productosJ2+'<br />productosP2: '+productosP2+'<br />equipJ: '+equipJ+'<br />equipP: '+equipP;
	var cad="tipoJugador: "+tipoJugador+'<br />unidades0: '+unidades0+'<br />unidades1: '+unidades1+'<br />unidades2: '+unidades2+'<br />despUniAbierto: '+despUniAbierto+'<br />opcionActiva0: '+opcionActiva0+'<br />opcionActiva1: '+opcionActiva1+'<br />opcionActiva2: '+opcionActiva2+'<br />marcaActiva0: '+marcaActiva0+'<br />marcaActiva1: '+marcaActiva1+'<br />marcaActiva2: '+marcaActiva2+'<br />productos0: '+productos0+'<br />productos1: '+productos1+'<br />productos2: '+productos2+'<br />promos0: '+promos0+'<br />promos1: '+promos1+'<br />promos2: '+promos2+'<br />equipaciones0: '+equipaciones0+'<br />equipaciones1: '+equipaciones1+'<br />equipaciones2: '+equipaciones2+'<br />tNoSerif: '+tNoSerif;
	document.getElementById('K_debug').innerHTML=cad;
}


function initOfertas()
{
	K_loadAJAX(K_mainPath+'ajax/cargaFamCatal.php','resCargaFamCatal');
}

function resCargaFamCatal(xmlDoc)
{
	famProd=xmlDoc;
	ponFamilia(0);
}
function ponFamilia(carga)
{
	var cad="<div style='padding:5px;font-weight:bold;line-height:18px'>";
	var e=famProd.getElementsByTagName('f');
	
	for (var x=0;x<e.length;++x)
	{
		//if(famAct==0)famAct=e[x].getAttribute('i');
		cad+="<div style='";
		if(famAct==e[x].getAttribute('i')) cad+="color:#FF5C00;";
		cad+="cursor:pointer;cursor:hand' onclick='cambiaFamilia("+(e[x].getAttribute('i')*1)+")'>"+e[x].firstChild.data+'</div>';
	}
	cad+="</div>";
	document.getElementById('contFamilias').innerHTML=cad;

	var fam=0;
	var pag=0;
	fam=famAct;pag=pagAct;
	if(carga)
		K_loadAJAX(K_mainPath+'ajax/cargaProdFam.php?fam='+fam+'&offset='+(pag*8),'resCargaProdFam');
}
function resCargaProdFam(xmlDoc)
{
	var pag=0;
	var cad="<table style='margin:10px;margin-bottom:0px;width:570px' class='df'><tr><td style='font-size:20px;font-weight:bold;color:#FF5C00'>";
	var e=famProd.getElementsByTagName('f');
	pag=pagAct;
	
	for (var x=0;x<e.length;++x)
	{
		if(famAct==e[x].getAttribute('i'))
		{
			cad+=e[x].firstChild.data;
			break;
		}
	}
	cad+="</td><td align='right' style='font-size:12px;font-weight:bold;'>";
	var total=xmlDoc.getElementsByTagName('data')[0].getAttribute('t')*1;
	var t=Math.ceil(total/8);

	if(pag>0)
		cad+="<a style='color:#000;text-decoration:none' href='#' onclick='pagAct="+(pagAct-1)+";ponFamilia(1);return false;'>Anterior</a>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;";
	else cad+="<span style='color:#BBBEBE'>Anterior</span>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;";

	cad+="<span style='color:#FF5C00'>Página "+(pag+1)+" </span>/ "+t+'&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;';

	if(pag<t-1)
		cad+="<a style='color:#000;text-decoration:none' href='#' onclick='pagAct="+(pagAct+1)+";ponFamilia(1);return false;'>Siguiente</a>";
	else cad+="<span style='color:#BBBEBE'>Siguiente</span>";
	cad+="</td></tr></table>";
	var pag=cad;
	cad+="<table style='margin-top:18px;background:#DDDEDE;' width='100%' cellpadding='5' cellspacing='0' class='df'>";
	var e=xmlDoc.getElementsByTagName('p');
	for (var x=0;x<e.length;++x)
	{
		var id=e[x].getAttribute('i')*1;
		cad+="<tr><td width='74'><img src='"+e[x].getElementsByTagName('f')[0].firstChild.data+"' style='margin-left:7px;border:1px solid #FFF;cursor:pointer;cursor:hand;'  onclick=\"descProd("+id+")\"/></td><td style='cursor:pointer;cursor:hand;' onclick=\"descProd("+id+")\"><b>"+e[x].getElementsByTagName('n')[0].firstChild.data+"</b><br />"+e[x].getElementsByTagName('d')[0].firstChild.data+"</td><td align='center' style='border-left:1px solid #FFF' width='100'>";
		
		var p=e[x].getAttribute('p')*1;
		var pp=e[x].getAttribute('pp')*1;
		
		if(parseInt(p)>0)
			cad+="<b>Precio: <span style='text-decoration:line-through'>"+number_format(p,2,',','.')+" &euro;</span></b><br /><b style='color:#FF5C00'>Oferta: "+number_format(pp,2,',','.')+" &euro;</b>";
		else cad+="<b style='color:#FF5C00'>Precio: <span>"+number_format(pp,2,',','.')+" &euro;</span></b>";
		cad+="</td><td align='right' width='90' align='center' style='border-left:1px solid #FFF'><img id='Ana"+id+"off' src='img/botAnaoff2.png' onmouseover=\"this.style.display='none';document.getElementById('Ana"+id+"on').style.display='block';\"/><img src='img/botAnaon2.png' id='Ana"+id+"on' style='display:none;cursor:pointer;cursor:hand' onmouseout=\"this.style.display='none';document.getElementById('Ana"+id+"off').style.display='block';\" onclick=\"descProd("+id+")\"/></td></tr><tr><td colspan='4' style='height:10px;background:#FFF'></td></tr>";
	}
	cad+="</table>"+pag;

	document.getElementById('principal').innerHTML=cad;
}
function cambiaFamilia(val)
{
	famAct=val;
	pagAct=0;
	ponFamilia(1);
}

function nif(dni) {
dni=dni.toUpperCase();
  numero = dni.substr(0,dni.length-1);
  let = dni.substr(dni.length-1,1);
  numero = numero % 23;
  letra='TRWAGMYFPDXBNJZSQVHLCKET';
  letra=letra.substring(numero,numero+1);
  if (letra!=let)
  		return false;
  	else return true; 
}
 function validarCIF(texto){
        
        var pares = 0;
        var impares = 0;
        var suma;
        var ultima;
        var unumero;
        var uletra = new Array("J", "A", "B", "C", "D", "E", "F", "G", "H", "I");
        var xxx;
        
        texto = texto.toUpperCase();
        
        var regular = new RegExp(/^[ABCDEFGHKLMNPQS]\d\d\d\d\d\d\d[0-9,A-J]$/g);
         if (!regular.exec(texto)) return false;
             
         ultima = texto.substr(8,1);

         for (var cont = 1 ; cont < 7 ; cont ++){
             xxx = (2 * parseInt(texto.substr(cont++,1))).toString() + "0";
             impares += parseInt(xxx.substr(0,1)) + parseInt(xxx.substr(1,1));
             pares += parseInt(texto.substr(cont,1));
         }
         xxx = (2 * parseInt(texto.substr(cont,1))).toString() + "0";
         impares += parseInt(xxx.substr(0,1)) + parseInt(xxx.substr(1,1));
         
         suma = (pares + impares).toString();
         unumero = parseInt(suma.substr(suma.length - 1, 1));
         unumero = (10 - unumero).toString();
         if(unumero == 10) unumero = 0;
         
         if ((ultima == unumero) || (ultima == uletra[unumero]))
             return true;
         else
             return false;

    } 
function checkEnviaPedido()
{
	if(document.enviaPedido.nombre.value=='' || document.enviaPedido.apellidos.value=='' || document.enviaPedido.nif.value=='' || document.enviaPedido.direccion.value=='' || document.enviaPedido.poblacion.value=='' || document.enviaPedido.cp.value=='' || document.enviaPedido.provincia.value=='' || document.enviaPedido.email.value=='' || document.enviaPedido.telefono.value=='')
	{
		alert('Por favor, rellena todos los datos de envío.\r\n\r\nSon imprescindibles para garantizar el correcto envío de tu pedido');
		return;
	}

	if(document.enviaPedido.telefono.value.length!=9 || isNaN (document.enviaPedido.telefono.value.length))
	{
		alert('Por favor, comprueba que el número de teléfono en los datos de envío consta de 9 dígitos sin espacios ni letras');
		return;
	}

	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   if(reg.test( document.enviaPedido.email.value) == false)
   {
   	alert('El email de los datos de envío parece incorrecto. Por favor, revisalo');
   	return;
   } 
   
   if(!nif(document.enviaPedido.nif.value) && ! validarCIF(document.enviaPedido.nif.value))
   {
   	alert('El NIF/CIF introducido en los datos de envio es incorrecto.\r\n\r\nPor favor, escribelo sin espacios ni caracteres no alfanumericos');
   	return;
   }
	
	if(document.getElementById('hayDatosFac').checked==true)
	{
		if(document.enviaPedido.nombre2.value=='' || document.enviaPedido.nif2.value=='' || document.enviaPedido.direccion2.value=='' || document.enviaPedido.poblacion2.value=='' || document.enviaPedido.cp2.value=='' || document.enviaPedido.provincia2.value=='' || document.enviaPedido.email2.value=='' || document.enviaPedido.telefono2.value=='')
		{
			alert('Por favor, rellena todos los datos de facturación.\r\n\r\nSon imprescindibles para poder emitir la factura');
			return;
		}	
		if(document.enviaPedido.telefono2.value.length!=9 || isNaN (document.enviaPedido.telefono2.value.length))
		{
			alert('Por favor, comprueba que el número de teléfono en los datos de facturación consta de 9 dígitos sin espacios ni letras');
			return;
		}
	
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	   if(reg.test( document.enviaPedido.email2.value) == false)
	   {
	   	alert('El email de los datos de facturación parece incorrecto. Por favor, revisalo');
	   	return;
	   }
	   if(!nif(document.enviaPedido.nif2.value) && ! validarCIF(document.enviaPedido.nif2.value))
   {
   	alert('El NIF/CIF introducido en los datos de envio es incorrecto.\r\n\r\nPor favor, escribelo sin espacios ni caracteres no alfanumericos');
   	return;
   } 				
	}
	if(document.enviaPedido.acepta.checked==false)
	{
		alert('Para enviar el pedido debes aceptar la Política de confidencialidad de datos personales');
		return;
	}
	document.enviaPedido.submit();
}
function checkEnviaPedido2()
{
	if(document.enviaPedido.nombre.value=='' || document.enviaPedido.apellidos.value=='' || document.enviaPedido.nif.value=='' || document.enviaPedido.direccion.value=='' || document.enviaPedido.poblacion.value=='' || document.enviaPedido.cp.value=='' || document.enviaPedido.provExt.value=='' ||document.enviaPedido.paisExt.value=='' || document.enviaPedido.email.value=='' || document.enviaPedido.telefono.value=='')
	{
		alert('Por favor, rellena todos los datos de envío.\r\n\r\nSon imprescindibles para garantizar el correcto envío de tu pedido');
		return;
	}

	if(document.enviaPedido.telefono.value.length!=9 || isNaN (document.enviaPedido.telefono.value.length))
	{
		alert('Por favor, comprueba que el número de teléfono en los datos de envío consta de 9 dígitos sin espacios ni letras');
		return;
	}

	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   if(reg.test( document.enviaPedido.email.value) == false)
   {
   	alert('El email de los datos de envío parece incorrecto. Por favor, revisalo');
   	return;
   } 

	
	if(document.getElementById('hayDatosFac').checked==true)
	{
		if(document.enviaPedido.nombre2.value=='' || document.enviaPedido.nif2.value=='' || document.enviaPedido.direccion2.value=='' || document.enviaPedido.poblacion2.value=='' || document.enviaPedido.cp2.value=='' || document.enviaPedido.provExt2.value=='' ||document.enviaPedido.paisExt2.value=='' || document.enviaPedido.email2.value=='' || document.enviaPedido.telefono2.value=='')
		{
			alert('Por favor, rellena todos los datos de facturación.\r\n\r\nSon imprescindibles para poder emitir la factura');
			return;
		}			
		
		if(document.enviaPedido.telefono2.value.length!=9 || isNaN (document.enviaPedido.telefono2.value.length))
		{
			alert('Por favor, comprueba que el número de teléfono en los datos de facturación consta de 9 dígitos sin espacios ni letras');
			return;
		}

	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   if(reg.test( document.enviaPedido.email2.value) == false)
   {
   	alert('El email de los datos de facturación parece incorrecto. Por favor, revisalo');
   	return;
   } 
	}
	if(document.enviaPedido.acepta.checked==false)
	{
		alert('Para enviar el pedido debes aceptar la Política de confidencialidad de datos personales');
		return;
	}
	document.enviaPedido.submit();
}
function checkDatosFac()
{
	if (document.getElementById('hayDatosFac').checked==true)
	{
		document.getElementById('datosFac').style.display='block';
		window.location.href='#datFac';
	}
	else document.getElementById('datosFac').style.display='none';
}
function actPrecioMP()
{
	var ge=gastosEnvio;
	if(envioGratis==1  && !in_array(document.getElementById('selProv').value,provNoGratis)) 
		ge=0;
	if(formaRecogida==0)
	{
		ge=0;
		document.getElementById('contGE').innerHTML='';
	}
	else
	{
		if(envioGratis==1 && !in_array(document.getElementById('selProv').value,provNoGratis))
		{
			document.getElementById('contGE').innerHTML='(envío gratuito a Península, tu compra supera '+minImpEnvioGratis+' &euro;)';
		}
		else
		{
			if(gastosEnvio>0)
				document.getElementById('contGE').innerHTML='('+(gastosEnvio*1)+' &euro;)';
			else document.getElementById('contGE').innerHTML='(coste según destino)';
		}
	}
	if(formaPago==1)
		document.getElementById('totalPrecio').innerHTML=number_format(totalPedido+ge,2,',','.')+' &euro;';
	else document.getElementById('totalPrecio').innerHTML=number_format(totalPedido+ge+gastoReembolso,2,',','.')+' &euro;';	
}
function cambiaRecogida(val)
{
	formaRecogida=val;
	if(val==0)
	{
		if(document.getElementById('radioReem'))
		{
			if(document.getElementById('radioReem').checked==true)
			{
				document.getElementById('radioTjt').checked=true;
				document.getElementById('radioReem').checked=false;
				cambiaFormaPago(1);
			}
			document.getElementById('radioReem').disabled=true;
		}
	}
	else
	{
		if(document.getElementById('radioReem'))
			document.getElementById('radioReem').disabled=false;
	}
	
	actPrecioMP();
}
function cambiaProvincia(id)
{
	gastosEnvio=gastosProv[id];
	actPrecioMP();
}
function cambiaFormaPago(val)
{
	formaPago=val;
	actPrecioMP();
}
function descProd(id)
{
	K_loadAJAX(K_mainPath+'ajax/cargaDatProd.php?id='+id,'resCargaDatProd');
	document.getElementById('transC18').innerHTML="<br /><br /><br /><br /><br /><div style='width:100px;margin-left:150px' align='center' class='loading'>Cargando datos...</div>";
	popDesc();
}
function resCargaDatProd(xmlDoc)
{
	var e=xmlDoc.getElementsByTagName('p')[0];
	var cad="<img src='img/cerrar.png' style='position:absolute;right:3px;top:3px;cursor:pointer;cursor:hand' onclick='cierrapopDesc()'/><br /><table width='100%' class='df' cellpadding='5' cellspacing='0' style='line-height:17px'><tr valign='top'><td align='center' width='200'><img style='border:1px solid #FF5C00' src='img_admin/"+e.getElementsByTagName('f')[0].firstChild.data+"'/></td><td><b>"+e.getElementsByTagName('n')[0].firstChild.data+"</b><br /><b>Ref:</b> "+e.getAttribute('r')+"<br /><b style='color:#FF5C00'>Precio: &nbsp;&nbsp;";
	if(parseInt(e.getAttribute('pa'))>0)
		cad+="<span style='text-decoration:line-through;color:#000'>"+number_format(e.getAttribute('pa'),2,',','.')+" &euro;</span> &nbsp;&nbsp;";
	cad+=number_format(e.getAttribute('p'),2,',','.')+" &euro;</b><br /><b>Color:</b> "+e.getElementsByTagName('c')[0].firstChild.data;
	var vari=e.getElementsByTagName('v')[0].firstChild.data;
	if(vari!='')
		cad+="<br /><b>"+vari+'</b>';
	var pr=xmlDoc.getElementsByTagName('pr');
	if(pr.length>0)
	{
		cad+="<div style='margin-top:5px;'><b>También disponible en:</b><br />";
		for (var y=0;y<pr.length;++y)
			cad+="<a href='#' style='text-decoration:none' onclick=\"K_loadAJAX('"+K_mainPath+"ajax/cargaDatProd.php?id="+pr[y].getAttribute('id')+"','resCargaDatProd');return false;\">"+pr[y].firstChild.data+'</a><br />';
		cad+="</div>";
	}
	
	cad+="<table class='df' align='right' style='margin-top:8px;'><tr valign='top'><td><b>Talla: </b><select class='df' id='selProdTalla'>";
	var t=xmlDoc.getElementsByTagName('t');
	for (var x=0;x<t.length;++x)
		cad+="<option value='"+t[x].getAttribute('id')+"'>"+t[x].firstChild.data+"</option>";
	cad+="</select>&nbsp;&nbsp;&nbsp;&nbsp;</td><td><b>Unidades: </b><input type='text' id='selProdUni' class='df' onkeyup='checkNum2b(this.id)' size='2' value='1'/>&nbsp;&nbsp;&nbsp;&nbsp;</td><td>";
	cad+="<div align='right' id='contBotSelProd'><img id='Prodoff' src='img/botAnaoff2.png' onmouseover=\"this.style.display='none';document.getElementById('Prodon').style.display='block';\"/><img src='img/botAnaon2.png' id='Prodon' style='display:none;cursor:pointer;cursor:hand' onmouseout=\"this.style.display='none';document.getElementById('Prodoff').style.display='block';\" onclick=\"aniadeProd("+e.getAttribute('id')+","+(e.getAttribute('p')*1)+")\"/></div></td></tr></table>";
	cad+="</td></tr></table><br />&nbsp;&nbsp;<span style='color:#FF5C00'><a href='#' onclick=\"document.getElementById('selProdTalla').style.display='none';document.getElementById('contTallaje').style.display='block';return false;\">Consultar las tablas de conversi&oacute;n de tallas</a></span>";
	document.getElementById('transC18').innerHTML=cad;
}

function aniadeProd(id,precio)
{
	var talla=document.getElementById('selProdTalla').value;
	var unidades=document.getElementById('selProdUni').value;
	if(isNaN(unidades) ||unidades=='')
	{
		alert('Por favor, introduce el número de unidades que deseas comprar');
		return;
	}
	totalCesta+=precio*unidades;
	document.getElementById('totalPrecio').innerHTML=number_format(totalCesta,2,',','.')+' &euro;';
	document.getElementById('contBotSelProd').innerHTML="<span class='loading'>Enviando...</span>";
	//console.info('ajax/aniadeProd.php?id='+id+'&cantidad='+unidades+'&talla='+talla);
	document.getElementById('linkCompra').className='menu2On';
	document.getElementById('imgCompra').src='img/carrito.png';
	
	K_loadAJAX(K_mainPath+'ajax/aniadeProd.php?id='+id+'&cantidad='+unidades+'&talla='+talla,'resAniadeProd');
}
function resAniadeProd(xmlDoc)
{
	var p=window.location.href.split('/');
	if(p[p.length-1]=='equipacion3.php')
		window.location.href='equipacion3.php';
	else cierrapopDesc();
}
function borraProd(id)
{
	if(confirm('¿Seguro que deseas quitar este producto de la cesta?'))
		document.getElementById('ifc').src='ajax/borraProd.php?id='+id;
}
function initEquip()
{
	//setInterval('miDebug()',500);
	K_loadAJAX(K_mainPath+'ajax/'+xmlFich,'resInitEquip');
}

function initDatos()
{
	unidades0=xmlData.getElementsByTagName('data')[0].getElementsByTagName('uni0')[0].firstChild.data*1;
	unidades1=xmlData.getElementsByTagName('data')[0].getElementsByTagName('uni1')[0].firstChild.data*1;
	unidades2=xmlData.getElementsByTagName('data')[0].getElementsByTagName('uni2')[0].firstChild.data*1;
	opcionActiva0=xmlData.getElementsByTagName('data')[0].getElementsByTagName('oa0')[0].firstChild.data*1;
	opcionActiva1=xmlData.getElementsByTagName('data')[0].getElementsByTagName('oa1')[0].firstChild.data*1;
	opcionActiva2=xmlData.getElementsByTagName('data')[0].getElementsByTagName('oa2')[0].firstChild.data*1;
	marcaActiva0=xmlData.getElementsByTagName('data')[0].getElementsByTagName('ma0')[0].firstChild.data*1;
	marcaActiva1=xmlData.getElementsByTagName('data')[0].getElementsByTagName('ma1')[0].firstChild.data*1;
	marcaActiva2=xmlData.getElementsByTagName('data')[0].getElementsByTagName('ma2')[0].firstChild.data*1;
	var p=xmlData.getElementsByTagName('data')[0].getElementsByTagName('p0')[0].firstChild.data.split(',');
	productos0=new Array(p[0],p[1],p[2]);
	var p=xmlData.getElementsByTagName('data')[0].getElementsByTagName('p1')[0].firstChild.data.split(',');
	productos1=new Array(p[0],p[1],p[2]);
	var p=xmlData.getElementsByTagName('data')[0].getElementsByTagName('p2')[0].firstChild.data.split(',');
	productos2=new Array(p[0],p[1],p[2]);
	var p=xmlData.getElementsByTagName('data')[0].getElementsByTagName('pp0')[0].firstChild.data.split(',');
	promos0=new Array(p[0],p[1],p[2]);
	var p=xmlData.getElementsByTagName('data')[0].getElementsByTagName('pp1')[0].firstChild.data.split(',');
	promos1=new Array(p[0],p[1],p[2]);
	var p=xmlData.getElementsByTagName('data')[0].getElementsByTagName('pp2')[0].firstChild.data.split(',');
	promos2=new Array(p[0],p[1],p[2]);
	equipaciones0=xmlData.getElementsByTagName('data')[0].getElementsByTagName('eq0')[0].firstChild.data*1;
	equipaciones1=xmlData.getElementsByTagName('data')[0].getElementsByTagName('eq1')[0].firstChild.data*1;
	equipaciones2=xmlData.getElementsByTagName('data')[0].getElementsByTagName('eq2')[0].firstChild.data*1;
	tNoSerif=xmlData.getElementsByTagName('tNoSerif')[0].firstChild.data.split(';');
	var e=xmlData.getElementsByTagName('serif')[0];
	serifData=e.firstChild.data;
	imgPatro=e.getAttribute('img');	
}
function resInitEquip(xmlDoc)
{
	xmlData=xmlDoc;
	initDatos();
	var cad='&nbsp;';
	if(unidades0<10)cad+='0';
	cad+=unidades0+' uds.';
	if(unidades0==0) cad='&nbsp;Ninguno';
	document.getElementById('desp'+0).innerHTML=cad;
	
	var cad='&nbsp;';
	if(unidades1<10)cad+='0';
	cad+=unidades1+' uds.';
	if(unidades1==0) cad='&nbsp;Ninguno';
	document.getElementById('desp'+1).innerHTML=cad;
	
	var cad='&nbsp;';
	if(unidades2<10)cad+='0';
	cad+=unidades2+' uds.';
	if(unidades2==0) cad='&nbsp;Ninguno';
	document.getElementById('desp'+2).innerHTML=cad;
		
	document.getElementById('nomequip').value=xmlData.getElementsByTagName('data')[0].getElementsByTagName('n')[0].firstChild.data;
	calculaPrecio(0);
	if(tipoIni)
		cambiaTipoJugador(tipoIni);
}

function initEquip2()
{
	//setInterval('miDebug()',500);
	K_loadAJAX(K_mainPath+'ajax/'+xmlFich,'resInitEquip2');
}
function resInitEquip2(xmlDoc)
{
	xmlData=xmlDoc;
	initDatos();
	calculaPrecio(1);
}
function borraEquip(orden)
{
	if(confirm('¿Seguro que deseas quitar esta equipación del pedido?\r\n\r\n(Seguirá estando disponible en tu área de cliente)'))
		document.getElementById('ifc').src='quitaEquip.php?orden='+orden;
}
function borraEquip2(orden)
{
	if(confirm('¿Seguro que deseas quitar esta equipación del pedido?\r\n\r\nEsta operación no se puede deshacer'))
		document.getElementById('ifc').src='quitaEquip.php?orden='+orden;
}
function borraEquip3(id)
{
	if(confirm('¿Seguro que deseas eliminar esta equipación?\r\n\r\nEsta operación no se puede deshacer'))
		document.getElementById('ifc').src='borraEquip.php?id='+id;
}
function checkSelSerifNoSerif()
{
	var tx=new Array('jugador', 'portero 1','portero 2');
	var nombre=document.getElementById('nomequip').value;
	if(nombre=='')
	{
		alert('Por favor, escribe un nombre para esta equipación');
		document.getElementById('nomequip').focus();
		return 0;
	}
	if(unidades0==0 && unidades1==0 && unidades2==0)
	{
		alert('Por favor, selecciona al menos una unidad de jugador o portero para continuar');
		return 0;
	}
	if(opcionActiva0==0 && unidades0>0)
	{
		alert('Por favor, selecciona alguna equipación de jugador para continuar');
		return 0;
	}
	if(opcionActiva1==0 && unidades1>0)
	{
		alert('Por favor, selecciona alguna equipación de portero tipo 1 para continuar');
		return 0;
	}
	if(opcionActiva2==0 && unidades2>0)
	{
		alert('Por favor, selecciona alguna equipación de portero tipo 2 para continuar');
		return 0;
	}
	
	for(var x=0;x<3;++x)
	{
		if(window['opcionActiva'+x]==0 && window['unidades'+x])
		{
			alert('Por favor, selecciona alguna equipación de '+tx[x]+' para continuar');
			return 0;
		}
		if(window['opcionActiva'+x]==2 && window['unidades'+x])
		{
			if(window['productos'+x][0]==0 && window['productos'+x][1]==0 &&window['productos'+x][2]==0)
			{
				var cad='';
				if(x==0) cad='Por favor, selecciona alguna equipación de jugador para continuar';
				if(x==1) cad='Por favor, selecciona alguna equipación de portero tipo 1 para continuar';
				if(x==2) cad='Por favor, selecciona alguna equipación de portero tipo 2 para continuar';
				alert(cad);
				return 0;
			}
		}
		if(window['opcionActiva'+x]==3 && window['unidades'+x])
		{
			if(window['promos'+x][0]==0 || window['promos'+x][1]==0 || window['promos'+x][2]==0)
			{
				var cad='';
				if(x==0) cad='En la equipacion de jugador has escogido productos de promocion.\r\n\r\nPara poder disfrutar de los precios de promocion debes seleccionar una prenda de cada tipo.\r\n\r\nPuedes comprarlo por separado en la sección de "camiseta, pantalón y medias" si lo prefieres.';
				if(x==1) cad='En la equipacion de portero tipo 1 has escogido productos de promocion.\r\n\r\nPara poder disfrutar de los precios de promocion debes seleccionar una prenda de cada tipo.\r\n\r\nPuedes comprarlo por separado en la sección de "camiseta, pantalón y medias" si lo prefieres.';
				if(x==2) cad='En la equipacion de portero tipo 2 has escogido productos de promocion.\r\n\r\nPara poder disfrutar de los precios de promocion debes seleccionar una prenda de cada tipo.\r\n\r\nPuedes comprarlo por separado en la sección de "camiseta, pantalón y medias" si lo prefieres.';
				alert(cad);
				return 0;
			}
		}		
	}
	return 1;
}
function abreSerif_()
{
	if(!checkSelSerifNoSerif())
		return;
	var hayCami=0;
	if(equipaciones0>0 && unidades0>0)hayCami=1;if(equipaciones1>0 && unidades1>0)hayCami=1;if(equipaciones2>0 && unidades2>0)hayCami=1;
	if(productos0[0]>0 && unidades0>0)hayCami=1;if(productos1[0]>0 && unidades1>0)hayCami=1;if(productos2[0]>0 && unidades2>0)hayCami=1;
	if(promos0[0]>0 && unidades0>0)hayCami=1;if(promos1[0]>0 && unidades1>0)hayCami=1;if(promos2[0]>0 && unidades2>0)hayCami=1;
	
	var hayPant=0;
	if(equipaciones0>0 && unidades0>0)hayPant=1;if(equipaciones1>0 && unidades1>0)hayPant=1;if(equipaciones2>0 && unidades2>0)hayPant=1;
	if(productos0[1]>0 && unidades0>0)hayPant=1;if(productos1[1]>0 && unidades1>0)hayPant=1;if(productos2[1]>0 && unidades2>0)hayPant=1;
	if(promos0[1]>0 && unidades0>0)hayPant=1;if(promos1[1]>0 && unidades1>0)hayPant=1;if(promos2[1]>0 && unidades2>0)hayPant=1;
	
	if(!hayCami && !hayPant)
	{
		alert('Para poder pedir tu equipación con serigrafía debes seleccionar camisetas y/o pantalones');
		return;
	}

	var colores=xmlData.getElementsByTagName('colSerif');
	var precios=xmlData.getElementsByTagName('pSerif')[0];

	var colSerif=xmlData.getElementsByTagName('colSerif');
	
	var cad="<img src='img/encPatro.png'/><div style='position:absolute;right:9px;top:9px;font-size:9px;color:#FFF;font-weight:bold;cursor:pointer;cursor:hand' onclick='cierrapopSerigrafia()'>Cerrar <img src='img/cerrar.png' align='absmiddle'/></div><div style='margin:18px'><b>El vinilo de primera calidad utilizado en nuestras equipaciones (&ldquo;Filmtex&rdquo;), es impreso a una temperatura de 180º en cualquier material, es elástico, imperceptible al tacto y de larga durabilidad.<br /><span style='color:#FF5C00'>Puede ser lavado sin riesgos de deterioro.</span></b></div>";
	
	
	cad+="<div id='contSerif1' style='width:628px;margin:10px;border:1px solid #FF5C00;";
	var col='';
	var check='';
	var num=0;
	var p=serifData.split(';');
	for(var z=0;z<p.length;++z)
	{
		var pp=p[z].split('#@#');
		if(pp[0]==1)
		{
			col="background:#FFDE8D";
			check="checked='checked'";
			num=pp[1];
			break;
		}
	}
	cad+=col+"'><table width='100%' class='df' cellpadding='5' cellspacing='0'><tr valign='top'><td width='120'><img src='img/serif1.png'/></td><td width='10'><input type='checkbox' id='tipoSerif1' onclick='serif(1)' "+check+"/></td><td><b>Marca esta opción si quieres poner número en tu camiseta</b><br />(la imagen mostrada es sólo una referencia)<br /><br /><br /><select class='df' id='tipoSerif1Color' ";
	if(!hayCami) cad+=' style="display:none"';
	cad+="><option value=''>Selecciona el color del número</option>";
	for (var x=0;x<colSerif.length;++x)
	{
		cad+="<option value='"+colSerif[x].getAttribute('id')+"'";
		if(colSerif[x].getAttribute('id')*1==num) cad+=" selected='selected'";
		cad+=">"+colSerif[x].firstChild.data+"</option>";
	}
	cad+="</select><br /><br /><br /><div align='right' style='color:#FF5C00'>Números sencillos y dobles al mismo precio  -  <b>PRECIO: "+(precios.getAttribute('n')*1)+"&euro;&nbsp;&nbsp;&nbsp;</b></div></td></tr></table></div>";
	if(!hayCami)
	   cad+="<div id='noDisp1a' style='text-align:center; font-size:40px;color:red;position:absolute;left:10px;top:114px;width:630px;height:134px;background:#FFF;-moz-opacity:0.7;opacity:0.7;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=70);'></div><div id='noDisp1b' style='text-align:center;font-weight:bold;font-size:40px;color:red;position:absolute;left:10px;top:126px;width:629px;height:132px;'>NO DISPONIBLE CON LA SELECCIÓN ACTUAL<br /><span style='font-size:16px'>(Debes seleccionar alguna camiseta)</span></div>";

	
	cad+="<div id='contSerif2' style='width:628px;margin:10px;border:1px solid #FF5C00;";
	col='';
	check='';
	num=0;
	for(var z=0;z<p.length;++z)
	{
		var pp=p[z].split('#@#');
		if(pp[0]==2)
		{
			col="background:#FFDE8D";
			check="checked='checked'";
			num=pp[1];
			break;
		}
	}

	cad+=col+"'><table width='100%' class='df' cellpadding='5' cellspacing='0'><tr valign='top'><td width='120'><img src='img/serif2.png'/></td><td width='10'><input type='checkbox' id='tipoSerif2' onclick='serif(2)' "+check+"/></td><td><b>Marca esta opción si quieres poner nombre y número en tu camiseta</b><br />(la imagen mostrada es sólo una referencia)<br /><br /><br /><select class='df' id='tipoSerif2Color'";
	if(!hayCami) cad+=' style="display:none"';
	cad+="><option value=''>Selecciona el color</option>";
	for (var x=0;x<colSerif.length;++x)
	{
		cad+="<option value='"+colSerif[x].getAttribute('id')+"'";
		if(colSerif[x].getAttribute('id')*1==num) cad+=" selected='selected'";
		cad+=">"+colSerif[x].firstChild.data+"</option>";
	}
	cad+="</select><br /><br /><br /><div align='right' style='color:#FF5C00'>Nombre y números -  <b>PRECIO: "+(precios.getAttribute('nn')*1)+" &euro;&nbsp;&nbsp;&nbsp;</b></div></td></tr></table></div>";
	if(!hayCami)
		cad+="<div id='noDisp2a' style='text-align:center; font-size:40px;color:red;position:absolute;left:10px;top:257px;width:630px;height:133px;background:#FFF;-moz-opacity:0.7;opacity:0.7;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=70);'></div><div id='noDisp2b' style='text-align:center;font-weight:bold;font-size:40px;color:red;position:absolute;left:10px;top:268px;width:629px;height:132px;'>NO DISPONIBLE CON LA SELECCIÓN ACTUAL<br /><span style='font-size:16px'>(Debes seleccionar alguna camiseta)</span></div>";


	cad+="<div id='contSerif3' style='margin:10px;border:1px solid #FF5C00;";
	col='';
	check='';
	num=0;
	for(var z=0;z<p.length;++z)
	{
		var pp=p[z].split('#@#');
		if(pp[0]==3)
		{
			col="background:#FFDE8D";
			check="checked='checked'";
			num=pp[1];
			break;
		}
	}	
	cad+=col+"'><table width='100%' class='df' cellpadding='5' cellspacing='0'><tr valign='top'><td width='120'><img src='img/serif3.png'/></td><td width='10'><input type='checkbox' id='tipoSerif3' onclick='serif(3)' "+check+"/></td><td><b>       Marca esta opción si quieres poner número en tu pantalón</b><br />(la imagen mostrada es sólo una referencia)<br /><br /><br /><select class='df' id='tipoSerif3Color'";
	if(!hayPant) cad+=' style="display:none"';
	cad+="><option value=''>Selecciona el color</option>";
	for (var x=0;x<colSerif.length;++x)
	{
		cad+="<option value='"+colSerif[x].getAttribute('id')+"'";
		if(colSerif[x].getAttribute('id')*1==num) cad+=" selected='selected'";
		cad+=">"+colSerif[x].firstChild.data+"</option>";
	}
	cad+="</select><br /><br /><br /><div align='right' style='color:#FF5C00'>Números sencillos y dobles al mismo precio -  <b>PRECIO: "+(precios.getAttribute('np')*1)+" &euro;&nbsp;&nbsp;&nbsp;</b></div></td></tr></table></div>";
	if(!hayPant)
		cad+="<div id='noDisp3a' style='text-align:center; font-size:40px;color:red;position:absolute;left:10px;top:400px;width:630px;height:133px;background:#FFF;-moz-opacity:0.7;opacity:0.7;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=70);'></div><div id='noDisp3b' style='text-align:center;font-weight:bold;font-size:40px;color:red;position:absolute;left:10px;top:413px;width:629px;height:132px;'>NO DISPONIBLE CON LA SELECCIÓN ACTUAL<br /><span style='font-size:16px'>(Debes seleccionar algún pantalón)</span></div>";
	
	
	cad+="<div id='contSerif4' style='width:628px;margin:10px;border:1px solid #FF5C00;";
	var texto='';
	var textoImg='';
	col='';
	var col2='';
	check='';	var check2='';	var check3=''; var check4='';var check5='';
	num=0;
	for(var z=0;z<p.length;++z)
	{
		var pp=p[z].split('#@#');
		if(pp[0]==41)
		{
			col="background:#FFDE8D";
			check="checked='checked'";
			num=pp[2];
			texto=pp[1];
			break;
		}
		if(pp[0]==42)
		{
			col="background:#FFDE8D";
			check2="checked='checked'";
			texto='';
			textoImg=imgPatro;
			num=pp[1];
			break;
		}
		if(pp[0]==43)
		{
			col="background:#FFDE8D";
			check3="checked='checked'";
			num=pp[1];
			break;
		}
		if(pp[0]==51)
		{
			col2="background:#FFDE8D";
			check4="checked='checked'";
			break;
		}
		if(pp[0]==52)
		{
			col2="background:#FFDE8D";
			check5="checked='checked'";
			break;
		}		
	}		
	cad+=col+"'><table width='100%' class='df' cellpadding='5' cellspacing='0'><tr valign='top'><td width='120'><img src='img/serif4.png'/></td><td><b>Si quieres poner la pubicidad de tu patrocinador, elige la forma de envío</b><br />(la imagen mostrada es sólo una referencia)<br /><table class='df' cellpadding='5' cellspacing='0'><tr valign='top'><td><input type='checkbox' id='tipoSerif41' onclick='serif(41)' "+check+"/></td><td>Escribe el texto de tu patrocinador aquí: &nbsp;<input type='text' style='width:210px' id='serif41txt' value='"+texto+"'/></td></tr><tr valign='top'><td><input type='checkbox' id='tipoSerif42' onclick='serif(42)' "+check2+"/></td><td>Selecciona la imagen de tu disco duro: <form action='ajax/subeImagenPatro.php' method='post' id='serifImg' enctype='multipart/form-data' target='ifc'><input type='hidden' name='MAX_FILE_SIZE' value='100000000'/><input type='file' name='foto' id='foto'/></form>";
	if(textoImg==imgPatro && textoImg)
	{
		cad+="<br /><a href='img_patro/"+textoImg+"' target='_blank'>Ver imagen seleccionada</a>";
		yaImagenPatro=1;
	}

	cad+="</td></tr><tr valign='top'><td><input type='checkbox' id='tipoSerif43' onclick='serif(43)' "+check3+"/></td><td>Envía tu imagen al Fax: 91 613 16 72  (adjunta el número de tu pedido)</td></tr></table><div align='right'><table class='df' cellpadding='0' cellspacing='0'><tr><td><select class='df' id='tipoSerif41Color'";
	if(!hayCami) cad+=' style="display:none"';
	cad+="><option value=''>Selecciona el color del patrocinio</option>";
	for (var x=0;x<colSerif.length;++x)
	{
		cad+="<option value='"+colSerif[x].getAttribute('id')+"'";
		if(colSerif[x].getAttribute('id')*1==num) cad+=" selected='selected'";
		cad+=">"+colSerif[x].firstChild.data+"</option>";
	}
	cad+="</select></td><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td style='color:#FF5C00'>Diseño y/o  &ldquo;plancha&rdquo;  - <b>PRECIO:  "+(precios.getAttribute('p')*1)+" €&nbsp;&nbsp;&nbsp;</b><br />Estampación - <b>PRECIO: "+(precios.getAttribute('e')*1)+" &euro;  / unidad&nbsp;&nbsp;&nbsp;</b></td></tr></table></div></td></tr></table></div>";
	if(!hayCami)
		cad+="<div id='noDisp4a' style='text-align:center; font-size:40px;color:red;position:absolute;left:10px;top:543px;width:630px;height:176px;background:#FFF;-moz-opacity:0.7;opacity:0.7;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=70);'></div><div id='noDisp4b' style='text-align:center;font-weight:bold;font-size:40px;color:red;position:absolute;left:10px;top:573px;width:629px;height:132px;'>NO DISPONIBLE CON LA SELECCIÓN ACTUAL<br /><span style='font-size:16px'>(Debes seleccionar alguna camiseta)</span></div>";
	
	
	cad+="<div id='contSerif5' style='width:628px;margin:10px;border:1px solid #FF5C00;"+col2+"'><table width='100%' class='df' cellpadding='5' cellspacing='0'><tr valign='top'><td width='120'><img src='img/serif5.png'/></td><td><b>Si prefieres que futbol factory te patrocine, marca el diseño que más te guste	y consigue un "+(precios.getAttribute('d')*1)+"% de descuento en el precio final. La estampación es gratuita.</b><br /><br /><table width='100%' class='df' cellpadding='3' cellspacing='0'><tr><td><input type='checkbox' id='tipoSerif51' onclick='serif(51)' "+check4+"/></td><td>Opción logotipo de futbol factory</td><td rowspan='2' align='right' style='padding:0;margin:0;font-size:50px;background:#FE5B00;color:#FFF'><b>"+(precios.getAttribute('d')*1)+"%<br /><span style='font-size:14px'>descuento&nbsp;</span></b></td></tr><tr><td><input type='checkbox' id='tipoSerif52' onclick='serif(52)' "+check5+"/></td><td>Opción jugador con balón</td></tr></table></select><br /><div align='right' style='color:#FF5C00'><b>Descuento del "+(precios.getAttribute('d')*1)+"% al elegir esta opción y estampación gratuita. &nbsp;&nbsp;&nbsp;</b></div></td></tr></table></div>";
	if(!hayCami)
		cad+="<div id='noDisp5a' style='text-align:center; font-size:40px;color:red;position:absolute;left:10px;top:728px;width:630px;height:162px;background:#FFF;-moz-opacity:0.7;opacity:0.7;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=70);'></div><div id='noDisp5b' style='text-align:center;font-weight:bold;font-size:40px;color:red;position:absolute;left:10px;top:750px;width:629px;height:132px;'>NO DISPONIBLE CON LA SELECCIÓN ACTUAL<br /><span style='font-size:16px'>(Debes seleccionar alguna camiseta)</span></div>";
	
	cad+="<table width='100%'><tr><td><div align='center' style='margin-top:15px' id='contButEnvSerif'><img id='envSerif2' src='img/continuaroff.png' onmouseover=\"this.style.display='none';document.getElementById('envSerifOn2').style.display='block';\"/><img src='img/continuaron2.png' id='envSerifOn2' style='display:none;cursor:pointer;cursor:hand' onmouseout=\"this.style.display='none';document.getElementById('envSerif2').style.display='block';\" onclick='envSerif()'/></div></td><td><div align='center' style='margin-top:15px'><img id='botCancelRegOff4' src='img/botCancelOff.png' onmouseover=\"this.style.display='none';document.getElementById('botCancelRegOn4').style.display='block';\"/><img src='img/botCancelOn.png' id='botCancelRegOn4' style='display:none;cursor:pointer;cursor:hand' onmouseout=\"this.style.display='none';document.getElementById('botCancelRegOff4').style.display='block';\" onclick='cierrapopSerigrafia()'/></div></td></tr></table></div>";	
	document.getElementById('transC13').innerHTML=cad;
	popSerigrafia();	
}
function serif(val)
{
	if(val==1)
	{
		if(document.getElementById('tipoSerif1').checked==true)
		{
			document.getElementById('tipoSerif2').checked=false;
			document.getElementById('contSerif1').style.background='#FFDE8D';
			document.getElementById('contSerif2').style.background='';
		}
		else
			document.getElementById('contSerif1').style.background='';
	}
	if(val==2)
	{
		if(document.getElementById('tipoSerif2').checked==true)
		{
			document.getElementById('tipoSerif1').checked=false;
			document.getElementById('contSerif2').style.background='#FFDE8D';
			document.getElementById('contSerif1').style.background='';
		}
		else
			document.getElementById('contSerif2').style.background='';
	}
	if(val==3)
	{
		if(document.getElementById('tipoSerif3').checked==true)
			document.getElementById('contSerif3').style.background='#FFDE8D';
		else
			document.getElementById('contSerif3').style.background='';
	}
	if(val==41)
	{
		if(document.getElementById('tipoSerif41').checked==true)
		{
			document.getElementById('contSerif5').style.background='';
			document.getElementById('contSerif4').style.background='#FFDE8D';
			document.getElementById('tipoSerif42').checked=false;
			document.getElementById('tipoSerif43').checked=false;
			document.getElementById('tipoSerif51').checked=false;
			document.getElementById('tipoSerif52').checked=false;
		}
		else document.getElementById('contSerif4').style.background='';
	}
	if(val==42)
	{
		if(document.getElementById('tipoSerif42').checked==true)
		{
			document.getElementById('contSerif5').style.background='';
			document.getElementById('contSerif4').style.background='#FFDE8D';
			document.getElementById('tipoSerif41').checked=false;
			document.getElementById('tipoSerif43').checked=false;
			document.getElementById('tipoSerif51').checked=false;
			document.getElementById('tipoSerif52').checked=false;
		}
		else document.getElementById('contSerif4').style.background='';
	}
	if(val==43)
	{
		if(document.getElementById('tipoSerif43').checked==true)
		{
			document.getElementById('contSerif5').style.background='';
			document.getElementById('contSerif4').style.background='#FFDE8D';
			document.getElementById('tipoSerif42').checked=false;
			document.getElementById('tipoSerif41').checked=false;
			document.getElementById('tipoSerif51').checked=false;
			document.getElementById('tipoSerif52').checked=false;
		}
		else document.getElementById('contSerif4').style.background='';
	}
	if(val==51)
	{
		if(document.getElementById('tipoSerif51').checked==true)
		{
			document.getElementById('contSerif4').style.background='';
			document.getElementById('contSerif5').style.background='#FFDE8D';
			document.getElementById('tipoSerif42').checked=false;
			document.getElementById('tipoSerif43').checked=false;
			document.getElementById('tipoSerif41').checked=false;
			document.getElementById('tipoSerif52').checked=false;
		}
		else document.getElementById('contSerif5').style.background='';
	}
	if(val==52)
	{
		if(document.getElementById('tipoSerif52').checked==true)
		{
			document.getElementById('contSerif4').style.background='';
			document.getElementById('contSerif5').style.background='#FFDE8D';
			document.getElementById('tipoSerif42').checked=false;
			document.getElementById('tipoSerif43').checked=false;
			document.getElementById('tipoSerif41').checked=false;
			document.getElementById('tipoSerif51').checked=false;
		}
		else document.getElementById('contSerif5').style.background='';
	}
}
function envSerif()
{
	var tipo=0;
	var cad='';
	esperaFoto=0;
	if(document.getElementById('tipoSerif1').checked==true)
	{
		tipo=1;
		var color=document.getElementById('tipoSerif1Color').value;
		if(color=='')
		{
			window.scrollBy(0,-1000);
			alert('Por favor, selecciona el color del número');
			return;
		}
		cad+='1#@#'+color+';';
	}
	if(document.getElementById('tipoSerif2').checked==true)
	{
		tipo=2;
		var color=document.getElementById('tipoSerif2Color').value;
		if(color=='')
		{
			window.scrollBy(0,-1000);
			alert('Por favor, selecciona el color del número');
			return;
		}
		cad+='2#@#'+color+';';
	}
	if(document.getElementById('tipoSerif3').checked==true)
	{
		tipo=3;
		var color=document.getElementById('tipoSerif3Color').value;
		if(color=='')
		{
			window.scrollBy(0,-1000);
			alert('Por favor, selecciona el color del número');
			return;
		}
		cad+='3#@#'+color+';';
	}
	if(document.getElementById('tipoSerif41').checked==true)
	{
		tipo=41;
		var texto=document.getElementById('serif41txt').value;
		var color=document.getElementById('tipoSerif41Color').value;
		if(texto=='')
		{
			document.getElementById('serif41txt').focus();
			alert('Por favor, escribe el texto del patrocinio');
			return;
		}
		if(color=='')
		{
			alert('Por favor, selecciona el color del texto del patrocinio');
			return;
		}
		cad+="41#@#"+texto+'#@#'+color+';';
	}
	if(document.getElementById('tipoSerif42').checked==true)
	{
		tipo=42;
		var color=document.getElementById('tipoSerif41Color').value;
		if(color=='')
		{
			alert('Por favor, selecciona el color de la imagen del patrocinio');
			return;
		}
		if(document.getElementById('foto').value=='' && !yaImagenPatro)
		{
			alert('Por favor, selecciona la imagen de patrocinio');
			return;
		}
		cad+="42#@#"+color+";";
		esperaFoto=1;
		document.getElementById('serifImg').submit();
	}
	if(document.getElementById('tipoSerif43').checked==true)
	{
		tipo=43;
		var color=document.getElementById('tipoSerif41Color').value;
		if(color=='')
		{
			alert('Por favor, selecciona el color de la imagen del patrocinio');
			return;
		}
		cad+='43#@#'+color+';';
	}
	if(document.getElementById('tipoSerif51').checked==true)
	{
		tipo=51;
		cad+='51;';
	}
	if(document.getElementById('tipoSerif52').checked==true)
	{
		tipo=52;
		cad+='52;';
	}
	if(tipo==0)
	{
		alert('Por favor, selecciona alguna de las opciones de serigrafía');
		return;
	}
	var t=document.getElementById('contButEnvSerif');
	t.old=t.innerHTML;
	t.innerHTML="<span class='loading'> Enviando datos...</span>";
	K_loadAJAX(K_mainPath+'ajax/cambiaSerif.php?data='+escape(cad)+'&nombre='+escape(document.getElementById('nomequip').value),'resEnvSerif');
}
function finSubeFoto()
{
	var t=document.getElementById('contButEnvSerif');
	t.innerHTML=t.old;
	esperaFoto=0;
	resEnvSerif();
}
function resEnvSerif(xmlDoc)
{
	if(esperaFoto==0)
	{
		window.location.href='equipacion2.php';
	}
}
function abreNoSerif()
{
	if(checkSelSerifNoSerif())
		K_loadAJAX(K_mainPath+'ajax/tallasNoSerif.php','resAbreNoSerif');
}

function resAbreNoSerif(xmlDoc)
{
	var txZ=new Array('CAMISETAS','PANTALONES','MEDIAS');
	var aZ=new Array('C','P','M');
	var aZ2=new Array('C2','P2','M2');
	var cad="<form action='equipacion3.php' method='post' id='fNoSerif'><input type='hidden' name='accion' value='noSerif'/><input type='hidden' name='nombre' value=''/><img src='img/encNoSerif.png'/><div style='position:absolute;right:9px;top:9px;cursor:pointer;cursor:hand;color:#FFF;font-weight:bold;font-size:9px;' onclick='cierrapopNoSerigrafia()'>Cerrar <img src='img/cerrar.png' align='absmiddle'/></div><div style='margin:18px'><b>Selecciona el número de camisetas, pantalones y/o medias que necesitas de cada talla.<br /><br /><span style='color:#FF5C00'><a href='#' onclick=\"document.getElementById('contTallaje').style.display='block';return false;\">Consultar las tablas de conversi&oacute;n de tallas</a></span></b></div>";

	for (var y=0;y<3;++y)
	{
		if(y==0 && window['unidades'+y]>0)
			cad+="<div style='border:1px solid #FF5C00;width:625px;margin:11px;'><div style='background:#BBBEBE;text-align:center;'><img src='img/enc_tallasJ.png'/></div>";
		if(y==1 && window['unidades'+y]>0)
			cad+="<div style='border:1px solid #FF5C00;width:625px;margin:11px;'><div style='background:#BBBEBE;text-align:center;'><img src='img/enc_tallasP1.png'/></div>";
		if(y==2 && window['unidades'+y]>0)
			cad+="<div style='border:1px solid #FF5C00;width:625px;margin:11px;'><div style='background:#BBBEBE;text-align:center;'><img src='img/enc_tallasP2.png'/></div>";
			
		if(window['unidades'+y]>0)
		{
			if(window['opcionActiva'+y]==1)
			{
				cad+="<div style='margin:6px'><b>TALLAS EQUIPACIONES</b><br /></div><div style='background:#EEEFEF' id='contT_"+y+"'><table class='df' align='center' cellpadding='0' cellspacing='5'><tr>";
				var e=xmlDoc.getElementsByTagName('e');
				for(var x=0;x<e.length;++x)
				{
					if(e[x].getAttribute('id')*1!=window['equipaciones'+y]) continue;
					cad+="<td><b>"+e[x].firstChild.data+"</b></td><td><input type='text' style='width:20px' name='t_E_"+y+"_"+e[x].getAttribute('idt')+"' id='t_E_"+y+"_"+e[x].getAttribute('idt')+"' onkeyup=\"checkNum(this.id,'contT_"+y+"')\" onfocus='focusNum(this.id)' value='";
					for (var tNS=0;tNS<tNoSerif.length;++tNS)
					{
						var g=tNoSerif[tNS].split('#');
						var gg='t_E_'+y+'_'+e[x].getAttribute('idt');
						if(g[0]==gg && g[1]*1>0)
							cad+=g[1];
					}
					cad+="'/></td>";
				}
				cad+="</tr></table></div>";
			}
			if(window['opcionActiva'+y]==2)
			{
				for(var z=0;z<3;++z)
				{
					if(window['productos'+y][z]>0)
						cad+="<div style='margin:6px'><b>TALLAS "+txZ[z]+"</b><br /></div><div style='background:#EEEFEF' id='contT"+aZ[z]+"_"+y+"'><table class='df' align='center' cellpadding='0' cellspacing='5'><tr>";
					var e=xmlDoc.getElementsByTagName('p');
					for(var x=0;x<e.length;++x)
					{
						if(e[x].getAttribute('id')*1!=window['productos'+y][z]) continue;
						cad+="<td><b>"+e[x].firstChild.data+"</b></td><td><input type='text' style='width:20px' name='t_"+aZ[z]+"_"+y+"_"+e[x].getAttribute('idt')+"' id='t_"+aZ[z]+"_"+y+"_"+e[x].getAttribute('idt')+"' onkeyup=\"checkNum(this.id,'contT"+aZ[z]+"_"+y+"')\" onfocus='focusNum(this.id)' value='";
						for (var tNS=0;tNS<tNoSerif.length;++tNS)
						{
							var g=tNoSerif[tNS].split('#');
							var gg='t_'+aZ[z]+'_'+y+'_'+e[x].getAttribute('idt');
							if(g[0]==gg && g[1]*1>0)
								cad+=g[1];
						}
						cad+="'/></td>";
					}
					cad+="</tr></table></div>";
				}
			}
			if(window['opcionActiva'+y]==3)
			{
				for(var z=0;z<3;++z)
				{
					if(window['promos'+y][z]>0)
						cad+="<div style='margin:6px'><b>TALLAS "+txZ[z]+"</b><br /></div><div style='background:#EEEFEF' id='contT"+aZ2[z]+"_"+y+"'><table class='df' align='center' cellpadding='0' cellspacing='5'><tr>";
					var e=xmlDoc.getElementsByTagName('p');
					for(var x=0;x<e.length;++x)
					{
						if(e[x].getAttribute('id')*1!=window['promos'+y][z]) continue;
						cad+="<td><b>"+e[x].firstChild.data+"</b></td><td><input type='text' style='width:20px' name='t_"+aZ2[z]+"_"+y+"_"+e[x].getAttribute('idt')+"' id='t_"+aZ2[z]+"_"+y+"_"+e[x].getAttribute('idt')+"' onkeyup=\"checkNum(this.id,'contT"+aZ2[z]+"_"+y+"')\" onfocus='focusNum(this.id)' value='";
						for (var tNS=0;tNS<tNoSerif.length;++tNS)
						{
							var g=tNoSerif[tNS].split('#');
							var gg='t_'+aZ2[z]+'_'+y+'_'+e[x].getAttribute('idt');
							if(g[0]==gg && g[1]*1>0)
								cad+=g[1];
						}
						cad+="'/></td>";
					}
					cad+="</tr></table></div>";
				}
			}			
		cad+="</div>";
		}
	}

	cad+="<table width='100%'><tr><td><div align='center' style='margin-top:15px' id='contButEnvNoSerif'><img id='envNoSerif2' src='img/continuaroff.png' onmouseover=\"this.style.display='none';document.getElementById('envNoSerifOn2').style.display='block';\"/><img src='img/continuaron2.png' id='envNoSerifOn2' style='display:none;cursor:pointer;cursor:hand' onmouseout=\"this.style.display='none';document.getElementById('envNoSerif2').style.display='block';\" onclick=\"envNoSerif()\"/></div></td><td><div align='center' style='margin-top:15px'><img id='botCancelRegOff5' src='img/botCancelOff.png' onmouseover=\"this.style.display='none';document.getElementById('botCancelRegOn5').style.display='block';\"/><img src='img/botCancelOn.png' id='botCancelRegOn5' style='display:none;cursor:pointer;cursor:hand' onmouseout=\"this.style.display='none';document.getElementById('botCancelRegOff5').style.display='block';\" onclick='cierrapopNoSerigrafia()'/></div></td></tr></table><br /></div></form>";
	document.getElementById('transC14').innerHTML=cad;
	popNoSerigrafia();
}
function envNoSerif()
{
	var tx1=new Array('jugador','portero','portero');
	var txZ=new Array('camisetas','pantalones','medias');
	var aZ=new Array('C','P','M');
	var aZ2=new Array('C2','P2','M2');
	
	var nombre=document.getElementById('nomequip').value;
	if(nombre=='')
	{
		alert('Por favor, escribe un nombre para esta equipación');
		return;
	}
	document.getElementById('fNoSerif').nombre.value=nombre;
	for(var y=0;y<3;++y)
	{
		var num=0;
		if(window['unidades'+y]>0)
		{
			if(window['opcionActiva'+y]==1)
			{
				var e=document.getElementById('contT_'+y).getElementsByTagName('input');
				for(var x=0;x<e.length;++x)
				{
					num+=e[x].value*1;
				}
				if(num!=window['unidades'+y])
				{
					alert('Debes especificar '+window['unidades'+y]+' tallas dee equipación de '+tx1[y]+' para continuar');
					return;
				}
			}
			if(window['opcionActiva'+y]==2)
			{
				for(var z=0;z<3;++z)
				{
					if(window['productos'+y][z]==0) continue;
					var num=0;
					var e=document.getElementById('contT'+aZ[z]+"_"+y).getElementsByTagName('input');
					for(var x=0;x<e.length;++x)
					num+=e[x].value*1;
					if(num!=window['unidades'+y])
					{
						alert('Debes especificar '+window['unidades'+y]+' tallas de '+txZ[z]+' de '+tx1[y]+' para continuar');
						return;
					}
				}
			}
			if(window['opcionActiva'+y]==3)
			{
				for(var z=0;z<3;++z)
				{
					if(window['promos'+y][z]==0) continue;
					var num=0;
					var e=document.getElementById('contT'+aZ2[z]+"_"+y).getElementsByTagName('input');
					for(var x=0;x<e.length;++x)
					num+=e[x].value*1;
					if(num!=window['unidades'+y])
					{
						alert('Debes especificar '+window['unidades'+y]+' tallas de '+txZ[z]+' de '+tx1[y]+' para continuar');
						return;
					}
				}
			}			
		}
	}
	document.getElementById('fNoSerif').submit();
}
function checkSelTallas()
{
	var err=0;
	var e=document.getElementById('contentN').getElementsByTagName('input');
	for (var x=0;x<e.length;++x)
	{
		if(e[x].type!='text' || e[x].id=='') continue;
		if(e[x].id.charAt(0)=='X' && (isNaN(e[x].value) || e[x].value=='') )
		{
			e[x].className='bordeRojo';
			err=1;
		}
		if(e[x].id.charAt(0)=='N' && (e[x].value=='max. 12 caracteres' || e[x].value=='' || e[x].length>12) )
		{
			e[x].className='bordeRojo';
			err=1;
		}
	}
	if(err==1)
	{
		alert('Por favor, rellena todos los datos de nombres y/o números de las equipaciones');
		return;
	}
	document.getElementById('form3').submit();
}
function checkNum(id,padre)
{
	var num=0;
	var n=document.getElementById(id).value;
	if(isNaN(n))
		document.getElementById(id).value='0';
	document.getElementById(id).value*=1;
	var p=padre.split('_');
	p=p[1];
	var e=document.getElementById(padre).getElementsByTagName('input');
	for(var x=0;x<e.length;++x)
		num+=e[x].value*1;
	if(num>window['unidades'+p])
	{
		alert('No puedes especificar más de '+window['unidades'+p]+' tallas');
		document.getElementById(id).value=0;
	}
}
function checkNum2(id)
{
	var t=document.getElementById(id).value;
	if(isNaN(t))
		document.getElementById(id).value='';
	if(t.length>2)
		document.getElementById(id).value=t.substr(0,2);
}
function checkNum2b(id)
{
	var t=document.getElementById(id).value;
	if(isNaN(t))
		document.getElementById(id).value='';
}
function checkNom(id)
{
	var t=document.getElementById(id).value;
	if(t.length>12)
		document.getElementById(id).value=t.substr(0,12);
}

function focusNom(id)
{
	document.getElementById(id).className='bordeGris';
	if(document.getElementById(id).value=='max. 12 caracteres')
		document.getElementById(id).value='';
}
function focusNum(id)
{
	if(document.getElementById(id).value=='0')
		document.getElementById(id).value='';
}
function focusNum2(id)
{
	document.getElementById(id).className='bordeGris';
}
function nuevoElem(tipo)
{
	document.getElementById('form3').params.value='1#'+tipo;
	document.getElementById('form3').submit();
}
function eliminaTipoJug(z,x)
{
	var cad='Confirma que deseas eliminar este ';
	if(z==0) cad+='jugador';else cad+='portero';
	if(confirm(cad))
	{
		document.getElementById('form3').params.value='2#'+z+'#'+x;
		document.getElementById('form3').submit();
	}
}
function calculaPrecio(conSerif)
{
	var total=0;

	for (var y=0;y<3;++y)
	{
		var precio=0;
		var precio2=0;
		var todasPromo=0;
		if(window['opcionActiva'+y]==1)
		{
			var e=xmlData.getElementsByTagName('e');
			for(var x=0;x<e.length;++x)
				if(e[x].getAttribute('i')*1==window['equipaciones'+y])
				{
					precio=e[x].getAttribute('p')*1;
					break;
				}
		}
		if(window['opcionActiva'+y]==2)
		{
			var e=xmlData.getElementsByTagName('p');
			for (var x=0;x<e.length;++x)
				if(e[x].getAttribute('i')*1==window['productos'+y][0])
				{
					precio+=e[x].getAttribute('p')*1;
					if(llevaPromo(e[x].getAttribute('i')*1))
					{
						precio2+=e[x].getAttribute('pp')*1;
						++todasPromo;
					}
					break;
				}
			for (var x=0;x<e.length;++x)
				if(e[x].getAttribute('i')*1==window['productos'+y][1])
				{
					precio+=e[x].getAttribute('p')*1;
					if(llevaPromo(e[x].getAttribute('i')*1))
					{
						precio2+=e[x].getAttribute('pp')*1;
						++todasPromo;
					}
					break;
				}
			for (var x=0;x<e.length;++x)
				if(e[x].getAttribute('i')*1==window['productos'+y][2])
				{
					precio+=e[x].getAttribute('p')*1;
					if(llevaPromo(e[x].getAttribute('i')*1))
					{
						precio2+=e[x].getAttribute('pp')*1;
						++todasPromo;
					}
					break;
				}
		}
		if(window['opcionActiva'+y]==3)
		{
			var e=xmlData.getElementsByTagName('p');
			for (var x=0;x<e.length;++x)
				if(e[x].getAttribute('i')*1==window['promos'+y][0])
				{
					precio+=e[x].getAttribute('pp')*1;
					break;
				}
			for (var x=0;x<e.length;++x)
				if(e[x].getAttribute('i')*1==window['promos'+y][1])
				{
					precio+=e[x].getAttribute('pp')*1;
					break;
				}
			for (var x=0;x<e.length;++x)
				if(e[x].getAttribute('i')*1==window['promos'+y][2])
				{
					precio+=e[x].getAttribute('pp')*1;
					break;
				}
		}
		if(window['opcionActiva'+y]==2 && todasPromo==3)
			precio=precio2;
		total+=precio*window['unidades'+y];
	}

	if(conSerif==1)
	{
		var precios=xmlData.getElementsByTagName('pSerif')[0];
		var p=serifData.split(';');
		for(var j=0;j<p.length;++j)
		{
			var pp=p[j].split('#@#');
			if(pp[0]==1)
			{
				for(var z=0;z<3;++z)
				{
					if(window['equipaciones'+z]>0 && window['unidades'+z]>0)
						total+=precios.getAttribute('n')*window['unidades'+z];
					if(window['productos'+z][0]>0 && window['unidades'+z]>0)
						total+=precios.getAttribute('n')*window['unidades'+z];
					if(window['promos'+z][0]>0 && window['unidades'+z]>0)
						total+=precios.getAttribute('n')*window['unidades'+z];	
				}
			}
			if(pp[0]==2)
			{
				for(var z=0;z<3;++z)
				{
					if(window['equipaciones'+z]>0 && window['unidades'+z]>0)
						total+=precios.getAttribute('nn')*window['unidades'+z];
					if(window['productos'+z][0]>0 && window['unidades'+z]>0)
						total+=precios.getAttribute('nn')*window['unidades'+z];
					if(window['promos'+z][0]>0 && window['unidades'+z]>0)
						total+=precios.getAttribute('nn')*window['unidades'+z];	
				}
			}		
			if(pp[0]==3)
			{
				for(var z=0;z<3;++z)
				{
					if(window['equipaciones'+z]>0 && window['unidades'+z]>0)
						total+=precios.getAttribute('np')*window['unidades'+z];
					if(window['productos'+z][1]>0 && window['unidades'+z]>0)
						total+=precios.getAttribute('np')*window['unidades'+z];
					if(window['promos'+z][1]>0 && window['unidades'+z]>0)
						total+=precios.getAttribute('np')*window['unidades'+z];	
				}
			}
			if(pp[0]==41 || pp[0]==42 || pp[0]==43)
			{
				var hayEst=0;
				for(var z=0;z<3;++z)
				{
					if(window['equipaciones'+z]>0 && window['unidades'+z]>0)
					{
						total+=precios.getAttribute('e')*window['unidades'+z];
						hayEst=1;
					}
					if(window['productos'+z][0]>0 && window['unidades'+z]>0)
					{
						total+=precios.getAttribute('e')*window['unidades'+z];
						hayEst=1;
					}
					if(window['promos'+z][0]>0 && window['unidades'+z]>0)
					{
						total+=precios.getAttribute('e')*window['unidades'+z];
						hayEst=1;
					}
				}
				if(hayEst==1)
					total+=precios.getAttribute('p')*1;
			}
			if(pp[0]==51 || pp[0]==52)
			{
				var desc=	precios.getAttribute('d')*1;
				total=total-(total*desc/100);
			}
		}
		
	}
	document.getElementById('totalPrecio').innerHTML=number_format(total,2,',','.')+' &euro;';

}
function sacaPadre(id)
{
	var e=xmlData.getElementsByTagName('p');
	for (var x=0;x<e.length;++x)
		if(e[x].getAttribute('i')*1==id)
			return e[x].getAttribute('ip')*1;
}

function llevaPromo(id)
{
	var e=xmlData.getElementsByTagName('p');
	for (var x=0;x<e.length;++x)
		if(e[x].getAttribute('i')*1==id)
			return e[x].getAttribute('pr')*1;
}
function mueveEquip(step)
{
	var nodo1='jug';
	if(tipoJugador>0) nodo1='por';
	var lista=new Array();
	var index=0;
	var e=xmlData.getElementsByTagName(nodo1)[0].getElementsByTagName('e');
	for (var x=0;x<e.length;++x)
	{
		if(e[x].getAttribute('idm')*1!=window['marcaActiva'+tipoJugador]) continue;
		lista[lista.length]=e[x].getAttribute('i');
		if(e[x].getAttribute('i')*1!=window['equipaciones'+tipoJugador]) continue;
		index=lista.length-1;
	}
	window['equipaciones'+tipoJugador]=lista[index+step];
	ponProducto();
}
function in_array(a,p)
{
	for (var x=0;x<p.length;++x)
		if(p[x]==a)
			return 1;
	return 0;
}
function mueveProd(cat,step)
{
	var opcion=window['opcionActiva'+tipoJugador];
	var mod='productos';
	if(opcion==3) mod='promos';
	var idProd=window[mod+tipoJugador][cat-1];
	var idPadre=sacaPadre(idProd);
	if(idPadre!=0)
		idProd=idPadre;
	var tmp=new Array();
	var idx=0;

	var nodo1='jug';
	if(tipoJugador>0) nodo1='por';
	var e=xmlData.getElementsByTagName(nodo1)[0].getElementsByTagName('p');
	//console.info('Idprod: '+idProd);
	for (var x=0;x<e.length;++x)
	{
		if(opcion==3 && e[x].getAttribute('pr')*1!=1)continue;
		if(in_array(e[x].getAttribute('i')*1,tmp)) continue;
		if(e[x].getAttribute('ip')=='0' && (e[x].getAttribute('c')*1)==cat && (e[x].getAttribute('idm')*1)==window['marcaActiva'+tipoJugador])
			tmp[tmp.length]=e[x].getAttribute('i')*1;
		if(e[x].getAttribute('i')*1==idProd)
			idx=tmp.length-1;
	}
	//console.info(idx*1+step);
	window[mod+tipoJugador][cat-1]=tmp[idx+step];
	ponProducto();
}
function selProd(cat,id)
{
	var opcion=window['opcionActiva'+tipoJugador];
	var mod='productos';
	if(opcion==3) mod='promos';
	window[mod+tipoJugador][cat-1]=id;
	document.getElementById('cont'+cat+'TxOt2').style.display='none';
	ponProducto();
	calculaPrecio(0);
}
function limpiaVentana()
{
	document.getElementById('ayuda').style.display='none';
	document.getElementById('cont1Img').style.display='none';
	document.getElementById('cont2Img').style.display='none';
	document.getElementById('cont3Img').style.display='none';
	document.getElementById('cont1Tx').style.display='none';
	document.getElementById('cont2Tx').style.display='none';
	document.getElementById('cont3Tx').style.display='none';
	document.getElementById('cont1TxOt').style.display='none';
	document.getElementById('cont2TxOt').style.display='none';
	document.getElementById('cont3TxOt').style.display='none';
	document.getElementById('cont1Tx2').style.display='none';
	document.getElementById('cont2Tx2').style.display='none';
	document.getElementById('cont3Tx2').style.display='none';
	document.getElementById('contEImg').style.display='none';
	document.getElementById('contETx').style.display='none';
	document.getElementById('sc1Iz').style.display='none';
	document.getElementById('sc1De').style.display='none';
	document.getElementById('sc2Iz').style.display='none';
	document.getElementById('sc2De').style.display='none';
	document.getElementById('sc3Iz').style.display='none';
	document.getElementById('sc3De').style.display='none';
	document.getElementById('botSig').style.display='none';
	document.getElementById('botAnt').style.display='none';
}

function auxPonProd(e,cat)
{
	//console.info('CATEGORIA: '+cat);
	var idProd=window['productos'+tipoJugador][cat-1];
	var idProdPadre=sacaPadre(idProd);
	var tmp=new Array();
	var pos=0;
	var listaOtros='';
	
	for (var x=0;x<e.length;++x)
	{
		if(e[x].getAttribute('c')*1!=cat) continue;
		//console.info(e[x].getElementsByTagName('n')[0].firstChild.data);
		if(e[x].getAttribute('idm')*1!=window['marcaActiva'+tipoJugador]) continue;
		if(e[x].getAttribute('ip')*1==0 && !in_array(e[x].getAttribute('i')*1,tmp))
			tmp[tmp.length]=e[x].getAttribute('i')*1;
	
		/*
		if(window['productos'+tipoJugador][cat-1]==0)
		{
			window['productos'+tipoJugador][cat-1]=e[x].getAttribute('i')*1;
			idProd=e[x].getAttribute('i')*1;
		}*/

		if(e[x].getAttribute('i')*1==idProd)
		{
			var tienePromo=e[x].getAttribute('pr')*1;
			var precio=e[x].getAttribute('p')*1;
			document.getElementById('cont'+cat+'Img').innerHTML="<img src='img_admin/"+e[x].getAttribute('f')+"'/>";
			var cad="";
			if(e[x].getElementsByTagName('n')[0].firstChild.data)
				cad+="<div style='font-size:12px;margin:5px'><b>PRODUCTO SELECCIONADO</b></div>";
			cad+="<div style='padding:10px'><b>"+e[x].getElementsByTagName('n')[0].firstChild.data+" &nbsp; ";
			if(precio>0) cad+="<span style='color:#FF5C00'>"+precio+" &euro;</span>";
			cad+="</b><br /><br />"+e[x].getElementsByTagName('d')[0].firstChild.data;
			if(tienePromo==1 && idProd>0)
				cad+="<br /><br /><div style='color:#FF5C00'><b>Precio en promoción: "+(e[x].getAttribute('pp')*1)+" &euro;</b>&nbsp;&nbsp;&nbsp;<img src='img/ayuda.png' align='absmiddle' style='cursor:pointer;cursor:hand' onclick='ponAyudaPromo("+cat+")'/></div>";
			cad+="</div>";
			document.getElementById('cont'+cat+'Tx').innerHTML=cad;
		}
		else
		{
			if(e[x].getAttribute('i')*1>0 && idProd>0)
				if(e[x].getAttribute('ip')*1==idProd || e[x].getAttribute('i')*1==idProdPadre || (idProdPadre!=0 && e[x].getAttribute('ip')*1==idProdPadre))
					listaOtros+="<a href='#' class='lOt' onclick=\"selProd("+cat+","+(e[x].getAttribute('i')*1)+");return false;\">Color "+e[x].getAttribute('co')+' - '+e[x].getAttribute('v')+'</a><br />';
		}
	}
	document.getElementById('cont'+cat+'TxOt2').innerHTML=listaOtros;
	if(listaOtros=='')
		document.getElementById('cont'+cat+'TxOt').style.display='none';
	else document.getElementById('cont'+cat+'TxOt').style.display='block';
	if(idProdPadre==0)
		idProdPadre=idProd;
	for (var x=0;x<tmp.length;++x)
		if(tmp[x]==idProdPadre)
			pos=x;
	
	document.getElementById('sc'+cat+'Iz').style.display='block';
	document.getElementById('sc'+cat+'De').style.display='block';
	//console.info(tmp);
	if(pos>0)
	{
		document.getElementById('sc'+cat+'Iz').className='sc'+cat+'IzOn';
		document.getElementById('sc'+cat+'Iz').onclick=function(){mueveProd(cat,-1);};
	}
	else
	{
		document.getElementById('sc'+cat+'Iz').className='sc'+cat+'IzOff';
		document.getElementById('sc'+cat+'Iz').onclick=function(){};
	}
	if(pos<tmp.length-1)
	{
		document.getElementById('sc'+cat+'De').className='sc'+cat+'DeOn';
		document.getElementById('sc'+cat+'De').onclick=function(){mueveProd(cat,1);};
	}
	else
	{
		document.getElementById('sc'+cat+'De').className='sc'+cat+'DeOff';
		document.getElementById('sc'+cat+'De').onclick=function(){};
	}
}

function auxPonProm(e,cat)
{
	//console.info('CATEGORIA: '+cat);
	var idProd=window['promos'+tipoJugador][cat-1];
	var idProdPadre=sacaPadre(idProd);
	var tmp=new Array();
	var pos=0;
	var listaOtros='';
	for (var x=0;x<e.length;++x)
	{
		if(e[x].getAttribute('c')*1!=cat) continue;
		if(e[x].getAttribute('idm')*1!=window['marcaActiva'+tipoJugador]) continue;
		if(e[x].getAttribute('pr')*1!=1) continue;
		if(e[x].getAttribute('ip')*1==0)
			tmp[tmp.length]=e[x].getAttribute('i')*1;


		/*if(window['promos'+tipoJugador][cat-1]==0)
		{
			window['promos'+tipoJugador][cat-1]=e[x].getAttribute('i')*1;
			idProd=e[x].getAttribute('i')*1;
		}*/


		if(e[x].getAttribute('i')*1==idProd)
		{
			var tienePromo=e[x].getAttribute('pr')*1;
			var precio=e[x].getAttribute('pp')*1;
			document.getElementById('cont'+cat+'Img').innerHTML="<img src='img_admin/"+e[x].getAttribute('f')+"'/>";
			var cad="";
			if(e[x].getAttribute('i')*1>0)
				cad+="<div style='font-size:12px;margin:5px'><b>PRODUCTO SELECCIONADO</b></div>";
			cad+="<div style='padding:10px'><b>"+e[x].getElementsByTagName('n')[0].firstChild.data+" &nbsp; ";
			if(precio>0) cad+="<span style='color:#FF5C00'>"+precio+" &euro;</span>";
			cad+="</b><br /><br />"+e[x].getElementsByTagName('d')[0].firstChild.data;
			cad+="</div>";
			document.getElementById('cont'+cat+'Tx').innerHTML=cad;
		}
		else
		{
			if(e[x].getAttribute('i')*1>0 && idProd>0)
				if(e[x].getAttribute('ip')*1==idProd || e[x].getAttribute('i')*1==idProdPadre || (idProdPadre!=0 && e[x].getAttribute('ip')*1==idProdPadre))
					listaOtros+="<a href='#' class='lOt' onclick=\"selProd("+cat+","+(e[x].getAttribute('i')*1)+");return false;\">Color "+e[x].getAttribute('co')+' - '+e[x].getAttribute('v')+'</a><br />';
		}
	}
	document.getElementById('cont'+cat+'TxOt2').innerHTML=listaOtros;
	if(listaOtros=='')
		document.getElementById('cont'+cat+'TxOt').style.display='none';
	else document.getElementById('cont'+cat+'TxOt').style.display='block';
	if(idProdPadre==0)
		idProdPadre=idProd;
	for (var x=0;x<tmp.length;++x)
		if(tmp[x]==idProdPadre)
			pos=x;
	//console.info(tmp+' '+pos);
	document.getElementById('sc'+cat+'Iz').style.display='block';
	document.getElementById('sc'+cat+'De').style.display='block';
	if(pos>0)
	{
		document.getElementById('sc'+cat+'Iz').className='sc'+cat+'IzOn';
		document.getElementById('sc'+cat+'Iz').onclick=function(){mueveProd(cat,-1);};
	}
	else
	{
		document.getElementById('sc'+cat+'Iz').className='sc'+cat+'IzOff';
		document.getElementById('sc'+cat+'Iz').onclick=function(){};
	}
	if(pos<tmp.length-1)
	{
		document.getElementById('sc'+cat+'De').className='sc'+cat+'DeOn';
		document.getElementById('sc'+cat+'De').onclick=function(){mueveProd(cat,1);};
	}
	else
	{
		document.getElementById('sc'+cat+'De').className='sc'+cat+'DeOff';
		document.getElementById('sc'+cat+'De').onclick=function(){};
	}
}

function ponProducto()
{
	limpiaVentana();

	var nodo1='jug';
	if(tipoJugador>0) nodo1='por';
	var opcion=window['opcionActiva'+tipoJugador];
	var nodo2='e';
	if(opcion>1) nodo2='p';

	if(opcion==1)
	{
		var lista=new Array();
		var index=0;
		var e=xmlData.getElementsByTagName(nodo1)[0].getElementsByTagName(nodo2);
		for (var x=0;x<e.length;++x)
		{
			/*if(window['equipaciones'+tipoJugador]==0)
				window['equipaciones'+tipoJugador]=e[x].getAttribute('i')*1;*/
			if(e[x].getAttribute('idm')*1!=window['marcaActiva'+tipoJugador]) continue;

			lista[lista.length]=e[x].getAttribute('i');
			if(e[x].getAttribute('i')*1!=window['equipaciones'+tipoJugador]) continue;
			index=lista.length-1;
			document.getElementById('contEImg').innerHTML="<img src='img_admin/"+e[x].getAttribute('f')+"'/>";
			var cad="<div style='padding:10px'>";
			if(e[x].getAttribute('i')*1>0)cad+="<div style='font-size:15px;margin-bottom:10px'><b>EQUIPACIÓN SELECCIONADA</b></div><b>"+e[x].getElementsByTagName('n')[0].firstChild.data+" &nbsp; <span style='color:#FF5C00'>"+(e[x].getAttribute('p')*1)+" &euro;</span></b><br />"+e[x].getElementsByTagName('d')[0].firstChild.data;
			cad+="</div>";
			document.getElementById('contETx').innerHTML=cad;
			document.getElementById('contEImg').style.display='inline';
			document.getElementById('contETx').style.display='inline';
		}

		document.getElementById('botAnt').style.display='inline';
		document.getElementById('botSig').style.display='inline';
		if(index>0)
		{
			document.getElementById('botAnt').className='botAntOn';
			document.getElementById('botAnt').onclick=function(){mueveEquip(-1);};
		}
		else
		{
			document.getElementById('botAnt').className='botAntOff';
			document.getElementById('botAnt').onclick=function(){};
		}
		if(index<lista.length-1)
		{
			document.getElementById('botSig').className='botSigOn';
			document.getElementById('botSig').onclick=function(){mueveEquip(1);};
		}
		else
		{
			document.getElementById('botSig').className='botSigOff';
			document.getElementById('botSig').onclick=function(){};
		}
	}

	if(opcion>1)
	{
		document.getElementById('cont1Img').innerHTML="<img src='img_admin/camisetaoff.jpg'/>";
		document.getElementById('cont1Img').style.display='inline';
		document.getElementById('cont2Img').innerHTML="<img src='img_admin/pantalonoff.jpg'/>";
		document.getElementById('cont2Img').style.display='inline';
		document.getElementById('cont3Img').innerHTML="<img src='img_admin/mediasoff.jpg'/>";
		document.getElementById('cont3Img').style.display='inline';
		document.getElementById('cont1Tx').innerHTML='';
		document.getElementById('cont1Tx').style.display='inline';
		document.getElementById('cont2Tx').innerHTML='';
		document.getElementById('cont2Tx').style.display='inline';
		document.getElementById('cont3Tx').innerHTML='';
		document.getElementById('cont3Tx').style.display='inline';

		document.getElementById('cont1Tx2').style.display='inline';
		document.getElementById('cont2Tx2').style.display='inline';
		document.getElementById('cont3Tx2').style.display='inline';

		var e=xmlData.getElementsByTagName(nodo1)[0].getElementsByTagName(nodo2);
		if(opcion==2)
		{
			auxPonProd(e,1);
			auxPonProd(e,2);
			auxPonProd(e,3);
		}
		if(opcion==3)
		{
			auxPonProm(e,1);
			auxPonProm(e,2);
			auxPonProm(e,3);
		}
	}

	guardaDatos();
	calculaPrecio(0);
}
function guardaDatos()
{
	var cad=unidades0+';'+unidades1+';'+unidades2+';'+opcionActiva0+';'+opcionActiva1+';'+opcionActiva2+';'+marcaActiva0+';'+marcaActiva1+';'+marcaActiva2+';'+productos0+';'+productos1+';'+productos2+';'+promos0+';'+promos1+';'+promos2+';'+equipaciones0+';'+equipaciones1+';'+equipaciones2+';'+document.getElementById('nomequip').value;
	K_loadAJAX(K_mainPath+'ajax/guardaDatos.php?d='+escape(cad),'resAJAXcall');
}
function cambiaUnidades(val,num)
{
	window['unidades'+val]=num;
	var cad='&nbsp;';
	if(num<10)cad+='0';
	cad+=num+' uds.';
	if(num==0)
		cad='&nbsp;Ninguno';
	document.getElementById('desp'+val).innerHTML=cad;
	document.getElementById('desp'+val+'ext').style.display='none';
	despUniAbierto=-1;
	guardaDatos();
	calculaPrecio(0);
}
function ponAyudaPromo(val)
{
	var t=document.getElementById('ayudaPromo'+val);
	if(t.style.display=='none')
		t.style.display='block';
	else t.style.display='none';
}

function abreSelOp(cat)
{
	//console.info("abreSelOp("+cat+")");
	if(document.getElementById('cont'+cat+'TxOt2').style.display!='block')
	{
		document.getElementById('cont1TxOt2').style.display='none';
		document.getElementById('cont2TxOt2').style.display='none';
		document.getElementById('cont3TxOt2').style.display='none';
		document.getElementById('cont'+cat+'TxOt2').style.display='block';
	}
	else
		document.getElementById('cont'+cat+'TxOt2').style.display='none';
}

function selecOpcion_(val)
{
	window['opcionActiva'+tipoJugador]=val;
	if(val==1)
	{
		window['productos'+tipoJugador]=new Array(0,0,0);
		window['promos'+tipoJugador]=new Array(0,0,0);
	}
	if(val==2)
	{
		window['equipaciones'+tipoJugador]=0;
		window['promos'+tipoJugador]=new Array(0,0,0);
	}
	if(val==3)
	{
		window['equipaciones'+tipoJugador]=0;
		window['productos'+tipoJugador]=new Array(0,0,0);
	}
	if(document.getElementById('linkProd1'))
		document.getElementById('linkProd1').className='opcionOff';
	if(document.getElementById('linkProd2'))
		document.getElementById('linkProd2').className='opcionOff';
	if(document.getElementById('linkProd3'))
		document.getElementById('linkProd3').className='opcionOff';
	if(val)
		document.getElementById('linkProd'+val).className='opcionOn';
	ponProducto();
}

function selecMarca_(id)
{
	if(window['marcaActiva'+tipoJugador]!=id)
	{
		window['opcionActiva'+tipoJugador]=0;
		window['productos'+tipoJugador]=new Array(0,0,0);
		window['promos'+tipoJugador]=new Array(0,0,0);
		window['equipaciones'+tipoJugador]=0;
	}

	window['marcaActiva'+tipoJugador]=id;
	var e=document.getElementById('contMarcas').getElementsByTagName('div');
	for (var x=0;x<e.length;++x)
		if(e[x].className=='marcaOn')
			e[x].className='marcaOff';
	if(id)
		document.getElementById('selMarca'+id).className='marcaOn';

	if(document.getElementById('linkProd1'))
		document.getElementById('linkProd1').parentNode.removeChild(document.getElementById('linkProd1'));
	if(document.getElementById('linkProd2'))
		document.getElementById('linkProd2').parentNode.removeChild(document.getElementById('linkProd2'));
	if(document.getElementById('linkProd3'))
		document.getElementById('linkProd3').parentNode.removeChild(document.getElementById('linkProd3'));

	var cad="<div id='selOpcion'>";
	var nodo='jug';
	if(tipoJugador>0) nodo='por';



	var e=xmlData.getElementsByTagName(nodo)[0].getElementsByTagName('prod')[0].getElementsByTagName('p');
	var hayProd=0;
	for(var x=0;x<e.length;++x)
	{
		if(e[x].getAttribute('idm')*1==id)
		{
			hayProd=1;
			break;
		}
	}
	if(hayProd)
		cad+="<div id='linkProd2' class='opcionOff' onclick='selecOpcion(2)'>Camisa, pantalón, medias</div>";

	var hayPromo=0;
	for(var x=0;x<e.length;++x)
	{
		if(e[x].getAttribute('idm')*1==id && e[x].getAttribute('pr')*1==1)
		{
			hayPromo=1;
			break;
		}
	}
	if(hayPromo)
		cad+="<div id='linkProd3' class='opcionOff' onclick='selecOpcion(3)'>Promociones</div>";
		
	var e=xmlData.getElementsByTagName(nodo)[0].getElementsByTagName('equip')[0].getElementsByTagName('e');
	var hayEquip=0;
	for(var x=0;x<e.length;++x)
	{
		if(e[x].getAttribute('idm')*1==id)
		{
			hayEquip=1;
			break;
		}
	}
	if(hayEquip)
		cad+="<div id='linkProd1' class='opcionOff' onclick='selecOpcion(1)'>Conjuntos</div>";		

	cad+='</div>';
	document.getElementById('selMarca'+id+'_dummy').innerHTML=cad;
	if(window['opcionActiva'+tipoJugador]*1>0)
		selecOpcion(window['opcionActiva'+tipoJugador]);
	else
	{
		limpiaVentana();
		document.getElementById('ayuda').style.display='block';
	}
}

function ponMarcas(limpia)
{
	var att1='eJ';var att2='pJ';
	if(tipoJugador>0){	att1='eP';	att2='pP';	}
	var cad='';
	alert(xmlData);
	var e=xmlData.getElementsByTagName('m');
	for (var x=0;x<e.length;++x)
	{
		if(e[x].getAttribute(att1)*1>0 || e[x].getAttribute(att2)*1>0)
			cad+="<div id='selMarca"+e[x].getAttribute('id')+"' class='marcaOff' onclick='selecMarca("+e[x].getAttribute('id')+")'>"+e[x].firstChild.data+"</div><div id='selMarca"+e[x].getAttribute('id')+"_dummy'></div>";
	}
	document.getElementById('contMarcas').innerHTML=cad;
	if(window['marcaActiva'+tipoJugador])
		selecMarca(window['marcaActiva'+tipoJugador]);
	else
	{
		if(limpia)
			limpiaVentana();
		document.getElementById('ayuda').style.display='block';
	}
}

function cambiaTipoJugador(val)
{
	/*if(val==tipoJugador)
		return;*/
	tipoJugador=val;

	document.getElementById('selTipoJug0').className='botJugOff';
	document.getElementById('selTipoJug1').className='botJugOff';
	document.getElementById('selTipoJug2').className='botJugOff';
	document.getElementById('desp0').className='txSelOff';
	document.getElementById('desp1').className='txSelOff';
	document.getElementById('desp2').className='txSelOff';
	document.getElementById('desp0ext').className='txSelOff';
	document.getElementById('desp1ext').className='txSelOff';
	document.getElementById('desp2ext').className='txSelOff';

	document.getElementById('selTipoJug'+val).className='botJugOn';
	document.getElementById('desp'+val).className='txSelOn';
	document.getElementById('desp'+val+'ext').className='txSelOn';

	ponMarcas(1);
}

function abreDespUni(val)
{
	//alert("abreDespUni");
	//alert(xmlData);
	if(despUniAbierto==val)
	{
		despUniAbierto=-1;
		return;
	}
	else
	{
		despUniAbierto=val;
		cambiaTipoJugador(val);
		/*document.getElementById('desp'+val+'ext').style.display='inline';
		*/
	}
}




/* Made by Mathias Bynens <http://mathiasbynens.be/> */
function number_format(a, b, c, d) {
 a = Math.round(a * Math.pow(10, b)) / Math.pow(10, b);
 e = a + '';
 f = e.split('.');
 if (!f[0]) {
  f[0] = '0';
 }
 if (!f[1]) {
  f[1] = '';
 }
 if (f[1].length < b) {
  g = f[1];
  for (i=f[1].length + 1; i <= b; i++) {
   g += '0';
  }
  f[1] = g;
 }
 if(d != '' && f[0].length > 3) {
  h = f[0];
  f[0] = '';
  for(j = 3; j < h.length; j+=3) {
   i = h.slice(h.length - j, h.length - j + 3);
   f[0] = d + i +  f[0] + '';
  }
  j = h.substr(0, (h.length % 3 == 0) ? 3 : (h.length % 3));
  f[0] = j + f[0];
 }
 c = (b <= 0) ? '' : c;
 return f[0] + c + f[1];
}
