/******************************************************************************
* eshopscript.js                                                              *
* --------------                                                              *
*                                                                             *
* FUNCTION USED IN PAGES BASKET, ORDER, PRINTABLE FORM                        *
*                                                                             *
*******************************************************************************
*                                                                             *
* Copyright 2000-2002 Isotools, all right reserved                            *
*                                                                             *
******************************************************************************/

var priceMode = "";
var priceDisplay = "";
var orderID = 0;

/******************************************************************************
*
* BASKET :
*
* function that display basket : qt and options can be modified by end user 
*
******************************************************************************/
function showBasket(cookieName)
{
	if (!areCookiesEnabled())
	{
		document.write(thesaurus.shop_cookieDisabled);
		return;
	}
	
	var items = getItems(cookieName);
	if (items == null || items.length == 0)
	{
		document.write(thesaurus.shop_basketIsEmpty + "<br>");
		return;
	}

	// retreive duty mode to display prices
	var tmp = dutyMode.split("_");
	priceMode = tmp[0];	// mode de saisie des prix (HT ou TTC);
	priceDisplay = tmp[1];	// mode d'affichage des prix (HT ou TTC);

	document.write("<input type='button' value='" + thesaurus.shop_emptyBasket + "' onClick='deleteCookie(cookieName);window.location.reload()'>");

	// heading cells
	var tWidth = (displayPrices == "true") ? "700" : "600";
	tWidth = "100%"
	document.write("<form name='basket' action='"+orderUrl+"' method='get' onSubmit='return true;'>"); 
	document.write("  <table border='0' cellspacing='0' cellpadding='0' width='" + tWidth + "' align='center' class='shopItemBgColor'>");
	document.write("    <tr>");
	document.write("      <td width='" + tWidth + "'>");
	document.write("        <table border='0' cellpadding='0' cellspacing='0' width='100%' align='left'>");
	document.write("          <tr>");
	document.write("            <td align='left' width='400' class='shopItemBgColor'><span class='text'><b>"+thesaurus.shop_itemTitle+"</b></span><img align='absmiddle' src='./iso_icons/empty.gif' width='1' height='25'></td>");
	if (displayPrices == "true")
	{
		if (priceDisplay == "HT")
			document.write("    <td align='right' class='shopItemBgColor' width='100'><span class='text'><b>"+thesaurus.shop_unitPriceHTTitle+"</b></span></td>");
		else
			document.write("    <td align='right' class='shopItemBgColor' width='100'><span class='text'><b>"+thesaurus.shop_unitPriceTitle+"</b></span></td>");
	}
	document.write("            <td align='center' class='shopItemBgColor' width='100'><span class='text'><b>"+thesaurus.shop_quantityTitle+"</b></span></td>");
	if (displayPrices == "true")
	{
		if (priceDisplay == "HT")
			document.write("    <td align='right' class='shopItemBgColor' width='100'><span class='text'><b>"+thesaurus.shop_priceHTTitle+"</b></span></td>");
		else
			document.write("    <td align='right' class='shopItemBgColor' width='100'><span class='text'><b>"+thesaurus.shop_priceTitle+"</b></span></td>");
	}
	document.write("          </tr>");

	var colspan = (displayPrices == "true") ? "4" : "2";
	document.write("<tr><td colspan='"+colspan+"' class='shopItemLineColor'><img src='./iso_icons/empty.gif' width='1' height='2'></td></tr>");

	// fill with items
	for(i=0; i<items.length; i++)
		items[i].writeBasket(cookieName);

	colspan = (displayPrices == "true") ? "4" : "2";
	document.write("<tr><td colspan='"+colspan+"' class='shopItemLineColor'><img src='./iso_icons/empty.gif' width='1' height='1'></td></tr>");
	
	colspan = (displayPrices == "true") ? "2" : "1";

	// display total
	calculateTotal(items, cookieName);

	if (displayPrices == "true")
	{
		// total
		document.write("<tr>");
		document.write("<td class='pageBgColor' valign='middle' align='right' colspan='" + colspan + "'><span class='text'>");
		if (priceDisplay == "TTC")
			document.write(thesaurus.shop_totalTTCTitle);
		else
			document.write(thesaurus.shop_totalHTTitle);
		document.write("</span></td>");
		document.write("<td class='pageBgColor'><img src='./iso_icons/empty.gif' width='1' height='20'></td>");
		document.write("<td class='pageBgColor' valign='middle' align='right'><span class='text'>");
		if (priceDisplay == "TTC")
			document.write(TOTAL_TTC);
		else
			document.write(TOTAL_HT);
		document.write("&nbsp;"+currency+"</td>");
		document.write("</tr>");

		// duty amount
		document.write("<tr>");
		document.write("<td class='pageBgColor' valign='middle' align='right' colspan='" + colspan + "'><span class='text'>");
		if (priceDisplay == "TTC")
			document.write(thesaurus.shop_dutyAmountTTC);
		else
			document.write(thesaurus.shop_dutyAmountHT);
		document.write("</span></td>");
		document.write("<td class='pageBgColor'><img src='./iso_icons/empty.gif' width='1' height='20'></td>");
		document.write("<td class='pageBgColor' valign='middle' align='right'><span class='text'>"+DUTY_AMOUNT+"&nbsp;"+currency+"</td>");
		document.write("</tr>");

		// totalTTC if needed
		if (priceDisplay == "HT")
		{
			document.write("<tr>");
			document.write("<td class='pageBgColor' valign='middle' align='right' colspan='" + colspan + "'><span class='text'>"+thesaurus.shop_totalTTCTitle+"</span></td>");
			document.write("<td class='pageBgColor'><img src='./iso_icons/empty.gif' width='1' height='20'></td>");
			document.write("<td class='pageBgColor' valign='middle' align='right'><span class='text'>"+TOTAL_TTC+"&nbsp;"+currency+"</td>");
			document.write("</tr>");
		}
		
		// shippingCosts
		var shippingCostCookieName = cookieName + "DeliveryArea";
		var currentArea = getCookie(shippingCostCookieName);
		if (currentArea == "" && shippingCosts.length >= 1)
			setShippingCosts(shippingCostCookieName, shippingCosts[0].zone, false);
		
		document.write("<tr>");
		document.write("<td class='pageBgColor' valign='middle' align='right' colspan='" + colspan + "'><span class='text'>");
		if (shippingCosts.length > 1)
		{
			document.write("<table width='100%' border='0' cellpading='0' cellspacing='0'><tr><td>&nbsp;</td><td width='50%' nowrap class='text' align='right'>");
			document.write(thesaurus.shop_deliveryArea + "&nbsp;:&nbsp;");
			document.write("<select onChange='setShippingCosts(\"" + shippingCostCookieName + "\", this.options[this.selectedIndex].value , true)'>");
			
			for(i=0; i<shippingCosts.length ; i++)
			{
				var shippingCostOption = shippingCosts[i];
				var label = shippingCostOption.zone ;
				
				var nFreeBeyond = parseFloat(shippingCostOption.freeBeyond);
				if ( !isNaN(nFreeBeyond) && nFreeBeyond > 0)
					label += "&nbsp;(" + thesaurus.shop_freeBeyondTitle + "&nbsp;" + shippingCostOption.freeBeyond + "&nbsp;"+currency+")";
				
				document.write("<option value=\"" + shippingCostOption.zone + "\"");
				if (currentArea == shippingCostOption.zone)
					document.write(" selected");
				document.write(">" + label + "</option>");
			}
			document.write("</select></td></tr></table>");
		}
		else if (shippingCosts.length == 1)
		{
			document.write(thesaurus.shop_shippingCostsTitle);
			
			var nFreeBeyond = parseFloat(shippingCosts[0].freeBeyond);
			if ( !isNaN(nFreeBeyond) && nFreeBeyond > 0)
				document.write("<br>("+ thesaurus.shop_freeBeyondTitle + "&nbsp;" + shippingCosts[0].freeBeyond + " " + currency + ")");
		}

		document.write("</span></td>");
		document.write("<td class='pageBgColor'><img src='./iso_icons/empty.gif' width='1' height='20'></td>");
		document.write("<td class='pageBgColor' valign='bottom' align='right'><span class='text'>"+SHIPPINGCOST_AMOUNT+"&nbsp;"+currency+"</td>");
		document.write("</tr>");

		// to pay
		document.write("<tr><td colspan='"+(parseInt(colspan)+2)+"' class='shopItemLineColor'><img src='./iso_icons/empty.gif' width='1' height='2'></td></tr>");
		document.write("<tr>");
		document.write("<td class='shopItemBgColor' valign='middle' align='right' colspan='" + colspan + "'><span class='text'><b>"+thesaurus.shop_toPay+"</b></span></td>");
		document.write("<td class='shopItemBgColor'><img src='./iso_icons/empty.gif' width='1' height='25'></td>");
		document.write("<td class='shopItemBgColor' valign='middle' align='right'><span class='text'><b>"+TOTAL_TO_PAY+"&nbsp;"+currency+"</b></span></td>");
		document.write("</tr>");
	}

	document.write("</table></td></tr>");
	document.write("<tr><td width='100%' class='pageBgColor' align='center'>");
	// display button to validate order
	document.write("<br><input type='button' value='" + thesaurus.shop_continueOrder + "' onClick='window.history.back()'>&nbsp;<input type='submit' value='" + thesaurus.shop_orderNow + "'>");
	document.write("</td></tr></table>");

	document.write("</form>");
}
/******************************************************************************
* END BASKET 
******************************************************************************/


/******************************************************************************
*
* SHOW ORDER :
*
* function that display order : can't modify anymore
*
******************************************************************************/
function showOrder(cookieName)
{
	if (!areCookiesEnabled())
	{
		document.write(thesaurus.shop_cookieDisabled);
		return;
	}
	
	var items = getItems(cookieName);
	if (items == null || items.length == 0)
	{
		document.write(thesaurus.shop_basketIsEmpty + "<br>");
		return;
	}

	// retreive duty mode to display prices
	var tmp = dutyMode.split("_");
	priceMode = tmp[0];	// mode de saisie des prix (HT ou TTC);
	priceDisplay = tmp[1];	// mode d'affichage des prix (HT ou TTC);

	document.write("<br><span class='shopItemName'>"+thesaurus.shop_orderDetails+"</span><br>");

	// heading cells
	var tWidth = (displayPrices == "true") ? "700" : "600";
	tWidth = "100%";
	document.write("<form name='basket' action='' method='get' onSubmit='return true;'>"); 
	document.write("  <table border='0' cellspacing='0' cellpadding='0' width='" + tWidth + "' align='center' class='shopItemBgColor'>");
	document.write("    <tr>");
	document.write("      <td width='" + tWidth + "'>");
	document.write("        <table border='0' cellpadding='0' cellspacing='0' width='100%' align='left'>");
	document.write("          <tr>");
	document.write("            <td align='left' width='400' class='shopItemBgColor'><span class='text'><b>"+thesaurus.shop_itemTitle+"</b></span><img align='absmiddle' src='./iso_icons/empty.gif' width='1' height='25'></td>");
	if (displayPrices == "true")
	{
		if (priceDisplay == "HT")
			document.write("    <td align='right' class='shopItemBgColor' width='100'><span class='text'><b>"+thesaurus.shop_unitPriceHTTitle+"</b></span></td>");
		else
			document.write("    <td align='right' class='shopItemBgColor' width='100'><span class='text'><b>"+thesaurus.shop_unitPriceTitle+"</b></span></td>");
	}
	document.write("            <td align='center' class='shopItemBgColor' width='100'><span class='text'><b>"+thesaurus.shop_quantityTitle+"</b></span></td>");
	if (displayPrices == "true")
	{
		if (priceDisplay == "HT")
			document.write("    <td align='right' class='shopItemBgColor' width='100'><span class='text'><b>"+thesaurus.shop_priceHTTitle+"</b></span></td>");
		else
			document.write("    <td align='right' class='shopItemBgColor' width='100'><span class='text'><b>"+thesaurus.shop_priceTitle+"</b></span></td>");
	}
	document.write("          </tr>");

	var colspan = (displayPrices == "true") ? "4" : "2";
	document.write("<tr><td colspan='"+colspan+"' class='shopItemLineColor'><img src='./iso_icons/empty.gif' width='1' height='2'></td></tr>");

	// fill with items
	for(i=0; i<items.length; i++)
		items[i].showOrder(cookieName);

	colspan = (displayPrices == "true") ? "4" : "2";
	document.write("<tr><td colspan='"+colspan+"' class='shopItemLineColor'><img src='./iso_icons/empty.gif' width='1' height='1'></td></tr>");
	
	colspan = (displayPrices == "true") ? "2" : "1";

	// display total
	calculateTotal(items, cookieName);
	
	if (displayPrices == "true")
	{
		// total
		document.write("<tr>");
		document.write("<td class='pageBgColor' valign='middle' align='right' colspan='" + colspan + "'><span class='text'><b>");
		if (priceDisplay == "TTC")
			document.write(thesaurus.shop_totalTTCTitle);
		else
			document.write(thesaurus.shop_totalHTTitle);
		document.write("</b></span></td>");
		document.write("<td class='pageBgColor'><img src='./iso_icons/empty.gif' width='1' height='20'></td>");
		document.write("<td class='pageBgColor' valign='middle' align='right'><span class='text'>");
		if (priceDisplay == "TTC")
			document.write(TOTAL_TTC);
		else
			document.write(TOTAL_HT);
		document.write("&nbsp;"+currency+"</td>");
		document.write("</tr>");

		// duty amount
		document.write("<tr>");
		document.write("<td class='pageBgColor' valign='middle' align='right' colspan='" + colspan + "'><span class='text'>");
		if (priceDisplay == "TTC")
			document.write(thesaurus.shop_dutyAmountTTC);
		else
			document.write(thesaurus.shop_dutyAmountHT);
		document.write("</span></td>");
		document.write("<td class='pageBgColor'><img src='./iso_icons/empty.gif' width='1' height='20'></td>");
		document.write("<td class='pageBgColor' valign='middle' align='right'><span class='text'>"+DUTY_AMOUNT+"&nbsp;"+currency+"</td>");
		document.write("</tr>");

		// totalTTC if needed
		if (priceDisplay == "HT")
		{
			document.write("<tr>");
			document.write("<td class='pageBgColor' valign='middle' align='right' colspan='" + colspan + "'><span class='text'><b>"+thesaurus.shop_totalTTCTitle+"</b></span></td>");
			document.write("<td class='pageBgColor'><img src='./iso_icons/empty.gif' width='1' height='20'></td>");
			document.write("<td class='pageBgColor' valign='middle' align='right'><span class='text'>"+TOTAL_TTC+"&nbsp;"+currency+"</td>");
			document.write("</tr>");
		}

		// shippingCosts
		var shippingCostCookieName = cookieName + "DeliveryArea";
		var currentArea = getCookie(shippingCostCookieName);
		if (currentArea == "" && shippingCosts.length >= 1)
			setShippingCosts(shippingCostCookieName, shippingCosts[0].zone, false);

		document.write("<tr>");
		document.write("<td class='pageBgColor' valign='middle' align='right' colspan='" + colspan + "'><span class='text'>");

		var label = "";

		if (shippingCosts.length > 1)
		{
			label += "<b>"+thesaurus.shop_shippingCostsTitle + "</b>&nbsp;(";
			for(i=0; i<shippingCosts.length ; i++)
			{
				var shippingCostOption = shippingCosts[i];
				if (currentArea == shippingCostOption.zone)
				{
					label += shippingCostOption.zone ;
					label += ")";

					var nFreeBeyond = parseFloat(shippingCostOption.freeBeyond);
					if ( !isNaN(nFreeBeyond) && nFreeBeyond > 0)
						label += "<br>"+ thesaurus.shop_freeBeyondTitle + "&nbsp;" + shippingCostOption.freeBeyond;
				}
			}
		}
		else
		{
			label += thesaurus.shop_shippingCostsTitle; 

			var nFreeBeyond = parseFloat(shippingCosts[0].freeBeyond);
			if ( !isNaN(nFreeBeyond) && nFreeBeyond > 0)
				label += "<br>"+ thesaurus.shop_freeBeyondTitle + "&nbsp;" + shippingCosts[0].freeBeyond;
		}

		document.write(label + "</span></td>");
		document.write("<td class='pageBgColor'><img src='./iso_icons/empty.gif' width='1' height='20'></td>");
		document.write("<td class='pageBgColor' valign='bottom' align='right'><span class='text'>"+SHIPPINGCOST_AMOUNT+"&nbsp;"+currency+"</td>");
		document.write("</tr>");

		// to pay
		document.write("<tr><td colspan='"+(parseInt(colspan)+2)+"' class='shopItemLineColor'><img src='./iso_icons/empty.gif' width='1' height='2'></td></tr>");
		document.write("<tr>");
		document.write("<td class='shopItemBgColor' valign='middle' align='right' colspan='" + colspan + "'><span class='text'><b>"+thesaurus.shop_toPay+"</b></span></td>");
		document.write("<td class='shopItemBgColor'><img src='./iso_icons/empty.gif' width='1' height='25'></td>");
		document.write("<td class='shopItemBgColor' valign='middle' align='right'><span class='text'><b>"+TOTAL_TO_PAY+"&nbsp;"+currency+"</b></span></td>");
		document.write("</tr>");
	}

	document.write("</table>");
	document.write("</td></tr></table>");

	// order mode
	displayOrderModes();

	document.write("</form><br>");
}

//////////////////////////////////////////////////////////////////////////////////////
// display choice of the order Mode
//////////////////////////////////////////////////////////////////////////////////////
function displayOrderModes()
{
	var modes = orderModes.split(" ");

	if (modes.length <= 0)
		return;

	document.write("<br><span class='shopItemName'>"+thesaurus.shop_chooseOrderModeTitle+"</span><br><br>")

	var tWidth = (displayPrices == "true") ? "700" : "600";
	tWidth = "100%";
	document.write("<table border='0' cellpadding='0' cellspacing='0' width='"+tWidth+"' align='center'><tr>");
	
	var html = "";
	if (securedPayment == true && displayPrices == "true")
		html += displaySecuredOrderModes(TOTAL_TO_PAY);
	document.write(html)

	var i;
	for (i=0 ; i<modes.length ; i++)
	{
		switch (modes[i])
		{
			case "email":
				document.write("<td align='left' class='text'><input name='orderMode' type='radio' value='email'>"+thesaurus.shop_mailOrder+"</td>");
				break;
			case "fax":
				document.write("<td align='left' class='text'><input name='orderMode' type='radio' value='fax'>"+thesaurus.shop_faxOrder+"</td>");
				break;
			case "phone":
				document.write("<td align='left' class='text'><input name='orderMode' type='radio' value='phone'>"+thesaurus.shop_phoneOrder+"</td>");
				break;
			case "postalService":
				document.write("<td align='left' class='text'><input name='orderMode' type='radio' value='postal'>"+thesaurus.shop_postalOrder+"</td>");
				break;
		}
	}
	document.write("</tr></table>");
}

function displayButtons()
{
	document.write("<p align='center'><input type='button' value='" + thesaurus.shop_backToBasketTitle + "' onClick='window.history.back()'>&nbsp;");
	document.write("<input type='button' value='" + thesaurus.shop_validateOrderTitle + "' onClick='validateOrder()'></p>");
}

function validateOrder()
{
	var action = "";
	var orderMode = window.document.basket.orderMode;

	var orderModeValue = "none";
	
	if (orderMode.length == null)
	{
		if (orderMode.checked == true)
			orderModeValue = orderMode.value;
	}
	else
	{
		var i;
		for (i=0 ; i<orderMode.length; i++)
		{
			if (orderMode[i].checked)
				orderModeValue = orderMode[i].value;
		}
	}

	switch(orderModeValue)
	{
		case "none":
			alert(thesaurus.shop_chooseOrderModeTitle)
			break
		case "securedpayment": //secured payment
			if(checkForm())
			{
				recordCoord();
				validateSecuredOrder();
				window.document.basket.target = "_self";
				window.document.basket.action=securedPaymentUrl;// + "?total=" + TOTAL_TO_PAY;
				window.document.basket.submit();
			}
			break;
		default: // phone, fax, postal, mail
			// we have to display a printable form 
			if(checkForm())
			{
				recordCoord();
				window.document.basket.target = "_blank";
				window.document.basket.action=printableFormUrl;
				window.document.basket.submit();
			}
			break;
	}
}
/******************************************************************************
* SHOW ORDER 
******************************************************************************/


/******************************************************************************
*
* PRINTABLE FORM :
*
* function that printable form : can't modify anymore
*
******************************************************************************/
function showPrintableOrder(cookieName)
{
	var html = "";

	if (!areCookiesEnabled())
	{
		html += thesaurus.shop_cookieDisabled;
		return html;
	}
	
	var items = getItems(cookieName);

	if (items == null || items.length == 0)
	{
		html += thesaurus.shop_basketIsEmpty + "<br>";
		return html;
	}
	
	// retreive duty mode to display prices
	var tmp = dutyMode.split("_");
	priceMode = tmp[0];	// mode de saisie des prix (HT ou TTC);
	priceDisplay = tmp[1];	// mode d'affichage des prix (HT ou TTC);

	// ORDER NUMBER
	if (currentOrderMode == "securedPayment")
	{
		orderID = getSecuredOrderID(window.location.search.substr(1));
		html += "<p align='left' style='font-size:10pt;'><b>"+thesaurus.shop_orderIDTitle+" "+orderID+"</b></p>";
	}
	else
	{
		orderID = getOrderID();
		html += "<p align='left' style='font-size:10pt;'><b>"+thesaurus.shop_orderIDTitle+" "+orderID+"</b></p>";
	}
	
	// heading cells
	var tWidth = (displayPrices == "true") ? "700" : "600";
	tWidth = "100%";
	html += "<form name='basket' action='' method='get' onSubmit='return true;'>"; 
	html += "<table border='0' cellpadding='0' cellspacing='0' width='100%'>";
	var colspan = (displayPrices == "true") ? "4" : "2";
	html += "<tr><td colspan='"+colspan+"'><img src='./iso_icons/black.gif' width='100%' height='2'></td></tr>";
	html += "<tr>";
	html += "<td align='left' width='400' bgcolor='#DDDDDD'><b>"+thesaurus.shop_itemTitle+"</b><img align='absmiddle' src='./iso_icons/empty.gif' width='1' height='25'></td>";
	if (displayPrices == "true")
	{
		if (priceDisplay == "HT")
			html += "<td align='right' bgcolor='#DDDDDD' width='100'><b>"+thesaurus.shop_unitPriceHTTitle+"</b></td>";
		else
			html += "<td align='right' bgcolor='#DDDDDD' width='100'><b>"+thesaurus.shop_unitPriceTitle+"</b></td>";
	}
	html += "<td align='center' bgcolor='#DDDDDD' width='100'><b>"+thesaurus.shop_quantityTitle+"</b></td>";
	if (displayPrices == "true")
	{
		if (priceDisplay == "HT")
			html += "<td align='right' bgcolor='#DDDDDD' width='100'><b>"+thesaurus.shop_priceHTTitle+"</b></td>";
		else
			html += "<td align='right' bgcolor='#DDDDDD' width='100'><b>"+thesaurus.shop_priceTitle+"</b></td>";
	}
	html += "</tr>";

	var colspan = (displayPrices == "true") ? "4" : "2";
	html += "<tr><td colspan='"+colspan+"'><img src='./iso_icons/black.gif' width='100%' height='2'></td></tr>";

	// fill with items
	var total = 0;
	for(i=0; i<items.length; i++)
		html += items[i].showPrintableOrder(cookieName);

	colspan = (displayPrices == "true") ? "4" : "2";
	html += "<tr><td colspan='"+colspan+"'><img src='./iso_icons/black.gif' width='100%' height='1'></td></tr>";
	colspan = (displayPrices == "true") ? "2" : "1";

	// display total
	calculateTotal(items, cookieName);

	if (displayPrices == "true")
	{
		// total
		html += "<tr>";
		html += "<td valign='middle' align='right' colspan='" + colspan + "'><b>";
		if (priceDisplay == "TTC")
			html += thesaurus.shop_totalTTCTitle;
		else
			html += thesaurus.shop_totalHTTitle;
		html += "</b></td>";
		html += "<td><img src='./iso_icons/empty.gif' width='1' height='20'></td>";
		html += "<td valign='middle' align='right'>";
		if (priceDisplay == "TTC")
			html += TOTAL_TTC;
		else
			html += TOTAL_HT;
		html += "&nbsp;"+currency+"</td>";
		html += "</tr>";

		// duty amount
		html += "<tr>";
		html += "<td valign='middle' align='right' colspan='" + colspan + "'>";
		if (priceDisplay == "TTC")
			html += thesaurus.shop_dutyAmountTTC;
		else
			html += thesaurus.shop_dutyAmountHT;
		html += "</td>";
		html += "<td><img src='./iso_icons/empty.gif' width='1' height='20'></td>";
		html += "<td valign='middle' align='right'>"+DUTY_AMOUNT+"&nbsp;"+currency+"</td>";
		html += "</tr>";

		// totalTTC if needed
		if (priceDisplay == "HT")
		{
			html += "<tr>";
			html += "<td valign='middle' align='right' colspan='" + colspan + "'><b>"+thesaurus.shop_totalTTCTitle+"</b></td>";
			html += "<td><img src='./iso_icons/empty.gif' width='1' height='20'></td>";
			html += "<td valign='middle' align='right'>"+TOTAL_TTC+"&nbsp;"+currency+"</td>";
			html += "</tr>";
		}

		//shippingCosts
		shippingCostCookieName = cookieName + "DeliveryArea";
		var currentArea = getCookie(shippingCostCookieName);
		
		html += "<tr>";
		html += "<td valign='middle' align='right' colspan='" + colspan + "'>";

		if (shippingCosts.length > 1)
		{
			html += "<b>"+thesaurus.shop_shippingCostsTitle + "</b>&nbsp;(";
			for(i=0; i<shippingCosts.length ; i++)
			{
				var shippingCostOption = shippingCosts[i];
				if (currentArea == shippingCostOption.zone)
				{
					var label = shippingCostOption.zone ;
					html += label + ")";
				}
			}
		}
		else
		{
			html += thesaurus.shop_shippingCostsTitle;
			
			var nFreeBeyond = parseFloat(shippingCosts[0].freeBeyond);
			if ( !isNaN(nFreeBeyond) && nFreeBeyond > 0)
				html += "<br>"+ thesaurus.shop_freeBeyondTitle + "&nbsp;" + shippingCosts[0].freeBeyond;
		}

		html += "</td>";
		html += "<td><img src='./iso_icons/empty.gif' width='1' height='20'></td>";
		html += "<td valign='bottom' align='right'>"+SHIPPINGCOST_AMOUNT+"&nbsp;"+currency+"</td>";
		html += "</tr>";

		// to pay
		html += "<tr><td colspan='"+(parseInt(colspan)+2)+"'><img src='./iso_icons/black.gif' width='100%' height='2'></td></tr>";

		html += "<tr>";
		html += "<td bgcolor='#DDDDDD' valign='middle' align='right' colspan='" + colspan + "'><b>"+thesaurus.shop_toPay+"</b></td>";
		html += "<td bgcolor='#DDDDDD'><img src='./iso_icons/empty.gif' width='1' height='25'></td>";
		html += "<td bgcolor='#DDDDDD' valign='middle' align='right'><b>"+TOTAL_TO_PAY+"&nbsp;"+currency+"</b></td>";
		html += "</tr>";
		html += "<tr><td colspan='"+(parseInt(colspan)+2)+"'><img src='./iso_icons/black.gif' width='100%' height='2'></td></tr>";
	}

	html += "</table>";
	html += "</form>";

	if (currentOrderMode == "securedPayment")
	{
		// remove cookie even if customer doesn't print
		deleteCookie(cookieName);
	}
	return html;
}

function showCoord(coordCookie, cookieName)
{
	var html = "";

	var items = getItems(cookieName);
	if (items == null || items.length == 0)
		return "";

	var coord = getCookie(coordCookie).split('#');
	
	html += "<table border='0' cellpadding='5' cellspacing='3' width='100%'>";
	
	var i;
	for (i=0 ; i<coord.length-1 ; i++)
	{
		var field = coord[i].split("*");
		html += "<tr>";
		html += "<td valign='top' align='left' width='43%'>" + unescape(field[0]) + "</td>";
		html += "<td valign='top' align='left' width='67%'>" + unescape(field[1]) + "&nbsp;</td>";
		html += "</tr>";
	}
	html += "</table>";

	return html;
}

function showPayments()
{
	var html = ""; 

	if (currentOrderMode != "securedPayment")
	{
		var items = getItems(cookieName);
		if (items == null || items.length == 0)
			return " ";

		var modes = paymentModes.split(" ");

		if (modes.length <= 0)
			return "";

		var tWidth = (displayPrices == "true") ? "700" : "600";
		tWidth = "100%";
		html += "<form name='payment'>";
		html += "<table border='0' cellpadding='5' cellspacing='0' width='"+tWidth+"'>";
		html += "<tr><td bgcolor='#DDDDDD' colspan='2'><img src='./iso_icons/black.gif' width='100%' height='2'></td></tr>";
		html += "<tr><td bgcolor='#DDDDDD' colspan='2'><b>"+thesaurus.shop_choosePaymentTitle+"</b></td></tr>";

		var i;
		for (i=0 ; i<modes.length ; i++)
		{
			switch (modes[i])
			{
				case "check":
					if ((acceptDelayedPayment == "true") || (currentOrderMode == "postal"))
					{
						if (currentOrderMode == "email")
						{
							html += "<tr><td bgcolor='#DDDDDD' width='15' align='left' valign='top'><input type='radio' name='paymentMode' value='check'></td>";
							html += "<td bgcolor='#DDDDDD' align='left'>"+thesaurus.shop_checkTitle+thesaurus.shop_payableToTitle+checkPayableTo+"</td></tr>";
						}
						else
						{
							html += "<tr><td bgcolor='#DDDDDD' width='15' align='left' valign='top'><img src='./iso_icons/checkbox.gif'></td>";
							html += "<td bgcolor='#DDDDDD' align='left'>"+thesaurus.shop_checkTitle+thesaurus.shop_payableToTitle+checkPayableTo+"</td></tr>";
						}
					}
					break;
				case "mandat":
					if ((acceptDelayedPayment == "true") || (currentOrderMode == "postal"))
					{
						if (currentOrderMode == "email")
						{
							html += "<tr><td bgcolor='#DDDDDD' width='15' align='left' valign='top'><input type='radio' name='paymentMode' value='mandat'></td>";
							html += "<td bgcolor='#DDDDDD' align='left'>"+thesaurus.shop_mandatTitle+thesaurus.shop_payableToTitle+checkPayableTo+"</td></tr>";
						}
						else
						{
							html += "<tr><td bgcolor='#DDDDDD' width='15' align='left' valign='top'><img src='./iso_icons/checkbox.gif'></td>";
							html += "<td bgcolor='#DDDDDD' align='left'>"+thesaurus.shop_mandatTitle+thesaurus.shop_payableToTitle+checkPayableTo+"</td></tr>";
						}
					}
					break;
				case "creditCardFax":
					if ( (currentOrderMode == "fax") || (currentOrderMode == "postal"))
					{
						html += "<tr><td bgcolor='#DDDDDD' width='15' align='left' valign='top'><img src='./iso_icons/checkbox.gif'></td>";
						html += "<td bgcolor='#DDDDDD' align='left'>"+thesaurus.shop_creditCardTitle+"<br>";
						html += thesaurus.shop_creditCardNumber+"&nbsp;<img src='./iso_icons/4numbers.gif' align='absmiddle'>&nbsp;<img src='./iso_icons/4numbers.gif' align='absmiddle'>&nbsp;<img src='./iso_icons/4numbers.gif' align='absmiddle'>&nbsp;<img src='./iso_icons/4numbers.gif' align='absmiddle'><br>";
						html += thesaurus.shop_creditCardExp+"&nbsp;<img src='./iso_icons/2numbers.gif' align='absmiddle'>&nbsp;<img src='./iso_icons/2numbers.gif' align='absmiddle'></td></tr>";
					}
					break;
				case "creditCardPhone":
					if ((acceptDelayedPayment == "true") || (currentOrderMode == "phone"))
					{
						if (currentOrderMode == "phone") 
						{
							html += "<tr><td bgcolor='#DDDDDD' width='15' align='left' valign='top'><img src='./iso_icons/checkbox.gif'></td>";
							html += "<td bgcolor='#DDDDDD' align='left'>"+thesaurus.shop_creditCardPhoneTitle+"</td></tr>";
						}
						if (currentOrderMode == "email") 
						{
							html += "<tr><td bgcolor='#DDDDDD' width='15' align='left' valign='top'><input type='radio' name='paymentMode' value='creditCardPhone'></td>";
							html += "<td bgcolor='#DDDDDD' align='left'>"+thesaurus.shop_creditCardPhoneTitle+"</td></tr>";
						}
					}
					break;
				case "customerAccount":
					if (currentOrderMode != "email")
					{
						html += "<tr><td bgcolor='#DDDDDD' width='15' align='left' valign='top'><img src='./iso_icons/checkbox.gif'></td>";
						html += "<td bgcolor='#DDDDDD' align='left'>"+thesaurus.shop_customerAccountTitle;
						html += thesaurus.shop_customerAccountNumber+"&nbsp;________________________________</td></tr>";
					}
					else
					{
						html += "<tr><td bgcolor='#DDDDDD' width='15' align='left' valign='top'><input type='radio' name='paymentMode' value='customerAccount'></td>";
						html += "<td bgcolor='#DDDDDD' align='left'>"+thesaurus.shop_customerAccountTitle;
						html += thesaurus.shop_customerAccountNumber+"&nbsp;<input type='text' value='' name='customerAccountNumber'></td></tr>";
					}
					break;
				default:
					break;
			}
		}

		html += "<tr><td bgcolor='#DDDDDD' colspan='2'><img src='./iso_icons/black.gif' width='100%' height='2'></td></tr>";
		html += "</table></form><br>";
	}

	// print or send button
	if (currentOrderMode == "email")
	{
		var action = "";
		if (formUseAdvanced == "true")
			action = formAction;
		else
			action = "mailto:" + emailOrder + "?subject=" + shopName;
		
		html += "<form name='orderForm' ENCTYPE='text/plain' action='" + action + "' method='post'>";
		html += "<input type ='hidden' name='commande' value=''>";
		html += "<INPUT VALUE='"+thesaurus.shop_sendOrder+"' ONCLICK='sendOrder()' TYPE='button'>";
		html += "</form>";
	}
	else
		html += "<form><INPUT VALUE='"+thesaurus.shop_printOrder+"' ONCLICK='printOrder()' TYPE='button'></form>";

	return html;
}

var currentOrderMode = "none";

function showInstructions()
{
	var html = "";
	var items = getItems(cookieName);
	if (items == null || items.length == 0)
		return "";

	var info = window.location.search;
	info = info.substr(1);
	var infoArray = info.split("&");

	var i;
	for (i=0 ; i< infoArray.length ; i++)
	{
		var tmp = infoArray[i].split("=");
		if (tmp[0] == "orderMode")
		{
			currentOrderMode = tmp[1];
			switch(tmp[1])
			{
				case "email":
					html += thesaurus.shop_instructionsMail1 + "<b>" + thesaurus.shop_instructionsMail2 + "</b>.";
					break;
				case "fax":
					html += thesaurus.shop_instructions+thesaurus.shop_instructionsFax + "<b>" + faxNumber + "</b>";
					break;
				case "postal":
					html += thesaurus.shop_instructions+thesaurus.shop_instructionsPostal + "<br><br>"+ "<b>" + address+ "</b>";
					break;
				case "phone":
					html += thesaurus.shop_instructions+thesaurus.shop_instructionsPhone + "<b>" + phoneNumber + "</b>";
					break;
			}
		}
	}

	if (currentOrderMode == "securedPayment")
	{
		return showInstructionsSecured();
	}

	if ((acceptDelayedPayment == "true") && (currentOrderMode != "postal"))
	{
		if (address != "" || (phoneNumber != "" && currentOrderMode == "email") )
		{
			html += "<br><br>"+thesaurus.shop_instructionsDelayedPayment1;
			if (address != "")
				html += thesaurus.shop_postalOrder+", ";
			if (phoneNumber != "" && currentOrderMode == "email")
				html += thesaurus.shop_phoneOrder+", ";
			html += thesaurus.shop_instructionsDelayedPayment2+"<br><br>";
			html += "<table width='100%' cellpading='5' cellspacing='0' border='0'><tr>";
			if (address != "")
				html += "<td align='center' valign='top' nowrap><b>"+thesaurus.shop_instructionsPostal+"</b><br>"+address+"</td>";
			if (phoneNumber != "" && currentOrderMode == "email")
				html += "<td align='center' valign='top' nowrap><b>"+thesaurus.shop_instructionsPhone+"</b><br>"+phoneNumber+"</td>";
			html += "</tr></table>";
		}
	}
	html += "<br>";

	return html;
}

function printOrder()
{
	var ua = window.navigator.userAgent.toLowerCase();
	var i = ua.indexOf('msie');
	var version = 0;
	if ( i != -1)
		version  = parseFloat('0' + ua.substr(i+5), 10);

	if ((document.all) && (version < 5))
	{
		// IE 4
		document.body.insertAdjacentHTML( "beforeEnd","<object id=\"idWBPrint\" width=0 height=0 classid=\"clsid:8856F961-340A-11D0-A96B-00C04FD705A2\"></object>");
		idWBPrint.ExecWB(6, 1);
	}
	else 
		window.print();

	// remove cookie
	// do not remove with NS4.x because 
	// it reload page before printing
	if ( !document.layers )
		deleteCookie(cookieName);
}

function makeOrderMail(paymentMode)
{
	var strOrder = "\n" + thesaurus.shop231 + orderID+" \n";
	strOrder += "==========================================================\n";
	//payment
	var strPayment = thesaurus.shop229;
	switch (paymentMode)
	{
		case "check":
			strPayment += thesaurus.shop_checkTitle;
			break;
		case "mandat":
			strPayment += thesaurus.shop_mandatTitle;
			break;
		case "creditCardPhone":
			strPayment += thesaurus.shop_creditCardPhoneTitle;
			break;
		case "customerAccount":
			strPayment += thesaurus.shop_customerAccountTitle + document.payment.customerAccountNumber.value;
			break;
		case "securedPayment":
			strPayment += thesaurus.shop230;
			break;
		default:
			break;
	}
	// get basket cookie to fill with item
	var items = getItems(cookieName);

	if (items == null)
		return;

	// retreive duty mode to display prices
	var tmp = dutyMode.split("_");
	priceMode = tmp[0];	// mode de saisie des prix (HT ou TTC);
	priceDisplay = tmp[1];	// mode d'affichage des prix (HT ou TTC);

	// fill with items
	for(i=0; i<items.length; i++)
	{
		var itemStr = items[i].fillOrderForm();
		strOrder += itemStr;
	}

	// display total
	var debugString = calculateTotal(items, cookieName);
	strOrder += debugString;

	if (displayPrices == "true")
	{
		// total
		if (priceDisplay == "TTC")
		{
			strOrder += thesaurus.shop_totalTTCTitle + " = " + TOTAL_TTC + " " + currency;
			strOrder += "\n" + thesaurus.shop_dutyAmountTTC + " " + DUTY_AMOUNT + " " + currency;
		}
		else
		{
			strOrder += thesaurus.shop_totalHTTitle + " = " + TOTAL_HT + " " + currency;
			strOrder += "\n" + thesaurus.shop_dutyAmountHT + " " + DUTY_AMOUNT + " " + currency;
			strOrder += "\n" + thesaurus.shop_totalTTCTitle + " = " + TOTAL_TTC;
		}

		strOrder += "\n";

		// shippingCosts
		shippingCostCookieName = cookieName + "DeliveryArea";
		var currentArea = getCookie(shippingCostCookieName);
		
		strOrder += thesaurus.shop_deliveryArea + " : " + currentArea + " = " + SHIPPINGCOST_AMOUNT + " " + currency + "\n";

		// to pay
		strOrder += thesaurus.shop_toPay + " = " + TOTAL_TO_PAY + " " + currency;
	}
	strOrder += "\n==========================================================\n\n";

	// coord
	var coord = getCookie(coordCookie).split('#');

	for (i=0 ; i<coord.length-1 ; i++)
	{
		var field = coord[i].split("*");
		var regexp = /<([^<]*)>/g;
		var unformatedLabel = replace(unescape(field[0]), "<br>", "\n");
		unformatedLabel = unformatedLabel.replace(regexp, "")
		strOrder += unformatedLabel + " : " + unescape(field[1]) + "\n";
	}

	strOrder += "\n==========================================================\n";
	strOrder += strPayment;
	strOrder += "\n==========================================================\n";

	strOrder = replace(strOrder, "<br>", "\n");

	strOrder = replace(strOrder, "&#8364;", "E");

	return strOrder
}

function sendOrder()
{
	var orderField = document.orderForm.commande;

	//payment
	var payment = "";
	var paymentFormField = document.payment.paymentMode;
	var checked = false;
	if (paymentFormField.length <= 0 || paymentFormField.length == null)
	{
		checked = paymentFormField.checked;
		payment = paymentFormField.value;
	}
	for (i=0 ; i<paymentFormField.length ; i++)
	{
		if (paymentFormField[i].checked)
		{
			payment = paymentFormField[i].value;
			switch (paymentFormField[i].value)
			{
				case "check":
				case "mandat":
				case "creditCardPhone":
					checked = true;
					break;
				case "customerAccount":
					if (document.payment.customerAccountNumber.value == "")
					{
						alert(thesaurus.shop_invalidCustomerAccountNumber);
						return
					}
					checked = true;
					break;
				default:
					break;
			}
		}
	}
	if (checked != true)
	{
		alert(thesaurus.shop_invalidPayment);
		return;
	}

	var strOrder = makeOrderMail(payment);

	orderField.value = strOrder;

	document.orderForm.submit();

	// remove cookie
	deleteCookie(cookieName);

	window.opener.location.reload();
}

function getOrderID()
{
	if (orderID != 0)
		return orderID;

	var date = new Date();
	var dateID=Math.round(date.valueOf()/1000)

	return dateID;
}
