(function($){  
	$.fn.extend({

		cart: function(options) {
		
			var m_this = $(this);
			var shopProxy = new ShopProxy("<c:out value/>");
			
			// setup
			function setup() {
				if (m_this.data("__setup"))
					return;
				m_this.data("__setup", true);
				
				$(window).resize(function() {				
					setScrollHeight();
				});
				setScrollHeight();
			}
			
			function setScrollHeight() {
				m_this.find(".scroll").height($(window).height()-400);
			}
					
			function displayCartStep1NotLogged(data) {
    			
  			$("#cart #step1").empty();		
  			var list = '<div class="basket"><div class="path"><a href="#" onclick="document.location=document.location.href.split(&#39;#&#39;)[0]; return false">Shop on line</a> &gt; <b>Acquista</b></div><div class="step"><ul><li class="first"><b>1. Carrello</b></li><li>2. Riepilogo ordine</li><li class="last">3. Ordine confermato</li></ul></div> <div class="scroll"><table border="0" cellpadding="0" cellspacing="0"><tr class="label"><th>Immagine</th><th>Descrizione</th><th>Quantit&agrave;</th><th>Prezzo</th></tr>';
  			$.each(data.data, function(i,aelement) {
  				list = list + '<tr id="product_' + aelement.product["kca:id"] + '">';
					list = list + '<td class="thumb"><span><img src="/images/thumb/'+ aelement.product["brand"]["code"] +'/' + aelement.product["code"] + '.jpg" alt="" /></span></td>';
  				list = list + '<td class="desc"><b class="focus">' + aelement.product["name"] + ' </b><span class="color">Colore/variante:' + aelement.product["colour"]["description"] + '</span></td>';		
   				list = list + '<td class="qta"><div class="custom_input_mini"><input class="qtv modifyQuantity"  maxlength="3" type="text" value="' + aelement.quantity + '" /><a href="#"  class="refreshQuantity"><img src="/consumer/res/shop/img/basket_back_ico_refresh.gif" alt=""/></a></div> Quantit&agrave;</td>';
   				list = list + '<td class="price"><a href="" class="delete removeItem">Elimina prodotto</a><span>&euro;'  + aelement.totalRow + '</span></td>';
   				list = list + '</tr>';
  			});
  			list = list + '</table></div>';
  			list = list + '<table border="0" cellpadding="0" cellspacing="0"><tr><th class="tot">Totale</th><td class="right"><b class="focus">&euro; ' + data.totalAmount + '</b></td></tr></table>';
  			list = list + '<div class="toolbars"><a class="empty" href="#view=empty" title="svuota carrello"><img src="/consumer/res/shop/img/basket_btn_svuota_carrello.gif" alt="svuota carrello" /></a> </div><div class="toolbars"><a href="#1" class="checkoutNL" title="continua"><img src="/consumer/res/shop/img/basket_btn_continua.gif" alt="continua" /></a></div>';
  			$("#cart #step1").append(list);

				setScrollHeight();

  			$("#cart #step1 .modifyQuantity").unbind('change');
  			$("#cart #step1 .modifyQuantity").change(function () {
  				var strProduct = $(this).closest("[id^='product_']").attr("id");
  				var idProduct = strProduct.substring('product_'.length);
  				shopProxy.getCart().changeQuantity(idProduct, $(this).val(), function() {
  					shopProxy.getCart().list($("#cart").cart().displayCartStep1);
  					$("#navi").navigation().fillNaviCartResume();
					});
  			});
			
			
			$("#cart #step1 .refreshQuantity").unbind('change');
  			$("#cart #step1 .refreshQuantity").click(function () {
  				var strProduct = $(this).closest("[id^='product_']").attr("id");
  				var idProduct = strProduct.substring('product_'.length);
  				shopProxy.getCart().changeQuantity(idProduct, $(this).val(), function() {
  					shopProxy.getCart().list($("#cart").cart().displayCartStep1);
  					$("#navi").navigation().fillNaviCartResume();
					});
  			});
			
			

  			$("#cart #step1 .removeItem").unbind('click');
  			$("#cart #step1 .removeItem").click(function () {
  				var strProduct = $(this).closest("[id^='product_']").attr("id");
  				var idProduct = strProduct.substring('product_'.length);
  				shopProxy.getCart().remove( idProduct, function() {
  					shopProxy.getCart().list($("#cart").cart().displayCartStep1);
  					$("#navi").navigation().fillNaviCartResume();
  				});
  				return false;
  			});

  			$("#cart #step1 .empty").unbind('click');
  			$("#cart #step1 .empty").click(function () {  //sloggato
			 
  				shopProxy.getCart().removeAll( function() {
  					shopProxy.getCart().list($("#cart").cart().displayCartStep1);
  					$("#navi").navigation().fillNaviCartResume();
  				});
  				return false;
  			});

				$("#cart #step1 .checkoutNL").unbind('click');
  			$("#cart #step1 .checkoutNL").click(function () { 				
  				$("#cart").navigation().login(function() {$(".cartlink").click();});
  				return false;
  			});

			}
			
			function displayCartStep1Logged(cartData, userObj) {

				var userData = userObj;
				var pinkDiscount = null;
				var shipCost = null;
				var shipMin = null;
				var totalAmount = cartData.totalAmount;
				
				shopProxy.getCart().pinkDiscount(function(pinkData) {
					
					if (!isEmptyOrNull(pinkData.pinkCardDiscount)) {
						pinkDiscount = pinkData.pinkCardDiscount;
					}
					
					shopProxy.getCart().shipCost(function(shipData) {
						
						if (!isEmptyOrNull(shipData.charges)) {
							shipCost = shipData.charges;
						}
						if (!isEmptyOrNull(shipData.minExpense)) {
							shipMin = shipData.minExpense;
						}

						shopProxy.getCart().finalPrice(function(finalData) {
							
				   		$("#cart #step1").empty();		
			    		var list = '<div class="basket"><div class="path"><a href="#" onclick="document.location=document.location.href.split(&#39;#&#39;)[0]; return false">Shop on line</a> &gt; <b>Acquista</b></div><div class="step"><ul><li class="first"><b>1. Carrello</b></li><li>2. Riepilogo ordine</li><li class="last">3. Ordine confermato</li></ul></div><div class="scroll"><table border="0" cellpadding="0" cellspacing="0"><tr class="label"><th>Immagine</th><th>Descrizione</th><th>Quantit&agrave;</th><th>Prezzo</th></tr>';
			    		$.each(cartData.data, function(i,aelement) {
			    			list = list + '<tr id="product_' + aelement.product["kca:id"] + '">';
								list = list + '<td class="thumb"><span><img src="/images/thumb/'+ aelement.product["brand"]["code"] +'/' + aelement.product["code"] + '.jpg" alt="" /></span></td>';
								list = list + '<td class="desc"><b class="focus">' + aelement.product["name"] + ' </b><span class="color">Colore/variante:' + aelement.product["colour"]["description"] + '</span></td>';		
								list = list + '<td class="qta"><div class="custom_input_mini"><input maxlength="3" class="qtv modifyQuantity" type="text" value="' + aelement.quantity + '" /><a href="#"  class="refreshQuantity"><img src="/consumer/res/shop/img/basket_back_ico_refresh.gif" alt=""/></a></div> Quantit&agrave;</td>';
								list = list + '<td class="price"><a href="" class="delete removeItem">Elimina prodotto</a><span>&euro;'  + aelement.totalRow + '</span></td>';
								list = list + '</tr>';
			    		});
								
		    			list = list + '</ul>';
		    			if (pinkDiscount > 0) {
		    				list = list + '<tr><td colspan="2"><b class="focus">Sconto Pink Card</b></td><td colspan="2" class="right"><span class="focus">&euro;' + pinkDiscount + ' </span></td></tr>';
		    			}

							if (isEmptyOrNull(cartData.promotionDiscount)) {
								list = list + '<tr><td colspan="2">Possiedi un <b class="focus">codice promozionale?</b></td><td colspan="2" class="right"><input type="text" class="custom_input_medium promocode" value="Inserisci qui il tuo codice" /></td></tr>';
							} else {
								list = list + '<tr><td colspan="2">Possiedi un <b class="focus">codice promozionale:</b></td><td colspan="2" class="right">' +cartData.promotionDiscount + '</td></tr>';
							}

							list = list + '<tr><td colspan="2">Spese di spedizione</td><td colspan="2" class="right"><span class="focus">&euro; '+ shipCost + '</span></td></tr></table></div>';
							list = list + '<table border="0" cellpadding="0" cellspacing="0"><tr><th class="tot">Totale</th><td class="right"><b class="focus">&euro;' + finalData.finalAmount + '</b></td></tr>';
							list = list + '<tr class="noback"><td colspan="2"><div class="toolbars"><a href="#view=empty" class="empty" title="svuota carrello"><img src="/consumer/res/shop/img/basket_btn_svuota_carrello.gif" alt="svuota carrello" /></a>  </div></td></tr>';
							list = list + '<tr><td colspan="2" class="bolder enable"><b class="focus left">Metodo di pagamento</b><div id="metodopag">';
 						
							
							var shippingAddressAdd3 = !userData.shippingAddress["address"]  ? userData.address["address"] : userData.shippingAddress["address"];
							var shippingCap3 = !userData.shippingAddress["cap"] ? userData.address["cap"] : userData.shippingAddress["cap"];
							var shippingCity3 = !userData.shippingAddress["city"] ?  userData.address["city"] : userData.shippingAddress["city"];
							var shippingProvince3 = !userData.shippingAddress["province"] ? userData.address["province"] : userData.shippingAddress["province"];
							var shippingCountry3 = !userData.shippingAddress["country"] ? userData.address["country"] : userData.shippingAddress["country"];
							
							if((shippingCountry3 == 'IT')) {
							list = list + '<input type="radio" name="payment" class="custom_input_check" value="ca"  /><span>Contrassegno</span>';
							} 
						
							list = list + '<input type="radio" name="payment" value="cc" /><span>Carta di credito</span></div></td></tr></table>';
							list = list + '<div class="txt"><p><b>Indirizzo di spedizione</b>: '+ userData.name + ' ' +userData.surname+ ', ' + shippingAddressAdd3 + '- ' + shippingCap3 + ' '+   shippingCity3 + ' ('+ shippingProvince3 +'), ' + shippingCountry3 + '</div><div id="modificadati"><a href="/it/consumer/vanity-room/common/il-mio-profilo.page?targetURI=/it/consumer/index.page&lang=it" title="modifica dati di spedizione"><img src="/consumer/res/shop/img/basket_btn_mod_dati_spedizione.gif" alt="modifica dati di spedizione" /></a></div>';
							list = list + '<div class="toolbars"> <a href="#1" class="checkout" title="continua"><img src="/consumer/res/shop/img/basket_btn_continua.gif" alt="continua" /></a></div>';	
							$("#cart #step1").append(list);
		    			
		    			setScrollHeight();
			    		
		    			$("#cart #step1 .modifyQuantity").unbind('change');
		    			$("#cart #step1 .modifyQuantity").change(function () {
		    				var strProduct = $(this).closest("[id^='product_']").attr("id");
		    				var idProduct = strProduct.substring('product_'.length);
		    				shopProxy.getCart().changeQuantity(idProduct, $(this).val(), function() {
		    					shopProxy.getCart().list($("#cart").cart().displayCartStep1);
		    					$("#navi").navigation().fillNaviCartResume();
								});
		    			});
						
						$("#cart #step1 .refreshQuantity").unbind('change');
						$("#cart #step1 .refreshQuantity").click(function () {
							var strProduct = $(this).closest("[id^='product_']").attr("id");
							var idProduct = strProduct.substring('product_'.length);
							shopProxy.getCart().changeQuantity(idProduct, $(this).val(), function() {
								shopProxy.getCart().list($("#cart").cart().displayCartStep1);
								$("#navi").navigation().fillNaviCartResume();
								});
						});
			
			    			
		    			$("#cart #step1 .removeItem").unbind('click');
		    			$("#cart #step1 .removeItem").click(function () {
		    				var strProduct = $(this).closest("[id^='product_']").attr("id");
		    				var idProduct = strProduct.substring('product_'.length);
		    				shopProxy.getCart().remove( idProduct, function() {
		    					shopProxy.getCart().list($("#cart").cart().displayCartStep1);
		    					$("#navi").navigation().fillNaviCartResume();
		    				});
		    				return false;
		    			});
			    		
		    			$("#cart #step1 .empty").unbind('click');
		    			$("#cart #step1 .empty").click(function () {   //loggato
							$('#cart #step1 .promocode').val('Inserisci qui il tuo codice');
		    				shopProxy.getCart().removeAll( function() {
		    					shopProxy.getCart().list($("#cart").cart().displayCartStep1);
		    					$("#navi").navigation().fillNaviCartResume();
		    				});
		    				return false;
		    			});
			    			
						$("#cart #step1 .promocode").unbind('change');
		    			$("#cart #step1 .promocode").change(function () {
		    				if($(this).val()) {	
			    				shopProxy.getCart().promoCode( $(this).val(), function(promoData) {
			    					
			    					if ( (!isEmptyOrNull(promoData.error)) && (promoData.error == true) ) {
			    						errorpopup(promoData.message);
			    					}
			    					
			    					shopProxy.getCart().list($("#cart").cart().displayCartStep1);
			    					$("#navi").navigation().fillNaviCartResume();
			    				});
		    				}
		    			});
							
		    			$("#cart #step1 .checkout").unbind('click');
		    			$("#cart #step1 .checkout").click(function () {
		    				
			    			checkShippingRules(function() {
		    					if ( isEmptyOrNull($("input[@name='payment']:checked").val()) ) {
		    						errorpopup("Scegli un metodo di pagamento.");
		    						return false;
		    					}
		    					shopProxy.getCart().addPaymentMode($("#cart #step1 input[@name='payment']:checked").val(), function() {
		    						shopProxy.getCart().list($("#cart").cart().displayCartStep2);
		    					});
		    				});
			    			return false;
			    		});

		    			if ( (!isEmptyOrNull(totalAmount)) && (totalAmount > 0) ) {
		    				checkShippingRules();
		    			}
						});
					});
				});
			}
		
  		function _displayCartStep1(data) {
  			$("#tracking").hide();
  			$("#showcase").hide();
  			$("#cart").show();
  			$("#cart #step1").show();
  			$("#cart #step2").hide();
  			$("#cart #step3").hide();

  			var cartData = data;
			
  			shopProxy.getShopTracker().track('carrello');

  			shopProxy.getUser().userLogged(function(userData) {

  				if(!isEmptyOrNull(userData.active) && (userData.active)) {
  					
  					// check if address or shipping address exists and is complete
  					if (!isObjectEmpty(userData.shippingAddress)) {
 
  						if (
	  						(!isEmptyOrNull(userData.shippingAddress.address))
	  						&& (!isEmptyOrNull(userData.shippingAddress.cap)) 
	  						&& (!isEmptyOrNull(userData.shippingAddress.city))
	  						&& (!isEmptyOrNull(userData.shippingAddress.country)) 
							&& ((!isEmptyOrNull(userData.phone)) || (!isEmptyOrNull(userData.mobilePhone))) 
	  						) {
  							displayCartStep1Logged(cartData, userData);
  						} else {
  							window.location = "/it/consumer/vanity-room/common/il-mio-profilo.page?targetURI=/it/consumer/index.page&lang=it&shop=true";
  						}
  					} else {
					
  	  					if (
	  						(!isEmptyOrNull(userData.address)) 
	  						&& (!isEmptyOrNull(userData.address.address))
	  						&& (!isEmptyOrNull(userData.address.cap)) 
	  						&& (!isEmptyOrNull(userData.address.city))
	  						&& (!isEmptyOrNull(userData.address.country)) 
							&& ((!isEmptyOrNull(userData.phone)) || (!isEmptyOrNull(userData.mobilePhone))) 
	  						) {
	  						displayCartStep1Logged(cartData, userData);
	  					} else {
	  						window.location = "/it/consumer/vanity-room/common/il-mio-profilo.page?targetURI=/it/consumer/index.page&lang=it&shop=true";
	  					}
  					}
  					
  				} else {
  					displayCartStep1NotLogged(cartData);
  				}
  				
  			});

  		}
    		
  		this.displayCartStep1 = function (data) {
  			_displayCartStep1(data);
  		}
			
    	function _displayCartStep2(cartData) {
    			
   			$("#cart").show();
    		$("#cart #step1").hide();
   			$("#cart #step2").show();
   			$("#cart #step3").hide();
    			
			shopProxy.getShopTracker().track('riepilogo');
		
    		var pinkDiscount = null;
				var shipCost = null;
				var shipMin = null;
				var totalAmount = cartData.totalAmount;
				var user = null;
				
				shopProxy.getUser().userLogged(function(userData) {

					user = userData;
					
					shopProxy.getCart().pinkDiscount(function(pinkData) {
						
						if (!isEmptyOrNull(pinkData.pinkCardDiscount)) {
							pinkDiscount = pinkData.pinkCardDiscount;
						}
						
						shopProxy.getCart().shipCost(function(shipData) {
							
							if (!isEmptyOrNull(shipData.charges)) {
								shipCost = shipData.charges;
							}
							if (!isEmptyOrNull(shipData.minExpense)) {
								shipMin = shipData.minExpense;
							}
	
							shopProxy.getCart().finalPrice(function(finalData) {
								
				   			$("#cart #step2").empty();	
 
						var shippingAddressAdd2 = !user.shippingAddress.address ? user.address.address : user.shippingAddress.address;
						var shippingCap2 = !user.shippingAddress.cap ? user.address.cap : user.shippingAddress.cap;
						var shippingCity2 = !user.shippingAddress.city ? user.address.city : user.shippingAddress.city;
						var shippingProvince2 = !user.shippingAddress.province ? user.address.province : user.shippingAddress.province;
						var shippingCountry2 = !user.shippingAddress.country ? user.address.country  : user.shippingAddress.country ;
 
 
						    var list = '<div class="basket"><div class="path" style="float: left; width: 400px;"><a href="#" onclick="document.location=document.location.href.split(&#39;#&#39;)[0]; return false">Shop on line</a> &gt; <b>Acquista</b></div><div class="step"><ul><li class="first">1. Carrello</li><li><b>2. Riepilogo ordine</b><li class="last">3. Ordine confermato</li></ul></div><div class="scroll"><table border="0" cellpadding="0" cellspacing="0"><tr class="label"><th>Immagine</th><th>Descrizione</th><th>Quantit&agrave;</th><th>Prezzo</th></tr>';
			    			list = list + '<div class="address"><img src="/consumer/res/shop/img/basket_logo_camomilla.gif" alt="Camomilla" /><b>Camomilla S.P.A.</b> <br />Cap-soc. Euro 2.000.000,00 Int Vers.<br />Sede Legale e Amministrativa<br />Via Bodoni, 8/14 20090 Buccinasco (MI)<br />Tel. 0248840405 - 45700537<br />Fax 0248841725</div><div class="address"><b class="focus">' + user.name + ' ' + user.surname + '</b><br />' + user.address.address + ' - ' + user.address.cap + ' '+  user.address.city + ' ('+ user.address.province +'), ' + user.address.country + '<br />Tel. <b>' + user.phone + '</b><br />E-mail <a href="mailto:' + user.email + '">' + user.email + ' </a><br/><br/><strong>Indirizzo di spedizione</strong><br/>' + shippingAddressAdd2 + ' - ' + shippingCap2 + ' '+  shippingCity2 + ' ('+ shippingProvince2 +'), ' + shippingCountry2 + '';
							if(user.address.notes) {
								list = list + '<br/><br/><strong>Note</strong>: ' +  user.address.notes + '<br /><br />';
							} else {
								list = list + '<br /><br />';
							}
							
			    			if (cartData.paymentType == 'ca') {
			    				list = list + 'Modalit&agrave; di pagamento: contrassegno</div>';
			    			} else if (cartData.paymentType == 'cc') {
			    				list = list + 'Modalit&agrave; di pagamento: carta di credito</div>';
			    			};
								list = list + '<table style="clear: both" border="0" cellpadding="0" cellspacing="0"><tr class="label"><th>Codice</th><th>Descrizione</th><th>Colore</th><th>Quantit&agrave;</th><th>Prezzo Singolo</th><th>Prezzo Totale</th></tr>';

							$.each(cartData.data, function(i,aelement) {
				    			list = list + '<tr id="product_' + aelement.product["kca:id"] + '">';
				    			list = list + '<td>' + aelement.product.code + '</td>';
				    			list = list + '<td><b class="focus">' + aelement.product["name"] + '</b></td>';
									list = list + '<td><span class="color">Colore/variante:' + aelement.product["colour"]["description"] + '</td>';
									list = list + '<td></td>';
				    			list = list + '<td>Quantit&agrave;: ' + aelement.quantity + '</td>';
				    			list = list + '<td>&euro; ' + aelement.product.priceB2C + '</td>';
				    			list = list + '<td>&euro; ' + aelement.totalRow + '</td>';
				    			list = list + '</tr>';
				    		});
 				    		if (pinkDiscount > 0) {
				    			list = list + '<tr><td colspan="4">Sconto <b class="focus">pink card</b></td><td colspan="3" class="right"><span class="focus">&euro; ' + pinkDiscount + '</span></td></tr>';
				    		}
							if (!isEmptyOrNull(cartData.promotionDiscount)) {
								list = list + '<tr><td colspan="4"><b class="focus">Codice promo</b></td><td colspan="3" class="right"><span class="focus">&euro; ' + cartData.promotionDiscount + '</span></td></tr>';
							}
				    			
				    		list = list + '<tr><td colspan="4">Spese di spedizione</td><td colspan="3" class="right"><span class="focus">&euro;' + shipCost + '</span></td></table></div>';
				   			list = list + '<table border="0" cellpadding="0" cellspacing="0"><tr class="noback"><th class="tot">Totale</th><td class="right"><b class="focus">&euro;'  + finalData.finalAmount + '</b></td></tr>';
					 			list = list + '<tr><td colspan="2" class="privacy"><fieldset><input type="checkbox" id="privacycheck"/><label class="lblrc">Autorizzo la societ&agrave; Camomilla Spa al <a href="#" class="trattdati">trattamento dei dati personali</a></label></fieldset><fieldset><input type="checkbox" id="condizionicheck"/><label class="lblrc">Accetto le <a href="#" class="condizioni">condizioni di vendita</a></label></fieldset></td></tr></table><div class="toolbars"> <a class="confirm" href="#view=result" title="conferma acquisto"><img src="/consumer/res/shop/img/basket_btn_conferma_acquisto.gif" alt="conferma acquisto" /></a></div>';
				    			
							$("#cart #step2").append(list);
							
							$("#cart #step2 .trattdati").unbind('click');
							$("#cart #step2 .trattdati").click(function () {
								window.open("/consumer/docs/privacy.html","privacyPopup", "width=800,height=600,status=yes,menubar=yes,scrollbars=yes");
								return false;
							});
							
							$("#cart #step2 .condizioni").unbind('click');
							$("#cart #step2 .condizioni").click(function () {
								window.open("/consumer/docs/condizioni.html","privacyPopup", "width=800,height=600,status=yes,menubar=yes,scrollbars=yes");
								return false;
							});
								
							setScrollHeight();

			    			$("#cart #step2 .confirm").unbind('click');
			    			$("#cart #step2 .confirm").click(function () {
									if(!$("#privacycheck").get(0).checked) {
										errorpopup("Attenzione: è necessario autorizzare la società Camomilla Spa al trattamento dei dati personali");
										return false;
									};
									if(!$("#condizionicheck").get(0).checked) {
										errorpopup("Attenzione: è necessario accettare le condizioni di vendita");
										return false;
									}
								
				    			if (cartData.paymentType == 'ca') {
				    	 			shopProxy.getCart().orderByCash(function(orderData) { _displayCartStep3(orderData.codTrans); });
				    			} else if (cartData.paymentType == 'cc') {
				    				shopProxy.getCart().orderByCard();
				    			}
				    				
				    			return false;
				    		});
				    		
							});
						});
					});
				});
    	}
    		
  		this.displayCartStep2 = function (data) {
  			_displayCartStep2(data);
  		}
			
			function displayCartStep3Result(orderData) {
			
				shopProxy.getShopTracker().track('conferma');
				
				var pinkDiscount = null;
				var shipCost = null;
				var shipMin = null;
				var totalAmount = null;
				var user = null;

				$("#cart #step3").empty();	
					
				var shippingAddressAdd = !orderData.order.shippingAddress["address"] ? orderData.order.address["address"] : orderData.order.shippingAddress["address"];
				var shippingCap = !orderData.order.shippingAddress["cap"] ? orderData.order.address["cap"] : orderData.order.shippingAddress["cap"];
				var shippingCity = !orderData.order.shippingAddress["city"] ? orderData.order.address["city"] : orderData.order.shippingAddress["city"];
				var shippingProvince = !orderData.order.shippingAddress["province"] ? orderData.order.address["province"] : orderData.order.shippingAddress["province"];
				var shippingCountry = !orderData.order.shippingAddress["country"] ? orderData.order.address["country"] : orderData.order.shippingAddress["country"];

    		var list = '<div class="basket"><div class="path"><a href="#" onclick="document.location=document.location.href.split(&#39;#&#39;)[0]; return false">Shop on line</a> &gt; <b>Acquista</b></div><div class="step"><ul><li class="first">1. Carrello</li><li>2. Riepilogo ordine</li><li class="last"><b>3. Ordine confermato</b></li></ul></div><div class="scroll">';
    		list = list + '<p><b class="focus">Gentile ' + orderData.order.name + ' ' + orderData.order.surname + '</b>,<br />grazie per aver scelto il nostro Shop On Line. Il tuo ordine &egrave; stato registrato con successo.<br /> Ti &egrave; stata inviata una mail al tuo indirizzo di posta elettronica contenente il riepilogo dell&#39;ordine.<br /><br /></p><p class="address"><img src="/consumer/res/shop/img/basket_logo_camomilla.gif" alt="Camomilla" /><b>Camomilla S.P.A.</b> <br />Cap-soc. Euro 2.000.000,00 Int Vers.<br />Sede Legale e Amministrativa<br />Via Bodoni, 8/14 20090 Buccinasco (MI)<br />Tel. 0248840405 - 45700537<br />Fax 0248841725</p><p class="address"><b class="focus">DATI ACQUIRENTE</b><br/><b>'+ orderData.order.name + ' ' +orderData.order.surname + '</b><br />'+ orderData.order.address["address"] + ' - ' + orderData.order.address["cap"] + ' - '+   orderData.order.address["city"] + ' ('+ orderData.order.address["province"] +'), ' + orderData.order.address["country"]+ '<br /><br/><b class="focus">DATI SPEDIZIONE</b><br />'+ shippingAddressAdd + ' - ' + shippingCap + ' - '+   shippingCity + ' ('+ shippingProvince +'), ' + shippingCountry + '<br />';
				if(orderData.order.address["notes"]) {
					list = list + '<strong>Note</strong>: ' + orderData.order.address["notes"] + '<br/><br/>';
				} else {
					list = list + '<br/>';
				};
			
				if (orderData.order.paymentType == 'ca') {
					list = list + 'Modalit&agrave; di pagamento: <b>contrassegno</b></p>';
				} else if (orderData.order.paymentType == 'cc') {
					list = list + 'Modalit&agrave; di pagamento: <b>carta di credito</b></p>';
				}
				list = list + '<div class="clear"></div><table border="0" cellpadding="0" cellspacing="0"><caption>N&deg; Ordine <b>' + orderData.order.code + '</b> del <b> ' + orderData.order.date + '</b></caption><tr class="label"><th>Codice</th><th>Descrizione</th><th>Colore/variante</th><th>Quantit&agrave;</th><th>Prezzo Singolo</th><th>Prezzo Totale</th></tr>';
				
				pageTracker._addTrans(
				   orderData.order.code ,           // order ID - required
				   '', // affiliation or store name
				   orderData.order.totalAmount ,          // total - required
				   ' ',           // tax
				   orderData.order.shippingCharges,          // shipping
				   orderData.order.address["city"] ,       // city
				   orderData.order.address["province"],     // state or province
				   orderData.order.address["country"]             // country
				);



				list = list + '<ul>';
				$.each(orderData.rows, function(i,aelement) {
					list = list + '<tr id="product_' + aelement.product["kca:id"] + '">';
					list = list + '<td>' + aelement.product.code + '</td>';
					list = list + '<td><b class="focus">' + aelement.product["name"] + '</b></td>';
					list = list + '<td> </td>';
					list = list + '<td>Quantit&agrave;: ' + aelement.quantity + '</td>';
					list = list + '<td>Prezzo: &euro; ' + aelement.product.priceB2C + '</td>';
					list = list + '<td>Totale: &euro; ' + aelement.totalRow + '</td>';
					list = list + '</tr>';
					pageTracker._addItem(
					   aelement.product["kca:id"],           // order ID - necessary to associate item with transaction
					   aelement.product.code,           // SKU/code - required
					   aelement.product["name"] ,        // product name
					   '',   // category or variation
					   aelement.product.priceB2C,          // unit price - required
					   aelement.quantity               // quantity - required
					);

					pageTracker._trackTrans();
			
			});
     		
     		if (pinkDiscount > 0) {
					list = list + '<tr><td colspan="4">Sconto Pink Card <b class="focus">pink card</b></td><td colspan="3" class="right"><span class="focus">&euro; ' + orderData.order.discountPK + '</span></td></tr>';
				}
				
//			list = list + '<p>codice promo </p>';
 				list = list + '<tr><td colspan="4">Spese di spedizione</td><td colspan="3" class="right"><span class="focus">&euro;' + orderData.order.shippingCharges + '</span></td></table></div>';
				list = list + '<table border="0" cellpadding="0" cellspacing="0"><tr class="noback"><th class="tot">Totale</th><td class="right"><b class="focus">&euro;'  + orderData.order.totalAmount + '</b></td></tr></table>';
				list = list + '<div class="toolbars"><a class="print" href="#view=result" title="stampa ordine"><img src="/consumer/res/shop/img/basket_btn_stampa_ordine.gif" alt="stampa ordine" /></a></div></div>';

				$("#cart #step3").append(list);
				
				setScrollHeight();

  			$("#cart #step3 .print").unbind('click');
  			$("#cart #step3 .print").click(function () {
					window.open ("shop-online-print.page?codTrans=" + orderData.order.transactionCode,"printOrder","status=1"); 
  				return false;
    		});
			}

			function displayCartStep3Error(codError) {
			
				shopProxy.getShopTracker().track('conferma');

				$("#cart #step3").empty();
				
				$("#cart #step3").append('<p id="erroretrs">Errore nella transazione.</p>');
				
			}
					
  		function _displayCartStep3(codTrans, codError) {
  			
  			$("#cart").show();
  			$("#cart #step1").hide();
  			$("#cart #step2").hide();
  			$("#cart #step3").show();

				if (!isEmptyOrNull(codError)) {
					displayCartStep3Error(codError);
				} else {
					shopProxy.getCart().showResult(codTrans, function(orderData) {
  					displayCartStep3Result(orderData);
  				});
				}

  		}
  		
  		this.displayCartStep3 = function (codTrans, codError) {
  			_displayCartStep3(codTrans, codError);
  		}
  		
  		this.displayCartStep2 = function (data) {
  			_displayCartStep2(data);
  		}

			function checkShippingRules(okCallback) {
			
				var result = true;
				shopProxy.getCart().rules( function(data) {
					
					if (data.underMinExpLimit) {
						errorpopup("Attenzione: L'importo minimo di spesa è di 25 euro, non comprensivo delle spese di spedizione.");
						result = false;
					}
					
					if (data.sanrioForeignAddress) {
						errorpopup("<p class='prodottilicence'>Attenzione: I prodotti Hello Kitty - Sanrio e Hello Kitty Licence non possono essere spediti all'estero: per completare l'ordine modifica l'indirizzo di spedizione o rimuovi quei prodotti dal carrello.</p>");
						result = false;
					}
					
					if (!isEmptyOrNull(okCallback)) {
						if (result) {
							okCallback();
						}
					}
				});
				
			}
			
    	setup();
    		
    	return this;
		}
	});
	
})(jQuery); 