/*
 * lib.js
 *
 * Solution e-commerce MyEShop v1.0
 * http://www.myeshop.fr
 *
 * Copyright (c) 2005 MyEShop
 *
 * Thanks to McPeter from Blinckers-groups ;)
 *
 */

// Bibliothèque Objet
function Ident(Obj){ return (document.all)?document.all[Obj]:document.getElementById(Obj); }
function posX(Obj){ return (Obj.offsetParent)?(Obj.offsetLeft + posX(Obj.offsetParent)):(Obj.offsetLeft); }
function posY(Obj){ return (Obj.offsetParent)?(Obj.offsetTop + posY(Obj.offsetParent)):(Obj.offsetTop); }
function posW(Obj){ return (Obj.offsetParent)?(Obj.offsetWidth + posX(Obj.offsetParent)):(Obj.offsetWidth); }
function posH(Obj){ return (Obj.offsetParent)?(Obj.offsetHeight + posY(Obj.offsetParent)):(Obj.offsetHeight); }

// Trouve le nombre de champs à calculer
function findNbMenu(){ var a=1; while(nbMenu=Ident('menu'+a)){ a++; } return a; }

// Détection du click sur menuLeft
function menuDynam(){
for(m=1; m<findNbMenu(); m++){
		if(document.all){
			Ident('menu'+m).onmousedown=thisMenu;
		}else{
			Ident('menu'+m).addEventListener("mousedown",thisMenu, false);
		}
	}
}
function thisMenu(e){ devl('s'+this.id); }


// fonction pour réglementation de l'attribut 'target' du W3C
function TargetBlank() { 
 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"; 
 } 
} 

// Fonction menu developpent
function devl(id) {
	var d = Ident(id), e=false;
	if(d){ if(d.style.display=='block') e=true; }
	for (var i = 1; i<findNbMenu(); i++) {
		if (Ident('smenu'+i)) {Ident('smenu'+i).style.display='none';}
	}
	if(d){
		d.style.display=(e==false)?'block':'none';
	}
}

function formatChamp(nombre){ // Retourne le nombre au format 2 chiffres après la virgule
	var num_string=Math.abs(Math.round(nombre*100)).toString(); 
	var moin=nombre<0?"-":""; 
	var pos=num_string.length-2; 
	var chiffre="."+num_string.substr(pos); 
	if(nombre==0) return "0.00"; 
	if(nombre > -1 && nombre < 1) return moin+"0"+chiffre; 
	while(pos>3){ pos=pos-3; chiffre=","+num_string.substr(pos,3)+chiffre; } 
	return moin+num_string.substring(0,pos)+chiffre;
}


function LoadJS(){
		TargetBlank();
		//devl();
		//menuDynam();
}