   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);
 }
 
function Test_log_Ce(mdp){
	var dataString = 'login='+ mdp;
	$("#resp_log").text('').removeClass().addClass('messagebox').fadeIn(1000);
	$.ajax({
	type: "POST", 
	url: "./index.php?supertitle=popBox_LoginCE", 
	data: dataString,
	success:function(data)
	{
	if(data=='passwordok') //Si log ok
    {
	$("#resp_log").fadeTo(200,0.1,function(){  //fading du loader
	$(this).html('Accès autorisé').removeClass().addClass('messageboxok').fadeTo(900,1,
         function(){//Redirection
         document.location='./index.php';
         });
	});
	}
     else
     {$("#resp_log").fadeTo(200,0.1,function() //start fading the messagebox
      {//add message and change the class of the box and start fading
       $(this).html('Accès refusé. <br /><br />Rapprochez vous de votre CE pour obtenir votre clé.').removeClass().addClass('messageboxerror').fadeTo(900,1);
      }
    );}
	}
});
	return false;
}
 
 
 //Affichage du select sous categorie sur le onChange du 1er select
 function selectSousCat(catid){ 
	 var dataString = 'supertitle=ajax_recherche&souscat='+ catid
		$.ajax({
			type: "GET", url: "index.php", data: dataString, dataType: 'html',
			success: function(data){
			$('#recherche_sous_cat').html(data);
			$('#mots_recherche').css({width:"350px"});
			}
		});
	}	 

 //Maj de la recherche après mouvement sur le slider prix
 function searchAjaxPag(numpage,prixfrom,prixto,id_marque){
		var dataString = "supertitle=ajax_recherche&prixfrom="+prixfrom+"&prixto="+prixto+"&num_page="+numpage+"&orderbymarque="+id_marque 
		$.ajax({
		type: "GET", url: "index.php", data: dataString, dataType: "html",
		success: function(data){
		$("#search_product").html(data);
		}
			});
		}
 
 //Maj de la recherche sur le onChange du select marque
 function selectMarque(markId){
		var dataString = "supertitle=ajax_recherche&orderbymarque="+markId
		$.ajax({
		type: "GET", url: "index.php", data: dataString, dataType: "html",
		success: function(data){
		$("#search_product").html(data);
		}
			});
		}
 
 
 function check_acessoires(id_accessoire,id_produit,etat)
 {
	 
	 var dataString = "pageid=17&cart_action=add_accessoires&type=ajax&produit="+id_accessoire+"&produit_lie="+id_produit+"&etat="+etat;
		$.ajax({
		type: "GET", url: "index.php", data: dataString, dataType: "html",
		success: function(data){
			if(etat==1){
				
			document.getElementById('check_acc_'+id_accessoire).innerHTML = "<a href='javascript:check_acessoires("+id_accessoire+","+id_produit+",0)'><img src='./css/img/produit_panier_min.jpg' /></a>";
			}else{
				
				document.getElementById('check_acc_'+id_accessoire).innerHTML = "<a href='javascript:check_acessoires("+id_accessoire+","+id_produit+",1)'><img src='./img/small_add_panier.jpg' alt='' title='Ajouter au panier' /></a>";	
			}
		}
			});
		}
 
 function check_acessoires_popup(id_accessoire,id_produit,etat)
 {
	 
	 var dataString = "pageid=17&cart_action=add_accessoires&type=ajax&produit="+id_accessoire+"&produit_lie="+id_produit+"&etat="+etat;
		$.ajax({
		type: "GET", url: "index.php", data: dataString, dataType: "html",
		success: function(data){
			if(etat==1){
				
			document.getElementById('check_'+id_accessoire).innerHTML = '<a href="javascript:check_acessoires_popup('+id_accessoire+','+id_produit+',0)"><img src="./css/img/produit_panier_min.jpg" /></a>';
			}else{
				
				document.getElementById('check_'+id_accessoire).innerHTML = '<a href="javascript:check_acessoires_popup('+id_accessoire+','+id_produit+',1)"><img src="./img/small_add_panier.jpg"  title="Ajouter au panier" /></a>';	
			}
		}
			});
		}
	 

 function verif_champ_login(champ,contenu){
	 
	 var saisie = document.getElementById(champ).value;
	 if(saisie == contenu)
	 {
		 document.getElementById(champ).value = "";
	 }
 }

//Permet de changer la qté du panier manuellement
 function input_qte_panier(id_prod)
{
 	document.getElementById('pence_qte_'+id_prod).style.display ='none';
 	document.getElementById('valid_upd_qte_'+id_prod).style.display ='inline';
 	document.getElementById('input_qte_'+id_prod).style.display ='inline';
 	document.getElementById('qte_'+id_prod).style.display ='none';
 	
}


//Permet de modifier les quantité du panier
function modifier_qte_panier(id_prod,locate)
{
	redirect = "./index.php?pageid=99";
	var qte = document.getElementById('input_qte_'+id_prod).value;
 	if(qte!='')
 	{
 	$.ajax({ type: "POST", 
 		url: "./includes/panier/panier_action.php", 
 		data: "action=1&id_prod=" + id_prod +"&qte=" + qte, 
 		success: function(msg){
 		location.href= redirect;
 			} 
 		});	
 	}
 	else
 	{
 	alert("Le prix doit être renseignée.");
 	}
}

//Permet de modifier les frais de port à la commande dans cas 3.1.2(cf CDC)
//type_fp=0 fp par défaut , type_fp=1 fp choisi par le client
function changefpX(fp,id_fourn,type_fp,tx_tva)
{
 	$.ajax({ type: "POST", 
 		url: "./includes/panier/panier_action.php", 
 		data: "action=2&fp=" + fp +"&id_fourn=" + id_fourn+"&type_fp=" + type_fp+"&tx_tva=" + tx_tva, 
 		success: function(msg){
 		location.href="./index.php?pageid=99";
 			} 
 		});	

}

function switch_bouton(id)
{
	$("#conteneur_"+id).width(335)
	$("#valid_"+id).html('<input type="submit" name="send_'+id+'" class="ajout_pj" value="" />');
}


//Suppresion pièce jointe actus
function detachepj(id)
{     
      $.ajax({ type: "POST",
            url: "./includes/actus/actus_actions.php", 
            data: "action=1&id="+id, 
            success: function(msg){
            	document.getElementById("lst_pj").innerHTML= msg;
            } 
      });   
}

//Suppresion image actus
function detacheimage(id)
{     
      $.ajax({ type: "POST",
            url: "./includes/actus/actus_actions.php", 
            data: "action=2&id="+id, 
            success: function(msg){
            	document.getElementById("lst_images").innerHTML= msg;
            } 
      });   
}

//Download une pj dans le select
function download_pj(name_pj){
	if(name_pj !=''){
		window.open(name_pj);
	}
}


function compter(target, max, nomchamp) {
	StrLen = target.value.length 
	if (StrLen > max ) { 
		target.value = target.value.substring(0,max); 
		CharsLeft = max; 
	}
	else {
		CharsLeft = StrLen; 
		} 
	nomchamp.value = CharsLeft; 
}

