   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 chbgcolor(ligne,color){
       if(color.substring(0,1) == '#'){
             // ligne.className= "vert";      
              ligne.style.backgroundColor = color;
      }
      else {
              ligne.className= "vert " + color;      
              //ligne.style.backgroundColor = "";
      }
}


function goURL(url)
{
   document.location.href = url;
}

var last_shown = '';

var speed_timer = 0;

function jquery_show_div(what_to_show,action){
         //~ speed_timer = 1;
         
         //~ $('.menu_deroulant').hide();
         
         if(action == 'show'){
            $('#'+what_to_show).fadeIn('slow');         
         }else{
            $('#'+what_to_show).fadeOut('fast');
         }
         //~ $('#'+what_to_show).slideDown('normal');



         //~ last_shown = what_to_show;    
         //~ setTimeout('speed_timer=0',300);
}      

function jFadeInOut(idTo_Do){
   if(toShow = $('#'+idTo_Do)){
         if(toShow.attr('cFade') == 'Out'  ||toShow.css('display') == 'none'  ){
            toShow.attr('cFade','In');
            toShow.fadeIn('normal');
         }else{
            toShow.attr('cFade','Out');
            toShow.fadeOut('normal');
         }
   }
}

function jSlideUpDown(idTo_Do){
   //alert('blop');
   if(toShow = $('#'+idTo_Do)){
         if(toShow.attr('cSlide') == 'Up' || toShow.css('display') == 'none' ){
            toShow.attr('cSlide','Down');
            toShow.slideDown('normal');
         }else{
            toShow.attr('cSlide','Up');
            toShow.slideUp('normal');
         }
   }
}

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' ;
         last_shown = what_to_show;         
     } else {
         document.getElementById(what_to_show).style.display = 'none' ;
     }
     first_start = 0;
}      

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(subdiv_to_show).style.display = 'none' 
         }
         //~ document.getElementById(subdiv_to_show).style.display = 'block' ;
         $('#'+subdiv_to_show).slideDown('normal');
         last_subdiv_shown = subdiv_to_show;         
     } else {
     $('#'+subdiv_to_show).slideUp('normal');
         //~ document.getElementById(subdiv_to_show).style.display = 'none' ;
     }
          first_start = 0;
}      


 function replaceAll(str, search, repl) {
    while (str.indexOf(search) != -1)
    str = str.replace(search, repl);
    return str;
}

function carac_restant(obj,max_value) {
   if( obj.value.length <= max_value ) {
         caractere_restant = "Caractères restants : " + (max_value - obj.value.length) ;
   } else {
      obj.value = obj.value.substring(0,91);
      caractere_restant ="Message Trop long !";
   }
   
    document.getElementById('infos_carrac').innerHTML = caractere_restant ;
}

function scroller_gauche() {      // fonction qui permet que la menu de gauche soit tjs présent à l'écran et défile vers le bas
      
      if( first_start == 0){ // au premier demarrage
            initialY = findPosY(lastlink); // on recupere la position du dernier lien de la page pour avoir la hauteur environ
            finalY = initialY; // 
            first_start =1;
      }

      
      if( typeof( window.pageYOffset ) == 'number' ) { //Netscape compliant
          myscrollY = window.pageYOffset;
     } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {          //DOM compliant
          myscrollY = document.body.scrollTop;
     } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {          //IE6 standards compliant mode
          myscrollY = document.documentElement.scrollTop;
     } else {
         myscrollY = '0'; // si rien de tout ca alors on desactive
     }
     
 scroller_height = parseInt(document.getElementById('scroller_gauche').style.height); // on recupere le (-)XXX correspondant a la hauteur du calq     
    
   if(myscrollY && myscrollY > header_hauteur) { // si on est au dela du header il faut repositionner
   
      // lastlink = document.getElementById('last_link_on_page');
      
      document.getElementById('scroller_gauche').style.display = 'block' ;
      
      delta = (myscrollY - header_hauteur ) - (scroller_height); // delta entre la pos du calque et celle a avoir
      
      initialheight = document.getElementById('scroller_gauche').style.height;
      
      if( delta >= 2 && block_scroll == 0 && (initialY - finalY) == 0) {
         document.getElementById('scroller_gauche').style.height = scroller_height + ((delta/5)+2) +"px"; 
         type = 1;
      } else if (delta <= -2) {
         document.getElementById('scroller_gauche').style.height = scroller_height + ((delta/5)-2) +"px";
         block_scroll = 0;
         type = -1;
      } else if(block_scroll == 0){
         document.getElementById('scroller_gauche').style.height = (myscrollY - header_hauteur) + "px";
         type = 0;
      }
      
         finalY = findPosY(lastlink);

      
      if((initialY - finalY) != 0 && block_scroll == 0) {
         //block_scroll = 1;
         block_scroll = 0;
         //document.getElementById('scroller_gauche').style.height = initialheight;         
         document.getElementById('scroller_gauche').style.height = "0px";         
         initialY = findPosY(lastlink);
      }
      
      //document.getElementById('js_infos').innerHTML = initialY - finalY; //debug
      
   } else { // si la hauteur du scroll est inférieur au header on repositionne en zero
      delta = 0;
      block_scroll = 0;
      document.getElementById('scroller_gauche').style.height = "0px";
      document.getElementById('scroller_gauche').style.display = 'none' ;
      initialY = findPosY(lastlink);
      initialheight = 0;
   }
   //document.getElementById('js_infos').innerHTML = initialY + " :: " + finalY + " :: " +  (initialY-finalY) + " :: " + block_scroll + ' :: ' + first_start + ' :: ' + type; //debug
   
   //document.getElementById('js_infos').innerHTML = scroller_height + " :: " + myscrollY + " :: " + delta; //debug
}

function declench_inter() {
   var timer_scroller = window.setInterval("scroller_gauche()",50);
}

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;
		}
}


// trouve le lien () avec comme id='lastlinkonpage'
// important pour savoir si le scroller fait bouG ce lien , si c'est le cas , il faut arreter de bouger le scroller 

function get_tag_obj(whattag,whatid){
   if (!document.links) {
         document.links = document.getElementsByTagName(whattag);
   }
   
    for (var ti=0; ti<document.links.length; ti++) {
        var lnk = document.links[ti];
        // * I added specific class names here..
        if (lnk.id == whatid) {
               return lnk;
               //document.getElementById('js_infos').innerHTML = 'Ca fonctionne' + initialY; // debug
        }               
   }
}

// Ouvre un popup avec des options, dont par defaut le redimmensionnement
function open_newwindow(urltoshow,options) {
      window.open(urltoshow,'sitepopup','resizable=yes,'+options);
      // window.open(page,"nom_popup","menubar=no, status=no, scrollbars=no, menubar=no, width=200, height=100");
}

// open_newwindow('wqsdfqsdfqsdfqsd','width=450,height=380')


function checked_box_show_div(destination){
   
     if(document.getElementById(destination).style.display == 'none'){
         document.getElementById(destination).style.display = 'block' ;
     } else {
         document.getElementById(destination).style.display = 'none' ;
     }
   
}


function check_box_by_prefix(form_id,box_prefix){

      if(document.getElementById(form_id)){
         myForm = document.getElementById(form_id) ;
      }else if( document.forms[form_id]) {
         myForm = document.forms[form_id] ;
      }else if( document.forms['the_form']) {
         myForm = document.forms['the_form'] ;
      }else return;

      for(t=0; t<myForm.elements.length;t++){
         myElement = myForm.elements[t];
         if(myElement.name && myElement.type == 'checkbox' ){
                  if(myElement.name.substr(0,box_prefix.length) == box_prefix){ // si on trouve bien le prefix
                        if(myElement.checked){
                              myElement.checked = null;
                        }else{
                              myElement.checked = "checked";
                        }
                  }
         }         
      }

}

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>'; ;
               document.getElementById(all_divs[i].id).innerHTML = fs_script ;    
               
               //writeHTML(fs_width+'x'+fs_height,all_divs[i].id);      

               all_divs[i].id = all_divs[i].id + '_OK' ;
         }
   }
}

 function  makeSelect_heure(select,heureD, heureF){
		var select1 =  $(select).val(); 
		var tabDebut = select1.split("h");
		
		if(select == "#heureDepart"){
			var debut = parseInt(tabDebut[0])+1;
			var select2 = "#heureFin";
			var fin = heureF;
			
		}else if( select == "#heureFin"){
			var fin = parseInt(tabDebut[0])-1;
			var debut = heureD;
			var select2 = "#heureDepart";
		}
		var minutes = tabDebut[1];
		//alert("heure debut:"+debut+" heure fin:"+fin);
		var html ="";
		while(debut<fin){
			if (minutes == "00"){
				html += "<option>"+debut+"h"+minutes+"</option>";
				minutes = "30";
			}else if (minutes == "30"){
				html += "<option>"+debut+"h"+minutes+"</option>";
				debut ++;
				minutes = "00";
			}
		}
		$(select2).html(html);
 }
	 
