if (document.cookie == "")
{
alert("Warning:\nIf you want buy in this shop you must qualify the cookies.\n\nFor Internet Explorer is enough qualify Privacy on Medium-high.\nNo one date will be record on your har disk.")
}

if (document.cookie.indexOf("Sel") ==-1)
	{document.cookie="Sel"+"="+"'',"}
	
if (document.cookie.indexOf("Sel2") ==-1)
	{document.cookie="Sel2"+"="+":"}

//Zoom Foto	
function Popup(desktopURL,w,h)
{
desktop = window.open(desktopURL, "new","toolbar=no,screenX=0,screenY=0,left=0,top=0,location=no,status=no,menubar=no,scrollbars=no,resizable=yes"+",width="+w+",height="+h );
}

//Funzione che rivela il valore di ogni cookie
function GetCookie(Name) 
{
var search = Name + "="
	if (document.cookie.length > 0) 
		{offset = document.cookie.indexOf(search);
			if (offset != -1)
				{offset += search.length;
				 end = document.cookie.indexOf(";", offset);
					if (end == -1)
						{end = document.cookie.length;
						}
				return unescape(document.cookie.substring(offset, end))
				}
		}
}

function Aggiungi (name,nome)
{
// Verica la presenza del prodotto
	 if (document.cookie.indexOf("Sel")!=-1)
	 	{query=GetCookie("Sel")
	 	}
	 if (query.indexOf("'"+name+"'")!=-1)
		{
		SetCookie(name,(Quantita(name)*1)+1)
		invia ()
		}
// Inserisce accodandolo il nuovo prodotto
	else 
		{if (document.cookie.indexOf("Sel2")!=-1)
			{query2=GetCookie("Sel2")
			}
		query += "'"+name+"',"
		query2 += name+"=1:"
		document.cookie = "Sel" + "=" + query;
		document.cookie = "Sel2" + "=" + query2;
		invia ()
		}
}

function AggiungiCarrello (name,nome)
{
// Verica la presenza del prodotto
	 if (document.cookie.indexOf("Sel")!=-1)
	 	{query=GetCookie("Sel")
	 	}
	 if (query.indexOf("'"+name+"'")!=-1)
		{
		SetCookie(name,(Quantita(name)*1)+1)
//		invia ()
		}
// Inserisce accodandolo il nuovo prodotto
	else 
		{if (document.cookie.indexOf("Sel2")!=-1)
			{query2=GetCookie("Sel2")
			}
		query += "'"+name+"',"
		query2 += name+"=1:"
		document.cookie = "Sel" + "=" + query;
		document.cookie = "Sel2" + "=" + query2;
//		invia ()
		}
}

//Richiama il Carrello
function invia ()
{
location.href="Carrello_UK.asp"
}

//Formattazione Prezzo in Euro
function euroformat(Valore)
{
    	Valore=Valore+""
    	if (Valore.substring(0,1)==".")
    		{Valore="0"+Valore}
    	testa=Valore.substring(0,Valore.indexOf("."))
    		if (testa==""){return migliaia(Valore)+","+"00"}
    	testa=migliaia(testa)
    	coda=Valore.substring(Valore.indexOf(".")+1,Valore.length)
    		if (coda.length==1){coda=coda+"0"}
     	Valore=testa+","+coda
return Valore}

//Formattazione Prezzo in Dollari
function USDformat(Valore)
{
var ValoreUSD
ValoreUSD=""
	for (var i=0; i<Valore.length; i++){
		if (Valore.charAt(i)=="."){
			ValoreUSD=ValoreUSD+","
		}
		else if (Valore.charAt(i)==","){
			ValoreUSD=ValoreUSD+"."
		}
		else {
		ValoreUSD=ValoreUSD+Valore.charAt(i)
		}
	}
return ValoreUSD}

//Restituisce un valore con inseriti i punti alle migliaia
function migliaia (stringanumerica)
{
var stringanumerica=stringanumerica.toString()
var testa=""

if (stringanumerica.substring(0,1)=="-")
	{testa="-"
	stringanumerica=stringanumerica.substring(1,stringanumerica.length)
	}

if (stringanumerica>0)
	{
	contator=0
	ins=0
	for (var i = 1 ; i < stringanumerica.length-ins ; i++)
		{
			contator= ++contator
				if (contator==3)
						{
						stringanumerica=
						stringanumerica.substring(0,(stringanumerica.length-i-ins))
						+"."+
						stringanumerica.substring(stringanumerica.length-i-ins,stringanumerica.length)
						contator=0
						ins=++ins
						} 
		}
	}
return testa+stringanumerica}

//Calcolo dei prodotti attuali nel carrello
function Aggiorna (value)
{		
//		Sp()
		var query="'',"
		if (document.cookie.indexOf("Sel") != -1)
			{var query=GetCookie("Sel")
			}
		if (value==0)
			{
			location.href='Carrello_UK.asp'
		}
		else
		{
			if (GetCookie("Tot") == "mod")
					{alert ("Attention:\nPlease update your shopping basket")
				 	return
			}
			if (query=="'',")
				{alert ("Attention:\nThe shopping basket is empty")
				 return
			}
			/*
			if (GetCookie("Tot") < ImportoMinimo)
					{alert ("Attention:\nL'ordine per poter essere evaso deve essere almeno di "+ImportoMinimo+" Euro")
				 	return
			}
			*/
			location.href='Modulo_UK.asp'
		}
}

//Funzione che Recupera i dati relativi alla spedizione
function RecDatiSped(Name) 
{
//Ricerca del Codice e del valore in Sped
	if (GetCookie("Sped")!=null){
		var search = Name + "="
		var Selezione2 = GetCookie("Sped")
			if (Selezione2.length > 0){
					offset = Selezione2.indexOf(search);
					if (offset != -1) 
						{offset += search.length;
						 end = Selezione2.indexOf("&", offset);
							if (end == -1)
								{end = Selezione2.length;
								}
						 return unescape(Selezione2.substring(offset, end))
						}
					else{
						Aggiorna (0) 
		//Aggiorna il carrello nel caso venga premuto back dopo una cancellazione
						}
			}
	}
	else {
		return "USA"
	}
}

//Funzione che rivela le quantita di ogni prodotto
function Quantita(Name) 
{
//Ricerca del Codice e del valore in Sel2
var search = ":" + Name + "="
var Selezione2 = GetCookie("Sel2")
	if (Selezione2.length > 0) 
		{offset = Selezione2.indexOf(search);
			if (offset != -1) 
				{offset += search.length;
				 end = Selezione2.indexOf(":", offset);
					if (end == -1)
						{end = Selezione2.length;
						}
				 return unescape(Selezione2.substring(offset, end))
				}
			else
				{
				Aggiorna (0) 
//Aggiorna il carrello nel caso venga premuto back dopo una cancellazione
				}
		}
}

//Funzione per Modificare la quantità e cancellare prodotti
function SetCookie (name, value) 
{
//Ricerca del Codice e del valore in Sel2
	var search = ":" + name + "="
	var Selezione2 = GetCookie("Sel2")
		if (Selezione2.length > 0) 
			{offset1 = Selezione2.indexOf(search);
				if (offset1 != -1) 
				{offset = offset1+search.length;
				 end = Selezione2.indexOf(":", offset);
						if (end == -1)
							{end = Selezione2.length;
							}
				}
				else	
					{return}
				
			}
			
	if (value==0)
//Elimina il prodotto dalle liste
		{
		Selezione2=Selezione2.substring(0,offset1)+Selezione2.substring(end,Selezione2.length)
			var search = "'"+name+"',"
			var Selezione = GetCookie("Sel")
				if (Selezione.length > 0) 
					{offset = Selezione.indexOf(search);
						if (offset != -1) 
							{end = offset+search.length;
								if (end == -1)
									{end = Selezione.length;
									}
							Selezione=Selezione.substring(0,offset)+Selezione.substring(end,Selezione.length)
							document.cookie="Sel"+"="+Selezione
							}
							else	
								{return}
					}
		}
	else
		{
		Selezione2=Selezione2.substring(0,offset)+value+Selezione2.substring(end,Selezione2.length)
		}
document.cookie="Sel2"+"="+Selezione2
}

//funzione che svuota completamente il carrello
function SvuotaCarrello ()
{
		document.cookie="Sel"+"="+"'',"
		document.cookie="Sel2"+"="+":"
		Aggiorna (0)
}

function CalcoloSpedUSA (Valore)
{

	if (Valore <= 30){
		Valore = 10
	}
	else if (Valore > 30 && Valore <= 400){
		Valore = 35
	}
	else if (Valore > 400 && Valore <= 800){
		Valore = 50
	}
	else if (Valore > 800 && Valore <= 1500){
		Valore = 95
	}
	else if (Valore > 1500){
		Valore = 115
	}				
return Valore
}

function CalcoloSpedROW (Valore)
{
	if (Valore <= 30){
		Valore = 10
	}
	else if (Valore > 30 && Valore <= 300){
		Valore = 25
	}
	else if (Valore > 300 && Valore <= 600){
		Valore = 35
	}
	else if (Valore > 600 && Valore <= 1200){
		Valore = 65
	}
	else if (Valore > 1200){
		Valore = 80
	}				
return Valore
}

//Funzione che setta il tipo di spedizione
function Sp()
{
if (document.Spedizione.COSTO.options[document.Spedizione.COSTO.selectedIndex].text.toLowerCase() == "usa")
	{document.cookie="Sped"+"="+"Indice="+document.Spedizione.COSTO.selectedIndex+"&"+"Nome=USA"+"&"+"Valore="+spede}
else
	{document.cookie="Sped"+"="+"Indice="+document.Spedizione.COSTO.selectedIndex+"&"+"Nome="+document.Spedizione.COSTO.options[document.Spedizione.COSTO.selectedIndex].text+"&"+"Valore="+spede}
}

function AssegnaValori(Codi,Prod,Prez,Qntt,Pret)
{
ProdSel=ProdSel+"Cod: "+Codi+"\n"+"Product Name: "+Prod+"\n"+"Price: EUR "+Prez+" "+"Qnt: "+Qntt+" "+"Total: EUR "+Pret+"\n\n"
}

function AssegnaValoriUSD(Codi,Prod,Prez,Qntt,Pret)
{
ProdSel=ProdSel+"Cod: "+Codi+"\n"+"Product Name: "+Prod+"\n"+"Price: USD "+USDformat(Prez)+" "+"Qnt: "+Qntt+" "+"Total: USD "+USDformat(Pret)+"\n\n"
}

//Funzione che converte le lettere accentate
function accenti(value)
{

	if (value.indexOf("&#224")!= -1)
		{value=value.substring(0,value.indexOf("&#224"))+"à"+value.substring(value.indexOf("&#224")+6,value.length)}
	if (value.indexOf("&#232")!= -1)
		{value=value.substring(0,value.indexOf("&#232"))+"è"+value.substring(value.indexOf("&#232")+6,value.length)}
	if (value.indexOf("&#233")!= -1)
		{value=value.substring(0,value.indexOf("&#233"))+"é"+value.substring(value.indexOf("&#233")+6,value.length)}
	if (value.indexOf("&#236")!= -1)
		{value=value.substring(0,value.indexOf("&#236"))+"ì"+value.substring(value.indexOf("&#236")+6,value.length)}
	if (value.indexOf("&#242")!= -1)
		{value=value.substring(0,value.indexOf("&#242"))+"ò"+value.substring(value.indexOf("&#242")+6,value.length)}
	if (value.indexOf("&#249")!= -1)
		{value=value.substring(0,value.indexOf("&#249"))+"ù"+value.substring(value.indexOf("&#249")+6,value.length)}

return value
}

//funzione che svuota completamente il carrello
function SvuotaCookie ()
{
document.cookie="Sel"+"="+"'',"
document.cookie="Sel2"+"="+":"		
}

//DATA
function data()
	{
	var days=new Array(8);
	days[1] = "Sun";
	days[2] = "Mon";
	days[3] = "Tue";
	days[4] = "Wed";
	days[5] = "Thu";
	days[6] = "Fri";
	days[7] = "Sat";
	var months=new Array(13);
	months[1] = "Jan";
	months[2] = "Feb";
	months[3] = "Mar";
	months[4] = "Apr";
	months[5] = "May";
	months[6] = "Jun";
	months[7] = "Jul";
	months[8] = "Ago";
	months[9] = "Sep";
	months[10] = "Oct";
	months[11] = "Nov";
	months[12] = "Dec";
	var dateObj=new Date()
	var wday=days[dateObj.getDay() + 1]
	var lmonth=months[dateObj.getMonth() + 1]
	var date=dateObj.getDate()
	var year=dateObj.getYear()
	var anno=year.toString()
	var anno2=anno.substring(anno.length-2,anno.length)
	document.write(wday + ", " + date + " " + lmonth + "&nbsp;" + "20" +anno2)
return}
