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 = '#2785BB';
			document.getElementById('tab_'+x).style.color = '#FFF';
		}
		document.getElementById('tabItems_'+idTab).style.display = 'block';
		document.getElementById('tab_'+idTab).style.backgroundColor = '#9A510C';
		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 addItem(id,nb,name,legend,noP,prix){
	var ifExist = false;
	var noItem = null;
	for(x=0;x<comArray.length;x++){
		if(comArray[x][0] == id+noP+legend){
			ifExist = true;
			noItem = x;
		}
	}
	if(ifExist === true && noItem != null){
		comArray[noItem][1] += 1;
	}else{
		var thisItem = Array(id+noP+legend,nb,name,legend,prix);
		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++){
		comHTML += '<tr class="'+className+'">';
			comHTML += '<td width="20"><div class="itemNb">'+comArray[x][1]+'</div></td>';
			comHTML += '<td><div class="itemName">'+comArray[x][2]+'</div><div class="itemDesc">'+comArray[x][3]+'</div></td>';
			comHTML += '<td class="itemPrice" width="50" align="right">'+comArray[x][4]+'$</td>';
			comHTML += '<td class="itemAdd" width="20" align="right" onClick="delItem('+x+')"><img src="img/iconDelete.gif" border="0"></td>';
		comHTML += '</tr>';
		if(className == 'tblLineLight'){
			className = 'tblLineDark';
		}else{
			className = 'tblLineLight';
		}
	}
	comHTML += '</table>';
	document.getElementById('comList').innerHTML = comHTML;
	calculatePrice();
}
function showCommandeClean(){
	var comHTML = '<table cellpadding="0" cellspacing="0" border="0" width="100%">';
	var className = 'tblLineLight';
	for(x=0;x<comArray.length;x++){
		comHTML += '<tr class="'+className+'">';
			comHTML += '<td width="20"><div class="itemNb">'+comArray[x][1]+'</div></td>';
			comHTML += '<td><div class="itemName">'+comArray[x][2]+'</div><div class="itemDesc">'+comArray[x][3]+'</div></td>';
			comHTML += '<td class="itemPrice" width="50" align="right">'+comArray[x][4]+'$</td>';
			comHTML += '<td class="itemAdd" width="20" align="right""></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][4];
		totPrice += thisPrice;
	}
	document.getElementById("boxPrixTot").innerHTML = arrondir(totPrice)+' $';
	var tps = totPrice/100*5;
	var totPriceTps = totPrice + tps;
	var tvq = totPriceTps/100*7.5;
	var totPriceTaxe = totPriceTps+tvq;
	document.getElementById("boxPrixTaxe").innerHTML = arrondir(totPriceTaxe)+' $';
}
function arrondir(resultat) {
      resultat = Math.round(resultat*100)/100;
      return resultat.toFixed(2);
}
function printCommande(){
	var HTMLpage = document.getElementById('comForPrint').innerHTML;
	var HTMLpage2 = document.getElementById('comForPrint2').innerHTML;
	printPopUp = window.open('','_blank',"fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=no,directories=no,location=no,width=400,height=600,left=0,top=0");
	printPopUp.document.open();
	printPopUp.document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><link rel="stylesheet" type="text/css" href="inc/css/style.css"><title>Commande</title></head><body><div class="divPrint"><br><br><img src="img/logo_coq.gif">');
	printPopUp.document.write('<div style="padding:15px;">'+HTMLpage);
	printPopUp.document.write(HTMLpage2+'</div>');
	printPopUp.document.write('</div></body></html>');
	printPopUp.document.close();
	printPopUp.print();
}
function getCmdAndSend(){
	
	if(document.formCmd.name.value == ''){ alert('Champ "Nom,Prenom" vide'); return false; }
	if(document.formCmd.tel.value == ''){ alert('Champ "Telephone" vide'); return false; }
	if(document.formCmd.rue.value == ''){ alert('Champ "No. Civique et rue" vide'); return false; }
	if(document.formCmd.cp.value == ''){ alert('Champ "Code Postal" vide'); return false; }
	if(document.formCmd.ville.value == ''){ alert('Champ "Ville" vide'); return false; }
	
	showCommandeClean();
	
	var HTMLpage = document.getElementById('comForPrint').innerHTML;
	document.getElementById('cmd').value = HTMLpage;
	document.formCmd.submit();
}
//window.addEvent('domready', function() {
	/*var windowHeight = window.getHeight();
	var heightContain = windowHeight-166;
	$('middle').setStyle('height', heightContain);
	$('mainNav').setStyle('height', heightContain);
	$('middleMiddle').setStyle('height', heightContain);
	$('middleRight').setStyle('height', heightContain);
	$('middleContain').setStyle('height', (heightContain-30));*/
//});