window.onload = init;
function init() {
	var gotfocus;
	//External Links
	if (document.getElementsByTagName) {
		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";
			}
		}
	}
	document.getElementById('menu').onclick=showBranch;
	if(document.getElementById('champsselectcart_a') !== null){
	document.getElementById('champsselectcart_a').onchange=showBranch2;
	}
		if(document.getElementById('mylist_b') !== null){
	document.getElementById('mylist_b').onchange=showBranch2;
		}
}
function showBranch(e) {
	try {
		if (!e) {
			e = window.event;
		}
		var o = e.srcElement;
		if (!o) {
			o = e.target;
		}
		if (o.tagName.match(/^a$/i) || o.tagName.match(/^small$/i) || o.tagName.match(/^span$/i)) {
			var m = o.id.match(/^(cat|plus|champsselectcart)_(\w+)$/);
			if (m) {
				if (document.getElementById('souscat_'+m[2])) {
					
					if (document.getElementById('souscat_'+m[2]).style.display == '' || document.getElementById('souscat_'+m[2]).style.display == 'none') {
						document.getElementById('souscat_'+m[2]).style.display = 'block';
						document.getElementById('plus_'+m[2]).className = 'selected';
					} else {
						document.getElementById('souscat_'+m[2]).style.display = 'none';
						document.getElementById('plus_'+m[2]).className = '';
					}
				}
				
				if (document.getElementById('barre_'+m[2])) {
					if(document.getElementById('sousbarre_'+m[2]).style.display == 'block' || document.getElementById('sousbarre_'+m[2]).style.display == ''){
					document.getElementById('sousbarre_'+m[2]).style.display = 'none';
					document.getElementById('fleche_'+m[2]).className = 'close';
					}else{
					document.getElementById('sousbarre_'+m[2]).style.display = 'block';
					document.getElementById('fleche_'+m[2]).className = '';
					}
				
				}


				if (m[1] == 'plus') {
					return false;
				}
			}
		}
	} catch (e) {
		alert('showBranch : '+e.message);
	}
}
function showBranch2(e) {
	try {
		if (!e) {
			e = window.event;
		}
		var o = e.srcElement;
		if (!o) {
			o = e.target;
		}
		if ( o.tagName.match(/^select$/i)) {
			var m = o.id.match(/^(champsselectcart|mylist)_(\w+)$/);
			if (m) {
				if(document.getElementById('champsselectcart_'+m[2])) {
					if(document.getElementById('champsselectcart_'+m[2]).value == 'compte'){
					document.getElementById('champscarte_'+m[2]).style.display = 'none';
					}else{
					document.getElementById('champscarte_'+m[2]).style.display = 'block';
					}
				}
				if(document.getElementById('mylist_'+m[2])) {
					if(document.getElementById('mylist_'+m[2]).value == "ok"){
						document.getElementById('address_'+m[2]).style.display = 'none';
					}else{
						document.getElementById('address_'+m[2]).style.display = 'block';
					}
				}


				if (m[1] == 'plus') {
					return false;
				}
			}
		}
	} catch (e) {
		alert('showBranch : '+e.message);
	}
}







/*function showBranch(branch) {
 var objBranch = document.getElementById(branch).style;
if(objBranch.display=="block" || objBranch.display=="")
 objBranch.display="none";
   else
      objBranch.display="block";
   }*/

  /*function swapClass(objet,nomClass){
		if(objet.className != nomClass){
		objet.className=nomClass;
		}else{
		objet.className='';
		}
   }*/
   
   function slowMotion(objet, cible) {

	var attributes = {
        height: { to: 0 }
    };
	
    var anim = new YAHOO.util.Anim(objet, attributes);

    YAHOO.util.Event.on(objet, 'click', function() {
        anim.animate();
    });
}

		function remplissage(){
			var nbchampstexteparproduit = 4;
			var prix = '';
			var qte = '';
			var total = new Number();
			var totalitems = new Number();
			for ( var n=0; n< document.panier.elements.length; n++ ){
								if(document.panier.elements[n].name=="q"+(n/nbchampstexteparproduit)){
								qte = document.panier.elements[n].value;
								}
								if(document.panier.elements[n].name=="p"+((n-1)/nbchampstexteparproduit)){
								prix = document.panier.elements[n].value;
								document.getElementById('stt'+(n-1)/nbchampstexteparproduit).value = format(qte*prix, 2, '')+" $";
								document.getElementById('stt'+(n-1)/nbchampstexteparproduit).innerHTML = document.getElementById('stt'+(n-1)/nbchampstexteparproduit).value;
								totalitems += (qte*1);
								total += qte*prix;
								document.panier.elements[n+1].value = format(qte*prix, 2, '');

								//document.getElementById('stt'+(n-1)/nbchampstexteparproduit)).innerHTML = qte*prix;

								}
								
								//document.getElementById("st"+(n-2)/nbchampstexteparproduit)).value = qte * prix;
					
			}
			document.getElementById('resultat').innerHTML = format(total, 2, '');
			//document.getElementById('totalitems').innerHTML = "<strong>"+totalitems+"</strong> Items";
			document.getElementById('totalprice').innerHTML = "<strong>"+format(total, 2, '')+"</strong>$";
		}

		function updateproductsincart(id, qte, language){
			if(qte == 0){
				deleteproductfromcart(id, language);
			}
			loading("panier.php?updatesku="+id+"&quantity="+qte, language);
			//window.location.href = "panier.php?updatesku="+id+"&quantity="+qte;
		}
		
		function format(valeur,decimal,separateur) {
		// formate un chiffre avec 'decimal' chiffres après la virgule et un separateur
			var deci=Math.round( Math.pow(10,decimal)*(Math.abs(valeur)-Math.floor(Math.abs(valeur)))) ; 
			var val=Math.floor(Math.abs(valeur));
			if ((decimal==0)||(deci==Math.pow(10,decimal))) {val=Math.floor(Math.abs(valeur)); deci=0;}
			var val_format=val+"";
			var nb=val_format.length;
			for (var i=1;i<4;i++) {
				if (val>=Math.pow(10,(3*i))) {
					val_format=val_format.substring(0,nb-(3*i))+separateur+val_format.substring(nb-(3*i));
				}
			}
			if (decimal>0) {
				var decim=""; 
				for (var j=0;j<(decimal-deci.toString().length);j++) {decim+="0";}
				deci=decim+deci.toString();
				val_format=val_format+"."+deci;
			}
			if (parseFloat(valeur)<0) {val_format="-"+val_format;}
			return val_format;
		}

		function afficher() {
			var val=document.forms[0].elements["chiffre"].value;
			var deci=document.forms[0].elements["decimal"].value;
			document.forms[0].elements["resultat"].value=format(val,deci,document.forms[0].elements["liste"].options[document.forms[0].elements["liste"].selectedIndex].value);
		}

		function addtocart(url, quantity, language){
				loading(url+"&quantity="+quantity, language);
				/*urltoredirect = url+"&quantity="+quantity;
				window.location.href= urltoredirect;*/
		}
		function redirect(url){
				document.displayresparpage.submit();
		}
		function redirecturl(url){
			loading(url);
		}
			function deleteproducts(){
				var id = '';
				var nbchampstexteparproduit = 5;
				for ( var n=0; n< document.panier.elements.length; n++ ){
					if(document.panier.elements[n].name=="id"+((n-4)/nbchampstexteparproduit)){
						if(document.panier.elements[n-1].checked == true){
							id += document.panier.elements[n].value+'-';
						}
					}
				}

			}
			function deleteproductfromcart(id, language){
				if(language == 1){
					if(confirm('Désirez vous vraiment supprimer ce produit de votre panier?')){
						loading("deleteproducts.php?deleteproducts="+id, language);
					}
				}else{
					if(confirm('Do you really want to delete this product from your cart?')){
						loading("deleteproducts.php?deleteproducts="+id, language);
					}
				}

			}
			function refuserToucheEntree(event){
				// Compatibilité IE / Firefox
				if(!event && window.event) {
					event = window.event;
				}
				// IE
				if(event.keyCode == 13) {
					event.returnValue = false;
					event.cancelBubble = true;
				}
				// DOM
				if(event.which == 13) {
					event.preventDefault();
					event.stopPropagation();
				}
			}
			function checkcartenum(num, language){
				if(!(num.length == 16 || num.length == 19)){
					if(language == 1){
					document.getElementById('errorcarte').innerHTML = "format invalide !";
					}else{
					document.getElementById('errorcarte').innerHTML = "invalid format !";
					}
					document.formpanier.error.value = "1";
				}else{
					document.getElementById('errorcarte').innerHTML = "<div style='color: green;'> format valide </div>";
					document.formpanier.error.value = "0";
				}
			}


YAHOO.namespace("example.container");
    function loading(url, language) {
        if (!YAHOO.example.container.wait) {
            // Initialize the temporary Panel to display while waiting for external content to load

            YAHOO.example.container.wait = 
                    new YAHOO.widget.Panel("wait",  
                                                    { width: "350px", 
                                                      fixedcenter: true, 
                                                      close: false, 
                                                      draggable: false, 
                                                      zindex:500,
                                                      modal: true,
                                                      visible: true
                                                    } 
                                                );
												if(language == 1){
			YAHOO.example.container.wait.setHeader("<img src=\"images/logo-bojeux.png\" alt=\"Bojeux\" class=\"float\" /><h2 class=\"float\"><br />Merci de patienter durant<br />le chargement de la page...</h2><span class=\"clear\"></span>");
            YAHOO.example.container.wait.setBody("<img src=\"./images/loading2.gif\" style=\"height: 30px;\"/><br />");
            YAHOO.example.container.wait.render(document.body);
												}else{
			YAHOO.example.container.wait.setHeader("<img src=\"images/logo-bojeux.png\" alt=\"Bojeux\" class=\"float\" /><h2 class=\"float\"><br />Thanks for waiting.<br />Loading in progress...</h2><span class=\"clear\"></span>");
            YAHOO.example.container.wait.setBody("<img src=\"./images/loading2.gif\" style=\"height: 30px;\"/><br />");
            YAHOO.example.container.wait.render(document.body);
												}

        }

        // Define the callback object for Connection Manager that will set the body of our content area when the content has loaded



        var callback = {
            success : function(o) {
                /*content.innerHTML = o.responseText;
                content.style.visibility = "visible";*/
				if(url != 'none'){
					
				window.location.href=document.location;
                //YAHOO.example.container.wait.hide();
				}
            },
            failure : function(o) {
               /* content.innerHTML = o.responseText;
                content.style.visibility = "visible";
                content.innerHTML = "CONNECTION FAILED!";
				*/
				alert(o.responseText);
                YAHOO.example.container.wait.hide();
            }
        }
    
        // Show the Panel
        YAHOO.example.container.wait.show();
        
        // Connect to our data source and load the data
        var conn = YAHOO.util.Connect.asyncRequest("GET", url, callback);
    }


