function xhr_connect(){
	var xhr = false
	if (window.XMLHttpRequest) {
		
		xhr = new XMLHttpRequest
		
	} else if (window.ActiveXObject) {
		
		var reussi = false
		
		var iexhr = new Array("Msxml2.XMLHTTP.7.0", "Msxml2.XMLHTTP.6.0","Msxml2.XMLHTTP.5.0","Msxml2.XMLHTTP.4.0","Msxml2.XMLHTTP.3.0","Msxml2.XMLHTTP.2.0", "Microsoft.XMLHTTP")
		
		for (var i = 0; i<iexhr.length && !reussi; i++) {
			try {
				xhr = new ActiveXObject(iexhr[i])
				reussi = true
			} catch(e) {}
		}
	}
	return xhr;
}

/*------------------------------------------
            Entrainement du jour
-------------------------------------------*/

function charge_entrainement(arg){
	var objxhr = xhr_connect()
	if (objxhr) {
			objxhr.onreadystatechange = function() {
			if (objxhr.readyState == 4) {
				if (objxhr.status == 200) {	
					reset_com();
					reset_entrainement()
					affiche_commentaire(arg)
					var retour = objxhr.responseText
					affiche_entrainement(retour)
	
				}
			}
		}
		var sql = "date=" + arg;
		objxhr.open("POST" , "charge_entrainement.php" ,true)
		objxhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		objxhr.send(sql)
}
}


function reset_com(){
	var bloc_comment = document.getElementById('com_deb');
	while (bloc_comment.firstChild) {
		bloc_comment.removeChild(bloc_comment.firstChild)
	}	
}

function reset_entrainement() {
	var bloc_training = document.getElementById('date_training');
	while (bloc_training.firstChild) {
		bloc_training.removeChild(bloc_training.firstChild)
	}
	
}

function affiche_comment(){
	new Effect.toggle('comments_training', 'appear');
}


function affiche_entrainement(entrainement) {
	
	var bloc_training = document.getElementById('date_training');
	var div = document.createElement('div');
	div.innerHTML = entrainement
	bloc_training.appendChild(div)
	new Effect.BlindDown('date_training');
	mask_comment_training()
	
}


function mask_comment_training(){
	var bloc_comment = document.getElementById('comments_training');
	bloc_comment.style.display = 'none';
}


function charge_commentaire(date,comment){
	
	var objxhr = xhr_connect()
	if (objxhr) {
			objxhr.onreadystatechange = function() {
			if (objxhr.readyState == 4) {
				if (objxhr.status == 200) {				
					//var retour = objxhr.responseText	
					charge_entrainement(date)
				}
			}
		}
		var comment_training = "date=" + date +"&comment=" + comment;
		objxhr.open("POST" , "charge_commentaires.php" ,true)
		objxhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		objxhr.send(comment_training)
}
}


function affiche_commentaire(arg) {
	
	var objxhr = xhr_connect()
	if (objxhr) {
			objxhr.onreadystatechange = function() {
			if (objxhr.readyState == 4) {
				if (objxhr.status == 200) {				
					var retour = objxhr.responseText
					place_commentaires(retour)
				}
			}
		}
		var com_training = "date=" + arg;
		objxhr.open("POST" , "affiche_commentaires.php" ,true)
		objxhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		objxhr.send(com_training)
}
	
}


function place_commentaires(arg){
		var coms = document.getElementById('les_coms');
		coms.innerHTML = arg
}

/*------------------------------------------
            Les news
-------------------------------------------*/

function affiche_area_comment_news(id_news){
	new Effect.toggle('comment_news'+id_news, 'appear');
}

function charge_commentaire_news(id_news,commentaire) {
	var objxhr = xhr_connect()
	if (objxhr) {
			objxhr.onreadystatechange = function() {
			if (objxhr.readyState == 4) {
				if (objxhr.status == 200) {	
					reset_com_news(id_news);
					affiche_area_comment_news(id_news)
					affiche_commentaire_news(id_news)
				}
			}
		}
		var commentaire_news = "id_news=" + id_news +"&comment=" + commentaire;
		objxhr.open("POST" , "charge_commentaire_news.php" ,true)
		objxhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		objxhr.send(commentaire_news)
}
}

function affiche_commentaire_news(idnews) {
	var objxhr = xhr_connect()
	if (objxhr) {
			objxhr.onreadystatechange = function() {
			if (objxhr.readyState == 4) {
				if (objxhr.status == 200) {				
					var retour = objxhr.responseText
					/*apres avoir construit la chaine, on la place au bon endroit*/
					place_commentaires_news(retour,idnews)
				}
			}
		}
		var com_training = "id_news=" + idnews;
		objxhr.open("POST" , "affiche_commentaires_news.php" ,true)
		objxhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		objxhr.send(com_training)
}
	
}

function place_commentaires_news(arg,idnews){
		var coms = document.getElementById('les_coms_news'+idnews);
		coms.innerHTML = arg
}

function reset_com_news(idnews){
	var bloc_comment_news = document.getElementById('com_deb_news'+idnews);
	while (bloc_comment_news.firstChild) {
		bloc_comment_news.removeChild(bloc_comment_news.firstChild)
	}	
	
	
}

function affiche_vignettes(){
	var doc_photos = document.getElementById('bloc_photoscadre');
	while (doc_photos.firstChild) {
		doc_photos.removeChild(doc_photos.firstChild)
	}	
	var lesvignettes = document.getElementById('vignettes_photos_bb09');
	lesvignettes.style.display = 'block'
}

function affiche_vignettes_ass(){
	var doc_photos = document.getElementById('bloc_photoscadre');
	while (doc_photos.firstChild) {
		doc_photos.removeChild(doc_photos.firstChild)
	}	
	var lesvignettes = document.getElementById('vignettes_photos_assemblee09');
	lesvignettes.style.display = 'block'
}

function affiche_vignettes_natathlon(){
	var doc_photos = document.getElementById('bloc_photoscadre');
	while (doc_photos.firstChild) {
		doc_photos.removeChild(doc_photos.firstChild)
	}	
	var lesvignettes = document.getElementById('vignettes_photos_natathlon');
	lesvignettes.style.display = 'block'
}

function apellevid100nl() {
	var le100dos = document.getElementById('100dos');
	le100dos.style.display = 'none';
	var le400nl = document.getElementById('400nl');
	le400nl.style.display = 'none';
	
	var lavid = document.getElementById('100nl');
	new Effect.BlindDown(lavid);

}

function apellevid100dos() {
	var le100nl = document.getElementById('100nl');
	le100nl.style.display = 'none';
	var le400nl = document.getElementById('400nl');
	le400nl.style.display = 'none';
	var lavid = document.getElementById('100dos');
	new Effect.BlindDown(lavid);

}

function apellevid400nl() {
	var le100dos = document.getElementById('100dos');
	le100dos.style.display = 'none';
	var le100nl = document.getElementById('100nl');
	le100nl.style.display = 'none';
	
	var lavid = document.getElementById('400nl');
	new Effect.BlindDown(lavid);

}