
//Pour le menu **

// Prototype getElementsByClassName
function getElementsByClassName(oElm, strTagName, oClassNames){
    var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    var arrRegExpClassNames = new Array();
    if(typeof oClassNames == "object"){
        for(var i=0; i<oClassNames.length; i++){
            arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames[i].replace(/\-/g, "\\-") + "(\\s|$)"));
        }
    }
    else{
        arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames.replace(/\-/g, "\\-") + "(\\s|$)"));
    }
    var oElement;
    var bMatchesAll;
    for(var j=0; j<arrElements.length; j++){
        oElement = arrElements[j];
        bMatchesAll = true;
        for(var k=0; k<arrRegExpClassNames.length; k++){
            if(!arrRegExpClassNames[k].test(oElement.className)){
                bMatchesAll = false;
                break;                      
            }
        }
        if(bMatchesAll){
            arrReturnElements.push(oElement);
        }
    }
    return (arrReturnElements)
}

var RefM = null, RefTM = null, IniM  = null, SM = null;

// Affichage des sous menus
function SHMenuOver(){
    if (RefTM != null)
    {
	    window.clearTimeout(RefTM);
	}
	RefTM = null;
	if(RefM!=null){
		RefM.className = "off";
		RefM.prt.className = RefM.prt.offc;
		RefM = null;
	}
    
	this.className = "on";
	this.prt.className = this.prt.onc;
	RefM = this;
}

// Masquage des sous menus
function SHMenuOut(){
	if(RefM!=null){
		RefM.className = "off";
		RefM.prt.className = RefM.prt.refc;
		RefTM = null;
	}
	if(IniM!=null){
		IniM.className = "on";
		IniM.prt.className = IniM.prt.refc;
		RefM = IniM;
	}
}

function InitMenu(){
	SM = getElementsByClassName(document, "div", "Header_Menu")[0];
	SMcol = SM.getElementsByTagName("A");
	for(i=0;i<SMcol.length;i++){
        if(SMcol[i].parentNode.parentNode.parentNode!=SM)
			continue;
		SMcol[i].prt = SMcol[i].parentNode;

		if (SMcol[i].className=='on'){
			IniM = RefM = SMcol[i];
		}
		SMcol[i].prt.refc = SMcol[i].prt.className;

		if(SMcol[i].prt.refc==''){
		    SMcol[i].prt.refc = SMcol[i].prt.offc = 'off';
		    SMcol[i].prt.onc = 'on';
        }
		else if(SMcol[i].prt.refc.indexOf(" ")>=0){
		     SMcol[i].prt.offc = SMcol[i].prt.refc.replace(" on", " off");
		     SMcol[i].prt.onc = SMcol[i].prt.refc.replace(" off", " on");
		 }
	    else{
 		     SMcol[i].prt.offc = SMcol[i].prt.refc + ' off';
 		     SMcol[i].prt.onc = SMcol[i].prt.refc + ' on';
        }

		SMcol[i].onmouseover = SHMenuOver;
		SMcol[i].bro = SMcol[i];
		if(SMcol[i].prt.getElementsByTagName("UL").length==1){
	        SMcol[i].bro = SMcol[i].prt.getElementsByTagName("UL")[0];
	        SMcol[i].bro.onmouseover = function(){
	        if (RefTM && RefTM != 'undefined')
	        {
			     window.clearTimeout(RefTM);
			    RefTM = null;
			    }
	        }
        }
   	
		SMcol[i].onmouseout = SMcol[i].bro.onmouseout = function(e)
		{
		    if (RefM && RefM != 'undefined')
		    {
			if(RefM==IniM)
				return;
			if(document.all){
				if(this.parentNode.contains(event.toElement))
					return;
			}
			/* je ne sais pas a koi sert ce code en dessous e.relatedTarget est tjs a null j'ai rajoute une
			*  Une condition au if pour 
			*/
			else if(e && e.relatedTarget != null){
				o = e.relatedTarget;
				while(o.tagName!="BODY"){
					if(o.parentNode==this.parentNode)
						return;
					o = o.parentNode;
				}
			}
    		 RefTM = window.setTimeout("SHMenuOut()", 500);
            }
		}
	}
}


window.onload = function() {
	if(document.getElementById("chk_all")) {
		document.getElementById("chk_all").onclick = function() {
			//Ipt = getElementsByClassName(document, "table", "war_tab")[0].getElementsByTagName("input");
			Ipt = getElementsByClassName(document, "table", "")[0].getElementsByTagName("input");
			for(i=0; i<Ipt.length; i++) {
				if(Ipt[i].type == "checkbox") {
					Ipt[i].checked = this.checked;
				}
			}
		}
	}
	if(document.getElementById("chk_all_f")) {
		document.getElementById("chk_all_f").onclick = function() {
//			Ipt = getElementsByClassName(document, "table", "war_tab")[0].getElementsByTagName("input");
			Ipt = getElementsByClassName(document, "table", "")[0].getElementsByTagName("input");
			for(i=0; i<Ipt.length; i++) {
				if(Ipt[i].type == "checkbox") {
					Ipt[i].checked = this.checked;
				}
			}
		}
	}
	
}

//recupere les elements de la liste des produits sélectionnés
function ListProductChecked()
{
    list = "$";
	Ipt = getElementsByClassName(document, "table", "")[0].getElementsByTagName("input");
	for(i=0; i<Ipt.length; i++) {
		if(Ipt[i].type == "checkbox" && Ipt[i].id != "chk_all" && Ipt[i].id != "chk_all_f" && Ipt[i].checked == true) {
			list += Ipt[i].id.replace("chk_","") + "$";
    	}
	}
	if (list.length == 1)
	    list = "";
	    
    return list;

}


function parentRefreshOnly()
{

   principalWindow=window.opener;
   if(principalWindow!=null)
   {
       principalWindow.location.reload();
   }
}


function parentRefresh()
{
   
   principalWindow=window.opener;
   if(principalWindow!=null)
   {
       principalWindow.location.reload();
   }
   window.location.href = window.location;
}

function parentRedirect(url)
{
   principalWindow=window.opener;

   while(principalWindow!=null)
   {
      v1=principalWindow;
      principalWindow=principalWindow.opener;
      if (principalWindow != null)
        v1.close();
   }
   v1.location.href = url;
   window.close();
}



/**fonctions d'ajout ou de suppression à un champ*/
function VarAug(field, nbvar)
{
    if (nbvar.length ==0) nbvar = 1;
    
    var valeur = document.getElementById(field).value;
    valeur = parseFloat(valeur.replace(",", ".")) + nbvar;
    valeur = valeur.toString().replace(".", ",")
    
    document.getElementById(field).value = valeur;
    
    if (document.getElementById(field).onchange != null)
    {
        onchange_ref = document.getElementById(field).onchange;
        onchange_ref(); 
    }
    else
    {
        document.getElementById(field).focus();
    }
}

function VarDim(field, nbvar)
{
    if (nbvar.length ==0) nbvar = 1;

    var valeur = document.getElementById(field).value;
    valeur = parseFloat(valeur.replace(",", ".")) - nbvar;
    valeur = valeur.toString().replace(".", ",")
    
    document.getElementById(field).value = valeur;

    if (document.getElementById(field).onchange != null)
    {
        onchange_ref = document.getElementById(field).onchange;
        onchange_ref(); 
    }
    else
    {
        document.getElementById(field).focus();
    }
    
}

function GetEnterKey(e, buttonid){
      var evt = e ? e : window.event;
      var bt = document.getElementById(buttonid);
      if (bt){
          if (evt.keyCode == 13){
                bt.click();
                return false;
          }
      }
}

