﻿//=====================================================================||
//               NOP Design JavaScript Shopping Cart                   ||
//                                                                     ||
// For more information on SmartSystems, or how NOPDesign can help you ||
// Please visit us on the WWW at http://www.nopdesign.com              ||
//                                                                     ||
// Javascript portions of this shopping cart software are available as ||
// freeware from NOP Design.  You must keep this comment unchanged in  ||
// your code.  For more information contact FreeCart@NopDesign.com.    ||
//                                                                     ||
// JavaScript Shop Module, V.4.4.0                                     ||
//=====================================================================||

//---------------------------------------------------------------------||
//                       Global Options                                ||
//                      ----------------                               ||
// Shopping Cart Options, you can modify these options to change the   ||
// the way the cart functions.                                         ||
//                                                                     ||
// Language Packs                                                      ||
// ==============                                                      ||
// You may include any language pack before nopcart.js in your HTML    ||
// pages to change the language.  Simply include a language pack with  ||
// a script src BEFORE the <SCRIPT SRC="nopcart.js">... line.          ||
//  For example: <SCRIPT SRC="language-it.js"></SCRIPT>                ||
//                                                                     ||
// Options For Everyone:                                               ||
// =====================                                               ||
// * MonetarySymbol: string, the symbol which represents dollars/euro, ||
//   in your locale.                                                   ||
// * DisplayNotice: true/false, controls whether the user is provided  ||
//   with a popup letting them know their product is added to the cart ||
// * DisplayShippingColumn: true/false, controls whether the managecart||
//   and checkout pages display shipping cost column.                  ||
// * DisplayShippingRow: true/false, controls whether the managecart   ||
//   and checkout pages display shipping cost total row.               ||
// * DisplayTaxRow: true/false, controls whether the managecart        ||
//   and checkout pages display tax cost total row.                    ||
// * TaxRate: number, your area's current tax rate, ie: if your tax    ||
//   rate was 7.5%, you would set TaxRate = 0.075                      ||
// * TaxByRegion: true/false, when set to true, the user is prompted   ||
//   with TaxablePrompt to determine if they should be charged tax.    ||
//   In the USA, this is useful to charge tax to those people who live ||
//   in a particular state, but no one else.                           ||
// * TaxPrompt: string, popup message if user has not selected either  ||
//   taxable or nontaxable when TaxByRegion is set to true.            ||
// * TaxablePrompt: string, the message the user is prompted with to   ||
//   select if they are taxable.  If TaxByRegion is set to false, this ||
//   has no effect. Example: 'Arizona Residents'                       ||
// * NonTaxablePrompt: string, same as above, but the choice for non-  ||
//   taxable people.  Example: 'Other States'                          ||
// * MinimumOrder: number, the minium dollar amount that must be       ||
//   purchased before a user is allowed to checkout.  Set to 0.00      ||
//   to disable.                                                       ||
// * MinimumOrderPrompt: string, Message to prompt users with when     ||
//   they have not met the minimum order amount.                       ||
//                                                                     ||
// Payment Processor Options:                                          ||
// ==========================                                          ||
// * PaymentProcessor: string, the two digit payment processor code    ||
//   for support payment processor gateways.  Setting this field to    ||
//   anything other than an empty string will override your OutputItem ||
//   settings -- so please be careful when receiving any form data.    ||
//   Support payment processor gateways are:                           ||
//    * Authorize.net (an)                                             ||
//    * Worldpay      (wp)                                             ||
//    * LinkPoint     (lp)
//                                                                     ||
// Options For Programmers:                                            ||
// ========================                                            ||
// * OutputItem<..>: string, the name of the pair value passed at      ||
//   checkouttime.  Change these only if you are connecting to a CGI   ||
//   script and need other field names, or are using a secure service  ||
//   that requires specific field names.                               ||
// * AppendItemNumToOutput: true/false, if set to true, the number of  ||
//   each ordered item will be appended to the output string.  For     ||
//   example if OutputItemId is 'ID_' and this is set to true, the     ||
//   output field name will be 'ID_1', 'ID_2' ... for each item.       ||
// * HiddenFieldsToCheckout: true/false, if set to true, hidden fields ||
//   for the cart items will be passed TO the checkout page, from the  ||
//   ManageCart page.  This is set to true for CGI/PHP/Script based    ||
//   checkout pages, but should be left false if you are using an      ||
//   HTML/Javascript Checkout Page. Hidden fields will ALWAYS be       ||
//   passed FROM the checkout page to the Checkout CGI/PHP/ASP/Script  ||
//---------------------------------------------------------------------||

//onclose script:
var linkClicked = false;
var UNLOAD_MSG = "ATTENZIONE! ATTENZIONE! ATTENZIONE! ATTENZIONE! ATTENZIONE! ATTENZIONE!";
UNLOAD_MSG += "\n\n";
UNLOAD_MSG += "Non hai salvato il preventivo e perderai i dati delle modifiche fatte.";
UNLOAD_MSG += "\n";
UNLOAD_MSG += "Annulla e scegli l'opzione 'salva preventivo' per memorizzarlo in modo da poterlo riutilizzare in futuro.";
UNLOAD_MSG += "\n\n";
UNLOAD_MSG += "Premi OK per ignorare questo avviso";
UNLOAD_MSG += "\n";
UNLOAD_MSG += "premi Annulla per rimanere in questa pagina.";
var IGNORE_UNLOAD = true

//Options for Everyone:
MonetarySymbol        = '€';
DisplayNotice         = false;
DisplayShippingColumn = false;
DisplayPriceColumn	  = true;	 
DisplayShippingRow    = true; 
DisplayTaxRow         = false; 
TaxRate               = 0;//0.20;
TaxByRegion           = false;
TaxPrompt             = 'For tax purposes, please select if you are an Arizona resident before continuing';
TaxablePrompt         = 'Arizona Residents';
NonTaxablePrompt      = 'Other States';
MinimumOrder          = 50.00;
MinimumOrderPrompt    = "Attenzione, l&quot;ordine minimo è di 50 euro.";
coming_from_preventivi = false;
add_silently = false;

//Payment Processor Options:
PaymentProcessor      = '';

//Options for Programmers:
discounts = "";
OutputItemId          = 'ID_';
OutputItemQuantity    = 'QUANTITY_';
OutputItemPrice       = 'PRICE_';
OutputItemName        = 'NAME_';
OutputItemShipping    = 'SHIPPING_';
OutputItemAddtlInfo   = 'ADDTLINFO_';
OutputOrderDiscount   = "SCONTO";
OutputOrderDiscountCaption = "SCONTOCAPTION";

OutputOrderSubtotal   = 'SUBTOTAL';
OutputOrderShipping   = 'SHIPPING';
OutputOrderTax        = 'TAX';
OutputOrderTotal      = 'TOTAL';
AppendItemNumToOutput = true;
HiddenFieldsToCheckout = false; //dan

// Variables for discounts
Discount_GLOBAL = 0;
Discount_GLOBAL_2 = 0;
Discount_GLOBAL_3 = 0;

Discount_LEX = false;
Discount_OKKIO_basic = false;
Discount_OKKIO_basic_DF = false;

Discount_OKKIO_PRO = false;
Discount_OKKIO_PRO_DF = false;

Discount_ECONOMY = false;

Discount_LXDM1  = 0;
Discount_LXFS4V3  = 0;
Discount_LXFS4 = 0; 
Discount_LXAL8L = 0;
Discount_LXAL8 = 0;
Discount_ECSIR  = 0;
Discount_RETE = 0;
Discount_WLSIR = 0;

Discount_SIRNB = 0;
Discount_PROSIR = 0;

Discount_ACCMOD = 0;
Discount_CONFIG_PERSONAL = 0;

Discount_WLRIP = 0;
Discount_GSMFWT =0;
Discount_ST101 =0;
Discount_ROLLER = 0;

Discount_MOBEYE = 0;

KIT_COMPLETO2012 = false;

var g_TotalCost = 0;

break_mobeye2rows = false;
break_mobeye2rows_price1 = 0;
break_mobeye2rows_price1 = 0;

Discount_diecimila = false;
Discount_3hours = false;
Discount_diecimila_to_substract = 0;

DISCOUNT_DF = false;
Discount_DF_sconto = 0;

OffertonaGift = false;
offerta20jul = false;
offerta2012 = false;
offerta2012YB = false;

offertona_prod_id  = "";
offertona_prod_name = "";

Discount_main_panel_in_cart = false;
Discount_KIT_in_cart = false;

gifttext = "";

diff_products = 0;
putMegaCookie = true;
show_MyCentrale = false;

//=====================================================================||
//---------------------------------------------------------------------||
//    YOU DO NOT NEED TO MAKE ANY MODIFICATIONS BELOW THIS LINE        ||
//---------------------------------------------------------------------||
//=====================================================================||


//---------------------------------------------------------------------||
//                      Language Strings                               ||
//                     ------------------                              ||
// These strings will not be used unless you have not included a       ||
// language pack already.  You should NOT modify these, but instead    ||
// modify the strings in language-**.js where ** is the language pack  ||
// you are using.                                                      ||
//---------------------------------------------------------------------||
if ( !bLanguageDefined ) {
   strSorry  = "I'm Sorry, your cart is full, please proceed to checkout.";
   strAdded  = " added to your shopping cart.";
   strRemove = "Click 'Ok' to remove this product from your shopping cart.";
   strILabel = "Product Id";
   strDLabel = "Product Name/Description";
   strQLabel = "Quantity";
   strPLabel = "Price";
   strSLabel = "Shipping";
   strRLabel = "Remove From Cart";
   strRButton= "Remove";
   strSUB    = "SUBTOTAL";
   
   strSHIP   = "SHIPPING";
   strTAX    = "TAX";
   strTOT    = "TOTAL";
   strErrQty = "Invalid Quantity.";
   strNewQty = 'Please enter new quantity:';
   bLanguageDefined = true;
}

//---------------------------------------------------------------------||
// FUNCTION Discount_Percent 										   ||	
// PURPOSE: a  is what percent of b ... 						       ||
//---------------------------------------------------------------------||

function Discount_Percent(a,b) {
 //a = document.form1.c.value;
// b = document.form1.d.value;
 c = a/b;
 d = c*100;
 return  " " + Math.round(d) + "%";
 }

//---------------------------------------------------------------------||
// FUNCTION readCookie 												   ||	
// PURPOSE:     for discount									       ||
//---------------------------------------------------------------------||

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

//---------------------------------------------------------------------||
// FUNCTION:    CKquantity                                             ||
// PARAMETERS:  Quantity to                                            ||
// RETURNS:     Quantity as a number, and possible alert               ||
// PURPOSE:     Make sure quantity is represented as a number          ||
//---------------------------------------------------------------------||
function CKquantity(checkString) {
   var strNewQuantity = "";

   for ( i = 0; i < checkString.length; i++ ) {
      ch = checkString.substring(i, i+1);
      if ( (ch >= "0" && ch <= "9") || (ch == '.') )
         strNewQuantity += ch;
   }

   if ( strNewQuantity.length < 1 )
      strNewQuantity = "1";

   return(strNewQuantity);
}

function AddToCartMobEye(thisForm) {
	AddToCart(thisForm);
	
	if (coming_from_preventivi == true)
	{
		window.location = "managecart-wiz2.asp";
	}
	else
	{
		window.location = "managecart.asp";
	}
}


function AddToCartPROFCAMX(thisForm) {
	AddToCart(thisForm);
	window.location = "managecart.asp";
}


function AddToCartGift(thisForm) {

   var iNumberOrdered = 0;
   var bAlreadyInCart = false;
   var notice = "";
   iNumberOrdered = GetCookie("NumberOrdered");
   
  // if (readCookie('preventivi_wiz') == "true") { coming_from_preventivi = true; }

   if ( iNumberOrdered == null )
      iNumberOrdered = 0;

      strID_NUM    = "Omaggio";
      strQUANTITY  = "1";
      strPRICE     = thisForm.PRICE.value;
      strNAME      = thisForm.NAME.value;
      strSHIPPING  = "9.00";

   if ( thisForm.ADDITIONALINFO == null ) {
      strADDTLINFO = "";
   } else {
      strADDTLINFO = thisForm.ADDITIONALINFO[thisForm.ADDITIONALINFO.selectedIndex].value;
   }
   if ( thisForm.ADDITIONALINFO2 != null ) {
      strADDTLINFO += "; " + thisForm.ADDITIONALINFO2[thisForm.ADDITIONALINFO2.selectedIndex].value;
   }
   if ( thisForm.ADDITIONALINFO3 != null ) {
      strADDTLINFO += "; " + thisForm.ADDITIONALINFO3[thisForm.ADDITIONALINFO3.selectedIndex].value;
   }
   if ( thisForm.ADDITIONALINFO4 != null ) {
      strADDTLINFO += "; " + thisForm.ADDITIONALINFO4[thisForm.ADDITIONALINFO4.selectedIndex].value;
   }

   //Is this product already in the cart?  If so, increment quantity instead of adding another.
   for ( i = 1; i <= iNumberOrdered; i++ ) {
      NewOrder = "Order." + i;
      database = "";
      database = GetCookie(NewOrder);

      Token0 = database.indexOf("|", 0);
      Token1 = database.indexOf("|", Token0+1);
      Token2 = database.indexOf("|", Token1+1);
      Token3 = database.indexOf("|", Token2+1);
      Token4 = database.indexOf("|", Token3+1);

      fields = new Array;
      fields[0] = database.substring( 0, Token0 );
      fields[1] = database.substring( Token0+1, Token1 );
      fields[2] = database.substring( Token1+1, Token2 );
      fields[3] = database.substring( Token2+1, Token3 );
      fields[4] = database.substring( Token3+1, Token4 );
      fields[5] = database.substring( Token4+1, database.length );

      if ( fields[0] == strID_NUM ) {
         bAlreadyInCart = true;
         dbUpdatedOrder = strID_NUM    + "|" +
                          "1" + "|" +
                          strPRICE     + "|" +
                          strNAME      + "|" +
                          strSHIPPING;
         strNewOrder = "Order." + i;
         DeleteCookie(strNewOrder, "/");
         SetCookie(strNewOrder, dbUpdatedOrder, null, "/");
         //notice = strQUANTITY + " " + strNAME + strAdded;
         break;
      }
   }


   if ( !bAlreadyInCart ) {
      iNumberOrdered++;

      if ( iNumberOrdered > 20 )
         alert( strSorry );
      else {
         dbUpdatedOrder = strID_NUM    + "|" + 
                          strQUANTITY  + "|" +
                          strPRICE     + "|" +
                          strNAME      + "|" +
                          strSHIPPING  + "|" +
                          strADDTLINFO;

         strNewOrder = "Order." + iNumberOrdered;
         SetCookie(strNewOrder, dbUpdatedOrder, null, "/");
         SetCookie("NumberOrdered", iNumberOrdered, null, "/");
         //notice = strQUANTITY + " " + strNAME + strAdded;
      }
   }

/*	if (coming_from_preventivi == true)
	{
		window.location = "checkout-wiz2.asp";
	}
	else
	{
		window.location = "checkout.asp";
	}
*/
}


function AddToCartAmico(thisForm) {

   var iNumberOrdered = 0;
   var bAlreadyInCart = false;
   var notice = "";
   iNumberOrdered = GetCookie("NumberOrdered");
   
  // if (readCookie('preventivi_wiz') == "true") { coming_from_preventivi = true; }

   if ( iNumberOrdered == null )
      iNumberOrdered = 0;

      strID_NUM    = "AMICO";
      strQUANTITY  = "1";
      strPRICE     = thisForm.PRICE.value;
      strNAME      = thisForm.NAME.value;
      strSHIPPING  = "9.00";

   if ( thisForm.ADDITIONALINFO == null ) {
      strADDTLINFO = "";
   } else {
      strADDTLINFO = thisForm.ADDITIONALINFO[thisForm.ADDITIONALINFO.selectedIndex].value;
   }
   if ( thisForm.ADDITIONALINFO2 != null ) {
      strADDTLINFO += "; " + thisForm.ADDITIONALINFO2[thisForm.ADDITIONALINFO2.selectedIndex].value;
   }
   if ( thisForm.ADDITIONALINFO3 != null ) {
      strADDTLINFO += "; " + thisForm.ADDITIONALINFO3[thisForm.ADDITIONALINFO3.selectedIndex].value;
   }
   if ( thisForm.ADDITIONALINFO4 != null ) {
      strADDTLINFO += "; " + thisForm.ADDITIONALINFO4[thisForm.ADDITIONALINFO4.selectedIndex].value;
   }

   //Is this product already in the cart?  If so, increment quantity instead of adding another.
   for ( i = 1; i <= iNumberOrdered; i++ ) {
      NewOrder = "Order." + i;
      database = "";
      database = GetCookie(NewOrder);

      Token0 = database.indexOf("|", 0);
      Token1 = database.indexOf("|", Token0+1);
      Token2 = database.indexOf("|", Token1+1);
      Token3 = database.indexOf("|", Token2+1);
      Token4 = database.indexOf("|", Token3+1);

      fields = new Array;
      fields[0] = database.substring( 0, Token0 );
      fields[1] = database.substring( Token0+1, Token1 );
      fields[2] = database.substring( Token1+1, Token2 );
      fields[3] = database.substring( Token2+1, Token3 );
      fields[4] = database.substring( Token3+1, Token4 );
      fields[5] = database.substring( Token4+1, database.length );

      if ( fields[0] == strID_NUM ) {
         bAlreadyInCart = true;
         dbUpdatedOrder = strID_NUM    + "|" +
                          "1" + "|" +
                          strPRICE     + "|" +
                          strNAME      + "|" +
                          strSHIPPING;
         strNewOrder = "Order." + i;
         DeleteCookie(strNewOrder, "/");
         SetCookie(strNewOrder, dbUpdatedOrder, null, "/");
         //notice = strQUANTITY + " " + strNAME + strAdded;
         break;
      }
   }


   if ( !bAlreadyInCart ) {
      iNumberOrdered++;

      if ( iNumberOrdered > 20 )
         alert( strSorry );
      else {
         dbUpdatedOrder = strID_NUM    + "|" + 
                          strQUANTITY  + "|" +
                          strPRICE     + "|" +
                          strNAME      + "|" +
                          strSHIPPING  + "|" +
                          strADDTLINFO;

         strNewOrder = "Order." + iNumberOrdered;
         SetCookie(strNewOrder, dbUpdatedOrder, null, "/");
         SetCookie("NumberOrdered", iNumberOrdered, null, "/");
         //notice = strQUANTITY + " " + strNAME + strAdded;
      }
   }
   
   
   
   
    SetCookie('enhanceamico-type', thisForm.TYPE.value, '', '/', '', '' );
    SetCookie('enhanceamico-name', thisForm.NAME.value, '', '/', '', '' );;

	window.location = "form-order2-amico.asp";
	

/*	if (coming_from_preventivi == true)
	{
		window.location = "checkout-wiz2.asp";
	}
	else
	{
		window.location = "checkout.asp";
	}
*/
}


function AddToCartKitSensorsColor(thisForm) {

   var iNumberOrdered = 0;
   var bAlreadyInCart = false;
   var notice = "";
   iNumberOrdered = GetCookie("NumberOrdered");

   if ( iNumberOrdered == null )
      iNumberOrdered = 0;

      strID_NUM    = thisForm.ID_NUM.value;
      strQUANTITY  = "4";
      strNAME      = thisForm.NAME.value;
      
      if (strNAME == "Sensore porte, finestre e tapparelle WHITE" )
      {
	      strPRICE     = "0";
      }
      else
      {
          strPRICE     = "5";
      }

      strSHIPPING  = "9.00";

   if ( thisForm.ADDITIONALINFO == null ) {
      strADDTLINFO = "";
   } else {
      strADDTLINFO = thisForm.ADDITIONALINFO[thisForm.ADDITIONALINFO.selectedIndex].value;
   }
   if ( thisForm.ADDITIONALINFO2 != null ) {
      strADDTLINFO += "; " + thisForm.ADDITIONALINFO2[thisForm.ADDITIONALINFO2.selectedIndex].value;
   }
   if ( thisForm.ADDITIONALINFO3 != null ) {
      strADDTLINFO += "; " + thisForm.ADDITIONALINFO3[thisForm.ADDITIONALINFO3.selectedIndex].value;
   }
   if ( thisForm.ADDITIONALINFO4 != null ) {
      strADDTLINFO += "; " + thisForm.ADDITIONALINFO4[thisForm.ADDITIONALINFO4.selectedIndex].value;
   }



   if ( !bAlreadyInCart ) {
      iNumberOrdered++;

      if ( iNumberOrdered > 20 )
         alert( strSorry );
      else {
         dbUpdatedOrder = strID_NUM    + "|" + 
                          strQUANTITY  + "|" +
                          strPRICE     + "|" +
                          strNAME      + "|" +
                          strSHIPPING  + "|" +
                          strADDTLINFO;

         strNewOrder = "Order." + iNumberOrdered;
         SetCookie(strNewOrder, dbUpdatedOrder, null, "/");
         SetCookie("NumberOrdered", iNumberOrdered, null, "/");
         //notice = strQUANTITY + " " + strNAME + strAdded;
      }
   }


	window.location = "http://www.sicurezza.pro/cart/htdocs/managecart.asp";

}

//---------------------------------------------------------------------||
// FUNCTION:    MultiAddToCart										   ||
// PARAMETERS:  Form Object                                            ||
// RETURNS:     Cookie to user's browser, with prompt                  ||
// PURPOSE:     Adds a product to the user's shopping cart             ||
//---------------------------------------------------------------------||
function MultiAddToCart(a,b,c,d,e,f,g) {
   var iNumberOrdered = 0;
   var bAlreadyInCart = false;
   var notice = "";
   iNumberOrdered = GetCookie("NumberOrdered");

   if ( iNumberOrdered == null )
      iNumberOrdered = 0;


      strID_NUM    = a;

      strQUANTITY  = b;


     strPRICE     = c;

      if (a == "LEXHS5-2012")
     {

      	strNAME      =  d + 
      						"  <br><br>+ Telecomando di chiamata aiuto Salva la vita"+
							"<br>+ 1 Adattatore di tensione (alimentatore)"+
							"<br>+ Manuali cartacei in italiano, certificazione CE (RTT&E, BT, EMC)"+
							"<br>+ 2 Anni di garanzia italiana diretta"+
							"<br>+ Consulenza per l'installazione su numero verde gratuito"+
							"<br>+ Copertura RC-prodotti di Unipol assicurazioni"+
							"<br>+ Batterie, cavetto telefonico e minuterie inclusi"+
							"<br>+ Istruzioni per la realizzazione fai da te del ripetitore visivo di stato";

      }
      else if (a == "OKKIO_basic" || a == "OKKIO_PRO")
      {
      	strNAME      =  d +
      					    "  <br><br>+ 1 Adattatore di tensione (alimentatore)"+
							"<br>+ Manuali cartacei in italiano, certificazione CE (RTT&E, BT, EMC)"+
							"<br>+ 2 Anni di garanzia italiana diretta"+
							"<br>+ Consulenza per l'installazione su numero verde gratuito"+
							"<br>+ Copertura RC-prodotti di Unipol assicurazioni"+
							"<br>+ Batterie, cavetto telefonico e minuterie inclusi"+
							"<br>+ Istruzioni per la realizzazione fai da te del ripetitore visivo di stato";
      }
      else if (a == "ECONOMY")
      {
      	strNAME      =  d +
      					    "  <br><br>+ modulo interno di espansione funzioni avanzate"+
							"<br>+ combinatore telefonico per linea fissa (no VOIP) integrato"+
							"<br>+ sirena interna integrata"+
							"<br>+ Manuali cartacei in italiano, certificazione CE (RTT&E, BT, EMC)."+
							"<br>+ 2 Anni di garanzia italiana diretta"+
							"<br>+ Consulenza per l'installazione su numero verde gratuito"+
							"<br>+ Copertura RC-prodotti di Unipol assicurazioni"+
							"<br>+ Batteria tampone, cavetto telefonico e minuterie inclusi";

      }
      

	  else
	  {
	  	strNAME      = d;
	  }

      strSHIPPING  = "9.00";

      strADDTLINFO = "prev-wizard";
   

   //Is this product already in the cart?  If so, increment quantity instead of adding another.
   for ( i = 1; i <= iNumberOrdered; i++ ) {
      NewOrder = "Order." + i;
      database = "";
      database = GetCookie(NewOrder);

      Token0 = database.indexOf("|", 0);
      Token1 = database.indexOf("|", Token0+1);
      Token2 = database.indexOf("|", Token1+1);
      Token3 = database.indexOf("|", Token2+1);
      Token4 = database.indexOf("|", Token3+1);

      fields = new Array;
      fields[0] = database.substring( 0, Token0 );
      fields[1] = database.substring( Token0+1, Token1 );
      fields[2] = database.substring( Token1+1, Token2 );
      fields[3] = database.substring( Token2+1, Token3 );
      fields[4] = database.substring( Token3+1, Token4 );
      fields[5] = database.substring( Token4+1, database.length );

      if ( fields[0] == strID_NUM &&
           fields[2] == strPRICE  &&
           fields[3] == strNAME   &&
           fields[5] == strADDTLINFO
         ) {
         bAlreadyInCart = true;
         dbUpdatedOrder = strID_NUM    + "|" +
                          (parseInt(strQUANTITY)+parseInt(fields[1]))  + "|" +
                          strPRICE     + "|" +
                          strNAME      + "|" +
                          strSHIPPING  + "|" +
                          strADDTLINFO;
         strNewOrder = "Order." + i;
         DeleteCookie(strNewOrder, "/");
         SetCookie(strNewOrder, dbUpdatedOrder, null, "/");
         notice = strQUANTITY + " " + strNAME + strAdded;
         break;
      }
   }


   if ( !bAlreadyInCart ) {
      iNumberOrdered++;

      if ( iNumberOrdered > 20 )
         alert( strSorry );
      else {
         dbUpdatedOrder = strID_NUM    + "|" + 
                          strQUANTITY  + "|" +
                          strPRICE     + "|" +
                          strNAME      + "|" +
                          strSHIPPING  + "|" +
                          strADDTLINFO;

         strNewOrder = "Order." + iNumberOrdered;
         SetCookie(strNewOrder, dbUpdatedOrder, null, "/");
         SetCookie("NumberOrdered", iNumberOrdered, null, "/");
         notice = strQUANTITY + " " + strNAME + strAdded;
      }
   }



	
   if ( DisplayNotice )
      alert(notice);
}


//---------------------------------------------------------------------||
// FUNCTION:    AddToCart                                              ||
// PARAMETERS:  Form Object                                            ||
// RETURNS:     Cookie to user's browser, with prompt                  ||
// PURPOSE:     Adds a product to the user's shopping cart             ||
//---------------------------------------------------------------------||
function AddToCart(thisForm) {
   var iNumberOrdered = 0;
   var bAlreadyInCart = false;
   var notice = "";
   iNumberOrdered = GetCookie("NumberOrdered");

   if ( iNumberOrdered == null )
      iNumberOrdered = 0;

   if ( thisForm.ID_NUM == null )
      strID_NUM    = "";
   else
      strID_NUM    = thisForm.ID_NUM.value;

   if ( thisForm.QUANTITY == null )
      strQUANTITY  = "1";
   else
      strQUANTITY  = thisForm.QUANTITY.value;

   if ( thisForm.PRICE == null )
      strPRICE     = "0.00";
   else
      strPRICE     = thisForm.PRICE.value;

   if ( thisForm.NAME == null )
      strNAME      = "";
   else
      strNAME      = thisForm.NAME.value;

 //  if ( thisForm.SHIPPING == null )
      strSHIPPING  = "9.00";
//   else
 //     strSHIPPING  = thisForm.SHIPPING.value;

   if ( thisForm.ADDITIONALINFO == null ) {
      strADDTLINFO = "";
   } else {
      strADDTLINFO = thisForm.ADDITIONALINFO[thisForm.ADDITIONALINFO.selectedIndex].value;
   }
   if ( thisForm.ADDITIONALINFO2 != null ) {
      strADDTLINFO += "; " + thisForm.ADDITIONALINFO2[thisForm.ADDITIONALINFO2.selectedIndex].value;
   }
   if ( thisForm.ADDITIONALINFO3 != null ) {
      strADDTLINFO += "; " + thisForm.ADDITIONALINFO3[thisForm.ADDITIONALINFO3.selectedIndex].value;
   }
   if ( thisForm.ADDITIONALINFO4 != null ) {
      strADDTLINFO += "; " + thisForm.ADDITIONALINFO4[thisForm.ADDITIONALINFO4.selectedIndex].value;
   }

   //Is this product already in the cart?  If so, increment quantity instead of adding another.
   for ( i = 1; i <= iNumberOrdered; i++ ) {
      NewOrder = "Order." + i;
      database = "";
      database = GetCookie(NewOrder);

      Token0 = database.indexOf("|", 0);
      Token1 = database.indexOf("|", Token0+1);
      Token2 = database.indexOf("|", Token1+1);
      Token3 = database.indexOf("|", Token2+1);
      Token4 = database.indexOf("|", Token3+1);

      fields = new Array;
      fields[0] = database.substring( 0, Token0 );
      fields[1] = database.substring( Token0+1, Token1 );
      fields[2] = database.substring( Token1+1, Token2 );
      fields[3] = database.substring( Token2+1, Token3 );
      fields[4] = database.substring( Token3+1, Token4 );
      fields[5] = database.substring( Token4+1, database.length );

      if ( fields[0] == strID_NUM &&
           fields[2] == strPRICE  &&
           fields[3] == strNAME   //&&
         //  fields[5] == strADDTLINFO
         ) {
         bAlreadyInCart = true;
         dbUpdatedOrder = strID_NUM    + "|" +
                          (parseInt(strQUANTITY)+parseInt(fields[1]))  + "|" +
                          strPRICE     + "|" +
                          strNAME      + "|" +
                          strSHIPPING  // + "|" +
                          //14.09.2009 strADDTLINFO;
         strNewOrder = "Order." + i;
         DeleteCookie(strNewOrder, "/");
         SetCookie(strNewOrder, dbUpdatedOrder, null, "/");
         //notice = strQUANTITY + " " + strNAME + strAdded;
         break;
      }
   }


   if ( !bAlreadyInCart ) {
      iNumberOrdered++;

      if ( iNumberOrdered > 20 )
         alert( strSorry );
      else {
         dbUpdatedOrder = strID_NUM    + "|" + 
                          strQUANTITY  + "|" +
                          strPRICE     + "|" +
                          strNAME      + "|" +
                          strSHIPPING  + "|" +
                          strADDTLINFO;

         strNewOrder = "Order." + iNumberOrdered;
         SetCookie(strNewOrder, dbUpdatedOrder, null, "/");
         SetCookie("NumberOrdered", iNumberOrdered, null, "/");
         //notice = strQUANTITY + " " + strNAME + strAdded;
      }
   }


   //if ( DisplayNotice )
     // alert(notice);
}



//---------------------------------------------------------------------||
// FUNCTION:    getCookieVal                                           ||
// PARAMETERS:  offset                                                 ||
// RETURNS:     URL unescaped Cookie Value                             ||
// PURPOSE:     Get a specific value from a cookie                     ||
//---------------------------------------------------------------------||
function getCookieVal (offset) {
   var endstr = document.cookie.indexOf (";", offset);

   if ( endstr == -1 )
      endstr = document.cookie.length;
   return(unescape(document.cookie.substring(offset, endstr)));
}


//---------------------------------------------------------------------||
// FUNCTION:    FixCookieDate                                          ||
// PARAMETERS:  date                                                   ||
// RETURNS:     date                                                   ||
// PURPOSE:     Fixes cookie date, stores back in date                 ||
//---------------------------------------------------------------------||
function FixCookieDate (date) {
   var base = new Date(0);
   var skew = base.getTime();

   date.setTime (date.getTime() - skew);
}


//---------------------------------------------------------------------||
// FUNCTION:    GetCookie                                              ||
// PARAMETERS:  Name                                                   ||
// RETURNS:     Value in Cookie                                        ||
// PURPOSE:     Retrieves cookie from users browser                    ||
//---------------------------------------------------------------------||
function GetCookie (name) {
   var arg = name + "=";
   var alen = arg.length;
   var clen = document.cookie.length;
   var i = 0;

   while ( i < clen ) {
      var j = i + alen;
      if ( document.cookie.substring(i, j) == arg ) return(getCookieVal (j));
      i = document.cookie.indexOf(" ", i) + 1;
      if ( i == 0 ) break;
   }

   return(null);
}


//---------------------------------------------------------------------||
// FUNCTION:    SetCookie                                              ||
// PARAMETERS:  name, value, expiration date, path, domain, security   ||
// RETURNS:     Null                                                   ||
// PURPOSE:     Stores a cookie in the users browser                   ||
//---------------------------------------------------------------------||
function SetCookie (name,value,expires,path,domain,secure) {
   document.cookie = name + "=" + escape (value) +
                     ((expires) ? "; expires=" + expires.toGMTString() : "") +
                     ((path) ? "; path=" + path : "") +
                     ((domain) ? "; domain=" + domain : "") +
                     ((secure) ? "; secure" : "");
}


//---------------------------------------------------------------------||
// FUNCTION:    DeleteCookie                                           ||
// PARAMETERS:  Cookie name, path, domain                              ||
// RETURNS:     null                                                   ||
// PURPOSE:     Removes a cookie from users browser.                   ||
//---------------------------------------------------------------------||
function DeleteCookie (name,path,domain) {
   if ( GetCookie(name) ) {
      document.cookie = name + "=" +
                        ((path) ? "; path=" + path : "") +
                        ((domain) ? "; domain=" + domain : "") +
                        "; expires=Thu, 01-Jan-70 00:00:01 GMT";
   }
}


//---------------------------------------------------------------------||
// FUNCTION:    MoneyFormat                                            ||
// PARAMETERS:  Number to be formatted                                 ||
// RETURNS:     Formatted Number                                       ||
// PURPOSE:     Reformats Dollar Amount to #.## format                 ||
//---------------------------------------------------------------------||
function moneyFormat(input) {
   var dollars = Math.floor(input);
   var tmp = new String(input);

   for ( var decimalAt = 0; decimalAt < tmp.length; decimalAt++ ) {
      if ( tmp.charAt(decimalAt)=="." )
         break;
   }

   var cents  = "" + Math.round(input * 100);
   cents = cents.substring(cents.length-2, cents.length)
           dollars += ((tmp.charAt(decimalAt+2)=="9")&&(cents=="00"))? 1 : 0;

   if ( cents == "0" )
      cents = "00";

   if (cents.slice(-1) > 0)
		cents = cents.slice(0,1)+"0";

   return(dollars + "." + cents);
   
   
}


//---------------------------------------------------------------------||
// FUNCTION:    RemoveFromCart                                         ||
// PARAMETERS:  Order Number to Remove                                 ||
// RETURNS:     Null                                                   ||
// PURPOSE:     Removes an item from a users shopping cart             ||
//---------------------------------------------------------------------||
function RemoveFromCart(RemOrder) {
   if ( confirm( strRemove ) ) {
      NumberOrdered = GetCookie("NumberOrdered");
      for ( i=RemOrder; i < NumberOrdered; i++ ) {
         NewOrder1 = "Order." + (i+1);
         NewOrder2 = "Order." + (i);
         database = GetCookie(NewOrder1);
         SetCookie (NewOrder2, database, null, "/");

      }
      NewOrder = "Order." + NumberOrdered;
      SetCookie ("NumberOrdered", NumberOrdered-1, null, "/");
      DeleteCookie(NewOrder, "/");
      DeleteCookie("Order-Mega-goodie", "/");
            
      // see if current item is the last item in the database,
      // if yes, don't remove the "prev-wizard" string
      
      if (NumberOrdered > 1) 
      {
	      // ------------
	      // change last order (remove "prev-wizard" string) to fire up the quote changed
	         
		  LastOrder = "Order."+ (NumberOrdered-1);
		  if (NumberOrdered == 2)
			  {
			  	  LastOrder = "Order.1";
			  }
		  database = GetCookie(LastOrder );
		
		  Token0 = database.indexOf("|", 0);
		  Token1 = database.indexOf("|", Token0+1);
		  Token2 = database.indexOf("|", Token1+1);
		  Token3 = database.indexOf("|", Token2+1);
		  Token4 = database.indexOf("|", Token3+1);
	 	
	  	  fields = new Array;
		  fields[0] = database.substring( 0, Token0 );
		  fields[1] = database.substring( Token0+1, Token1 );
		  fields[2] = database.substring( Token1+1, Token2 );
		  fields[3] = database.substring( Token2+1, Token3 );
		  fields[4] = database.substring( Token3+1, Token4 );
		  fields[5] = database.substring( Token4+1, database.length );
		
		  dbUpdatedOrder = fields[0] + "|" +
		                   fields[1]+ "|" +
		                   fields[2] + "|" +
		                   fields[3] + "|" +
		                   fields[4] + "|" +
		                   ""; // set this field to "" for the new preventivi to catch the changed price
		  SetCookie (LastOrder , dbUpdatedOrder, null, "/");
		  // ---------
	  }	
	  	  
      IGNORE_UNLOAD = true; // set to "true" & let the page reload without triggering on-close procedure
      location.href=location.href;
   }
}


//---------------------------------------------------------------------||
// FUNCTION:    ChangeQuantity                                         ||
// PARAMETERS:  Order Number to Change Quantity                        ||
// RETURNS:     Null                                                   ||
// PURPOSE:     Changes quantity of an item in the shopping cart       ||
//---------------------------------------------------------------------||
function ChangeQuantity(OrderItem,NewQuantity) {
   if ( isNaN(NewQuantity) ) {
      alert( strErrQty );
   } else {
   
   		if(NewQuantity<=0){
  	        IGNORE_UNLOAD = true; // set to "true" & let the page reload without triggering on-close procedure
			RemoveFromCart(OrderItem);
			location.href=location.href;
			return;
  	        IGNORE_UNLOAD = false; 

		} 

      NewOrder = "Order." + OrderItem;
      database = "";
      database = GetCookie(NewOrder);

      Token0 = database.indexOf("|", 0);
      Token1 = database.indexOf("|", Token0+1);
      Token2 = database.indexOf("|", Token1+1);
      Token3 = database.indexOf("|", Token2+1);
      Token4 = database.indexOf("|", Token3+1);

      fields = new Array;
      fields[0] = database.substring( 0, Token0 );
      fields[1] = database.substring( Token0+1, Token1 );
      fields[2] = database.substring( Token1+1, Token2 );
      fields[3] = database.substring( Token2+1, Token3 );
      fields[4] = database.substring( Token3+1, Token4 );
      fields[5] = database.substring( Token4+1, database.length );

	var a = fields[0];
	if ( a.substring(0,11) == "KIT_SENSORS" && NewQuantity > 4)
	{
        IGNORE_UNLOAD = true; // set to "true" & let the page reload without triggering on-close procedure
		alert ("I sensori porte inclusi nel kit sono 4. Pertanto puoi richiedere al massimo che tutti e 4 possano essere colorati. Se desideri aggiungere ulteriori sensori colorati, torna al negozio e vai al catalogo 'sensori perimetrali'");
		location.href=location.href;
		return;
	    IGNORE_UNLOAD = false;
		
	}
      dbUpdatedOrder = fields[0] + "|" +
                       NewQuantity + "|" +
                       fields[2] + "|" +
                       fields[3] + "|" +
                       fields[4] + "|" ;
                       //fields[5];
		if (coming_from_preventivi == "true") { dbUpdatedOrder = dbUpdatedOrder  + fields[5]; }
                   
                 //      ""; // set this field to "" for the new preventivi to catch the changed price
      strNewOrder = "Order." + OrderItem;
      DeleteCookie(strNewOrder, "/");
      DeleteCookie("Order-Mega-goodie", "/");

      SetCookie(strNewOrder, dbUpdatedOrder, null, "/");
      IGNORE_UNLOAD = true; // set to "true" & let the page reload without triggering on-close procedure
      location.href=location.href;      
   }
}


//---------------------------------------------------------------------||
// FUNCTION:    GetFromCart                                            ||
// PARAMETERS:  Null                                                   ||
// RETURNS:     Product Table Written to Document                      ||
// PURPOSE:     Draws current cart product table on HTML page          ||
//              **DEPRECATED FUNCTION, USE ManageCart or Checkout**    ||
//---------------------------------------------------------------------||
function GetFromCart( fShipping ) {
   ManageCart( );
}


//---------------------------------------------------------------------||
// FUNCTION:    RadioChecked                                           ||
// PARAMETERS:  Radio button to check                                  ||
// RETURNS:     True if a radio has been checked                       ||
// PURPOSE:     Form fillin validation                                 ||
//---------------------------------------------------------------------||
function RadioChecked( radiobutton ) {
   var bChecked = false;
   var rlen = radiobutton.length;
   for ( i=0; i < rlen; i++ ) {
      if ( radiobutton[i].checked )
         bChecked = true;
   }    
   return bChecked;
} 


//---------------------------------------------------------------------||
// FUNCTION:    QueryString                                            ||
// PARAMETERS:  Key to read                                            ||
// RETURNS:     value of key                                           ||
// PURPOSE:     Read data passed in via GET mode                       ||
//---------------------------------------------------------------------||
QueryString.keys = new Array();
QueryString.values = new Array();
function QueryString(key) {
   var value = null;
   for (var i=0;i<QueryString.keys.length;i++) {
      if (QueryString.keys[i]==key) {
         value = QueryString.values[i];
         break;
      }
   }
   return value;
} 

//---------------------------------------------------------------------||
// FUNCTION:    QueryString_Parse                                      ||
// PARAMETERS:  (URL string)                                           ||
// RETURNS:     null                                                   ||
// PURPOSE:     Parses query string data, must be called before Q.S.   ||
//---------------------------------------------------------------------||
function QueryString_Parse() {
   var query = window.location.search.substring(1);
   var pairs = query.split("&"); for (var i=0;i<pairs.length;i++) {
      var pos = pairs[i].indexOf('=');
      if (pos >= 0) {
         var argname = pairs[i].substring(0,pos);
         var value = pairs[i].substring(pos+1);
         QueryString.keys[QueryString.keys.length] = argname;
         QueryString.values[QueryString.values.length] = value;
      }
   }
}




function DISCOUNT_MainPanels(check_ID_NUM, put_quntity)
{	
	// DOPPIA FREQUENZA PANELS
	if (check_ID_NUM == "OKKIO_basic_DF") 			{ Discount_KIT_in_cart = false; Discount_main_panel_in_cart = true; DISCOUNT_DF = true; Discount_DF_sconto += (sconto_OKKIO_basic_DF * put_quntity); Discount_OKKIO_basic = true; Discount_OKKIO_basic_DF = true;}
	if (check_ID_NUM == "OKKIO_PRO_DF")				{ Discount_KIT_in_cart = false;  Discount_main_panel_in_cart = true; DISCOUNT_DF = true; Discount_DF_sconto += (sconto_OKKIO_PRO_DF * put_quntity); Discount_OKKIO_PRO = true; Discount_OKKIO_PRO_DF = true; }
	if (check_ID_NUM == "KIT_OKKIO_basic_DF")		{ Discount_KIT_in_cart = true; DISCOUNT_DF = true; Discount_DF_sconto += (sconto_KIT_OKKIO_basic_DF * put_quntity); Discount_OKKIO_basic = true; Discount_OKKIO_basic_DF = true;}
	if (check_ID_NUM == "KIT_OKKIO_basic_GSM_DF")	{ Discount_KIT_in_cart = true; DISCOUNT_DF = true; Discount_DF_sconto += (sconto_KIT_OKKIO_basic_GSM_DF * put_quntity); Discount_OKKIO_basic = true; Discount_OKKIO_basic_DF = true;}
	if (check_ID_NUM == "Okkio_KIT_PRO_DF") 		{ Discount_KIT_in_cart = true; DISCOUNT_DF = true; Discount_DF_sconto += (sconto_Okkio_KIT_PRO_DF * put_quntity); Discount_OKKIO_PRO = true; Discount_OKKIO_PRO_DF = true;}
	if (check_ID_NUM == "Okkio_KIT_PRO_GSM_DF") 	{ Discount_KIT_in_cart = true; DISCOUNT_DF = true; Discount_DF_sconto += (sconto_Okkio_KIT_PRO_GSM_DF * put_quntity); Discount_OKKIO_PRO = true; Discount_OKKIO_PRO_DF = true; }

	if (check_ID_NUM == "KIT_COMPLETO2012") 	{ Discount_KIT_in_cart = true; KIT_COMPLETO2012 = true;  }

	
	// LEX panels & kits
	// ECONOMY is a synomim of LEX
	
	if (check_ID_NUM == "ECONOMY" || check_ID_NUM == "KIT_ECONOMY" || check_ID_NUM == "KIT_ECONOMY_GSM" || check_ID_NUM == "LEXHS5-2012" || check_ID_NUM == "KIT_ENTRY" || check_ID_NUM == "KIT_ENTRY GSM" || check_ID_NUM == "KIT_ENTRY+GSM" || check_ID_NUM == "KIT_ENTRY_GSM")
	{ 
		if (check_ID_NUM == "ECONOMY" || check_ID_NUM == "KIT_ECONOMY" || check_ID_NUM == "KIT_ECONOMY_GSM")
		{
		Discount_ECONOMY = true;
		}
		
		Discount_LEX = true;
		Discount_OKKIO_PRO = false; 
	}
	
	// okkios basic panels & kits
	if (check_ID_NUM == "OKKIO_basic" || check_ID_NUM == "okkio" || check_ID_NUM == "KIT_OKKIO_basic" || check_ID_NUM == "KIT_OKKIO_basic_GSM") 
	{ 
		Discount_OKKIO_basic = true; 
	}
	
	// okkio PRO panels & kits
	if (check_ID_NUM == "OKKIO_PRO" || check_ID_NUM == "Okkio_KIT_PRO" || check_ID_NUM == "Okkio_KIT_PRO_GSM") 
	{ 
		Discount_OKKIO_PRO = true; 
	}
	
	// if there is no main panel in the shopping cart (okkio pro, basic or LEX9) 
	// ECONOMY is a synomim of LEX
	if (check_ID_NUM == "ECONOMY" || check_ID_NUM == "LEXHS5-2012" || check_ID_NUM == "OKKIO_basic" || check_ID_NUM == "OKKIO_PRO" )
	{
		Discount_main_panel_in_cart = true;
	}
	
	
	// is kit in cart?	
	
	if (check_ID_NUM == "Okkio_KIT_PRO" || check_ID_NUM == "Okkio_KIT_PRO_GSM" || check_ID_NUM == "KIT_OKKIO_basic" || check_ID_NUM == "KIT_OKKIO_basic_GSM" || check_ID_NUM == "KIT_ECONOMY" || check_ID_NUM == "KIT_ECONOMY_GSM" || check_ID_NUM == "KIT_ENTRY" || check_ID_NUM == "KIT_ENTRY GSM" || check_ID_NUM == "KIT_ENTRY+GSM" || check_ID_NUM == "KIT_ENTRY_GSM")	
	{
		Discount_KIT_in_cart = true;
	}	

}

//---------------------------------------------------------------------||
// FUNCTION:    How_many_discounted_products();  						||
// PARAMETERS:  Null                                                   ||
// RETURNS:     How many discounted products are in cart               ||
// PURPOSE:     Calculate how many discounted products are in cart          ||
//---------------------------------------------------------------------||

function DISCOUNT_How_many_products(check_ID_NUM, put_quntity){
	
	if (check_ID_NUM == "DM1" || check_ID_NUM == "DM1-col") { Discount_LXDM1  += parseInt(put_quntity) }
	if (check_ID_NUM == "AL8") { Discount_LXAL8 += parseInt(put_quntity) }
	if (check_ID_NUM == "AL8-L") { Discount_LXAL8L += parseInt(put_quntity) }
	if (check_ID_NUM == "FS4-V3") { Discount_LXFS4V3 += parseInt(put_quntity) }
	if (check_ID_NUM == "FS4") { Discount_LXFS4 += parseInt(put_quntity) }	
	if (check_ID_NUM == "ECSIR") { Discount_ECSIR  +=    parseInt(put_quntity) }
	if (check_ID_NUM == "WLSIR") { Discount_WLSIR +=  parseInt(put_quntity) }			
	if (check_ID_NUM == "WLrip") { Discount_WLRIP +=  parseInt(put_quntity) }
	if (check_ID_NUM == "RETE") { Discount_RETE += parseInt(put_quntity) }

	// 15 mai 2009
	if (check_ID_NUM == "GSMFWT") { Discount_GSMFWT += parseInt(put_quntity) }
	if (check_ID_NUM == "ST101") { Discount_ST101 += parseInt(put_quntity) }
	
	// 12 iulie 2009
	if (check_ID_NUM == "ROLLER") { Discount_ROLLER += parseInt(put_quntity) }
	
	// 12 septembrie 2009
	if (check_ID_NUM == "MOBEYE") { Discount_MOBEYE += parseInt(put_quntity) }
	
	
	
	if (check_ID_NUM == "SIRNB") { Discount_SIRNB +=    parseInt(put_quntity) }
	if (check_ID_NUM == "PROSIR") { Discount_PROSIR +=    parseInt(put_quntity) }
	
	if (check_ID_NUM == "ACCMOD") { Discount_ACCMOD += parseInt(put_quntity) }
	if (check_ID_NUM == "CONFIG_PERSONAL") { Discount_CONFIG_PERSONAL += parseInt(put_quntity) }


	if (check_ID_NUM == "GSMFWT") { Discount_GSMFWT += parseInt(put_quntity) }

	if (check_ID_NUM == "FS4" || check_ID_NUM == "FS4-V3" || check_ID_NUM == "ROLLER" || check_ID_NUM == "FS1" 
	|| check_ID_NUM == "KEYB" || check_ID_NUM == "KEYB" || check_ID_NUM == "METAL " || check_ID_NUM == "METAL-COL"
	|| check_ID_NUM == "VST-S" || check_ID_NUM == "ARV" ) 
		{
		//all remotes
		show_MyCentrale = true;
		}
	
}


//---------------------------------------------------------------------||
// FUNCTION:    ManageCart                                             ||
// PARAMETERS:  Null                                                   ||
// RETURNS:     Product Table Written to Document                      ||
// PURPOSE:     Draws current cart product table on HTML page          ||
//---------------------------------------------------------------------||
function ManageCart( stare ) {
   var iNumberOrdered = 0;    //Number of products ordered
   var fTotal         = 0;    //Total cost of order
	var TotalDF	= 0;
	var fTotalTemp = 0; // totalul fara obiectele DF, fara alte discounturi si fara Gift
   var fTax           = 0;    //Tax amount
   
   var Discount_GLOBAL_Gift = 0;
   var Discount_GLOBAL_Speciale= 0;
   
   var fSpecialePretIntreg = 0;

   var fShipping      = 9;    //Shipping amount
   var strTotal       = "";   //Total cost formatted as money
   var strTotalBeforeDiscount = ""; // Total before disount
   var strTax         = "";   //Total tax formatted as money
   var strShipping    = "";   //Total shipping formatted as money
   var strOutput      = "";   //String to be written to page
   var bDisplay       = true; //Whether to write string to the page (here for programmers)
   var strPP          = "";   //Payment Processor Description Field
	var stare_colspan = 0;
	var TotalDF = 0;
	var CashDiscounts = 0;

	var show_dascontare = false;
	
	if (stare == "manage") stare_colspan = 4; 
	if (stare == "checkout") stare_colspan = 3;
	if (stare == "savequote") stare_colspan = 4;
	   if	(readCookie('offerta%2DAMICO2012')) offerta2012 = true;
   if	(readCookie('offerta%2DAMICO2012YB')) offerta2012YB = true;

      if (offerta2012 == true) { fShipping  = 0; }
      if (offerta2012 == false  && offerta2012YB == true) { fShipping  = 0; }

   if	(readCookie('diecimila')) Discount_diecimila = true
	if	(readCookie('offertona') == "showed") OffertonaGift = true
	
   if (readCookie('preventivi_wiz') == "true") { coming_from_preventivi = true; }

   // offerta20jul discount
   if	(readCookie('offerta20jul')) offerta20jul = true;
   // sicko discount


   iNumberOrdered = GetCookie("NumberOrdered");
   if ( iNumberOrdered == null )
      iNumberOrdered = 0;

   if ( TaxByRegion ) {
      QueryString_Parse();
      fTax = parseFloat( QueryString( OutputOrderTax ) );
      strTax = moneyFormat(fTax);
   }

   if ( bDisplay )
      strOutput = "<TABLE CLASS=\"nopcart\"><TR>" +
                  "<TD CLASS=\"nopheader\"><B>"+strILabel+"</B></TD>" +
                  "<TD CLASS=\"nopheader\"><B>"+strDLabel+"</B></TD>" +
                  "<TD CLASS=\"nopheader\"><B>"+strQLabel+"</B></TD>";
                  	if (stare == "manage") 
					{
                  	 strOutput +=   "<TD CLASS=\"nopheader\"><B>"+strPLabel+"</B></TD>" +
	                 "<TD CLASS=\"nopheader\"><B>"+strRLabel+"</B></TD>" ;
					}
   strOutput +=  "</TR>";

// discount... get type of main panel
   for ( i = 1; i <= iNumberOrdered; i++ ) {
      NewOrder = "Order." + i;
      database = "";
      database = GetCookie(NewOrder);

      Token0 = database.indexOf("|", 0);
      Token1 = database.indexOf("|", Token0+1);


      fields = new Array;
      fields[0] = database.substring( 0, Token0 );                 // Product ID
      fields[1] = database.substring( Token0+1, Token1 );          // Quantity
   	 
	  if (fields[5] == "prev-wizard") { coming_from_preventivi = true; }

//	diff_products = diff_products + 1;
	DISCOUNT_MainPanels(fields[0], fields[1]);  
}


   for ( i = 1; i <= iNumberOrdered; i++ ) {
      NewOrder = "Order." + i;
      database = "";
      database = GetCookie(NewOrder);

      Token0 = database.indexOf("|", 0);
      Token1 = database.indexOf("|", Token0+1);
      Token2 = database.indexOf("|", Token1+1);
      Token3 = database.indexOf("|", Token2+1);
      Token4 = database.indexOf("|", Token3+1);

      fields = new Array;
      fields[0] = database.substring( 0, Token0 );                 // Product ID
      fields[1] = database.substring( Token0+1, Token1 );          // Quantity
      fields[2] = database.substring( Token1+1, Token2 );          // Price
      fields[3] = database.substring( Token2+1, Token3 );          // Product Name/Description
      fields[4] = database.substring( Token3+1, Token4 );          // Shipping Cost
      fields[5] = database.substring( Token4+1, database.length ); //Additional Information

		show_dascontare = false;
	
	if (fields[0] == "Omaggio" || fields[0] == "OMAGGIO2" )
	{
		if (stare == "manage" || stare == "savequote")
		{
			continue;
		}

		if (stare == "checkout")
		{
			// put discont
			
		
			// goodies A&B for 500 and 1000
			if (fields[3] == "Configurazione gratis!") { Discount_GLOBAL_Gift += 50; }//fields[2] = 0; }
			if (fields[3] == "Configurazione gratis! + 60 euro di sconto!") { Discount_GLOBAL_Gift += 50; CashDiscounts = 60;}
			if (fields[3] == "Sconto immediato alla cassa di 100,00 euro") { Discount_GLOBAL_Gift += 0; CashDiscounts = 100;}
			if (fields[3] == "Sconto immediato alla cassa di 30,00 euro") { Discount_GLOBAL_Gift += 0; CashDiscounts = 30;}
			if (fields[3] == "1 Videocamera Mobeye+ GRATIS!") { Discount_GLOBAL_Gift += 139;}//fields[2] = 0;}
			if (fields[3] == "1 Telecamera IP senza fili PROFCAMX GRATIS!") { Discount_GLOBAL_Gift += 115; }//fields[2] = 0;}
			
		
		//	continue;

			if (GetCookie( 'Order-Mega-goodie' ) != "A" && GetCookie( 'Order-Mega-goodie' ) != "B" ) 
			{
				continue; 
			}

		}
	}


// temp // de sters
	// DOPPIA FREQUENZA PANELS
	if (fields[0] == "OKKIO_basic_DF") 			{  TotalDF += parseInt(fields[1]) *price_OKKIO_basic_DF; fields[3] +=  "<br>(in offerta! <span class=textstrike><del>"+ price_OKKIO_basic_DF +",00 EUR</del></span>, <span class=price>"+(price_OKKIO_basic_DF-sconto_OKKIO_basic_DF)+",00 EUR</span>)"; show_dascontare = true;}
	if (fields[0] == "OKKIO_PRO_DF")			{  TotalDF += parseInt(fields[1]) *price_OKKIO_PRO_DF; fields[3] +=  "<br>(in offerta! <span class=textstrike><del>"+ price_OKKIO_PRO_DF +",00 EUR</del></span>, <span class=price>"+(price_OKKIO_PRO_DF-sconto_OKKIO_PRO_DF)+",00 EUR</span>)"; show_dascontare = true;}
	if (fields[0] == "KIT_OKKIO_basic_DF")		{  TotalDF += parseInt(fields[1]) *price_KIT_OKKIO_basic_DF;  fields[3] +=  "<br>(in offerta! <span class=textstrike><del>"+ price_KIT_OKKIO_basic_DF +",00 EUR</del></span>, <span class=price>"+(price_KIT_OKKIO_basic_DF-sconto_KIT_OKKIO_basic_DF)+",00 EUR</span>)"; show_dascontare = true;}
	if (fields[0] == "KIT_OKKIO_basic_GSM_DF")	{  TotalDF += parseInt(fields[1]) *price_KIT_OKKIO_basic_GSM_DF; fields[3] +=  "<br>(in offerta! <span class=textstrike><del>"+ price_KIT_OKKIO_basic_GSM_DF +",00 EUR</del></span>, <span class=price>"+(price_KIT_OKKIO_basic_GSM_DF-sconto_KIT_OKKIO_basic_GSM_DF)+",00 EUR</span>)";show_dascontare = true; }
	if (fields[0] == "Okkio_KIT_PRO_DF") 		{  TotalDF += parseInt(fields[1]) *price_Okkio_KIT_PRO_DF; fields[3] +=  "<br>(in offerta! <span class=textstrike><del>"+ price_Okkio_KIT_PRO_DF +",00 EUR</del></span>, <span class=price>"+(price_Okkio_KIT_PRO_DF-sconto_Okkio_KIT_PRO_DF)+",00 EUR</span>)";show_dascontare = true; }
	if (fields[0] == "Okkio_KIT_PRO_GSM_DF") 	{  TotalDF += parseInt(fields[1]) *price_Okkio_KIT_PRO_GSM_DF; fields[3] +=  "<br>(in offerta! <span class=textstrike><del>"+ price_Okkio_KIT_PRO_GSM_DF +",00 EUR</del></span>, <span class=price>"+(price_Okkio_KIT_PRO_GSM_DF-sconto_Okkio_KIT_PRO_GSM_DF)+",00 EUR</span>)";show_dascontare = true; }

	 // speciale products discounts:		
	if (fields[0] == "MOBEYEPLUS") {	Discount_GLOBAL_Speciale += 	(parseInt(fields[1]) * 40 ); fSpecialePretIntreg += (parseInt(fields[1]) * 139); fields[3] = fields[3] + "<br><small>(lo sconto viene sommato nella casella SCONTO). Prezzo finale 99,00 euro</small>";show_dascontare = true; }
	if (fields[0] == "PROFCAMX") {	Discount_GLOBAL_Speciale += 	(parseInt(fields[1]) * 16 ); fSpecialePretIntreg += (parseInt(fields[1]) * 115); fields[3] = fields[3] + "<br><small>(lo sconto viene sommato nella casella SCONTO). Prezzo finale 99,00 euro</small>";show_dascontare = true;	}
	if (fields[0] == "OUTCAMX") {	Discount_GLOBAL_Speciale += 	(parseInt(fields[1]) * 20 ); fSpecialePretIntreg += (parseInt(fields[1]) * 139); fields[3] = fields[3] + "<br><small>(lo sconto viene sommato nella casella SCONTO). Prezzo finale 119,00 euro</small>";show_dascontare = true;	}

	if (fields[0] == "KIT_COMPLETO2012") { Discount_GLOBAL_Speciale += 	(parseInt(fields[1]) * 90 ); fSpecialePretIntreg += (parseInt(fields[1]) * 389); show_dascontare = true;	}
	

// temp // de sters

	// diecimila offer ---------------------------------------------------------------------------
	// if diecimila offer then
 		if (Discount_diecimila == true)
 		{  
			DiecimilaDiscountRules ();
		}  	  
	// diecimila offer ---------------------------------------------------------------------------


	  // additiona discounts RETE, WLRIP, WLSIR    +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// if there is no main panel in the shopping cart (okkio pro, basic or LEX9) 
// then you get NO discount from the additional products (so no discount for 
// lxfs4-v3, lxfs4, roller, lxdm1, lxal8, st101) but only the 10% or 5% or other discounts, if any.
	   
 DISCOUNT_How_many_products(fields[0], fields[1]);  

if (Discount_main_panel_in_cart == true && coming_from_preventivi == true) // panel in preventivi AND coming from preventivi link
{
	  if (Discount_OKKIO_basic == true && fields[0] == "RETE") { fields[2] = 0; }
	  if (Discount_OKKIO_PRO == true && fields[0] == "RETE") { fields[2] = 0; }
	  if (Discount_ECONOMY == true && fields[0] == "RETE") { fields[2] = 0; }

	  // dan remove / force remove the free configuration in the preventivi
	// if (Discount_3hours == true && fields[0] == "CONFIG_PERSONAL") { fields[2] = 0; fields[3] = fields[3] + "<font color=red> -GRATIS!</font>"; }

	    

} // end panel in preventivi"	   


      fTotal     += (parseInt(fields[1]) * parseFloat(fields[2]) );

      if ( !TaxByRegion ) fTax = (fTotal * TaxRate);
      strTotal    = moneyFormat(fTotal);
      if ( !TaxByRegion ) strTax = moneyFormat(fTax);
      strShipping =  moneyFormat(fShipping);

  	  if (fields[5] == "prev-wizard") my_nopentry = "nopentry-wiz"
  	  else if (fields[0] == "Omaggio") my_nopentry = "nopentry-discount"
  	  else if (fields[0] == "OMAGGIO2") my_nopentry = "nopentry-offertona"

 	  else my_nopentry = "nopentry";
  	  
  	  if (fields[5] == "cheap") my_nopentry = "nopentry-wiz-cheap";

  	  
      if ( bDisplay && fields[0] != "AMICO") {
      
			      // kit color sensors
	        strOutput += "<TR><TD CLASS="+my_nopentry+">"  + fields[0] + "</TD>";


	        strOutput += "<TD CLASS="+my_nopentry+">"  + fields[3] + " </TD>";
	//special check, don't show AMICO products in manage mode	

	if (stare == "manage"  && fields[0] != "Omaggio") 
		strOutput += "<TD CLASS=\""+my_nopentry+"\"><INPUT TYPE=TEXT NAME=Q SIZE=2 VALUE=\"" + fields[1] + "\" onChange=\"ChangeQuantity("+i+", this.value);\"" + "\" onkeypress=\"return handleEnter(this, event,"+i+");\"></TD>";
	else
		strOutput += "<TD CLASS="+my_nopentry+">" + fields[1] + "</TD>";
					     
	if ( parseFloat(fields[2]) > 0 )
	{
		if (show_dascontare == true)
		{
			strOutput += "<TD CLASS="+my_nopentry+">"+ MonetarySymbol + moneyFormat(fields[2]) + "<br><small>da scontare</small></TD>";
		}
		else
		{
			strOutput += "<TD CLASS="+my_nopentry+">"+ MonetarySymbol + moneyFormat(fields[2]) + "</TD>";
		}
	}
	else if (parseFloat(fields[2]) < 0)
	{
		strOutput += "<TD CLASS="+my_nopentry+">"+ MonetarySymbol + moneyFormat(fields[2]) + "</TD>";
	}
	
	else if (parseFloat(fields[2]) == 0)
	{
		if (fields[0] == "OMAGGIO2") 
		{
			strOutput += "<TD CLASS="+my_nopentry+"><font color=red>a scelta!</font></TD>";
		}
		else
		{
			strOutput += "<TD CLASS="+my_nopentry+"><font color=red>GRATIS!</font></TD>";
		}
	}
	

         if (stare == "manage") 
          {
           	strOutput += "<TD CLASS="+my_nopentry+" + ALIGN=CENTER><input type=button value=\" "+strRButton+" \" onClick=\"RemoveFromCart("+i+")\" class=\"nopbutton\"><br><input type=button value=\" "+"Aggiorna"+" \" onClick=\"location.href=location.href;\" class=\"nopbutton\"></TD></TR>";
		}
		if (stare == "checkout") 
		{
		}

       //  strOutput += "<TD CLASS="+my_nopentry+">" + fields[1] + "</TD>";
        // strOutput += "<TD CLASS="+my_nopentry+">"+ MonetarySymbol + moneyFormat(fields[2]) + "/cad</TD>"; 


          if ( DisplayShippingColumn ) {
             if ( parseFloat(fields[4]) > 0 )
	strOutput += "<TD CLASS="+my_nopentry+">"+ MonetarySymbol + moneyFormat(fields[4]) + "/cad</TD>";
             else 
                strOutput += "<TD CLASS="+my_nopentry+">N/A</TD>";
          }


         strOutput += "</TR>";
         
      }

	    // coming from wizard?
	    if (fields[5] == "prev-wizard") { coming_from_preventivi = true; }
    
		//DISCOUNT_How_many_products(fields[0], fields[1]);  

      if ( AppendItemNumToOutput ) {
         strFooter = i;
      } else {
         strFooter = "";
      }
      if ( PaymentProcessor != '' ) {
         //Process description field for payment processors instead of hidden values.
         //Format Description of product as:
         // ID, Name, Qty X
         strPP += fields[0] + ", " + fields[3];
         if ( fields[5] != "" )
            strPP += " - " + fields[5];
         strPP += ", Qty. " + fields[1] + "\n";
      } else {
      //dan  format field output
         strOutput += "<input type=hidden name=\"" + OutputItemId        + strFooter + "\" value=\"" + fields[0] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemName      + strFooter + "\" value=\"" + fields[3] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemQuantity  + strFooter + "\" value=\"" + fields[1] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemPrice     + strFooter + "\" value=\"" + fields[2] + "\">";
         

       //dan  strOutput += "<input type=hidden name=\"" + OutputItemShipping  + strFooter + "\" value=\"" + fields[4] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemAddtlInfo + strFooter + "\" value=\"" + fields[5] + "\">";
      } 

   }

   if ( bDisplay ) {




if (Discount_main_panel_in_cart == true && coming_from_preventivi == true) // panel in preventivi AND coming from preventivi link
{

	
	// LEXHS5-2012 panel ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    if (Discount_LEX == true ) 
    { 
		
    	if (Discount_LXDM1 == 2) Discount_GLOBAL += 10 ;
    	if (Discount_LXDM1 == 3) Discount_GLOBAL += 15 ;
	   	if (Discount_LXDM1 > 3) Discount_GLOBAL += 20 ;
	   	
    	if (Discount_LXFS4V3 > 1) Discount_GLOBAL += 20;
    	if (Discount_LXAL8L > 0 || Discount_LXAL8 > 0) Discount_GLOBAL += 15;

    	if (Discount_GSMFWT == 1) Discount_GLOBAL += 30;
    	if (Discount_ST101 > 0) Discount_GLOBAL += 10;

		//if panel = h05 and (dm1 > 3 and ( al8 > 0 or st101 > 0) and v3 > 1) then discount = discount + 19
		if (Discount_LXDM1 > 3 && Discount_LXFS4V3 > 1)
		{
			if ( Discount_LXAL8L > 0 || Discount_LXAL8 > 0 || Discount_ST101> 0) 
			{
					Discount_GLOBAL += 19; 
			}
		}

    }
    
    
    // OKKIO panels (OKKIO_basic & OKKIO_PRO panels) +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    if (Discount_OKKIO_basic == true || Discount_OKKIO_PRO == true ) 
    { 
    
       	// updated 12 iulie 2009 --------------------------------------

    	// if OKKIO panel is Okkio basic then discount = discount + 29
		// if OKKIO panel is Okkio Pro then discount = discount + 19
	    if (Discount_OKKIO_basic == true) Discount_GLOBAL += 29;
	    if (Discount_OKKIO_PRO == true) Discount_GLOBAL += 19;
	 //   if (Discount_OKKIO_PRO_DF == true) Discount_GLOBAL += 15;  // adaugat 9 ianuarie 2011

 	    if (Discount_GSMFWT == 1) Discount_GLOBAL += 30;
	
	    if (Discount_LXDM1 == 2) Discount_GLOBAL += 15 ;
	    if (Discount_LXDM1 == 3) Discount_GLOBAL += 20 ;
	    
	    if (Discount_LXDM1 > 3) Discount_GLOBAL += 30 ;
		
	    if (Discount_ROLLER == 1) Discount_GLOBAL += 10 ;
	    if (Discount_ROLLER == 2) Discount_GLOBAL += 20 ;

		if (Discount_LXFS4 > 1) Discount_GLOBAL += 10;
		
		if (Discount_LXAL8L > 0 || Discount_LXAL8 > 0) Discount_GLOBAL += 15;
		if (Discount_ST101 > 0) Discount_GLOBAL += 15;

    }  
    
    if (Discount_ECSIR > 0) Discount_GLOBAL += 5;
    
    if (Discount_WLSIR > 0) Discount_GLOBAL += 15;
    if (Discount_SIRNB > 0) Discount_GLOBAL += 15;
    if (Discount_PROSIR > 0) Discount_GLOBAL += 30;

    
} // end panel in preventivi"
    fTotal =  fTotal + CashDiscounts  ; 
    strTotalBeforeDiscount = Math.round(fTotal)   ;
	
    // CALCULATE ***NEW*** SUBTOTAL NOW  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	Discount_GLOBAL = Discount_GLOBAL + Discount_DF_sconto +  Discount_GLOBAL_Speciale;// + CashDiscounts ; discounturile cash se aplica la sfarsit
	fTotal =  fTotal - Discount_GLOBAL  ;
	strTotal    = moneyFormat(fTotal);
	
	// totalul fara obiectele DF, fara alte discounturi si fara Gift
	fTotalTemp = strTotalBeforeDiscount - fSpecialePretIntreg -  TotalDF;

	if (fTotalTemp > 0 )
	{
		if (offerta2012 == true || offerta2012YB == true) 
		{
			// first visit: + 5% discount on everything except DF items
		    Discount_GLOBAL_2 = 0;
			Discount_GLOBAL_3 = (0.05*fTotalTemp );
			
		    if (coming_from_preventivi == true)
			{
	  		Discount_GLOBAL_3 +=  (0.05*fTotalTemp ); 
			}
	
		}
		else
		{
		}
	}	
	Discount_GLOBAL = Discount_GLOBAL + Discount_GLOBAL_2 + Discount_GLOBAL_3 ;

	fTotal = (parseInt(strTotalBeforeDiscount) - Discount_GLOBAL); 

	// % extra discount only for preventivi
    if (coming_from_preventivi == true)
    {
	    if (fTotal > 700) {  Discount_GLOBAL_2 +=  (0.05*fTotal); }
	    if (fTotal > 1300) { Discount_GLOBAL_2 += (0.10*fTotal);  }
	    
	    Discount_GLOBAL = Discount_GLOBAL + Discount_GLOBAL_2  ;
		fTotal = fTotal  - Discount_GLOBAL_2; 

	}	
	
	Discount_GLOBAL = Discount_GLOBAL + CashDiscounts  ;
	fTotal = fTotal  - CashDiscounts ; 

	//if (fShipping == 0)
	//{
	//	Discount_GLOBAL = Discount_GLOBAL + 9; 
	//	fTotal = fTotal  - 9; 
	//}
	strTotal = moneyFormat(fTotal);

    // --------------------------------------------------------------------------------------------------------
    
   //if (DisplayPriceColumn == false) 
   {
		// show GIFT messege?
	g_TotalCost = (fTotal + fShipping + fTax);
	if (stare == "manage" ||  stare == "savequote")
	{
		if (stare == "savequote")
		{
			putMegaCookie =false;
		}
		DoOnLoadCommonPartStuff();
	}

   	if (gifttext != "" && stare == "manage" ||  stare == "savequote")
   	{
   	   	if (stare == "savequote") 
   		{
   		stare_colspan = stare_colspan -1 ; 
   		}

		if (g_TotalCost > 1000)
		{
		strOutput += "<TR><TD CLASS=\"nopentry-discount\" align=center COLSPAN="+(stare_colspan+1)+"><B>"+gifttext+"</B></TD>";
		strOutput += "</TR>";
		strOutput +="<td class=nopentry-offertona>OMAGGIO GENERALE</td><td class=nopentry-offertona>Ulteriore sconto di 100 euro! <span class=text_small_italic>oppure</span><br>Configurazione gratis! + 60 euro di sconto! <span class=text_small_italic>oppure</span><br>Telecamera Mobeye+ GRATIS! <span class=text_small_italic>oppure</span><br>Telecamera PROFCAMX GRATIS! <span class=text_small_italic>oppure</span><br>Riconoscitore impronte digitali<br></td><td class=nopentry-offertona>1</td><td class=nopentry-offertona>a scelta</td>";      
		
		if (stare != "savequote")
		{
		strOutput +="<td class=nopentry-offertona> </td>";      		
		}
		
		}
		else if (g_TotalCost > 500)
		{
		strOutput += "<TR><TD CLASS=\"nopentry-discount\" align=center COLSPAN="+(stare_colspan+1)+"><B>"+gifttext+"</B></TD>";
		strOutput += "</TR>";
		strOutput +="<td class=nopentry-offertona>OMAGGIO GENERALE</td><td class=nopentry-offertona>Configurazione gratis! <span class=text_small_italic>oppure</span><br>Telecamera Mobeye+ GRATIS! <span class=text_small_italic>oppure</span><br>Telecamera PROFCAMX GRATIS!</td><td class=nopentry-offertona>1</td><td class=nopentry-offertona>a scelta</td>";      
						
		if (stare != "savequote")
		{
		strOutput +="<td class=nopentry-offertona> </td>";      		
		}
		

		}
		
		if (stare == "savequote") 
   		{
   		//stare_colspan = stare_colspan + 1 ; 
   		}

	}


      strOutput += "<TR><TD CLASS=\"nopsubtotal\" COLSPAN="+stare_colspan+">"+strSUB+"</TD>";
      strOutput += "<TD CLASS=\"nopsubtotal\"  colspan=1  ALIGN=RIGHT>" + MonetarySymbol + moneyFormat(strTotalBeforeDiscount) + "</TD>";
      strOutput += "</TR>";
      
      // discount: SCONTO field
      if (Discount_diecimila == true) { strDISCOUNT = "SCONTO ADDIZIONALE";}
      // SICKO offer
      if (offerta2012 == true) {
      	strDISCOUNT = "SCONTO CUMULATIVO"; /* +  Discount_Percent(Discount_GLOBAL,strTotalBeforeDiscount ) +  " circa"*/;
      }
      else
      {
      	strDISCOUNT = "SCONTO " +  /* Discount_Percent(Discount_GLOBAL,strTotalBeforeDiscount )  + */ "<small>(valevole per ordini confermati entro la scadenza dell'offerta attuale)</small>";
      }

	// if sconto = 0 then doesn't show "SCONTO" nor the 0
	if (Discount_GLOBAL > 0 )
	{
      strOutput += "<TR><TD CLASS=\"nopdiscount\" COLSPAN="+stare_colspan+"><B>"+strDISCOUNT +"</B></TD>";
      strOutput += "<TD CLASS=\"nopdiscount\"  colspan=1  ALIGN=RIGHT><B>" + MonetarySymbol + moneyFormat(Discount_GLOBAL) + "</B></TD>";
      strOutput += "</TR>";
	}
// DEBUG +++++++++++++++++++++
//      // discount: SCONTO field for preventivi
//      strOutput += "<TR><TD CLASS=\"nopdiscount\" COLSPAN=3><B>"+strDISCOUNT +"</B></TD>";
//      // 23 oct
//      strOutput += "<TD CLASS=\"nopdiscount\" COLSPAN=2 ALIGN=RIGHT><B>" + MonetarySymbol + moneyFormat(Discount_GLOBAL - Discount_GLOBAL_3) + "</B></TD>";
//      strOutput += "</TR>";
      
//      if (readCookie('nuovolistino2011DFYB%2D3hours') || readCookie('nuovolistino2011DFYB3hours%2D5days'))
//      { 
//	      // discount: SCONTO field for 5% or 10% discounts
//	      strOutput += "<TR><TD CLASS=\"nopdiscount\" COLSPAN=3><B>"+strDISCOUNT +" 5%/10%</B></TD>";
//	      strOutput += "<TD CLASS=\"nopdiscount\" COLSPAN=2 ALIGN=RIGHT><B>" + MonetarySymbol + moneyFormat(Discount_GLOBAL_3) + "</B></TD>";
//	      strOutput += "</TR>";
//	}
// DEBUG +++++++++++++++++++++
      if ( DisplayShippingRow ) {
      	 if (fShipping > 0)
      	 {
	         strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN="+stare_colspan+"><B>"+strSHIP+"</B></TD>";
	         strOutput += "<TD CLASS=\"noptotal\"  colspan=1  ALIGN=RIGHT><B>" + MonetarySymbol + strShipping + "</B></TD>";
	         strOutput += "</TR>";
      	 }
      	 else 
      	 {
	         strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN="+stare_colspan+"><B>"+strSHIP+"</B></TD>";
	         strOutput += "<TD CLASS=\"noptotal\"  colspan=1  ALIGN=RIGHT><B>" + "<font color=red>GRATIS!</font>" + "</B></TD>";
	         strOutput += "</TR>";
         }
      }

      if ( DisplayTaxRow || TaxByRegion ) {
         strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN="+stare_colspan+"><B>"+strTAX+"</B></TD>";
         strOutput += "<TD CLASS=\"noptotal\"  colspan=1 ALIGN=RIGHT><B>" + MonetarySymbol + strTax + "</B></TD>";
         strOutput += "</TR>";
      }
	
      strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN="+stare_colspan+"><B>"+strTOT+"</B></TD>";
      strOutput += "<TD CLASS=\"noptotal\"  colspan=1 ALIGN=RIGHT><B>" + MonetarySymbol + moneyFormat((fTotal + fShipping + fTax)) + "</B></TD>";
      strOutput += "</TR>";

      strOutput += "</TABLE>";

      
      if ( PaymentProcessor == 'an') {
         //Process this for Authorize.net WebConnect
         strOutput += "<input type=hidden name=\"x_Version\" value=\"3.0\">";
         strOutput += "<input type=hidden name=\"x_Show_Form\" value=\"PAYMENT_FORM\">";
         strOutput += "<input type=hidden name=\"x_Description\" value=\""+ strPP + "\">";
         strOutput += "<input type=hidden name=\"x_Amount\" value=\""+ moneyFormat((fTotal + fShipping + fTax)) + "\">";
      } else if ( PaymentProcessor == 'wp') {
         //Process this for WorldPay
         strOutput += "<input type=hidden name=\"desc\" value=\""+ strPP + "\">";
         strOutput += "<input type=hidden name=\"amount\" value=\""+ moneyFormat((fTotal + fShipping + fTax)) + "\">";
      } else if ( PaymentProcessor == 'lp') {
         //Process this for LinkPoint         
         strOutput += "<input type=hidden name=\"mode\" value=\"fullpay\">";
         strOutput += "<input type=hidden name=\"chargetotal\" value=\""+ moneyFormat((fTotal + fShipping + fTax)) + "\">";
         strOutput += "<input type=hidden name=\"tax\" value=\""+ MonetarySymbol + strTax + "\">";
         strOutput += "<input type=hidden name=\"subtotal\" value=\""+ MonetarySymbol + strTotal + "\">";
         strOutput += "<input type=hidden name=\"shipping\" value=\""+ MonetarySymbol + strShipping + "\">";
         strOutput += "<input type=hidden name=\"desc\" value=\""+ strPP + "\">";
      } else {
      	// paypal
         strOutput += "<input type=hidden name=\""+OutputOrderSubtotal+"\" value=\""+ moneyFormat(strTotalBeforeDiscount)+ "\">";

         strOutput += "<input type=hidden name=\""+OutputOrderDiscount+"\" value=\""+ moneyFormat(Discount_GLOBAL)+ "\">";
         strOutput += "<input type=hidden name=\""+OutputOrderDiscountCaption +"\" value=\""+ strDISCOUNT + "\">";

         strOutput += "<input type=hidden name=\""+OutputOrderDiscount+"510\" value=\""+ moneyFormat(Discount_GLOBAL_3)+ "\">";

         strOutput += "<input type=hidden name=\""+OutputOrderShipping+"\" value=\""+ strShipping + "\">";
         //strOutput += "<input type=hidden name=\""+OutputOrderTax+"\"      value=\""+ MonetarySymbol + strTax + "\">";
         strOutput += "<input type=hidden name=\""+OutputOrderTotal+"\"    value=\""+ moneyFormat((fTotal + fShipping + fTax)) + "\">";
      }
   }
}

   g_TotalCost = (fTotal + fShipping + fTax);
   
   document.write(strOutput);
   document.close();


}

//---------------------------------------------------------------------||
// FUNCTION:    ValidateCart                                           ||
// PARAMETERS:  Form to validate                                       ||
// RETURNS:     true/false                                             ||
// PURPOSE:     Validates the managecart form                          ||
//---------------------------------------------------------------------||
var g_TotalCost = 0;
function ValidateCart( theForm ) {

   if ( TaxByRegion ) {
      if ( !RadioChecked(eval("theForm."+OutputOrderTax)) ) {
         alert( TaxPrompt );
         return false;
      }
   }

if (coming_from_preventivi == true)
{
	// preventivi blinking checkout button
//	show_button = '<img class="managecartbutton" src=images/but_wiz1.gif onclick="IGNORE_UNLOAD = true;window.location=\''
//	show_button += document.forms[0].action;//'http://www.sicurezza.pro/cart/htdocs/checkout-wiz2.asp
//	show_button += '\'" height=60 width=300>';

	show_button = '<img class="managecartbutton" src=images/but_wiz1.gif onclick="IGNORE_UNLOAD = true;document.forms[0].submit();" height=60 width=300>';
	if (gifttext != "" && g_TotalCost > 500) { show_button = '<img class="managecartbutton" src=images/but_wiz1_2.gif onclick="IGNORE_UNLOAD = true;document.forms[0].submit();" height=60 width=300><br><span class=text_small></span>'; }

}
else
{
	show_button = '<INPUT TYPE=IMAGE SRC="images/checkout.gif" BORDER=0 name="I1" class="managecartbutton"></font>'; 
	if (gifttext != "" && g_TotalCost > 500) { show_button = '<INPUT TYPE=IMAGE SRC="images/checkout_2.gif" BORDER=0 name="I1" class="managecartbutton"></font>'; }
}
  // WHEN FREE SHIPPING COOKIE IS ACTIVE
  if (offerta2012 == true && gifttext == "" && g_TotalCost < MinimumOrder ) 
  {
         show_button = '<a href="ordina.asp"><img border="0" src="images/min50euro_wiz.jpg"></a></font>';
         return false;
  }
  else if (offerta2012YB == true && gifttext == "" && g_TotalCost < MinimumOrder ) 
  { 
         show_button = '<a href="ordina.asp"><img border="0" src="images/min50euro_wiz.jpg"></a></font>';
         return false;

  }
   return true;
}




//onclose script:

function doBeforeUnload() {
   if(IGNORE_UNLOAD) 
   {
   return; // Let the page unload
   }

   if(window.event)
      window.event.returnValue = UNLOAD_MSG; // IE
   else
      return UNLOAD_MSG; // FX
}

if(window.body)
   window.body.onbeforeunload = doBeforeUnload; // IE
else
   window.onbeforeunload = doBeforeUnload; // FX

function SetTxtFocus(txtId) {
   var oTxt = document.getElementById(txtId);
   oTxt.focus();
   oTxt.select();
}

function SendQuote() {
	IGNORE_UNLOAD = true;
	window.location= "http://www.sicurezza.pro/cart/htdocs/checkout-wiz2-sendquote.asp";
}

//=====================================================================||
//               END NOP Design SmartPost Shopping Cart                ||
//=====================================================================||


//-------------------------------------------------------------------------------------------------


// MAKE PREVENTIVI CHEAPER



// ------------------------------------------------------------------------------------------------



function PC_RemoveFromCart(RemOrder) {
      NumberOrdered = GetCookie("NumberOrdered");
      for ( i=RemOrder; i < NumberOrdered; i++ ) {
         NewOrder1 = "Order." + (i+1);
         NewOrder2 = "Order." + (i);
         database = GetCookie(NewOrder1);
         SetCookie (NewOrder2, database, null, "/");

      }
      NewOrder = "Order." + NumberOrdered;
      SetCookie ("NumberOrdered", NumberOrdered-1, null, "/");
      DeleteCookie(NewOrder, "/");   
}


function PC_ChangeName(iPassedOrder,iPassedNumberOrdered, new_ID_NUM, new_QUANTITY, new_PRICE, new_NAME) {
   var iNumberOrdered = 0;
   var bAlreadyInCart = false;
   var notice = "";
   iNumberOrdered = GetCookie("NumberOrdered");

	//RemoveFromCart(iPassedOrder);
  
    dbUpdatedOrder = new_ID_NUM    + "|" + 
                      new_QUANTITY+ "|" +
                      new_PRICE     + "|" +
                      new_NAME      + "|" +
                      "9"  + "|" +
                      //"prev-wizard";
                      "cheap";
                      // set this field to "" for the new preventivi to catch the changed price 
                      

     strNewOrder = "Order." + iPassedOrder;
     DeleteCookie(strNewOrder, "/");
     SetCookie(strNewOrder, dbUpdatedOrder, null, "/");
    // SetCookie("NumberOrdered", iPassedNumberOrdered, null, "/");
   //  notice = dbUpdatedOrder;
    // alert (notice);
     
   
}

//---------------------------------------------------------------------||
// FUNCTION:    MakePreventiviCheaper									||
// PARAMETERS:  Null                                                   ||
// RETURNS:     Product Table Written to Document                      ||
// PURPOSE:     Draws current cart product table on HTML page          ||
//---------------------------------------------------------------------||
function MakePreventiviCheaper( ) {
   var iNumberOrdered = 0;    //Number of products ordered
   var fTotal         = 0;    //Total cost of order
   var fTax           = 0;    //Tax amount
   var fShipping      = 0;    //Shipping amount
   var strTotal       = "";   //Total cost formatted as money
   var strTax         = "";   //Total tax formatted as money
   var strShipping    = "";   //Total shipping formatted as money
   var strOutput      = "";   //String to be written to page
   var bDisplay       = true; //Whether to write string to the page (here for programmers)
   var my_nopentry	 = "nopentry";
   
    var	remove_WLrip = 0;
	var remove_GASMET= 0;
	var remove_LXDM1ALL = 0;
	var remove_LX98RF = 0;
	var remove_SST59M524 = 0;
	var remove_Omaggio = 0;

// write g_TotalCost to cookie for total money sade calculations
 SetCookie("TotalBefore", g_TotalCost, null, "/");

   iNumberOrdered = GetCookie("NumberOrdered");
   if ( iNumberOrdered == null )
      iNumberOrdered = 0;

   for ( i = 1; i <= iNumberOrdered; i++ ) {
		NewOrder = "Order." + i;
		database = "";
		database = GetCookie(NewOrder);
		
		Token0 = database.indexOf("|", 0);
		Token1 = database.indexOf("|", Token0+1);
		Token2 = database.indexOf("|", Token1+1);
		Token3 = database.indexOf("|", Token2+1);
		Token4 = database.indexOf("|", Token3+1);
		
		fields = new Array;
		fields[0] = database.substring( 0, Token0 );                 // Product ID
		fields[1] = database.substring( Token0+1, Token1 );          // Quantity
		fields[2] = database.substring( Token1+1, Token2 );          // Price
		fields[3] = database.substring( Token2+1, Token3 );          // Product Name/Description
		fields[4] = database.substring( Token3+1, Token4 );          // Shipping Cost
		fields[5] = database.substring( Token4+1, database.length ); //Additional Information
		
		fTotal     += (parseInt(fields[1]) * parseFloat(fields[2]) );
		fShipping  = 9;//(parseInt(fields[1]) * parseFloat(fields[4]) );
		fTax        = (fTotal * TaxRate);
		strTotal    = moneyFormat(fTotal);
		strTax      = moneyFormat(fTax);
		strShipping = moneyFormat(fShipping);
		
	
		// make the preventivi less expensive:
		
		// ChangeName ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		// - if there is the okkio panel, substitute it with the basic one
		if ( fields[0] == "OKKIO_PRO" )	 {	 PC_ChangeName(i,iNumberOrdered,"OKKIO_basic", fields[1], "199", "Centrale di allarme OKKIO") }
		// - if there is the okkio panel DF, substitute it with the basic DF
		if ( fields[0] == "OKKIO_PRO_DF" )	 {	 PC_ChangeName(i,iNumberOrdered,"OKKIO_PRO", fields[1], "289", "Centralina allarme Okkio PRO") }

		if ( fields[0] == "OKKIO_basic_DF" )	 {	 PC_ChangeName(i,iNumberOrdered,"OKKIO_basic", fields[1], "199", "Centrale di allarme OKKIO") }

		// - if there is the st805 panel, put the LEX one
		if ( fields[0] == "OKKIO_basic" )	 {	 PC_ChangeName(i,iNumberOrdered,"LEXHS5-2012", fields[1], "99", "Centralina allarme LEXHS5-2012") }
		// - if present, change the sae16sf / prosir siren with the wlsir
		if ( fields[0] == "SAE16SF" )	 {	 PC_ChangeName(i,iNumberOrdered,"WLSIR", fields[1], "79", "Sirena esterna senza fili con lampeggiante") }
		if ( fields[0] == "PROSIR" )	 {	 PC_ChangeName(i,iNumberOrdered,"WLSIR", fields[1], "79", "Sirena esterna senza fili con lampeggiante") }


		if ( fields[0] == "LEXHS5-2012" )	 {	 PC_ChangeName(i,iNumberOrdered,"ECONOMY", fields[1], "89", "Centralina di allarme ECONOMY") }


		// fs4-v3 to fs4
		// roller to fs4
		// ecsrw to wlsir
		// prosir to wlsir


		// - if present, change the sirnb siren with ecsir
		
		if ( fields[0] == "SIRNB" )	 {	 PC_ChangeName(i,iNumberOrdered,"ECSIR", fields[1], "19", "Sirena esterna piccola filare con lampeggiante") }
		// - if there are the roller remotes, put the lxfs4 ones
		if ( fields[0] == "ROLLER" )	 {	 PC_ChangeName(i,iNumberOrdered,"FS4", fields[1], "12", "Telecomando 4 tasti da borsetta/auto") }
		
		// - if there are lxal8 sensors, change them with st101 sensors
		if ( fields[0] == "AL8" )	 {	 PC_ChangeName(i,iNumberOrdered,"ST101", fields[1], "20", "Sensore di movimento PIR senza fili") }
		if ( fields[0] == "AL8-L" )	 {	 PC_ChangeName(i,iNumberOrdered,"ST101", fields[1], "20", "Sensore di movimento PIR senza fili") }
		if ( fields[0] == "AL8-L2" )	 {	 PC_ChangeName(i,iNumberOrdered,"ST101", fields[1], "20", "Sensore di movimento PIR senza fili") }
		// - if there are lxdm1-col sensors, change them with lxdm1 (white ones)
		if ( fields[0] == "DM1-col" || fields[0] == "METAL-col" || fields[0] == "METAL" )	 {	 PC_ChangeName(i,iNumberOrdered,"DM1", fields[1], "15", "Sensore porte, finestre e tapparelle senza fili") }

		// - if there is the ecsrw siren, change it with wlsir
		if ( fields[0] == "ECSRW" || fields[0] == "TRIPLEX" )	 {	 PC_ChangeName(i,iNumberOrdered,"WLSIR", fields[1], "79", "Sirena esterna senza fili con lampeggiante") }
		
		// - if there are lxfs4-v3 remotes, change them with lxfs4 ones
		if ( fields[0] == "LXFS4-V3" )	 {	 PC_ChangeName(i,iNumberOrdered,"LXFS4", fields[1], "12", "Telecomando 4 tasti da borsetta/auto") }
		// - if there are BASCULA sensors, add the same their amount to lxdm1 and remove bascula
		if ( fields[0] == "BASCULA" )	 {	 PC_ChangeName(i,iNumberOrdered,"LXDM1", fields[1], "15", "Sensore porte, finestre e tapparelle senza fili") } 
		
		
		// marcheaza RemoveFromCart +++++++++++++++++++++++++++++++++++++++++++++++++++++
		// - if present, remove all gas water smoke sensors, wlrip product
		// - if there are SST59M524, remove them
		if ( fields[0] == "WLrip" ) { remove_WLrip = i;	}
		if ( fields[0] == "GASMET" ) {		remove_GASMET= i; }
		if ( fields[0] == "LXDM1-ALL" ) {		remove_LXDM1ALL = i; }
		if ( fields[0] == "LX98RF" ) {		remove_LX98RF = i; }
		if ( fields[0] == "SST59M524" ) {		remove_SST59M524 = i; }
		//if ( fields[0] == "Omaggio" ) {		remove_Omaggio = i; }

}
      
// remove stuff from preventivi marcate -----------------------------------------------
	if ( remove_WLrip > 0) { PC_RemoveFromCart(remove_WLrip) ; }
	if ( remove_GASMET> 0) { PC_RemoveFromCart(remove_GASMET) ; }
	if ( remove_LXDM1ALL > 0) { PC_RemoveFromCart(remove_LXDM1ALL ) ; }
	if ( remove_LX98RF > 0) { PC_RemoveFromCart(remove_LX98RF ) ; }
	if ( remove_SST59M524> 0) { PC_RemoveFromCart(remove_SST59M524) ; }
	if ( remove_Omaggio> 0) { PC_RemoveFromCart(remove_Omaggio) ; }

   	// show the cheaper preventivi
    IGNORE_UNLOAD = true; // set to "true" & let the page reload without triggering on-close procedure
	location.href=location.href;

}

// FUNCTIONS from old nopcart:

function Back_to_Ordina( ) {
	SetCookie( 'Order-back-to-ordina', '3', '', '/', '', '' );
}

function Back_from_mobeye( ) {
	SetCookie( 'Order-back-to-ordina', 'mobeye', '', '/', '', '' );
//	SetCookie( 'Order-back-to-ordina', '3', '', '/', '', '' );
}


function Back_from_PROFCAMX( ) {
	SetCookie( 'Order-back-to-ordina', 'PROFCAMX', '', '/', '', '' );
//	SetCookie( 'Order-back-to-ordina', '3', '', '/', '', '' );

}

function handleEnter (field, event, ids) {
		var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
		if (keyCode == 13) {
			ChangeQuantity(ids, field.value);
//			var i;
//			for (i = 0; i < field.form.elements.length; i++)
//				if (field == field.form.elements[i])
//					break;
//			i = (i + 1) % field.form.elements.length;
//			field.form.elements[i].focus();
			return false;
		} 
		else
		return true;
	}      


function PutMegaCookie ()
{
//if (Discount_main_panel_in_cart == true || DISCOUNT_DF == true || Discount_LEX == true || Discount_OKKIO_basic == true || Discount_OKKIO_PRO == true || Discount_ECONOMY == true) 
	if (g_TotalCost > 1000) 
	{
		if (putMegaCookie == true)
		{
		document.forms[0].action = "managecart-gift.asp";
		// put cookie: goodies = A 
		SetCookie( 'Order-Mega-goodie', 'B', '', '/', '', '' );
		}
		gifttext = "Complimenti!<br>Hai raggiunto almeno 1000 euro di acquisto e potrai scegliere fra gli omaggi aggiuntivi a te riservati dopo aver cliccato su acquista!"; 

	}
	else if (g_TotalCost > 500) 
	{ 
		if (putMegaCookie == true)
		{
		document.forms[0].action = "managecart-gift.asp";
		// put cookie: goodies = A 
		SetCookie( 'Order-Mega-goodie', 'A', '', '/', '', '' );
		}
		gifttext = "Complimenti!<br>Hai raggiunto almeno 500 euro di acquisto e potrai scegliere fra i benefit aggiuntivi a te riservati dopo aver cliccato su acquista!";

	}
	else
	{
		DeleteCookie('Order-Mega-goodie');
	}

}



function DoOnLoadCommonPartStuff() {

if (g_TotalCost > 500 && Discount_KIT_in_cart == true)
{
	PutMegaCookie ();
}

if (g_TotalCost > 500 && Discount_main_panel_in_cart == true) // && diff_products > 3)
{
	PutMegaCookie ();
}

}

function DoOnLoadStuff() {
//Get_Cookie( 'preventivi_wiz' );
if ( GetCookie("preventivi_wiz") == "true" && GetCookie("NumberOrdered") > 0)
{
	//cookie_set = true;
	// wizard
	// set last link
	SetCookie( 'Order-back-link', document.referrer, '', '/', '', '' );

	url="http://www.sicurezza.pro/cart/htdocs/managecart-wiz2.asp";
	location.href=url;
	//Delete_Cookie('test', '/', '');
}
else
{
DoOnLoadCommonPartStuff();
}
}

