var XHTMLNS = 'http://www.w3.org/1999/xhtml';

var initialY = 0;
var lastlink = '';
var block_scroll = 0;
var initialheight = 0;
var first_start = 0;
var type = 0;
var header_hauteur = 0; // la hauteur du header ( pas de scroll avant cette taille la ) // la hauteur par defaut est de 128, pou



function myStartScript(){
	//--- ON MET LA TAILLE DE POLICE CONVENU PAR L'UTILSATEUR
	
	getFontSize = parseInt(getCookie('font-size'));
	if(getFontSize >= min_fontSize && getFontSize <= max_fontSize){
	set_font_size(getFontSize) ;
	} 
	//------------------------------------------------------------------------------

	// ON RAJOUTE DANS LES BALISES TITLE DES LIENS LE RACCOURCI CLAVIER D'ACCES RAPIDE
	accessKey_inTitle();

   
	affichage_swf(); // tricks pour IE qui affiche des cadres au tour des flash et autres objects 
	externalLinks();
	//~ title_img_parse();
	mt_ajax_form_parse('html_body');
	
	//~ manu_addEvent(document, "click", hide_helpbox);	
	
	//~ if(window.ActiveXObject){  document.recalc() } ;
	//~ view_file_thumbnail();
}

function mt_ajax_form_parse(in_div){ // 
	// fonction qui va parcourir tous les formulaires et qui va transformé les formulaires mt_ajax comme il faut 
	if(in_div == 'html_body'  ){
		form_elements = $$('form.ajaxed');
		//~ alert('tck1');
	}else{
		form_elements = $$('#'+in_div+' form.ajaxed');
		//~ alert('tck2');
	}
	
	//~ option = {} ;
	//~ option['submitter'] == 'submitted';
	
	for( var i = 0;i<form_elements.length; i++){
		cElement = form_elements[i] ;
		cElement.innerHTML = '<input name="submitter" value="1" type="hidden" />'+cElement.innerHTML;
		//~ alert(cElement.id);
		cElementDestination = cElement.getAttribute("rel");
		
		cElement.addEvent('submit', function(e) {
			new Event(e).stop();
			//~ var destDiv = $(cElementDestination).empty().addClass('ajax-loading');
			show_chargement('Mise à jour ...',cElementDestination);
			this.send({
				//~ data:option,
				//~ encoding : 'iso-8859-1',
				update: cElementDestination,
				onComplete: function() {
					window.location = '#centre'
					window.hide_chargement(cElementDestination);					
					mt_ajax_form_parse(cElementDestination);
					if(window.ActiveXObject){  document.recalc() } ; // hack pour recalculer les effets css avec le hack IE7
				}
			});
			
		});
		
		
		//~ alert(cElement.getAttribute("rel"));
	}
}

function title_img_parse(){

	var wtag = new Array();
	wtag[0] = 'h1';
	wtag[1] = 'h2';
	wtag[2] = 'h3';
	
	for(var t = 0; t<wtag.length ; t++){
		title_elements = document.getElementsByTagName(wtag[t]);
		for( var i = 0;i<title_elements.length; i++){
			cElement = title_elements[i] ;
			//~ alert(cElement.style.color);
			

			classText = '|'+cElement.className+'|';
			//~ alert(classText.indexOf('title_img'));
			
			
			var expression =/title_img/i ;
			//~ alert(expression.exec(classText));
			
			//~ if(cElement.className == 'title_img' || cElement.className == 'title_img_orange'){				
			if(expression.exec(classText) != null){				
			//~ if(cElement){			
				defColor = getCssValue(cElement,'color');
				defWidth = parseInt(getCssValue(cElement,'width'));
				innerText = '';			
				for( var x = 0; x < cElement.childNodes.length; x++ ) {
					if( cElement.childNodes[x].className || cElement.childNodes[x].style) {					
						innerText += '<span style="color:' +getCssValue(cElement.childNodes[x],'color')+'" >'+ cElement.childNodes[x].innerHTML +'</span>';
					}else{
						innerText += cElement.childNodes[x].nodeValue;
					}
				}
				
				//~ alert(innerText);
				cElement.innerHTML = '<img src="./title_generator.php?width='+defWidth+'&size='+wtag[t]+'&color='+encodeURIComponent(defColor)+'&texte='+encodeURIComponent(innerText)+'" alt="'+striptags(innerText)+'"/>' ;
				//~ cElement.innerHTML = '<img src="./title_generator.php?texte='+innerText+'" alt="'+escape(innerText)+'"/>' ;
				//~ break;
			}
		}	
	}
}





function manu_addEvent(obj, evType, fn) { // ajoute un listener sur un élément
	if (obj.addEventListener)	{
		obj.addEventListener(evType, fn, false);
		return true;
	}else if (obj.attachEvent){
		var r = obj.attachEvent('on'+evType, fn);
		return r;
	}else{
		return false;
	}
}



//uniformisation des appels 
if (!document.createElementNS) {
	document.createElementNS = function(ns, elt) {
		return document.createElement(elt);
	}
}

function goURL(url){
   document.location.href = url;
}

function goURL_parent(url){
   window.opener.parent.document.location.href = url ;
   window.close();
}

function refresh_parent(wdiv,closing){   
   window.opener.parent.getRefresh(wdiv) ;
   if(closing == 1){
         window.close();
   }
}


var wtag = new Array();
wtag[0] = 'input';
wtag[1] = 'textarea';
wtag[2] = 'select';

function get_object_by_name(wname){

	for(var t = 0; t<wtag.length ; t++){

		var all_obj = document.getElementsByTagName(wtag[t]);
	   
		for( var i = 0;i<all_obj.length; i++){
			if(all_obj[i].name == wname){				
				return all_obj[i] ;
				break;
			}
		}	
	}
}

var last_shown = '';

function findPos(myobj) {
	if (myobj.offsetParent) {
	
		for (var posX = 0, posY = 0; myobj.offsetParent; myobj = myobj.offsetParent) {
			posX += myobj.offsetLeft;
			posY += myobj.offsetTop;
		}
		return [posX, posY];
		
	} else {
		return [myobj.x, myobj.y];
	}
}

function show_div(what_to_show){
   
     if(document.getElementById(what_to_show).style.display == 'none'){
         if(last_shown != '') {
            document.getElementById(last_shown).style.display = 'none' ;
         }
         document.getElementById(what_to_show).style.display = 'block' ;
         to_return = 1;
         last_shown = what_to_show;         
     } else {
         document.getElementById(what_to_show).style.display = 'none' ;
         to_return = 0;
     }
     first_start = 0;
     //return to_return;

}  

function pop_div(what_to_show){
     if(document.getElementById(what_to_show).style.display != 'block'){
         document.getElementById(what_to_show).style.display = 'block' ;
     }
}

function hide_div(what_to_show){
     if(document.getElementById(what_to_show).style.display != 'none'){
         document.getElementById(what_to_show).style.display = 'none' ;
     }
}


 function replaceAll(str, search, repl) {
    while (str.indexOf(search) != -1)
    str = str.replace(search, repl);
    return str;
}


function jumpMenu(target_baseurl,selObj){ //jump menu, based on dreamweaver concept
   if(selObj.options[selObj.selectedIndex].value != ''){
      eval("location='"+target_baseurl+selObj.options[selObj.selectedIndex].value+"'");
  }
}

function findPosY(obj) { // recupere la position d'un lien , ou alors le décalage avec son parent 

	if (obj.offsetParent)
		{
		for (var posX = 0, posY = 0; obj.offsetParent; obj = obj.offsetParent)
			{
			posX += obj.offsetLeft;
			posY += obj.offsetTop;
			}
		return posY;
		}
	else
		{
		return obj.y;
		}
}



// Ouvre un popup avec des options, dont par defaut le redimmensionnement
function open_newwindow(urltoshow,options) {
      //window.open(urltoshow,'sitepopup','resizable=yes,menubar=yes,'+options);
      window.open(urltoshow,'sitepopup','resizable=yes,'+options);
}

// open_newwindow('wqsdfqsdfqsdfqsd','width=450,height=380')

function affichage_swf(){
   var all_divs = document.getElementsByTagName('div');
   
   for( var i = 0;i<all_divs.length; i++){
         if(all_divs[i].id.substring(all_divs[i].id.length - 4, all_divs[i].id.length) == '.swf' ){ // si le div ce termine par .swf 
               
               
               if( fs_width = parseInt(all_divs[i].width) ){               
               }else fs_width = parseInt(all_divs[i].style.width) ; 

               if( fs_height = parseInt(all_divs[i].height) ){               
               }else fs_height = parseInt(all_divs[i].style.height) ;
               
              
         
               fs_script = '<object type="application/x-shockwave-flash" data="'+ all_divs[i].id  +'" ';
               
               if(fs_width >= 1){
                  fs_script =  fs_script + 'width="'+fs_width+'" ' ;
               }else fs_script =  fs_script + 'width="auto" ' ;
               
               if(fs_height >= 1){
                  fs_script =  fs_script + 'height="'+ fs_height +'" ';
               }else fs_script =  fs_script + 'height="auto" ' ;
               
               fs_script =  fs_script +  '>\n<param name="movie" value="'+ all_divs[i].id +'" />\n<param name="wmode" value="transparent" />\n<p>&nbsp;</p></object>'; ;
               writeHTML(fs_script,all_divs[i].id);    
               
               //writeHTML(fs_width+'x'+fs_height,all_divs[i].id);      

               all_divs[i].id = all_divs[i].id + '_OK' ;
         }
   }

}

function accessKey_inTitle(){
   var all_a = document.getElementsByTagName('a');
   
   for( var i = 0;i<all_a.length; i++){
         if(all_a[i].accessKey){         
            all_a[i].title = all_a[i].title + ' | [' + all_a[i].accessKey+']';   
            // ---- ADD underline on accesskey in innerHTML
            //~ innertxt = all_a[i].innerHTML ;
            //~ innertxtLower = innertxt.toLowerCase() ;
            
            //~ accessKey_pos = innertxtLower.indexOf(all_a[i].accessKey,0) + 1 ;
            //~ if(accessKey_pos >= 2){
               //~ new_txt = innertxt.substr(0,accessKey_pos-1) 
            //~ }else new_txt = ''
            
            //~ new_txt = new_txt +  '<u>' + innertxt.substr(accessKey_pos-1,1)  + '</u>' + innertxt.substr(accessKey_pos,innertxt.length);
            //~ all_a[i].innerHTML = new_txt;
         }
   }

}

function count_down(div,countdown){

      destination = div;
      CD = countdown - 1;
      
      if(countdown >= 1){
         writeHTML('('+(countdown - 1)+')',div+'_CD');
         if(countdown == 1){
            setTimeout("count_down(destination,(CD));",150);
         }else{
            setTimeout("count_down(destination,(CD));",1000);
         }
      }else{ // si on est a zero il faut effectuer la redirection vers la page du lien
         url = document.getElementById(div).href ;
         window.location = url;
      }
      
}

var hpBox ;
var current_hpDiv = null ;
var hpBoxHeight = 16;
var hpBoxWidth = 16;

function  show_help_point(what_id,hpPos){
   //~ position for help_point on the div
   //~ 012
   //~ 345
   //~ 678
   
   hpDiv = document.getElementById(what_id);
   
   if(hpDiv){
	   //~ if(current_hpDiv == what_id) return ;
	   //~ hide_help_point();

	   if(!document.getElementsByTagName) return;
	   
		//~ alert('what_id');
	   
	   hpDivPos = findPos(hpDiv); // on recuper la position de l'element dans l'espace page
	   wX = hpDivPos[0];
	   wY = hpDivPos[1];   
	   wH = hpDiv.offsetHeight;
	   wW = hpDiv.offsetWidth;
	   
	   if( hpPos == 0 || hpPos == 3 || hpPos == 6 ){ // suivant le nombre qui est demandé on regle la largeur
	      hpX = wX + 5 - (hpBoxWidth / 2 );
	   }else if( hpPos == 2 || hpPos == 5 || hpPos == 8 ){
	      hpX = wX + wW - 5 + (hpBoxWidth / 2 ) ;
	   }else { // par defaut il est centré 
	      hpX = wX + ( wW  / 2 ) - (hpBoxWidth / 2 ) ;
	   }

	   if( hpPos == 6 || hpPos == 7 || hpPos == 8 ){ // idem hauteur
	      hpY = wY + wH - 5 + (hpBoxHeight / 2 );
	   }else if( hpPos == 0 || hpPos == 1 || hpPos == 2 ){
	      hpY = wY + 5 - (hpBoxHeight / 2 );
	   }else { // par defaut il est centré
	      hpY = wY + ( wH  / 2 ) - (hpBoxHeight / 2 );
	   }
	
	if(!hpBox){
	   hpBox = document.createElementNS(XHTMLNS, 'div'); // on 	créé un nouvel élément
	   hpBox.id = "HelpPoint" ; // on lui donne l'id HP 
	   hpBox.className = 'petit';

	   //vbox.style.width = (bbcodebox_width+20) + 'px';
	   //vbox.style.height = bbcodebox_height + 'px';
	   
	}
	   hpBox.style.position = 'absolute' ; // on deplace notre tooltip vers la droite de xx px 
	   hpBox.style.left = (hpX) + 'px' ; // on deplace notre tooltip vers la droite de xx px 
	   hpBox.style.top = (hpY) + 'px' ; // on deplace vers le bas de xxpx

		document.getElementsByTagName('body')[0].appendChild(hpBox); // on accroche notre élément au body
	   
	   //~ current_hp = hpBox;	 // on défini notre  HP courant
	
	   //---------------------------------------------------------------------------------------
	   // REMPLISSAGE DES BOX
	   //---------------------------------------------------------------------------------------

	   if(hpBox){ // on a bien une help box 
	      hpBox.innerHTML = '<img src="./img/Pointer_help_point.gif?'+Math.random()+'" />';
	      setTimeout("hide_help_point();",1000);
	   }  
	}
}

function hide_help_point(){	
	if (!document.getElementsByTagName) return;

	if (hpBox) {
		document.getElementsByTagName('body')[0].removeChild(hpBox);
		//~ hpBox = null;
	}
	return;
}

var max_fontSize = '12';
var min_fontSize = '7';
var fontSize_unit = 'pt';
var fontSize_default = '9';

function set_font_size(action){

      actual_size = parseInt(getCssValue(document.getElementsByTagName('body')[0],'fontSize')) ;
      
      //writeHTML(actual_size,'sub_menu');      
      
      if( action && action == 'up'){         
         if(actual_size < max_fontSize){
            document.getElementsByTagName('body')[0].style.fontSize = (actual_size + 1) + fontSize_unit ;
         }         
      }else if(action && action == 'down'){
         if(actual_size > min_fontSize){
            document.getElementsByTagName('body')[0].style.fontSize = (actual_size - 1) + fontSize_unit ;
         }         
      }else if( !isNaN(action) ){
         document.getElementsByTagName('body')[0].style.fontSize = (action) + fontSize_unit ;
      }

      setCookie('font-size',document.getElementsByTagName('body')[0].style.fontSize);
      
}

function getCssValue(wobj,element) {

   var value = wobj.style[element] ;  
     
   if(value==null || value=='' || value=='undefined'){
      var aClass = wobj.className;
      //~ alert(aClass);
      //~ allAClass = (' ',aClass);
      
      //~ var expression =/\[url=([a-zA-Z0-9&\/\.:\%_\?=-]*)\]/i ;
    //~ expression.exec(txtarea);
    
     
      if(aClass==null || aClass=='' || aClass=='undefined'){
         aClass = wobj.tagName.toLowerCase();
      }
	//~ alert(aClass);
      //writeHTML(aClass,'sub_menu');   
      var cssRules = 'rules';
      for (var sSheet=0; sSheet < document.styleSheets.length; sSheet++){
      
      if (document.styleSheets[0].cssRules) my_rules=document.styleSheets[sSheet].cssRules ;
      else if (document.styleSheets[0].rules) my_rules=document.styleSheets[sSheet].rules ;

         
         for (var rule=0; rule <my_rules.length ; rule++) {
		//~ alert(rule);
            var currentClass = my_rules[rule].selectorText.toLowerCase() ;
	     //~ alert(currentClass);s
            //document.getElementById('sub_menu').innerHTML = document.getElementById('sub_menu').innerHTML + '<br />' +currentClass ;
	     //---------------------------------------------------------------------------------------------
	     //~ var expression = /currentClass/i ;
	     //~ if( expression.exec(aClass) != null){
			//~ alert(currentClass);
	     //~ }
	     
            if (currentClass == aClass || currentClass == '.'+aClass) {
                  //writeHTML('|' + aClass+'| - |' +currentClass+'| - |'+ document.styleSheets[sSheet].cssRules[rule].style[element] +'|' ,'sub_menu');   
               value = my_rules[rule].style[element] ;
            }
         }
      }
   }
    
   
   return  value;
}	

function setCookie(what, value) {
   var argv = setCookie.arguments ;
   var argc = setCookie.arguments.length ;
   var expires = (argc > 2) ? argv[2] : null ;
   var path = (argc > 3) ? argv[3] : null ;
   var domain = (argc > 4) ? argv[4] : null ;
   var secure = (argc > 5) ? argv[5] : false ;
   document.cookie = what+"="+escape(value)+
   ((expires==null) ? "" : ("; expires="+expires.toGMTString()))+
   ((path==null) ? "" : ("; path="+path))+
   ((domain==null) ? "" : ("; domain="+domain))+
   ((secure==true) ? "; secure" : "") ;
}

function getCookieVal(offset){
   var endstr=document.cookie.indexOf (";", offset);
   if (endstr==-1) endstr=document.cookie.length;
   return unescape(document.cookie.substring(offset, endstr));
}

function getCookie(what) {
   var arg = what+"=" ;
   var alen = arg.length ;
   var clen = document.cookie.length ;
   var i=0;
   while (i<clen){
      var j=i+alen;
      if (document.cookie.substring(i, j)==arg) return getCookieVal(j);
      i=document.cookie.indexOf(" ",i)+1;
      if (i==0) break;
   }
   return null;
}





var current_my_div ;
var chargement_box_width = 150 ;


function show_chargement(optional_text,destination){
	
	hide_chargement(destination);
	
	output_div = document.getElementById(destination) ;
       
	if(!optional_text){
		optional_text = 'Chargement ...';
		
	}
	
	if(document.getElementsByTagName && output_div){
	
		my_cache_div = document.createElementNS(XHTMLNS, 'div'); // on 	
		my_div = document.createElementNS(XHTMLNS, 'div'); // on 	
		my_div.id = "AJAX_load_box_"+destination;
			
		divpos = findPos(output_div); // on recuper la position du text area dans l'espace page
		dx = divpos[0];
		dy = divpos[1];		

		//my_div.style.width = (bbcodebox_width-6) + 'px';
		//my_div.style.height = bbcodebox_height + 'px';
		
		div_width = parseInt(output_div.offsetWidth)
		div_height = parseInt(output_div.offsetHeight)
		
		my_cache_div.id = "AJAX_cache_box_"+destination;
		my_cache_div.style.cssText = 'background-color:#FFF;opacity:0.75;' ;
		if(window.ActiveXObject){ my_cache_div.style.cssText = 'background-color:#FFF;filter: alpha(opacity=75);' }
		
		my_cache_div.style.position = 'absolute' ;
		//my_cache_div.style.cssText = 'opacity:0.75;'
		
		my_cache_div.style.left = dx + 'px'; // on deplace notre tooltip vers la droite de xx px 
		my_cache_div.style.top = dy + 'px';
		my_cache_div.style.width = div_width + 'px';
		my_cache_div.style.height = div_height + 'px';
		
		my_div.style.cssText = 'font-size:9px;' ;
		my_div.style.position = 'absolute' ;
		my_div.style.padding = '8px' ;
		my_div.style.textalign = 'center' ;
		my_div.style.border = '1px solid #999' ;
		my_div.style.backgroundColor = '#000' ;
		my_div.style.color = '#CCC' ;
		
		my_div.style.left = parseInt( dx + (div_width - chargement_box_width) / 2)  + 'px'; // on deplace notre tooltip vers la droite de xx px 
		my_div.style.top = ( dy + 25) + 'px'; // on deplace vers le bas de xxpx
		
		document.getElementsByTagName('body')[0].appendChild(my_cache_div); // on definit notre balise d comme sous element de body  (affiche le tooltip en gros :) )
		document.getElementsByTagName('body')[0].appendChild(my_div); // on definit notre balise d comme sous element de body  (affiche le tooltip en gros :) 
              
		//~ writeHTML('<table cellpadding="0px" cellspacing="1px" ><tr><td valign="center">'+ optional_text + '&nbsp;</td><td valign="center"></td></tr></table>',my_div.id);
		writeHTML('<table cellpadding="0px" cellspacing="1px" ><tr><td valign="center"><img src="./css/img/ajax-loader.gif" alt="" /></td><td valign="center">'+ optional_text + '&nbsp;</td></tr></table>',my_div.id);
		//writeHTML(dx + ' ' + dy ,my_div.id);
		//~ current_my_div = my_div;
		//~ current_my_cache_div = my_cache_div;
	}else return;	
}

function hide_chargement(destination){
	if(document.getElementsByTagName){
		
		if (document.getElementById("AJAX_load_box_"+destination) && document.getElementById("AJAX_cache_box_"+destination) ) {
		//~ alert('blop');	
			box_div = document.getElementById("AJAX_load_box_"+destination);
			cache_div = document.getElementById("AJAX_cache_box_"+destination);
			
			document.getElementsByTagName('body')[0].removeChild(box_div);
			document.getElementsByTagName('body')[0].removeChild(cache_div);
			
		}
	}
}


var current_helpbox = null ;
var current_helpinput = null ;


function show_helpbox(winput , wtxt){
	
	hide_helpbox();
			
	if(!document.getElementsByTagName) return; // on verifie qu'on peut recup les elements par tag, permet de savoir si en gros on a besoin d'exec cette fonction, puisk sans ca rien ne marche

	
	//---------------------------------------------------------------------------------------
	// HELP BOX
	//---------------------------------------------------------------------------------------
	txtpos = findPos(winput); // on recuper la position du text area dans l'espace page
	//divpos = findPos(document.getElementById('requested')); // on recuper la position du text area dans l'espace page
	tx = txtpos[0];
	ty = txtpos[1];
	
	inputHeight = winput.offsetHeight ;	
	inputWidth = winput.offsetWidth ;	
	
	var vbox = document.createElement('div'); // on
	vbox.id = "help_input_box";
	vbox.className = 'apercu_box petit classic_ul ';
	
	//vbox.style.width = (bbcodebox_width+20) + 'px';
	//vbox.style.height = bbcodebox_height + 'px';

	vbox.style.left = (tx) + 'px'; // on deplace notre tooltip vers la droite de xx px 
	vbox.style.top = (ty+inputHeight) + 'px'; // on deplace vers le bas de xxpx

	
	if(winput.type == 'select' || winput.type == 'select-one' ||winput.type == 'select-multiple' || winput.type == 'textarea'){
		vbox.style.top = (ty) + 'px'; // on deplace vers le bas de xxpx
		vbox.style.left = (tx + inputWidth) + 'px';		
	}
	vbox.style.width = '400px';
	

	document.getElementsByTagName('body')[0].appendChild(vbox); // on definit notre balise d comme sous element de body  (affiche le tooltip en gros :) )
	current_helpbox = vbox;	
	//---------------------------------------------------------------------------------------	

	//---------------------------------------------------------------------------------------
	// REMPLISSAGE DES BOX
	//---------------------------------------------------------------------------------------

	if(current_helpbox){ // on a bien une help box 
		
		if(isNaN(wtxt) && wtxt.substring(0,5) == 'HELP:' ){  // du text qui commence par HELP: alors il faut aller chercher la page php qui echo de l'aide 
			spe_url = './index.php?supertitle=help_api&whelp=' + wtxt.substring(5,wtxt.length) ;
			//writeHTML('<img src="./img/connect_box.gif" alt="" style="" class="float_left" />',current_helpbox.id);		//writeHTML('&nbsp;&nbsp;Veuillez patienter...',defautdestination);	
			my_chb_id = current_helpbox.id ;
			getPage(spe_url,my_chb_id,0);
			//~ setTimeout("loadPage(spe_url,my_chb_id)",50);
		}else { // si c du texte 
			writeHTML(wtxt,current_helpbox.id);		//writeHTML('&nbsp;&nbsp;Veuillez patienter...',defautdestination);	
			//writeHTML(inputHeight,current_helpbox.id);		//writeHTML('&nbsp;&nbsp;Veuillez patienter...',defautdestination);	
			if(window.ActiveXObject){  document.recalc() } ; // hack pour recalculer les effets css avec le hack IE7
		}
	}

	//---------------------------------------------------------------------------------------
	
	current_helpinput = winput ;
	//~ alert(winput);
	if(current_helpinput){
		current_helpinput.focus();		
		//setTimeout("addEvent(current_helpinput, 'blur', hide_helpbox);",200); 
		//setTimeout("addEvent(current_helpbox, 'click', hide_helpbox);",400); 
		manu_addEvent(current_helpbox, 'blur', hide_helpbox);	
		manu_addEvent(current_helpbox, 'click', hide_helpbox);	
		manu_addEvent(current_helpinput, 'blur', hide_helpbox);	
	}	
	
}

function hide_helpbox(){	
	if (!document.getElementsByTagName) return;

	if (current_helpbox) {
		document.getElementsByTagName('body')[0].removeChild(current_helpbox);
		current_helpbox = null;
		current_helpinput = null;
	}
	return;
}




var langbox = null;
var langinput = null ;


function show_languagebox(ini_obj,referer_id){

	if(langbox) hide_languagebox(1);
			
	if(!document.getElementsByTagName) return; // on verifie qu'on peut recup les elements par tag, permet de savoir si en gros on a besoin d'exec cette fonction, puisk sans ca rien ne marche


	//---------------------------------------------------------------------------------------
	// HELP BOX
	//---------------------------------------------------------------------------------------
	txtpos = findPos(ini_obj); // on recuper la position du text area dans l'espace page
	//divpos = findPos(document.getElementById('requested')); // on recuper la position du text area dans l'espace page
	tx = txtpos[0];
	ty = txtpos[1];
	
       //document.getElementById('sub_menu').innerHTML = tx+'x'+ty;
	
	var vbox = document.createElement('div'); // on
	vbox.id = "language_select_box";
	vbox.className = 'language_box petit classic_ul';
	
	//vbox.style.width = (bbcodebox_width+20) + 'px';
	//vbox.style.height = bbcodebox_height + 'px';

	vbox.style.left = (tx-140) + 'px'; // on deplace notre tooltip vers la droite de xx px 
	vbox.style.top = (ty + 24) + 'px'; // on deplace vers le bas de xxpx

	vbox.style.width = '220px';
	

	document.getElementsByTagName('body')[0].appendChild(vbox); // on definit notre balise d comme sous element de body  (affiche le tooltip en gros :) )
	if(document.getElementById('focus_util').innerHTML == ''){
		document.getElementById('focus_util').innerHTML = '<a href="javascript: ;" id="focus_util_textarea" ></a>';
	}
	langbox = vbox;	
	langbox_for_focus = document.getElementById('focus_util_textarea');	
	
	//var langbox = langboxS[last_id];
	
	
	//---------------------------------------------------------------------------------------	

	//---------------------------------------------------------------------------------------
	// REMPLISSAGE DES BOX
	//---------------------------------------------------------------------------------------

	if(langbox){ // on a bien une help box 		
			spe_url = './index.php?supertitle=langue_selection&referer_id='+referer_id ;
			//writeHTML('<img src="./img/connect_box.gif" alt="" style="" class="float_left" />',current_helpbox.id);		//writeHTML('&nbsp;&nbsp;Veuillez patienter...',defautdestination);	
			my_chb_id = langbox.id ;
			setTimeout("loadPage(spe_url,my_chb_id)",50);
	}

	//---------------------------------------------------------------------------------------
	
	langinput = ini_obj;
	if(langinput){
		langbox_for_focus.focus();		
		//setTimeout("manu_addEvent(current_helpinput, 'blur', hide_helpbox);",200); 
              body_obj = document.getElementsByTagName('body')[0];
		//setTimeout("addEvent(body_obj, 'click', hide_languagebox)",100); 
		manu_addEvent(langbox_for_focus, 'blur', hide_languagebox);	
		//addEvent(document.getElementsByTagName('body')[0], 'click', hide_languagebox);	
	}	
}

function hide_languagebox(immediate){	
	if (!document.getElementsByTagName) return;

	if (langbox) {
		if(immediate == 1){
			document.getElementsByTagName('body')[0].removeChild(langbox);
			langbox = null;
			langinput = null;
		}else {
			setTimeout("document.getElementsByTagName('body')[0].removeChild(langbox);langbox = null;langinput = null;",400);			
		}
	}
	return;
}

function change_language(newlang_id,referer_id){
	document.location.href = './index.php?lang='+newlang_id+'&pageid='+referer_id;
}

function striptags(txt){
	return noHtml(txt);
}

 function noHtml(txt) {
    a = txt.indexOf('<');
    b = txt.indexOf('>');
    len = txt.length;
    c = txt.substring(0, a);
    if(b == -1) {
       b = a;
    }
    d = txt.substring((b + 1), len);
    txt = c + d;
    cont = txt.indexOf('<');
    if (cont != -1) {
      txt = noHtml(txt);
    }
    return txt;
 }

// Fonction sur les caractères restants pour un champs SPAW
function carac_restant(input_name,max_char,message,delete_extra_char){

	var iframe_elems = document.getElementsByTagName('iframe');
	
	for(i =0;i<iframe_elems.length ;i++){
		if(iframe_elems[i].name == input_name+'_rEdit' ){
			if(noHtml(iframe_elems[i].contentDocument.body.innerHTML).length > max_char){
				document.getElementById(input_name+'_retour_infos').innerHTML = message;
				if(delete_extra_char == 1){
					document.getElementById(input_name+'_retour_infos').innerHTML += ' | <span style="color:#F00" class="gras">'+ (max_char - noHtml(iframe_elems[i].contentDocument.body.innerHTML).length) +'</span>';
					//~ a =  iframe_elems[i].contentDocument.body.innerHTML.substring(0,max_char)  ;
					//~ b = iframe_elems[i].contentDocument.body.innerHTML.substring(max_char, iframe_elems[i].contentDocument.body.innerHTML.length) ;
					//~ iframe_elems[i].contentDocument.body.innerHTML = a ;
					//~ if(iframe_elems[i].contentDocument.body.setSelectionRange){
						//~ iframe_elems[i].setSelectionRange(max_char, max_char); // on redéfinis la selection
					//~ }else alert('blop');
					//~ //iframe_elems[i].contentDocument.body.innerHTML = iframe_elems[i].contentDocument.body.innerHTML.substring(0,max_char) + "<span style=\"color:#F00\">"+b+"</span>" ;						
				}
			}else{
				document.getElementById(input_name+'_retour_infos').innerHTML = '';
			}
		}
		//document.getElementById('retour_infos').innerHTML = noHtml(iframe_elems[i].contentDocument.body.innerHTML);
	}
	
	setTimeout("carac_restant('"+input_name+"',"+max_char+",'"+message+"',"+delete_extra_char+")",600);
	return;
}

function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") &&
		anchor.getAttribute("rel") == "external")
		anchor.target = "_blank";
	}	
}



function catch_right_click(event,what_to_show,posToClick,e){
	//~ alert(what_to_show);
	//~ show_div(what_to_show);
	if (window.event && window.event.srcElement){
              lnk = window.event.srcElement
       }else if (e){
              lnk = e
       }
	//~ alert(lnk);
	show_window(what_to_show,posToClick,lnk,1);
	//~ setTimeout('show_window("'+what_to_show+'","'+posToClick+'","'+lnk+'")',50);

	
	event.cancelBubble = true;
       event.returnValue = false;
        //~ this.action("contextmenu"); 
	 	//~ alert(what_to_show);
	return false;
}

//-------------------------------------------------
// Fonction spécifique a l'accueil toolkit
//-------------------------------------------------
var last_arbo_shown = '';
var last_etat_arbo = 'none';

function show_all_arbo(div_prefix){

       if(last_etat_arbo == 'none'){
              last_etat_arbo = 'block';
       }else{
              last_etat_arbo = 'none';
       }
       
       var AllDiv=document.getElementsByTagName('*')
       

      
      for (i=0;i<AllDiv.length;i++){
         if (AllDiv[i].id.substr(0,div_prefix.length) == div_prefix){
         
            document.getElementById(AllDiv[i].id).style.display = last_etat_arbo ;
         }
      }
       
       
       
   //~ for(var ti=1 ; ti < 100 ; ti++){
      //~ div_name = div_prefix + '_' + ti ;
      //~ if(document.getElementById(div_name)){
            //~ document.getElementById(div_name).style.display = last_etat_arbo ;
         //~ }
      //~ }
   
}

function show_arbo_div(what_to_show){
   
     if(document.getElementById(what_to_show).style.display == 'none'){
         if(last_arbo_shown != '') {
            document.getElementById(last_arbo_shown).style.display = 'none' ;
         }
         document.getElementById(what_to_show).style.display = 'block' ;
         to_return = 1;
         last_arbo_shown = what_to_show;         
     } else {
         document.getElementById(what_to_show).style.display = 'none' ;
         to_return = 0;
     }
     //return to_return;
}      
//-------------------------------------------------


var last_subdiv_shown = '';


function show_subdiv(subdiv_to_show){
   
     if(document.getElementById(subdiv_to_show).style.display == 'none'){
         if(last_subdiv_shown != '') {
            document.getElementById(last_subdiv_shown).style.display = 'none' ;
         }
         document.getElementById(subdiv_to_show).style.display = 'block' ;
         to_return = 1;
         last_subdiv_shown = subdiv_to_show;         
     } else {
         document.getElementById(subdiv_to_show).style.display = 'none' ;
         to_return = 0;
     }
          first_start = 0;
          return to_return;
} 

//~ document.oncontextmenu=new Function("return false")


function getRefresh(destination){
	div = destination ;
	
	if(viewed_pages[currentPage]){
		currentlink = viewed_pages[currentPage];
		
		//writeHTML(currentlink,"footer");
		
		if(currentlink != ''){
			//writeHTML('<img src="./img/connect_dot.gif" alt="" style="position:relative;top:-3px;float:right;" />Rafraîchissement ...<br /><br />',div);	
			show_chargement('',destination);
			setTimeout("loadPage(currentlink,div);",200); 			
		}
		
		update_ajax_buttons();
	}
	
}

function js_print_r(arr,level) {
var dumped_text = "";
if(!level) level = 0;

//The padding given at the beginning of the line.
var level_padding = "";
for(var j=0;j<level+1;j++) level_padding += "    ";

if(typeof(arr) == 'object') { //Array/Hashes/Objects
 for(var item in arr) {
  var value = arr[item];
 
  if(typeof(value) == 'object') { //If it is an array,
   dumped_text += level_padding + "'" + item + "' ...\n";
   dumped_text += js_print_r(value,level+1);
  } else {
   dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
  }
 }
} else { //Stings/Chars/Numbers etc.
 dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
}
return dumped_text;
} 

manu_addEvent(window, "load", myStartScript);


function stripslashes(str){
	return str.replace(/\\("|'|\\)/g, "$1");
}

function addslashes(str){
	return str.replace(/("|'|\\)/g, "\\$1");
}

var wait_counter = 0;

function wait_confirm(wuser_mail){
	url = './index.php?pageid=36';
	
	wuser_etat = getPageContent(url,encodeURI('wuser='+encodeURIComponent(wuser_mail)));
	
	if(parseInt(wuser_etat) == 1){
		//document.getElementById('attente_etat').style.display = 'none';
		writeHTML('<span style="font-size:11px" class="cl_var_1"><b>Confirmation reçue !</b></span><br />Votre inscription est terminée !','attente_etat');
		writeHTML('<p class="center gras gros"><a href="./index.php?pageid=3" >Accédez à la page de connexion</a></p>','requested');
		if(window.ActiveXObject){  document.recalc() } ; 
	}else{
		setTimeout("wait_confirm('"+wuser_mail+"')",1500); 
		//writeHTML('Not  ' + wuser_mail + ' ' +wait_counter +' |' + wuser_etat + '| ','requested');
		//wait_counter = wait_counter + 1 ;
	}

}


function show_marge_div(divNumber){

   for( i = 0; i < 6 ; i++){
      if(i == divNumber){
         if(document.getElementById('marge'+i+'img')){
            document.getElementById('marge'+i+'img').src = './img/marges/Marge'+i+'_hover.jpg';
         }
         if(document.getElementById('marge'+i+'_box')){
            document.getElementById('marge'+i+'_box').style.display = 'block'  
         }
      }else{
         if(document.getElementById('marge'+i+'img')){
            document.getElementById('marge'+i+'img').src = './img/marges/Marge'+i+'.jpg';
         }
         if(document.getElementById('marge'+i+'_box')){
            if(document.getElementById('marge'+i+'_box').style.display == 'block'  ){
               document.getElementById('marge'+i+'_box').style.display = 'none'
            }
         }
      }
      
      
   }
   

}
