//   ************************************************************************//
//   * Module Name		: InitCompets2.js									*//
//   * Release			: 3.0												*//
//   * Date				: 20/01/2009										*//
//   * Project			: AGSE_TT											*//
//   * Author			: aCOSwt											*//
//   * Description		: Scripts associated with Compets.html management.	*//
//   * History			: 1.0 : First Site Version							*//
//	 *					  2.0 : 5° Tour + Poules							*//
//	 *					  3.0 : Adaptation to Compets.php phpisation		*//
//   * Language			: JavaScript										*//
//   * Compatibility	: FireFox 2 - IE 7 - Opera 9 - Konqueror 3			*//
//   ************************************************************************//

//********************************* Global Declarations *********************//

	var TourIndiv, PRStat, ToWait, UserId;
	
//**************************** Page init ************************************//

function initCompets(){

var defmes;

	defmes="DESOLES !<br>SOIT VOUS N'ETES PAS IDENTIFIE COMME MEMBRE DU CLUB,<br>SOIT VOUS NE PARTICIPEZ PAS AU CRITERIUM FEDERAL.<br>VOUS POUVEZ NEANMOINS OBTENIR LES POULES ET LES RESULTATS DES COMPETITIONS EN SELECTIONNER UN COMPETITEUR DANS LA LISTE DES COMPETITEURS DU CLUB PLUS BAS DANS CETTE PAGE, ET ACCEDER A SON PARCOURS VIA LE TABLEAU CI-CONTRE";
	UserId=initPage(1,0,8);
	ToWait=0;
	PRStat="P";
	if(RqstId){
		document.getElementById("IDLIN_"+RqstId).style.background="#FFDF12";
		filmylist();}
	else{
		document.getElementById("CGFRAM").contentWindow.document.body.innerHTML=defmes;
		adjframfont("CGFRAM",13);}}

//******************************** Change user id ***************************//

function changeuser(rqstusr){

var vlhref;

	vlhref="http://www.essarts-le-roi-tt.fr/Pages/Compets.php?";
	vlhref=(UserId)?vlhref+"uid="+UserId+"&":vlhref;
	window.location.href=vlhref+"rqstid="+rqstusr;}

//******************************* Fill my turns tab *************************//

function filmylist(){

var	i;

	document.getElementById("TH1").innerHTML=Name;
	for(i=1;i<Persdescr.length;i++)
		if(Persdescr[i][0]!=""){
			document.getElementById("GNRLTD"+i+"_1").innerHTML=Persdescr[i][0];
			if(Persdescr[i][1]!="0")
				document.getElementById("GNRLTD"+i+"_2").innerHTML=Persdescr[i][1];
			else
				disp_mespers();}
	DisplayDetails(i-1);}

//*************************** Display conditions for specific turn **********//

function DisplayDetails(turn){

	TourIndiv=turn;
	if(Persdescr[turn][3]!="")
		document.getElementById("CGFRAM").contentWindow.document.body.innerHTML=Persdescr[turn][3];
	else
		document.getElementById("CGFRAM").contentWindow.document.body.innerHTML="INFORMATIONS NON DISPONIBLES";	
	adjframfont("CGFRAM",14);
	if(ToWait)
		document.getElementById("RSLTFRAM").src="about:blank";
	else
		nextpoules();}


//************************* On iframe load event catcher ********************//

function onRSLTLoad(){

	if(ToWait)
		nextpoules();}

//**************************** Go on after wiping Iframe ********************//

function nextpoules(){

	if(PRStat=="P"){
		if(Persdescr[TourIndiv][4]!="")
			document.getElementById("RSLTFRAM").contentWindow.document.body.innerHTML=Persdescr[TourIndiv][4];
		else
			document.getElementById("RSLTFRAM").contentWindow.document.body.innerHTML="INFORMATIONS NON DISPONIBLES";
		adjframfont("RSLTFRAM",11);}
	else{
		if(Persdescr[TourIndiv][2]!="")
			document.getElementById("RSLTFRAM").src=Persdescr[TourIndiv][2];
		else{
			document.getElementById("RSLTFRAM").contentWindow.document.body.innerHTML="INFORMATIONS NON DISPONIBLES";
			adjframfont("RSLTFRAM",14);}}
	ToWait=0;}

//******************************* Adjust iframe content fonts ***************//

function adjframfont(framid,ftsize){

var ifram, doc;

	ifram=document.getElementById(framid);
	doc = ifram.contentDocument || ifram.contentWindow.document;
	if(PRStat=="P"||framid=="CGFRAM"){
		doc.body.style.fontSize=ftsize+"px";
		doc.body.style.fontFamily="arial";}}

//************************* Display Personal Message if appropriate *********//

function disp_mespers(){

var mesper;

	mespers="Tu es convoqué au prochain tour du criterium fédéral tel qu'indiqué ci-après";
	document.getElementById("PERSMES").innerHTML=mespers;
	document.getElementById("FIREBALL").style.display="block";}

//*************************** Toggle Poules / Results display ***************//

function toggle(categ){

	if(categ=='P'){
		document["PSW"].src="../Images/ActiveWidgets/PouleSwitchOn.gif";
		document["RSW"].src="../Images/ActiveWidgets/ResSwitchOff.gif";
		if(PRStat=="R")
			ToWait=1;
		PRStat="P";}
	else{
		document["PSW"].src="../Images/ActiveWidgets/PouleSwitchOff.gif";
		document["RSW"].src="../Images/ActiveWidgets/ResSwitchOn.gif";
		PRStat="R";}
	DisplayDetails(TourIndiv);}