function  changeq(quantity,description){ //add to order and go to a new page
	var deletion = 0;
   mycookies=new Array(20);
   var i=0;
   var startpoint=0;         //  validate the contents of the quantity field (numeric and positive)      qlen = quantity.length;
   ilen = qlen - 1;   invalidq = 0;   numbers = "0123456789";
      for (count=0; count<=ilen; count++)
   {		digit = quantity.substr(count,1);
		if (numbers.indexOf(digit) == -1)		{
			invalidq = 1;	
		}
   }   if (invalidq)
   {
		alert('Invalid quantity, please input a positive integer');
   }   
   else
   {		deleteitem = 0;
		delquantity = 0;		donothing = 0;   	   		workanswer = quantity;   
  	
		whole_len=document.cookie.length;		while(whole_len!=startpoint && i< 20)
		{
			if ((temlen=document.cookie.indexOf(";",startpoint))!=-1)
			{
				mycookies[i]=document.cookie.substring(startpoint,temlen);
				i++;
				startpoint=temlen+1
			}
			else if (startpoint != whole_len)
			{
			 mycookies[i]=document.cookie.substring(startpoint,whole_len);
			 i++;
			 startpoint=whole_len;
			}
		}		
		for (j=0;j<i;j++)
		{
			//filter out cookies that are not used by YEo
			if((mycookies[j].substring(0,2)=="YE")||(mycookies[j].substring(0,3)==" YE"))			{
				// if the item already exists adjust the quantity if not
				// add the new item onto the end of the cookie and replace it    
				acookie = mycookies[j];
				clen = acookie.length;
				
				itemexists = 0;								data= acookie.substring(3,clen);
    
   				items = data.split("endofitem");
		
				// how many items? store in count
		
				start = 0;
				end = data.length - 8;
				count = 0;						while (items[count] != "")				{
						count++;				}	 
						position = 0;
				for (k=0; k<count; k++)				{
					anitem = items[k].split("+");					$itemquantity = anitem[0];					$itemdescription = anitem[1];
					$itemprice = anitem[2];
					
										if ($itemdescription == description)
					{
						position = k;						itemexists = 1;						workanswer = quantity - 0;						anitem[0] = workanswer;						items[k] = anitem.join("+");
					}				}
	
					if (itemexists)
				{
					if (quantity == 0 || workanswer <= 0)
					{						deletion = 1;						// remove the item and display a warning
						items[position] = "";
						if (count == 1)						{
							// delete the cookie as nothing left							deleteitem = 1;								data = items.join("endofitem");
							$thisitem = data;						}
						else
						{							data = "";
							for (k=0; k<count; k++)
							{								if (k != position)								{									data = data + items[k] + "endofitem";																}						
							}							$thisitem = data;
						}					}					else					{
						data = items.join("endofitem");
						$thisitem = data;					}
				}				else				{					if (quantity == 0 || workanswer <= 0)					{
						donothing = 1;					}					else					{
						$thisitem = data + $itemquantity + "+"  + $itemdescription + "+" +  $itemprice + "+" + "endofitem";
					}
				}				 				
				if (deleteitem)
				{					$expiration = new Date((new Date()).getTime() - 10*3600000);
					document.cookie =  "YE=" + $thisitem + "; expires=" + $expiration.toGMTString(); 					location="vieworder.htm";
					alert('The item has been removed from your order.');
				}
				else
				{
					if (!donothing)					{ 						$expiration = new Date((new Date()).getTime() + 10*3600000);
						document.cookie =  "YE=" + $thisitem + "; expires=" + $expiration.toGMTString(); 					
						location="vieworder.htm";
						if (deletion)
						{
							alert('The item has been removed from your order.');
						}					}
				}				
			}        } 
    }  
}

