
// ................................................................................................
// VISUALIZZAZIONE ARTICOLO NELLA SCHEDA PRODOTTO
// °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°

// :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
// COSTRUZIONE DELL'OGGETTO PER LE SCHEDE CATALOGO
// In ogni pagina catalogo "vox" è sostituito dal nome prodotto 
// rintracciabile nel db (shop_db.js).
// :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
function useItem(vox){
	var num = 0;	// in writeItem(i) è il parametro "i"

	// estrazione dei valori prodotto dal db
	for(i=0;i<a.length;i++){
		for(n=0;n<a[i].a_name.length;n++){
			result = a[i].a_name.substring(n,n+vox.length); 
			if(result==vox){
				itemNo			= a[i].a_weight
				itemName		= a[i].a_name
				itemPriceEuro	= a[i].a_euro
				itemIva			= a[i].a_iva
			}
		}
	}
	// Variabili (iNo,iName,iQuantity,iPriceEuro,iIva) definite in shop_all.js
	iNo[num]			= itemNo
	iName[num]			= itemName
	iPriceEuro[num]		= itemPriceEuro
	iIva[num]			= itemIva
}

// :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
// PREPARAZIONE DEL PRODOTTO RICHIESTO DALLA PAGINA HTML
// :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
function writeItem(i){
	var wI = ''
	wI += '<TABLE width=160 cellPadding=0 cellSpacing=0 border=0>'
	wI += '<FORM name=theProduct>'
	wI += '<TR>'
	wI += '<TD COLSPAN=5><IMG src="imgs/09_03_buy.gif" width=160 height=29 border=0 alt="Acquista"><BR></TD>'
	wI += '</TR>'

	wI += '<TR>'
	wI += '<TD width=12>&nbsp;</TD>'
	wI += '<TD width=1 bgcolor=#7c9c76><IMG src="imgs/00_00_px.gif" width=1 height=1 border=0></TD>'
	wI += '<TD width=10 bgcolor=#ebefbd><IMG src="imgs/00_00_px.gif" width=1 height=1 border=0></TD>'
	wI += '<TD width=136 class=buy bgcolor=#ebefbd>'
	/*
	// importi in EURO CON TASSE per residenti
	if (MEMreside=='0'){
		iEuro = fix((iPriceEuro[i]*.20) + (iPriceEuro[i]/100*100));	// (I.V.A.) + (importo)
		wI += '<B>Prezzo: ' +iEuro+ ' Eu</B><BR><FONT size=1><B>I.V.A. inclusa</B></FONT><BR>'
	} 
	// importi in EURO SENZA TASSE per non residenti
	if ((MEMreside=='1')||(MEMreside=='2')){
		wI += '<B>Prezzo: ' +iPriceEuro[i]+ ' Eu</B><BR>'
	}
	*/
	//
	// importi senza I.V.A.
	wI += '<B>Prezzo: ' +iPriceEuro[i]+ ' Euro</B><BR><FONT size=1><B>I.V.A. esclusa</B></FONT><BR>'
	//
	wI += '</TD>'
	wI += '<TD width=1 bgcolor=#7c9c76><IMG src="imgs/00_00_px.gif" width=1 height=1 border=0></TD>'
	wI += '</TR>'

	wI += '<TR>'
	wI += '<TD width=12>&nbsp;</TD>'
	wI += '<TD width=1 bgcolor=#7c9c76><IMG src="imgs/00_00_px.gif" width=1 height=1 border=0></TD>'
	wI += '<TD width=10 bgcolor=#ebefbd><IMG src="imgs/00_00_px.gif" width=1 height=1 border=0></TD>'
	wI += '<TD width=136 class=buy bgcolor=#ebefbd><IMG src="imgs/00_00_px.gif" width=130 height=6 border=0><BR><B>Quantità:</B> <INPUT class=formAlignCenter name=qty type=text size=2 value=1 onClick="document.theProduct.qty.select();"><BR><IMG src="imgs/00_00_px.gif" width=1 height=4 border=0><BR></TD>'
	wI += '<TD width=1 bgcolor=#7c9c76><IMG src="imgs/00_00_px.gif" width=1 height=1 border=0></TD>'
	wI += '</TR>'
	wI += '<TR>'
	wI += '<TD COLSPAN=5><A href="javascript:addItem('+i+')"><IMG src="imgs/09_07_buy.gif" width=160 height=18 border=0 alt="Aggiungi alla lista"></A></TD>'
	wI += '</TR>'
	wI += '</FORM>'
	wI += '</TABLE>'
	document.write(wI);
	document.close();
}

// :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
// SCRITTURA DELLA TABELLA CON IL PRODOTTO PREDISPOSTO PER LA PAGINA
// :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
function writeArt(){
	for (i=0;i<iNo.length;i++) writeItem(i)
}

// ................................................................................................
// AGGIORNAMENTO COOKIE "Scart" QUANDO SI AGGIUNGONO PRODOTTI
// °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°

// :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
// VARIABILI GLOBALI 
// indispensabili alla funzione addItem() quando il carrello è vuoto
// :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
var counter = 0;
var cookData = '';

// :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
// AGGIUNGE UN PRODOTTO AL CARRELLO
// :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
function addItem(num){
	if (getCookieData('Altomedia')){
		orderString = getCookieData('Altomedia');
		cLen = orderString.length;
		countEnd = orderString.indexOf('@');
		pointer = countEnd + 1;
		counter = orderString.substring(0,countEnd);
		cookData = orderString.substring(pointer,cLen);
	}
	// valuta se il campo quantità (qty) è vuoto
	iQuantity[num] = document.theProduct.qty.value;
	c = eval('iQuantity[num]');
	if (iQuantity[num]==0){
		alert('Inserire un numero di prodotti           \nda aggiungere alla lista.');
		document.theProduct.qty.value = '';
		document.theProduct.qty.focus();
		return;
	}
	for (i=0;i<c.length;i++){
		var oneChar = c.substring(i, i + 1);
		if ((oneChar<'0')||(oneChar>'9')){
			alert('La quantità contiene un valore non valido.           \n Reinserire il numero di prodotti desiderato.');
			document.theProduct.qty.value = '';
			document.theProduct.qty.focus();
			return;
		}
	}
	if (confirm('Aggiungo ' + iQuantity[num] + ' confezioni di ' + iName[num] + ' alla lista degli acquisti?')){
		addCart = '' + iNo[num] + '`' + iQuantity[num] + '*' + iName[num] + '~' + iPriceEuro[num] + '#' + iIva[num] + '^';
		cookData += eval('addCart');
		setCookieData('Altomedia', cookData, expdate.toGMTString());
	}else{}
}
