totalWines=0;
tdStyle=' style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; color: #444444; text-decoration: none;"';
function initialize()
 { if(location.search.indexOf("?Page=9&")>-1)
    { data=document.getElementById("wineList").innerHTML;
      data=data.split(";");
      html='<table border=0 cellpadding=1 cellspacing=2 width=500>';
      for(i=0;i<data.length-1;i++)
       { data[i]=data[i].split(",");
         html+='<tr>';
         html+='<td'+tdStyle+' width=350><input type="hidden" name="dat'+i+'dat0" value="'+data[i][0]+'">'+data[i][0]+'</td>';
         html+='<td'+tdStyle+' width=50 align="center" nowrap><input type="hidden" name="dat'+i+'dat1" value="'+data[i][1]+'">'+data[i][1]+'</td>';
         html+='<td'+tdStyle+' width=50 align="center" nowrap><input type="text" name="qty'+i+'" onchange="calculate();" size=5></td>';
         html+='<td'+tdStyle+' width=50 align="center" nowrap><div class=tdStyle id="total'+i+'">&nbsp;</div></td></tr>';
       };
      totalWines=data.length-1;
      document.getElementById("winePrices").innerHTML=html;
    };
 };


// variable number of wines dependent on First Name input box named Q2001SB
function calculate()
 { total=0;
   for(i=0;i<totalWines;i++)
    { obj=eval("document.orderForm.qty"+i);
      qty=obj.value;
      if(isNaN(qty) || qty<1)
       { obj.value="";
         qty="";
       }
      else
       { obj2=eval("document.orderForm.dat"+i+"dat1");
         qty*=obj2.value;
       };
      document.getElementById("total"+i).innerHTML=decimalize(Math.floor(qty*100)/100);
      total=Math.floor((total*1+qty)*100)/100;
    };
   document.getElementById("grandTotal").innerHTML=decimalize(total);
 };
// force two decimal currency places or "" for zero values
function decimalize(v)
 { v+="";
   if(v=="" || v=="0")
    { v=""
    }
   else
    { if(v.indexOf(".")==-1)
      v+=".";
     while(v.indexOf(".")>v.length-3)
      v+="0";
    };
   return v;
 };
function copyDetails(cb)
 { if(cb.checked==true)
    { obj=new Array();
      c=0;
      for(i=0;i<2;i++)
       { obj[i]=c;
         while(document.orderForm.elements[obj[i]].name!="First Name")
          obj[i]++;
         c=obj[i]+1;
       };
      for(i=0;i<9;i++)
       document.orderForm.elements[obj[1]+i].value=document.orderForm.elements[obj[0]+i].value;
    };
 };
