	function elimina(id,what)
	{
		// id e' un carrello e elimino OH
		// altrimenti id e' una riga della tabella tbl_ordini
		var doc=document.getElementById("Fcancella");
		doc.idrow.value=id;
		doc.what.value=what;
		doc.submit();
	}
	
	
	function goArticolo(id,flag)
	{
		if (flag==0) 
		{
			parent.goArticolo(id,1);
		}
		else
		{
			myLytebox.end();
			var orig=window.location+" ";
			i=orig.indexOf("/page");
			serv=orig.substr(0,i);
			window.location=serv+"/page.php?mod=schedaArticoli&idArticolo="+id;
		}
		
	}
	function aggiungiCarrello()
	{
		var datiPost="";
		if (totaleForm>=1000)
		{
			for (k in confezioniArray) 
			{
				if ((k!="removeDuplicates")&&(k!="empty")) datiPost=datiPost+"|"+k+","+confezioniArray[k]+","+totaleArray[k];
			}
			document.getElementById("_datiCarrello").value=datiPost;
			document.getElementById("formOpenH").submit();
		}
		else alert("Importo minimo ordinabile 1.000,00 euro");
		
	}

	function aggiungiCarrello2()
	{
		var datiPost="";
		
		if (totaleForm>0)
		{
			for (k in confezioniArray) 
			{
				if ((k!="removeDuplicates")&&(k!="empty")) datiPost=datiPost+"|"+k+","+confezioniArray[k]+","+totaleArray[k];
			}
		}
		else alert("Non ci sono articoli selezionati nel modulo");
		
		window.parent.document.getElementById("_datiCarrello").value=datiPost;
		parent.sendCarrello();
	}
	
	function sendCarrello()
	{
		myLytebox.end();
		document.getElementById("formOpenH").submit();
		return false;
	}
	
	function pagina(id)
	{
		d1=document.getElementById('cat_pag1');
		d2=document.getElementById('cat_pag2');
		d3=document.getElementById('cat_pag3');
		
		f1=document.getElementById('tfoot1');
		f2=document.getElementById('tfoot2');
		f3=document.getElementById('tfoot3');

		
		/*
		p1=document.getElementById('pag_1');
		p2=document.getElementById('pag_2');
		p3=document.getElementById('pag_3');	
		*/
		/*
		p1=document.pag_1;
		p2=document.pag_2;
		p3=document.pag_3;
		*/
		//document[img_name].src=img_src;	
		
		a = document.getElementById('aggiungi');
		
		ie = (document.all) ? 1 : 0;
		tablefootergroup = (document.all) ? 'block' : 'table-footer-group';
		tablerowgroup = (document.all) ? 'block' : 'table-row-group';
		/*
		table-footer-group
		table-row-group
		*/
		if (id==1) { 
				d1.style.display=tablerowgroup; d2.style.display='none'; d3.style.display='none';
				f1.style.display=tablefootergroup; f2.style.display='none'; f3.style.display='none';
				document.pag_1.src='/images/2009/pag_on_1.gif'; document.pag_2.src='/images/2009/pag_off_2.gif'; document.pag_3.src='/images/2009/pag_off_3.gif';
				a.style.display='none';  
		};
		if (id==2) { 
				d1.style.display='none'; d2.style.display=tablerowgroup; d3.style.display='none';
				f1.style.display='none'; f2.style.display=tablefootergroup; f3.style.display='none';
				document.pag_1.src='/images/2009/pag_off_1.gif'; document.pag_2.src='/images/2009/pag_on_2.gif'; document.pag_3.src='/images/2009/pag_off_3.gif';
				a.style.display='none';  
		};
		if (id==3) { 
				d1.style.display='none'; d2.style.display='none'; d3.style.display=tablerowgroup;
				f1.style.display='none'; f2.style.display='none'; f3.style.display=tablefootergroup;
				document.pag_1.src='/images/2009/pag_off_1.gif'; document.pag_2.src='/images/2009/pag_off_2.gif'; document.pag_3.src='/images/2009/pag_on_3.gif';
				a.style.display='block';
		};
		return;
	}
	
	function java2euro(val) {
			val = val.toFixed(2);
			val = punti(val);
			val = val.replace(/,/,"-");
			val = val.replace(/\./,",");
			val = val.replace(/-/,"."); 
			return val+'\u20ac';
	}
	
	function euro2java(val) {
		val = trim(val);
		//val=val.substr(0,val.length-1);
		val = val.replace(/€/,"");
		//alert(val);
		val = val.replace(/\./,"");
		val = val.replace(/,/,".");
		return val;
	}
	
	function punti(numero){
	   numero=numero.toString();
	   dp=numero.indexOf(".")!=-1?numero.substring(0,numero.indexOf(".")).length:numero.length;
	   for (i=dp-3;i>0;i-=3)
	      numero=numero.substring(0,i)+","+numero.substr(i);
	   numero=numero.replace(/-,/,"-");
	   return numero
   }	
	
function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
	
	function calcola(r,codice,chk)
	{
		
		errore=0;
		
		var confezioni=document.getElementById("e"+r).value;
		if(confezioni == '') confezioni="0";	// ATTENZIONE ''/0 => JS Error
		confezioni=parseInt(confezioni);
		if (chk==1)
		{
			var qmin=document.getElementById("q"+r).firstChild.nodeValue;
			
			qmin=parseInt(qmin);
			//if ((qmin>confezioni)&&(confezioni>0))
			//deve essere multiplo del qmin
			if (confezioni%qmin != 0)
			{
				//alert("La quantita' inserita e' minore di quella ordinabile");
				alert("La quantita' inserita non e' un multiplo ordinabile.");
				document.getElementById("e"+r).value="";
				document.getElementById("l"+r).innerHTML ="&nbsp;";
				errore=1;
			}
		};
		
		if ((errore==0)&&(confezioni>=0))
		{
			var prezzo=trim(document.getElementById("p"+r).firstChild.nodeValue);
			prezzo = euro2java(prezzo);
			
			if (chk!=1) { var pezzi_confezione=document.getElementById("pc"+r).firstChild.nodeValue; } else {pezzi_confezione=1;};
			
			var tot=parseFloat(prezzo)*confezioni*pezzi_confezione;

			tot=parseFloat(parseFloat(tot).toFixed(2));
			var risC=document.getElementById("l"+r);
			
			tot_euro = java2euro(tot);
			var txt=document.createTextNode(tot_euro);
			if (risC.hasChildNodes()) 
			{ 
				prevTot=trim(risC.firstChild.nodeValue);
				//prevTot=prevTot.substr(0,prevTot.length-1);
				//alert(prevTot);
				prevTot = euro2java(prevTot);
			//	alert(prevTot);
				totaleForm=totaleForm-prevTot;
				//alert(totaleForm);
				risC.innerHTML ="&nbsp;";
				//risC.removeChild(risC.childNodes[0]);
			}
			
			
			if (tot!=0)
			{
				//risC.appendChild(txt);
				risC.innerHTML = trim(tot_euro);
				totaleForm=totaleForm+tot;
				totaleForm=parseFloat(parseFloat(totaleForm).toFixed(2));
			}
			
			
			var idTotal=document.getElementById("total");
			var idsubTotal1=document.getElementById("subtotal1");
			var idsubTotal2=document.getElementById("subtotal2");
			
			if (idTotal.hasChildNodes()) idTotal.removeChild(idTotal.childNodes[0]);
			if (idsubTotal1 && idsubTotal1.hasChildNodes()) idsubTotal1.removeChild(idsubTotal1.childNodes[0]);
			if (idsubTotal2 && idsubTotal2.hasChildNodes()) idsubTotal2.removeChild(idsubTotal2.childNodes[0]);
			
			if (totaleForm>0) 
			{
				totaleForm = parseFloat(parseFloat(totaleForm).toFixed(2));
				//var newTot=document.createTextNode(totaleForm.toFixed(2)+'\u20ac');
				var newTot=document.createTextNode(java2euro(totaleForm));
				idTotal.appendChild(newTot);
				//var newTot=document.createTextNode(totaleForm.toFixed(2)+'\u20ac');
				var newTot=document.createTextNode(java2euro(totaleForm));
				if(idsubTotal1) idsubTotal1.appendChild(newTot);
				//var newTot=document.createTextNode(totaleForm.toFixed(2)+'\u20ac');
				var newTot=document.createTextNode(java2euro(totaleForm));
				if(idsubTotal2) idsubTotal2.appendChild(newTot); 
			}
			if (chk==0)
			{

				if (totaleForm>=1000)
				{
					// commuto ad icona grigia
					oldic=document.getElementById("agg_ordine_img");
					oldic.removeChild(oldic.childNodes[0]);
					newic=document.createElement("img");
					newic.setAttribute("src","images/aggiungi_ordine.gif");
					newic.setAttribute("border","0");
					oldic.appendChild(newic);
					
				} 
				else 
				{ //ritorno alla rossa
					oldic=document.getElementById("agg_ordine_img");
					oldic.removeChild(oldic.childNodes[0]);
					newic=document.createElement("img");
					newic.setAttribute("src","images/aggiungi_ordine_red.gif");
					newic.setAttribute("border","0");
					oldic.appendChild(newic);					
				}
			}
			confezioniArray[codice+""]=confezioni;
			totaleArray[codice+""]=tot;
		}
	
	}
