function emptyField(obj) {
	if(obj.id == 'identifiant') {
		if(obj.value=='votre identifiant') obj.value='';
	} else if(obj.id == 'password') {
		obj.style.backgroundColor = '#FFFFFF';
	}
}

/* Menu */
function openMenu(obj, act) {
	if(obj && obj!='') {
		var myMenu = obj.parentNode;
		var allMenus = myMenu.parentNode.getElementsByTagName('li');
		if(myMenu.className.search(/Actif/)!=-1 && act) myMenu.className = myMenu.className.replace(/Actif/,"");
		else {
			for(var i=0; i<allMenus.length; i++) {
				allMenus[i].className = allMenus[i].className.replace(/Actif/,"");
			}
			myMenu.className = myMenu.className + 'Actif';
		}
	}
}

/* Scroll */
function getObj(name) {
	if(document.getElementById) {
		this.obj = document.getElementById(name);
		this.style = document.getElementById(name).style;
	}
	else if(document.all) {
		this.obj = document.all[name];
		this.style = document.all[name].style;
	}
	else if(document.layers) {
		this.obj = document.layers[name];
		this.style = document.layers[name];
	}
}

var varsDeb = new Array()
var time,amount,theTime,theHeight,DHTML,thelayer;
var zoneScroll = "zonescroll";

function init() {
	DHTML = (document.getElementById || document.all || document.layers)
	if(!DHTML) { return; }
	var x = new getObj(zoneScroll);
	if(document.layers) {
		lyrheight = x.style.clip.bottom;
		lyrheight += 20;
		x.style.clip.top = clipTop;
		x.style.clip.left = 0;
		x.style.clip.right = clipWidth;
		x.style.clip.bottom = clipBottom;
	}
	else if(document.getElementById || document.all) {
		lyrheight = x.obj.offsetHeight;
		x.style.clip = 'rect('+clipTop+'px,'+clipWidth+'px,'+clipBottom+'px,0)';
	}
}

function scrollayer(layername,amt,tim) {
	if(!DHTML) { return; }
	thelayer = new getObj(layername);
	if(!thelayer) { return; }
	amount = amt;
	theTime = tim;
	realscroll();
}

function realscroll() {
	if(!DHTML) return;
	clipTop += amount;
	clipBottom += amount;
	topper -= amount;
	if(clipTop < 0 || clipBottom >= lyrheight) {
		clipTop -= amount;
		clipBottom -= amount;
		topper += amount;
		return;
	}

	// Déplacement du texte
	reinitscroll(clipTop,clipBottom,topper);

	if(theTime!=0) time = setTimeout('realscroll()',theTime);
}

function reinitscroll(clipTop,clipBottom,topper) {
	if(!DHTML) return;
	if(document.getElementById || document.all) {
		var clipstring = 'rect('+clipTop+'px,'+clipWidth+'px,'+clipBottom+'px,0)';
		thelayer.style.clip = clipstring;
		thelayer.style.top = topper + 'px';
	}
	else if(document.layers) {
		thelayer.style.clip.top = clipTop;
		thelayer.style.clip.bottom = clipBottom;
		thelayer.style.top = topper;
	}
}

function stopScroll() {
	if(time) { clearTimeout(time); }
}

function prepLyr() {
	DHTML = (document.getElementById || document.all || document.layers)
	if(!DHTML) { return; }
	if(document.layers) {
		lyrheight = x.style.clip.bottom;
		lyrheight += 20;

		x.style.clip.top = clipTop;
		x.style.clip.left = 0;
		x.style.clip.right = clipWidth;
		x.style.clip.bottom = clipBottom;
	}
	else if(document.getElementById || document.all) {
		lyrheight = x.obj.offsetHeight;
		x.style.clip = 'rect('+clipTop+'px,'+clipWidth+'px,'+clipBottom+'px,0)';
	}
}
/* Fin scroll */

/* scroll obj */
function theScroll(zoneScroll, clipTop, clipWidth, clipBottom, topper, lyrheight) {
	this.zoneScroll = zoneScroll;
	this.varsDeb = new Array()
	this.clipTop = this.varsDeb["clipTop"] = clipTop;
	this.clipWidth = clipWidth;
	this.clipBottom = this.varsDeb["clipBottom"] = clipBottom;
	this.topper = this.varsDeb["topper"] = topper;
	this.lyrheight = lyrheight;
	this.amount = 10;
	this.theTime = 40;
	this.time,this.theHeight,this.DHTML,this.thelayer;

	function getObj(name) {
		if(document.getElementById) {
			this.obj = document.getElementById(name);
			this.style = document.getElementById(name).style;
		}
		else if(document.all) {
			this.obj = document.all[name];
			this.style = document.all[name].style;
		}
		else if(document.layers) {
			this.obj = document.layers[name];
			this.style = document.layers[name];
		}
	}

	this.init = function () {
		this.DHTML = (document.getElementById || document.all || document.layers);
		if(!this.DHTML) { return; }
		this.x = new getObj(this.zoneScroll);
		if(document.layers) {
			this.lyrheight = this.x.style.clip.bottom;
			this.lyrheight += 20;
			this.x.style.clip.top = this.clipTop;
			this.x.style.clip.left = 0;
			this.x.style.clip.right = this.clipWidth;
			this.x.style.clip.bottom = this.clipBottom;
		}
		else if(document.getElementById || document.all) {
			this.lyrheight = this.x.obj.offsetHeight;
			this.x.style.clip = 'rect('+this.clipTop+'px,'+this.clipWidth+'px,'+this.clipBottom+'px,0)';
		}
	}
	this.init();

	this.scrollayer = function (layername,amt,tim) {
		if(!this.DHTML) { return; }
		this.thelayer = new getObj(layername);
		if(!this.thelayer) { return; }
		this.amount = amt;
		this.theTime = tim;
		this.realscroll();
	}

	this.realscroll = function () {
		if(!this.DHTML) return;
		this.clipTop += this.amount;
		this.clipBottom += this.amount;
		this.topper -= this.amount;

		if(this.clipTop < 0 || this.clipBottom >= this.lyrheight) {
			this.clipTop -= this.amount;
			this.clipBottom -= this.amount;
			this.topper += this.amount;
			return;
		}

		//déplacement du texte
		this.reinitscroll(this.clipTop,this.clipBottom,this.topper);
		obj = this;
		if(this.theTime!=0) this.time = setTimeout( 'obj.realscroll()' ,this.theTime);
	}

	this.reinitscroll = function (clipTop,clipBottom,topper) {
		if(!this.DHTML) return;
		if(document.getElementById || document.all) {
			var clipstring = 'rect('+clipTop+'px,'+this.clipWidth+'px,'+clipBottom+'px,0)';
			this.thelayer.style.clip = clipstring;
			this.thelayer.style.top = topper + 'px';
		}
		else if(document.layers) {
			this.thelayer.style.clip.top = clipTop;
			this.thelayer.style.clip.bottom = clipBottom;
			this.thelayer.style.top = topper;
		}
	}

	this.stopScroll = function () {
		clearTimeout(this.time);
	}
}
/* fin scroll obj */

function chooseValues(idSelect) {
	myOptions = document.getElementById(idSelect).getElementsByTagName('div')[0];
	if(myOptions.style.display!='block'){
		myOptions.style.display = 'block';
	}
	else{
		myOptions.style.display = 'none';
	}
}

function checkValue(idSelect,idField,newValue) {
	myLink = document.getElementById(idSelect).getElementsByTagName('a')[0];

	clickedLink = document.getElementById(idSelect+'_'+newValue);
	if(idField != '') {
		myField = document.getElementById(idField);
		myField.value = newValue;
	}
	myLink.innerHTML = clickedLink.innerHTML;
	chooseValues(idSelect);
}

function chkBox(checkbox, css) {
	if(document.getElementById(checkbox).checked == false ) document.getElementById(checkbox).parentNode.className=css;
	else document.getElementById(checkbox).parentNode.className=css+'On';
}

function fileValue() {
	document.getElementById('nsFileText').innerHTML=document.getElementById('video').value;
}

function openClose(obj) {
	var myObj = document.getElementById(obj);
	if(myObj.style.display!='block') myObj.style.display='block';
	else myObj.style.display='none'
}

function openVideoJury (myurl,idCadre) {
	if(myurl && myurl!='' && document.getElementById(idCadre).style.display!='block') {
		var flashvars = {};
		var params = { quality: "high", wmode: "transparent" };
		var attributes = {};
		swfobject.embedSWF(myurl, idCadre, "600", "332", "9.0.0", "../includes/swf/expressInstall.swf", flashvars, params, attributes);
		document.getElementById(idCadre).style.display='block';
	}
	else {
		document.getElementById(idCadre).style.display='none';
	}
}

function createRequest(mimetype){
	var request = null;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		request = new XMLHttpRequest();
		if (request.overrideMimeType) {
			request.overrideMimeType(mimetype);
		}
	}
	else if (window.ActiveXObject) { // IE
		try {
			request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	if (!request) {
		alert('Abandon :( Impossible de créer une instance XMLHTTP');
		return false;
	}
	return request;
}

function sendRequest(request, url, typeaction, cible1, cible2){
	request.onreadystatechange = function() { processReqChangeGeneric(request, typeaction, cible1, cible2); };
	request.open('GET', url, true);
	request.send(null);
}


function processReqChangeGeneric(request, typeaction, cible1, cible2) {
	if (request.readyState == 4) {
		if (request.status == 200) {
			if (typeaction=='innerHTML' && document.getElementById(cible1))
				{ document.getElementById(cible1).innerHTML = request.responseText; }
			else if (typeaction=='Alert')
				{ alert(request.responseText); }
			else if (typeaction=='Javascript')
				{ eval(cible1); }
		}

		request.abort();
		request=null;
		request=false;
	}
}

function displayComments(pseudo, page){
	var request1 = createRequest('text/html');
	sendRequest(request1,'/dynamic/web.php?q=display_comments_ajax&pseudo='+escape(pseudo)+'&page='+escape(page), 'innerHTML', 'bottle_comments', '');
}

function change_news(id_news) {
	var request1 = createRequest('text/html');
	sendRequest(request1,'/dynamic/news.php?q=change_news&id_news='+escape(id_news), 'innerHTML', 'newsDetail', '');
}

function change_faq(id_faq) {
	var request1 = createRequest('text/html');
	sendRequest(request1,'/dynamic/faq.php?q=change_faq&id_faq='+escape(id_faq), 'innerHTML', 'FaqDetail', '');
}

function change_liste_video(tri) {
	var request1 = createRequest('text/html');
	sendRequest(request1,'/dynamic/news.php?q=change_liste_video&orderby='+escape(tri), 'innerHTML', 'liste_video_tri', '');
}

function change_video_encours(id_equipe) {
	var request1 = createRequest('text/html');
	sendRequest(request1,'/dynamic/video.php?q=change_video_encours&id_equipe='+escape(id_equipe), 'innerHTML', 'flashMain', '');
}

function change_liste_video_recherche(tri,withcritere) {
	var request1 = createRequest('text/html');
	sendRequest(request1,'/dynamic/video.php?q=liste_video_recherche&orderby='+escape(tri)+'&withcritere='+escape(withcritere), 'innerHTML', 'liste_video_tri', '');
}

function si_connecte() {
	var request1=createRequest('text/html');
	sendRequest(request1,'/dynamic/web.php?q=verif_connection', 'innerHTML', 'form_identite', '');
}

function checkValue_ecole(newValue) {
	if(newValue==0) {
		document.getElementById('ecole2').style.visibility='visible';
		document.getElementById('label_ecole').style.visibility='visible';
	}
	else {
		document.getElementById('ecole2').style.visibility='hidden';
		document.getElementById('label_ecole').style.visibility='hidden';
		document.getElementById('ecole2').value='';
	}
}
