function showTabContain(idTab){
	if(idTab !== ''){
		for(var x=0;x<nbTab;x++){
			document.getElementById('tabItems_'+x).style.display = 'none';
			document.getElementById('tab_'+x).style.backgroundColor = '#004990';
			document.getElementById('tab_'+x).style.color = '#FFF';
		}
		document.getElementById('tabItems_'+idTab).style.display = 'block';
		document.getElementById('tab_'+idTab).style.backgroundColor = '#D20B10';
		document.getElementById('tab_'+idTab).style.color = '#FFF';
	}
}
function showCat(noGroup){
	for(x=1;x<5;x++){
		if(document.getElementById('groupTab_'+x)){
			document.getElementById('groupTab_'+x).style.display = 'none';
		}
	}
	if(document.getElementById('groupTab_'+noGroup)){
		document.getElementById('groupTab_'+noGroup).style.display = 'block';
		for(var x=0;x<nbTab;x++){
			document.getElementById('tabItems_'+x).style.display = 'none';
			document.getElementById('tab_'+x).style.backgroundColor = '#2785BB';
			document.getElementById('tab_'+x).style.color = '#FFF';
		}
		document.getElementById('tabItems_'+firstTab[noGroup]).style.display = 'block';
		document.getElementById('tab_'+firstTab[noGroup]).style.backgroundColor = '#9A510C';
		document.getElementById('tab_'+firstTab[noGroup]).style.color = '#FFF';
	}
}
function delItem(no){
	if(comArray[no][1] > 1){
		comArray[no][1] -= 1;
	}else{
		comArray.splice(no,1);
	}
	showCommande();
}
function delItemT(no){
	if(comArray[no][1] > 1){
		comArray[no][1] -= 1;
	}else{
		comArray.splice(no,1);
	}
	showCommandeT();
}
function addItem(id,nb,name,noP,prix){
	var ifExist = false;
	var noItem = null;
	for(x=0;x<comArray.length;x++){
		if(comArray[x][0] == id+noP){
			ifExist = true;
			noItem = x;
		}
	}
	if(ifExist === true && noItem != null){
		comArray[noItem][1] += 1;
	}else{
		var thisItem = Array(id+noP,nb,name,prix,noP);
		comArray.push(thisItem);
	}
	showCommande();
}
function showCommande(){
	var comHTML = '<table cellpadding="0" cellspacing="0" border="0" width="100%">';
	var className = 'tblLineLight';
	for(x=0;x<comArray.length;x++){
		var this_x =  x+1;
		comHTML += '<tr class="'+className+'">';
			comHTML += '<td width="20"><div class="itemNb"><input type="hidden" name="quantity_'+this_x+'" value="'+comArray[x][1]+'">'+comArray[x][1]+'</div></td>';
			comHTML += '<td><div class="itemName">'+comArray[x][2]+'<input type="hidden" name="item_number_'+this_x+'" value="'+comArray[x][4]+'"><input type="hidden" name="item_name_'+this_x+'" value="'+comArray[x][2]+'"></div><div class="itemDesc">'+comArray[x][4]+'</div></td>';
			comHTML += '<td class="itemPrice" width="50" align="right"><input type="hidden" name="amount_'+this_x+'" value="'+comArray[x][3]+'">'+comArray[x][3]+'$</td>';
			comHTML += '<td class="itemAdd" width="20" align="right" onClick="delItem('+x+')"><img src="inc/img/panierMoin.gif" border="0"></td>';
		comHTML += '</tr>';
		if(className == 'tblLineLight'){
			className = 'tblLineDark';
		}else{
			className = 'tblLineLight';
		}
	}
	comHTML += '</table>';
	document.getElementById('comList').innerHTML = comHTML;
	calculatePrice();
}
function calculatePrice(){
	var totPrice = 0;
	for(x=0;x<comArray.length;x++){
		var thisPrice = 0;
		thisPrice = comArray[x][1]*comArray[x][3];
		totPrice += thisPrice;
	}
	document.getElementById("boxPrixTot").innerHTML = arrondir(totPrice)+' $';
	var tps = totPrice/100*5;
	var totPriceTps = totPrice + tps;
	var tvq = totPriceTps/100*8.5;
	var totPriceTaxe = totPriceTps+tvq;
	document.getElementById("boxPrixTaxe").innerHTML = arrondir(totPriceTaxe)+' $';
	var taxeOnly = arrondir(totPriceTaxe-totPrice);
	var cmdHTML = document.getElementById('comList').innerHTML;
	var this_x =  x+1;
	cmdHTML += '<input type="hidden" name="quantity_'+this_x+'" value="1">';
	cmdHTML += '<input type="hidden" name="item_name_'+this_x+'" value="Taxe">';
	cmdHTML += '<input type="hidden" name="amount_'+this_x+'" value="'+taxeOnly+'">';
	document.getElementById('comList').innerHTML = cmdHTML;
}
function arrondir(resultat) {
      resultat = Math.round(resultat*100)/100;
      return resultat.toFixed(2);
}
