function reload() {
	var ajax = new Ajax.Request(
			"http://www.sivm-moto.fr/hac/web/live/view",
			{method: 'post',  
				onSuccess:function(t){$('content').innerHTML=t.responseText;}});

	setTimeout("reload()",30000);
}


function liveAjax() {
	jQuery.get("/live/ajax/liveid/"+liveId+"/lastid/"+lastId, function(xml){
		action = jQuery("commentaire", xml).attr("action");
		if(action != '' && action !=undefined) {
			equipe = jQuery("commentaire", xml).attr("equipe");
			id = jQuery("commentaire", xml).attr("id");
			temps = jQuery("commentaire", xml).attr("temps");
			tempsf = jQuery("commentaire", xml).attr("tempsf");
			commentaireTxt = jQuery("commentaire", xml).text();

			if(jQuery("#td_mil_"+temps).html()==null || jQuery("#td_mil_"+temps).html()=='') {
				jQuery("#live_tbody_com").html(getLiveBloc(temps, tempsf, domicile)+jQuery("#live_tbody_com").html());
			}
			
			if(equipe=='' || equipe==undefined) jQuery("#td_mil_"+temps).html('<div>'+commentaireTxt+'</div>'+jQuery("#td_mil_"+temps).html());
			else jQuery("#td_"+equipe+"_"+temps).html('<div>'+jQuery("commentaire", xml).text()+'</div>'+jQuery("#td_"+equipe+"_"+temps).html());
			
			joueur = jQuery("commentaire", xml).attr("joueur");
			if(action =='6') {
				jQuery("#score_"+equipe).text(Number(jQuery("#score_"+equipe).text())+1);
				jQuery("#joueur_"+joueur).html('<img src="/img/but.gif"/>'+jQuery("#joueur_"+joueur).html());
				jQuery("#buteur_"+equipe).html(jQuery("#joueur_"+joueur).text()+'('+tempsf+')<br />'+jQuery("#buteur_"+equipe).html());
			}
			if(action =='8') {
				jQuery("#joueur_"+joueur).html('<img src="/img/carton_jaune.gif"/>'+jQuery("#joueur_"+joueur).html());
			}
			if(action =='9') {
				jQuery("#joueur_"+joueur).html('<img src="/img/carton_rouge.gif"/>'+jQuery("#joueur_"+joueur).html());
			}
			if(action =='10') {
				remplacent = jQuery("commentaire", xml).attr("remplacent");
				objJoueur = jQuery("#joueur_"+joueur);
				objRemplacent = jQuery("#joueur_"+remplacent);
				txtJoueur = objJoueur.html();
				txtRemplacent = objRemplacent.html();
				objJoueur.html('<img src="/img/entree.gif"/>'+txtRemplacent);
				objJoueur.attr("id","joueur_"+remplacent);
				objRemplacent.html(txtJoueur+'<img src="/img/sortie.gif"/>');
				objRemplacent.attr("id","joueur_"+joueur);
				$("#puceJoueur_"+joueur).attr("id", "puceJoueur_"+remplacent);
			}
			if(action=='11') {
				window.location.reload(true);
			}
			lastId = id;
			liveAjax();
		}
		else {
			setTimeout("liveAjax()",90000);
		}
	}, "xml");
}

function getLiveBloc(temps, tempsf, dom) {
	if(dom) { gauche='hac'; droite='adv'; }
	else { gauche='adv'; droite='hac'; }

	retour = '<tr class="ligne1"><td id="td_'+gauche+'_'+temps+'" class="td_left" width="45%" valign="top"></td>'+
			'<td width="10%" style="text-align:center;" valign="top"><strong>'+tempsf+'</strong></td>'+
			'<td id="td_'+droite+'_'+temps+'" class="td_right" width="45%" valign="top"></td></tr>'+
			'<tr class="ligne2"><td colspan="3" style="text-align:center;"  id="td_mil_'+temps+'"><hr/></td></tr>';
	return retour;
}
