var dom = net = iex = false;
if (document.getElementById) dom = true; // IE5+ ou Netscape6+/Mozilla
if (document.layers) net = true; // Netscape4
if (document.all) iex = true; // IE4+

if (iex) {
  var larg_utile = "document.body.offsetWidth";
  var haut_utile = "document.body.offsetHeight";
}
else if (dom || net) {
  var larg_utile = "window.innerWidth";
  var haut_utile = "window.innerHeight";
}
else {}
var nb_couleurs = screen.colorDepth;
var larg_ecran = screen.width;
var haut_ecran = screen.height;

function confirmLink(theLink)
{
    // Confirmation is not required in the configuration file
    // or browser is Opera (crappy js implementation)
    if (confirmMsg == '' || typeof(window.opera) != 'undefined') {
        return true;
    }

    var is_confirmed = confirm(confirmMsg + ' :\nAttention');
    if (is_confirmed) {
        theLink.href += '&is_js_confirmed=1';
    }

    return is_confirmed;
} // end of the 'confirmLink()' function

//REDUCTIONS 
function swapz(zone) {
  var map = document.getElementById(zone);

  if (map.style.display == "none"){
    map.style.display = "block"; 
  }else{
    map.style.display = "none"; 
  }
}
//reduction d'une zone, changement des images
function afficherAutre(theblok,zone) {
  var map = document.getElementById(zone);
  var nav = document.getElementById(theblok);

  if (map.style.display == "none"){
    map.style.display = "block"; 
	nav.src = path+'img/moins.png';
  }else{
    map.style.display = "none"; 
	nav.src = path+'img/plus.png';
  }
}
function ChangeStatut(formulaire) {
if(formulaire.reglement.checked == true) {formulaire.validation.disabled = false }
if(formulaire.reglement.checked == false) {formulaire.validation.disabled = true }
}
function ouvrir() {
var nouvelleFenetre =
	open("reglement.php", "secondeFenetre",
		"width=500,height=400");
}
function val(formulaire) {
formulaire.submit()
}



//SCRIPT 3
function ViewPage(page) {
var options="menubar=no,scrollbars=yes,statusbar=no";
  var top=(0);
  var left=(0);
 window.open(page,"","top="+top+",left="+left+","+options); 
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function hide_me(){
	zone_clock.style.display = "none"; 
}
/*
	AUTO-REFRESH SYSTEM
*/
function clear(){
	document.getElementById("zt").innerHTML='';
	document.getElementById("bod").innerHTML='';
}
function reload_now(){
	clear();
	history.go(0);
}
function delai(){
	tleft--;
	document.getElementById("zonetps").innerHTML = tleft;
	if(tleft>0){
		setTimeout("delai()",1000);
	}else{
		if(tleft==0){
			reload_now();
		}
	}
}
function cancel(){
	document.getElementById("zt").innerHTML='';
	tleft=-1;
}
/*
	HORLOGE
*/
var age=0;

function display_time(second, disp){
	var min=0, hour=0, out='';
	if(second>=60){
		min = Math.floor(second / 60);
		second =  second-(60*min);
	}
	if(min>=60){
		hour = Math.floor(min / 60);
		min =  min- (60*hour);
	}
	if(min<10){
		min='0'+min;
	}
	if(second<10){
		second='0'+second;
	}
	if(hour<10){
		hour='0'+hour;
	}
	/*
	if(hour>=24){
		days = Math.floor(hour / 24);
		hour -= 24*days;
	}
	*/
	if(disp==1){
		if(hour>0){
			out=hour+'h';
			if(min>0){
				out=out+min+'\'';
			}
		}else{
			if(min>0){
				out=min+'\'';
			}
		}
		out=out+second+'\'\'';
	}else{
		out=hour+':'+min+':'+second;
	}
	return out;
}

function top_swap(){
	zone_top1=document.getElementById('zone_top1');
	if(zone_top1.style.display == 'none'){
		zone_top1.style.display = 'block';
	}else{
		zone_top1.style.display = 'none';
	}
}

function letemps(){
	temps+=1;
	age=temps-temps_i;
	if(temps==86400){
		history.go(0);
	}
	zone_tps.innerHTML= display_time(temps, 0);
	zone_age.innerHTML= display_time(age, 1);
	setTimeout("letemps()",1000);
}

function mod_motd(zone_name, text){
	zone=document.getElementById(zone_name);
	zone.innerHTML= '<form action="" method="post">\n<input type="text" name="motd_txt" maxlength="64" size="60" value="'+text+'" />&nbsp;&nbsp;<input type="submit" name="send" value="Ok" /></form>';
}

//fonctionnement de la box
function close_box_info(){
	var zone = document.getElementById('zone_info');
	zone.style.display = 'none';
}
function show_box_info(titre, page, args){
	var zone = document.getElementById('zone_info');
	var zone_t = document.getElementById('zi_bando');
	var zone_c = document.getElementById('zi_content');
	
	zone_c.innerHTML='';
	zone_t.innerHTML=titre;
	ajax_fill('zi_content', page, args);
	
	zone.style.display = 'block';
}
function parse_form(page){
	var ret;
	var zone = document.getElementById('zone_txt_send');
	var zone_s = document.getElementById('zone_id_send');
	ret='action=send&sujet='+zone_s.value+'&msg='+zone.innerHTML;
	show_box_info('Message envoye !', page, ret);
	//close_box_info();
}
function hide_zone(zone_name){
	var zone = document.getElementById(zone_name);
	zone.style.display = 'none';
}

function sec2hms(second, sec){
	min=0;
	hour=0;
	day=0;

	if(second>=60){
		min = Math.floor(second / 60);
		second -= 60*min;
	}
	if(min>=60){
		hour = Math.floor(min / 60);
		min -= 60*hour;
	}
	if(hour>=24){
		day = Math.floor(hour / 24);
		hour -= 24*day;
	}

	if(sec==1){
		out = "&nbsp;"+second+"s";
	}

	if(min>0){
		out=min+"m"+out;
	}
	if(hour>0){
		out=hour+"h "+out;
	}
	if(day>0){
		out=day+" jour(s) "+out;
	}
	return out;
}


/* Fonction multi select pr le mailer */
    //////////////////////////////////////////////////////////////////////////////////////
   // function checkall()
    // cette fonction s'execute lorsqu'on clique sur la checkbox principale
    // elle passe en revue les checkbox et les coche si necessaire
    // la checkbox d'indice 0 est la checkbox principale
    // rem si ovus ajouter des element de formulaire, il faudra mofifier le script
   // car l'instruction : temp = document.main.elements.length; comptabilise
   // tous les elements et pas uniquement les checkbox...
   //////////////////////////////////////////////////////////////////////////////////////
   function checkall()
   {
      // compte tous les éléments du formulaire en numérotant chronologiquement
    temp = document.main.elements.length;
      if (document.main.elements[0].checked)
      { // si la case est cochée
        for (i=1; i < temp; i++)
        { // on coche toutes les autres
            document.main.elements[i].checked=1;
       }
      }
     else
      {
         for (i=1; i < temp; i++)
        { // on décoche tout
            document.main.elements[i].checked=0;
        }
      }
   }
   //////////////////////////////////////////////////////////////////////////////////////
   // function checkone()
   // cette fonction s'execute lorsqu'on coche ou décoche une checkbox qcq
   // elle fait le compte des checkbox cochée pour savoir s'il faut décocher
   // ou cocher la checkbox principale...
   //////////////////////////////////////////////////////////////////////////////////////
   function checkone()
   {
      m=0; // initialisation du nombre de cases cochées
      temp = document.main.elements.length;
      for (i=1; i < temp; i++)
      { // on commence à 1 pour ne pas prendre en compte la checkbox principale
        if (document.main.elements[i].checked)
        { // si la checkbox courante est cochée, on comptabilise
        m++;
        }
      }
      if (document.main.elements[0].checked)
      { // si la checkbox principale est cochée, on la décoche
         document.main.elements[0].checked=0;
      }
      else
      { // dans le cas contraire, on vérifie que toutes les checkbox sont cochées
        if (m == (temp-1)) document.main.elements[0].checked=1;
     }
   }
   //////////////////////////////////////////////////////////////////////////////////////
  // function verifselection()
   // cette fonction s'execute qd on clique sur le bouton supprimer
   // elle vérifie que l'on a bien selectionné un objet au moins...
   //////////////////////////////////////////////////////////////////////////////////////
   function verifselection(msg_config, msg_error)
   {
      n=0;
      temp = document.main.elements.length;
     for (i=1; i< temp;i++)
      {
        if (document.main.elements[i].checked)
        {
        n=n+1;
        }
      }
      if (n != 0)
     {
        if (msg_config!=''){
			if(confirm(msg_config))
	        {
	            document.main.submit();
	        }
		}else{
			document.main.submit();
		}
      }
      else
      {
        alert(msg_error);
      }
  }
  
  
  
/*** menu du haut pour user***************/
function CreerMenu(titre,target,carac) {
	this.nb=0;this.titre=titre;this.target=target;this.carac=carac;
	this.Add=AddObjet;
	this.Aff=AffMenu;
}
function AddObjet(deep,txt,page) {
	var rub = new Object;
	rub.deep=deep;
	rub.txt=txt;
	rub.page=page;
	this[this.nb]=rub;
	this.nb++;
}
function space(i) {var Z="";for (var j=1;j<i;j++){Z+="&nbsp;&nbsp;&nbsp;&nbsp;";}return Z}
function AffMenu() {
	var Z="<FORM name='mf'>";var z="";
	Z+="<SELECT size=1 name='tjs' onChange='Clic(this.form);'><OPTION>"+this.titre+"</OPTION>";
	for (var i=0;i<this.nb;i++) {
		z=""; if ((this[i].page!="")&&(this[i].page!=null)) {z=this.carac}
		Z+="<OPTION value='"+this[i].page+"'>"+space(this[i].deep)+z+this[i].txt+"</OPTION>"
	}
	Z+="</SELECT>";
	Z+="</FORM>";
	document.write(Z);
}
function Clic(f){
	var i=f.elements["tjs"].selectedIndex-1;
	if (i>=0) {
		var page=menu[i].page;
		if ((page!="")&&(page!=null)) {
			window.location=page
			
		}
	}
}


function change_race(r){// pour la PDE
    window.location="?action=r&r="+r+"";
}
function js_max_ship(nb,lieu){// pour le /space/index.php
    document.getElementById(lieu).value=nb;
}
function tpst(s){
            m=0;h=0;jrs=0;
            sss=s;
			if(s<0){
                return 0;
            }else{
                if(s>59){m=Math.floor(s/60);s=s-m*60}
                if(m>59){h=Math.floor(m/60);m=m-h*60}
                if(h>23){jrs=Math.floor(h/24);h=h-jrs*24}
				
				if(s==0){s=""}
				if(m==0){m=""}
				if(h==0){h=""}
				if(jrs==0){jrs=""}
				
				if(s!="")s=s+"sec";
				if(m!="")m=m+"min ";
				if(h!="")h=h+"h ";
				if(jrs!="")jrs=jrs+"jrs ";
				
				if(sss>0){re="<span id=red><i><b>"+jrs+h+m+s+"</b></i></span>";}
				if(sss>5*60){re="<span id=red><i>"+jrs+h+m+s+"</i></span>";}
				if(sss>10*60){re="<span id=orange><i>"+jrs+h+m+s+"</i></span>";}
				if(sss>30*60){re="<span id=green><i>"+jrs+h+m+s+"</i></span>";}
				if(sss>3600){re="<span id=purple><i>"+jrs+h+m+s+"</i></span>";}
				return re;
     }
}
function de(zone,x){
		    document.getElementById(zone).innerHTML=tpst(x);
			x=x-1;
			if(x==-1){window.location.replace("?");}
			setTimeout("de('"+zone+"',"+x+")",1000);
}
function decompteur(zone,x){
	document.getElementById(zone).innerHTML=tpst(x);
	x=x-1;
	if(x+2>0){
	    setTimeout("decompteur('"+zone+"',"+x+")",1000);
	}else{
	    document.getElementById(zone).innerHTML="<a href=\"?\">Terminé</a>"
	}
}
function pat(zone,formulaire){
	zone.disabled=true;
	zone.value='Chargement';
	formulaire.submit();
}
function esc(pEvent){
  if(pEvent.keyCode==27){
    pEvent.returnValue=false;
	//alert('Arret du chargement impossible!');
  }
}


var tab_img=new Array;
   tab_img[0]="<img src=\"img/cpt/0.png\" />";
   tab_img[1]="<img src=\"img/cpt/1.png\" />";
   tab_img[2]="<img src=\"img/cpt/2.png\" />";
   tab_img[3]="<img src=\"img/cpt/3.png\" />";
   tab_img[4]="<img src=\"img/cpt/4.png\" />";
   tab_img[5]="<img src=\"img/cpt/5.png\" />";
   tab_img[6]="<img src=\"img/cpt/6.png\" />";
   tab_img[7]="<img src=\"img/cpt/7.png\" />";
   tab_img[8]="<img src=\"img/cpt/8.png\" />";
   tab_img[9]="<img src=\"img/cpt/9.png\" />";
function modulo(nb){
	var rst=nb%10;
	var dix=Math.floor(nb/10);
	return tab_img[dix]+tab_img[rst];
}
function conv_tps_img(s){
    m=0;h=0;jrs=0;
	sss=s;
	if(s<0){
        document.location.reload();
    }else{
        if(s>59){m=Math.floor(s/60);s=s-m*60}
        if(m>59){h=Math.floor(m/60);m=m-h*60}
		if(h>23){jrs=Math.floor(h/24);h=h-jrs*24}			
		
		if(jrs==0){tjrs="";}else{tjrs=modulo(jrs);if(jrs!="")tjrs=tjrs+"<img src=\"img/cpt/p.png\" /> ";}
		if(h==0){th="";}else{th=modulo(h);if(h!="")th=th+"<img src=\"img/cpt/p.png\" /> ";}
		if(m==0){tm="";}else{tm=modulo(m);if(m!="")tm=tm+"<img src=\"img/cpt/p.png\" /> ";}
		return tjrs+th+tm+modulo(s);
     }
}
function layer_insc(){
	layer_insc_sec--;
	document.getElementById('layer_insc').innerHTML=conv_tps_img(layer_insc_sec)+"&nbsp;&nbsp;";
    setTimeout("layer_insc()",1000);				
}
function display_slide(champ,direct){
	var etat_slide=document.getElementById(champ+'_etat').value;
	if(etat_slide==0){
		Effect.SlideDown(champ);
		if(direct==1)Effect.Pulsate(champ);
		document.getElementById(champ+'_etat').value=1;
	}else{
		Effect.SlideUp(champ);
		document.getElementById(champ+'_etat').value=0;
	}
}
// damier
function bulle_aff(id){
	document.getElementById('dpop_'+id).style.display = "block";
	document.getElementById('dpop_'+id).style.position = "absolute";
}
function bulle_not_aff(id){
	document.getElementById('dpop_'+id).style.display = "none";
}
// menu theme
function clear_menu(){
	for(i=1;i<=nb_title;i++){
		disp_menu[i]=0;
	}
	for(i=1;i<=nb_title;i++){
		document.getElementById('menu_'+i).style.display = "none";
	}
}
function disp_menu(id){
	clear_menu();
	disp_menu[id]=1;
	for(i=1;i<=nb_title;i++){
		if(disp_menu[i]==1){
			document.getElementById('menu_'+id).style.display = "block";
		}
	}
}
