//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////

/*

DISCLAIMER: THESE JAVASCRIPT FUNCTIONS ARE SUPPLIED 'AS IS', WITH 
NO WARRANTY EXPRESSED OR IMPLIED. YOU USE THEM AT YOUR OWN RISK. 
PAUL STEPHENS DOES NOT ACCEPT ANY LIABILITY FOR 
ANY LOSS OR DAMAGE RESULTING FROM THEIR USE, HOWEVER CAUSED. 

Paul Stephens' cookie-handling object library

Version 2.1
2.0 - Introduces field names
2.1 - Fixes bug where undefined embedded fields[] elements weren't written to disk

www.paulspages.co.uk 

TO USE THIS LIBRARY, INSERT ITS CONTENTS IN THE <HEAD> SECTION 
OF YOUR WEB PAGE SOURCE, BEFORE ANY OTHER JAVASCRIPT ROUTINES.

(C) Paul Stephens, 2001-2003. Feel free to use this code, but please leave this comment block in. This code must not be sold, either alone or as part of an application,  without the consent of the author.

*/

function cookieObject(name, expires, accessPath) {
var i, j
this.name = name
this.fieldSeparator = "#"
this.found = false
this.expires = expires
this.accessPath = accessPath
this.rawValue = ""
this.fields = new Array()
this.fieldnames = new Array() 
if (arguments.length > 3) { // field name(s) specified
  j = 0
  for (i = 3; i < arguments.length; i++) {
    this.fieldnames[j] = arguments[i]    
    j++
  }
  this.fields.length = this.fieldnames.length 
}
this.read = ucRead

this.write = ucWrite

this.remove = ucDelete
this.get = ucFieldGet
this.put = ucFieldPut
this.namepos = ucNamePos
this.read()
}


function ucFieldGet(fieldname) {
var i = this.namepos(fieldname)
if (i >=0) {
  return this.fields[i]
} else {
  return "BadFieldName!"
}
}

function ucFieldPut (fieldname, fieldval) {
var i = this.namepos(fieldname)
if (i >=0) {
  this.fields[i] = fieldval
  return true
} else {
  return false
}
}

function ucNamePos(fieldname) {
var i 
for (i = 0; i < this.fieldnames.length; i++) {
  if (fieldname == this.fieldnames[i]) {
    return i
  }
}
return -1
}


function ucWrite() {      
  var cookietext = this.name + "=" 

// concatenate array elements into cookie string

// Special case - single-field cookie, so write without # terminator
if (this.fields.length == 1) {
  cookietext += escape(this.fields[0])
  } else { // multi-field cookie
    for (i= 0; i < this.fields.length; i++) {
      cookietext += escape(this.fields[i]) + this.fieldSeparator }
  }


// Set expiry parameter, if specified
    if (this.expires != null) {  
      if (typeof(this.expires) == "number") { // Expiry period in days specified  
        var today=new Date()     
        var expiredate = new Date()      
        expiredate.setTime(today.getTime() + 1000*60*60*24*this.expires)
        cookietext += "; expires=" + expiredate.toGMTString()
      } else { // assume it's a date object
        cookietext +=  "; expires=" + this.expires.toGMTString()
      } // end of typeof(this.expires) if
    } // end of this.expires != null if 
   
// add path, if specified
   if (this.accessPath != null) {
   cookietext += "; PATH="+this.accessPath }

// write cookie
   // alert("writing "+cookietext)
   document.cookie = cookietext 
   return null  
}


function ucRead() {
  var search = this.name + "="                       
  var CookieString = document.cookie            
  this.rawValue = null
  this.found = false     
  if (CookieString.length > 0) {                
    offset = CookieString.indexOf(search)       
    if (offset != -1) {                         
      offset += search.length                   
      end = CookieString.indexOf(";", offset)   
      if (end == -1) {  // cookie is last item in the string, so no terminator                        
       end = CookieString.length }              
      this.rawValue = CookieString.substring(offset, end)                                   
      this.found = true 
      } 
    }
   
if (this.rawValue != null) { // unpack into fields

  var sl = this.rawValue.length
  var startidx = 0
  var endidx = 0
  var i = 0

// Special case - single-field cookies written by other functions,
// so without a '#' terminator

if (this.rawValue.substr(sl-1, 1) != this.fieldSeparator) {
  this.fields[0] = unescape(this.rawValue)
  } else { // separate fields

  do  
  {
   endidx = this.rawValue.indexOf(this.fieldSeparator, startidx)
   if (endidx !=-1) {
     this.fields[i] = unescape(this.rawValue.substring(startidx, endidx))
     i++
     startidx = endidx + 1}
  }
  while (endidx !=-1 & endidx != (this.rawValue.length -1));
}
} // end of unpack into fields if block
  return this.found
} // end of function


function ucDelete() {
  this.expires = -10
  this.write()
  return this.read()
}



/*
*********** IT'S OK TO REMOVE THE CODE BELOW HERE IF YOUR PAGE 
DOESN'T USE cookieList() OBJECTS OR THE findCookieObject() FUNCTION.
*/




function findCookieObject(cName, cObjArray) {
/* 
This function finds a named cookie among the objects
pointed to by a cookieList array (see below).

Parameters are the cookie name to search for (a string), and an array created with 
the new cookieList() constructor (see below)

NOTE - if you're only dealing with a specific, named cookie, then it's
more efficient to ceate a single cookieObject directly with that name,
and check its .found property to see if it already exists on this client.

This function is for when you've created an all-cookies array anyway,
and now want to check whether a specific cookie is present.

It returns a pointer to the cookieObject if found, or null if not found.
*/

var cpointer = null, i
for (i in cObjArray) {
  if (cName == cObjArray[i].name) {
    cpointer = cObjArray[i]
  }
}
return cpointer
}


function cookieList() {
/* 
This constructor function creates a cookieObject object (see below) 
for each cookie in document.cookie,
and returns an array of pointers to the objects.

You can use it to load all the cookies available to a page, then walk through them.

Example usage:

cookList = new cookieList()
for (i in cookList) {
 document.write(cookList[i].name + " " + cookList[i].fields[0] + "
")
}

*/

var i = 0, rawstring, offset = 0, start, newname
cpointers = new Array()
rawstring = document.cookie
if (rawstring.length > 0) {
  do {
   start = rawstring.indexOf("=", offset)
   if (start != -1) { // another cookie found in string
     // get cookie string up to end of current cookie name
     newname = rawstring.substring(0, start) 
     if (offset > 0) { 
       // if not first cookie in string, remove previous cookie data from substring
       // subsequent cookie names have a space before them (just a little browser foible!)
       newname = newname.substring(newname.lastIndexOf(";")+2, start)
     }     
     cpointers[i] = new cookieObject(newname)
     offset = start + 1
     i++
   }
  } while (start != -1)
} // end rawstring.length > 0
return cpointers
} //end function



//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
/////////////////////                                      ///////////////////////
/////////////////////   GESTIONE NORMALE DEI COOKIE        ///////////////////////
/////////////////////                                      ///////////////////////
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////


/*
Paul Stephens' NetScape-based cookie-handling library
http://web.ukonline.co.uk/paul.stephens/index.htm
*/

function setCookie(name, value, lifespan, access_path) {
      
  var cookietext = name + "=" + escape(value)  
    if (lifespan != null) {  
      var today=new Date()     
      var expiredate = new Date()      
      expiredate.setTime(today.getTime() + 1000*60*60*24*lifespan)
      cookietext += "; expires=" + expiredate.toGMTString()
    }
    if (access_path != null) { 
      cookietext += "; PATH="+access_path 
    }
   document.cookie = cookietext 
   return null  
}


function setDatedCookie(name, value, expire, access_path) {
    var cookietext = name + "=" + escape(value)
      + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()))
     if (access_path != null) { 
      cookietext += "; PATH="+access_path 
     }
   document.cookie = cookietext 
   return null        
}


function getCookie(Name) {
  var search = Name + "="                       
  var CookieString = document.cookie            
  var result = null                               
  if (CookieString.length > 0) {                
    offset = CookieString.indexOf(search)       
    if (offset != -1) {                         
      offset += search.length                   
      end = CookieString.indexOf(";", offset)   
      if (end == -1)                            
        end = CookieString.length               
      result = unescape(CookieString.substring(offset, end))         
                                                
      } 
    }
   return result                                
}


function deleteCookie(Name, Path) {
  setCookie(Name,"Deleted", -1, Path)
}

////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////


function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

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 eraseCookie(name)
{
	createCookie(name,"",-1);
}

////////////////////////////////////////////////////////
//////////////// AGGIORNA PAGINA ///////////////////////
////////////////////////////////////////////////////////

		function reload()	{
			strURL = location.href
			self.location = strURL
		}

////////////////////// USATA NELLA HOME PAGE //////////////////////////

	function resetShoppingBasket() {
	var data = new Date()
	data.setTime(data.getTime() + (1000 * 60 * 60))
 
//		alert("Ecco il Cookie resettato con resetShoppingBasket: " + document.cookie)
	}
	
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////	QUESTA FUNZIONE PULISCE IL CARRELLO    /////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////

	function clearBasket(lang) 
	{	
		if (lang == 'eng')
		{
		var stringa1 = 'Empty cart?';
		}
		else
		{	
		var stringa1 = 'Svuoto il carrello?';
		}
		
		if (confirm(stringa1 )) {

				strURL = location.href+"?erase=yes"
				self.location = strURL
		}
	}

	
///////////////////////////////////////////////
///////////////////////////////////////////////
////// Funzione per aprire una finestra ///////
////// Usata solitamente per aprire la  ///////
//////      MOSTRA_ETICHETTE.ASP        ///////
///////////////////////////////////////////////
///////////////////////////////////////////////

function aprifin(desktopURL,w,h)
{
//    window.open(desktopURL, "new","toolbar=no,location=no,status=no,menubar=no,scrollbars=1,resizable=yes,left=100,top=100,width="+w+",height="+h );
    window.open(desktopURL, "new","toolbar=no,location=no,status=no,menubar=no,scrollbars=1,resizable=yes,left=200,top=100,width=650,height=450");
}

///////////////////////////////////////////////
///////////////////////////////////////////////
////// Funzione per URL esterni dentro un frame
///////////////////////////////////////////////
///////////////////////////////////////////////
// <a class="xxx" href="javascript:openlink('http://www.xxx.com/')">
// Il sito di <span style="font-weight:bold;">descrizione del sito</span> (in inglese)</a>
///////////////////////////////////////////////////////////////////////////////////////////////

function openlink(xlink)
	{
	window.open("/sito/comuni/openxlink.shtml?" + xlink);
	}

/////////////////////////////////////////////// 	window.open("/sito/comuni/openxlink.shtml?" + xlink, "xpage");

///////////////////////////////////////////////
////// Apre immagini con finestra auto ridimensionata
///////////////////////////////////////////////
///////////////////////////////////////////////

   function ApriImmagini(file)
    {
      var prop = "toolbar=no,location=no,status=no,menubar=no,scrollbars=0,resizable=no,left=100,top=100"; // Altre proprietà... eccetto width ed height!
      window.open(file, null, prop);
    }


////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
/////////////////	FUNZIONE INCREMENTO DECREMENTO BOTTIGLIE ///////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////

function increaseNumber(my_form, my_textfield, minqty) 
{
		if (isNaN(minqty) || minqty == "" || minqty == 0) {
		var minqty = 1 }
   var curr_value = my_textfield.value;
   var new_value = parseInt(curr_value) + parseInt(minqty);
   if(new_value > 72) new_value=72;  
   my_textfield.value = new_value;

}

function decreaseNumber(my_form, my_textfield, minqty) 
{
		if (isNaN(minqty) || minqty == "" || minqty == 0) {
		var minqty = 1 }
   var curr_value = my_textfield.value;
   var new_value  = parseInt(curr_value) - parseInt(minqty);
   if(new_value < 0) new_value=0;  
   my_textfield.value = new_value;
}

////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
/////////////////	UTILITY UTILITY UTILITY UTILITY UTILITY  ///////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////

	function clearField(thefield) {
		if (thefield.defaultValue==thefield.value)
		thefield.value = ""
	}
	
	function focus()	{
	document.form_ricerca.ricerca.focus()
	} 
	
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
// Pulisce il carrello nella pagina default_carrello aggiungendo alla //
// fine erase=yes tenendo conto della querystring eventualmente già ////
// presente, come per MODIFICA_CAMBIO più sotto ////////////////////////
////////////////////////////////////////////////////////////////////////

	function clearbasket(lang) 
		{	
		if (lang == 'eng')
			{
			var stringa1 = 'Empty cart?';
			}
		else
			{	
			var stringa1 = 'Svuoto il carrello?';
			}
		if (confirm(stringa1))
			{
				l = location.href;
				qs = location.search;
				var pc = "";
				if (qs != "") 
					{
					pc += "?erase=yes";
					var pa = getParameterNames();
					for (var i = 0; i < pa.length; i++)
						{
							if (pa[i] != "prov" && pa[i] != "prod" && pa[i] != "campagna")
							{
								pc += "&" + pa[i] + "=" + getParameter(pa[i]);
							}
						}
					}
				else
					{
					pc += "?erase=yes";
					}
				pagina = (l.substr(l.lastIndexOf("/")+1).split(/[?#]/)[0]);
				self.location = pagina + pc
			}
		}

////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
//////////////////////////	MODIFICA CAMBIO ////////////////////////////
/////// AGGIUNGE currency=xyz alla fine tenendo gestendo anche /////////
/////// la querystring eventualmente già presente. Utilizzata //////////
/////// da selettore_valuta.asp ////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////

	function modifica_valuta_selettore(lcid)
	{
	l = location.href;
	qs = location.search;
//	alert(qs);
	var pc = "";

		if (qs != "") 
		{
			pc += "?" + "currency" + "=" + (lcid);
			var pa = getParameterNames();
			for (var i = 0; i < pa.length; i++) {
				if (pa[i] != "currency" && pa[i] != "prov" && pa[i] != "prod" && pa[i] != "campagna")
				{
					pc += "&" + pa[i] + "=" + getParameter(pa[i]);
				}
				}
		}
		else
		{
			pc += "?" + "currency" + "=" + (lcid);
		}

//	alert(pc.substring(1));
	pagina = (l.substr(l.lastIndexOf("/")+1).split(/[?#]/)[0]);
	self.location = pagina + pc
	}

	function getParameterNames()
	{
	var ar = location.search.substring(1).split('&');
	for (var i = 0; i < ar.length; i++) {
		ar[i] = ar[i].substring(0, ar[i].indexOf('='));
	}
	return ar;
	}
	
	function getParameter(whichOne) 
	{
	var pairs = location.search.substring(1).split('&');
	var r = "";
	var tp = new Array();
	for (var i = 0; i < pairs.length; i ++) {
		tp = pairs[i].split('=');
		if (whichOne == tp[0])
		r = unescape(tp[1].replace(/\+/g, " "));
		}
	return r;
	}

////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
///////////////////////////// PAGINA RICERCA ///////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////


	function hide(){
		var a = 'advanced';
		document.getElementById(a).style.display='none';
		document.getElementById('adv').style.display='';
		document.getElementById('easy').style.display='none';
	}
	
	function show(){
		var a = 'advanced';
		document.getElementById(a).style.display='';
		document.getElementById('adv').style.display='none';
		document.getElementById('easy').style.display='';
	}
	
	function toggle_visibility(id)
		{
		var e = document.getElementById(id);
		if(e != null)
			{
			if(e.style.display == 'none')
				{
				e.style.display = '';
				document.getElementById('adv').style.display='none';
				document.getElementById('easy').style.display='';
				}
			else
				{
			e.style.display = 'none';
				document.getElementById('adv').style.display='';
				document.getElementById('easy').style.display='none';
				}
			}
		}

	function toggle_visibility_editor(id,number)
		{
		var e = document.getElementById(id);
		if(e != null)
			{
			if(e.style.display == 'none')
				{
				e.style.display = '';
				document.getElementById('adv'+number).style.display='none';
				document.getElementById('easy'+number).style.display='';
				}
			else
				{
			e.style.display = 'none';
				document.getElementById('adv'+number).style.display='';
				document.getElementById('easy'+number).style.display='none';
				}
			}
		}


////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
///////////////////////////// GESTIONE CARRELLO ////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////

function modifica_country_carrello(nazione)
{
				strURL = "default_carrello.asp?country=" + (nazione)
	//			alert(strURL)
				self.location = strURL
}

function modifica_cambio(lcid)
{
				strURL = "carrello.asp?currency=" + (lcid)
				self.location = strURL
}

function update_qty(code,qty,min_qty,bottiglie,qty_code)
{
		strURL = "default_carrello.asp?update=" + (code) + "&qty=" + qty + "&bottiglie=" + bottiglie
		valore = parseInt(bottiglie) - parseInt(qty_code) + parseInt(qty);

		var stringa1 = 'Invalid quantity!\n\nMust be a multiple of ';
		var stringa2 = 'Invalid quantity!\n\nMust be greater than zero and must not exceed 72.';
		var stringa3 = 'Cannot add to the cart!\n\nThe shopping cart capacity is 72 bottles.\nBottles in your shopping cart now: '

		var stringa1 = 'Quantità non valida!\n\nLa quantità deve essere un multiplo di ';
		var stringa2 = 'Quantità non valida!\n\nLa quantità deve essere maggiore di zero e non deve eccedere 72.';
		var stringa3 = 'Impossibile aggiungere ulteriori bottiglie al carrello!\n\nIl carrello può contenere al massimo 72 bottiglie.\nBottiglie attualmente nel vostro carrello: ';

		if ( qty%min_qty > 0 ) {
			rc = alert(stringa1 + min_qty + '.');
			return(false);
		}

		if (qty <=0 | qty >= 73) {
			rc = alert(stringa2);
			return(false);
		} 

		if ( valore > 72 ) {
			rc = alert(stringa3 + bottiglie);
			strURL = "default_carrello.asp"
		} 

		self.location = strURL
}

//////////////////////////////////////////////////////////////
////// PER CALCOLARE QUANTI CARATTERI SONO DISPONIBILI ///////
////// ALLA FINE DELLA PAGINA X I CAMPI NOTE E MESSAGGIO /////
//////////////////////////////////////////////////////////////

function calcCharLeft1(lang) {
	var msgLen;
	var MaxLength;
		var stringacheck1 = 'Il messaggio può contenere al massimo '
		var stringacheck2 = ' caratteri.'
		if (lang == 'eng') {
		var stringacheck1 = 'Message field can not exceed ';
		var stringacheck2 = ' characters.'
		}
	MaxLength = 200;
	msgLen=document.userdata.messaggio.value.length;
	if (msgLen >= MaxLength ){
	document.userdata.charsleft1.value= "0";
	window.alert(stringacheck1 + MaxLength + stringacheck2);
	document.userdata.messaggio.value=document.userdata.messaggio.value.substring(0,MaxLength);
	}else{
	document.userdata.charsleft1.value = MaxLength - msgLen;
	}
}

function calcCharLeft2(lang) {
	var msgLen;
	var MaxLength;
		var stringacheck1 = 'Le note possono contenere al massimo '
		var stringacheck2 = ' caratteri.'
		if (lang == 'eng') {
		var stringacheck1 = 'Delivery instruction can not exceed ';
		var stringacheck2 = ' characters.'
		}	MaxLength = 200;
	msgLen=document.userdata.comment.value.length;
	if (msgLen >= MaxLength ){
	document.userdata.charsleft2.value= "0";
	window.alert(stringacheck1 + MaxLength + stringacheck2);
	document.userdata.comment.value=document.userdata.comment.value.substring(0,MaxLength);
	}else{
	document.userdata.charsleft2.value = MaxLength - msgLen;
	}
}

//////////////////////////////////////////////////////
//////////////////////////////////////////////////////
//////////////////////////////////////////////////////

function modifica_pagamento(name,value,nazione,shipnazione)
{
			setCookie (name, value)
			strURL = "raccolta_dati_new.asp?country=" + (nazione) + "&shipcountry=" + (shipnazione) + "&step=2"
			document.userdata.action = strURL
			document.userdata.method= "post"
			document.userdata.submit()
}
//////////////////////////////////////////////////////
//////////////////////////////////////////////////////
//////////////////////////////////////////////////////

function check_pagamento(lang)
{

if (document.form_pagamento.Pagamento[0].checked == true){
//	alert('pagamento tipo 1')
		}
	
	else

if (document.form_pagamento.Pagamento[1].checked == true){
//	alert('pagamento tipo 2')
		}
		
	else

if (document.form_pagamento.Pagamento[2].checked == true){
//	alert('pagamento tipo 3')
		}
	else
	{
		if (lang == 'eng')
	{
	alert('Select payment method.')
	}
		else
	{
	alert('E\' necessario selezionare prima di tutto la modalità di pagamento.')
	}
//  questo potrebbe servire a togliere il focus dal campo dati selezionato
	document.form_pagamento.Pagamento[0].focus()
		 return(false);
	}
}

//////////////////////////////////////////////////////
///////// FORM VALIDATOR /////////////////////////////
//////////////////////////////////////////////////////

function form_validator(obj,lang,richiesta,bottiglie_carrello)
{
		var stringacontrollo1 = 'Selezionare la modalità di pagamento.';
		var stringacontrollo2 = 'Per favore inserire nome e cognome.';
		var stringacontrollo3 = 'Indirizzo email non valido.'
		var stringacontrollo4 = 'Per favore inserire l\'indirizzo.'
		var stringacontrollo5 = 'Per favore inserire il comune.'
		var stringacontrollo6 = 'Per favore inserire il CAP.'
		var stringacontrollo7 = 'Per favore inserire la provincia.'
		var stringacontrollo8 = 'Per favore inserire il numero di telefono.'
		var stringacontrollo9 = 'Inserire al massimo 200 caratteri nel campo "Messaggio per il destinatario".'
		var stringacontrollo10 = 'Inserire al massimo 200 caratteri nel campo "Vincoli di consegna/posizionamento".'
		var stringacontrollo11 = 'Per favore selezionare la nazione di spedizione.'
		var stringacontrollo12 = 'Per favore selezionare la provincia di spedizione.'
		var stringacontrollo13 = 'Spedizione in contrassegno disponibile solo in Italia.'
		var stringacontrollo14 = 'Il numero minimo di bottiglie non deve essere inferiore a 2.'
		var stringacontrollo15 = 'Per favore inserire il codice fiscale (per l\'estero: come Partita Iva).'
		var stringacontrollo16 = 'Per favore inserire il numero di telefono del destinatario.'

	if (lang == 'eng') {
		var stringacontrollo1 = 'Select payment method first.';
		var stringacontrollo2 = 'Enter the required information: first and last name.';
		var stringacontrollo3 = 'Not a valid email address.'
		var stringacontrollo4 = 'Enter the required information: billing address.'
		var stringacontrollo5 = 'Enter the required information: city/town.'
		var stringacontrollo6 = 'Enter the required information: postal code.'
		var stringacontrollo7 = 'Enter the required information: state or province or district.'
		var stringacontrollo8 = 'Enter the required information: phone number.'
		var stringacontrollo9 = 'Please do not exceed 200 characters in the "Message" field.'
		var stringacontrollo10 = 'Please do not exceed 200 characters in the "Delivery Instructions/Comments" field.'
		var stringacontrollo11 = 'Enter the required information: shipping country.'
		var stringacontrollo12 = 'Enter the required information: shipping state or province or district.'
		var stringacontrollo13 = 'Collect on Delivery payment is available in Italy only.'
		var stringacontrollo14 = 'A minimum of two bottles is required to process your order.'
		var stringacontrollo15 = 'Enter the required information: Tax Code (same as VAT code outside Italy).'
		var stringacontrollo16 = 'Enter the required information: Addressee phone number.'
		}

if (document.form_pagamento.Pagamento[0].checked == true){
		}
	
	else

if (document.form_pagamento.Pagamento[1].checked == true){
		}

	else
	
if (document.form_pagamento.Pagamento[2].checked == true){
		}
		
	else {
	alert(stringacontrollo1)
		 return(false);
	}
	
	if(document.userdata.nominativo.value == "") {
		 alert(stringacontrollo2);
		 document.userdata.nominativo.focus();
		 return(false);
	}

	var x = document.userdata.email.value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(x)) {}
	else {
		alert(stringacontrollo3);
		document.userdata.email.focus();
		return(false)
	}
	
	if (richiesta == "ITALIA" && document.userdata.partita_iva.value != "" && document.userdata.codice_fiscale.value == "") {
		alert(stringacontrollo15);
		show();
	    document.userdata.codice_fiscale.focus();
	    return (false);
	}

	if(document.userdata.indirizzo01.value == "") {
		 alert(stringacontrollo4);
		 document.userdata.indirizzo01.focus();
		 return(false);
	}

	if(document.userdata.citta.value == "") {
		 alert(stringacontrollo5);
		 document.userdata.citta.focus();
		 return(false);
	}

	if(document.userdata.zip.value == "") {
		 alert(stringacontrollo6);
		 document.userdata.zip.focus();
		 return(false);
	}

	if(document.userdata.provincia.value == "") {
		 alert(stringacontrollo7);
		 document.userdata.provincia.focus();
		 return(false);
	}

	if(document.userdata.telefono.value == "") {
		 alert(stringacontrollo8);
		 document.userdata.telefono.focus();
		 return(false);
	}

	if (document.userdata.messaggio.value.length > 200) {
		 alert(stringacontrollo9);
	    document.userdata.messaggio.focus();
	    return (false);
	}

	if (document.userdata.comment.value.length > 200) {
		 alert(stringacontrollo10);
	    document.userdata.comment.focus();
	    return (false);
	}

	if (document.userdata.provincia_spedizione.value != "" && document.userdata.stato_spedizione.value == "-----") {
		 alert(stringacontrollo11);
	    document.userdata.stato_spedizione.focus();
	    return (false);
	}

	if (document.userdata.provincia_spedizione.value == "" && document.userdata.stato_spedizione.value != "-----") {
		 alert(stringacontrollo12);
	    document.userdata.provincia_spedizione.focus();
	    return (false);
	}

	if (richiesta != "ITALIA" && document.form_pagamento.Pagamento[0].checked == true) {
		 alert(stringacontrollo13);
	    document.userdata.stato_spedizione.focus();
	    return (false);
	}
	
		if (bottiglie_carrello < 2 ) {
		 alert(stringacontrollo14);
		return(false);
		} 

	if (document.userdata.nome_spedizione.value != "" && document.userdata.telefono_spedizione.value == "") {
		 alert(stringacontrollo16);
	    document.userdata.telefono_spedizione.focus();
		return(false);
		} 

	return (true);
}

	function hide(){
		var a = 'cf';
		document.getElementById(a).style.display='none';
	}
	function show(){
		var a = 'cf';
		document.getElementById(a).style.display='';
	}
	function mostracf(cf){
		if (document.userdata.partita_iva.value != "" || document.userdata.codice_fiscale.value != ""){
		document.getElementById(cf).style.display='';
		} else {
		document.getElementById(cf).style.display='none';
		}
	}

/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
	function nascondi(){
		document.getElementById('riduci').style.display='none';
		document.getElementById('help').style.display='';
	}
	function mostra(){
		document.getElementById('riduci').style.display='';
		document.getElementById('help').style.display='none';
	}
//
	function commuta(id)
		{
		var e = document.getElementById(id);
		if(e != null)
			{
			if(e.style.display == 'none')
				{
				e.style.display = '';
				}
			else
				{
			e.style.display = 'none';
				}
			}
		}

//////////////////////////////////////////////////////////////////
////// Utilizzata nella RACCOLTA DATI per cambiare NAZIONE ///////
//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////

function ricarica(nazione,shipnazione)

{
			strURL = "raccolta_dati_new.asp?country=" + (nazione) + "&shipcountry=" + (shipnazione) + "&step=2"
			document.userdata.action = strURL
			document.userdata.method= "post"
			document.userdata.submit()
}

function modifica_shipcountry_raccolta(shipnazione,nazione)
{
			strURL = "raccolta_dati_new.asp?shipcountry=" + (shipnazione) + "&country=" + (nazione) + "&step=2"
			document.userdata.action = strURL
			document.userdata.method= "post"
			document.userdata.submit()
}

//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
////// Utilizzata nelle news per aprire le immagin ///////////////
//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
