function aprifin2(foto,riga)
{
	var larghezza = 50;
	var altezza = 50;
	var rislarg = 5000;
	var risalt = 5000;
	formRef=document.queryx;
	qta=formRef.qta[riga].value;
	formato=formRef.formato[riga].value;
	carlee = formRef.carrella[riga];
		
	qta = qta.replace(',','.')
	
	if ((qta != 0) && (formato != 0))
		{
		carlee.src = "images/conferma1b.gif"
		framecarrello.location.href = "querycarrello.asp?tipo=aggiungi&cod_prodotto="+foto+"&qta="+qta+"&formato="+formato
//		var wino = window.open ("querycarrello.asp?tipo=aggiungi&cod_prodotto="+foto+"&qta="+qta+"&formato="+formato,"wino","toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=no,top=5000,left=5000,width=10,height=10")
//		wino.document.close();
		}
	else
		{
		if (qta == 0)
			{alert("Valorizzare la quantità")}	
		else
			{alert("Selezionare un formato")}	
		}
}

function aprifinall()
{
	var larghezza = 50;
	var altezza = 50;
	var rislarg = 5000;
	var risalt = 5000;
	formRef=document.queryx;
	qta=formRef.qtaall.value;
	formatos=formRef.formato.value;
	carlee = formRef.carrellaall;
		
	qta = qta.replace(',','.')
	
	if ((qta != 0) && (formatos != 0))
		{
		carlee.src = "images/conferma1b.gif"
//		framebasso2.location.href = "querycarrello.asp?tipo=aggiungiall&qta="+qta+"&formato="+formato
//		location.href = "viscarrello.asp"
		framecarrello.location.href = "querycarrello.asp?tipo=aggiungiall&qta="+qta+"&formato="+formatos
		}
	else
		{
		if (qta == 0)
			{alert("Valorizzare la quantità")}	
		else
			{alert("Selezionare un formato")}	
		}
}

function format_number(p,d) 
{
  var r;
  if(p<0){p=-p;r=format_number2(p,d);r="-"+r;}
  else   {r=format_number2(p,d);}
  return r;
}
function format_number2(pnumber,decimals) 
{
  var strNumber = new String(pnumber);
  var arrParts = strNumber.split('.');
  var intWholePart = parseInt(arrParts[0],10);
  var strResult = '';
  if (isNaN(intWholePart))
    intWholePart = '0';
  if(arrParts.length > 1)
  {
    var decDecimalPart = new String(arrParts[1]);
    var i = 0;
    var intZeroCount = 0;
     while ( i < String(arrParts[1]).length )
     {
       if( parseInt(String(arrParts[1]).charAt(i),10) == 0 )
       {
         intZeroCount += 1;
         i += 1;
       }
       else
         break;
    }
    decDecimalPart = parseInt(decDecimalPart,10)/Math.pow(10,parseInt(decDecimalPart.length-decimals-1)); 
    Math.round(decDecimalPart); 
    decDecimalPart = parseInt(decDecimalPart)/10; 
    decDecimalPart = Math.round(decDecimalPart); 

    //If the number was rounded up from 9 to 10, and it was for 1 'decimal' 
    //then we need to add 1 to the 'intWholePart' and set the decDecimalPart to 0. 

    if(decDecimalPart==Math.pow(10, parseInt(decimals)))
    { 
      intWholePart+=1; 
      decDecimalPart="0"; 
    } 
    var stringOfZeros = new String('');
    i=0;
    if( decDecimalPart > 0 )
    {
      while( i < intZeroCount)
      {
        stringOfZeros += '0';
        i += 1;
      }
    }
    decDecimalPart = String(intWholePart) + "." + stringOfZeros + String(decDecimalPart); 
    var dot = decDecimalPart.indexOf('.');
    if(dot == -1)
    {
      decDecimalPart += '.'; 
      dot = decDecimalPart.indexOf('.'); 
    } 
    var l=parseInt(dot)+parseInt(decimals); 
    while(decDecimalPart.length <= l) 
    {
      decDecimalPart += '0'; 
    }
    strResult = decDecimalPart;
  }
  else
  {
    var dot; 
    var decDecimalPart = new String(intWholePart); 

    decDecimalPart += '.'; 
    dot = decDecimalPart.indexOf('.'); 
    var l=parseInt(dot)+parseInt(decimals); 
    while(decDecimalPart.length <= l) 
    {
      decDecimalPart += '0'; 
    }
    strResult = decDecimalPart;
  }
  return strResult;
}

function cambiaprezzo(wid,riga)
{
/*
	formRef=document.query;
	var indice = formRef.formato[riga].options.value;
	formRef.prezzo2[riga].options.value = indice;
	qta = formRef.qta[riga].value;
	prezzo = formRef.prezzo2[riga].options[formRef.prezzo2[riga].selectedIndex].text;
	prezzo = prezzo.replace(',','.')
	prezzoform = format_number(prezzo,2)
	prezzoform = prezzoform.replace('.',',')
	formRef.prezzo[riga].value = prezzoform;
	totriga = prezzo * qta;
	totriga = totriga.toString();
	totriga = totriga.replace(',','.')
	totrigaform = format_number(totriga,2)
	totrigaform = totrigaform.replace('.',',')
	formRef.totriga[riga].value = totrigaform;
*/
}

function cambiaqta(riga)
{
/*
	formRef=document.query;
	prezzo = formRef.prezzo[riga].value;
	prezzo = prezzo.replace(',','.')
	qta = formRef.qta[riga].value;
	totriga = prezzo * qta;
	totriga = totriga.toString();
	totriga = totriga.replace(',','.')
	totrigaform = format_number(totriga,2)
	totrigaform = totrigaform.replace('.',',')
	formRef.totriga[riga].value = totrigaform;
*/
}

function aggiornaqta(cod_prodotto,idformato,valore,npage)
{
	valore = valore.replace(',','.')
	if (isNaN(valore))
		{valore = 0}	

	if (valore == 0)
		{alert("Valorizzare la quantità")}	
	else
		{
		location.href = "querycarrello.asp?tipo=modifica&cod_prodotto="+cod_prodotto+"&formato="+idformato+"&qta="+valore+"&npage="+npage
		}
}

function eliminaart(cod_prodotto,idformato,npage)
{
	framecarrello.location.href = "querycarrello.asp?tipo=cancella&cod_prodotto="+cod_prodotto+"&formato="+idformato+"&npage="+npage
}

function puliscicarr()
{
	if (confirm ("Sei sicuro di voler eliminare il contenuto del carrello ?"))
		{
		framecarrello.location.href = "querycarrello.asp?tipo=pulisci"
		}
	else
		{return false}
	return true
}

function aprifin(foto)
{
	var larghezza = 530;
	var altezza = 400;
	var rislarg = screen.width;
	var risalt = screen.height;
	var win = window.open ("dettagliofoto.asp?foto="+foto,"win","toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=no,top="+((risalt-altezza)/2-20)+",left="+((rislarg-larghezza)/2)+",width="+larghezza+",height=" + altezza + "")
	win.document.close();
}

function apridettprod(id)
{
	var larghezza = 530;
	var altezza = 400;
	var rislarg = screen.width;
	var risalt = screen.height;
	var win = window.open ("dettaglioprod.asp?id="+id,"win","toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=no,top="+((risalt-altezza)/2-20)+",left="+((rislarg-larghezza)/2)+",width="+larghezza+",height=" + altezza + "")
	win.document.close();
}

function confermaordine()
{
	location.href = "confermacarrello.asp"
}

function apriprod(codprodotto,riga)
{
	var larghezza = 50;
	var altezza = 50;
	var rislarg = 5000;
	var risalt = 5000;
	formRef=document.query;
	qta=formRef.qta[riga].value;
	carlee = formRef.carrella[riga];
		
	qta = qta.replace(',','.')
	
	if (qta != 0)
		{
		carlee.src = "images/conferma1b.gif"
		framecarrello.location.href = "querycarrello.asp?tipo=aggiungiprod&cod_prodotto="+codprodotto+"&qta="+qta
		}
	else
		{alert("Valorizzare la quantità")}	
}

function aprinoreg()
{
	var larghezza = 400;
	var altezza = 200;
	var rislarg = screen.width;
	var risalt = screen.height;
	var win = window.open ("visnoreg.htm","win","toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no,top="+((risalt-altezza)/2-20)+",left="+((rislarg-larghezza)/2)+",width="+larghezza+",height=" + altezza + "")
	win.document.close();
}

function aprinogia()
{
	var larghezza = 400;
	var altezza = 200;
	var rislarg = screen.width;
	var risalt = screen.height;
	var win = window.open ("visnogia.htm","win","toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no,top="+((risalt-altezza)/2-20)+",left="+((rislarg-larghezza)/2)+",width="+larghezza+",height=" + altezza + "")
	win.document.close();
}

function NewWindow(url, windowName, w, h, scrolla) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scrolla+',resizable';
	win = window.open(url, windowName, winprops);
	if (parseInt(navigator.appVersion) >= 4) { 
		win.window.focus(); 
	}
	}
