
/*function Prodotto(Codice, Descrizione, Prezzo, Numero, Scontato, Peso)
{
	this.Codice = Codice;
	this.Descrizione = Descrizione;
	this.Prezzo = Prezzo;
	this.Numero = Numero;
	this.Scontato= Scontato;
	this.Peso=Peso;
}

function getCookieVal (offset) 
{
   var endstr = document.cookie.indexOf (";", offset);
   if (endstr == -1)
      endstr = document.cookie.length;
   return unescape(document.cookie.substring(offset, endstr));
}

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 "";
}

function DeleteCookie(name)
{
  SetCookie(name, "", -3600, null, null, false);
}*/

function SetCookie (name, value, expires, path, domain, secure)
{
  var expdate = new Date();
  if (expires != null) expdate.setTime(expdate.getTime() + (expires * 1000));

  document.cookie = name + "=" + escape (value) +
  ((expires == null) ? "" : ("; expires=" + expdate.toGMTString())) +
  ((path == null) ? "" : ("; path=" + path)) +
  ((domain == null) ? "" : ("; domain=" + domain)) +
  ((secure == true) ? "; secure" : "");
}

function OrdinaProdotto(Codice,Descrizione,Prezzo,Numero,Scontato,Peso)
{
  var Ordinato = false;
  var verbo,art;
  var msg;
  var indice;
  for (Indice = 0 ; Indice < Carrello.length ; Indice++)
  {
    if (Carrello[Indice] != null)
    {
      if (Carrello[Indice].Codice == Codice)
      {
			msg='Questo prodotto è già stato inserito nel Cestino degli acquisti!';
			msg=msg + '\n\nPer scegliere la quantità da ordinare e completare l\'ordine,';
			msg=msg + '\ncliccate sulla voce \"Cestino\" nel menù principale.';
			alert(msg);
			Ordinato = true;
      }
    }
  }
  if (Ordinato == false)
  {
    if (!confirm('Inserire il prodotto\nnel Cestino degli acquisti?')) return;
    var Nuovo = Carrello.length;
    Carrello[Nuovo] = new Prodotto(Codice,Descrizione,Prezzo,Numero,Scontato,Peso);
	msg="Il prodotto\n\n"+ " \"" + Descrizione + "\"\n\n" + "è stato aggiunto al Cestino degli Acquisti.";
    msg=msg + '\nPer completare l\'ordine, cliccate sulla voce';
    msg=msg + '\n\"Cestino\" nel menù principale.';
    alert(msg);
    AddItem(Nuovo);
  }
}

var durataCookie = 604800; // 1 settimana

function AddItem(Indice)
{
  var CookieValue=GetCookie("ErboristeriaCartValue");
  var car= Carrello[Indice];
  
  CookieValue += "|"+ car.Codice + "!" + car.Descrizione + "!" + car.Prezzo + "!" + car.Numero + "!" + car.Scontato + "!" + car.Peso + "!|";
  SetCookie("ErboristeriaCartValue", CookieValue, durataCookie, null, null, false);

  var TopString = GetCookie("ErboristeriaTopString");
  SetCookie("ErboristeriaTopString", TopString + "|" + car.Codice + "|", durataCookie, null, null, false);
}

function RemoveItem(Indice)
{
  var Value=GetCookie("ErboristeriaCartValue");
  start = Value.indexOf(Carrello[Indice].Codice);
  if (start == -1) return;
  end=start;
  while((Value.charAt(end) != '|') && (end<Value.length-1)) end++;
  var NewValue=Value.substring(0,start-1) + Value.substring(end+1,Value.length);
  if (NewValue=="") DeleteCookie("ErboristeriaCartValue");
  else SetCookie("ErboristeriaCartValue", NewValue, durataCookie, null, null, false);

  TopString= GetCookie("ErboristeriaTopString");
  start = TopString.indexOf(Carrello[Indice].Codice);
  if (start == -1) return;
  end=start;
  while((TopString.charAt(end) != '|') && (end<TopString.length-1)) end++;
  var NewTopString=TopString.substring(0,start-1) + TopString.substring(end+1,TopString.length);
  if (NewTopString=="") DeleteCookie("ErboristeriaTopString");
  else SetCookie("ErboristeriaTopString", NewTopString, durataCookie, null, null, false);
}

function TrailZero(valore)
{
  var temp=valore.toString();
  if (temp.indexOf(".")==-1) return(temp+".00");
  if (temp.length-temp.indexOf(".")==2) return(temp+"0");
  else return(temp);
}

function EliminaProdotto(Numero)
{
  var TopString="",NewTopString="";
  if (confirm('Eliminare dal Cestino?'))
  {
    RemoveItem(Numero);
    Carrello[Numero] = null;
    location.href="cestino.php";
  }
}

function SvuotaCestino()
{
  if (confirm('Eliminare tutti i prodotti dal Cestino?'))
  {
    var car=Carrello;
    if (car!= null)
      for (var Indice = 0 ; Indice <= car.length ; Indice++)
        if (car[Indice] != null) car[Indice]=null;
    DeleteCookie("ErboristeriaTopString");
    DeleteCookie("ErboristeriaCartValue");
    location.href="cestino.php";
  }
}

function GetDestSelects()
{
	SaveDest=document.Ordine1.Paese.selectedIndex;
	SaveStato=document.Ordine1.Stato.selectedIndex;
}

function SetDestSelects()
{
	document.Ordine1.Paese.selectedIndex=SaveDest;
}

function GetPaySelects()
{
	SaveSped=document.Ordine1.Sped.selectedIndex;
	SavePagam=document.Ordine1.Pagamento.selectedIndex;
}

function SetPaySelects()
{
	document.Ordine1.Sped.selectedIndex=SaveSped;
	document.Ordine1.Pagamento.selectedIndex=SavePagam;
}

function DelSaved()
{
	SaveStato=0;
	SaveSped=0;
	SavePagam=0;
}

function Over()
{
	alert("Peso dei prodotti eccessivo per la destinazione scelta, impossibile spedire!\nRidurre i prodotti nel cestino per continuare.");
	document.Ordine1.Bottone.disabled=true;
}

function QuickPack_enabled()
{
	P=document.Ordine1.Stato.selectedIndex;
	if ((P==3) || (P==5) || (P==10) || (P==12) || (P==13) || (P==14) || (P==16) || (P==18) || (P==23) || (P==30) || (P==31) || (P==33) || (P==41) || (P==42) || (P==43))
		return true;
	else return false;
}

function SetPrices(Totale)
{
	var pmax="0", dmax="0", contrass="0"; spese_post="0";
	document.Ordine1.Bottone.disabled=false;
	if (document.Ordine1.Paese.selectedIndex!=0)
	{
		tipo_sped="Estero";
		if (document.Ordine1.Paese.selectedIndex==1) // Europa
		{
			// *** Raccomandata ***
			if (document.Ordine1.PesoTotale.value<1000) { spese_post="13.00"; pmax="1"; dmax="Somma lati 90 cm. Lato lungo 60 cm."; }
			else if (document.Ordine1.PesoTotale.value<2000) { spese_post="19.00"; pmax="2"; dmax="Somma lati 90 cm. Lato lungo 60 cm."; }
			else
			{
				dmax="Somma lati 225 cm. Lato lungo 150 cm.";
				if (QuickPack_enabled())
				{
					// *** Quick Pack ***
					if (document.Ordine1.PesoTotale.value<3000) { spese_post="27.00"; pmax="3"; }
					else if (document.Ordine1.PesoTotale.value<5000) { spese_post="31.00"; pmax="5"; }
					else if (document.Ordine1.PesoTotale.value<15000) { spese_post="48.00"; pmax="15"; }
					else if (document.Ordine1.PesoTotale.value<30000) { spese_post="65.00"; pmax="30"; }
					else { Over(); return; }
					// *** Norvegia o Svizzera ***
					if ((document.Ordine1.Stato.selectedIndex==30) || (document.Ordine1.Stato.selectedIndex==43))
						spese_post=TrailZero(Math.round((8+parseFloat(spese_post))*100)/100);
				}
				else
				{
					// *** Paccocelere Internazionale - scaglione minimo - 2 Kg ***
					spese_post="75.00"; pmax="-1"; dmax="Da verificare.";
				}
			}
		}
		else if (document.Ordine1.Paese.selectedIndex==2) // Bacino del Mediterraneo
		{
			// *** Raccomandata ***
			if (document.Ordine1.PesoTotale.value<1000) { spese_post="13.00"; pmax="1"; dmax="Somma lati 90 cm. Lato lungo 60 cm."; }
			else if (document.Ordine1.PesoTotale.value<2000) { spese_post="19.00"; pmax="2"; dmax="Somma lati 90 cm. Lato lungo 60 cm."; }
			else
			{
				// *** Ordinario internazionale ***
				if (document.Ordine1.PesoTotale.value<5000) { spese_post="30.00"; pmax="5"; "Lato lungo + giro max 200 cm. Lato lungo 100 cm."; }
				// *** Paccocelere Internazionale - scaglione minimo - 2 Kg ***
				else { spese_post="75.00"; pmax="-1"; dmax="Da verificare."; }
			}
		}
		else if (document.Ordine1.Paese.selectedIndex==3 || document.Ordine1.Paese.selectedIndex==4 || document.Ordine1.Paese.selectedIndex==5) // Americhe, Asia, Africa
		{
			 dmax="Somma lati 90 cm. Lato lungo 60 cm.";
			// *** Raccomandata ***
			if (document.Ordine1.PesoTotale.value<1000) { spese_post="18.00"; pmax="1"; }
			else if (document.Ordine1.PesoTotale.value<2000) { spese_post="29.00"; pmax="2"; }
			else if (document.Ordine1.PesoTotale.value<4000) { spese_post="58.00"; pmax="4"; }
			else { Over(); return; }
		}
		else // Oceania
		{
			 dmax="Somma lati 90 cm. Lato lungo 60 cm.";
			// *** Raccomandata ***
			if (document.Ordine1.PesoTotale.value<1000) { spese_post="24.00"; pmax="1"; }
			else if (document.Ordine1.PesoTotale.value<2000) { spese_post="34.00"; pmax="2"; }
			else if (document.Ordine1.PesoTotale.value<4000) { spese_post="68.00"; pmax="4"; }
			else { Over(); return; }
		}
	}
	else // Italia
	{
		if (document.Ordine1.Sped.selectedIndex==1)
		{
			tipo_sped="Celere3"; 
			if (document.Ordine1.Pagamento.selectedIndex==2) spese_post="3.95";
			else if (document.Ordine1.Pagamento.selectedIndex > 0) spese_post="5.45";
			if (document.Ordine1.Pagamento.selectedIndex==1) contrass="3.00";
			else contrass="0";
		}
		else if (document.Ordine1.Sped.selectedIndex==2)
		{
			spese_post="9.70"; tipo_sped="Celere1";
			if (document.Ordine1.Pagamento.selectedIndex==1) contrass="4.60";
			else contrass="0";
		}
		else { spese_post=0; tipo_sped=""; contrass="0"; }
		if (parseFloat(Totale) >= 75) 
		{
			spese_post="0";
		}
	}
	document.Ordine1.Spese.value=spese_post;
	document.Ordine1.Contrass.value=contrass;
	if (parseFloat(contrass)>0) ShowContr();
	else HideContr();
	document.Ordine1.Totale.value=TrailZero(Math.round((parseFloat(Totale)+parseFloat(spese_post)+parseFloat(contrass))*100) / 100);
	document.Ordine1.TipoSpedizione.value=tipo_sped;
	document.Ordine1.PesoMax.value=pmax;
	document.Ordine1.DimensMax.value=dmax;
}

function ShowContr()
{
	if (document.all) { document.all.Contr.style.visibility='visible'; document.all.Contr2.style.visibility='visible'; }
	else if (document.layers) { document.layers.Contr.visibility='show'; document.layers.Contr2.visibility='show'; }
	else if (document.getElementById) { document.getElementById('Contr').style.visibility='visible'; document.getElementById('Contr2').style.visibility='visible'; }
}

function HideContr()
{
	if (document.all) { document.all.Contr.style.visibility='hidden'; document.all.Contr2.style.visibility='hidden'; }
	else if (document.layers) { document.layers.Contr.visibility='hide'; document.layers.Contr2.visibility='hide'; }
	else if (document.getElementById) { document.getElementById('Contr').style.visibility='hidden'; document.getElementById('Contr2').style.visibility='hidden'; }
}

function Formatta(prezzo)
{
//  var risult="",temp="";
//  var ind,cont=0;
//  temp=prezzo.toString();
//  ind=temp.length;
//  for (i=ind-1; i>=0; i--)
//  {
//    if (cont<3) { risult+=temp.charAt(i); cont++; }
//    else { risult+="."+temp.charAt(i); cont=1; }
//  }
//  cont=risult.length-1; temp="";
//  while (cont>=0) temp+=risult.charAt(cont--);
//  return(temp);

  return(prezzo); 
}

function aggiornaFormQuantita()
{
  var count=1;
  var FormName="";
  for (var Ind = 0 ; Ind < Carrello.length ; Ind++)
  {
    if (Carrello[Ind] != null)
    {
      FormName="Quant"+count; 
      document.forms[FormName].Quantita.selectedIndex=Carrello[Ind].Numero-1;
      count++;
    }
  }
}

function AggiornaCarrello()
{
  var count=1;
  var FormName="",cookieValue="";
  for (var Ind = 0 ; Ind < Carrello.length ; Ind++)
  {
    if (Carrello[Ind] != null)
    {
      FormName="Quant"+count;
      Carrello[Ind].Numero=document.forms[FormName].Quantita.selectedIndex+1;
      RemoveItem(Ind); AddItem(Ind);
      count++;
    }
  }
  location.href="cestino.php";
}

function p_interr(testo,titolo)
{
	parametri=",LEFT,WIDTH,260";
	if (titolo!="") parametri+=",CAPTION,'"+titolo+"'";
	if (testo=="") return "<td>&nbsp;</td>";
	else return "<td><a href=\"javascript:void(0);\" onmouseout=\"nd()\" onmouseover=\"return overlib("+testo+parametri+")\"><img src='imgs/punto_interrogativo.gif' width='15' height='15' border='0'></a></td>";
}

function GetCode()
{
	alt=260;
	largh=350;
	leftPos = (screen.width) ? (screen.width-largh)/2 : 300;
	topPos = (screen.height) ? (screen.height-alt)/2 : 200;
	settings='width='+largh+',height='+alt+',top='+topPos+',left='+leftPos+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes'
	window.open('codice_cliente.php','sendwin',settings);
}

function writeSped(country)
{
	if (country=="Italia")
		//Spediz = new Array("no", "----- Scegli -----", "Celere3", "Standard (3-4 giorni lavorativi)", "Celere1", "Celere (1-2 giorni lavorativi)");
		Spediz = new Array("no", "----- Scegli -----", "Celere3", "Standard (3-4 giorni lavorativi)");
	else
		Spediz = new Array("Estero", "Pacco Internazionale");
	document.Ordine1.Sped.length = 0;
	for (i=0; i<Spediz.length/2; i++)
	{
		document.Ordine1.Sped.length++;
		thisEntry = Spediz[2*i+1];
		newOption = new Option(thisEntry);
		newOption.value = Spediz[2*i];
		document.Ordine1.Sped.options[i] = newOption;
	}
	document.Ordine1.Sped.options[0].selected = true;
}

function writePagam(country)
{
	if (country=="Italia")
		Pagam=new Array("no", "----- Scegli -----", "Contrassegno", "Contrassegno (contanti alla consegna)", "Carta", "Carta di Credito o Prepagata", "Bollettino", "Bollettino postale anticipato", "Bonifico", "Bonifico anticipato");
	else
		Pagam=new Array("no", "----- Scegli -----", "Carta", "Carta di Credito (Credit Card)", "Western", "Western Union", "Bonifico", "Bonifico (Bank Transfer)");
	document.Ordine1.Pagamento.length = 0;
	for (i=0; i<Pagam.length/2; i++)
	{
		document.Ordine1.Pagamento.length++;
		thisEntry = Pagam[2*i+1];
		newOption = new Option(thisEntry);
		newOption.value = Pagam[2*i];
		document.Ordine1.Pagamento.options[i] = newOption;
	}
	document.Ordine1.Pagamento.options[0].selected = true;
}

function DinamicSelects(country)
{
	newcountry = country.replace(/[^0-9a-zA-Z]/g,'');
	newcountry = newcountry.replace(/\'/g,'');
	if (newcountry.length == 0)
	{
		document.Ordine1.Stato.length = 1;
		document.Ordine1.Stato.options[0] = new Option('---');
		document.Ordine1.Stato.options[0].value = '';
		return;
	}
	if (newcountry=='Italia')
	{
		document.Ordine1.Stato.length = 1;
		document.Ordine1.Stato.options[0] = new Option('');
		document.Ordine1.Stato.options[0].value = '';
		document.Ordine1.Stato.disabled=true;
	}
	else
	{
		document.Ordine1.Stato.disabled=false;
		newOptions = eval(newcountry+'Array');
		document.Ordine1.Stato.length = 1;
		document.Ordine1.Stato.options[0] = new Option('Scegli uno Stato/Choose Country');
		document.Ordine1.Stato.options[0].value = '';
		document.Ordine1.Stato.options[0].selected = true;

		for (i=0; i<newOptions.length; i++)
		{
			document.Ordine1.Stato.length++;
			thisEntry = newOptions[i];
			newOption = new Option(thisEntry);
			newOption.value = thisEntry;
			document.Ordine1.Stato.options[i+1] = newOption;
		}
		if(newOptions.length == 1) document.Ordine1.Stato.options[1].selected = true;
	}
	writeSped(country);
	writePagam(country);
	SetPrices(document.Ordine1.CostoProdotti.value);
	document.Ordine1.Stato.selectedIndex=SaveStato;
}

function VisualizzaOrdine ()
{
  var msg,TotForm="";
  var Vuoto=true;
  var Totale=0, PesoTotale=0;
  var count=0,TabIndexCount=1;
  var ConfRegalo=false;

  for (var Indice = 0 ; Indice < Carrello.length ; Indice++)
    if (Carrello[Indice] != null) Vuoto = false;
  if (Vuoto)
  {
    msg='<div align=center><center><font face=\"Verdana,Arial\" size=\"2\" color=\"#004000\"><strong>';
    msg=msg+ 'Il Cestino è vuoto.</strong></font></center></div>';
    document.write(msg);
    return;
  }

  document.write('<div align=center><center><font face=\"Verdana,Arial\" size=\"2\" color=\"#004000\"><strong>');
  document.write('Contenuto del cestino:</strong></font></center></div><br>');

  document.write("<div align=\"center\"><center><table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"");
  document.write('bordercolor=\"#008000\" bordercolordark=\"#008000\" bordercolorlight=\"#008000\"><tr>');
  document.write('<td align=\"center\" nowrap><font color=\"#E67300\" size=\"3\" face=\"Verdana,Arial\"><strong>Prodotto</strong></font></td>');
  document.write('<td align=\"center\" nowrap><font color=\"#E67300\" size=\"3\" face=\"Verdana,Arial\"><strong>Importo</strong></font></td>');
  document.write('<td align=\"center\" nowrap><font color=\"#E67300\" size=\"3\" face=\"Verdana,Arial\"><strong>Quantità</strong></font></td>');
  document.write('<td align=\"center\" nowrap><font color=\"#E67300\" size=\"3\" face=\"Verdana,Arial\"><strong>Totale</strong></font></td>');
  document.write('<td align=\"center\" nowrap><font color=\"#E67300\" size=\"2\" face=\"Verdana,Arial\"><strong>Cancella</strong></font></td></tr>');

  count=1;
  for (var Ind = 0 ; Ind < Carrello.length ; Ind++)
  {
    if (Carrello[Ind] != null)
    {
      document.write('<tr><td align=\"center\" nowrap><font color=\"#008000\" size=\"2\" face=\"Verdana,Arial\"><strong>');
      document.write('<a alt=\"Dettagli sul prodotto\" title=\"Dettagli sul prodotto\" href=\"prodotto.php?code='+Carrello[Ind].Codice+'\"><img src=\"imgs/lente_picc.gif\" border=\"0\" align=\"absmiddle\" alt=\"Dettagli sul prodotto\" width=\"14\" height=\"17\">'+Carrello[Ind].Descrizione+'</a></strong></font></td>');
      document.write('<td align=\"center\" nowrap><font color=\"#008000\" size=\"2\" face=\"Verdana,Arial\"><img src=\"imgs/euro10pt.gif\" alt=\"Euro\" width=\"9\" height=\"9\"> '+TrailZero(Carrello[Ind].Prezzo)+'</font></td>');
      document.write('<td align=\"center\" nowrap><font color=\"#008000\" size=\"1\" face=\"Verdana,Arial\"><br><form method=\"POST\" name=\"Quant'+count+'\"><select name=\"Quantita\" size=\"1\" style=\"font-family:verdana,arial; font-size:8pt;\" onchange=\"javascript:AggiornaCarrello()\">');
      document.write('<option>1</option><option>2</option><option>3</option><option>4</option><option>5</option>');
      //document.write('<option>1</option><option>2</option><option>3</option><option>4</option><option>5</option><option>6</option><option>7</option><option>8</option><option>9</option><option>10</option>');
      document.write('</select><input type=\"hidden\" name=\"Indice\" value=\"' + Ind + '\"></form>');

      document.write('</font></td>');
      document.write('<td align=\"center\" nowrap><font color=\"#008000\" size=\"2\" face=\"Verdana,Arial\">');
      document.write('<img src=\"imgs/euro10pt.gif\" alt=\"Euro\" width=\"9\" height=\"9\"> ');
      TotaleItem=parseInt(Carrello[Ind].Numero) * Carrello[Ind].Prezzo;
      TotaleItem=Math.round(TotaleItem * 100) / 100;
      document.write(TrailZero(TotaleItem)+'</font></td>');
      document.write('<td align=\"center\"><a href=\"javascript:EliminaProdotto('+Ind+')\">');
      document.write('<img src=\"imgs/cestino1.gif\" alt=\"Elimina il prodotto dal Cestino\" border=\"0\" width=\"30" height=\"28\"></a></td>');
      Totale=Totale+(parseInt(Carrello[Ind].Numero) * Carrello[Ind].Prezzo);
      PesoTotale=PesoTotale +(parseInt(Carrello[Ind].Numero) * Carrello[Ind].Peso);
      
      if ((Carrello[Ind].Codice>'2000') && (Carrello[Ind].Codice<'3000')) ConfRegalo=true;
      
      count++;
    }
  }
  Totale=Math.round(Totale * 100) / 100;
  TotForm=TrailZero(Formatta(Totale));
  PesoTotale=Math.round(PesoTotale*1.15 + 250);
  PesoFormatt=Math.round(PesoTotale * 10) / 10000;
  
  document.write('</tr></table></center></div>');
  document.write('<table width=\"100%\"><tr><td nowrap><h4 style=\"text-align:left\"><font color=\"#005000\"><br>Totale articoli ordinati: ');
  document.write('<img src=\"imgs/euro10ptdark.gif\" alt=\"Euro\" width=\"9\" height=\"9\"> '+TotForm+'<br>');
  //document.write('Peso del pacco: '+PesoFormatt+' Kg<br>');
  if (Totale<15)
  {
    document.write('L\'ordine minimo è di <img src=\"imgs/euro10ptdark.gif\" alt=\"Euro\" width=\"9\" height=\"9\"> 15');
    aggiornaFormQuantita();
  }
  document.write('</font></h4>');
  document.write('</td><td align=\"right\" valign=\"top\" nowrap>');
  document.write('<a href=\"javascript:SvuotaCestino()\" class=\"L4\"><br>SVUOTA CESTINO</a>');
  document.write('</td></tr>');
  document.write('</table>');
  if (Totale<15) return;

  document.write("<h4>Per completare l'ordine degli articoli contenuti nel cestino, compila il modulo qui sotto con i tuoi dati.</h4>");
  document.write("<h4>Se è la prima volta che fai un ordine su questo sito, compila il modulo per intero, lasciando vuoto il codice cliente.<br>In caso contrario, è sufficiente inserire l'indirizzo e-mail e il 'Codice cliente' ricevuto in occasione del primo acquisto, evitando così di dover immettere tutti i dati ogni volta.</h4>");
  document.write("<h4>Infine, clicca su 'Continua' per visualizzare il riepilogo dell'ordine e dare la conferma definitiva. Fatto questo, entro pochi minuti riceverai un'e-mail che ti confermerà che l'invio dei dati è andato a buon fine.<br>");
  document.write("Entro 1-2 giorni lavorativi riceverai, sempre per e-mail, la conferma dell'evasione dell'ordine.<br>");
  document.write("Tutti i prodotti ordinati saranno accompagnati da complete e dettagliate istruzioni d'uso e da numerosi depliant informativi e campioni omaggio.<br>");
  document.write("Per qualunque problema o informazione, ");
  document.write("<a href=\"contatti.php\" class=\"L2\"><font color=\"#005000\">contattaci</font></a>.</h4>");

  document.write("<hr color=\"#008000\"><br>");
  
  document.write("<form action=\"ordine_riepilogo.php\" method=\"post\" name=\"Ordine1\" onsubmit=\"return VerificaForm()\">");
  count=0;
  for (var Ind = 0 ; Ind < Carrello.length ; Ind++)
    if (Carrello[Ind] != null) count++;
  document.write("<input type=\"hidden\" name=\"NumeroProdotti\" value=\"" + count + "\">");
  //document.write("<input type=\"hidden\" name=\"TotaleOrdine\" value=\"" + Totale + "\">");
  document.write("<input type=\"hidden\" name=\"TipoSpedizione\" value=\"Ordinaria\">");
  document.write("<input type=\"hidden\" name=\"PesoTotale\" value='"+PesoTotale+"'>");
  document.write("<input type=\"hidden\" name=\"PesoMax\" value=\"0\">");
  document.write("<input type=\"hidden\" name=\"DimensMax\" value=\"0\">");
  count=1;
  for (var Ind = 0 ; Ind < Carrello.length ; Ind++)
  {
    if (Carrello[Ind] != null)
    {
      document.write("<input type=\"hidden\" name=\"CodiceProdotto" +count+ "\" value=\"" +Carrello[Ind].Codice+ "\">");
      document.write("<input type=\"hidden\" name=\"Prodotto" +count+ "\" value=\"" +Carrello[Ind].Descrizione+ "\">");
      document.write("<input type=\"hidden\" name=\"Quantita" +count+ "\" value=\"" +Carrello[Ind].Numero+ "\">");
      document.write("<input type=\"hidden\" name=\"Prezzo" +count+ "\" value=\"" + (Math.round(Carrello[Ind].Prezzo*Carrello[Ind].Numero * 100) / 100)+ "\">");
      document.write("<input type=\"hidden\" name=\"Scontato" +count+ "\" value=\"" +Carrello[Ind].Scontato+ "\">");
      count++;
    }
  }

  spieg_codice="Se sei già nostro cliente, inserisci solo il tuo codice e l'e-mail, lasciando vuoti gli altri campi (salvo che tu voglia indicare un indirizzo di consegna differente).";
  spieg_comm="Inserisci qui qualsiasi informazione utile, ad esempio il nome presente sul citofono se diverso dal tuo, o il nome dell'azienda se hai inserito l'indirizzo del lavoro, e inoltre qualsiasi richiesta o comunicazione riguardante l'ordine.";
  spieg_convenzioni="Se hai un buono sconto, o fai parte di un ente o sito web convenzionato con noi, inserisci in questo campo il codice del buono o il numero di tessera. Nella pagina di riepilogo dell'ordine, prima della conferma dello stesso, verrà calcolato l'importo scontato.";
  //messaggio_laterale="<td rowspan='23' align='center' valign='top' width='200'><h5><span style='color:red'>AVVISO IMPORTANTE:<br>Se stai per andare in ferie, comunicaci la data prevista per la partenza, scrivendola nello spazio \"Commenti\" del modulo d'ordine. Questo ci consentirà di organizzare al meglio la spedizione, evitando qualunque disguido, oppure di proporti una soluzione alternativa.<br><br>Gli ordini ricevuti o pagati tra sabato 11 e domenica 26 Agosto verranno spediti a partire da lunedì 27 Agosto.</span></h5></td>";
  //messaggio_laterale="<td rowspan='23' align='center' valign='top' width='200'><h5><span style='color:red'>AVVISO IMPORTANTE:<br>Se stai per andare in ferie, comunicaci il periodo in cui sarai assente, scrivendolo nello spazio \"Commenti\" del modulo d'ordine. Questo ci consentirà di organizzare al meglio la spedizione, evitando qualunque disguido, oppure di proporti una soluzione alternativa.</span></h5></td>";
  //messaggio_laterale="<td rowspan='23' align='center' valign='top' width='200'><h5><span style='color:red'>AVVISO IMPORTANTE:<br>Se desideri ricevere gli articoli ordinati entro Natale, ti suggeriamo di utilizzare la spedizione celere.</span></h5></td>";
  //messaggio_centrale="<h4><div style='color:red; text-align:center;'>AVVISO IMPORTANTE:<br>Gli ordini ricevuti da Venerdì 14 a Martedì 18 Agosto saranno spediti a partire da Mercoledì 19 Agosto.</div></h4>";
  messaggio_laterale="<td rowspan='24' align='center' valign='top' width='220' style='padding-top:435px;'><h5><div style='color:red; border:1px solid #008000; padding:3px;'>Solo 3.95 euro di spese postali<br>se paghi con carta di credito!</div><br><div style='color:red; border:1px solid #008000; padding:3px; margin-top:20px;'>Spese postali gratuite<br>per ordini oltre i 75 euro!</div><div style='color:red; padding:3px; margin-top:20px;'>(Offerte valide per le spedizioni in Italia)</div></h5></td>";
  messaggio_centrale="";
  //messaggio_laterale="";
  
  document.write(messaggio_centrale);
  document.write("<div align='center'><center><table border='0' cellpadding='2' cellspacing='0'>");
  document.write("<tr>"+p_interr("spieg_codice","Codice cliente")+"<td valign='top' nowrap class='C2'>Codice cliente<br><div style='font-weight: normal; font-size: 8pt;'>(solo se già clienti)</div></td>");
	document.write("<td colspan='1'><input type=\"text\" size=\"6\" maxlength=\"6\" name=\"Codice\" tabindex='"+(TabIndexCount++)+"'></td><td align='left' colspan='2'><a href=\"javascript:GetCode();\" class='L4'>Ricordami<br>il codice</a></td>"+messaggio_laterale+"</tr>");
  
  document.write("<tr>"+p_interr("","")+"<td class=\"C2\">E-mail</td><td colspan='3'><input type=\"text\" size=\"25\" name=\"Email\" tabindex='"+(TabIndexCount++)+"'></td></tr>");
  document.write("<tr>"+p_interr("","")+"<td class='C2'>Nome</td><td colspan='3'><input type='text' size='25' name='Nome' tabindex='"+(TabIndexCount++)+"'></td></tr>");
  document.write("<tr>"+p_interr("","")+"<td class='C2'>Cognome</td><td colspan='3'><input type='text' size='25' name='Cognome' tabindex='"+(TabIndexCount++)+"'></td></tr>");
  document.write("<tr>"+p_interr("","")+"<td class='C2'>Sesso</td><td colspan='3' class='C2'><input type='radio' name='Sesso' value='1' tabindex='"+(TabIndexCount++)+"'>M&nbsp;&nbsp;&nbsp;<input type='radio' name='Sesso' value='2'>F</td></tr>");
  
  //document.write("<tr>"+p_interr("","")+"<td class='C2'>Nome sul citofono<div style='font-weight: normal; font-size: 8pt;'>(solo se diverso dal vostro)</div></td><td colspan='3'><input type='text' size='20' name='Citofono' tabindex='"+(TabIndexCount++)+"'></td></tr>");
  document.write("<tr>"+p_interr("","")+"<td class='C2'>Codice Fiscale</td><td colspan='3'><input type='text' size='25' name='CF' tabindex='"+(TabIndexCount++)+"'></td></tr>");
  document.write("<tr>"+p_interr("","")+"<td class='C2'>Partita IVA</td><td colspan='3'><input type='text' size='25' name='PIVA' tabindex='"+(TabIndexCount++)+"'></td></tr>");
  document.write("<tr>"+p_interr("","")+"<td class='C2'>Indirizzo di consegna</td><td colspan='3'><input type='text' size='25' name='Indirizzo' tabindex='"+(TabIndexCount++)+"'></td></tr>");
  document.write("<tr>"+p_interr("","")+"<td class='C2'>Città</td><td colspan='3'><input type='text' size='25' name='Citta' tabindex='"+(TabIndexCount++)+"'></td></tr>");
  document.write("<tr>"+p_interr("","")+"<td class='C2'>Provincia</td><td><input type='text' size='2' name='Provincia' tabindex='"+(TabIndexCount++)+"'></td>");
  document.write("<td class='C2'>Cap</td><td class='C2'><input type='text' size='6' name='Cap' tabindex='"+(TabIndexCount++)+"'></td></tr>");

  document.write("<tr>"+p_interr("","")+"<td class='C2'>Destinazione</td><td colspan='3' class='C2'><select name='Paese' size='1' tabindex='"+(TabIndexCount++)+"' onChange=\"javascript:DelSaved(); DinamicSelects(this.options[selectedIndex].value); GetDestSelects();\"><option value='Italia' selected>Italia</option><option value='Europa'>Europe</option><option value='Mediterraneo'>Middle East and Mediterranean area</option><option value='Americhe'>North/South America</option><option value='Asia'>Asia</option><option value='Africa'>Africa</option><option value='Oceania'>Australian continent (Oceania)</option></select></td></tr>");
  document.write("<tr>"+p_interr("","")+"<td class='C2'>Stato<br><div style='font-weight: normal; font-size: 8pt;'>(solo per ordini dall'estero)</div></td><td colspan='3' class='C2'><select name='Stato' tabindex='"+(TabIndexCount++)+"' onChange=\"javascript:GetDestSelects(); SetPrices(document.Ordine1.CostoProdotti.value);\" disabled><option value=''></option></select></td></tr>");

	document.write("<tr>"+p_interr("","")+"<td class='C2'>Telefono fisso</td><td colspan='2'><input type='text' size='15' name='Telefono' tabindex='"+(TabIndexCount++)+"'></td><td class='C2' rowspan='2'><img src='imgs/barrette.gif' align='left'><span style='font-size:8pt'>Indicarne almeno uno<br>(meglio se entrambi)</span></td></tr>");
	document.write("<tr>"+p_interr("","")+"<td class='C2'>Cellulare</td><td colspan='2'><input type='text' size='15' name='Cell' tabindex='"+(TabIndexCount++)+"'></td></tr>");

  if (navigator.appName=="Microsoft Internet Explorer")
    document.write("<tr>"+p_interr("spieg_comm","Commenti")+"<td class=\"C2\">Commenti<br><div style='font-weight: normal; font-size: 8pt;'>(opzionale)</div></td><td colspan='3'><textarea name=\"Commenti\" rows=\"3\" cols=\"30\" style=\"font-family: verdana,arial;\" tabindex='"+(TabIndexCount++)+"'></textarea></td></tr>");
  else document.write("<tr>"+p_interr("spieg_comm","Commenti")+"<td class=\"C2\">Commenti<br><div style='font-weight: normal; font-size: 8pt;'>(opzionale)</div></td><td colspan='3'><textarea name=\"Commenti\" rows=\"3\" cols=\"30\" tabindex='"+(TabIndexCount++)+"'></textarea></td></tr>");

  //document.write("<tr>"+p_interr("","")+"<td class='C2'><br>Spedizione</td><td colspan='3' class=\"C2\"><br><select name='Sped' size='1' onChange=\"javascript:GetPaySelects(); SetPrices(document.Ordine1.CostoProdotti.value)\" tabindex='"+(TabIndexCount++)+"'><option selected value='no'>----- Scegli -----</option><option value='Celere3'>Pacco Celere 3 giorni</option><option value='Celere1'>Pacco Celere 1 giorno</option><option value='Ordinario'>Pacco Ordinario</option></select></td></tr>");
  document.write("<tr>"+p_interr("","")+"<td class='C2'><br>Spedizione</td><td colspan='3' class=\"C2\"><br><select name='Sped' size='1' onChange=\"javascript:GetPaySelects(); SetPrices(document.Ordine1.CostoProdotti.value)\" tabindex='"+(TabIndexCount++)+"'></select></td></tr>");

  document.write("<tr>"+p_interr("","")+"<td class='C2'>Pagamento</td><td class='C2' colspan='3'><select name='Pagamento' size='1' onChange=\"javascript:GetPaySelects(); SetPrices(document.Ordine1.CostoProdotti.value); document.Ordine1.Condizioni.focus();\" tabindex='"+(TabIndexCount++)+"'><option selected value='no'>----- Scegli -----</option><option>Contrassegno</option><option value='Carta'>Carta di credito</option><option value='Bollettino'>Bollettino postale anticipato</option><option value='Bonifico'>Bonifico anticipato</option></select>");

  document.write("<tr>"+p_interr("","")+"<td class='C2'>Costo Prodotti</td><td class='C2' colspan='3'><input type='text' size='6' name='CostoProdotti' value='" + TrailZero(Totale) + "' readonly onfocus=\"this.blur()\"> Euro</td></tr>");
  document.write("<tr>"+p_interr("","")+"<td class='C2'>Spese postali</td><td class='C2' colspan='3'><input type='text' size='6' name='Spese' value='' readonly onfocus=\"this.blur()\"> Euro</td></tr>");
  document.write("<tr>"+p_interr("","")+"<td class='C2'><div id='Contr'>Contrassegno</div></td><td class='C2' colspan='3'><div id='Contr2'><input type='text' size='6' name='Contrass' value='' readonly onfocus=\"this.blur()\"> Euro</div></td></tr>");
  document.write("<tr>"+p_interr("","")+"<td class='C2'>Totale ordine</td><td class='C2' colspan='3'><input type='text' size='6' name='Totale' readonly onfocus=\"this.blur()\"> Euro (IVA compresa)</td></tr>");
  document.write("<tr>"+p_interr("spieg_convenzioni","Buoni sconto e Convenzioni")+"<td class='C2'>Buoni Sconto<br>e <a href=\"convenzioni.php\" class=\"L2\" title=\"Visualizza convenzioni attive\" alt=\"Visualizza convenzioni attive\">Convenzioni</a></td><td colspan='3'><input type='text' size='20' name='Convenzioni' tabindex='"+(TabIndexCount++)+"'></td></tr>");

  if (ConfRegalo)
  {
    document.write("<tr>"+p_interr("","")+"<td colspan='4' class=\"C2\"><br><input type=\"checkbox\" name=\"ConfRegalo\" value=\"ON\" tabindex='"+(TabIndexCount++)+"'>Richiedo la confezione Regalo (Gratuita).</td></tr>");
    CRegSpace="";
  }
  else CRegSpace="<br>";
    
  document.write("<tr>"+p_interr("","")+"<td colspan='4' class=\"C2\">"+CRegSpace+"<input type=\"checkbox\" checked name=\"Condizioni\" value=\"ON\" tabindex='"+(TabIndexCount++)+"'>Dichiaro di aver letto e approvato<br> le <a href=\"condizioni.php\" class=\"L2\"><font color=\"#005000\">Condizioni di Vendita</font></a>.</td></tr>");
  document.write("<tr>"+p_interr("","")+"<td colspan='4' class=\"C2\"><input type=\"checkbox\" checked name=\"Newsletter\" value=\"ON\" tabindex='"+(TabIndexCount++)+"'>Vorrei ricevere la Newsletter mensile.</td></tr>");
  document.write("<tr>"+p_interr("","")+"<td colspan='4' class=\"C2\"><input type=\"checkbox\" checked name=\"Privacy\" value=\"ON\" tabindex='"+(TabIndexCount++)+"'>Do il consenso al trattamento dei miei dati<br>personali (vedi <a href=\"condizioni.php#Privacy\" class=\"L2\"><font color=\"#005000\">Informativa sulla privacy</font></a>).</td></tr>");

  document.write("<tr>"+p_interr("","")+"<td align=\"center\" colspan='4'>");
  document.write("<br><input type=\"submit\" name=\"Bottone\" value=\"Continua ->\" tabindex='"+(TabIndexCount++)+"'></td></tr>");

  document.write("</table></center></div></form><br>");

	aggiornaFormQuantita();
	SetDestSelects();
	DinamicSelects(document.Ordine1.Paese.value);
	SetPaySelects();
	SetPrices(Totale);
}


// YAV form validation rules
var rules=new Array();
document.write("<DIV id='errorsDiv'></DIV>");

function VerificaForm()
{
	rules=new Array();
	rules[0]='Email|required';
	if (document.Ordine1.Codice.value=='')
	{
		rules[1]='Nome|required';
		rules[2]='Cognome|required';
		rules[3]='Indirizzo|required';
		rules[4]='Citta|required';
		rules[5]='Cap|required';
		rules[6]="Telefono|equal||pre-condition";
		rules[7]="Cell|required|post-condition";
		rules[8]='6|implies|7';
		rules[9]="Cell|equal||pre-condition";
		rules[10]="Telefono|required|post-condition";
		rules[11]='9|implies|10';
		rules[12]='Sesso|required';
		if (document.Ordine1.Paese.selectedIndex==0)
			rules[13]='Provincia|required';
		
	}
	if (!performCheck('Ordine1', rules, 'jsVar'))
	{
		alert("Inserisci i tuoi dati completi,\noppure solo il codice cliente e l'email.");
		return false;
	}

	rules=new Array();
	rules[0]='Email|regexp|^([\\w_\\.\\-])+\\@(([\\w\\-]{2,})+\\.)+([\\w]{2,})+$|Email non valida.';
	if (!performCheck('Ordine1', rules, 'classic')) return false;
	
	if (document.Ordine1.Codice.value=='')
	{
		IndirFilt=document.Ordine1.Indirizzo.value.replace(/[^0-9]/g,'');
		if ((IndirFilt.search(/\d+/)==-1) && (document.Ordine1.Indirizzo.value.search(" SN")==-1) && (document.Ordine1.Indirizzo.value.search(" sn")==-1))
		{
			alert("Manca il numero civico.\nSe il tuo indirizzo è senza numero,\nal posto del numero scrivi SN.");
			return false;
		}
	}
	
	if (document.Ordine1.Paese.selectedIndex==0)
	{
		rules=new Array();
		rules[0]='Codice|equal||pre-condition';
		rules[1]='Cap|minlength|5|post-condition';
		rules[2]='0|implies|1';
		rules[3]='Cap|maxlength|5|post-condition';
		rules[4]='0|implies|3';
		if (!performCheck('Ordine1', rules, 'jsVar'))
		{
			alert("Il CAP deve essere di 5 cifre.");
			document.Ordine1.Cap.focus();
			return false;
		}
		
		if (document.Ordine1.Sped.selectedIndex==0)
		{
			alert("Seleziona un tipo di spedizione.");
			document.Ordine1.Sped.focus();
			return false;
		}
		/*if (document.Ordine1.Pagamento.selectedIndex==2)
		{
			telStr=document.Ordine1.Telefono.value;
			tel=telStr.substring(0,3);
			if ((telStr=="") || (telStr==null) || (tel=="340") || (tel=="343") || (tel=="347") || (tel=="348") || (tel=="349") || (tel=="330") || (tel=="332") || (tel=="333") || (tel=="334")|| (tel=="335") || (tel=="336") || (tel=="337") || (tel=="338") || (tel=="339") || (tel=="360") || (tel=="363") || (tel=="368") || (tel=="320") || (tel=="323") || (tel=="328") || (tel=="329") || (tel=="380") || (tel=="383") || (tel=="388") || (tel=="389") || (tel=="390") || (tel=="391") || (tel=="392") || (tel=="393"))
			{
				alert("In caso di pagamento con carta di credito è necessario inserire un numero di telefono fisso.");
				document.Ordine1.Telefono.focus();
				return false;
			}
		}*/
	}
	else
	{
		rules=new Array();
		rules[0]='Stato|required|Seleziona lo stato di destinazione.';
		if (!performCheck('Ordine1', rules, 'classic')) { document.Ordine1.Stato.focus(); return false; }
	}

	if (document.Ordine1.Codice.value=='')
	{
		if (document.Ordine1.CF.value == "" && document.Ordine1.PIVA.value == "")
		{
			alert("Inserire il Codice Fiscale o la Partita IVA.");
			document.Ordine1.CF.focus();
			return false;
		}
		if (document.Ordine1.CF.value != "" && document.Ordine1.CF.value.length != 16 && document.Ordine1.CF.value.length != 11 && document.Ordine1.CF.value.length != 13)
		{
			alert("Codice Fiscale non valido.");
			document.Ordine1.CF.focus();
			return false;
		}
		if (document.Ordine1.PIVA.value != "" && document.Ordine1.PIVA.value.length != 11 && document.Ordine1.PIVA.value.length != 13)
		{
			alert("Partita IVA non valida.");
			document.Ordine1.PIVA.focus();
			return false;
		}
	}
	
	if (document.Ordine1.Pagamento.selectedIndex==0)
	{
		alert("Seleziona una modalità di pagamento.");
		document.Ordine1.Pagamento.focus();
		return false;
	}
	if (!(document.Ordine1.Condizioni.checked))
	{
	 alert("Per inviare l'ordine è necessario approvare le condizioni di vendita.");
	 document.Ordine1.Condizioni.focus();
	 return false;
	}
	if (!(document.Ordine1.Privacy.checked))
	{
	 alert("Per inviare l'ordine è necessario dare il consenso al trattamento dei dati personali.");
	 document.Ordine1.Privacy.focus();
	 return false;
	}
	return true;
}
