var car_nb;

function getMinSec(nb){
	min = Math.floor(nb / 60);
	sec = nb % 60;
	if (sec < 10){
		sec  = "0" + sec;
	}
	return "" + min + ":" + sec;
}

function compte_a_rebours(div1,nb,url){
	var d;		
	d = document.getElementById(div1);
	d.innerHTML = getMinSec(nb);
	nb = nb -1;
	if (nb < 0 ){
		document.location = url;
	}
	fonc = "compte_a_rebours('" + div1 + "'," + nb + ",'"+ url+"')";
	window.setTimeout(fonc,1000)
}


function compte_a_rebours_no_redir(div1,nb){
	var d;		
	d = document.getElementById(div1);
	d.innerHTML = getMinSec(nb);
	nb = nb -1;
	if (nb < 0 ){
		nb = 0;
	}
	fonc = "compte_a_rebours_no_redir('" + div1 + "'," + nb + ")";
	window.setTimeout(fonc,1000)
}


function createObjectAJAX() {
	var xhr_object = null;
	if(window.XMLHttpRequest) //Pour Firefox
	{xhr_object = new XMLHttpRequest();}
	else if(window.ActiveXObject){ // Internet Explorer 
		try {
			xhr_object = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) 
		{
			xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	else {alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");return;}
		return xhr_object;
}


var div_refresh

function replace(id_r,url,server){
	div_refresh = document.getElementById(id_r);
	xhr_object = createObjectAJAX();
	
	xhr_object.onreadystatechange=function() {
		var response=null;
		var ready=xhr_object.readyState;
		
		if(ready == 4 ) {
			response=xhr_object.responseText;
			div_refresh.innerHTML=response;
		}
	};
	
	xhr_object.open("GET", url, true);
	xhr_object.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=latin1");
	
	xhr_object.send(server);
}

//Function calc de la page d'accueil
function calc(mon_id){
	document.form_question.reponse.value = mon_id;
	document.form_question.btn_submit_jouer.focus();	
	
    for(i=1;i<6;i++){
    	var image = document.getElementById('img' + i);    		
    	if (image == null){
    		break;
    	}
    	var style_q =  document.getElementById('q'+i).style;
        if(mon_id==i) {
        	image.src = "img/commun/caseOn.gif";
        	style_q.backgroundColor = "#F7F6EF";
        	style_q.color = "#000";
        	style_q.fontWeight = "bold";
        	style_q.borderStyle = "solid";
        	style_q.borderColor = "#E8E7D8";
        } else {
        	image.src = "img/commun/caseOff.gif";
        	style_q.backgroundColor = "transparent";
        	style_q.color = "#909090";
        	style_q.fontWeight = "normal";
        }
    }
}



function setSpanClass2Blue(item,laClass){
	span = item.getElementsByTagName("span");
	span = span[0];
	span.setAttribute("class","txt_bleu");
	span.setAttribute("className","txt_bleu");
}

function setClassementDecorator(tr,response){
	
	if (tr != null){
		tr.setAttribute("class","align_center td_ciel bold");
		tr.setAttribute("className","align_center td_ciel bold");
		tds = tr.getElementsByTagName("td");
		setSpanClass2Blue(tds[0]);
		a  = tds[2].getElementsByTagName("a");
		a = a[1];
		a.setAttribute("class","tooltip txt_bleu txt_taille_110");
		a.setAttribute("className","tooltip txt_bleu txt_taille_110");
		tds[3].setAttribute("class","align_right td_ciel");
		tds[3].setAttribute("className","align_right td_ciel");
		setSpanClass2Blue(tds[3]);
		setSpanClass2Blue(tds[4]);
	}
	
	tab = response.split('|');
	for (i=0; i < tab.length; i++){
		ligne = tab[i].split('#');		
		id = ligne[0];
		date = ligne[1];
		defiable = ligne[2];
	
		if (date != ''){
			span = document.getElementById("date_defi_" + id);
			if (span != null) {
				span.setAttribute('style','visibility:visible');
				if (document.all)  span.style.setAttribute("cssText","visibility:visible");
				y = date.substring(0,4);
				m = date.substring(5,7);				
				j = date.substring(8,10);
				d = new Date(y, m - 1 ,j);
				span.setAttribute('title','Vous avez défié ce joueur le ' + j + '/' + m + '/' + y);
			}
		}
		
		if (defiable == "1") {		
			now = new Date();
			if ( date == '' || now.getTime() - d.getTime() > 15 * 86400 * 1000){
				bouton = document.getElementById('defi_' + id);
				if (bouton != null) {
					bouton.setAttribute('style','visibility:visible');					
					if (document.all) bouton.style.setAttribute("cssText","visibility:visible");
				}
			}
		}
	}
}