/*****************************************************************************/
/*                                2010 Shio2e                                */
/*    JAVASCRIPT BUSCADOR :: ANUNCIOS :: TIPOS :: PORTAL :: MULTIPORTAL      */
/*****************************************************************************/

buscador.anuncios.tipos.portal_multiportal = {
	// VARIABLES CONFIGURACION
	prefijo_opc_menu 			: 'opc_',
	prefijo_div_seccion 		: 'pdt_',
	numOpcMenuPatrocinadores	: 7,

	// VARIABLES INTERNAS
	parent 						: buscador.anuncios.tipos,

	// FUNCIONES
	mostrar : function (anuncio, datos){
		// CONFIGURAR PORTAL
		this.actual_anuncio = anuncio.id_anuncio;

		// MOSTRAR BOTONES
		$('b_portal_deportivo').show();

		// CONFIGURAR SECCIONES
		this.mostrarSeccion('');
		$('sel_liga').update('');
		$('sel_division').update('');
		this.mostrarMenu();

		// DIRECCION COMERCIO
		var info_comercio = '';
		info_comercio += '<h2>'+datos.nombre+'</h2>';
		info_comercio += datos.direccion+'<br/>'+datos.codigo_postal+' '+datos.poblacion+'<br/>'+datos.provincia;
		$(this.parent.parent.divInfoComercio).update(info_comercio);

		// CARTELERIA
		$('cartel_pm_img').alt = anuncio.nombre;
		$('cartel_pm_img').src = 'http://img.shio2e.com/n/buscador-anuncio-'+anuncio.id_anuncio+'.jpg';

		// TITULO CONTENIDO
		$('pm_titulo_generico').update(datos.extras.titulo_contenido != '' ? datos.extras.titulo_contenido : 'instalaciones');

		// OPCIONES DEL MENU DE LA DERECHA
		var prefijo = 'li.por.';
		var nuevo_listado = '';
		var style;

		// PATROCINADORES - CREAR LOS NUEVOS ELEMENTOS
		var obj, creados = 0;
		for (i=0; i<datos.extras.portales.length; i++) {
			obj = datos.extras.portales[i];

			nuevo_listado += '<li id="li.por.'+creados+'" style="'+style+'">';
			nuevo_listado += '<a href="javascript:void(0);" onclick="javascript:buscador.abrir(\'carteleria\', {id_anuncio: '+obj.id_anuncio+', tipo: '+obj.tipo+', id_comercio: '+obj.id_comercio+', nombre: \''+addslashes(obj.nombre)+'\'});">'+obj.nombre_abreviado+'</a>';
			nuevo_listado += '</li>';

			creados++;
		}

		$('lom_menu').update(nuevo_listado);
		menuListadoVertical.reset('por');

		// PATROCINADORES
		var prefijo = 'li.pd.';
		var nuevo_listado = '';
		var style;

		// PATROCINADORES - ELIMINAR TODAS LAS OPCIONES DEL LISTADO ACTUAL
		var i = 0;
		while($(prefijo+i))
			$(prefijo+(i++)).remove();

		// PATROCINADORES - CREAR LOS NUEVOS ELEMENTOS
		var obj;
		var creados = 0;
		for (i=0; i<datos.extras.patrocinadores.length; i++) {
			obj = datos.extras.patrocinadores[i];

			style = creados < this.numOpcMenuPatrocinadores ? '' : 'display: none;';

			nuevo_listado += '<li id="li.pd.'+creados+'" style="'+style+'" onmouseover="javascript:buscador.fichaTecnica.mostrarInfoListado('+obj.id_comercio+', \''+addslashes(obj.nombre)+'\', ['+obj.categorias.join(',')+'], \'pd.\', 0, 5, 133);" onmouseout="javascript:buscador.fichaTecnica.ocultarInfo();">';
			nuevo_listado += '<a id="pd.'+obj.id_comercio+'" href="javascript:void(0);" onclick="javascript:buscador.abrir(\'ficha\', {id_comercio: '+obj.id_comercio+'});">'+obj.nombre_abreviado+'</a>';
			nuevo_listado += '</li>';

			creados++;
		}

		$('sponsors_pm').update(nuevo_listado);
		menuListadoVertical.reset('pd');

		// ANUNCIOS
		var prefijo = 'li.anu.';
		var nuevo_listado = '';
		var style;

		// ANUNCIOS - ELIMINAR TODAS LAS OPCIONES DEL LISTADO ACTUAL
		var i = 0;
		while($(prefijo+i))
			$(prefijo+(i++)).remove();

		// ANUNCIOS - CREAR LOS NUEVOS ELEMENTOS QUE PASEN EL FILTRO
		var creados = 0;
		for (i=0; i<datos.extras.anuncios.length; i++) {
			var obj = datos.extras.anuncios[i];

			style = creados < buscador.numOpcMenuAnu ? '' : 'display: none;';

			nuevo_listado += '<li id="li.anu.'+creados+'" style="'+style+'">';
			nuevo_listado += '<a href="javascript:void(0);" onclick="javascript:buscador.anuncios.clic('+obj.id_anuncio+');buscador.abrir(\'carteleria\', {id_anuncio: '+obj.id_anuncio+', tipo: '+obj.tipo+', id_comercio: '+obj.id_comercio+', nombre: \''+addslashes(obj.nombre)+'\'});"><img id="anuncio.'+obj.id_anuncio+'" src="http://img.shio2e.com/n/buscador-anuncio_banner-'+obj.id_anuncio+'.png"></a>';
			nuevo_listado += '</li>';

			creados++;
		}

		$('pm_minibanners').update(nuevo_listado);
		menuListadoVertical.reset('anu');
	},

	mostrarMenu : function (selector_division, elemento){
		selector_division = typeof selector_division == "undefined" ? false : selector_division;
		elemento = typeof elemento == "undefined" ? 0 : parseInt(elemento);

		if (selector_division) {
			$('d_division').show();
		} else {
			$('d_division').hide();
		}

		$('pd_msg_liga').hide();
		$('pd_msg_division').hide();
		$('pd_menu').hide();

		switch(elemento){
			case 0:
				$('pd_msg_liga').show();
				break;
			case 1:
				$('pd_msg_division').show();
				break;
			case 2:
				$('pd_menu').show();
				break;
			default:
				alert('ERROR!!!');
		}
	},

	mostrarSeccion : function (seccion){
		// CAMBIAR FONDO DEL CUADRO
		if (typeof seccion != "undefined")
			$('cartel_pd_img').src = 'http://img.shio2e.com/n/buscador-anuncio-'+this.actual_anuncio+'-fondo.jpg';

		// OCULTAR TODAS LAS SECCIONES
		$(this.prefijo_div_seccion+'ultima_jornada').hide();
		$(this.prefijo_div_seccion+'proxima_jornada').hide();
		$(this.prefijo_div_seccion+'noticias').hide();
		$(this.prefijo_div_seccion+'clasificacion').hide();
		$(this.prefijo_div_seccion+'pichichi').hide();
		$(this.prefijo_div_seccion+'sanciones').hide();
		$(this.prefijo_div_seccion+'calendario').hide();
		$(this.prefijo_div_seccion+'equipos').hide();
		$(this.prefijo_div_seccion+'arbitros').hide();

		// MOSTRAR DIV DE LA SECCION A MOSTRAR
		if ($(this.prefijo_div_seccion+seccion))
			$(this.prefijo_div_seccion+seccion).show();

		// ESCRIBIR INFOLIGA
		if ($('infoliga_'+this.prefijo_div_seccion+seccion))
			$('infoliga_'+this.prefijo_div_seccion+seccion).update(this.getNombreLiga(this.actual_liga)+' - '+this.getNombreDivision(this.actual_division));

		// REGENERAR MENU
		$(this.prefijo_opc_menu+'ultima_jornada').className = '';
		$(this.prefijo_opc_menu+'proxima_jornada').className = '';
		$(this.prefijo_opc_menu+'noticias').className = '';
		$(this.prefijo_opc_menu+'clasificacion').className = '';
		$(this.prefijo_opc_menu+'pichichi').className = '';
		$(this.prefijo_opc_menu+'sanciones').className = '';
		$(this.prefijo_opc_menu+'calendario').className = '';
		$(this.prefijo_opc_menu+'equipos').className = '';
		$(this.prefijo_opc_menu+'arbitros').className = '';
		if ($(this.prefijo_opc_menu+seccion))
			$(this.prefijo_opc_menu+seccion).className = 'actual';

		// MOSTRAR CONTENIDO
		switch(seccion) {
			case 'ultima_jornada':
				this.mostrarSeccionUltimaJornada();
				break;
			case 'proxima_jornada':
				this.mostrarSeccionProximaJornada();
				break;
			case 'noticias':
				this.mostrarSeccionNoticias();
				break;
			case 'clasificacion':
				this.mostrarSeccionClasificacion();
				break;
			case 'pichichi':
				this.mostrarSeccionPichichi();
				break;
			case 'sanciones':
				this.mostrarSeccionSanciones();
				break;
			case 'calendario':
				this.mostrarSeccionCalendario();
				break;
			case 'equipos':
				this.mostrarSeccionEquipos();
				break;
			case 'arbitros':
				this.mostrarSeccionArbitros();
				break;
			default:
		}
	},

	mostrarSeccionArbitros : function (){
		var retorno = '';

		this.datos_liga_actual.arbitros.each(function(arbitro) {
			retorno += '<h3>'+arbitro.nombre+'</h3>';
			retorno += '<table cellspacing="10">';
			retorno += '<tr>';
			retorno += '<td><img src="http://img.shio2e.com/n/'+arbitro.imagen+'" alt="'+arbitro.nombre+'"/></td>';
			retorno += '<td valign="top">';
			retorno += '<b>Partidos arbitrados:</b> '+arbitro.partidos+'<br/>';
			retorno += '<b>Tarjetas amarillas mostradas:</b> '+arbitro.tarjetas_amarillas+'<br/>';
			retorno += '<b>Tarjetas rojas mostradas:</b> '+arbitro.tarjetas_rojas;
			retorno += '</td>';
			retorno += '</tr>';
			retorno += '</table>';
		}.bind(this));

		$('arbitros_pdt_arbitros').update(retorno);
	},

	mostrarSeccionCalendario : function (){
		var retorno = '';

		for (var i=1; i<=parseInt(this.datos_division.cantidad_jornadas); i++) {
			retorno += '<h3>Jornada '+i+'</h3>';
			retorno += '<table class="tabla_resultados" cellspacing="5">';
			retorno += this.getJornadaJugada(i);
			retorno += '</table>';
		}

		$('jornadas_pdt_calendario').update(retorno);
	},

	mostrarSeccionClasificacion : function (){
		var retorno = '';

		// CABECERA
		retorno += '<tr>';
		retorno += '	<th>Pos.</th>';
		retorno += '	<th class="equipo">Equipo</th>';
		retorno += '	<th>J</th>';
		retorno += '	<th>G</th>';
		retorno += '	<th>E</th>';
		retorno += '	<th>P</th>';
		retorno += '	<th>GF</th>';
		retorno += '	<th>GC</th>';
		retorno += '	<th>Dif</th>';
		retorno += '	<th>Ptos</th>';
		retorno += '</tr>';

		// EQUIPOS
		var posicion = 1;
		this.datos_division.equipos.each(function(equipo) {
			retorno += '<tr>';
			retorno += '	<td>'+(posicion++)+'</td>';
			retorno += '	<td class="equipo">'+equipo.nombre+'</td>';
			retorno += '	<td>'+equipo.partidos_jugados+'</td>';
			retorno += '	<td>'+equipo.partidos_ganados+'</td>';
			retorno += '	<td>'+equipo.partidos_empatados+'</td>';
			retorno += '	<td>'+equipo.partidos_perdidos+'</td>';
			retorno += '	<td>'+equipo.goles_favor+'</td>';
			retorno += '	<td>'+equipo.goles_contra+'</td>';
			retorno += '	<td>'+(parseInt(equipo.goles_favor)-parseInt(equipo.goles_contra))+'</td>';
			retorno += '	<td class="puntos">'+equipo.puntos+'</td>';
			retorno += '</tr>';
		}.bind(this));

		$('clasificacion').update(retorno);
	},

	mostrarSeccionEquipos : function (id_equipo, seccion){
		id_equipo = typeof id_equipo == "undefined" ? 0 : id_equipo;
		seccion = typeof seccion == "undefined" ? 'opciones' : seccion;

		if (id_equipo == 0) {
			this.mostrarSeccionEquiposListado();
		} else if (seccion == 'opciones') {
			this.mostrarSeccionEquiposOpciones(id_equipo);
		} else if (seccion == 'plantilla') {
			this.mostrarSeccionEquiposPlantilla(id_equipo);
		} else if (seccion == 'calendario') {
			this.mostrarSeccionEquiposCalendario(id_equipo);
		} else if (seccion == 'sanciones') {
			this.mostrarSeccionEquiposSanciones(id_equipo);
		}
	},

	mostrarSeccionEquiposListado : function (){
		var retorno = '';

		// H3
		$('infoequipo_pdt_equipos').hide();

		// EQUIPOS
		var equipos_mostrados = 0;
		this.datos_division.equipos.each(function(equipo) {
			if (equipos_mostrados % 2 == 0) retorno += '<tr>';
			retorno += '<td><a href="javascript:void(0);" onclick="javascript:buscador.anuncios.tipos.portalDeportivo.mostrarSeccionEquipos('+equipo.id+');">'+equipo.nombre+'</a></td>';
			if (equipos_mostrados % 2 == 1) retorno += '</tr>';
			equipos_mostrados++;
		}.bind(this));
		if (equipos_mostrados % 2 == 1) retorno += '<td></td></tr>';

		$('equipos').update(retorno);
	},

	mostrarSeccionEquiposOpciones : function (id_equipo){
		var retorno = '';
		var equipo = this.getEquipo(id_equipo);

		// H3
		$('infoequipo_pdt_equipos').show();
		$('infoequipo_pdt_equipos').update(equipo.nombre+'<span><a href="javascript:void(0);" onclick="javascript:buscador.anuncios.tipos.portalDeportivo.mostrarSeccionEquipos();">volver</a></span>');

		// OPCIONES
		retorno += '<tr><td>';
		retorno += '<a href="javascript:void(0);" onclick="javascript:buscador.anuncios.tipos.portalDeportivo.mostrarSeccionEquipos('+id_equipo+', \'plantilla\');">plantilla</a>';
		retorno += '</td></tr>';

		retorno += '<tr><td>';
		retorno += '<a href="javascript:void(0);" onclick="javascript:buscador.anuncios.tipos.portalDeportivo.mostrarSeccionEquipos('+id_equipo+', \'calendario\');">calendario</a>';
		retorno += '</td></tr>';

		retorno += '<tr><td>';
		retorno += '<a href="javascript:void(0);" onclick="javascript:buscador.anuncios.tipos.portalDeportivo.mostrarSeccionEquipos('+id_equipo+', \'sanciones\');">sanciones</a>';
		retorno += '</td></tr>';

		// WEB
		if (equipo.web != '') {
			retorno += '<tr>';
			retorno += '	<td class="web">Para más información, visita la web de <b>Los Falleros</b>: <a href="http://equipo.shio2e.com" target="_blank">http://equipo.shio2e.com</a></td>';
			retorno += '</tr>';
		}

		$('equipos').update(retorno);
	},

	mostrarSeccionEquiposPlantilla : function (id_equipo){
		var retorno = '';
		var equipo = this.getEquipo(id_equipo);

		// H3
		$('infoequipo_pdt_equipos').show();
		$('infoequipo_pdt_equipos').update(equipo.nombre+' - Plantilla<span><a href="javascript:void(0);" onclick="javascript:buscador.anuncios.tipos.portalDeportivo.mostrarSeccionEquipos('+id_equipo+');">volver</a></span>');

		// CABECERA
		retorno += '<tr>';
		retorno += '	<th class="jugador" style="text-align: left;">Jugador</th>';
		retorno += '	<th>Tarj. amar.</th>';
		retorno += '	<th>Tarj. rojas</th>';
		retorno += '	<th>Goles</th>';
		retorno += '</tr>';

		// EQUIPOS
		equipo.jugadores.each(function(jugador) {
			retorno += '<tr>';
			retorno += '	<td class="equipo">'+jugador.nombre+'</td>';
			retorno += '	<td>'+jugador.amarillas+'</td>';
			retorno += '	<td>'+jugador.rojas+'</td>';
			retorno += '	<td class="goles">'+jugador.goles+'</td>';
			retorno += '</tr>';
		}.bind(this));

		$('equipos').update(retorno);
	},

	mostrarSeccionEquiposCalendario : function (id_equipo){
		var retorno = '';
		var equipo = this.getEquipo(id_equipo);

		// H3
		$('infoequipo_pdt_equipos').show();
		$('infoequipo_pdt_equipos').update(equipo.nombre+' - Calendario<span><a href="javascript:void(0);" onclick="javascript:buscador.anuncios.tipos.portalDeportivo.mostrarSeccionEquipos('+id_equipo+');">volver</a></span>');

		// JORNADAS
		for (var i=1; i<=parseInt(this.datos_division.cantidad_jornadas); i++) {
			retorno += '<tr><td colspan="4">';
			retorno += '<h3>Jornada '+i+'</h3>';
			retorno += '<table class="tabla_resultados" cellspacing="5">';
			retorno += this.getJornadaJugada(i, id_equipo);
			retorno += '</table>';
			retorno += '</td></tr>';
		}

		$('equipos').update(retorno);
	},

	mostrarSeccionEquiposSanciones : function (id_equipo){
		var retorno = '', subretorno;
		var equipo = this.getEquipo(id_equipo);

		// H3
		$('infoequipo_pdt_equipos').show();
		$('infoequipo_pdt_equipos').update(equipo.nombre+' - Sanciones<span><a href="javascript:void(0);" onclick="javascript:buscador.anuncios.tipos.portalDeportivo.mostrarSeccionEquipos('+id_equipo+');">volver</a></span>');

		retorno += '<tr><td colspan="4">';

	////// SANCIONADOS
		retorno += '<h3>Jugadores sancionados</h3>';
		retorno += '<table class="tabla_sanciones">';

		subretorno = '';

		// CABECERA
		subretorno += '<tr>';
		subretorno += '	<th class="jugador" style="width:60%;">Jugador</th>';
		subretorno += '	<th>Sanc. hasta</th>';
		subretorno += '</tr>';

		// JUGADORES
		var posicion = 1, sancionados = 0;
		this.datos_division.sanciones.each(function(jugador) {
			if (parseInt(jugador.jornada_fin) >= (parseInt(this.datos_division.proxima_jornada) - 1) && parseInt(jugador.id_equipo) == id_equipo) {
				sancionados++;
				subretorno += '<tr>';
				subretorno += '	<td>'+jugador.nombre_jugador+'</td>';
				subretorno += '	<td>'+jugador.jornada_fin+'</td>';
				subretorno += '</tr>';
				subretorno += '<tr>';
				subretorno += '	<td colspan="2" class="motivo"><span>Motivo: </span>'+jugador.motivo+'</td>';
				subretorno += '</tr>';
			}
		}.bind(this));

		if (sancionados == 0) {
			subretorno = '';
			subretorno += '<tr>';
			subretorno += '	<td>Actualmente no hay ningún jugador sancionado.</th>';
			subretorno += '</tr>';
		}

		retorno += subretorno;
		retorno += '</table>';

	////// APERCIBIDOS
		retorno += '<h3>Jugadores apercibidos (una tarjeta amarilla acarrear&iacute;a sanci&oacute;n)</h3>';
		retorno += '<table class="tabla_sanciones">';

		subretorno = '';

		// JUGADORES
		var num_tarj_sancion = 3, apercibidos = 0;
		this.datos_division.equipos.each(function(equipo) {
			if (parseInt(equipo.id) == id_equipo)
				equipo.jugadores.each(function(jugador) {
					if (parseInt(jugador.amarillas) % num_tarj_sancion == (num_tarj_sancion - 1)) {
						apercibidos++;
						subretorno += '<tr>';
						subretorno += '	<td>'+jugador.nombre+'</td>';
						subretorno += '</tr>';
					}
				}.bind(this));
		}.bind(this));

		if (apercibidos == 0) {
			subretorno = '';
			subretorno += '<tr>';
			subretorno += '	<td>Actualmente no hay ningún jugador apercibido.</th>';
			subretorno += '</tr>';
		}

		retorno += subretorno;
		retorno += '</table>';
		retorno += '</td></tr>';

		$('equipos').update(retorno);
	},

	mostrarSeccionNoticias : function (){
		var retorno = '';

		this.datos_division.comunicaciones.each(function(noticia) {
			retorno += '<div class="pd_noticias">';
			retorno += '	<h3>';
			retorno += noticia.titulo;
			retorno += '	</h3>';
			retorno += '	<div class="pd_fecha_noticia">';
			retorno += '		Publicada el '+noticia.fecha;
			retorno += '	</div>';
			retorno += '	<div class="pd_body_noticia">';
			retorno += '		<p>'+noticia.texto+'</p>';
			retorno += '	</div>';
			retorno += '</div>';
		}.bind(this));

		$('noticias_pdt_noticias').update(retorno);
	},

	mostrarSeccionPichichi : function (){
		var retorno = '';

		// CABECERA
		retorno += '<tr>';
		retorno += '	<th>Pos.</th>';
		retorno += '	<th class="jugador">Jugador</th>';
		retorno += '	<th class="equipo">Equipo</th>';
		retorno += '	<th>Goles</th>';
		retorno += '</tr>';

		// EQUIPOS
		var posicion = 1;
		this.datos_division.pichichi.each(function(jugador) {
			retorno += '<tr>';
			retorno += '	<td>'+(posicion++)+'</td>';
			retorno += '	<td class="equipo">'+jugador.nombre+'</td>';
			retorno += '	<td>'+this.getNombreEquipo(jugador.id_equipo)+'</td>';
			retorno += '	<td class="goles">'+jugador.goles+'</td>';
			retorno += '</tr>';
		}.bind(this));

		$('pichichi').update(retorno);
	},

	mostrarSeccionProximaJornada : function (){
		var jornada_num = parseInt(this.datos_division.proxima_jornada);
		$('texto_proxima_jornada').update('Jornada '+jornada_num);
		$('tabla_proxima_jornada').update(this.getJornadaNoJugada(jornada_num));
	},

	mostrarSeccionSanciones : function (){
		var retorno;

	////// SANCIONADOS
		retorno = '';

		// CABECERA
		retorno += '<tr>';
		retorno += '	<th class="jugador">Jugador</th>';
		retorno += '	<th class="equipo">Equipo</th>';
		retorno += '	<th>Sanc. hasta</th>';
		retorno += '</tr>';

		// JUGADORES
		var posicion = 1, sancionados = 0;
		this.datos_division.sanciones.each(function(jugador) {
			if (parseInt(jugador.jornada_fin) >= (parseInt(this.datos_division.proxima_jornada) - 1)) {
				sancionados++;
				retorno += '<tr>';
				retorno += '	<td>'+jugador.nombre_jugador+'</td>';
				retorno += '	<td>'+this.getNombreEquipo(jugador.id_equipo)+'</td>';
				retorno += '	<td>'+jugador.jornada_fin+'</td>';
				retorno += '</tr>';
				retorno += '<tr>';
				retorno += '	<td colspan="3" class="motivo"><span>Motivo: </span>'+jugador.motivo+'</td>';
				retorno += '</tr>';
			}
		}.bind(this));

		if (sancionados == 0) {
			retorno = '';
			retorno += '<tr>';
			retorno += '	<td>Actualmente no hay ningún jugador sancionado.</th>';
			retorno += '</tr>';
		}

		$('sanciones').update(retorno);

	////// APERCIBIDOS
		retorno = '';

		// CABECERA
		retorno += '<tr>';
		retorno += '	<th width="50%">Jugador</th>';
		retorno += '	<th width="50%">Equipo</th>';
		retorno += '</tr>';

		// JUGADORES
		var num_tarj_sancion = 5, apercibidos = 0;
		this.datos_division.equipos.each(function(equipo) {
			equipo.jugadores.each(function(jugador) {
				if (parseInt(jugador.amarillas) % num_tarj_sancion == (num_tarj_sancion - 1)) {
					apercibidos++;
					retorno += '<tr>';
					retorno += '	<td>'+jugador.nombre_jugador+'</td>';
					retorno += '	<td>'+this.getNombreEquipo(jugador.id_equipo)+'</td>';
					retorno += '</tr>';
				}
			}.bind(this));
		}.bind(this));

		if (apercibidos == 0) {
			retorno = '';
			retorno += '<tr>';
			retorno += '	<td>Actualmente no hay ningún jugador apercibido.</th>';
			retorno += '</tr>';
		}

		$('apercibidos').update(retorno);
	},

	mostrarSeccionUltimaJornada : function (){
		var jornada_num = parseInt(this.datos_division.proxima_jornada) - 1;
		if (jornada_num <= 0) jornada_num = 1;
		$('texto_ultima_jornada').update('Jornada '+jornada_num);
		$('tabla_ultima_jornada').update(this.getJornadaJugada(jornada_num));
	},

	procesarFormularioInscripcion : function () {
		var id_formulario 	= 'formulario_inscripcion';
		var id_div_msg 		= 'msg_inscripcion_formulario';
		var id_error 		= 'error_inscripcion_';

		$(id_div_msg).show();
		$(id_div_msg).update('Enviando...');

		// GENERAR JSON DE LA INFORMACION DEL FORMULARIO
		var json = {};
		json.nombre = $(id_formulario).nombre.value;
		json.web = $(id_formulario).web.value;
		json.pc = {};
		json.pc.nombre = $(id_formulario).pc_nombre.value;
		json.pc.telefono = $(id_formulario).pc_telefono.value;
		json.pc.email = $(id_formulario).pc_email.value;
		json.jugadores = new Array();
		var i = 1, elemform, json_temp;
		while(eval('$(id_formulario).jugador'+i+'_dorsal')) {
			json_temp = {};
			json_temp.dorsal 	= eval('$(id_formulario).jugador'+i+'_dorsal.value');
			json_temp.nombre 	= eval('$(id_formulario).jugador'+i+'_nombre.value');
			json_temp.dni 		= eval('$(id_formulario).jugador'+i+'_dni.value');
			json_temp.email 	= eval('$(id_formulario).jugador'+i+'_email.value');
			json_temp.telefono 	= eval('$(id_formulario).jugador'+i+'_telefono.value');

			json.jugadores.push(json_temp);
			i++;
		}

		// CONSULTA AJAX
		new Ajax.Request('/exec/ajax/carteleria_pd_inscripcion.php', {
			parameters: {
				json: encodeURIComponent(Object.toJSON(json))
			},
			onSuccess: function(respuesta) {
				/*$(id_error+'nombre').hide();
				$(id_error+'email').hide();
				$(id_error+'tipo').hide();
				$(id_error+'descripcion').hide();*/

				if (respuesta.responseText != 'ok') {
					$(id_div_msg).update('Revisa que los datos sean correctos.');
					if (respuesta.responseText.startsWith('errores-')) {
						respuesta.responseText.split('-').each(function(nombre, posicion) {
						  if ($(id_error+nombre)) $(id_error+nombre).show();
						});
					}
				} else {
					buscador.anuncios.abrirSeccion('inscripcion_ok');
					$(id_div_msg).update('');
				}
			}
		});
	}
}
