//variable goblales necesarias antes de la carga total de la pagina
var pais_liga=new Array();
var liga_partido=new Array();
var continuar_favoritos=1;
var divPartido =new Array();
var anteriorr = new Hash();
var envivo = new Array();
var novivo = new Array();
var partFin = new Array();
var partidos_gol = new Array();
var partidos_actualizados = new Array();
var temporizador_gol ;
var cuotasMaximas = 0;
var casaApuestas = new Array(3);
casaApuestas[0] = '';
casaApuestas[1] = '';
casaApuestas[2] = '';
//variable para saber si esta activo el sonido, por defecto esta en activo
var sonido = 1;
var filtros_activado=0;
//saber si esta ordenado por hora o por liga
// ordenar =1 esta ordenado por liga 
// ordenar = 0 esta ordenado por hora
var ordenar=1;
//cargamos los partido que han variado en los ultimos 3min.
//Cogemos 3 min por si hay algun desfase de recogida de datos
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();
}
function cargarCadaMinuto(){
    var tiempo_ = new Date();
    tiempo_ = tiempo_.getTime();
    limpiar_actualizados();
    var url = "/mostrarBD/mostrar_resultadoMin.php";
    var myAjax = new Ajax.Request(url, {
        method: "get",
        parameters: {
            'deporte': 'SOC',
			'gmt':tiempo,
            'time': tiempo_
        },
        onComplete: function(t){
           var  partidos_ind = t.responseText.evalJSON();
					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();
                    pintarLista(partidos_ind);
        }
    });
	 var myAjax2 = new Ajax.Request(url, {
        method: "get",
        parameters: {
            'deporte': 'BSK',
			'gmt':tiempo,
            'time': tiempo_
        },
        onComplete: function(t){
           var  partidos_ind = t.responseText.evalJSON();
                    pintarListaBSK(partidos_ind);
        }
    });
	 var myAjax3 = new Ajax.Request(url, {
        method: "get",
        parameters: {
            'deporte': 'TEN',
			'gmt':tiempo,
            'time': tiempo_
        },
        onComplete: function(t){
           var  partidos_ind = t.responseText.evalJSON();
                    pintarListaTEN(partidos_ind);
        }
    });
	 var myAjax4 = new Ajax.Request(url, {
        method: "get",
        parameters: {
            'deporte': 'HOC',
			'gmt':tiempo,
            'time': tiempo_
        },
        onComplete: function(t){
           var  partidos_ind = t.responseText.evalJSON();
					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();
                    pintarListaHOC(partidos_ind);
        }
    });
}


//cargamos los partidos entre 2 fechas
//cambiar la clase de la fila cuando cambia de estado
cambiar_color = function(id){
    if ($('fila_' + id).hasClassName("filaVivo")) {
        $('fila_' + id).className = "fila" + $('codigo' + id).innerHTML;
    }
    else {
        $('fila_' + id).className = "filaVivo";
    }
    if ($('combi_' + id).hasClassName("celdaVivo")) {
		$('combi_' + id).removeClassName("celdaVivo");
        $('combi_' + id).addClassName ( "celda" + $('codigo' + id).innerHTML);
    }
    else {
		 $('combi_' + id).removeClassName ("celda" + $('codigo' + id).innerHTML)
        $('combi_' + id).addClassName ("celdaVivo");
    }
    if ($('fav_' + id).hasClassName("celdaVivo")) {
		$('fav_' + id).removeClassName("celdaVivo");
        $('fav_' + id).addClassName ("celda" + $('codigo' + id).innerHTML);
    }
    else {
			$('fav_' + id).removeClassName("celda" + $('codigo' + id).innerHTML);
     		 $('fav_' + id).addClassName ("celdaVivo" );
    }
    if ($('res_' + id).hasClassName("celdaVivo")) {
		$('res_' + id).removeClassName("celdaVivo");
        $('res_' + id).addClassName ("celda" + $('codigo' + id).innerHTML);
       
    }
    else {
     	$('res_' + id).removeClassName("celda" + $('codigo' + id).innerHTML);
     	$('res_' + id).addClassName ("celdaVivo" );
    }
    if ($('res_1_' + id).hasClassName("celdaVivo")) {
        $('res_1_' + id).removeClassName("celdaVivo");
        $('res_1_' + id).addClassName ("celda" + $('codigo' + id).innerHTML);
    }
    else {
        $('res_1_' + id).removeClassName("celda" + $('codigo' + id).innerHTML);
     	$('res_1_' + id).addClassName ("celdaVivo" );
    }
	if ($('res_x_' + id)) {
		if ($('res_x_' + id).hasClassName("celdaVivo")) {
			$('res_x_' + id).removeClassName("celdaVivo") ;
			$('res_x_' + id).addClassName("celda" + $('codigo' + id).innerHTML);
			
		}
		else {
			$('res_x_' + id).removeClassName("celda" + $('codigo' + id).innerHTML);
			$('res_x_' + id).addClassName("celdaVivo") ;
			
		}
	}
    if ($('res_2_' + id).hasClassName("celdaVivo")) {
        $('res_2_' + id).removeClassName("celdaVivo") ;
			$('res_2_' + id).addClassName("celda" + $('codigo' + id).innerHTML);
    }
    else {
       $('res_2_' + id).removeClassName("celda" + $('codigo' + id).innerHTML);
			$('res_2_' + id).addClassName("celdaVivo") ;
    }
    
    
}
//Cambiamos los datos que han cambiado SOC

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 ($('partido_' + e.id).getStyle('display') == 'none' || $('liga_' + e.ligaCode).getStyle('display') == 'none') 
						sonidolocal = 'no';
					
					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 ($('partido_' + e.id).getStyle('display') == 'none' || $('liga_' + e.ligaCode).getStyle('display') == 'none') 
						sonidolocal = 'no';
					
					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 cuarenta' : $('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);
    }
}
pintarListaBSK = function(partidos_ind){
	if (partidos_ind != null) {
		partidos_ind.each(function(e){
			if ($('partido_' + e.id  )) {
				if (anteriorr.get(e.id).statusType != e.statusType) {
					cambiar_color(e.id);
					if (e.statusType == 'fin') {
						$('status_celda_' + e.id).className = 'infoFin treinta';
					}
				}
				if (cuotasMaximas == 1 && e.o1 != '0.00' && e.o3 != '0.00' && e.statusType=='sched') {
					link_01 = comparar_cuotas(e.o1, e.o1_ant, e.o1Bid, e.o1Name);
					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_1_' + 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>');
					link_03 = comparar_cuotas(e.o3, e.o3_ant, e.o3Bid, e.o3Name);
					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_2_' + 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>');
				}
				
				$('resultado_actual_' + e.id).update(e.current);
				$('c1_' + e.id).update(e.Q1);
				$('c2_' + e.id).update(e.Q2);
				$('c3_' + e.id).update(e.Q3);
				$('c4_' + e.id).update(e.Q4);
				$('t_' + e.id).update(e.OT);
				$('statu_' + e.id).update(e.status_idioma.substr(0, 4));
				var estado = String(e.statusType);
			
			var partido_anterior=anteriorr.get(e.id);
			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;
			}
				anteriorr.unset(e.id);
				anteriorr.set(e.id, e);
			}
		});
		partidos_ind.clear();
	}
}

pintarListaTEN = function(partidos_ind){
   if (partidos_ind != null) {
		partidos_ind.each(function(e){
			if ($('partido_' + e.id)) {
				if (anteriorr.get(e.id).statusType != e.statusType) {
					cambiar_color(e.id);
					if (e.statusType == 'fin') {
						$('status_celda_' + e.id).className = 'infoFin treinta';
					}
				}
				if (cuotasMaximas == 1 && e.o1 != '0.00' && e.o3 != '0.00' && e.statusType=='sched') {
					link_01 = comparar_cuotas(e.o1, e.o1_ant, e.o1Bid, e.o1Name);
					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_1_' + 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>');
					link_03 = comparar_cuotas(e.o3, e.o3_ant, e.o3Bid, e.o3Name);
					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_2_' + 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>');
				}
				$('resultado_actual_' + e.id).update(e.current);
				$('c1_' + e.id).update(e.S1);
				$('c2_' + e.id).update(e.S2);
				$('c3_' + e.id).update(e.S3);
				$('c4_' + e.id).update(e.S4);
				$('t_' + e.id).update(e.S5);
				$('statu_' + e.id).update(e.status_idioma.substr(0, 4));
				var estado = String(e.statusType);
				var partido_anterior=anteriorr.get(e.id);
				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;
			}
				anteriorr.unset(e.id);
				anteriorr.set(e.id, e);
						}
		});
		partidos_ind.clear();
	}
}
pintarListaHOC = 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 ($('partido_' + e.id).getStyle('display') == 'none' || $('liga_' + e.ligaCode).getStyle('display') == 'none') 
						sonidolocal = 'no';
					
					if ($('div_oculto_' + e.id).getStyle('display') == 'block') 
						activar_individual(e.id, 'HOC');
				}
				else {
					$('golaway' + e.id).setStyle({
						display: 'none'
					});
				}
				if (resultado_h > resultado_anterior_h) {
					cambio = 0;
					sonidolocal = "si";
					$('golhome' + e.id).setStyle({
						display: 'block'
					});
					if ($('partido_' + e.id).getStyle('display') == 'none' || $('liga_' + e.ligaCode).getStyle('display') == 'none') 
						sonidolocal = 'no';
					
					if ($('div_oculto_' + e.id).getStyle('display') == 'block') {
						activar_individual(e.id, 'HOC');
					}
					
				}
				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 cuarenta' : $('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);
				$('p1_' + e.id).update(e.p1);
				$('p2_' + e.id).update(e.p2);
				$('p3_' + e.id).update(e.p3);
				$('ot_' + e.id).update(e.ot);
				$('pn_' + e.id).update(e.pn);
				//$('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.p1=e.p1;
			partido_anterior.p2=e.p2;
			partido_anterior.p3=e.p3;
			partido_anterior.ot=e.ot;
			partido_anterior.pn=e.pn;
			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);
    }
}


//cargamos los goleadores y la apuestas
activar_individual = function(id, tipo_deporte){
    cargar_resultado_ind(id, tipo_deporte);
    cargar_cuotas_ind(id, tipo_deporte);
	if (!$('img_1_'+id))
		pintar_imagnes_cuotas(id);
	
}
//pintamos la imagenes de cuotas
pintar_imagnes_cuotas=function(id){
	var columna='';
	if (location.pathname == '/favoritos.php') {
				var clas_resultado=$('resultado_cuotas'+id).className;
				switch (clas_resultado){
					case 'cntCasasTns':
						var flecha='flechasTns';
						columna='cincuentayseis';
						break;
					case 'cntCasasBsk':
						var flecha='flechaRojaBasket';
						columna='cincuentayseis';
						break;
					default:
						var flecha='flechaRojaFutbol';
						columna='cuarenta';
						break;
				}
			}
			
	partido=anteriorr.get(id);
	 var tdOcultoApuesta3 ="";
	 var tdOcultoApuesta1 ="";
	 var tdOcultoApuesta2 ="";
	 
		var tdOcultoApuesta1 = '<td class="'+columna+'"><img src="/img/'+flecha+'.jpg" alt="flecha" width="19" height="11"  class="tablaFlechasCuotasMargin" /></td>';
        var trOcultoApuesta1 = "<tr>" + tdOcultoApuesta1;
		if ($('res_x_' + partido.id)) {
			var td_temp=tdOcultoApuesta1;
			if (partido.o2 == '0.00'){
				td_temp='<td class="cuarenta">&nbsp;</td>';
			}
			trOcultoApuesta1 += td_temp;
		}
		  trOcultoApuesta1 += tdOcultoApuesta1 + "</tr>";
       
		var link_01_img="";
		var link_02_img="";
		var link_03_img="";
        if (partido.o1 != '0.00') 
            link_01_img = comparar_cuotas_img(partido.o1, partido.o1_ant, partido.o1Bid, partido.o1Name, 1, partido.id);
        if (partido.o2 != '0.00') 
            link_02_img = comparar_cuotas_img(partido.o2, partido.o2_ant, partido.o2Bid, partido.o2Name, 2, partido.id);
        if (partido.o3 != '0.00') 
            link_03_img = comparar_cuotas_img(partido.o3, partido.o3_ant, partido.o3Bid, partido.o3Name, 3, partido.id);
        if (partido.o1 != '0.00') 
		var 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>';
       if (partido.o2 != '0.00' && $('res_x_' + partido.id)) {
	   	var 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>';
	   }
	   else {
	   	if ($('res_x_' + partido.id)) 
	   		var tdOcultoApuesta2 = '<td id="img_2_' + partido.id + '">&nbsp;</td>';
	   }
        if (partido.o3 != '0.00') 
	     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>' + tbodyOcultoApuesta + '</table>';
		$('div_oculto_cuotas'+id).update(tablaOcultaApuesta);
		if (cuotasMaximas==1)
		 cargarCasas_elegidas_partido2(id);
}
//recogemos los goles del partido
cargar_resultado_ind = function(id, tipo_deporte){
	 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_
			        },
        onComplete: function(t){
            res_ind = t.responseText.evalJSON();
            
            pintarGoles(id, tipo_deporte); // pintaremos las listas de todo
        }
        
    });
    
}
obtener_tarjetas = function(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_
        },
        onComplete: function(t){
            pintarTarjetas_ultimas(id,t.responseText.evalJSON()); // pintaremos las listas de todo
        }
    });
    
}
//recogemos las cuotas del partido
cargar_cuotas_ind = function(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,
			'tiempo': tiempo_
        },
        onComplete: function(t){
            var cuotas_ind = t.responseText.evalJSON();
            pintarApuestas(id, tipo_deporte,cuotas_ind); // pintaremos las listas de todo
        }
        
    });
}
//pintamos goles de hockey
function pintar_goles_hoc(id){
	var tabla_res;
	tabla_res = 'tablaResultadoHockey';
	
    if (res_ind) {
        var tabla = new Element('table', {
            'id': tabla_res
        });
        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;
		var imagen_gol = '/img/tanto_hky.png'; 
		
        res_ind.each(function(e){
			e.time = e.time.substring(0,1) + '-' + e.time.substring(1);
          	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 != 5) {
							resultadoA += 1;
						}else{
							resultadoPA+=1;
						}
						gol = e.time + "' " + e.name.substr(0, 10)+" (p.p.)";
						golA = '<div class="golhome"><img src="' + imagen_gol + '" alt="gol" width="12" height="12" /> </div>' + gol;
					}
					else {
						gol = e.time + "' " + e.name.substr(0, 10)+" "+tipo;
						if (e.period != 5) {
							resultadoH += 1;
						}else{
							resultadoPH+=1;
							gol=e.type+" "+ e.time;
						}
						
						golH = '<div class="golaway"><img src="' + imagen_gol + '" alt="gol" width="12" height="12" /> </div>' + gol;
					}
				}else {
						gol = e.time + "' " + e.name.substr(0, 10)+" "+tipo;
						if (e.period != 5) {
							resultadoH += 1;
						}
						else{
							resultadoPH+=1;
							gol=e.type+" "+ e.time;
						}
					golH = '<div class="golaway"><img src="' + imagen_gol + '" 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 != 5) {
							resultadoH += 1;
						}else{
							resultadoPH+=1;
							
						}
						gol = e.time + "' " + e.name.substr(0, 10)+" (p.p.)";
						golH = '<div class="golaway"><img src="' + imagen_gol + '" alt="gol" width="12" height="12" /> </div>' + gol;
					}
					else {
						gol = e.time + "' " + e.name.substr(0, 10)+" "+tipo;
						if (e.period != 5) {
							resultadoA += 1;
						}else{
							resultadoPA+=1;
							gol=e.type+" "+ e.time;
						}
						
						golA = '<div class="golhome"><img src="' + imagen_gol + '" alt="gol" width="12" height="12" /> </div>' + gol;
						
					}
				}else {
						gol = e.time + "' " + e.name.substr(0, 10)+" "+tipo;
						if (e.period != 5) {
							resultadoA += 1;
						}else{
							resultadoPA+=1;
							gol=e.type+" "+ e.time;
						}
						
						golA = '<div class="golhome"><img src="' + imagen_gol + '" alt="gol" width="12" height="12" /> </div>' + gol;
					}
			}
			
			if ( e.period==5){
				periodo4=1;
				resultadoTA=resultadoPA;
				resultadoTH=resultadoPH;
				
				calseP='penalty';
				calseR='penaltyRst';
			}else{
				resultadoTH=resultadoH
				resultadoTA=resultadoA
				calseP='celdaResulIzq';
				calseR='celdaResulCentro bold';
			}
			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': calseP,
                '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) ;
}
//PINTAMOS los goles
pintarGoles = function(id,tipo_deporte){
	if( tipo_deporte == 'HOC')	pintar_goles_hoc(id);
	else							tabla_res = 'tablaResultado';
    if (res_ind) {
        var tabla = new Element('table', {
            'id': tabla_res
        });
        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.)";
						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;
						if (e.period != 4) {
							resultadoH += 1;
						}else{
							resultadoPH+=1;
							gol=e.type+" "+ 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;
						if (e.period != 4) {
							resultadoH += 1;
						}
						else{
							resultadoPH+=1;
							gol=e.type+" "+ 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.)";
						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;
						if (e.period != 4) {
							resultadoA += 1;
						}else{
							resultadoPA+=1;
							gol=e.type+" "+ 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;
						if (e.period != 4) {
							resultadoA += 1;
						}else{
							resultadoPA+=1;
							gol=e.type+" "+ 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;
				
				calseP='penalty';
				calseR='penaltyRst';
			}else{
				resultadoTH=resultadoH
				resultadoTA=resultadoA
				calseP='celdaResulIzq';
				calseR='celdaResulCentro';
			}
			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': calseP,
                '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) ;
}
pintarTarjetas_ultimas = function(id,tar_ind){
	var calseP='celdaResulIzq';
	var calseR='celdaResulCentro';
    if (tar_ind[0]) {
        var tabla = new Element('table', {
            'id': "tablaResultado2"
        });
        var tbody = new Element('tbody');
		if (!res_ind) {
			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'
			});
		}
		if (cantidad_tar == 0) {
			 cantidad_tar = tar_ind.size();
			for (i = 0; i < cantidad_tar; i++) {
				var e = tar_ind[i];
				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" /> ';
				home = e.team == e.id_eHome;
				if (home) {
				
					tarH = '<div class="golaway">' + tarjeta + '</div>' + e.time + "' " + e.name.substr(0, 10);
				}
				away = e.team == e.id_eAway;
				if (away) {
					tarA = '<div class="golhome">' + tarjeta + '</div>' + e.time + "' " + e.name.substr(0, 10);
				}
				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': calseP,
					'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
pintarApuestas = function(id, tipo_deporte,cuotas_ind){
    if (cuotas_ind) {
        var clases = "";
        switch (tipo_deporte) {
            case 'BSK':
                clases = 'Bsk';
                break;
            case 'TEN':
                clases = 'Tns';
                break;
                
        }
        num = cuotas_ind.size();
        var tabla = new Element('table', {
            'id': 'tablaDspCasas' + clases
        });
        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' + clases + '" scope="col">&nbsp;</td>', {
            postion: 'after'
        });
        tr2.insert('<td class="columnaCasas' + clases + '" >1</td>', {
            postion: 'after'
        });
        tr3.insert('<td class="columnaCasas" >X</td>', {
            postion: 'after'
        });
        tr4.insert('<td class="columnaCasas' + clases + '" >2</td>', {
            postion: 'after'
        });
        mejor_o1=0;
		mejor_o2=0;
		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' + clases
            }).update('<a href="' + linkapuesta('casa' + e.bid) + '"  onclick="clic(\'marcadoresonline_link_apuesta_max\',\'' + e.bid + '\');" target="_blank" ><img src="/img/' + e.bid + 'p.png" alt="' + e.name + '" width="34" height="16" class="imgBloqueCasa' + clases + '" /></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.bid + '\');" 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.bid + '\');" 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.bid + '\');" target="_blank"  class="' + clase3 + '">' + e.o3 + '</a>');
            tr4.insert(td, {
                position: 'after'
            });
        });
        tbody.insert(tr1, {
            position: 'after'
        });
        tbody.insert(tr2, {
            position: 'after'
        });
        if (tipo_deporte == 'SOC') {
            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'
        });
    }
}
cargarCasas_elegidas = function(){
    var url = "/mostrarBD/mostrar_casas.php";
    var myAjax = new Ajax.Request(url, {
        method: "get",
        parameters: {
            'fecha1': fecha1,
            'fecha2': fecha2,
            'casas1': casaApuestas[0],
            'casas2': casaApuestas[1],
            'casas3': casaApuestas[2],
			'partidos': anteriorr.keys().join(';')
        },
        onComplete: function(t){
            var  cuotas_casa_max = t.responseText.evalJSON();
            pintarCasasMax(1,cuotas_casa_max); // pintaremos las listas de todo
        }
    });
}
cargarCasas_elegidas_partido = function(id_liga){
	liga_partido[id_liga].each(function(e){
	if ($('img_1_'+e)){
		$('res_1_'+e).update('-')
		$('img_1_'+e).update('')
	}
	if ($('img_2_'+e)){
		$('res_x_'+e).update('-')
		$('img_2_'+e).update('')
	}
	if ($('img_3_'+e)){
		$('res_2_'+e).update('-')
		$('img_3_'+e).update('')
	}
	});
    var url = "/mostrarBD/mostrar_casas.php";
    var myAjax = new Ajax.Request(url, {
        method: "get",
        parameters: {
            'deporte': deporte,
            'fecha1': fecha1,
            'fecha2': fecha2,
            'casas1': casaApuestas[0],
            'casas2': casaApuestas[1],
            'casas3': casaApuestas[2],
            'partidos': liga_partido[id_liga].join(';')
        },
        onComplete: function(t){
           var cuotas_casa_max = t.responseText.evalJSON();
            pintarCasasMax(0,cuotas_casa_max); // pintaremos las listas de todo
        }
    });
}
cargarCasas_elegidas_partido2 = function(id_partido){
	if ($('img_1_'+id_partido)){
		$('img_1_'+id_partido).update('')
	}
	if ($('img_2_'+id_partido)){
		$('img_2_'+id_partido).update('')
	}
	if ($('img_3_'+id_partido)){
		$('img_3_'+id_partido).update('')
	}
    var url = "/mostrarBD/mostrar_casas.php";
    var myAjax = new Ajax.Request(url, {
        method: "get",
        parameters: {
            'deporte': deporte,
            'fecha1': fecha1,
            'fecha2': fecha2,
            'casas1': casaApuestas[0],
            'casas2': casaApuestas[1],
            'casas3': casaApuestas[2],
            'partidos': id_partido
        },
        onComplete: function(t){
            cuotas_casa_max = t.responseText.evalJSON();
            pintarCasasMax(0,cuotas_casa_max); // pintaremos las listas de todo
        }
    });
}
pintarCasasMax = function(borrar,cuotas_casa_max){
    var link_01 = '';
    var link_02 = '';
    var link_03 = '';
    var o1 = 0;
    var o2 = 0;
    var o3 = 0;
    var xsid = 0;
    if (borrar == 1) {
        anteriorr.each(function(e){
            	if ($('img_1_' + e.key)) 
               	 $('img_1_' + e.key).update('');
              	  $('res_1_' + e.key).update("-");
                if ($('res_x_' + e.key)) {
                     $('res_x_' + e.key).update("-");
					 if ($('img_2_' + e.key)) 
                   	 	$('img_2_' + e.key).update('');
                }
                $('res_2_' + e.key).update("-");
                if ($('img_3_' + e.key)) 
               	 $('img_3_' + e.key).update('');
        });
    }
    cuotas_casa_max.each(function(e){
        if ($('partido_' + e.xsid)) {
            if (xsid == e.xsid) {
                if (o1 < e.o1) {
                    link_01 = comparar_cuotas(e.o1, e.o1_ant, e.bid, e.name, 1, e.xsid);
                    link_01_img = comparar_cuotas_img(e.o1, e.o1_ant, e.bid, e.name, 1, e.xsid);
                    o1 = e.o1;
					bid1=e.bid;
					bName1=e.name;
                }
                if ($('res_x_' + e.xsid)) {
                    if (o2 < e.o2) {
                        link_02 = comparar_cuotas(e.o2, e.o2_ant, e.bid, e.name, 2, e.xsid);
                        link_02_img = comparar_cuotas_img(e.o2, e.o2_ant, e.bid, e.name, 2, e.xsid);
                        o2 = e.o2;
						bid2=e.bid;
						bName2=e.name;
                    }
                }
                if (o3 < e.o3) {
                    link_03 = comparar_cuotas(e.o3, e.o3_ant, e.bid, e.name, 3, e.xsid);
                    link_03_img = comparar_cuotas_img(e.o3, e.o3_ant, e.bid, e.name, 3, e.xsid);
                    o3 = e.o3;
					bid3=e.bid;
					bName3=e.name;
                }
            }
            else {
				if (xsid!=0){
					 $('res_1_' + xsid).update(link_01 + o1 + '</a>');
					 if ($('img_1_' + xsid))
                   	 $('img_1_' + xsid).update(link_01_img + '<img src="/img/' + bid1+ 'v.jpg" alt="' + bName1+ '" width="21" height="45" /></a>');
					 if ($('res_x_' + xsid)) {
					 	$('res_x_' + xsid).update(link_02 + o2 + '</a>');
					 	 if ($('img_2_' + xsid))
						$('img_2_' + xsid).update(link_02_img + '<img src="/img/' + bid2 + 'v.jpg" alt="' + bName2 + '" width="21" height="45" /></a>');
					 }
					 $('res_2_' + xsid).update(link_03 + o3 + '</a>');
                    if ($('img_3_' + xsid))
				    $('img_3_' + xsid).update(link_03_img + '<img src="/img/' + bid3+ 'v.jpg" alt="' + bName3+ '" width="21" height="45" /></a>');
				}
                link_01 = comparar_cuotas(e.o1, e.o1_ant, e.bid, e.name, 1, e.xsid);
                link_01_img = comparar_cuotas_img(e.o1, e.o1_ant, e.bid, e.name, 1, e.xsid);
                o1 = e.o1;
				bid1=e.bid;
				bName1=e.name;
                if ($('res_x_' + e.xsid)) {
                    link_02 = comparar_cuotas(e.o2, e.o2_ant, e.bid, e.name, 2, e.xsid);
                    link_02_img = comparar_cuotas_img(e.o2, e.o2_ant, e.bid, e.name, 2, e.xsid);
                    o2 = e.o2;
					bid2=e.bid;
					bName2=e.name;
                }
                link_03 = comparar_cuotas(e.o3, e.o3_ant, e.bid, e.name, 3, e.xsid);
                link_03_img = comparar_cuotas_img(e.o3, e.o3_ant, e.bid, e.name, 3, e.xsid);
                o3 = e.o3;
				bid3=e.bid;
				bName3=e.name;
            }
        }
        xsid = e.xsid;
    });
	if (xsid!=0){
					 $('res_1_' + xsid).update(link_01 + o1 + '</a>');
					  if ($('img_1_' + xsid))
                    $('img_1_' + xsid).update(link_01_img + '<img src="/img/' + bid1+ 'v.jpg" alt="' + bName1+ '" width="21" height="45" /></a>');
					 if ($('res_x_' + xsid)) {
					 	$('res_x_' + xsid).update(link_02 + o2 + '</a>');
					 	 if ($('img_2_' + xsid))
						$('img_2_' + xsid).update(link_02_img + '<img src="/img/' + bid2 + 'v.jpg" alt="' + bName2 + '" width="21" height="45" /></a>');
					 }
					 $('res_2_' + xsid).update(link_03 + o3 + '</a>');
                    if ($('img_3_' + xsid))
				    $('img_3_' + xsid).update(link_03_img + '<img src="/img/' + bid3+ 'v.jpg" alt="' + bName3+ '" width="21" height="45" /></a>');
				}
}
pintarCasasMax_todas=function(){
	cerrarCasasApuestas();
	cuotasMaximas=0;
	anteriorr.each(function(m){
		var e=anteriorr.get(m.key);
		var continuar= String(e.o1)=="0.00"?false:true;
		if (continuar) {
			link_01 = comparar_cuotas(e.o1, e.o1_ant, e.o1Bid, e.o1Name, 1, e.id);
			link_01_img = comparar_cuotas_img(e.o1, e.o1_ant, e.o1Bid, e.o1Name, 1, e.id);
			$('res_1_' + e.id).update(link_01 + e.o1 + '</a>');
			  if ($('img_1_' + 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 ($('res_x_' + e.id)) {
				link_02 = comparar_cuotas(e.o2, e.o2_ant, e.o2Bid, e.o2Name, 2, e.id);
				link_02_img = comparar_cuotas_img(e.o2, e.o2_ant, e.o2Bid, e.o2Name, 2, e.id);
				$('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>');
			}
			link_03 = comparar_cuotas(e.o3, e.o3_ant, e.o3Bid, e.o3Name, 3, e.id);
			link_03_img = comparar_cuotas_img(e.o3, e.o3_ant, e.o3Bid, e.o3Name, 3, e.id);
			 $('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>');
		}  
	})
}
//añadirle el link a las casa de apuestas
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 (!isNaN(cuota_ant)) {
        if (cuota > cuota_ant) {
            imgFlecha = mayor;
            titulo = cuota_ant + ' >> ' + cuota;
        }
        else {
            imgFlecha = menor;
            titulo = cuota_ant + ' >> ' + cuota;
        }
        if (cuota == cuota_ant) {
            titulo = "";
            imgFlecha = igual;
        }
    }
    else {
        imgFlecha = igual;
    }
    var link = imgFlecha + '<a  class="help" id="link_' + o + partido + '" onclick="clic(\'marcadoresonline_link_apuesta_max\',\'' + bid + '\');" target="_blank" title="' + name + ' ' + titulo + '" href="' + linkapuesta('casa' + bid) + '">';
    return link;
}

function comparar_cuotas_img(cuota, cuota_ant, bid, name, o, partido){
    var titulo = '';
    cuota = parseFloat(cuota);
    cuota_ant = parseFloat(cuota_ant);
    if (!isNaN(cuota_ant)) {
        if (cuota > cuota_ant) {
            titulo = cuota_ant + ' >> ' + cuota;
        }
        else {
            titulo = cuota_ant + ' >> ' + cuota;
        }
        if (cuota == cuota_ant) {
            titulo = "";
        }
    }
    var link = '<a  class="help"  id="link_' + o + partido + '" onclick="clic(\'marcadoresonline_link_apuesta_max\',\'' + bid + '\');" target="_blank" title="' + name + ' ' + titulo + '" href="' + linkapuesta('casa' + bid) + '">';
    return link;
}

function ordenar_partidos(){
    var url = "/mostrarBD/mostrar_resultado_ordenados.php";
    if (partidos_ind2.size() == 0) {
        var myAjax = new Ajax.Request(url, {
            method: "get",
            parameters: {
				'gmt':tiempo,
                'deporte': deporte,
                'fecha1': fecha1,
                'fecha2': fecha2
            },
            onComplete: function(t){
                partidos_ind2 = t.responseText.evalJSON();
                pintar_ordenar(); // pintaremos las listas de todo
            }
        });
    }
    else {
        pintar_ordenar();
    }
}

function pintar_ordenar(){
    partidos_ind2.each(function(e){
        if ($('partido_' + e)) {
            $('partidos_en_orden' + deporte).insert($('partido_' + e), {
                position: 'after'
            });
        }
    });
    sin_patido();
}

function pintar_lorden_ligas(){
    anteriorr.each(function(e){
    
        $('partido_liga' + anteriorr.get(e.key).ligaCode).insert($('partido_' + anteriorr.get(e.key).id), {
            position: 'after'
        });
    });
    sin_patido();
}

