var wh;
var pe;
	
	function cortaCadena(cadena,maximo){
		if(cadena.length > maximo){
			return cadena.substring(0,maximo - 1) + '...';
		}
		else{
			return cadena;
		}
	}
	
	function iniciar(tipoWidget){
		wh = new WidgetHoy(tipoWidget);
	}
	
	function registrarVisita(ip, script_name, referer, dominio_referer ) {
	    var url = "/widgets/widget_visita.php";
	    var myAjax = new Ajax.Request(url, {
	        method: "get",
	        parameters: {
	            'ip'				: ip,
				'script_name'		: script_name,
				'referer' 			: referer,
				'dominio_referer' 	: dominio_referer
				        },
	        onComplete: function(t){ 
//				        	alert(t.responseText);
				        }
	    });
	}
	
	function cargarPartidos(){
		wh.cargarPartidos();
	}

	function ordenarPartidos(a,b){
		if(parseFloat(a.prioridad) < parseFloat(b.prioridad)) return -1;
		else if(parseFloat(a.prioridad) > parseFloat(b.prioridad)) return 1;
		else if(parseInt(a.orden) < parseInt(b.orden)) return -1;
		else if(parseInt(a.orden) > parseInt(b.orden)) return 1;
		else if(a.starTime < b.starTime) return -1;
		else if(a.starTime > b.starTime) return 1;
		else return 0;
	}
	
	function ordenarPartidosTenis(a,b){
		if(a.country < b.country) return -1;
		if(a.country > b.country) return 1;
		else if(a.league < b.league) return -1;
		else if(a.league > b.league) return 1;
		else if(a.starTime < b.starTime) return -1;
		else if(a.starTime > b.starTime) return 1;
		else return 0;
	}
	
var WidgetHoy = Class.create({
	tipoWidget: null,
	deporte: null,
	numHuecos: null,
	gmt: null,
	
	offsetPartidos: null,
	offsetMasculino: null,
	offsetFemenino: null,
	offsetDobles: null,

	destinoLink: null,
	destinoClasif: null,

	pantalla: null,
	iteracion: null,
	numCargasAjax: null,
	iteracionCambiarPantalla: null,
	numPantallasPorRefresco: null,
	cargando: false,
	
	fecha: null,
	jugadorComodin: 6780,
	
	initialize: function(tipoWidget){
		
		var d = new Date();
		this.gmt = d.getTimezoneOffset();
		
		this.tipoWidget = tipoWidget;
		switch(this.tipoWidget){
			case 1: this.numHuecos = 11; break;
			case 2: this.numHuecos = 13; break;
			case 3: this.numHuecos = 12; break;
			case 4: this.numHuecos = 12; break;
		}

		this.offsetPartidos = 0;
		this.offsetMasculino = 0;
		this.offsetFemenino = 0;
		this.offsetDobles = 0;

		this.iteracion = 0;
		this.pantalla = 0;
		this.iteracionCambiarPantalla = 0;
		this.numPantallasPorRefresco = $F('pantallasRefrescoHid');
		this.numCargasAjax = 0;

		this.deporte = 'SOC';
		this.destinoLink = 'http://www.marcadoresonline.com/?rf='+$('refererHid').value;
		this.destinoClasif = 'http://www.marcadoresonline.com/clasificacion.php?rf='+$('refererHid').value;
		if($('deporteHid').value != ''){
			this.deporte = $('deporteHid').value;
		}
		this.fecha = $('fechasHid').value;
		this.cambiarDeporte(this.deporte)
	},
	
	resetPeriodicalExecuter: function(){
		this.iteracion = 0;
		this.pantalla = 0;
		this.iteracionCambiarPantalla = 0;
		this.cargando = false;
		this.offsetPartidos = 0;
		this.offsetMasculino = 0;
		this.offsetFemenino = 0;
		if(pe != null){
			pe.stop();
		}
		pe = new PeriodicalExecuter(cargarPartidos,5);
	},
	
	cambiarLiga: function(deporte){
		var tiposBotones = ['','Uno','Dos','Tres','Cuatro'];
		$('ft_hoy').className = 'bt_inicio_' + tiposBotones[this.tipoWidget];
		$('ft_cham').className = 'bt_Bundes_' + tiposBotones[this.tipoWidget];
		$('bk_hoy').className = 'bt_inicio_' + tiposBotones[this.tipoWidget];
		$('bk_nba').className = 'bt_inicio_' + tiposBotones[this.tipoWidget];
		$('bk_euro').className = 'bt_Bundes_' + tiposBotones[this.tipoWidget];
		switch(deporte){
			case 'SOC': $('ft_hoy').className = 'bt_inicio_' + tiposBotones[this.tipoWidget] + 'Activo'; break;
			case 'CHAMPIONS': $('ft_cham').className = 'bt_Bundes_' + tiposBotones[this.tipoWidget] + 'Activo'; break;
			case 'BSK': $('bk_hoy').className = 'bt_inicio_' + tiposBotones[this.tipoWidget] + 'Activo'; break;
			case 'NBA': $('bk_nba').className = 'bt_inicio_' + tiposBotones[this.tipoWidget] + 'Activo'; break;
			case 'EUROLIGA': $('bk_euro').className = 'bt_Bundes_' + tiposBotones[this.tipoWidget] + 'Activo'; break;
		}
	},

	verLiga: function(nombreLiga){
		switch(nombreLiga){
			case '': 		return; break;
			case 'OTRAS':	window.open(this.destinoLink,'_blank');	return; break;
			case 'EUROPA LEAGUE': case 'EUROCHALLENGE':	this.cambiarDeporte(nombreLiga); break;
			default: document.location.href = 'http://www.marcadoresonline.com/widgets/widget'+((this.tipoWidget>1)?this.tipoWidget:'')+'.php?mantenerse=si&liga='+nombreLiga;
		}
	},
	
	cambiarDeporte: function(deporte){
		this.deporte = deporte;
		this.resetPeriodicalExecuter();

		var divFutbol = 'submenu';
		var divBaloncesto = 'submenuBsk';
		var divTenis = 'submenuTns';
		var divBotonFutbol = 'btFutbol';
		var divBotonBsk = 'btBsk';
		var divBotonTenis = 'btTns';
		var tiposBotones = ['','Uno','Dos','Tres','Cuatro'];
		var tiposSubmenus = ['','Uno','Dos','Tres','Cuatro']; 

		switch(this.deporte){
			case 'SOC': case 'CHAMPIONS': case 'EUROPA LEAGUE':
				this.destinoLink = 'http://www.marcadoresonline.com/?rf='+$('refererHid').value;
				/*if(this.deporte == 'SOC')*/	this.destinoClasif = 'http://www.marcadoresonline.com/clasificacion.php?rf='+$('refererHid').value;
				//else						this.destinoClasif = 'http://www.marcadoresonline.com/clasificacion.php?torneo=20209&rf='+$('refererHid').value;
				$(divFutbol + tiposSubmenus[this.tipoWidget]).setStyle({'display' : 'block'});
				$(divBaloncesto+tiposSubmenus[this.tipoWidget]).setStyle({'display': 'none'});
				$(divTenis+tiposSubmenus[this.tipoWidget]).setStyle({'display': 'none'});
				$(divBotonFutbol).className = 'btFutbol' + tiposBotones[this.tipoWidget] +  'Activo';
				$(divBotonBsk).className = 'btBsk' + tiposBotones[this.tipoWidget];
				$(divBotonTenis).className = 'btTns' + tiposBotones[this.tipoWidget];
				break;
			case 'BSK': case 'NBA': case 'EUROLIGA': case 'EUROCHALLENGE':
				this.destinoLink = 'http://www.marcadoresonline.com/basket.php?rf='+$('refererHid').value;
				/*if(this.deporte == 'BSK') */	this.destinoClasif = 'http://www.marcadoresonline.com/clasificacion.php?deporte=3&rf='+$('refererHid').value;
				//else						this.destinoClasif = 'http://www.marcadoresonline.com/clasificacion.php?deporte=3&torneo=20821&rf='+$('refererHid').value;
				$(divFutbol + tiposSubmenus[this.tipoWidget]).setStyle({'display' : 'none'});
				$(divBaloncesto+tiposSubmenus[this.tipoWidget]).setStyle({'display': 'block'});
				$(divTenis+tiposSubmenus[this.tipoWidget]).setStyle({'display': 'none'});
				$(divBotonFutbol).className = 'btFutbol' + tiposBotones[this.tipoWidget];
				$(divBotonBsk).className = 'btBsk' + tiposBotones[this.tipoWidget] + 'Activo';
				$(divBotonTenis).className = 'btTns' + tiposBotones[this.tipoWidget];
				break;
			case 'TEN':
				this.destinoLink = 'http://www.marcadoresonline.com/tenis.php?rf='+$('refererHid').value;
				this.destinoClasif = 'http://www.marcadoresonline.com/clasificacion.php?deporte=2&rf='+$('refererHid').value;
				$(divFutbol + tiposSubmenus[this.tipoWidget]).setStyle({'display' : 'none'});
				$(divBaloncesto + tiposSubmenus[this.tipoWidget]).setStyle({'display': 'none'});
				$(divTenis+tiposSubmenus[this.tipoWidget]).setStyle({'display': 'block'});
				$(divBotonFutbol).className = 'btFutbol' + tiposBotones[this.tipoWidget];
				$(divBotonBsk).className = 'btBsk' + tiposBotones[this.tipoWidget];
				$(divBotonTenis).className = 'btTns' + tiposBotones[this.tipoWidget] + 'Activo';
				break;
		}
		this.cambiarLiga(deporte);
		this.cargarPartidos();
	},
	
	/* estas funciones ya no se utilizan
	verDiaAnterior: function(){
		this.fecha--;
		this.resetPeriodicalExecuter();
		this.cargarPartidos();
	},
	
	verDiaSiguiente: function(){
		this.fecha++;
		this.resetPeriodicalExecuter();
		this.cargarPartidos();
	}, */
	
	verDiaSelect: function(value){
		this.fecha = value;
		//$('fechasHid').value = value;
		//$('fechasHid').value = $('select2').value;
		this.resetPeriodicalExecuter();
		this.cargarPartidos();
	},
	
	cargarPartidos: function(){
		if(this.iteracion == this.iteracionCambiarPantalla){
			if(this.pantalla % this.numPantallasPorRefresco == 0){
				this.numCargasAjax++;
				if(this.numCargasAjax == 1 && this.deporte == 'SOC'){
					this.mostrarPartidos(partidosInicial);
					this.iteracion++;
					this.pantalla++;
					this.cargando = false;
				}
				else{
					if(this.cargando)	return;
					var inicialSN; var deporte; var fecha;
					if(this.iteracion > 0){
						inicialSN = 1;
						fecha = this.fecha;
						switch(this.deporte){
							case 'SOC': case 'CHAMPIONS': case 'EUROPA LEAGUE':						deporte = 'SOC'; break;
							case 'BSK': case 'NBA':		  case 'EUROLIGA':	case 'EUROCHALLENGE':	deporte = 'BSK'; break;
							case 'TEN': 															deporte = 'TEN'; break;
						}
					}
					else{
						inicialSN = 0;
						fecha = this.fecha;
						deporte = this.deporte;
					}
					var url;
					if(fecha == $F('hoyHid') && deporte == 'SOC' && inicialSN == 0){
						url = '/widgets/includes/partidos_hoy.html';
					}else if(fecha == $F('hoyHid') && deporte == 'SOC' && inicialSN == 1){
						url = '/widgets/includes/partidos_hoy_cambios.html';
					}else{
						url = '/widgets/includes/obtenerPartidosWidgetDiarios.php';
					} 
					var pars = {
						'deporte': deporte, 
						'gmtCliente': this.gmt,
						'fecha': fecha, // this.fecha,
						'time': Math.random(),
						'inicialSN': inicialSN //(this.iteracion>0)?1:0
					};
					this.cargando = true;
					var myAjax = new Ajax.Request(url, {
						method: "get",
						parameters: pars,
						//onLoading: $('bannerMarcadores').update('<img src="/img/loading.gif" class="cargando" />'),
						onComplete: function(transport){
							wh.mostrarPartidos(transport.responseText.evalJSON());
							wh.iteracion++;
							wh.pantalla++;
							wh.cargando = false;
						}
					});			
				}
			}
			else{
				this.recalcularOffsetListas();
				this.generarHTMLPartidos();
				this.iteracion++;
				this.pantalla++;
			}
		}
		else{
			this.iteracion++;
		}
	},
	
	recargarDatos: function(responseList){
		var i; var j;
		// calcular la hora de los partidos segun la configuracion GMT del cliente, y quedarnos solo
		// con los partidos que correspondan al dia seleccionado
		var listaAux = responseList;
		var nuevaLista = new Array();
		for(i = 0; i < listaAux.length; i++){
			var st = listaAux[i].starTime;
			var fecha = new Date(st.substring(0,4),st.substring(5,7)-1,st.substring(8,10),
					st.substring(11,13),st.substring(14,16) - this.gmt,st.substring(17));
			var anyoLocal = fecha.getFullYear();
			var mesLocal = fecha.getMonth() + 1;	if(mesLocal < 10) 	mesLocal = "0" + mesLocal;
			var diaLocal = fecha.getDate();			if(diaLocal < 10)	diaLocal = "0" + diaLocal;
			var horaLocal = fecha.getHours();		if(horaLocal < 10)	horaLocal = "0" + horaLocal;
			var minLocal = fecha.getMinutes();		if(minLocal < 10)	minLocal = "0" + minLocal;
			listaAux[i].starTime = anyoLocal + "-" + mesLocal + "-" + diaLocal + " " + horaLocal + ":" + minLocal + ":00";
			if(anyoLocal + "-" + mesLocal + "-" + diaLocal == this.fecha){
				nuevaLista.push(listaAux[i]);		//this.listaPartidos.push(listaAux[i]);
			}
			//alert(st + "\n" + listaAux[i].starTime + "\n" + 
			//	anyoLocal + "-" + mesLocal + "-" + diaLocal + "==" + this.fecha +
			//	(anyoLocal + "-" + mesLocal + "-" + diaLocal == this.fecha));
		}

		if(this.iteracion == 0){
			this.listaPartidos = nuevaLista;
		}
		else{ // mixear las dos listas
			//var nuevaLista = responseText.evalJSON();
			for(i = 0; i < nuevaLista.length; i++){
				for(j = 0; j < this.listaPartidos.length && this.listaPartidos[j].id != nuevaLista[i].id; j++);
				if(j < this.listaPartidos.length){
					this.listaPartidos[j] = nuevaLista[i];
				}
				else{
					//this.listaPartidos.push(nuevaLista[i]);
				}
			}
		}
		if(this.deporte == 'TEN')		this.listaPartidos.sort(ordenarPartidosTenis);
		else							this.listaPartidos.sort(ordenarPartidos);
		if(this.deporte == 'TEN'){
			for(i = 0; i < this.listaPartidos.length; i++){
				var p = this.listaPartidos[i];
				if(p.country == 'wta-d'){
					p.country = 'dobles';
					p.league = 'F ' + p.league;
				}
				else if(p.country == 'atp-d'){
					p.country = 'dobles';
					p.league = 'M ' + p.league;
				}	
			}
		}
		
	},
	
	recalcularOffsetListas: function(){
		this.offsetPartidos += this.numHuecos;
		if((this.offsetPartidos >= 3 * this.numHuecos) || (this.offsetPartidos >= this.listaPartidos.length)){
			this.offsetPartidos = 0;
		}
	},
	
	mostrarPartidos: function(responseList){ 
		this.recargarDatos(responseList);
		if(this.iteracion > 1){ // en la primera no
			this.recalcularOffsetListas();
		}
		this.generarHTMLPartidos();
	},

	generarHTMLPartido: function(p){
		var duracionPantalla;
		if(p.prioridad <= 0)										duracionPantalla = 2;
		else if(parseInt(p.orden) <= 6 && p.statusType == 'live')	duracionPantalla = 4;
		else if(parseInt(p.orden) <= 6)								duracionPantalla = 3;
		else														duracionPantalla = 2;

		if( this.iteracion + duracionPantalla > this.iteracionCambiarPantalla)
			this.iteracionCambiarPantalla = this.iteracion + duracionPantalla;
		
		var html = '';
				var fechaTrozos = p.fecha.split('-');
				var starTimeTrozos = p.starTime.split(' ');
				
				var claseFila;
				var claseResultado;
				var estado;
				switch(p.statusType){
					case 'sched': 
						estado = 'Pdt'; 
						claseFila = 'fondoTabla';
						claseResultado = 'resultado';
						break;
					case 'live': 
						estado = p.minutoFutbol + "'"; 
						claseFila = 'vivo';
						claseResultado = 'resultadoVivo';
						break;
					case 'fin': 
						estado = p.status.substring(0,4); 
						claseFila = 'fondoTablaFinal';
						claseResultado = 'resultadoFinalTabla';
						break;
				}
				
				var numLetras = [
					[0,15,8,16,14],// futbol
					[0,14,6,16,13]//bsk
					];

				var resultado; var deporteInt;
				switch(p.codeSport){
					case 'SOC': resultado = p.socCurrent; deporteInt = 0; break;
					case 'BSK': resultado = p.bskCurrent; deporteInt = 1; break;
					case 'TEN': resultado = p.tenCurrent; break;
				}
				if(p.statusType == 'sched' || p.status == 'Post')	resultado = '-';
				if(this.tipoWidget == 2 && resultado != null){
					resultado = resultado.replace(/ /g,'');
				}

				var destino = this.destinoLink;
				if(p.url_partido != null) destino = p.url_partido;
				html += 
				     '<tr class="' + claseFila + '">' +
				       '<td><span class="comunes_paises '+p.bandera+'" title="'+p.country+' '+p.league+'" >&nbsp;</span></td>' +
				       '<td>' + starTimeTrozos[1].substring(0,5) + '</td>' +
				       '<td class="txtDch"><a onclick="clicWidget();" target="_blank" title="'+p.n_eHome+'" href="'+destino+'">' + 
					   		p.n_eHome.substring(0,numLetras[deporteInt][this.tipoWidget]) + '</a></td>' +
				       '<td class="'+claseResultado+'"><a onclick="clicWidget();" class="linkResultado" target="_blank"  href="'+destino+'">' + 
					   	((resultado==null)?'-':resultado) + 
					   '</a></td>' +
				       '<td class="txtIzq"><a onclick="clicWidget();" target="_blank" title="'+p.n_eAway+'" href="'+destino+'">' + 
					   		p.n_eAway.substring(0,numLetras[deporteInt][this.tipoWidget]) + '</a></td>' +
				       '<td>' + estado + '</td>' +
				     '</tr>';
	
		return html;
	},	

	indexTablaPartido: function(i){
		switch(this.tipoWidget){
			case 1: return 0; 
			case 2: return 0;
			case 3: return (i>=6)?1:0;
			case 4: return (i<12)?parseInt(i/4):2;
		}
	},

	generarHTMLPartidoTenis: function(p){
		var html = '';
		var fechaTrozos = p.fecha.split('-');
		var starTimeTrozos = p.starTime.split(' ');
				
		var claseFila;
		var claseResultado;
		var estado;
		var setActual;
		switch(p.statusType){
			case 'sched': 
				estado = 'Pdt'; 
				claseFila = 'fondoTabla';
				claseResultado = 'resultado';
				setActual = '';
				break;
			case 'live': 
				estado = p.status; 
				claseFila = 'vivo';
				claseResultado = 'resultadoVivo';
				setActual = eval ('p.s' + p.status.substring(3)); 
				if(setActual == undefined) setActual = '';
				break;
			case 'fin': 
				//alert ('$' + p.s1 + '$' +p.s2 +'$' +p.s3 +'$' +p.s4 +'$' +p.s5 + '$');
				if(p.s5 != '0-0')		setActual = p.s5; 
				else if(p.s4 != '0-0')	setActual = p.s4;
				else if(p.s3 != '0-0') 	setActual = p.s3;
				else if(p.s2 != '0-0')	setActual = p.s2;
				else					setActual = p.s1;
				estado = p.status.substring(0,3); 
				claseFila = 'fondoTablaFinal';
				claseResultado = 'resultadoFinalTabla';
				break;
		}
		
		var numLetras;
		switch(this.tipoWidget){
			case 1: numLetras = 16; break;
			case 2: numLetras = 8; break;
			case 3: numLetras = 16; break;
			case 4: numLetras = 13; break;
		}

		var resultado = p.tenCurrent;
		if(p.statusType == 'sched')	resultado = '-';

		var html = 
			'<tr class="'+ claseFila + '">' +
				'<td>'+ starTimeTrozos[1].substring(0,5) +'</td>' +
				'<td class="txtDch"><a onclick="clicWidget();" target="_blank" title="'+p.n_eHome+'" href="'+this.destinoLink+'">'+ 
					p.n_eHome.substring(0,numLetras)+'</a></td>' +
				'<td class="resultado"><a onclick="clicWidget();" class="linkResultado" target="_blank" href="'+this.destinoLink+'">'+
					((resultado==null)?'-':resultado) +  '</a></td>' +
				'<td class="txtIzq"><a onclick="clicWidget();" target="_blank" title="'+p.n_eAway+'" href="'+this.destinoLink+'">'+
					p.n_eAway.substring(0,numLetras)+'</a></td>' +
		  		'<td>'+ setActual +'</td>' +
				'<td>' + estado + '</td>' +
			'</tr>';
		return html;
	},

	generarHTMLPartidosTenis: function(tipo){
		var maxFilas = [0,5,5,5,4];
		var tipos = ['','','Dos','Tres','Cuatro'];
		var col_hora = 	[0,30,28,30,30];
		var col_jug1 = 	[0,96,53,96,110];
		var col_res = 	[0,25,27,25,25];
		var col_jug2 =	[0,96,53,96,110];
		var col_set = 	[0,22,20,22,22];
		var col_info = 	[0,0,0,0,0];
		
		//var offset = (tipo == 'masculino')?this.offsetMasculino:this.offsetFemenino;
		//var country = (tipo == 'masculino')?'atp-s':'wta-s';
		var league = null; 

		var i; var huecosCompletados; var htmlFilas = '';
		var offset; 		var country; var cabecera;
		switch(tipo){
			case 'masculino':	country = 'atp-s'; 	offset = this.offsetMasculino; 	cabecera = 'Masculino'; 	break;
			case 'femenino':	country = 'wta-s'; 	offset = this.offsetFemenino;  	cabecera = 'Femenino'; 		break;
			case 'dobles':		country = 'dobles';	offset = this.offsetDobles;  	cabecera = 'Dobles'; 	break;
		}
		
		for(i = offset; i < this.listaPartidos.length && this.listaPartidos[i].country != country; i++);
		if(i >= this.listaPartidos.length)
			for(i = 0; i < this.listaPartidos.length && this.listaPartidos[i].country != country; i++);
		for(huecosCompletados = 0; 
				i < this.listaPartidos.length && huecosCompletados < maxFilas[this.tipoWidget] &&
				this.listaPartidos[i].country == country && (league == null || league == this.listaPartidos[i].league ); 
		i++){
			var p = this.listaPartidos[i];
			if(this.jugadorComodin != parseInt(p.id_eHome) && this.jugadorComodin != parseInt(p.id_eAway)){
				htmlFilas += this.generarHTMLPartidoTenis(p,tipo);
				huecosCompletados++;
				if(league == null)			league = p.league;
			}
		}
		if(tipo == 'masculino')		this.offsetMasculino = (i < this.listaPartidos.length)?i:0;
		else if(tipo == 'femenino')	this.offsetFemenino = (i < this.listaPartidos.length)?i:0;
		else if(tipo == 'dobles')	this.offsetDobles = (i < this.listaPartidos.length)?i:0;
		var numLetrasTorneo = [0,23,16,23,23];
		var html = 
			'<table class="tenis'+tipos[this.tipoWidget]+'">' +
			    '<colgroup width="'+col_hora[this.tipoWidget]+'" span="1"></colgroup>' +
			    '<colgroup width="'+col_jug1[this.tipoWidget]+'" span="1"></colgroup>' +
			    '<colgroup width="'+col_res[this.tipoWidget]+'" span="1"></colgroup>' +
			    '<colgroup width="'+col_jug2[this.tipoWidget]+'" span="1"></colgroup>' +
			    '<colgroup width="'+col_set[this.tipoWidget]+'" span="1"></colgroup>' +
			    '<colgroup width="'+col_info[this.tipoWidget]+'" span="1"></colgroup>' +
			    '<tr>' +
			    	'<td colspan="4" scope="col"class="torneos_Tenis_izq">TORNEO:'+((league==null)?'':league.substring(0,numLetrasTorneo[this.tipoWidget]))+'</td>' +
			        '<td colspan="2" scope="col" class="torneos_Tenis_dch">'+cabecera+'</td>' +
			    '</tr>' +
			    '<tr>' +
			    	'<th class="celdaAzulOscuro" scope="col">HORA</th>' +
			    	'<th colspan="3" scope="col" class="celdaAzul">&nbsp;</th>' +
			    	'<th class="celdaAzulOscuro" scope="col">SET</th>' +
			    	'<th class="celdaAzulOscuro" scope="col">INFO</th>' +
			    '</tr>' +
				htmlFilas;
				
		for( i = huecosCompletados ; i < maxFilas[this.tipoWidget]; i++){
			if( i == 0){
				html += '<tr class="fondoTabla"><td colspan="6">No hay partidos para la fecha seleccionada</td></tr>';
			}
			else{
				html += 
					'<tr class="fondoTabla">' + 
						'<td>&nbsp;</td>' + 
						'<td>&nbsp;</td>' + 
						'<td class="resultado">&nbsp;</td>' + 
						'<td>&nbsp;</td>' + 
						'<td>&nbsp;</td>' + 
						'<td>&nbsp;</td>' + 
					'</tr>';
			}
		}

		html +=	'</table>';
		return html;
	},
	
	generarHTMLPartidosFutBsk: function(){
		var i;
		var htmlInicio = ''; var desplegableFechas = ''; var htmlInicio2 = '';
		var htmlCabeceraOk;
		var htmlCabeceraVacia;
		var htmlCuerpo = new Array(); htmlCuerpo.push('');htmlCuerpo.push('');htmlCuerpo.push('');
		var htmlFin = '';
		var htmlPie = new Array(); htmlPie.push('');htmlPie.push('');htmlPie.push('');
		var tablaVacia = new Array(); tablaVacia.push(true);tablaVacia.push(true);tablaVacia.push(true);
		
		if(this.listaPartidos.length == 0){
			var noPartidos = '<table id="noPartidos">'+
				'<tr>' + 
					'<td>No hay partidos para la fecha seleccionada</td>' +
					 '<td><select name="select" size="1" id="selecFecha" class="select_fecha" onchange="javascript:wh.verDiaSelect(this.value);">'+
					   	$('fechasHid').innerHTML +
					   '</select></td>' + 
				'</tr></table>';
			if(this.tipoWidget == 1){
				$('tablaWidget').update(noPartidos);
			}
			else{
				$('tablaWidget0').update(noPartidos);
			}
			if(this.tipoWidget == 3) {
				$('tablaWidget1').update('<table><tr><td></td></tr></table>');
			}
			if(this.tipoWidget == 4){
				$('tablaWidget1').update('<table><tr><td></td></tr></table>');
				$('tablaWidget2').update('<table><tr><td></td></tr></table>');
			}
		}
		else{
			//var fechaTrozos = this.listaPartidos[0].fecha.split('-');
			//var fechaTrozos = this.listaPartidos[0].fecha.split('-');
			var deporteInt;//= (this.deporte == 'SOC')?0:1;
			switch(this.deporte){
				case 'SOC': case 'CHAMPIONS': case 'EUROPA LEAGUE':	deporteInt = 0; break;
				case 'BSK': case 'NBA':		  case 'EUROLIGA':	case 'EUROCHALLENGE':	deporteInt = 1; break;
			} 
			switch(this.tipoWidget){
				case 1:
				var columnas = [	
					[26,28,90,29,90,15],
					[26,28,83,45,83,15]
				];
				htmlInicio += 
				'<table>' + 
					'<colgroup width="'+columnas[deporteInt][0]+'" span="1"> </colgroup>' +
					'<colgroup width="'+columnas[deporteInt][1]+'" span="1"> </colgroup>' +
					'<colgroup width="'+columnas[deporteInt][2]+'" span="1"> </colgroup>' +
					'<colgroup width="'+columnas[deporteInt][3]+'" span="1"> </colgroup>' +
					'<colgroup width="'+columnas[deporteInt][4]+'" span="1"> </colgroup>' + 
					'<colgroup width="'+columnas[deporteInt][5]+'" span="1"> </colgroup>' + 
					'<tr>' + 
						'<th class="celdaAzulOscuro" scope="col">PAIS</th>' + 
						'<th class="celdaAzulOscuro" scope="col">HORA</th>' + 
						'<th colspan="3" scope="col" class="celdaAzul">'+
						  '<select  name="select" size="1" id="selecFecha" class="select_fecha" onchange="javascript:wh.verDiaSelect(this.value);">'+
						   	$('fechasHid').innerHTML +
						   '</select>' +
						'</th>' + 
						'<th class="celdaAzulOscuro" scope="col">TMP</th>' + 
					'</tr>'
				      
				break;
				case 2:
				var columnas = [	
					[22,29,56,29,56,15],
					[22,29,46,42,46,15]
				];
				htmlInicio += 
				'<table>' + 
					'<colgroup width="'+columnas[deporteInt][0]+'" span="1"> </colgroup>' + 
					'<colgroup width="'+columnas[deporteInt][1]+'" span="1"> </colgroup>' + 
					'<colgroup width="'+columnas[deporteInt][2]+'" span="1"> </colgroup>' + 
					'<colgroup width="'+columnas[deporteInt][3]+'" span="1"> </colgroup>' + 
					'<colgroup width="'+columnas[deporteInt][4]+'" span="1"> </colgroup>' + 
					'<colgroup width="'+columnas[deporteInt][5]+'" span="1"> </colgroup>' + 
		    
					'<tr>' + 
						'<th class="celdaAzulOscuro" scope="col">PAIS</th>' + 
						'<th class="celdaAzulOscuro" scope="col">HR</th>' + 
						'<th colspan="3" class="celdaAzul" scope="col">'+
						'<select  name="select" size="1" id="selecFecha" class="select_fecha" onchange="javascript:wh.verDiaSelect(this.value);">'+
						   $('fechasHid').innerHTML +
						'</select>' +
					    '</th>' + 
						'<th class="celdaAzulOscuro" scope="col">TMP</th>' + 
					'</tr>';
				break;
				case 3:
				var columnas = [	
					[20,28,98,29,98,15],
					[20,28,90,42,90,15]
				];
				htmlInicio += 
				'<table>' + 
				    '<colgroup width="'+columnas[deporteInt][0]+'" span="1"> </colgroup>' + 
			        '<colgroup width="'+columnas[deporteInt][1]+'" span="1"> </colgroup>' + 
			        '<colgroup width="'+columnas[deporteInt][2]+'" span="1"> </colgroup>' + 
			        '<colgroup width="'+columnas[deporteInt][3]+'" span="1"> </colgroup>' + 
			        '<colgroup width="'+columnas[deporteInt][4]+'" span="1"> </colgroup>' + 
			        '<colgroup width="'+columnas[deporteInt][5]+'" span="1"> </colgroup>' + 
			        '<tr>' + 
			          '<th class="celdaAzulOscuro" scope="col">PAIS</th>' + 
			          '<th class="celdaAzulOscuro" scope="col">HORA</th>' + 
			          '<th colspan="3" scope="col" class="celdaAzul">';
					  
				desplegableFechas =
						   '<select  name="select" size="1" id="selecFecha" class="select_fecha" onchange="javascript:wh.verDiaSelect(this.value);">'+
						   		$('fechasHid').innerHTML +
						   '</select>';

				htmlInicio2 =
						'</th>' +  
			          '<th class="celdaAzulOscuro" scope="col">TMP</th>' + 
			        '</tr>';
				break;
				case 4:
				var columnas = [	
					[25,36,100,45,100,15],
					[25,36,100,45,100,15]
				];
				htmlInicio += 
				'<table>' + 
					'<colgroup width="'+columnas[deporteInt][0]+'" span="1"> </colgroup>' + 
					'<colgroup width="'+columnas[deporteInt][1]+'" span="1"> </colgroup>' + 
					'<colgroup width="'+columnas[deporteInt][2]+'" span="1"> </colgroup>' + 
					'<colgroup width="'+columnas[deporteInt][3]+'" span="1"> </colgroup>' + 
					'<colgroup width="'+columnas[deporteInt][4]+'" span="1"> </colgroup>' + 
					'<colgroup width="'+columnas[deporteInt][5]+'" span="1"> </colgroup>' + 

			        '<tr>' + 
			          '<th class="celdaAzulOscuro" scope="col">PAIS</th>' + 
			          '<th class="celdaAzulOscuro" scope="col">HORA</th>' + 
			          '<th colspan="3" scope="col" class="celdaAzul">';
				desplegableFechas = 
						   '<select  name="select" size="1" id="selecFecha" class="select_fecha" onchange="javascript:wh.verDiaSelect(this.value);">'+
						   		$('fechasHid').innerHTML +
						   '</select>';
				htmlInicio2 =
						'</th>' +
			          '<th class="celdaAzulOscuro" scope="col">TMP</th>' + 
			        '</tr>';
				break;
			}
			
			htmlCabeceraOk = '';
			htmlCabeceraVacia = ''; 

			for(i = 0; i < this.listaPartidos.length && this.listaPartidos[i].prioridad <= 0 ; i++ ){
				var p = this.listaPartidos[i];
				htmlCuerpo[(this.indexTablaPartido(i))] += this.generarHTMLPartido(p);
				tablaVacia[(this.indexTablaPartido(i))] = false;
			}

			this.offsetPartidos =  (this.pantalla )% 3 * (this.numHuecos - i);	 
			//alert(this.offsetPartidos + ' ' + this.listaPartidos.length);
			if(i + this.offsetPartidos >= this.listaPartidos.length) this.offsetPartidos = 0;
			for(; i + this.offsetPartidos < this.listaPartidos.length && i < this.numHuecos ; i++){
				var p = this.listaPartidos[i + this.offsetPartidos];
				htmlCuerpo[(this.indexTablaPartido(i))] += this.generarHTMLPartido(p);
				tablaVacia[(this.indexTablaPartido(i))] = false;
			}

			for(; i < this.numHuecos; i++){
				htmlCuerpo[(this.indexTablaPartido(i))] += /*'<tr><td colspan="6">&nbsp;</td></tr>';*/
					'<tr class="fondoTabla">' +
				       '<td>&nbsp;</td>' +
				       '<td>&nbsp;</td>' +
				       '<td>&nbsp;</td>' +
				       '<td class="resultado">&nbsp;</td>' +
				       '<td>&nbsp;</td>' +
				       '<td>&nbsp;</td>' +
				     '</tr>'
			}
			
			htmlFin += 
				'</table>';
				
			if(this.tipoWidget == 1){
				$('tablaWidget').update(htmlInicio +
					((tablaVacia[0])?htmlCabeceraVacia:htmlCabeceraOk) +
					htmlCuerpo[0] + htmlFin + htmlPie[0]);
			}
			else{
				$('tablaWidget0').update(htmlInicio + desplegableFechas + htmlInicio2 +
					((tablaVacia[0])?htmlCabeceraVacia:htmlCabeceraOk) +
					 htmlCuerpo[0] + htmlFin + htmlPie[0]);
			}
			if(this.tipoWidget == 3 || this.tipoWidget == 4){
				$('tablaWidget1').update(htmlInicio + htmlInicio2 +
					((tablaVacia[1])?htmlCabeceraVacia:htmlCabeceraOk) +
					htmlCuerpo[1] + htmlFin + htmlPie[1]);
			}
			if(this.tipoWidget == 4){
				$('tablaWidget2').update(htmlInicio + htmlInicio2 +
					((tablaVacia[2])?htmlCabeceraVacia:htmlCabeceraOk) +
					htmlCuerpo[2] + htmlFin + htmlPie[2]);
			}
		}
		var torneoClasif = '';
		if(this.deporte != 'SOC' && this.deporte != 'BSK' && this.listaPartidos.length > 0) 
			torneoClasif = '&torneo='+this.listaPartidos[0].id_liga;

		//alert(this.fecha);
		$('selecFecha').value = this.fecha;
		$('tablaBotones').update(
			'<dt><a onclick="clicWidget();" target="_blank"  href="'+this.destinoClasif+torneoClasif+'"  class="botonClasif">clasificaciones</a></div>' +
	   		'<div><a onclick="clicWidget();" target="_blank"  href="'+this.destinoLink+'" class="boton">ver + partidos</a></div>' 
		);
	},
	
	generarHTMLPartidos: function(){
		if(this.deporte == 'TEN'){	
			this.iteracionCambiarPantalla = this.iteracion + 2;
			$('tablaWidget' + ((this.tipoWidget>1)?'0':'')).update(
				this.generarHTMLPartidosTenis('masculino') +
				this.generarHTMLPartidosTenis('femenino') +
				((this.tipoWidget == 4)?this.generarHTMLPartidosTenis('dobles'):'')
			)
			$('tablaBotones').update(
				'<dt><a onclick="clicWidget();" target="_blank"  href="'+this.destinoClasif+'"  class="botonClasif">clasificaciones</a></div>' +
		   		'<div><a onclick="clicWidget();" target="_blank"  href="'+this.destinoLink+'" class="boton">ver + partidos</a></div>'
			);
			if($('tablaWidget1')) $('tablaWidget1').update('');
			if($('tablaWidget2')) $('tablaWidget2').update('');
		}
		else{
			this.generarHTMLPartidosFutBsk();
		}
	},
	
	yUltima: function(){
		
	}
});
