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_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();
   }
}

function refresh_contratfile(wtarget,wfile,closing){   
   if(wtarget == 'parent'){ // s'il faut rafraichir dans la fenetre parente la piece jointe / fichier lier
      window.opener.parent.refresh_contratfile('return_file_path',wfile,0)
   }else if(document.getElementById(wtarget)){
         document.getElementById(wtarget).value = wfile ;
         if(document.getElementById(wtarget+"_disabled")){
            document.getElementById(wtarget+"_disabled").value = wfile ;
         }
   }else{
      alert('impossible de trouver la fenetre parente ');
   }
   
   if(closing == 1){
         window.close();
   }
}

function reset_contratfile(){
   get_object_by_name('file').value='';
   get_object_by_name('file_disabled').value='';
}

function goURL(url){
   document.location.href = url;
}

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 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;
}  
//-------------------------------------------------
// 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;
}      


 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);
}

// 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 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 current_hp ;
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(current_hpDiv == what_id) return ;
   hide_help_point();

   if(!document.getElementsByTagName) return;
   

   
   hpDivPos = findPos(hpDiv); // on recuper la position du text area dans l'espace page
   wX = hpDivPos[0];
   wY = hpDivPos[1];   
   wH = hpDiv.offsetHeight;
   wW = hpDiv.offsetWidth;
   
   if( hpPos == 0 || hpPos == 3 || hpPos == 6 ){
      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 ){
      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 );
   }

   var hpBox = document.createElementNS(XHTMLNS, 'div'); // on 	
   hpBox.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 definit notre balise d comme sous element de body  (affiche le tooltip en gros :) )
   current_hp = hpBox;	

   //---------------------------------------------------------------------------------------
   // REMPLISSAGE DES BOX
   //---------------------------------------------------------------------------------------

   if(current_hp){ // on a bien une help box 
      current_hp.innerHTML = '<img src="./img/fleche_help_point.gif" />';
      setTimeout("hide_help_point();",1000);
   }  

}

function hide_help_point(){	
	if (!document.getElementsByTagName) return;

	if (current_hp) {
		document.getElementsByTagName('body')[0].removeChild(current_hp);
		current_hp = null;
		current_hpDiv = null;
	}
	return;
}
