var host = window.location.host;
path = (host == "localhost") ? "http://" + host + "/rusm2/" : "http://" + host + "/";

if (document.images)
{
  pic1 = new Image(16,11);
  pic1.src = path + "images/ajax-loader.gif";  
  pic2 = new Image(16,11);
  pic2.src = path + "images/journeeSel.jpg";
  pic2 = new Image(21,4);
  pic2.src = path + "images/tridesc.jpg";
}
function getXhr()
{
    var xhr = null;
	if(window.XMLHttpRequest) // Firefox et autres
	   xhr = new XMLHttpRequest();
	else if(window.ActiveXObject)
	{ // Internet Explorer
	   try
	   {
                xhr = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                xhr = new ActiveXObject("Microsoft.XMLHTTP");
            }
	}
	else
	{ // XMLHttpRequest non supporté par le navigateur
	   alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
	   xhr = false;
	}
       return xhr;
}
function resultats(journee, numero, count)
{	
	var j = document.getElementById('num').innerHTML;
	if(document.getElementById('j[' + j + ']')) document.getElementById('j[' + j + ']').className = "normal";
	document.getElementById('num').innerHTML = numero;
	var xhr = getXhr();
	xhr.onloading = showwaiting("load");
	xhr.onreadystatechange = function(){
		if(xhr.readyState == 4 && xhr.status == 200){
			xhr.oncomplete = hidewaiting("load");
			leselect = xhr.responseText;			
			document.getElementById('resultats').innerHTML = leselect;
			
			document.getElementById('j[' + numero + ']').className = "selected";
			document.getElementById('journee2').innerHTML = numero;
			document.getElementById('j').innerHTML = (numero == 1) ? "ère" : "ème";
			
		}
	}

	xhr.open("POST", path + "team/resultats2.php",true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send("journee=" + journee);
}
function classement(team, tri, ou)
{
	var ancien = document.getElementById('ancien').innerHTML;
	document.getElementById('class_' + ancien).className = "";
	document.getElementById('ancien').innerHTML = tri + ou;
	
	var xhr = getXhr();
	xhr.onloading = showwaiting("load");
	xhr.onreadystatechange = function(){
		if(xhr.readyState == 4 && xhr.status == 200){
			leselect = xhr.responseText;
			document.getElementById('classement').innerHTML = leselect;
			document.getElementById("class_" + tri + ou).className = "sel";
			xhr.oncomplete = hidewaiting("load");
		}
	}
	xhr.open("POST", path + "team/classement2.php",true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send("team=" + team + "&ou=" + ou + "&tri=" + tri);
}
function matchs(path, mois, cat)
{
	if(mois == 8) document.getElementById('ch8').className = "active";
	else document.getElementById('ch8').className = "p";

	if(mois == 11) document.getElementById('ch11').className = "active";
	else document.getElementById('ch11').className = "p";
	
	if(mois == 1) document.getElementById('ch2').className = "active";
	else document.getElementById('ch2').className = "p";
	
	if(mois == 4) document.getElementById('ch5').className = "active";
	else document.getElementById('ch5').className = "p";

	var xhr = getXhr();
	xhr.onloading = showwaiting("load");
	xhr.onreadystatechange = function(){
		if(xhr.readyState == 4 && xhr.status == 200){
			leselect = xhr.responseText;
			document.getElementById('matchs').innerHTML = leselect;
			xhr.oncomplete = hidewaiting("load");
		}
	}
	xhr.open("POST", path + "calendriercomplet2.php",true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send("mois=" + mois + "&cat=" + cat);
}
function showwaiting(div)
{
	document.getElementById(div).innerHTML = "<img src='" + path + "images/ajax-loader.gif' width='16' height='11' alt='' />";
}
function hidewaiting(div)
{
	document.getElementById(div).innerHTML = "";
}

function changeJournee(numero, count, sens)
{
	if(sens == "next" && numero < count - 2) 
	{
		if(numero < 4) numero = 3;
		numero += 5;
	}
	else if(sens == "prev" && numero > 0) 
	{
		if(numero > 26) numero = 28;
		numero -= 5;
	}

	var t = new Array();
	
	if(numero < 3)
	{
		for(i = 1; i < 6; i++)
		{
			t += journee[i];
		}
	}	
	else if(numero > 2 && numero <= count - 3)
	{
		for(i = numero - 2; i < numero + 3; i++)
		{
			t += journee[i];
		}
	}				
	else if(numero > count - 3)
	{
		for(i = count - 4; i < count + 1; i++)
		{
			t += journee[i];
		}
	}
	document.getElementById("journee").innerHTML = t;
	
	if(numero < 4)
	{
		document.getElementById("next").innerHTML = '<span onclick="changeJournee(' + numero + ', ' + count + ', \'next\')"></span>';
		document.getElementById("prev").className = "blanc";
		document.getElementById("next").className = "next";
	}
	else if(numero >= 4 && numero <= count - 3)
	{
		document.getElementById("next").innerHTML = '<span onclick="changeJournee(' + numero + ', ' + count + ', \'next\')"></span>';
		document.getElementById("prev").innerHTML = '<span onclick="changeJournee(' + numero + ', ' + count + ', \'prev\')"></span>';
		document.getElementById("next").className = "next";
		document.getElementById("prev").className = "prev";
	}
	else if(numero > count - 3) 
	{
		document.getElementById("prev").innerHTML = '<span onclick="changeJournee(' + numero + ', ' + count + ', \'prev\')"></span>';
		document.getElementById("next").className = "blanc";
		document.getElementById("prev").className = "prev";
	}
}

function noyau(team, tri, noyau)
{
	var ancien = document.getElementById('ancien').innerHTML;
	var ordre = document.getElementById('ordre').innerHTML;
	
	if(ancien == tri)
	{
		ordre = (ordre == "desc") ? "asc" : "desc";
	}
	else
	{
		if(tri == "nom" || tri == "date_naissance") ordre = "asc";
		else ordre = "desc";
	}

	document.getElementById('n_' + ancien).className = "tri";
	document.getElementById('n_' + tri).className = "tri" + ordre;
	
	document.getElementById('ancien').innerHTML = tri;
	document.getElementById('ordre').innerHTML = ordre;
	var xhr = getXhr();
	xhr.onloading = showwaiting("load");
	xhr.onreadystatechange = function(){
		if(xhr.readyState == 4 && xhr.status == 200){
			leselect = xhr.responseText;
			document.getElementById('noyau').innerHTML = leselect;
			xhr.oncomplete = hidewaiting("load");
		}
	}
	xhr.open("POST", path + "team/noyau2.php",true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send("team=" + team + "&tri=" + tri + "&ordre=" + ordre + "&noyau=" + noyau);
}
function changerPhoto(path, idPhoto, folder, sens, year, month, day)
{
	if(day < 10) day = "0" + day;
	if(month < 10) month = "0" + month;
 	var num = document.getElementById("numPhoto").innerHTML;
	var xhr = getXhr();
	xhr.onloading = showwaiting("load2");
	xhr.onreadystatechange = function()
	{
		if(xhr.readyState == 4 && xhr.status == 200)
		{
			document.getElementById("load2").innerHTML = "";
			leselect = xhr.responseText;
			document.getElementById('photoo').innerHTML = leselect;
			document.getElementById("numPhoto").innerHTML = parseInt(document.getElementById("numPhoto").innerHTML) + parseInt(sens);
		}
	}
	xhr.open("POST", path + "album/album_photo_detail2.php",true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send("idPhoto=" + idPhoto + "&folder=" + folder + "&year=" + year + "&month=" + month + "&day=" + day);
}




