function ModifyOrder(codID)
{


if (isNaN(document.all('qty' + codID).value)==true) {
   document.all('qty' + codID).value = '';
   }



var qty = document.all('qty' + codID).value;
if (qty=='') {qty = 0;}

var cod = codID;

var RobaName = 'RobaOrder';
var RobaExpdate = new Date ();
RobaExpdate.setTime (RobaExpdate.getTime() + (24 * 60 * 60 * 1000 * 31));

var r =0;
var ckModify = false;
var RobaValue = '';
var aCookie = unescape(document.cookie);
aCookie = aCookie.split('; ');
for (var i=0; i < aCookie.length; i++)
  {var aCrumb = aCookie[i].split('=');
	    if ('RobaOrder' == aCrumb[0]) {
	  	   var aLine = aCrumb[1].split('_');
	  	   for (var ii=0; ii < aLine.length; ii++)
	  	   	   {var aCell = aLine[ii].split('|');
	  	   	   if (aCell[1] == codID) {
			   if (qty!=0) {
	  	 	   	  r++;
				  RobaValue = RobaValue + qty + '|' + cod + ((ii < (aLine.length - 1)) ? '_' : '');
				  ckModify = true;
				  }
		 	   }
			   else {
			   if (aLine[ii]!='Vuoto') {
			   r++;
			   RobaValue = RobaValue + aLine[ii] + ((ii < (aLine.length - 1)) ? '_' : '');
			   }
			   }
			}
	      }
	}


var EndRobaValue = RobaValue.slice((((RobaValue.length - 1) < 0) ? 0 : (RobaValue.length - 1) ), RobaValue.length);
if (EndRobaValue == '_') {RobaValue = RobaValue.slice(0, RobaValue.length - 1)}

if (ckModify == false) {
if (qty!=0) {
   r++;
   RobaValue = RobaValue + ((r < 2) ? '' : '_') + qty + '|' + cod;
   ckModify = true;
   }
   }

if (RobaValue=='') {RobaValue='Vuoto';}

SetCookie (RobaName, RobaValue, RobaExpdate);
}



function SetCookie (RobaName, RobaValue) {
		var argv = SetCookie.arguments;
		var argc = SetCookie.arguments.length;
		var RobaExpires = (argc > 2) ? argv[2] : null;
		 
		var aCookie = unescape(document.cookie);
		aCookie = aCookie.split('; ');

		//alert(RobaName + '=' + escape(RobaValue) + '; path=/; domain=.roba.coop' + ((RobaExpires == null) ? '' : ('; expires=' + RobaExpires.toGMTString())));

         document.cookie = RobaName + '=' + escape(RobaValue) + '; path=/; domain=.roba.coop' + 
         ((RobaExpires == null) ? '' : ('; expires=' + RobaExpires.toGMTString())) 

}


function CheckQty (codID) {

var aCookie = unescape(document.cookie);
aCookie = aCookie.split('; ');
for (var i=0; i < aCookie.length; i++)
  {var aCrumb = aCookie[i].split('=');
	    if ('RobaOrder' == aCrumb[0]) {
		  if (aCrumb.length < 2) {return;}
	  	   var aLine = aCrumb[1].split('_');
	  	   for (var ii=0; ii < aLine.length; ii++)
	  	   	   {var aCell = aLine[ii].split('|');
	  	   	   if (aCell[1] == codID) {
	  	 	   document.all('qty' + codID).value = aCell[0];
		 	   return;}
			   }
	     }
  }
}


function EraseCookie () {
var RobaOld = new Date ();
RobaOld.setTime (RobaOld.getTime() - (24 * 60 * 60 * 1000 * 31));
var aCookie = unescape(document.cookie);
if (aCookie=='') {return;}
aCookie = aCookie.split('; ');
for (var i=0; i < aCookie.length; i++)
  {var aCrumb = aCookie[i].split('=');
  	   document.cookie = aCrumb[0] + ';path=/;domain=.roba.coop; expires=Thu, 01-Jan-1970 00:00:01 GMT';
	   }
}


function ModifyOrderField (Field, Value) {
var RobaOld = new Date ();
RobaOld.setTime (RobaOld.getTime() + (24 * 60 * 60 * 1000 * 31));
if (Value == '') {Value = 'Vuoto'}
SetCookie (Field, Value, RobaOld);
}


function ReadOrderField (Field) {
var V = '';
var aCookie = unescape(document.cookie);
aCookie = aCookie.split('; ');
for (var i=0; i < aCookie.length; i++)
  {var aCrumb = aCookie[i].split('=');
	    if (Field == aCrumb[0]) {
		if (aCrumb.length < 2) {return(V);}
		V = aCrumb[1];
		if (V == 'Vuoto') {V = ''}
	    }
  }

return(V);
}



function loadOrder()
{
var x = 0;
var stop = String.fromCharCode(13 ,10);
var T = '';


var aCookie = unescape(document.cookie);

if (aCookie == '') {
			   alert('Ordine assente');
			   }
			   
aCookie = aCookie.split('; ');
for (var i=0; i < aCookie.length; i++)
  {var aCrumb = aCookie[i].split('=');
	    if ('Mittente' == aCrumb[0]) {
		    if (aCrumb.length < 2) {
			   alert('Manca il Mittente');
			   }
		    if (aCrumb[1] == 'Vuoto') {
			   alert('Manca il Mittente');
			   }
			   x++;
			   T = T + stop;
			   T = T + 'MITTENTE:' + stop;
			   T = T + aCrumb[1] + stop;}}


var aCookie = unescape(document.cookie);
aCookie = aCookie.split('; ');
for (var i=0; i < aCookie.length; i++)
  {var aCrumb = aCookie[i].split('=');
	    if ('Destinazione' == aCrumb[0]) {
		    if (aCrumb.length < 2) {
			   alert('Manca la Destinazione');
			   }
		    if (aCrumb[1] == 'Vuoto') {
			   alert('Manca la Destinazione');
			   }
			   x++;
	  	   	   T = T + stop;
			   T = T + stop;
			   T = T + 'DESTINAZIONE:' + stop;
			   T = T + aCrumb[1] + stop;}}


var aCookie = unescape(document.cookie);
aCookie = aCookie.split('; ');
for (var i=0; i < aCookie.length; i++)
  {var aCrumb = aCookie[i].split('=');
	    if ('Note' == aCrumb[0]) {
		    if (aCrumb.length < 2) {
			   break;}
		    if (aCrumb[1] == 'Vuoto') {
			   break;}
	  	   	   T = T + stop;
			   T = T + stop;
			   T = T + 'NOTE:' + stop;
			   T = T + aCrumb[1] + stop;}}


var aCookie = unescape(document.cookie);
aCookie = aCookie.split('; ');
for (var i=0; i < aCookie.length; i++)
  {var aCrumb = aCookie[i].split('=');
	    if ('RobaOrder' == aCrumb[0]) {
		    if (aCrumb.length < 2) {
			   alert('Manca l\'Ordine');
			   }
		    if (aCrumb[1] == 'Vuoto') {
			   alert('Manca l\'Ordine');
			   }
			   x++;
	  	   	   T = T + stop;
			   T = T + stop;
			   T = T + 'ORDINE:' + stop;
	  	   var aLine = aCrumb[1].split('_');
	  	   for (var ii=0; ii < aLine.length; ii++)
	  	   	   {var aCell = aLine[ii].split('|');
	  	   	   T = T + aCell[0] + ' pz. cod. ' + aCell[1] + ' ' + String.fromCharCode(34) + aCell[2] + String.fromCharCode(34) + '   Euro ' + aCell[3] + stop;}}}

if (x < 3) {
   alert('Ordine incompleto');
   }

T = T + stop;
T = T + stop;
T = T + stop;

document.all('oBody').value=T;

}



function OrderQty()
{

var aCookie = unescape(document.cookie);
aCookie = aCookie.split('; ');
for (var i=0; i < aCookie.length; i++)
  {var aCrumb = aCookie[i].split('=');
	    if ('RobaOrder' == aCrumb[0]) {
		if (aCrumb.length < 2) {return;}
		if (aCrumb[1] == 'Vuoto') {return;}
	  	   var aLine = aCrumb[1].split('_');
	  	   for (var ii=0; ii < aLine.length; ii++)
	  	   	   {var aCell = aLine[ii].split('|');
	  	   	   document.all('qty' + aCell[1]).value = aCell[0];

}
}
}


}




function EraseOrder () {
var RobaOld = new Date ();
var RobaNew = new Date ();
RobaOld.setTime (RobaOld.getTime() - (24 * 60 * 60 * 1000 * 31));
RobaNew.setTime (RobaNew.getTime() + (24 * 60 * 60 * 1000 * 31));
var aCookie = unescape(document.cookie);
if (aCookie=='') {return;}
aCookie = aCookie.split('; ');
for (var i=0; i < aCookie.length; i++)
  {var aCrumb = aCookie[i].split('=');
  	switch(aCrumb[0]) {
    	case 'RobaOrder': //cancella ordine
    		document.cookie = 'RobaOrder=;path=/;domain=.roba.coop; expires=Thu, 01-Jan-1970 00:00:01 GMT';
    		document.cookie = 'RobaOrder=;path=/cat/;domain=.roba.coop; expires=Thu, 01-Jan-1970 00:00:01 GMT';
    	case 'Mittente': //cancella mittente
    		document.cookie = 'Mittente=;path=/;domain=.roba.coop; expires=Thu, 01-Jan-1970 00:00:01 GMT';
    		document.cookie = 'Mittente=;path=/cat/;domain=.roba.coop; expires=Thu, 01-Jan-1970 00:00:01 GMT';
    	case 'Destinazione': //cancella destinazione
    		document.cookie = 'Destinazione=;path=/;domain=.roba.coop; expires=Thu, 01-Jan-1970 00:00:01 GMT';
    		document.cookie = 'Destinazione=;path=/cat/;domain=.roba.coop; expires=Thu, 01-Jan-1970 00:00:01 GMT';
    	case 'Mail': //cancella email
    		document.cookie = 'Mail=;path=/;domain=.roba.coop; expires=Thu, 01-Jan-1970 00:00:01 GMT';
    		document.cookie = 'Mail=;path=/cat/;domain=.roba.coop; expires=Thu, 01-Jan-1970 00:00:01 GMT';
    	case 'Note': //cancella note
    		document.cookie = 'Note=;path=/;domain=.roba.coop; expires=Thu, 01-Jan-1970 00:00:01 GMT';
    		document.cookie = 'Note=;path=/cat/;domain=.roba.coop; expires=Thu, 01-Jan-1970 00:00:01 GMT';
    		break;
    	default: //passa oltre
        	break;
		}
    }


}




function AddCarrello()
{
	alert('aggiunto in carrello.');
	top.document.getElementById('Carrello').style.cssText = 'display: block; border:0px solid #999999; width: 610px; overflow: hidden; float: left;';
	top.frames['Carrello'].location.reload(true);
	top.calcHeight('Carrello',40);
	top.frames['Carrello'].location.hash = 'hTop';
	
}

