// 7/11/11 Added the global variable 'salestax' so I don't have to go searching for it in the code each time it changes
//         See also line 763 where the text is 'Sales Tax (8.25%)' -- probably should build the string from the variable
//         rather than hard code it as I do now -- OK it's done.
var cart=new Array(24);
cart[0]=0;  // element 0 holds the number of items in the cart
var cartSize=0;
var currentItem=-1;
var shipping=0;   // is shipping on or off
var salestax=0.0825;

/*  resetItem(mode) receives one of two modes (0 = reset and close, 1 = reset only) and operates on the
      global 'currentItem' idex into the product array. It iterates throught item depending on its type to
      zero out all current input.
      It also updates the cart by decrimenting the items in the cart, removing the item from the cart and
      tidying/compacting the cart.
*/      
function resetItem(mode){ // 
  var n=currentItem;
  var sz=cart[0];
  cart[0]--;
  currentItem=-1;
  var p=0;
  for (i=1; i<=sz&&cart[i]!=n; i++); // search
  if (i<sz) {for (i; i<sz+1; i++) cart[i]=cart[i+1];} // if found, move the back guys forward
  cart[i]=0;
  cart[sz--]=0;
  var ca = pArray[n][8];
  var sa = pArray[n][7];
  switch (pArray[n][0]){
    case 0:   // just pass thru to the bottom to update target objects
      break;
    case 1:   // colors only
      for (i=1; i<=ca[0][0]; i++) ca[i][1]=0;
      break;
    case 2:   // sizes only
      for (i=1; i<=sa[0][0]; i++) sa[i][1]=0;
      break;
    case 3:   // both colors and sizes
      for (i=1; i<=ca[0][0]; i++) for (j=1; j<=sa[0][0]; j++) ca[i][j]=0;
      for (i=1; i<=sa[0][0]; i++) sa[i][1]=0; // clear the size totals
      for (i=1; i<=ca[0][0]; i++) ca[0][i]=0; // clear the color totals
  }
  pArray[n][10]=0; // reset qty.
  pArray[n][11]=0; // reset total item price
  if (mode==0) return hideObj('itemSp');
  else return mkItemForm4a(n);
}
/*  totalPrice(n) receives the item index and iterates through units selected and,
      based on the pricing type (size or just how many, no quantity discounts!), calculates both
      the total price and the total number of units. Both values are inserted into the array.  
*/      
function totalPrice(n){
  var ct=parseInt(pArray[n][10]);
  var pa=pArray[n][9];        // price array
  var ca=pArray[n][8];        // color array
  var sa=pArray[n][7];        // size array
  var tn=0;
  var tc=0;
  if (pArray[n][9]==0) return 0;
  if (pa[0][1]==2){
    for (i=2; i<=pa[0][0]; i++) {
      tc+=pa[i][1]*sa[pa[i][2]][1];
      tn+=sa[pa[i][2]][1];
    }
    var nt=pArray[n][10]-tn;
    tc+=nt*pa[1][1];
    return pArray[n][11]=tc;
  }
  for (i=1; i<=pa[0][0]&&pa[i][0]<ct; i++);
  return pArray[n][11]=pa[i][1]*ct;
}
/** 7/12/11:  Forgotten notes -- this looks to be a first run at the total price for development purposes.
              I'm finding a lot of baggage from the early development.  
function totalPrice1(n){
  var ct=parseInt(pArray[n][10]);
  var pa=pArray[n][9];
  if (pArray[n][9]==0) return 0;
  for (i=1; i<=pa[0][0]&&pa[i][0]<ct; i++); // search for the correct price according to total number
  return pArray[n][11]=pa[i][1]*ct;
}
************************/
//-----------------------------------------------------------
// The following three functions are called by updateArray2() 
// Each function receive the # selected (v) for the array item (n).
// The other inputs are either the chosen color (mode 1), or size (mode 2), or the color and size (mode 3).
// They then set the value into the proper array position then count all the number of item selections
// and finally update the total number selected.
function totColorOnly(v, n, clr){     // handles mode 1
  var ca=pArray[n][8];  // points to the first entry at [n][8] -- the 1st color array
  ca[clr][1]=v;
  var x=0;
  for (i=1; i<=ca[0][0]; i++) x+=ca[i][1];
  pArray[n][10]=x;
  return pArray[n][10];
}
function totSize(v, n, sz){           // handles mode 2
  var sa = pArray[n][7];
  sa[sz][1] = v;
  var x=0;
  for (i=1; i<=sa[0][0]; i++) x+=sa[i][1];
  pArray[n][10]=x;
  return pArray[n][10];
}
function totColor(v, n, clr, sz){     // handles mode 3
  var sa = pArray[n][7];  // size array  -- element 0 holds # sizes
  var ca = pArray[n][8];  // color array -- element 0 holds # colors, element 1 has an array of sizes associated
  var x=0; var y=v-ca[clr][sz];

  ca[clr][sz]=v;
  sa[sz][1]+=y;
  for (i=1, z=0; i<=sa[0][0]; i++) x+=ca[clr][i];    // this sums by reading each field value
  ca[0][clr]=x;
  for (i=1, y=0; i<=ca[0][0]; i++) y+=ca[0][i];
  pArray[n][10]=y;
  var tx=""+clr+"CTOT";
  var ctot=document.getElementById(tx);
  ctot.innerHTML="<font id='cart-font'><center>"+x+"</font></center>";
  return pArray[n][10];
}
//-----------------------------------------------------------
// updateArray2() is called each time the item selection object receives input.
//		It updates the item database/array.
function updateArray2(inp, n, clr, sz){
  if (isNaN(inp.value)){alert("Please enter numbers only"); return mkItemForm4a(n);}
  if (pArray[n][10]==0) cart[++cart[0]]=n;    //
  var v = 0;
  if (inp.value!="") v=parseInt(inp.value);
  switch (pArray[n][0]){
    case 0:   // just pass thru to the bottom to update target objects
      pArray[n][10]=v;
      break;
    case 1:   // colors only
      var t = totColorOnly(v, n, clr);
      var tx =""+n+"TOT";
      var tt=document.getElementById(tx);
      tt.innerHTML="<font id='cart-font'><center>"+t+"</font></center>";
      break;
    case 2:   // sizes only
      var t = totSize(v, n, sz);
      var tx =""+n+"TOT";
      var tt=document.getElementById(tx);
      tt.innerHTML="<font id='cart-font'><center>"+t+"</font></center>";
      break;
    case 3:   // both colors and sizes
      var t = totColor(v, n, clr, sz);
      var tx=""+n+"TOT";
      var ctot=document.getElementById(tx);
      ctot.innerHTML="<font id='cart-font'><center>"+t+"</font></center>";
  }
//  totalPrice(n);
  var p=Number(totalPrice(n)).toFixed(2);
  var tx=""+n+"PTOT";
  var ptot=document.getElementById(tx);
  if (ptot==null) return 1;
  ptot.innerHTML="<font id='cart-font'><center>"+p+"</font></center>";
  return 0;
}
// The following mkTxtMode functions receive the item number and build the corresponding selection object text.
//		Each function is specific to a single product "mode" based on color/sizing and pricing.
// 		All are called by mkItemForm4a().

// neither sizes nor colors
function mkTxtMode0(n){
  var txt="<b<center>Qty</center</b></td></tr>";
  var x = parseInt(pArray[n][10]);
  var tx;
  if (x!=0) tx="value="+x+""; else tx="";
  txt+="<tr><td><input class='cart-font-class' id="+n+"'QTY' size=1 ";
  txt+="onchange='updateArray2(this, "+n+", 0, 0)' "+tx+"></td>";
  if (pArray[n][9]!=0){
    var sa=pArray[n][9];
    var m=sa[0][0]+1;
    txt+="</tr><tr><td colspan="+m+" align=center valign=center><font id='cart-font'><b>Price</b></font></td></tr><tr>";
    var newDiv = document.createElement("div");  // now create a new <div> and 'register' it with the document
    document.getElementsByTagName("div").item(2).appendChild(newDiv);
    newDiv.id = ""+n+"PTOT";
    var t=pArray[n][11];
    var tn=Number(t).toFixed(2);
    txt+="<td align=center colspan='m'><div id='"+n+"PTOT' style='{background-color:lightgray; color:black; position:relative; visibility:inherit; ";
    txt+="size:8pt}'><font id='cart-font'>"+tn+"</div></b></font></td>";
  }
  return txt;
}
// colors only
function mkTxtMode1(n){
  var ca=pArray[n][8];
  var txt="<b>Color</b></td><td><font id='cart-font'><b><center>Qty</center</b></td></tr>";  // color heading
  for (i=1; i<=ca[0][0]; i++){
    var x = parseInt(ca[i][1]);
    var tx="";
    if (x!=0 && !isNaN(x)) tx+="value="+x+"";
    txt+="<td align=right valign=top><font id='cart-font'>"+ca[i][0]+"</font></td>";
    txt+="<td><input class='cart-font-class' id='"+j+"COLOR' size=1 onchange='updateArray2(this, "+n+", "+i+", 0)'";
    txt+=""+tx+"></font></td></tr>";
  }
  txt+="<tr><td><center><font id='cart-font'><b>Total</b></font></center></td>";
  txt+="<td align='center'><center><font id='cart-font'>";
  var newDiv = document.createElement("div");  // now create a new <div> and 'register' it with the document
  document.getElementsByTagName("div").item(2).appendChild(newDiv);
  newDiv.id = ""+n+"TOT";
  x=parseInt(pArray[n][10]);
  if (isNaN(x)) x=0;
  txt+="<div id='"+n+"TOT' style='{background-color:lightgray; color:black; position:relative; visibility:inherit; ";
  txt+="size:8pt;}'><font id='cart-font'><center>"+x+"</div></b></font></center></td>";
  if (pArray[n][9]!=0){
    var sa=pArray[n][9];
    var m=sa[0][0]+1;
    txt+="</tr><tr><td align=right><font id='cart-font'><b>Price $</b></font></td>";
    var newDiv = document.createElement("div");  // now create a new <div> and 'register' it with the document
    document.getElementsByTagName("div").item(2).appendChild(newDiv);
    newDiv.id = ""+n+"PTOT";
    var t=pArray[n][11];
    var tn=Number(t).toFixed(2);
    txt+="<td align=center><div id='"+n+"PTOT' style='{background-color:lightgray; color:black; position:relative; visibility:inherit; ";
    txt+="size:8pt}'><font id='cart-font'>"+tn+"</div></b></font></td>";
  }
  return txt;
}
// sizes only
function mkTxtMode2(n){
  var sa=pArray[n][7];
  var txt="<b>Size</b></td><td><font id='cart-font'><b><center>Qty</center</b></td></tr>";  // color heading
  for (i=1; i<=sa[0][0]; i++){
    var x = parseInt(sa[i][1]);
    var tx="";
    if (x!=0) tx+="value="+x+"";
    txt+="<td align=right valign=top><font id='cart-font'>"+sa[i][0]+"</font></td>";
    txt+="<td><input class='cart-font-class' id='"+j+"COLOR' size=1 onchange='updateArray2(this, "+n+", 0, "+i+")'";
    txt+=""+tx+"></td></tr>";
  }
  txt+="<tr><td><center><font id='cart-font'><b>Total</b></font></center></td>";
  txt+="<td align='center'><center><font id='cart-font'>";
  var newDiv = document.createElement("div");  // now create a new <div> and 'register' it with the document
  document.getElementsByTagName("div").item(2).appendChild(newDiv);
  newDiv.id = ""+n+"TOT";
  txt+="<div id='"+n+"TOT' style='{background-color:lightgray; color:black; position:relative; visibility:inherit; ";
  txt+="size:8pt;}'><font id='cart-font'><center>"+parseInt(pArray[n][10])+"</div></b></font></center></td>";
  if (pArray[n][9]!=0){
    var m=sa[0][0]+1;
    txt+="</tr><tr><td align=right><font id='cart-font'><b>Price  $</font></b></td>";
    var newDiv = document.createElement("div");  // now create a new <div> and 'register' it with the document
    document.getElementsByTagName("div").item(2).appendChild(newDiv);
    newDiv.id = ""+n+"PTOT";
    var t=pArray[n][11];
    var tn=Number(t).toFixed(2);
    txt+="<td align=center><div id='"+n+"PTOT' style='{background-color:lightgray; color:black; position:relative; visibility:inherit; ";
    txt+="size:8pt}'><font id='cart-font'>"+tn+"</div></b></font></td>";
  }
  return txt;
}
// colors and sizes
function mkTxtMode3(n){
  var mode=pArray[n][0];
  var ca=pArray[n][8];
  var sa=pArray[n][7];
  var txt="";
  var cs=sa[0][0]+1;
  var sp="nbsp;";
  if (ca[0][0]==1) txt+="</td>"; else txt+="<b>Color</b></td>";  // color heading
  for (j=1; j<=sa[0][0]; j++){txt+="<td><center><font id='cart-font'>"+sa[j][0]+"</font></center></td>";} // writes in the sizes available
  txt+="<td width=50><center><font id='cart-font'><b>Total</b></font></center></td></tr>";  // terminate the row
  for (i=1; i<=ca[0][0]; i++){ // make a row of inputs ending in a total #
    txt+="<tr><td align=right valign=top><font id='cart-font'>"+ca[i][0]+"</font></td>"; // write the color name
    for (j=1; j<=sa[0][0]; j++){  // map in the inputs ordered by item size
      var x=parseInt(ca[i][j]);
      if (isNaN(x)) {x=0; ca[i][j]=0;}
      txt+="<td><input class='cart-font-class' id='"+j+"SVAL' size=1";
      if (x!=0) txt+=" value="+x+"";     // add-in the current value, blank if 0
      txt+=" onchange='updateArray2(this, "+n+", "+i+", "+j+")'><center></td>";
    }
    txt+="<td align='center'><center><font id='cart-font'>";
    var newDiv = document.createElement("div");  // now create a new <div> and 'register' it with the document
    document.getElementsByTagName("div").item(1).appendChild(newDiv);
    newDiv.id = ""+i+"CTOT";
    txt+="<div id='"+i+"CTOT' style='{background-color:lightgray; color:black; position:relative; ";
    txt+="visibility:inherit; ";
    x=parseInt(ca[0][i]);
    if (isNaN(x)) {x=0; ca[0][i]=0;}
    txt+="size:8pt}'><font id='cart-font'><center>"+x+"</div></b></font></center></td>";
  }
  txt+="</tr><tr><td colspan="+cs+" align=right><font id='cart-font'><b>Total: </b></font></td>";
  var newDiv = document.createElement("div");  // now create a new <div> and 'register' it with the document
  document.getElementsByTagName("div").item(2).appendChild(newDiv);
  newDiv.id = ""+n+"TOT";
  ref = newDiv.style;
  txt+="<td><div id='"+n+"TOT' style='{background-color:lightgray; color:black; position:relative; visibility:inherit; ";
  txt+="size:8pt;}'><font id='cart-font'><center>"+parseInt(pArray[n][10])+"</div></b></font></center></td>";
  if (pArray[n][9]!=0){
    txt+="</tr><tr><td colspan="+cs+" align=right><font id='cart-font'><b>Price  $</b></font></td>";
    var newDiv = document.createElement("div");  // now create a new <div> and 'register' it with the document
    document.getElementsByTagName("div").item(2).appendChild(newDiv);
    newDiv.id = ""+n+"PTOT";
    var t=pArray[n][11];
    var tn=Number(t).toFixed(2);
    txt+="<td align=center><div id='"+n+"PTOT' style='{background-color:lightgray; color:black; position:relative; visibility:inherit; ";
    txt+="size:8pt}'><font id='cart-font'>"+tn+"</div></b></font></td>";
  }
  return txt;
}
// mkItemForm4a(n) builds the item (n) selection object and, when changes are made, updates the item array and 
//		displayed totals.
function mkItemForm4a(n){
  currentItem=n;
  var rf=getRef('itemSp');
  var sty=getSty('itemSp');
  var s1="hideObj('itemSp')";
  var mode=pArray[n][0];
  var ca=pArray[n][8];
  var txt="<table cellpadding=5><tr><td colspan=2 align='center' class='banner-class'><b>"+pArray[n][4]+"</b></td></tr><tr>";
  txt+="<td valign=top width=350><img src="+pArray[n][1]+" align=left hspace=5 width="+(pArray[n][2])/2+" height="+(pArray[n][3])/2+">"; // insert scaled image
  txt+="<font id='cart-font'>"+pArray[n][5]+"</font>";     // insert the description
  if(pArray[n][9]!=0){    // is there a price list?
    txt+="<hr><table cellpadding=5><tr>";
    var p=pArray[n][9];
    var np=1;
    var tx;
    if (p[0][0]>1 && p[0][1]!=2) {txt+="<td align='right' valign=bottom><font id='cart-font'><b>Quantity</b></font></td>";
      for (i=1; i<=p[0][0]; i++){
        (p[i][0]!="+") ? (tx=""+np+"-"+p[i][0]+"") : (tx=""+np+"+");
        txt+="<td align='center'><font id='cart-font'>"+tx+"</font></td>";
        np=p[i][0]+1;
      }
    }
    else if (p[0][1]==2) {txt+="<td align='right' valign=bottom><font id='cart-font'><b>Sizes</b></font></td>";
      for (i=1; i<=p[0][0]; i++){
        tx=""+p[i][0]+"";
        txt+="<td align='center'><font id='cart-font'><b>"+tx+"</b></font></td>";
        np=p[i][0]+1;
      }
    }
    txt+="</tr><tr><td><font id='cart-font'><b>Price/ea.</b></font></td>";
    for (i=1; i<=p[0][0]; i++){
      txt+="<td align='center' class='price-class'><font id='cart-font'>"+Number(p[i][1]).toFixed(2)+"</font></td>";
    }
    txt+="</tr></table>";
  }
  txt+="</td><td valign=top>";
  txt+="<table><tr><td align='right' valign='center'><font id='cart-font'>"; // INNER TABLE
  if (mode == 3) txt+=mkTxtMode3(n);      // both colors and sizes
  if (mode == 2) txt+=mkTxtMode2(n);      // sizes only
  if (mode == 1) txt+=mkTxtMode1(n);      // colors only
  if (mode == 0) txt+=mkTxtMode0(n);      // neither sizes nor colors
  txt+="</tr></table></td></tr><tr><td colspan=2 align=right><hr>";      // end of INNER
  txt+=mkMenuTbl(n);
  txt+="</td></tr></table>";  // end of OUTER
  rf.innerHTML=txt;
  return sty.visibility="visible";
}
function chkOut(){
  if (cart[0]== 0) {alert('You have no items in your cart'); return 1;}
  hideObj("itemSp");
  return mkContactForm();
}
// mkMenuTbl() adds buttons on the lower right of the parent object. The buttons are: cancel, reset, continue, check-out
function mkMenuTbl(n){
  var txt="<table><tr><td id='tr0' align=center class='mode-class' ";
  txt+="onMouseOver=chgClass('tr0','mode-class-on') onMouseOut=chgClass('tr0','mode-class') ";
  txt+="onClick=resetItem(0)>cancel</td>";
  txt+="<td id=tr1 align=center class='mode-class' ";
  txt+="onMouseOver=chgClass('tr1','mode-class-on') onMouseOut=chgClass('tr1','mode-class') ";
  txt+="onClick='resetItem(1)'>reset</td>";
  txt+="<td id=tr2 align=center class='mode-class' ";
  txt+="onMouseOver=chgClass('tr2','mode-class-on') onMouseOut=chgClass('tr2','mode-class') ";
  txt+="onClick=moreShopping('itemSp')>add to cart</td>";
  txt+="<td id=tr3 align=center class='mode-class' ";
  txt+="onMouseOver=chgClass('tr3','mode-class-on') onMouseOut=chgClass('tr3','mode-class') ";
  txt+="onClick=chkOut()>check-out</td>";
  txt+="</tr></table>";
  return txt;
}
// noEntryText(inp) simply checks for ANY input. If no input, it belches and alert.
function noEntryText(inp) {
  var txt = inp.value;
  var tx="";
  if (txt!="") return true;
  if (inp.name=='realname' ) tx='Name';
  if (inp.name=='email') tx='Email Address';
  if (inp.name=='phone') tx='Phone Number';
  if (inp.name=='dept') tx='Department';
  if (inp.name=='floor') tx='Floor';
  if (inp.name=='address2') return true;
  if (inp.name=='address1') tx='Address 1';
  if (inp.name=='city') tx='City';
  if (inp.name=='state') tx='State';
  if (inp.name=='zip') tx='Zip';
  txt="Please enter the "+tx+" before submitting your order";
  alert(txt);
  inp.focus();
//  inp.select();
  return false;
}

function chkForm(form){
  for(i=0; i<3; i++){
    if(noEntryText(form.elements[i])==false) {return false;}
  }
  var eStr=new String(form.elements[1].value);
  if (emailCheck(eStr)==false){
    alert("Your email address appears to be incorrect. Please examine and resubmit.");
    form.elements[1].focus();
    return false;
  }
  if (document.cart.deliver[0].checked==true)
    for (i=5; i<7; i++) if (noEntryText(form.elements[i])==false) {return false;}
  if (document.cart.deliver[1].checked==true)
    for (i=7; i<=12; i++) if (noEntryText(form.elements[i])==false) {return false;}
  for (i=1; i<=cart[0]; i++) {currentItem=cart[i]; resetItem(0);}
  var cs=getSty("cartSp");
  cs.visibility="hidden";
  return form.submit();
}

function chkRadio(r){
//  var i = (r==0 ? 1 : 0);
  var f00=document.getElementById('dept');    // form
  var f01=document.getElementById('floor');   // form
  var f10=document.getElementById('address1');// form
  var f11=document.getElementById('address2');// form
  var f12=document.getElementById('city');    // form
  var f13=document.getElementById('state');   // form
  var f14=document.getElementById('zip');     // form

  var f0=document.getElementById('fr8');      // display
  var f1=document.getElementById('Freight');  // form
  var t0=document.getElementById('ttl');      // display
  var t1=document.getElementById('Total');    // form
  var it=document.getElementById('Ittl');     // form
  var st=document.getElementById('Subttl');   // form
  var subt=parseFloat(it.value);
  var tx=document.getElementById('tax');      // form

  var td0=document.getElementById('hall');
  var td1=document.getElementById('ups');

  var tax=parseFloat(tx.value);
  subt+=tax;
  if (r==0) {                                        // this means city hall delivery
    if (document.cart.deliver[1].checked==true){     // UPS already checked? CHANGED 8/24  10:43AM
      document.cart.deliver[0].checked=true;         // turn city hall on
      document.cart.deliver[1].checked=false;        // turn off UPS
      td0.innerHTML="<font color='red'><i>*</font>City Hall Delivery</i>";
      td1.innerHTML="<font color='black'><i>City Site or UPS/FedEx Delivery</i>";
/*      shipping=0;
      var x=f1.value;         // current freight price
      if (x=="call" || x=="n/c"){
        f1.value="n/c";
        f0.innerHTML="n/c";
        t0.innerHTML="$"+Number(subt).toFixed(2)+"";
//        return 0;
      }
      else {
        var y=parseFloat(t1.value)-x;       // remove freight from the total price
        f1.value='n/c';
        f0.innerHTML="n/c";
        t0.innerHTML="$"+Number(y).toFixed(2)+"";
        t1.value=Number(y).toFixed(2);
      }		*/
    }
///////////////////////////
    f00.disabled=false;
    f01.disabled=false;
    f10.disabled=false;
    f11.disabled=false;
    f12.disabled=true;
    f13.disabled=true;
    f14.disabled=true;
    f00.className='form-font-class-on';
    f01.className='form-font-class-on';
    f10.className='form-font-class-on';
    f11.className='form-font-class-on';
    f12.className='form-font-class-off';
    f13.className='form-font-class-off';
    f14.className='form-font-class-off';
///////////////////////////
    return 0;
  }
  else {                                             // this means UPS delivery
    if (document.cart.deliver[0].checked==true){          // city hall already checked? CHANGED 8/24  10:43AM
      document.cart.deliver[1].checked=true;         // turn UPS on
      document.cart.deliver[0].checked=false;        // turn city hall off
      td0.innerHTML="<font color='black'><i>City Hall Delivery</i></font>";
      td1.innerHTML="<font color='red'><i>*</font>City Site or UPS/FedEx Delivery</i></font>";
/*      shipping=1;
      for (i=1; i<=freight[0][0] && subt>parseFloat(freight[i][0]); i++); // lookup the shipping price
      if (i==freight[0][0]) {    // over $200
        f1.value="call";
        t1.value="call";
        f0.innerHTML="call";
        t0.innerHTML="call";		
       return 0;
      }
      else {
        var fr=freight[i][1];     // shipping
        var y=Number(subt+fr).toFixed(2);
        f1.value=Number(fr).toFixed(2);
        f0.innerHTML=""+Number(fr).toFixed(2)+"";
        t0.innerHTML="$"+y+"";
        t1.value=y;
      }		*/
///////////////////////////
      f00.disabled=true;
      f01.disabled=true;
      f10.disabled=false;
      f11.disabled=false;
      f12.disabled=false;
      f13.disabled=false;
      f14.disabled=false;
      f00.className='form-font-class-off';
      f01.className='form-font-class-off';
      f10.className='form-font-class-on';
      f11.className='form-font-class-on';
      f12.className='form-font-class-on';
      f13.className='form-font-class-on';
      f14.className='form-font-class-on';
///////////////////////////
    }
    return 0;
  }
  return 0;
}
/*  7/12/11: Below appears to be a version that includes a fair amount of logic dealing with both
      the button status and the freight charges.
*/
/*
function chkRadio0(r){
//  var i = (r==0 ? 1 : 0);
  var f00=document.getElementById('dept');    // form
  var f01=document.getElementById('floor');   // form
  var f10=document.getElementById('address1');// form
  var f11=document.getElementById('address2');// form
  var f12=document.getElementById('city');    // form
  var f13=document.getElementById('state');   // form
  var f14=document.getElementById('zip');     // form

  var f0=document.getElementById('fr8');      // display
  var f1=document.getElementById('Freight');  // form
  var t0=document.getElementById('ttl');      // display
  var t1=document.getElementById('Total');    // form
  var it=document.getElementById('Ittl');     // form
  var st=document.getElementById('Subttl');   // form
  var subt=parseFloat(it.value);
  var tx=document.getElementById('tax');      // form

  var td0=document.getElementById('hall');
  var td1=document.getElementById('ups');

  var tax=parseFloat(tx.value);
  subt+=tax;
  if (r==0) {                                        // this means city delivery  CHANGED 1/5/10 from City Hall only
    if (document.cart.deliver[1].checked==true){     // UPS already checked? CHANGED 8/24  10:43AM
      document.cart.deliver[0].checked=true;         // turn city hall on
      document.cart.deliver[1].checked=false;        // turn off UPS
      td0.innerHTML="<font color='red'><i>*</font>For City Delivery Only</i>";
      td1.innerHTML="<font color='red'><i>*</font>City Site or UPS/FedEx Delivery</i>";
      shipping=0;
      var x=f1.value;         // current freight price
      if (x=="call" || x=="n/c"){
        f1.value="n/c";
        f0.innerHTML="n/c";
        t0.innerHTML="$"+Number(subt).toFixed(2)+"";
//        return 0;
      }
      else {
        var y=parseFloat(t1.value)-x;       // remove freight from the total price
        f1.value='n/c';
        f0.innerHTML="n/c";
        t0.innerHTML="$"+Number(y).toFixed(2)+"";
        t1.value=Number(y).toFixed(2);
      }
    }
///////////////////////////
    f00.disabled=false;
    f01.disabled=false;

    
    f00.className='form-font-class-on';
    f01.className='form-font-class-on';
    f10.className='form-font-class-on';
    f11.className='form-font-class-on';
    f12.className='form-font-class-on';
    f13.className='form-font-class-on';
    f14.className='form-font-class-on';
///////////////////////////
    return 0;
  }
  else {                                             // this means UPS delivery
    if (document.cart.deliver[0].checked==true){     // city hall already checked? CHANGED 8/24  10:43AM
      document.cart.deliver[1].checked=true;         // turn UPS on
      document.cart.deliver[0].checked=false;        // turn city hall off
      td0.innerHTML="<font color='black'><i>For City Delivery Only</i></font>";
      td1.innerHTML="<font color='red'><i>*</font>City Site or UPS/FedEx Delivery</i></font>";
      shipping=1;
      for (i=1; i<=freight[0][0] && subt>parseFloat(freight[i][0]); i++); // lookup the shipping price
      if (i==freight[0][0]) {    // over $200
        f1.value="call";
        t1.value="call";
        f0.innerHTML="call";
        t0.innerHTML="call";
//        return 0;
      }
      else {
        var fr=freight[i][1];     // shipping
        var y=Number(subt+fr).toFixed(2);
        f1.value=Number(fr).toFixed(2);
        f0.innerHTML=""+Number(fr).toFixed(2)+"";
        t0.innerHTML="$"+y+"";
        t1.value=y;
      }
///////////////////////////
      f00.disabled=true;
      f01.disabled=true;
       
      
      f00.className='form-font-class-off';
      f01.className='form-font-class-off';
      f10.className='form-font-class-on';
      f11.className='form-font-class-on';
      f12.className='form-font-class-on';
      f13.className='form-font-class-on';
      f14.className='form-font-class-on';            
///////////////////////////
    }
    return 0;
  }
  return 0;
}
******************************/
function mkContactForm(){
  var tot=0;
  var txt="";

  for (i=1; i<=cart[0]; i++){
    var x = cart[0];
    var y = cart[i];
    var tx="total: "+pArray[y][10]+", price: $"+Number(pArray[y][11]).toFixed(2)+"";
    tot+=parseFloat(pArray[y][11]);
    var sa = pArray[y][7];
    var ca = pArray[y][8];
    switch (pArray[y][0]){
      case 3:                     // sizes and colors
        var t="<input type=hidden name='"+i+". "+pArray[y][4]+"' value='"+tx+"'>";
        txt+=t;
        for (k=1; k<=ca[0][0]; k++){  // run through the color array
          if (ca[0][k]!=0){            // does the color have a total?
            tx="";
            for (j=1; j<=sa[0][0]; j++){
              tx += ""+sa[j][0]+": "+ca[k][j]+", ";
            }
            tx+="total = "+ca[0][k]+""; // total color
            t="<input type=hidden name='&nbsp;&nbsp;&nbsp;&nbsp;"+i+"."+k+"- "+ca[k][0]+"' value='"+tx+"'>";
            txt+=t;
          }
        }
        break;
      case 2:                         // sizes only
        var t="<input type=hidden name='"+i+". "+pArray[y][4]+"' value='"+tx+"'>";
        txt+=t;
        tx="";
        for (k=1; k<=sa[0][0]; k++){
          tx += ""+sa[k][0]+": "+sa[k][1]+", ";
        }
        var t="<input type=hidden name='"+i+". "+pArray[y][4]+"' value='"+tx+"'>";
        txt+=t;
        break;
      case 1:                         // colors only
        tx="total: "+pArray[y][10]+", price: $"+Number(pArray[y][11]).toFixed(2)+", "; // item name
        for (k=1; k<=ca[0][0]; k++){
          tx += ""+ca[k][0]+": "+ca[k][1]+",";
        }
        var t="<input type=hidden name='"+i+". "+pArray[y][4]+"' value='"+tx+"'>";
        txt+=t;
        break;
      case 0:                        // neither colors or sizes
        var tx="total: "+pArray[y][10]+", price: $"+Number(pArray[y][11]).toFixed(2)+""; // item name, total and $$
        var t="<input type=hidden name='"+i+". "+pArray[y][4]+"' value='"+tx+"'>";
        txt+=t;
        break;
    }
  }
  var t="<input id='Ittl' type=hidden name='Item total' value='"+Number(tot).toFixed(2)+"'>";
  txt+=t;
  var tax=tot*salestax;
  t="<input id='tax' type=hidden name='Sales Tax' value='"+Number(tax).toFixed(2)+"'>";
  txt+=t;
  tot+=tax;
  var subt=tot;
  t="<input id='Subttl' type=hidden name='Subtotal' value='"+Number(subt).toFixed(2)+"'>";
  txt+=t;
  //////////////////////////////////////// 6/22/09
  if (shipping==0){
    shp="n/c";
    tot=Number(subt).toFixed(2);
  }
  else {
   for (i=1; i<=freight[0][0] && subt>parseFloat(freight[i][0]); i++);
   shp=freight[i][1];
   if (shp=="call") tot="call";
   else {shp=Number(parseFloat(shp)).toFixed(2); tot=Number(parseFloat(subt+shp)).toFixed(2)};
  }
  ////////////////////////////////////////
  t="<input id='Freight' type=hidden name='Freight' value='"+0+"'>";
  t+="<input id='Total' type=hidden name='Total' value='"+Number(tot).toFixed(2)+"'>";
  txt+=t;
  var hd=getRef("hidden-data");
  hd.innerHTML=txt;
  var ci=getRef("cart-items");
  txt=mkItemStrs();
  ci.innerHTML=txt;
//  var rf=getRef("cartSp");
  return showObj("cartSp");
}

function moreShopping(o){
  currentItem=-1;
  return hideObj(o);
}
function addFreightTbl(){
  var np=1;
  var tx;
  var txt="<tr><td colspan=3 height=20>&nbsp</td></tr><tr><td colspan=3 align=center>";
  txt+="<center><table><tr><td colspan="+freight[0][0]+1+" align=center class='cart-font-class'><b>";
  txt+="<center>Non-City Hall Freight Charges</b></center></td></tr>";
  txt+="<tr>";

  txt+="<td align='right' class='cart-font-class'><b>Total incl. Tax</b></td>";

  for (i=1; i<=freight[0][0]; i++){
    (freight[i][0]!="+") ? (tx="$"+np+"-"+freight[i][0]+"") : (tx="$"+np+"+");
    txt+="<td align='center'><font id='cart-font'>"+tx+"</font></td>";
    np=freight[i][0]+1;
  }
  txt+="</tr><tr>";

  txt+="<td align='right' class='cart-font-class'><b>Freight</b></td>";

  for (i=1; i<=freight[0][0]; i++){
    (freight[i][1]!="call") ? (tx=Number(freight[i][1]).toFixed(2)) : (tx="call");
    txt+="<td align='center' class='freight-class'>$"+tx+"</td>";
    np=freight[i][0]+1;
  }
  txt+="</tr></table></center>";
  return txt;
}
function addFreightTbl2(){
  var np=1;
  var tx;
  var txt="<tr><td colspan=3 height=20>&nbsp</td></tr><tr><td colspan=3>";
//  txt+="<center><table><tr><td colspan="+freight[0][0]+1+" align=center class='cart-font-class'><b>";
  txt+="<font class='cart-font-class'><b><u><center>FREE SHIPPING TO ALL CITY SITES</u></b></center><br>";
  txt+="Additionally, we can ship to any private address at current UPS or FedEx rates.<br><br> If you wish to have your purchase ";
  txt+="delivered to a private address, please indicate by clicking on UPS/FedEx on the left of this page. ";
  txt+="You will be contacted by a Vineyard Unlimited representative to make arrangements and to update ";
  txt+="the total price of your purchase to include the cost of shipping.";
  return txt;
}

function mkItemStrs(){                 // last change 4/30/09, 3:45PM
  var tot=0;
  var shp;
  var txt="<table width=330><tr><td colspan=3 align=center class='cart-font-class'>";
  txt+="<font class='h4-class'>Items Selected</font><br><br>";
  txt+="<i>click on an item to view or edit</i></td></tr>";
  txt+="<tr><td align=center valign=top><table><tr><td class='cart-font-class' align=right><b>Item Description";
  txt+="</b></td><td class='cart-font-class' align=center>";
  txt+="<b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
  txt+="Quantity&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b></td>";
  txt+="<td class='cart-font-class' align=center width=40px><b>Price</td></b></tr>";
  for (i=1; i<=cart[0]; i++){
    var x=cart[i];
    tot+=pArray[x][11];
    txt+="<tr><td class='cart-font-class' align=right><a href='JavaScript:null1()' class='cart-font-class' ";
    txt+="onClick='editItem("+x+")'>"+pArray[x][4]+"</font></a></td><td class='cart-font-class' align=center>"+pArray[x][10]+"";
    txt+="</td><td class='cart-font-class' align=right>$"+Number(pArray[x][11]).toFixed(2)+"</td></tr>";
  }
  txt+="<tr><td colspan=3><hr></td></tr><tr><td colspan=2 align=right class='cart-font-class'><b>Item total</b>";
  txt+="</td><td class='cart-font-class' align=right>"+Number(tot).toFixed(2)+"</td></tr>";
  txt+="<tr><td colspan=2 align=right class='cart-font-class'><b>Sales Tax ("+salestax*100+"%)</b></td>";

  var tax=tot*salestax;
  txt+="<td class='cart-font-class' align=right>"+Number(tax).toFixed(2)+"</td></tr>";
  var subt=parseFloat(tot+tax);
  /////////////////////////////////////////// 7-21-09

  txt+="<tr><td colspan=2 align=right class='cart-font-class'><b>Subtotal</b></td>";
  txt+="<td class='cart-font-class' align=right>"+Number(subt).toFixed(2)+"</td></tr>";

  ///////////////////////////////////////////
  var x=0;
  if (shipping==0){
    shp="n/c";
    tot=Number(subt).toFixed(2);
  }
  else {
   for (i=1; i<=freight[0][0] && subt>parseFloat(freight[i][0]); i++);
   shp=freight[i][1];
   if (shp=="call") tot="call";
   else {shp=Number(parseFloat(shp)).toFixed(2); tot=Number(parseFloat(subt+shp)).toFixed(2)};
  }

//  txt+="<tr><td colspan=2 align=right class='cart-font-class'><b>Freight</b></td>";
//  txt+="<td id='fr8' align=right class='cart-font-class'>"+shp+"</td></tr>";
//  txt+="<tr><td colspan=2></td><td><hr></td></tr>";
//  txt+="<tr><td colspan=2 align=right class='cart-font-class'><b>Total</b></td>";
//  txt+="<td id='ttl' align=right class='cart-font-class'>"+tot+"</td></tr>";
  txt+=addFreightTbl2();
  txt+="</table></td></tr></table>";
  return txt;
}
function editItem(n){
  hideObj("cartSp");
  return mkItemForm4a(n);
}

