var insiemi=new crearray(11);
var prodotti2 = "";

function prezz2() {
var stringa=leggi("eurokigi");
if (stringa != null) {
elabora(stringa);
var totale = elabora2();
return totale;
}
else {
var totale = 0;
return totale;
}
}

function cookies(nome, valore, dataf) {
     document.cookie = nome+ "=" + escape(valore) + ((dataf == null) ? "" : ("; expires=" + dataf.toGMTString())) + ";";
}

function crearray(numval) {
this.length=numval;
for (ind=0;ind<=10;ind++) {
this[ind]="";
}
return this;
}

function cancella() {
var data = new Date();
data.setDate(data.getDate() + 356 );
cookies("eurokigi", " ",data);
}

function leggi(nome)
{
  var cerca= nome+"="
  var fine=0
  var offset=0
  if (document.cookie.length>0)
     {
     offset=document.cookie.indexOf(cerca)
     if(offset != -1) {
                        offset += cerca.length
                        fine = document.cookie.indexOf(";", offset)
                        if (fine == -1) {
                                             fine=document.cookie.length   }
     return unescape(document.cookie.substring(offset,fine))
    	}      
        }
}

function manda() {
var vprodotto=elabora3();
var variabili= vprodotto;
return variabili;
}

function elabora (testo) {
inizio=0;
for (x=1;x<=11;x++) {
     insiemi[x]="";
     var cerca="::::";
     offset=0;
     offset=testo.indexOf(cerca);
     if(offset != -1) {
           insiemi[x]=unescape(testo.substring(inizio,offset));
           nuovastringa=testo.substring(offset+cerca.length,testo.length);
           testo=nuovastringa;
           }
     }
}

function elabora3() {
for (y=2;y<=11;y++) {
if (insiemi[y] != "") {
var prodotto = "";
var indirizzo = "";
var costo = "";
var colore = "";
var quant = "";
var offset=insiemi[y].indexOf("=");
if(offset != -1) {
prodotto = insiemi[y].substring(0,offset);
var offset2=insiemi[y].indexOf(",");
if(offset2 != -1) {
quant = insiemi[y].substring(offset+1,offset2);
resto = insiemi[y].substring(offset2+1,insiemi[y].length);
var offset3=resto.indexOf(",");
if(offset3 != -1) {
indirizzo = resto.substring(0,offset3);
costocolore = resto.substring(offset3+1,resto.length);
var offset4=costocolore.indexOf(",");
if(offset4 != -1) {
costo = costocolore.substring(0,offset4);
colore = costocolore.substring(offset4+1,costocolore.length);
}
}
}
}
prodotti2 += quant + " " +prodotto + "----";
}
}
return unescape (prodotti2);
}

function elabora2() {
var offset=insiemi[1].indexOf("=");
if(offset != -1) {
           return unescape (insiemi[1].substring(offset+1,insiemi[1].length));
           }
}

function esegui() {
var tot=prezz2();
var variabili=manda();
document.modulo.prod.value=variabili;
document.modulo.tot.value=tot;
document.modulo.submit();
}
