var hoy=new Date();
hoy = hoy.getDate();

var partidosIds = new Array();

function cambiar_sonido(){
    if ($('link_sonido').innerHTML == sonidoOn) {
        $('link_sonido').update(sonidoOf);
        sonido = 0;
    }
    else {
        $('link_sonido').update(sonidoOn);
        sonido = 1;
    }
}


//cambiar el color 


function mostrar_liga(id_liga, titulo, phasesTabla, phasesLiga){
    url = phasesLiga != "" ? '/estadisticas/clasificacionLiga.php?id_phase=' + id_liga + '&id_liga=' + phasesLiga + '&tabla=' + phasesTabla : '/estadisticas/clasificacionLiga.php?id_liga=' + id_liga + '&deporte=' + deporte;
    if (!$('dialog' + id_liga)) {
        foo = new Window('dialog' + id_liga, {
            className: "dialog",
            title: titulo,
            width: 674,
            zIndex: 100,
            opacity: 1,
            resizable: false,
            claseCabecera: "cabeceraAjaxLiga2",
            options: {
                method: 'get'
            }
        });
        foo.setAjaxContent(url, {
            method: 'get'
        }, true, false);
        foo.toFront();
    }
}

function mostrar_estadistica(id_liga, id_home, id_away, id_fecha, h_name, a_name, tabla, partido_id,proveedor){
    if (!$('dialog' + id_home)) {
        foo = new Window('dialog' + id_home, {
            className: "dialog",
            width: 648,
            height: 342,
            zIndex: 100,
            opacity: 1,
            resizable: false,
            claseCabecera: "cabeceraAjaxLiga1",
            title: h_name + ' vs ' + a_name,
            options: {
                method: 'get'
            },
            draggable: true,
            url: '/estadisticas/clasificacionEnfrentamiento2.php?id_liga=' + id_liga + 
				'&id_home=' + id_home + '&id_away=' + id_away + '&id_fecha=' + id_fecha + 
				'&n_home=' + h_name + '&n_away=' + a_name + '&tabla=' + tabla + '&partido_id=' + partido_id +
				'&deporte=' + deporte + '&proveedor=' + proveedor
        });
        foo.showCenter();
        foo.toFront();
    }
}


function setHomePage(){
    var siteURL = "http://www.marcadoresonline.com";
    if (document.all) {
        document.body.style.behavior = "url(#default#homepage)";
        document.body.setHomePage(siteURL);
    }
    else 
        if (document.getElementById) {
            $('firefox_homepage').update('<a href="http://www.marcadoresonline.com">Arrastra este enlace sobre tu boton de inicio para hacer esta tu pagina de inicio.</a>');
        }
}

function bookmark(){
    var title = 'Marcadores online';
    var url = 'http://www.marcadoresonline.com';
    if (document.all) 
        window.external.AddFavorite(url, title);
    else 
        if (window.sidebar) 
            window.sidebar.addPanel(title, url, "")
        else 
            if (window.sidebar && window.sidebar.addPanel) 
                window.sidebar.addPanel(title, url, "");
}

function MM_preloadImages(){ //v3.0
    var d = document;
    if (d.images) {
        if (!d.MM_p) 
            d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments;
        for (i = 0; i < a.length; i++) 
            if (a[i].indexOf("#") != 0) {
                d.MM_p[j] = new Image;
                d.MM_p[j++].src = a[i];
            }
    }
}

function MM_swapImgRestore(){ //v3.0
    var i, x, a = document.MM_sr;
    for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) 
        x.src = x.oSrc;
}

function MM_findObj(n, d){ //v4.01
    var p, i, x;
    if (!d) 
        d = document;
    if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document;
        n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) 
        x = d.all[n];
    for (i = 0; !x && i < d.forms.length; i++) 
        x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) 
        x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) 
        x = d.getElementById(n);
    return x;
}

function MM_swapImage(){ //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments;
    document.MM_sr = new Array;
    for (i = 0; i < a.length - 2; i += 3) 
        if ((x = MM_findObj(a[i])) != null) {
            document.MM_sr[j++] = x;
            if (!x.oSrc) 
                x.oSrc = x.src;
            x.src = a[i + 2];
        }
}

function FindXY(obj){
    var x = 0, y = 0;
    while (obj != null) {
        x += obj.offsetLeft - obj.scrollLeft;
        y += obj.offsetTop - obj.scrollTop;
        obj = obj.offsetParent;
    }
    return {
        x: x,
        y: y
    };
}

function smf_avatarResize2(){
	var possibleAvatars = document.getElementsByTagName ? document.getElementsByTagName("img") : document.all.tags("img");
	for (var i = 0; i < possibleAvatars.length; i++) {
		if (possibleAvatars[i].className != "avatar") 
			continue;
		var tempAvatar = new Image();
		tempAvatar.src = possibleAvatars[i].src;
		var altura = 40;
		var anchura = 40;
		if (smf_avatarMaxWidth != 0 && tempAvatar.width > smf_avatarMaxWidth) {
			altura = smf_avatarMaxWidth * tempAvatar.height / tempAvatar.width;
			anchura = smf_avatarMaxWidth;
			if (smf_avatarMaxHeight != 0 && altura > smf_avatarMaxHeight) {
				anchura = anchura * smf_avatarMaxHeight / altura;
				altura = smf_avatarMaxHeight;
			}
		}
		else 
			if (smf_avatarMaxHeight != 0 && tempAvatar.height > smf_avatarMaxHeight) {
				anchura = smf_avatarMaxHeight * tempAvatar.width / tempAvatar.height;
				possibleAvatars[i].height = smf_avatarMaxHeight;
				if (smf_avatarMaxWidth != 0 && anchura > smf_avatarMaxWidth) {
					altura = altura * smf_avatarMaxWidth / anchura;
					anchura = smf_avatarMaxWidth;
				}
			}
			else {
				anchura = tempAvatar.width;
				altura = tempAvatar.height;
			}
		possibleAvatars[i].width = anchura;
		possibleAvatars[i].height = altura;
	}
	if (typeofwindow_oldAvatarOnload != "undefined" && window_oldAvatarOnload) {
		window_oldAvatarOnload();
		window_oldAvatarOnload = null;
	}
}
function img_error(elemento){
	elemento.src = "/img/banderas.gif";
	elemento.onerror = "";
	return true;
}
/**
 * @author alex
 */

function color_fila(contenido, id){
  if (typeof(divPartido)=='undefined')
  		divPartido=new Array();
    switch (contenido) {
        case 1:
            value = '';
            break;
        case 2:
            value = '#B5D4F4';
            break;
        case 3:
            value = '#8ebeee';
            break;
    }
    if (divPartido[id] != "si") {
        $("fila_" + id).setStyle({
            backgroundColor: value
        });
        $("res_" + id).setStyle({
            backgroundColor: value
        });
        $("fav_" + id).setStyle({
            backgroundColor: value
        });
        $("combi_" + id).setStyle({
            backgroundColor: value
        });
        $("res_1_" + id).setStyle({
            backgroundColor: value
        });
        $("res_x_" + id).setStyle({
            backgroundColor: value
        });
        $("res_2_" + id).setStyle({
            backgroundColor: value
        });
    }
}

function ver_resultado(partido_id){
    var el = $('div_oculto_' + partido_id); //se define la variable "el" igual a nuestro div
    var cuotas = $('div_oculto_cuotas' + partido_id);
    if (el.style.display == 'none') {
        Effect.Appear(cuotas);
        Effect.Appear(el);
//        alert(eval(anteriorr.get(parseInt(partido_id))));
        if (anteriorr.get(parseInt(partido_id)).statusType != 'live') 
            color_fila(3, partido_id);
        divPartido[partido_id] = "si";
        activar_individual(partido_id, deporte);
        $('desplegar_combi' + partido_id).writeAttribute({
            'src': '/img/iconoCombiAbajo.png',
            'title': 'Ocultar',
            'alt': '"Ocultar'
        });
    }
    else {
        Effect.Fade(cuotas);
        Effect.Fade(el);
        divPartido[partido_id] = "no";
        color_fila(2, partido_id);
        $('desplegar_combi' + partido_id).writeAttribute({
            'src': '/img/iconoCombi.png',
            'title': 'Desplegar',
            'alt': '"Desplegar'
        });
    }
}
function activar_individual (id, tipo_deporte){
    cargar_resultado_ind(id);
    cargar_cuotas_ind(id, tipo_deporte);
	if (!$('img_1_'+id))
		pintar_imagnes_cuotas(id);
}
//pintamos la imagenes de cuotas
function pintar_imagnes_cuotas (id){
	partido=anteriorr.get(id);
	var link_01_img="";
	var link_02_img="";
	var link_03_img="";
	var tdOcultoApuesta3 ="";
	var tdOcultoApuesta1 ="";
	var tdOcultoApuesta2 ="";
	var tdOcultoApuesta1 = '<td class="cuarenta"><img src="/img/flechaRojaFutbol.jpg" alt="flecha" width="19" height="11"  class="tablaFlechasCuotasMargin" /></td>';
    var trOcultoApuesta1 = "<tr>" + tdOcultoApuesta1;
	var td_temp=tdOcultoApuesta1;
	trOcultoApuesta1 += td_temp;
	trOcultoApuesta1 += tdOcultoApuesta1 + "</tr>";
    if (partido.o1 != '0.00') {
		link_01_img = comparar_cuotas_img(partido.o1, partido.o1_ant, partido.o1Bid, partido.o1Name, 1, partido.id);			
		link_02_img = comparar_cuotas_img(partido.o2, partido.o2_ant, partido.o2Bid, partido.o2Name, 2, partido.id);
		link_03_img = comparar_cuotas_img(partido.o3, partido.o3_ant, partido.o3Bid, partido.o3Name, 3, partido.id);
		tdOcultoApuesta1 = '<td id="img_1_' + partido.id + '">' + link_01_img + '<img src="/img/' + partido.o1Bid + 'v.jpg" alt="' + partido.o1Name + '" width="21" height="45" /></a></td>';
		tdOcultoApuesta2 = '<td id="img_2_' + partido.id + '">' + link_02_img + '<img src="/img/' + partido.o2Bid + 'v.jpg" alt="' + partido.o2Name + '" width="21" height="45"  /></a></td>';
		tdOcultoApuesta3 = '<td id="img_3_' + partido.id + '">' + link_03_img + '<img src="/img/' + partido.o3Bid + 'v.jpg" alt="' + partido.o3Name + '" width="21" height="45"  /></a></td>';
	}
    var trOcultoApuesta2 = "<tr>" + tdOcultoApuesta1 + tdOcultoApuesta2 + tdOcultoApuesta3 + "</tr>";
    var tdOcultoApuesta1 = '<td colspan="3">&nbsp;</td>';
    var trOcultoApuesta3 = "<tr>" + tdOcultoApuesta1 + "</tr>";
    var tdOcultoApuesta1 = '<td class="cuarenta">&nbsp;</td>';
    var trOcultoApuesta4 = "<tr>" + tdOcultoApuesta1 + tdOcultoApuesta1 + tdOcultoApuesta1 + "</tr>";
  	if (partido.o1 != '0.00' && partido.o3 != '0.00') {
     	tbodyOcultoApuesta = "<tbody>" + trOcultoApuesta1 + trOcultoApuesta2 + trOcultoApuesta3 + "</tbody>";
    }else {
        tbodyOcultoApuesta = "<tbody>" + trOcultoApuesta4 + "</tbody>";
        }
        //montamos la tabla
    var tablaOcultaApuesta = '<table style="width:110px">' + tbodyOcultoApuesta + '</table>';
	$('div_oculto_cuotas'+id).update(tablaOcultaApuesta);
}
//recogemos los goles del partido
function cargar_resultado_ind   (id){
	 var tiempo_ = new Date();
    tiempo_ = tiempo_.getTime();
    var url = "/mostrarBD/mostrar_goles.php";
    var myAjax = new Ajax.Request(url, {
        method: "get",
        parameters: {
            'id': id,
			'tiempo': tiempo_,
			'proveedor': 'enetpulse'
			        },
        onComplete: function(t){
            pintarGoles(id,t.responseText.evalJSON()); // pintaremos las listas de todo
        }
        
    });
    
}
function obtener_tarjetas (id){
	 cantidad_tar=0;
	  var tiempo_ = new Date();
    tiempo_ = tiempo_.getTime();
    var url = "/mostrarBD/mostrar_tarjetas.php";
    var myAjax = new Ajax.Request(url, {
        method: "get",
        parameters: {
            'id': id,
			'tiempo': tiempo_,
			'proveedor': 'enetpulse'
        },
        onComplete: function(t){
            pintarTarjetas_ultimas(id, t.responseText.evalJSON()); // pintaremos las listas de todo
        }
    });
    
}
//recogemos las cuotas del partido
function cargar_cuotas_ind  (id, tipo_deporte){
	 var tiempo_ = new Date();
    tiempo_ = tiempo_.getTime();
    var url = "/mostrarBD/mostrar_cuotas.php";
    var myAjax = new Ajax.Request(url, {
        method: "get",
        parameters: {
            'id': id,
            'deporte': tipo_deporte,
			'proveedor': 'enetpulse',
			'tiempo': tiempo_
        },
        onComplete: function(t){
            pintarApuestas(id, tipo_deporte,t.responseText.evalJSON()); // pintaremos las listas de todo
        }
        
    });
    
}
//PINTAMOS los goles
function pintarGoles (id,res_ind){
    if (res_ind) {
        var tabla = new Element('table', {
            'id': "tablaResultado"
        });
        var tbody = new Element('tbody');
        var tr = new Element('tr');
        tr.insert('<td scope="col">&nbsp;</td>', {
            position: 'after'
        });
        tr.insert('<td class="celdaResulNeutra" scope="col">&nbsp;</td>', {
            position: 'after'
        });
        tr.insert('<td scope="col">&nbsp;</td>', {
            position: 'after'
        });
        tbody.insert(tr, {
            position: 'after'
        });
        resultadoH = 0;
        resultadoA = 0;
		resultadoPH = 0;
		resultadoPA = 0;
		var periodo4 = 0;
        res_ind.each(function(e){
          	var   golH = '&nbsp;';
			var golA = '&nbsp;';
            home = e.team == e.id_eHome;
			var tipo="";
			if (e.type=='Pen'){
				tipo="("+e.type+")";
			}
            if (home) {
				if (e.type) {
					if (e.type == 'Own') {
						
						if (e.period != 4) {
							resultadoA += 1;
						}else{
							resultadoPA+=1;
						}
						//gol = e.time + "' " + e.name.substr(0, 10)+" (p.p.)";
						gol = e.time + "' " + e.name +" (p.p.)";
						golA = '<div class="golhome"><img src="/img/gol.gif" alt="gol" width="12" height="12" /> </div>' + gol;
					}
					else {
						//gol = e.time + "' " + e.name.substr(0, 10)+" "+tipo;
						gol = e.time + "' " + e.name +" "+tipo;		
						if (e.period != 4) {
							resultadoH += 1;
						}else{
							resultadoPH+=1;
							gol=e.type+ " " + e.name +" "+ e.time;
						}
						
						golH = '<div class="golaway"><img src="/img/gol.gif" alt="gol" width="12" height="12" /> </div>' + gol;
					}
				}else {
						//gol = e.time + "' " + e.name.substr(0, 10)+" "+tipo;
						gol = e.time + "' " + e.name +" "+tipo;
						if (e.period != 4) {
							resultadoH += 1;
						}
						else{
							resultadoPH+=1;
							gol=e.type+ " " + e.name +" "+ e.time;
						}
					golH = '<div class="golaway"><img src="/img/gol.gif" alt="gol" width="12" height="12" /> </div>' + gol;
					}
            }
            away = e.team == e.id_eAway;
            if (away) {
				if (e.type) {
					if (e.type == 'Own') {
						
						if (e.period != 4) {
							resultadoH += 1;
						}else{
							resultadoPH+=1;
							
						}
						//gol = e.time + "' " + e.name.substr(0, 10)+" (p.p.)";
						gol = e.time + "' " + e.name+" (p.p.)";
						golH = '<div class="golaway"><img src="/img/gol.gif" alt="gol" width="12" height="12" /> </div>' + gol;
					}
					else {
						//gol = e.time + "' " + e.name.substr(0, 10)+" "+tipo;
						gol = e.time + "' " + e.name+" "+tipo;
						if (e.period != 4) {
							resultadoA += 1;
						}else{
							resultadoPA+=1;
							gol=e.type+ " " + e.name + " "+ e.time;
						}
						
						golA = '<div class="golhome"><img src="/img/gol.gif" alt="gol" width="12" height="12" /> </div>' + gol;
						
					}
				}else {
						//gol = e.time + "' " + e.name.substr(0, 10)+" "+tipo;
						gol = e.time + "' " + e.name+" "+tipo;
						if (e.period != 4) {
							resultadoA += 1;
						}else{
							resultadoPA+=1;
							gol=e.type+ " " + e.name +" "+ e.time;
						}
						
						golA = '<div class="golhome"><img src="/img/gol.gif" alt="gol" width="12" height="12" /> </div>' + gol;
					}
			}
			
			if ( e.period==4){
				periodo4=1;
				resultadoTA=resultadoPA;
				resultadoTH=resultadoPH;
				
				calseD = calseP='penalty';
				calseR='penaltyRst';
			}else{
				resultadoTH=resultadoH
				resultadoTA=resultadoA
				calseP='celdaResulIzq';
				calseR='celdaResulCentro';
				calseD='celdaResulDch';
			}
			tr = new Element('tr');
			td = new Element('td', {
                'class': calseP,
                'scope': "col"
            }).update(golH);
            
            tr.insert(td, {
                position: 'after'
            });
            td = new Element('td', {
                'class': calseR,
                'scope': "col"
            }).update(resultadoTH + ' - ' + resultadoTA);
            
            tr.insert(td, {
                position: 'after'
            });
            td = new Element('td', {
                'class': calseD,
                'scope': "col"
            }).update(golA);
            
            tr.insert(td, {
                position: 'after'
            });
            tbody.insert(tr, {
                position: 'after'
            });
        });
		var resultado_final=resultadoTH + ' - ' + resultadoTA;
		if (resultado_final != anteriorr.get(id).current) {
			tbody.insert('<tr><td colspan="3" class="celdaResulCentro">' + anteriorr.get(id).current + '</td></tr>', {
				position: 'after'
			});
		}
        tabla.insert(tbody, {
            position: 'after'
        });
        $('resultado_individual' + id).update('');
        $('resultado_individual' + id).insert(tabla, {
            position: 'after'
        });
    }
    else {
        $('resultado_individual' + id).update('');
    }
   obtener_tarjetas(id) ;
}
function pintarTarjetas_ultimas (id,tar_ind){
	var calseP='celdaResulIzq';
	var calseR='celdaResulCentro';
	var calseD='celdaResulDch';
    if (tar_ind) {
		
        var tabla = new Element('table', {
            'id': "tablaResultado2"
        });
        var tbody = new Element('tbody');
		if (!$('tablaResultado')) {
			var tr = new Element('tr');
			tr.insert('<td scope="col">&nbsp;</td>', {
				position: 'after'
			});
			tr.insert('<td class="celdaResulNeutra" scope="col">&nbsp;</td>', {
				position: 'after'
			});
			tr.insert('<td scope="col">&nbsp;</td>', {
				position: 'after'
			});
			tbody.insert(tr, {
				position: 'after'
			});
		}
          tar_ind.each(function(e){
				var tarH = '&nbsp;';
				var tarA = '&nbsp;';
				//var tarjeta = String(e.type) == 'Red' ? '<img src="/img/roja.jpg" alt="tar roja" width="8" height="11" /> ' : '<img src="/img/amarilla.jpg" alt="tar amrilla" width="8" height="11" /> ';
				if(String(e.type) == 'Yellow') {
					tarjeta = '<img src="/img/amarilla.jpg" alt="tar amrilla" width="8" height="11" /> ';
				}
				else if(String(e.type) == 'Red') {
					tarjeta = '<img src="/img/roja.jpg" alt="tar roja" width="8" height="11" /> ';
				}
				else {
					tarjeta = '<img src="/img/amarilla.jpg" alt="tar amrilla" width="8" height="11" /><img src="/img/roja.jpg" alt="tar roja" width="8" height="11" />';
				}				
				home = e.team == e.id_eHome;
				if (home) tarH = '<div class="golaway">' + tarjeta + '</div>' + e.time + "' " + e.name;
				away = e.team == e.id_eAway;
				if (away) tarA = '<div class="golhome">' + tarjeta + '</div>' + e.time + "' " + e.name;
				
				tr = new Element('tr');
				td = new Element('td', {
					'class': calseP,
					'scope': "col"
				}).update(tarH);
				tr.insert(td, {
					position: 'after'
				});
				td = new Element('td', {
					'class': calseR,
					'scope': "col"
				}).update('&nbsp;');
				
				tr.insert(td, {
					position: 'after'
				});
				td = new Element('td', {
					'class': calseD,
					'scope': "col"
				}).update(tarA);
				
				tr.insert(td, {
					position: 'after'
				});
				tbody.insert(tr, {
					position: 'after'
				});
			});
			tabla.insert(tbody, {
				position: 'after'
			});
		$('resultado_individual' + id).insert(tabla, {
            position: 'after'
        });
    }
}
//pintamos la tabla de apuestas
function pintarApuestas (id, tipo_deporte,cuotas_ind){
    if (cuotas_ind) {
        num = cuotas_ind.size();
        var tabla = new Element('table', {
            'id': 'tablaDspCasas' 
        });
        var tbody = new Element('tbody');
        var tr1 = new Element('tr');
        var tr2 = new Element('tr');
        var tr3 = new Element('tr');
        var tr4 = new Element('tr');
        tabla.insert(' <colgroup span="1" width="30"></colgroup>', {
            position: 'after'
        });
        tabla.insert(' <colgroup span="' + num + '" width="30"></colgroup>', {
            position: 'after'
        });
        tr1.insert('<td class="celdaNeutraCasas" scope="col">&nbsp;</td>', {
            postion: 'after'
        });
        tr2.insert('<td class="columnaCasas" >1</td>', {
            postion: 'after'
        });
        tr3.insert('<td class="columnaCasas" >X</td>', {
            postion: 'after'
        });
        tr4.insert('<td class="columnaCasas" >2</td>', {
            postion: 'after'
        });
       	var mejor_o1 = 0;
		var mejor_o2 = 0;
		var mejor_o3 = 0;
		cuotas_ind.each(function(e){
			mejor_o1 = parseFloat(e.o1)>mejor_o1?parseFloat(e.o1):mejor_o1;
			mejor_o2 = parseFloat(e.o2)>mejor_o2?parseFloat(e.o2):mejor_o2;
			mejor_o3 = parseFloat(e.o3)>mejor_o3?parseFloat(e.o3):mejor_o3;
			});
        cuotas_ind.each(function(e){
            var td = new Element('td', {
                'scope': 'col',
                'class': 'columnaCasas' 
            }).update('<a href="' + linkapuesta('casa' + e.bid) + 
					'"  onclick="clic(\'marcadoresonline_link_apuesta_max\',\'' + e.name + 
					'\');" target="_blank" ><img src="/img/' + e.bid + 'p.png" alt="' + e.name + 
					'" width="34" height="16" class="imgBloqueCasa" /></a>');
            tr1.insert(td, {
                position: 'after'
            });
            clase1 = "linkDspCasas";
            mejor_cla_o1 = e.o1 == mejor_o1;
            if (mejor_cla_o1) 
                clase1 = "linkMejorCuota";
            td = new Element('td').update('<a href="' + linkapuesta('casa' + e.bid) + '"  onclick="clic(\'marcadoresonline_link_apuesta_max\',\'' + e.name + '\');" target="_blank"  class="' + clase1 + '">' + e.o1 + '</a>');
            tr2.insert(td, {
                position: 'after'
            });
            clase2 = "linkDspCasas";
            mejor_cla_o2 = e.o2 == mejor_o2;
            if (mejor_cla_o2) {
                clase2 = "linkMejorCuota";
            }
            td = new Element('td').update('<a href="' + linkapuesta('casa' + e.bid) + 
								'"  onclick="clic(\'marcadoresonline_link_apuesta_max\',\'' + e.name + 
								'\');" target="_blank"  class="' + clase2 + '" >' + e.o2 + '</a>');
            clase3 = "linkDspCasas";
            mejor_cla_o3 = e.o3 == mejor_o3;
            if (mejor_cla_o3) 
                clase3 = "linkMejorCuota";
            
            tr3.insert(td, {
                position: 'after'
            });
            td = new Element('td').update('<a href="' + linkapuesta('casa' + e.bid) + 
								'"  onclick="clic(\'marcadoresonline_link_apuesta_max\',\'' + e.name + 
								'\');" target="_blank"  class="' + clase3 + '">' + e.o3 + '</a>');
            tr4.insert(td, {
                position: 'after'
            });
        });
        tbody.insert(tr1, {
            position: 'after'
        });
        tbody.insert(tr2, {
            position: 'after'
        });
         tbody.insert(tr3, {
                position: 'after'
            });
        tbody.insert(tr4, {
            position: 'after'
        });
        tabla.insert(tbody, {
            position: 'after'
        });
		
        $('resultado_cuotas' + id).update('');
        $('resultado_cuotas' + id).insert(tabla, {
            position: 'after'
        });
        
    }
    else {
        $('resultado_cuotas' + id).update('<p></br></p><p></br>No Hay resultado de apuestas</br></p></br>');
        $('resultado_cuotas' + id).insert(new Element('br'), {
            position: 'after'
        });
    }
}
function comparar_cuotas(cuota, cuota_ant, bid, name, o, partido){
    var menor = '<img class="flechasCuotas" src="/img/bajaCuota.gif" alt="1" />';
    var mayor = '<img class="flechasCuotas" src="/img/subeCuota.gif" alt="2" />';
    var igual = '<img class="flechasCuotas" src="/img/flechaVacia.gif" alt="3" />';
    var imgFlecha = '';
    var titulo = '';
    cuota = parseFloat(cuota);
    cuota_ant = parseFloat(cuota_ant);
        if (cuota > cuota_ant) {
            imgFlecha = mayor;
            titulo = cuota_ant + ' >> ' + cuota;
        }else if (cuota < cuota_ant){
            imgFlecha = menor;
            titulo = cuota_ant + ' >> ' + cuota;
        }else{
            titulo = "";
            imgFlecha = igual;
        }
    return  imgFlecha + '<a  class="help" id="link_' + o + partido + '" onclick="clic(\'marcadoresonline_link_apuesta_max\',\'' + name + '\');" target="_blank" title="' + name + ' ' + titulo + '" href="' + linkapuesta('casa' + bid) + '">';
}

function comparar_cuotas_img(cuota, cuota_ant, bid, name, o, partido){
    var titulo = '';
    cuota = parseFloat(cuota);
    cuota_ant = parseFloat(cuota_ant);
            titulo =cuota > cuota_ant? cuota_ant + ' >> ' + cuota:cuota_ant + ' >> ' + cuota;
            titulo =cuota == cuota_ant?"":titulo;
    return'<a  class="help"  id="link_' + o + partido + '" onclick="clic(\'marcadoresonline_link_apuesta_max\',\'' + name + '\');" target="_blank" title="' + name + ' ' + titulo + '" href="' + linkapuesta('casa' + bid) + '">';
}
//cargamos los partido que han variado en los ultimos 5min.
//Cogemos 5 min por si hay algun desfase de recogida de datos
function cargarCadaMinuto(){
    var tiempo_ = new Date();
    tiempo_ = tiempo_.getTime();
	//paramos el temporizador del aviso de goles
	if (typeof temporizador_gol!='undefined')
		temporizador_gol.stop();
	//vaciamos los partidos que se han actualizado en la pasada anterior
	if (typeof temporizador_gol=='undefined')
		partidos_actualizados=new Array();
    limpiar_actualizados();
    var url = "/mostrarBD/mostrar_resultadoMin.php";
    var myAjax = new Ajax.Request(url, {
        method: "get",
        parameters: {
            'deporte': deporte,
			'gmt':tiempo,
            'time': tiempo_,
			'proveedor':'enetpulse'
        },
        onComplete: function(t){
            pintarLista(t.responseText.evalJSON());
        }
    });
}
//cambiar la clase de la fila cuando cambia de estado
 function cambiar_color(id){
    if ($('fila_2' + id).hasClassName("filaVivo")) {
        $('fila_2' + id).className = "fila" + $('codigo' + id).innerHTML;
		$('fila_' + id).removeClassName ("ulVivo") ;
		$('fila_' + id).addClassName( "ul" + $('codigo' + id).innerHTML);
    }else {
        $('fila_2' + id).className ="filaVivo";
		$('fila_' + id).removeClassName( "ul" + $('codigo' + id).innerHTML);
		$('fila_' + id).addClassName ("ulVivo") ;
    }
}
function color_gol(){
    var tamanio_vector = partidos_gol.size();
    for (i = 0; i < tamanio_vector; i++) {
        if (pasada[partidos_gol[i]] == 1) {
            value = '#FF8040';
            pasada[partidos_gol[i]] = 0;
        }else {
            value = '';
            pasada[partidos_gol[i]] = 1;
        }
        $("fila_" + partidos_gol[i]).setStyle({
            backgroundColor: value
        });
        $("res_" + partidos_gol[i]).setStyle({
            backgroundColor: value
        });
        $("fav_" + partidos_gol[i]).setStyle({
            backgroundColor: value
        });
        $("combi_" + partidos_gol[i]).setStyle({
            backgroundColor: value
        });
        $("res_1_" + partidos_gol[i]).setStyle({
            backgroundColor: value
        });
        $("res_x_" + partidos_gol[i]).setStyle({
            backgroundColor: value
        });
        $("res_2_" + partidos_gol[i]).setStyle({
            backgroundColor: value
        });
    }
}

//limpiamos las ultimas actualizaciones del lo partidos
function limpiar_actualizados(){
    partidos_gol = new Array();
    var tamanio_vector = partidos_actualizados.size();
    for (i = 0; i < tamanio_vector; i++) {
        if ($('partido_' + partidos_actualizados[i])) {
            $('golaway' + partidos_actualizados[i]).setStyle({
                display: 'none'
            });
            $('golhome' + partidos_actualizados[i]).setStyle({
                display: 'none'
            });
            value = '';
            $("fila_" + partidos_actualizados[i]).setStyle({
                backgroundColor: value
            });
            $("res_" + partidos_actualizados[i]).setStyle({
                backgroundColor: value
            });
            $("fav_" + partidos_actualizados[i]).setStyle({
                backgroundColor: value
            });
            $("combi_" + partidos_actualizados[i]).setStyle({
                backgroundColor: value
            });
            $("res_1_" + partidos_actualizados[i]).setStyle({
                backgroundColor: value
            });
            if ($("res_x_" + partidos_actualizados[i])) {
                $("res_x_" + partidos_actualizados[i]).setStyle({
                    backgroundColor: value
                });
            }
            $("res_2_" + partidos_actualizados[i]).setStyle({
                backgroundColor: value
            });
        }
    }
    partidos_actualizados = new Array();
}

pintarLista = function(partidos_ind){
    var cambio_resultado = new Array();
    var sonidolocal = "no";    
	if (partidos_ind != null) {
		partidos_ind.each(function(e){
		if ($('partido_' + e.id) && e.statusType!='sched') {
			var cambio = 1;
			var partido_anterior = anteriorr.get(e.id);
			
			if (e.current != '0 - 0' ) {
				resultado_anterior = partido_anterior.current;
				resultado_anterior = resultado_anterior.replace(" - ", "-");
				resultado_anterior_h = resultado_anterior.substr(0, resultado_anterior.indexOf('-'));
				resultado_anterior_a = resultado_anterior.substr(resultado_anterior.indexOf('-') + 1, resultado_anterior.length);
				resultado = e.current.replace(" - ", "-");
				resultado_h = resultado.substr(0, resultado.indexOf('-'));
				resultado_a = resultado.substr(resultado.indexOf('-') + 1, resultado.length);
				if (resultado_a > resultado_anterior_a) {
					cambio = 0;
					$('golaway' + e.id).setStyle({
						display: 'block'
					});
					sonidolocal = "si";
					
					if ($('div_oculto_' + e.id).getStyle('display') == 'block') 
						activar_individual(e.id, 'SOC');
				}
				else {
					$('golaway' + e.id).setStyle({
						display: 'none'
					});
				}
				if (resultado_h > resultado_anterior_h) {
					cambio = 0;
					sonidolocal = "si";
					$('golhome' + e.id).setStyle({
						display: 'block'
					});
					
					if ($('div_oculto_' + e.id).getStyle('display') == 'block') {
						activar_individual(e.id, 'SOC');
					}
					
				}
				else {
					$('golhome' + e.id).setStyle({
						display: 'none'
					});
				}
			}
			if (partido_anterior.statusType != e.statusType) {
				cambiar_color(e.id);
				$('status_celda_' + e.id).className = e.statusType == 'fin' ? 'infoFin liInfo' : $('status_celda_' + e.id).className;
			}
			
			if (e.statusType == 'live' || e.statusType == 'fin'){
				$('tiempo_' + e.id).update(e.tiempo + "\'");
				$('resultado_actual_' + e.id).update(e.current);
				$('media_parte_' + e.id).update(e.HT);
				$('porroga_' + e.id).update(e.ET);
				$('penalti_' + e.id).update(e.PEN);
				$('statu_' + e.id).update(e.status_idioma.substr(0, 4));
				}
			var estado = String(e.statusType);
			var estado_anterior = String(partido_anterior.statusType);
			switch (estado) {
				case "live":
					if (estado_anterior == "sched") {
						var posicion = novivo.indexOf(parseInt(e.id));
						var provi = novivo.slice(posicion+1);
  						novivo = novivo.slice(0,posicion);
  						novivo = novivo.concat(provi); 
						envivo[envivo.size()] =parseInt(e.id);
					}
					break;
				case "fin":
					if (estado_anterior == "live") {
						var posicion = envivo.indexOf(parseInt(e.id));
						var provi = envivo.slice(posicion+1);
  						envivo = envivo.slice(0,posicion);
  						envivo = envivo.concat(provi); 
						partFin[partFin.size()] = parseInt(e.id);
					}
					break;
			}
			partido_anterior.current=e.current;
			partido_anterior.ET=e.ET;
			partido_anterior.HT=e.HT;
			partido_anterior.PEN=e.PEN;
			partido_anterior.status=e.status;
			partido_anterior.statusType=e.statusType;
			partido_anterior.status_idioma=e.status_idioma;
			partido_anterior.o1=e.o1;
			partido_anterior.o2=e.o2;
			partido_anterior.o3=e.o3;
			partido_anterior.o1Name=e.o1Name;
			partido_anterior.o2Name=e.o2Name;
			partido_anterior.o3Name=e.o3Name;
			partido_anterior.o1Bid=e.o1Bid;
			partido_anterior.o2Bid=e.o2Bid;
			partido_anterior.o3Bid=e.o3Bid;
			partido_anterior.o1_ant=e.o1_ant;
			partido_anterior.o2_ant=e.o2_ant;
			partido_anterior.o3_ant=e.o3_ant;
			partido_anterior.tiempo=e.tiempo;
			
			anteriorr.unset(e.id);
			anteriorr.set(e.id, partido_anterior);
			partidos_actualizados[partidos_actualizados.size()] = e.id;
			if (cambio == 0) {
				pasada[e.id] = 1
				partidos_gol[partidos_gol.size()] = e.id;
			}
		}else if ($('partido_' + e.id) && e.statusType=='sched'){
			var partido_anterior = anteriorr.get(e.id);
			if (cuotasMaximas == 0 && e.o1 != '0.00') {
				if (partido_anterior.o1 != e.o1) {
					var link_01 = comparar_cuotas(e.o1, e.o1_ant, e.o1Bid, e.o1Name);
					var link_01_img = comparar_cuotas_img(e.o1, e.o1_ant, e.o1Bid, e.o1Name);
					$('res_1_' + e.id).update(link_01 + e.o1 + '</a>');
					if ($('img_2_' + e.id)) 
						$('img_1_' + e.id).update(link_01_img + '<img src="/img/' + e.o1Bid + 'v.jpg" alt="' + e.o1Name + '" width="21" height="45" /></a>');
				}
				if (partido_anterior.o1 != e.o1) {
					var link_02 = comparar_cuotas(e.o2, e.o2_ant, e.o2Bid, e.o2Name);
					var link_02_img = comparar_cuotas_img(e.o2, e.o2_ant, e.o2Bid, e.o2Name);
					$('res_x_' + e.id).update(link_02 + e.o2 + '</a>');
					if ($('img_2_' + e.id))	
						$('img_2_' + e.id).update(link_02_img + '<img src="/img/' + e.o2Bid + 'v.jpg" alt="' + e.o2Name + '" width="21" height="45" /></a>');
					}
				if (partido_anterior.o1 != e.o1) {
					var link_03 = comparar_cuotas(e.o3, e.o3_ant, e.o3Bid, e.o3Name);
					var link_03_img = comparar_cuotas_img(e.o3, e.o3_ant, e.o3Bid, e.o3Name);
					$('res_2_' + e.id).update(link_03 + e.o3 + '</a>');
					if ($('img_3_' + e.id)) 
						$('img_3_' + e.id).update(link_03_img + '<img src="/img/' + e.o3Bid + 'v.jpg" alt="' + e.o3Name + '" width="21" height="45" /></a>');
				}
			}
			partido_anterior.o1=e.o1;
			partido_anterior.o2=e.o2;
			partido_anterior.o3=e.o3;
			partido_anterior.o1Name=e.o1Name;
			partido_anterior.o2Name=e.o2Name;
			partido_anterior.o3Name=e.o3Name;
			partido_anterior.o1Bid=e.o1Bid;
			partido_anterior.o2Bid=e.o2Bid;
			partido_anterior.o3Bid=e.o3Bid;
			partido_anterior.o1_ant=e.o1_ant;
			partido_anterior.o2_ant=e.o2_ant;
			partido_anterior.o3_ant=e.o3_ant;
			anteriorr.unset(e.id);
			anteriorr.set(e.id, partido_anterior);
		}
		});
	}
    if (sonidolocal == "si" && sonido == 1) 
	  Sound.play('http://www.marcadoresonline.com/sonido/gol.mp3');
   
    if (partidos_gol.size() > 0) {
        temporizador_gol = new PeriodicalExecuter(color_gol, 1);
    }
}
function anadir_favoritos(id_liga, fecha, id_partido){
    var url = "/setCookie.php";
    var nombre = "";
    if (id_partido == 0) {
        nombre = "liga_favorito";
        cambiar_icono_liga(id_liga, fecha);
        ligas_favoritos[ligas_favoritos.size()] = id_liga;
    }else {
        nombre = "partido_favorito";
        cambiar_icono_partido(id_partido,id_liga);
        var url = "/setCookiePartido.php";
        partidos_favoritos[partidos_favoritos.size()] = id_partido;
    }
    var myAjax = new Ajax.Request(url, {
        method: "get",
        parameters: {
            'nombre': nombre,
            'fecha': fecha,
            'ligaCode': id_liga,
            'partido_id': id_partido,
            'deporte': deporte
        }
    });
    if (location.pathname == '/favoritos.php') {
        if (id_partido == 0) {
            $('partido_liga' + id_liga).update('');
            pintar_partido(id_liga, 1);
        }
    }
}

function eliminar_favoritos(id_liga, fecha, id_partido){
    var opcion = 0;
    var url = "/delCookie.php";
    var nombre = "";
    if (id_partido == 0) {
        nombre = "liga_favorito";
        opcion = 1
        texto = "¿Desea eliminar la liga de favoritos?"
    }
    else {
        nombre = "partido_favorito";
        var url = "/delCookiePartido.php";
        texto = "¿Desea eliminar el partido de favoritos?"
    }
    if (confirm(texto)) {
        var myAjax = new Ajax.Request(url, {
            method: "get",
            parameters: {
                'nombre': nombre,
                'fecha': fecha,
                'ligaCode': id_liga,
                'partido_id': id_partido,
                'deporte': deporte
            }
        });
        if (opcion == 1) {
            cambiar_icono_liga_fav(id_liga, fecha);
            ligas_favoritos = ligas_favoritos.without(id_liga);
            if (fecha2 == "") {
                liga_partido[id_liga].each(function(e){
                    eliminar_partido_fav(e);
                    if (partidos_favoritos.indexOf(e) >= 0) {
                        partidos_favoritos = partidos_favoritos.without(e);
                    }
                });
            }
        }else {
            cambiar_icono_partido_fav(id_partido, id_liga);
            partidos_favoritos = partidos_favoritos.without(id_partido);
        }
   
     
    }
}

function eliminar_partido_fav(id_partido){
    var myAjax = new Ajax.Request('/delCookiePartido.php', {
        method: "get",
        parameters: {
            'nombre': 'partido_favorito',
            'fecha': '0',
            'ligaCode': '0',
            'partido_id': id_partido,
            'deporte': deporte
        }
    });
}

function cambiar_icono_liga(id_liga, fecha){
	mes = fecha1.substr(3, 2) < 10 ? "0" + fecha1.substr(3, 2) : fecha1.substr(3, 2);
    dia = fecha1.substr(0, 2) < 10 ? "0" + fecha1.substr(0, 2) : fecha1.substr(0, 2);
    var fec1 = new Date(fecha1.substr(6, 4), fecha1.substr(3, 2), fecha1.substr(0, 2));
    var fec2 = new Date(fecha2.substr(6, 4), fecha2.substr(3, 2), fecha2.substr(0, 2));
        var diferencia = (fec2.getTime() - fec1.getTime()) / 86400000;
        pos_fec = id_liga.indexOf('-' + fecha1.substr(0, 4));
        for (i = 0; i <= diferencia; i++) {
            fec = fec1.getTime() + i * 86400000;
            var fec_ = new Date();
            fec_.setTime(fec);
            mes2 = fec_.getMonth() < 10 ? '0' + fec_.getMonth() : fec_.getMonth();
            dia2 = fec_.getDate() < 10 ? '0' + fec_.getDate() : fec_.getDate();
            var fec_fav =dia2+ "-" + mes2 + "-" + fec_.getFullYear()  ;
            var variable = String(id_liga) + String(fec_fav);
            if ($('fav_img' + variable)) {
                $('fav_img' + variable).writeAttribute({
                    'src': '/img/iconoFav2.png',
                    'title': 'Eliminar Favoritos',
                    'alt': 'Eliminar Favoritos'
                });
                $('fav_link' + String(id_liga) + String(fec_fav)).writeAttribute({
                    'href': 'javascript:eliminar_favoritos("' + id_liga + '",0,0);',
					'onclick' : ''
                });
            }
        }
        anteriorr.each(function(e){
            cambiar_icono_partido(e.key, id_liga + String(fec_fav));
        });
}

function cambiar_icono_liga_fav(id_liga){
        mes = fecha1.substr(3, 2) < 10 ? "0" + fecha1.substr(3, 2) : fecha1.substr(3, 2);
        dia = fecha1.substr(0, 2) < 10 ? "0" + fecha1.substr(0, 2) : fecha1.substr(0, 2);
        var fec1 = new Date(fecha1.substr(6, 4), fecha1.substr(3, 2), fecha1.substr(0, 2));
        var fec2 = new Date(fecha2.substr(6, 4), fecha2.substr(3, 2), fecha2.substr(0, 2));
        var diferencia = (fec2.getTime() - fec1.getTime()) / 86400000;
        pos_fec = id_liga.indexOf('-' + fecha1.substr(0, 4));
        for (i = 0; i <= diferencia; i++) {
            fec = fec1.getTime() + i * 86400000;
            var fec_ = new Date();
            fec_.setTime(fec);
            mes2 = fec_.getMonth() < 10 ? '0' + fec_.getMonth() : fec_.getMonth();
            dia2 = fec_.getDate() < 10 ? '0' + fec_.getDate() : fec_.getDate();
           // var fec_fav = fec_.getDate() + "-" + mes2 + "-" + fec_.getFullYear();
            var fec_fav =dia2+ "-" + mes2 + "-" + fec_.getFullYear()  ;
            var variable = String(id_liga) + String(fec_fav);
            if ($('fav_img' + variable)) {
                $('fav_img' + variable).writeAttribute({
                    'src': '/img/iconoFav2_selec.png',
                    'title': 'Agregar Favoritos',
                    'alt': 'Agregar Favoritos'
                });
				
                $('fav_link' + String(id_liga) + String(fec_fav)).writeAttribute({
                    'href': 'javascript:anadir_favoritos("' + id_liga + '",0,0);',
					'onclick': ''
                });
               
            }
        }
        
        	anteriorr.each(function(e){
                cambiar_icono_partido_fav(e.key, id_liga + String(fec_fav));
            });
        
}

function cambiar_icono_partido(id_partido, id_liga){
    if ($('fav_' + id_partido)) {
		
        $('fav_par_img' + id_partido).writeAttribute({
            'src': '/img/iconoFav1.png',
            'title': 'Eliminar Partido de Favoritos',
            'alt': 'Eliminar Partido de Favoritos'
        });
		var link="javascript:eliminar_favoritos('" + id_liga + "','0','" + id_partido + "');"
        $('fav_par_link' + id_partido).writeAttribute({
            'href': link,
			'onclick':''
        });
		
    }
}

function cambiar_icono_partido_fav(id_partido, id_liga){
    if ($('fav_' + id_partido)) {
        $('fav_par_img' + id_partido).writeAttribute({
            'src': '/img/iconoFav1_selec.png',
            'title': 'Agregar Partido de Favoritos',
            'alt': 'Agregar Partido de Favoritos'
        });
        $('fav_par_link' + id_partido).writeAttribute({
            'href': 'javascript:anadir_favoritos("' + id_liga + '",0,"' + id_partido + '");',
			'onclick': ''
        });
    }
}

function setTextJornadas(ligaid) {
	var selJornadas = $('jornada' +ligaid);
	var nOpciones = selJornadas.options.length;
	var seleccionado = selJornadas.selectedIndex;
//	alert(selJornadas.options[seleccionado].value);
	var jAnt = "";
	var jSig = "";
	if((seleccionado -1) >=0 && (seleccionado -1) <= (nOpciones -1) ) {
		jAnt = "jornada "+ selJornadas.options[seleccionado -1].value;
	}
	if((seleccionado +1) >=0 && (seleccionado +1) <= (nOpciones -1)) {
		jSig = "jornada "+ selJornadas.options[seleccionado +1].value;
	}
	
	if(eval($('jornadaAnt'+ligaid))){
		if(!jAnt.empty() ) $('linkJornadaAnt'+ligaid).className="linkJornadaAnt";
		else  $('linkJornadaAnt'+ligaid).className="vacio";
		$('jornadaAnt'+ligaid).innerHTML = jAnt;
	}
	if(eval($('jornadaSig'+ligaid))){
		if(!jSig.empty() )	$('linkJornadaSig'+ligaid).className="linkJornadaSig";
		else  $('linkJornadaSig'+ligaid).className="vacio";
		$('jornadaSig'+ligaid).innerHTML = jSig;
	}
	if(eval($('ligaJornada'+ligaid)) && seleccionado!= -1) $('ligaJornada'+ligaid).innerHTML = "Jornada " + selJornadas.options[seleccionado].value;
}

function getLigaCode (ligaid) {
	var tsLigacode = '';
	url = "/deportes/getTournamentStageName.php";
    new Ajax.Request(url, {
        method: "get",
        asynchronous : false,
        parameters: {'tsId': ligaid },
        onComplete: function(t){ 
        	tsLigacode  = t.responseText;
        }
    });
    return tsLigacode ;
}

function jornadaDesplaza(ligaid, deporte, despl,_ligacode) {
	if(deporte == '') {
		deporte = 1;
	}
	if(_ligacode == '') {
		_ligacode = getLigaCode (ligaid); 
	}
	var x = parseInt(despl, 10);
	if(eval($('jornada'+ligaid))) {
		var selJornadas = $('jornada'+ligaid);
		if(x!=0) {
			var nOpciones = selJornadas.options.length;
			var opc = selJornadas.selectedIndex;
			if( opc + x >= 0 && opc+x <= nOpciones -1 ) {
				selJornadas.selectedIndex = selJornadas.selectedIndex + x;
			}
		}
		setTextJornadas(ligaid);
		var url = "";
		if (deporte == "1") {
			url = "/inc_pagina/partidos_futbol_liga_lista.php";
		}
		if(url != "" && selJornadas.selectedIndex != -1) {
		    new Ajax.Request(url, {
		        method: "get",
		        asynchronous : false,
		        evalScripts  : true,
		        parameters: {
					'proveedor': 'enetpulse',
					'dxt':deporte, 
		            'pais': paisSeleccionado,
		            'ligacode': _ligacode,
		            'jornada': selJornadas.options[selJornadas.selectedIndex].value
		        },
		        onComplete: function(t){ 
		        	$('partidos'+ ligaid ).innerHTML = t.responseText;
		        	// Rellena cabeceras UL //
		        	var uls = $$('ul.partidos ul.titResult_Streaming');
		        	for(i= 0 ; i < uls.length ; i++) {
		        		uls[i].update("<li class=\"liDesple\"></li><li class=\"liFav\">&nbsp;</li><li class=\"liPais\">PAIS</li><li class=\"liHora\">HORA</li><li class=\"liTmp\">TMP</li><li class=\"liLocal\">EQUIPO LOCAL</li><li class=\"liResult\">RESULTADO</li><li class=\"liVisitante\">EQUIPO VISITANTE</li><li class=\"liInfo\">DES</li><li class=\"liInfo\">INFO</li><li class=\"liEstad\">&nbsp;</li><li class=\"liStreamingUno\">INTERNET</li><li class=\"liStreamingDos\">TV</li><li class=\"liCuotaUno\">1</li><li class=\"liCuotaEquis\">X</li><li class=\"liCuotaDos\">2</li>");
		        	}
		        	rellenar_hash_partidos(ligaid);
		        	cargaPartidosTV();
		        	cargaPartidosTVStreaming();
		        }
		    });
		}
	}
}

/**
 * 
 * @param ligaid
 * @param deporte
 * @param despl
 * @param _ligacode
 */
function jornadaDesplazaStages(ligaid, deporte, despl,_ligacode) {
	var x = parseInt(despl, 10);
	if(eval($('jornada'+ligaid))) {
		var selJornadas = $('jornada'+ligaid);
		if(x!=0) {
			var nOpciones = selJornadas.options.length;
			var opc = selJornadas.selectedIndex;
			if( opc + x >= 0 && opc+x <= nOpciones -1 ) {
				selJornadas.selectedIndex = selJornadas.selectedIndex + x;
			}
		}
		setTextJornadas(ligaid);
		var url = "";
		if (deporte == "1") {
			url = "/inc_pagina/partidos_futbol_liga_lista_general.php";
		}
		if(typeof(paisSeleccionado) === 'undefined'){
			paisSeleccionado = "";
		}
			
			
		if(url != "" && selJornadas.selectedIndex != -1) {
		    new Ajax.Request(url, {
		        method: "get",
		        asynchronous : false,
		        evalScripts  : true,
		        parameters: {
					'proveedor': 'enetpulse',
					'dxt':deporte, 
		            'pais': paisSeleccionado,
		            'ligacode': _ligacode,
		            'jornada': selJornadas.options[selJornadas.selectedIndex].value,
		            'stages' : stagesID
		        },
		        onComplete: function(t){ 
		        	$('partidos').innerHTML = t.responseText;
		        	var uls = $$('ul.partidos ul.titResult_Streaming');
		        	for(i= 0 ; i < uls.length ; i++) {
		        		uls[i].update("<li class=\"liDesple\"></li><li class=\"liFav\">&nbsp;</li><li class=\"liPais\">PAIS</li><li class=\"liHora\">HORA</li><li class=\"liTmp\">TMP</li><li class=\"liLocal\">EQUIPO LOCAL</li><li class=\"liResult\">RESULTADO</li><li class=\"liVisitante\">EQUIPO VISITANTE</li><li class=\"liInfo\">DES</li><li class=\"liInfo\">INFO</li><li class=\"liEstad\">&nbsp;</li><li class=\"liStreamingUno\">INTERNET</li><li class=\"liStreamingDos\">TV</li><li class=\"liCuotaUno\">1</li><li class=\"liCuotaEquis\">X</li><li class=\"liCuotaDos\">2</li>");
		        	}
		        	rellenar_hash_partidos(ligaid);
		        	cargaPartidosTV();
		        	cargaPartidosTVStreaming();
		        	
		        }
		    });
		}
	}
}


function rellenar_hash_partidos(ligaid){
	var texto=$('divPartidos').innerHTML;
	anteriorr = new Hash();
	partidosIds = new Array();
	eval(texto);
	
	anteriorr.each(function(pair) {
		partidosIds.push(pair.key);
	});
	
	/*
	var texto=$('divPartidos'+ligaid).innerHTML;
	var arrayTexto=texto.split('%');
	var total=arrayTexto.size()-1;
	partidosIds = new Array();
	for (i=0;i<total;i++){
		var partido_json=arrayTexto[i];
		var arrayPartidoJson=partido_json.split('$');
		anteriorr.set(arrayPartidoJson[0].toString().replace('\n',''),arrayPartidoJson[1].evalJSON());
		partidosIds.push(arrayPartidoJson[0].toString().replace('\n',''));
	}
	*/
}


function cargaPartidosTV() {
//	alert(partidosIds);
	url = "/inc_pagina/partidosTV.php";
    new Ajax.Request(url, {
        method: "get",
        asynchronous : false,
        evalScripts  : true,
        parameters: {
			'partidos':partidosIds.join(',') ,
			'proveedor': 'enetpulse'
        },
        onComplete: function(t){
        	eval(t.responseText);
        }
    });
}
function cargaPartidosTVStreaming() {
	url = "/inc_pagina/partidosTVStreaming.php";
    new Ajax.Request(url, {
        method: "get",
        evalScripts  : true,
        parameters: {
			'partidos':partidosIds.join(',') 
        },
        onComplete: function(t){
        	eval(t.responseText);
        }
    });
}
