﻿// Fichier JScript
function format(valeur,decimal) {         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;		 	    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;}

var valueTotale  = 0.00
var cmpt = 0
var tabListProducts = new Array();
function UpdateSelect(obj, name, price)
{
 

        price = price.replace(",",".")
        var label = document.getElementById('listProducts');
        var text = "";
        if(obj.checked)             
        {
            tabListProducts[tabListProducts.length] = new Array(obj, name, price);
               
            viewSelect(tabListProducts) 
            
        }
        else
        {
               var tmpTabListProducts = new Array()
            var ii = 0
            for (var i=0;i<tabListProducts.length;i++)
            {
                 
                      if((tabListProducts[i][0]).value !=obj.value)
                    {
                        tmpTabListProducts[ii] = tabListProducts[i]
                        ii += 1
                         
                    }
                
                
                
            }
            tabListProducts = new Array()
            tabListProducts = tmpTabListProducts
            viewSelect(tabListProducts) 
            
        }
       
}

function viewSelect(tab)
{
    var text = "";
    var total = 0.00
    var nbr = tab.length
    if(tab.length>0)  text += "<UL>"  
    
    for (var i=0;i<nbr;i++)
    {
      text  += "<LI >"+tab[i][1]+"</LI>"
      total += parseFloat(tab[i][2])
    }
    
    if(tab.length>0)  text += "</UL>"      
    
    var label = document.getElementById('listProducts');
    //alert(text)
    //label.innerHTML = text
    
     var labelTotal = document.getElementById('totalArticleSelect');
    if (labelTotal) {
         if(nbr==0)
             valueTotale = 0.00
            
        //labelTotal.innerHTML = "<p class='trait'>&nbsp;</p> Total : "+format(total,2)+"&nbsp;&euro;";
        labelTotal.innerHTML = " "+format(total,2)+"&nbsp;&euro;";
        //titreSelectCart   
    }
    
    var labelTitre = document.getElementById('nbrArticleSelect');
    if (labelTitre) { 
         
        if(nbr == 1)
            labelTitre.innerHTML =      nbr+" Article ";
        else if(nbr > 1)
            labelTitre.innerHTML = "    "+nbr+" Articles ";
        else
            labelTitre.innerHTML = " ";
     
    }
}


function popup(src,name,width, height, screenx, screeny, scrollbar, resize, toolbar, status, menubar, location, directories) 
{
    var size, pos;
	size = '';
	pos = '';
	if (width > 0)		size = ',width='+width;
	if (height > 0)		size = size + ',height='+height;
	if (screenx >= 0)	pos = ',screenX='+screenx+',left='+screenx;
	if (screeny >= 0)	pos = pos + ',screenY='+screeny+',top='+screeny;
	scrollbar = (scrollbar == 1)?'yes':'no';
	status = (status == 1)?'yes':'no';
	resize = (resize == 1)?'yes':'no';
	menubar = (menubar == 1)?'yes':'no';
	location = (location == 1)?'yes':'no';
	toolbar = (toolbar == 1)?'yes':'no';
	directories = (directories == 1)?'yes':'no';
	window.open(src, name,'scrollbars='+scrollbar+',resizable='+resize+',toolbar='+toolbar+',status='+status+',menubar='+menubar+',location='+location+',directories='+directories+pos+size);

}


function popupByTXT(txt)
{	
    name = (new Date()).getSeconds()
    var myWindow = window.open("", name+(new Date()).getSeconds(), 'toolbar=no,width=720px,height=520px,resize=yes,scrollbars=yes');
    myWindow.document.write(txt);
    myWindow.document.close();
}

function addBookmark(){
    var title=window.document.title;
    var url=window.location.href;
    if(navigator.appName!="Microsoft Internet Explorer"){
        window.sidebar.addPanel(title,url,"");
    }else{
        window.external.AddFavorite(url,title);
    }
}

var ie=(navigator.appName=="Microsoft Internet Explorer");
function setHomePage(obj,txt){
    if(ie){
        obj.style.behavior="url(#default#homepage)";
        obj.setHomePage(window.location.href);
    }else{
        alert(txt);
    }
}
