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 = '#DFE2E4';
			document.getElementById('tab_'+x).style.color = '#455560';
		}
		document.getElementById('tabItems_'+idTab).style.display = 'block';
		document.getElementById('tab_'+idTab).style.backgroundColor = '#455560';
		document.getElementById('tab_'+idTab).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,legend,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,legend,prix);
		comArray.push(thisItem);
	}
	showCommande();
}
function addItemT(id,nb,name,prix,no,prixsup){
	var psup = document.getElementById('psup_'+no).value;
	var ifExist = false;
	var noItem = null;
	for(x=0;x<comArray.length;x++){
		if(comArray[x][0] == id){
			ifExist = true;
			noItem = x;
		}
	}
	if(ifExist === true && noItem != null){
		alert("Cet article est d�ja dans votre commande");
	}else{
		var thisItem = Array(id,nb,name,prix,psup,prixsup);
		comArray.push(thisItem);
	}
	showCommandeT();
}
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="../../imports/images/iconMoin.gif" border="0"></td>';
		comHTML += '</tr>';
		if(className == 'tblLineLight'){
			className = 'tblLineDark';
		}else{
			className = 'tblLineLight';
		}
	}
	comHTML += '</table>';
	document.getElementById('comList').innerHTML = comHTML;
	calculatePrice();
}
function showCommandeT(){
	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" valign="top"><div class="itemNb" style="padding-top:3px;">'+comArray[x][1]+'</div></td>';
			comHTML += '<td><div class="itemName">'+comArray[x][2]+'</div><div class="itemDesc">'+comArray[x][3]+'$ + <br>Pers.Supp: '+comArray[x][4]+' &agrave; '+comArray[x][5]+'$ ch.</div></td>';
			var thisPrice = arrondir((comArray[x][5]*comArray[x][4])+comArray[x][3]);
			comHTML += '<td class="itemPrice" width="50" align="right">'+thisPrice+'$</td>';
			comHTML += '<td class="itemAdd" width="20" align="right" onClick="delItemT('+x+')">S</td>';
		comHTML += '</tr>';
		if(className == 'tblLineLight'){
			className = 'tblLineDark';
		}else{
			className = 'tblLineLight';
		}
	}
	comHTML += '</table>';
	document.getElementById('comList').innerHTML = comHTML;
	calculatePriceT();
}
function showCommandeTClean(){
	var comHTML = '<table cellpadding="0" cellspacing="0" border="0" >';
	var className = 'tblLineLight';
	for(x=0;x<comArray.length;x++){
		comHTML += '<tr class="'+className+'">';
			comHTML += '<td  width="20%" valign="top"><div class="itemNb" style="padding-top:3px;">'+comArray[x][1]+'</div></td>';
			comHTML += '<td class="middleCol" width="60%" ><div class="itemName">'+comArray[x][2]+'</div><div class="itemDesc">'+comArray[x][3]+'$ + <br>Pers.Supp: '+comArray[x][4]+' &agrave; '+comArray[x][5]+'$ ch.</div></td>';
			var thisPrice = arrondir((comArray[x][5]*comArray[x][4])+comArray[x][3]);
			comHTML += '<td class="itemPrice" width="50"  width="20%" align="right">'+thisPrice+'$</td>';
		comHTML += '</tr>';
		if(className == 'tblLineLight'){
			className = 'tblLineDark';
		}else{
			className = 'tblLineLight';
		}
	}
	comHTML += '</table>';
	document.getElementById('comList').innerHTML = comHTML;
	calculatePriceT();
}
function calculatePriceT(){
	var totPrice = 0;
	for(x=0;x<comArray.length;x++){
		var thisPrice = 0;
		thisPrice = (comArray[x][5]*comArray[x][4])+comArray[x][3];
		totPrice += thisPrice;
	}
	document.getElementById("boxPrixTot").innerHTML = arrondir(totPrice)+' $';
	var tps = totPrice/100*6;
	var totPriceTps = totPrice + tps;
	var tvq = totPriceTps/100*7.5;
	var totPriceTaxe = totPriceTps+tvq;
	document.getElementById("boxPrixTaxe").innerHTML = arrondir(totPriceTaxe)+' $';
}
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*6;
	var totPriceTps = totPrice + tps;
	var tvq = totPriceTps/100*7.5;
	var totPriceTaxe = totPriceTps+tvq;
	document.getElementById("boxPrixTaxe").innerHTML = arrondir(totPriceTaxe)+' $';
	document.getElementById("tot").value = 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="../../imports/css/se_styles_menu.css"><link rel="stylesheet" type="text/css" href="../../imports/css/se_styles.css"><title>Commande</title></head><body><div class="divPrint"><br><br><img src="../../imports/images/logo_sushiexpress.gif">');
	printPopUp.document.write('<div style="padding:15px;">'+HTMLpage);
	printPopUp.document.write(HTMLpage2+'</div>');
	printPopUp.document.write('<br /><br /><p>40 Boulevard Jacques-Cartier Nord<br /> Sherbrooke, QC<br /> J1J 2Z8</p> <p class="style1">819.823.2333</p> <p> <a href="mailto:info@sushiexpress.ca">info @ sushiexpress.ca</a></p>');
	printPopUp.document.write('</div></body></html>');
	printPopUp.document.close();
	printPopUp.print();
}
function getCmdAndSend(){
	showCommandeTClean();
	var HTMLpage = document.getElementById('comForPrint').innerHTML;
	document.getElementById('cmd').value = HTMLpage;
	document.formCmd.submit();
}

/* this function posts the form to ./paypal.php */
function payPalCmd(){
	var total = parseInt(document.getElementById('tot').value);
	if (!(total > 0)){ 
		alert("Sélectionnez vos sushies favoris avant de procéder au paiement.");
		return;
	}
	if(confirm("Voulez-vous procéder au paiement?") == true && total >= 1){
		
		var HTMLpage = tableGen(comArray); 
		if(HTMLpage == false)
			HTMLpage = document.getElementById('comForPrint').innerHTML; 
		 		 
		HTMLpage = HTMLpage + " <br/><hr/>"+ document.getElementById('comForPrint2').innerHTML+'<br/><hr/>';
		document.getElementById('od').value = HTMLpage; 
		document.formCmd.submit();	
		
	}else{		
		return;
	}	
}

/**
 * @author Pascal Maniraho 
 * @version MediaMeg 1.0.0 
 * @param {Object} dataArray Multidimensional array for bought items 
 */
function tableGen(dataArray){	
	if( dataArray.length < 1 || dataArray === undefined )
		return false; 							
	try{
		var table = "<table width='650px' border='0' cellspacing='2'  cellpadding='2' >", row = "", rows = "", trh = "";
		for( i in dataArray){
			for ( j in dataArray[i] )	row += ' <td '+( ( j == 2 ||   j == 3 ) ? ' width = \'350\' ' :'' ) + ' > ' + dataArray[i][j] + ' </td>';/*+ ( ( i % 2 )? ' bgcolor= \'#6694E3\' ' : ' bgcolor= \'#E0ECFF\' ')*/		 		
				rows += '<tr>' + row + '</tr>';	
				row = '';		
		}
		//adding captions 
		if(j >= 4) 
		trh = "<tr><th>Code</th><th>Quantit&eacute;</th><th align='left'>Sushi</th><th  align='left'>Options</th><th>Prix U.</th></tr>";
		table =  table + trh +rows+"</table>";
	}catch(error){
		table = false; 
	}			
	return ((table == false )?false:(table)); 
}



