//Shopping cart Javascript functions

//test to see if cookies are enabled
var cookiesEnabled=true;
if (location.href.indexOf('orderform.htm')==-1 && document.cookie=='')
  {
  var testname='HofMTest',testvalue='nothing';
  if (location.href.indexOf('?1') > -1)
    {
    if (GetCookie(testname)==null) cookiesEnabled=false;
    }
  else
    {
    var testdate=new Date();
    testdate.setDate(1000 * 60 * 30);
    SetCookie(testname, testvalue, testdate);
    location.href += '?1';
    }
  }

function nocookiewarning()
 {
  if (!cookiesEnabled)
   {
    var cstring='<center><table border="1" cellspacing="0" cellpadding="5" bgcolor="#ffffff" width="540"><tr><td>';
    cstring += '<center><span class="arial16 black bold">WARNING</span></center>';
    cstring += '<span class="arial12 black">';
    cstring += 'This site\'s shopping cart utilizes small text files known as cookies and contain a list of items you select.  ';
    cstring += 'They do not store any personal or credit card information.  If you have cookies disabled you will not be able to use ';
    cstring += 'our shopping cart.  Consult your computer documentation on how to enable cookies on your computer.  Instead, you may ';
    cstring += 'call in your order at <b>419-382-MEAT</b>.';
    cstring += '</span></td></tr></table></center><br>';
    document.write(cstring);
   }
 }

function isNumber(onestring)
 {
  var digit='0123456789.';
  if (onestring.length==0) return true;
  for (var oi=0;oi<onestring.length;oi++)
   {
    var onechar=onestring.charAt(oi);
    if (digit.indexOf(onechar)==-1) return false;
   }
  return true;
 }

function checknumber(number)
 {
  if (number.length==0) return false;
  if (!isNumber(number.value))
   {
    alert('Not a valid number: ' + number.value);
    number.focus();
    number.select();
    return false;
   }
  return true;
 }

function isWholeNumber(onestring)
 {
  var digit='0123456789';
  if (onestring.length==0) return true;
  for (var oi=0;oi<onestring.length;oi++)
   {
    var onechar=onestring.charAt(oi);
    if (digit.indexOf(onechar)==-1) return false;
   }
  return true;
 }

function checkWholenumber(number, mtype)
 {
  if (number.length==0) return false;
  if (!isWholeNumber(number.value))
   {
    if (mtype == 'w') alert('Not a valid whole number: ' + number.value);
    else if (mtype == 'z') alert('Not a valid ZIP code: ' + number.value);
    number.focus();
    number.select();
    return false;
   }
  return true;
 }

var state=new Array('','OH','AL','AK','AZ','AR','CA','CO','CT','DE','DC','FL','GA','HI','ID','IL','IN','IA','KS','KY','LA','ME','MD','MA','MI','MN','MS','MO','MT','NE','NV','NH','NJ','NM','NY','NC','ND','OH','OK','OR','PA','RI','SC','SD','TN','TX','UT','VT','VA','WA','WV','WI','WY');
function statedropdown()
 {
  for (var si=0;si<state.length;si++)
   {
    document.write('<option>' + state[si]);
   }
 }

function checkzip()
 {
  var doc=document.form1;
//alert('|'+doc.shipmentweight.value+'|');
  if (doc.receiverpostalcode.value.length==0)
   {
    alert('You must enter a zip code to get the shipping charge.');
    document.form1.receiverpostalcode.focus();
    return false;
   }
  else
   {
    doc.action='Fedexestimator.asp';
    return true;
   }
  return false;
 }

function clearForms()
 {for (var i=0; (i<document.forms.length); i++) document.forms[i].reset();}

function addtocart(ID, desc, price, Weight, WeightUnit, minimumqty, pricemultiplier)
 {
//if (pricemultiplier > 1) alert(pricemultiplier);
  var qty = eval("document.orderform.qty"+ID+".value") * 1;
  if (qty==0)
   {
    alert('You must specify a quantity');
    return;
   }
  if (qty < minimumqty)
   {
    alert('You must specify a minimum amount of ' + minimumqty + ' for this item');
    return;
   }
//alert('ID='+ID+'|desc='+desc+'|price='+price+'|qty='+qty+'unit Weight='+Weight+'|WeightUnit='+WeightUnit);
  AddItem(ID, desc, price, qty, Weight,WeightUnit, pricemultiplier);
  clearForms();
 }

var opwin;
function openwindow(link)
 {
  if (opwin != null) {if (!opwin.closed) opwin.close();}
  opwin=window.open(link,'opwin','scrollbars=yes,toolbar=yes,resizable=yes,location= yes,status=yes,height=550,width=750');
  opwin.focus();
 }

var MaxCartItems = 30;
var ReferrerLife = 1000 * 60 * 60 * 24 * 5;
var pageloc = self.location;
var storeID='houseofmeats';

//using ASCII values 182, 183, 184, 185, 186, 187 as separators
var sp1="¶";
var sp2="·";
var sp3="¸";
var sp4="¹";
var sp5="º";
var sp6="»";

function SaveReferrer()
  {
  CookieName = storeID;
  CookieValue = GetCookie(CookieName);
  if(CookieValue == null){CookieValue = document.referrer;}
  var expdate = new Date();
  expdate.setDate(ReferrerLife);
  SetCookie(CookieName,CookieValue,expdate);
  }

function getCookieVal (offset)
  {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1) endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
  }

function GetCookie (name)
  {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen)
    {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg) return getCookieVal(j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break;
    }
  return null;
  }

function SetCookie (name, value, expdate)
  {
  var argv = SetCookie.arguments;
  var argc = SetCookie.arguments.length;
  var expires = expdate;
  var path = "/";
  var domain = null;
  var secure = false;

  document.cookie = name + "=" + escape (value) +
    ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
    ((path == null) ? "" : ("; path=" + path)) +
    ((domain == null) ? "" : ("; domain=" + domain)) +
    ((secure == true) ? "; secure" : "");
  }

function DeleteCookie(name)
  {
  var exp = new Date();
  exp.setTime (exp.getTime() - 1);  // This cookie is history
  var cval = GetCookie (name);
  if (cval != null){document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString() + ";path=/";}
  }

function AddItem(ID,Sdesc,Price,Qty,Weight,WeightUnit,Spship)
{
if (Qty <= 0)
  {
  var rc = alert('The Quantity must be greater than 0');
  return false;
  }

//confirmation for adding to shopping cart removed 03/22/00, re-added 03/27/00

var iunit = WeightUnit;
if ((Qty > 1) && (iunit == 'lb')) iunit += 's';
if (confirm('Please confirm the addition of\n'+Qty+' '+iunit+' of "'+Sdesc+'" '+'to the shopping cart.'))
  {
  for(var NumItems = 0; NumItems<=MaxCartItems; NumItems++)
    {
    if(NumItems == MaxCartItems)
      {
      alert('Maximum of '+MaxCartItems+' different items can fit in the shopping cart, please go to the Checkout Page and submit your order.  Then empty your cart and shop some more later.');
      }
    else
      {
      var CookieName = storeID + NumItems;
      var CookieValue = GetCookie(CookieName);
      if(CookieValue == null)
        {
        CookieValue = "["+ID+sp1+Sdesc+sp2+Price+sp3+Qty+sp4+Weight+sp5+WeightUnit+sp6+Spship+"]";
        SetCookie(CookieName,CookieValue);
        break;
        }
      }
    }
  }
return true;
}

function FloatFormat(expr,decplaces)
  {
  var str = "" + Math.round(eval(expr) * Math.pow(10,decplaces));
  while(str.length <= decplaces){str = "0" + str;}
  var decpoint = str.length - decplaces;
  return str.substring(0,decpoint) + "." + str.substring(decpoint,str.length);
  }

function showweight (weight)
 {
  var uwt = '';
  var uwtlb = Math.floor(weight / 16);
  if (uwtlb > 0) uwt = uwtlb + 'lb ';
  var uwtoz = Math.round(weight % 16);
  if (uwtoz > 0) uwt += uwtoz + 'oz';
  return uwt;
//Response.Write('<span class="arial9">unit wt. '+uwt+'</span><br>');
 }

function ShowCart()
  {
  totprice = 0;
  itemlist = 0;
  TotWeight = 0;
  flatrate = true;
  document.writeln('<!form name="cart">');
  document.writeln('<font size=2 face=arial color="#dd5555">To change quantity, edit number then click anywhere on this page</font>');
  document.writeln('<table border=1 cellspacing=0 cellpadding=4 bgcolor="#ffffff">');
  document.writeln('<tr><td align=center><b>ID</b></td><td align=center width=300><b>Description</b></td><td align=center><b>Qty</b></td><td align=center><b>Unit Price</b></td><td align=center><b>Item Total</b></td><td align=center><b>Action</b></td></tr>');
  for(NumItems = 0; NumItems<MaxCartItems; NumItems++)
    {
    CookieName = storeID +NumItems;
    CookieValue = GetCookie(CookieName);
    if(CookieValue != null)
      {
      for(var i=0;i<=CookieValue.length;i++)
        {
        if (CookieValue.substring(i,i+1) == '[') {itemstart = i+1;}
        else if (CookieValue.substring(i,i+1) == sp1)
          {
          ID = CookieValue.substring(itemstart, i);
          itemstart = i+1;
          }
        else if (CookieValue.substring(i,i+1) == sp2)
          {
          Sdesc = CookieValue.substring(itemstart, i);
          itemstart = i+1;
          }
        else if (CookieValue.substring(i,i+1) == sp3)
          {
          Price = CookieValue.substring(itemstart, i);
          itemstart = i+1;
          }
        else if (CookieValue.substring(i,i+1) == sp4)
          {
//          itemend = i;
//          Qty = CookieValue.substring(itemstart, itemend);
          Qty = CookieValue.substring(itemstart, i);
          itemstart = i+1;
          }
        else if (CookieValue.substring(i,i+1) == sp5)
          {
         itemend = i;
          Weight = CookieValue.substring(itemstart, itemend);
//          Weight = CookieValue.substring(itemstart, i);
          itemstart = i+1;
          }
        else if (CookieValue.substring(i,i+1) == sp6)
          {
          WeightUnit = CookieValue.substring(itemstart, i);
          itemstart = i+1;
          }
        else if (CookieValue.substring(i,i+1) == ']')
          {
          Spship = CookieValue.substring(itemstart, i);
//Spship is used for the price availability
          itemstart = i+1;
          var shipflag = true;
          if (Spship.charAt(13) == 'O') shipflag = false;
          var andpickup = true;
          if ((Spship.charAt(7) == 'O') || (Spship.charAt(8) == 'O') || (Spship.charAt(9) == 'O') || (Spship.charAt(10) == 'O') || (Spship.charAt(11) == 'O') || (Spship.charAt(12) == 'O')) andpickup = false;
          ItemTotal = 0;

          if ((shipflag) || (ometh != 'Shipped'))
           {
            ItemTotal = (eval(Price*Qty));
            TotWeight += Weight * Qty;
           }
          else Sdesc += '<br><span class="arial10 black">This item is not available for shipping</span>';
          if ((!andpickup) && (ometh == 'Store Pickup')) Sdesc += '<br><span class="arial10 black">This item is not available for pickup at The Andersons units</span>';
          totprice = totprice + ItemTotal;
          itemlist=itemlist+1;
          FItemTotal = FloatFormat(ItemTotal,2);
          document.writeln('<tr><td><font size=2 face=arial>'+ID+'</font></td><td><font size=2 face=arial>'+Sdesc+'</font></td><td align=right><input method=post name=Qty'+NumItems+' type=text size=3 onChange=QtyChange('+NumItems+',Qty'+NumItems+'.value) value='+Qty+'></td><td align=right><font size=2 face=arial>$ '+Price+' '+WeightUnit+'</font></td><td align=right><font size=2 face=arial>');

          if ((shipflag) || (ometh != 'Shipped')) document.writeln(FItemTotal);
          else document.writeln('---');
          document.writeln('</font></td><td><a href="javascript:RemoveItem('+NumItems+')"><font size=2 face=arial>Remove</font></a></td></tr>');
//if Jerky or Landjaegers only, then flat rate shipping
          var idesc = Sdesc.toLowerCase();
          if ((idesc.indexOf('jerky') == -1) && (idesc.indexOf('landjaegers') == -1)) flatrate = false;
          }
        }
      }
    }
  if (itemlist == 0) document.writeln('<tr><td colspan="6" align="center" class="red bold">There are no items in your shopping cart.</td></tr>');
  else
   {
    Ftotprice = FloatFormat(totprice,2);
if (ometh != 'Store Pickup')
    document.writeln('<tr><td colspan=4><b>Sub Total</b></td><td align=right>'+Ftotprice+'</td><td rowspan=4><img src="images/butcher-hofmsm.gif" alt="You Old Fashion Service Butcher Shop"></td></tr>');

    Shipping=parseFloat(fedsh);
    GrandTotal=0;
    var proccharge = 0;

//alert(ometh);
//if (ometh == 'Delivered') alert(ometh+' here');
// }
if (ometh == 'Shipped')
 {
    if (!flatrate)
     {
      proccharge = 8.95;
      document.writeln('<tr><td colspan=4><b>Processing Charge</b></td><td align=right>' + proccharge + '</td></tr>');
        document.writeln('<tr><td colspan=4>');
          document.writeln('<table border=0 width=100% cellspacing=0 cellpadding=0><tr>');
            document.writeln('<td><b>Shipping</b><span class="arial10"><br>via FEDEX Ground</span></td>');
            document.writeln('<td align=right class="arial12 black">');
                document.writeln('<form name="form1" method="post" onsubmit="return checkzip();">');
              document.writeln('<input type=hidden name="shipmentweight" value="'+(TotWeight*0.0625)+'">');
              document.writeln('Enter Zip Code to Calculate Shipping: ');
              document.writeln('<input type="text" name="receiverpostalcode" id="receiverpostalcode" size="8" maxlength="10" value="'+rzip+'" onblur="checkWholenumber(this,\'z\'); return true;">');
              document.writeln('<input type="submit" name="Submit" value="Go">');
//              document.writeln('<br><span class="arial11 black">Shipping Weight: ');
//              document.writeln(showweight(TotWeight)+'</span>');
///if (TotWeight != fedshwt) alert('TotWeight='+TotWeight+' | fedshwt='+fedshwt);
                if (TotWeight != fedshwt) Shipping = 0;
            document.writeln('</td>');
          document.writeln('</tr></table>');
        document.writeln('</td><td align=right>');
          if (Shipping != 0) document.writeln(FloatFormat(Shipping,2));
          else
           {
            if (rzip != '') document.write('<input type="submit" name="Submit" value="Recalulate">');
//            if (rzip != '') document.write('<input type="image" name="submit" src="images/butcher-hofmsm.gif" border="0">');
            else document.writeln('<span class="arial12 black"><--Enter Zip</span>');
           }
        document.writeln('</td></tr>');
                document.writeln('</form>');
     }
    else
     {
      Shipping = 9.95;
      document.writeln('<tr><td colspan=4><table border=0 width=100% cellspacing=0 cellpadding=0><tr><td><b>Flat Rate Shipping Charge<br>via Priority Mail</b></td><td align=right class="arial11 black"> &nbsp;</td></tr></table></td><td align=right>'+FloatFormat(Shipping,2)+'</td></tr>');
//      document.writeln('<tr><td colspan=4><table border=0 width=100% cellspacing=0 cellpadding=0><tr><td><b>Flat Rate Shipping Charge<br>via Priority Mail</b></td><td align=right class="arial11 black">Shipping Weight: '+showweight(TotWeight)+'</td></tr></table></td><td align=right>'+FloatFormat(Shipping,2)+'</td></tr>');
     }
    GrandTotal=FloatFormat(totprice + proccharge + Shipping,2);
 }
else if (ometh == 'Delivered')
 {
  deliverycharge = 15.00;
  document.writeln('<tr><td colspan=4><b>Delivery Charge</b></td><td align=right>' + FloatFormat(deliverycharge,2) + '</td></tr>');
  GrandTotal=FloatFormat(totprice + deliverycharge,2);
 }
else
 {
  GrandTotal=FloatFormat(totprice,2);
 }
    document.writeln('<tr><td colspan=4><b><font color=red>TOTAL</font></b>');
    if ((ometh == 'Shipped') && (Shipping == 0)) document.writeln(' (without shipping)');
    document.writeln('</td><td align=right><font color=red><b>$ '+GrandTotal+'</b></font></td>');
    if (ometh == 'Store Pickup') document.writeln('<td> &nbsp;</td>');
    document.writeln('</tr>');
   }
  document.writeln('</table>');
  document.writeln('</form>');
  }

function checkprice(itemID, itemQty)
{
var pindex=getindex(itemID);
var prices=pitem[pindex].price.split('|');
var pricebreakpt=pitem[pindex].pricebreakpt.split('|');

if (pricebreakpt.length == 1) return prices[0];
if (itemQty<pricebreakpt[1]*1) return prices[0];
else if (itemQty >= pricebreakpt[1]*1) return prices[1];
else return prices[1];
}

function checkshipping(itemID, itemQty)
{
var pindex=getindex(itemID);
var ishipping=pitem[pindex].shipping.split('|');
var pricebreakpt=pitem[pindex].pricebreakpt.split('|');

if (pricebreakpt.length == 1) return ishipping[0];
if (itemQty<pricebreakpt[1]*1) return ishipping[0];
else if (itemQty >= pricebreakpt[1]*1) return ishipping[1];
else return ishipping[1];
}

function checkQty(itemID, itemQty)
{
var pindex=getindex(itemID);
var pricebreakpt=pitem[pindex].pricebreakpt.split('|');

if (itemQty<pricebreakpt[0]*1)
 {
  itemQty = pricebreakpt[0]*1;
  alert('You must specify a minimum quantity of ' + pricebreakpt[0] + ' for this item');
 }
return itemQty;
}

function QtyChange(itemnum,Qty)
  {
//alert('itemnum='+itemnum+'| Qty='+Qty+'| storeID='+storeID);
  CookieName = storeID +itemnum;
  CookieValue = GetCookie(CookieName);
  for(var i=0;i<=CookieValue.length;i++)
    {
    if (CookieValue.substring(i,i+1) == '['){itemstart = i+1;}
    else if (CookieValue.substring(i,i+1) == sp1)
      {
      ID = CookieValue.substring(itemstart, i);
      itemstart = i+1;
      }
    else if (CookieValue.substring(i,i+1) == sp2)
      {
      Sdesc = CookieValue.substring(itemstart, i);
      itemstart = i+1;
      }
    else if (CookieValue.substring(i,i+1) == sp3)
      {
      Price = CookieValue.substring(itemstart, i);
      itemstart = i+1;
      }
//CookieValue = "["+ID+sp1+Sdesc+sp2+Price+sp3+Qty+sp4+Weight+sp5+WeightUnit+sp6+Spship+"]";
    else if (CookieValue.substring(i,i+1) == sp4)
      {
      OldQty = CookieValue.substring(itemstart, itemend);
      itemstart = i+1;
      }
    else if (CookieValue.substring(i,i+1) == sp5)
      {
      Weight = CookieValue.substring(itemstart, i);
      itemstart = i+1;
      }
    else if (CookieValue.substring(i,i+1) == sp6)
      {
      WeightUnit = CookieValue.substring(itemstart, i);
      itemstart = i+1;
      }
    else if (CookieValue.substring(i,i+1) == ']')
      {
      Spship = CookieValue.substring(itemstart, i);
      itemstart = i+1;
      }
    }

//alert('OldQty='+OldQty+'| Qty='+Qty);
  NewCookieValue = "["+ID+sp1+Sdesc+sp2+Price+sp3+Qty+sp4+Weight+sp5+WeightUnit+sp6+Spship+"]";
  if(Qty <= 0){DeleteCookie(CookieName);}
  else{SetCookie(CookieName,NewCookieValue);}
  self.location = pageloc;
  }

function RemoveItem(itemnum)
  {
  CookieName = storeID +itemnum;
  DeleteCookie(CookieName);
  self.location = pageloc;
  }

function EmptyCart()
  {
  if(confirm('Are you sure you want to empty the shopping cart?'))
    {
    for(NumItems = 0; NumItems<MaxCartItems; NumItems++)
      {
      CookieName = storeID +NumItems;
      DeleteCookie(CookieName);
      }
    self.location = pageloc;
    }
  }

function Dollarize(expr)
  {
  return "$" + format(expr,2);
  }


var rsize = 10;		// rounding size
var oz_factor = 1;		// ounces to ounces
var lbs_factor = 0.0625;		// ounces to pounds
var mg_factor = 28349.5;		// ounces to miligrams
var g_factor = 28.3495;		// ounces to grams
var kg_factor = .0283495;	// ounces to kilograms
var UnitSize;	// weight number being converted
var OldUnit;	// converting from
var NewUnit;	// converting to
var NewUnitSize;	// new weight in new unit

function ConvertUnit(UnitSize,OldUnit,NewUnit)
{
// possible units
// oz
// lbs
// mg
// g
// kg

// if not oz, convert to oz first

NewUnitSize = 0;
TmpUnitSize = 0;

if(OldUnit != 'oz')
  {
  if(OldUnit == 'lbs'){TmpUnitSize = UnitSize / lbs_factor;}
  else if(OldUnit == 'mg'){TmpUnitSize = UnitSize / mg_factor;}
  else if(OldUnit == 'g'){TmpUnitSize = UnitSize / g_factor;}
  else if(OldUnit == 'kg'){TmpUnitSize = UnitSize / kg_factor;}
  }
else
  {
  // if oz, keep as is
  TmpUnitSize = UnitSize;
  }

// since TmpUnitSize is now oz, convert to NewUnit;
if(NewUnit == 'oz'){NewUnitSize = TmpUnitSize;}
else if(NewUnit == 'lbs'){NewUnitSize = TmpUnitSize * lbs_factor;}
else if(NewUnit == 'mg'){NewUnitSize = TmpUnitSize * mg_factor;}
else if(NewUnit == 'g'){NewUnitSize = TmpUnitSize * g_factor;}
else if(NewUnit == 'kg'){NewUnitSize = TmpUnitSize * kg_factor;}
}

function ShowInvoice()
{
//alert(ometh);
totprice = 0;
itemlist = 0;
TotQty = 0;
TotWeight = 0;
FinalTotWeight = 0;
TotalShipping = 0;
icount = 0;
  flatrate = true;

document.writeln('<table border=1 cellspacing=0 cellpadding=4 bgcolor="#ffffff">');
document.writeln('<tr><td align=center><b>ID</b></td><td align=center width=300><b>Description</b></td><td align=center><b>Qty</b></td><td align=center><b>Unit Price</b></td><td align=center><b>Item Total</b></td><td align=center><b>Comments</b></td></tr>');

for(NumItems = 0; NumItems<MaxCartItems; NumItems++)
  {
  CookieName = storeID +NumItems;
  CookieValue = GetCookie(CookieName);

  if(CookieValue != null)
    {
    for(var i = 0;i <= CookieValue.length; i++)
      {
      if (CookieValue.substring(i,i+1) == '['){itemstart = i+1;}
      else if (CookieValue.substring(i,i+1) == sp1)
        {
        ID = CookieValue.substring(itemstart, i);
        itemstart = i+1;
        }
      else if (CookieValue.substring(i,i+1) == sp2)
        {
        Sdesc = CookieValue.substring(itemstart, i);
        itemstart = i+1;
        }
      else if (CookieValue.substring(i,i+1) == sp3)
        {
        Price = CookieValue.substring(itemstart, i);
        itemstart = i+1;
        }
      else if (CookieValue.substring(i,i+1) == sp4)
        {
        Qty = CookieValue.substring(itemstart, i);
        itemstart=i+1;
        }
      else if (CookieValue.substring(i,i+1) == sp5)
        {
        Weight = CookieValue.substring(itemstart, i);
        itemstart = i+1;
        }
      else if (CookieValue.substring(i,i+1) == sp6)
        {
        WeightUnit = CookieValue.substring(itemstart, i);
        itemstart = i+1;
        }
      else if (CookieValue.substring(i,i+1) == ']')
        {
        Spship = CookieValue.substring(itemstart, i);
        itemstart = i+1;
        var shipflag = true;
        if (Spship.charAt(13) == 'O') shipflag = false;
        var andpickup = true;
        if ((Spship.charAt(7) == 'O') || (Spship.charAt(8) == 'O') || (Spship.charAt(9) == 'O') || (Spship.charAt(10) == 'O') || (Spship.charAt(11) == 'O') || (Spship.charAt(12) == 'O')) andpickup = false;
        TotQty = TotQty + parseInt(Qty);
        TotalShipping += Spship * Qty;

        SdescT = Sdesc;
        ItemTotal = 0;
        if ((shipflag) || (ometh != 'Shipped'))
         {
          ItemTotal = (eval(Price*Qty));
          TotWeight += Weight * Qty;
         }
        else SdescT += '<br><span class="arial10">This item is not available for shipping</span>';
        if ((!andpickup) && (ometh == 'Store Pickup'))
         {
          SdescT += '<br><span class="arial10 black">This item is not available for pickup at The Andersons units</span>';
          Sdesc += ' [Not available for pickup at The Andersons]';
         }
        totprice = totprice + ItemTotal;

        FItemTotal = FloatFormat(ItemTotal,2);

//if Jerky or Landjaegers only, then flat rate shipping
          var idesc = Sdesc.toLowerCase();
          if ((idesc.indexOf('jerky') == -1) && (idesc.indexOf('landjaegers') == -1)) flatrate = false;

if ((shipflag) || (ometh != 'Shipped'))
 {
        icount = icount + 1;
        document.writeln('<input type=hidden name="ID'+icount+'" value="'+ID+'">');
        document.writeln('<input type=hidden name="Description'+icount+'" value="'+Sdesc+'">');
        document.writeln('<input type=hidden name="Qty'+icount+'" value="'+Qty+'">');
        document.writeln('<input type=hidden name="UnitPrice'+icount+'" value="'+Price+'">');
        document.writeln('<input type=hidden name="Weight'+icount+'" value="'+Weight+'">');
        document.writeln('<input type=hidden name="WeightUnit'+icount+'" value="'+WeightUnit+'">');
        document.writeln('<input type=hidden name="TotalPrice'+icount+'" value="'+FItemTotal+'">');
 }
        document.writeln('<tr><td><font size=2 face=arial>'+ID+'</font></td><td><font size=2 face=arial>'+SdescT+'</font></td><td align=right><font size=2 face=arial>'+Qty+'</font></td><td align=right><font size=2 face=arial>$ '+Price+' '+WeightUnit+'</font></td><td align=right><font size=2 face=arial>');
        if ((shipflag) || (ometh != 'Shipped')) document.writeln(FItemTotal);
        else document.writeln('---');
        document.writeln('</font></td><td><input type=text name="Comments'+icount+'" size=10></td></tr>');
        }
      }
    }
  }

    Shipping=parseFloat(fedsh);
//if no items are put in shopping cart, go to the viewcart page
if (TotQty==0)
  {
  alert('There are no items in your shopping cart.\nPlease go to a product page and select the desired item(s) before trying to check out.');
  location.replace('http://www.solarstop.net/houseofmeats/viewcart.asp');
  }
if ((!flatrate) && (Shipping == 0) && (ometh == 'Shipped'))
  {
  alert('You must specify a shipping zip code to checkout.\nPlease return to the View Cart page and add a zip code.');
  location.replace('http://www.solarstop.net/houseofmeats/viewcart.asp');
  }

Ftotprice = FloatFormat(totprice,2);
if (ometh != 'Store Pickup')
 {
  document.writeln('<tr><td colspan=4><b>Sub Total</b></td><td align=right>' + Ftotprice + '</td><td rowspan=4 align=center><img src="images/butcher-hofmsm.gif" alt="You Old Fashion Service Butcher Shop"></td></tr>');
  document.writeln('<input type=hidden name="SubTotal" value="' + Ftotprice +  '">');
 }

//alert(ometh);
if (ometh == 'Shipped')
 {
    var proccharge = 0;
    if (!flatrate)
     {
      proccharge = 8.95;
      document.writeln('<tr><td colspan=4><b>Processing Charge</b></td><td align=right>' + proccharge + '</td></tr>');
      document.writeln('<tr><td colspan=4><table border=0 width=100% cellspacing=0 cellpadding=0><tr><td><b>Shipping</b><span class="arial10"> via FEDEX Ground</span></td><td align=right class="arial11 black">Shipping Weight: '+showweight(TotWeight)+'</td></tr></table></td><td align=right>'+FloatFormat(Shipping,2)+'</td></tr>');
     }
    else
     {
      Shipping = 9.95;
      document.writeln('<tr><td colspan=4><table border=0 width=100% cellspacing=0 cellpadding=0><tr><td><b>Flat Rate Shipping Charge<br>via Priority Mail</b></td><td align=right class="arial11 black">Shipping Weight: '+showweight(TotWeight)+'</td></tr></table></td><td align=right>'+FloatFormat(Shipping,2)+'</td></tr>');
     }
//document.writeln('<tr><td colspan=4><table border=0 cellspacing=0 cellpadding=0 width=100%><tr><td><b>Shipping</b></td><td align=right class="arial11 black">Shipping Weight: '+showweight(TotWeight)+'</td></tr></table></td><td align=right>'+FloatFormat(Shipping,2)+'</td></tr>');
var NTotWeight = showweight(TotWeight);
document.writeln('<input type=hidden name="ProcessingCharge" value="' + proccharge + '">');
document.writeln('<input type=hidden name="ShippingWeight" value="' + NTotWeight + '">');
document.writeln('<input type=hidden name="Shipping" value="' + FloatFormat(Shipping,2) + '">');
GrandTotal=FloatFormat(totprice + proccharge + Shipping,2);
document.writeln('<tr><td colspan=4><b><font color=red>Total</font></b></td><td align=right><font color=red><b>$ '+GrandTotal+'</b></font></td></tr>');
 }
else if (ometh == 'Delivered')
 {
  deliverycharge = 15.00;
  document.writeln('<input type=hidden name="deliverycharge" value="' + FloatFormat(deliverycharge,2) + '">');
  document.writeln('<tr><td colspan=4><b>Delivery Charge</b></td><td align=right>' + FloatFormat(deliverycharge,2) + '</td></tr>');
  GrandTotal=FloatFormat(totprice + deliverycharge,2);
document.writeln('<tr><td colspan=4><b><font color=red>Total</font></b></td><td align=right><font color=red><b>$ '+GrandTotal+'</b></font></td></tr>');
 }
else
 {
  GrandTotal=FloatFormat(totprice,2);
  document.writeln('<tr><td colspan=4><b><font color=red>Total</font></b></td><td align=right><font color=red><b>$ '+GrandTotal+'</b></font></td><td> &nbsp;</td></tr>');
 }

document.writeln('<input type=hidden name="Total" value="$ '+GrandTotal+'">');
document.writeln('</table>');
}

//this function switches domains to Solarstop domain for secure server transactions

var newURL="HTTP://www.solarstop.net/";
var secURL="HTTPs://www.solarstop.net/secure";

function setURL(checkURL)
{
var thisURL= top.location.href;

thisURL=thisURL.toLowerCase();
newURL=newURL.toLowerCase();
secURL=secURL.toLowerCase();

var length=newURL.length;
var testURL=thisURL.substring(0,length);

if(newURL==testURL){return;}

var length=secURL.length;
var testURL=thisURL.substring(0,length);

if(secURL==testURL){return;}

var dot = thisURL.indexOf(".",1);
var slash = thisURL.indexOf("/",dot);
var onepage = thisURL.substring(slash);

newURL= newURL + checkURL + onepage;
top.location.replace(newURL);
}

setURL("houseofmeats");


