//--------------------------------------
// PPP -  javascript - globals & cookies
//
//  Except were noted below, all code written by:
//  Philip P. Parshley - Copyright 2001-2009 <parshley@hevanet.com> All rights reserved.


//--------------------------------------
//******************************************************************
//******************************************************************
//******************************************************************
//  Cookie Functions -- "Night of the Living Cookie" Version (25-Jul-96)
//
//  Written by:  Bill Dortch, hIdaho Design <bdortch@hidaho.com>
//******************************************************************
//
// "Internal" function to return the decoded value of a cookie
//
function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}
//
//  Function to correct for 2.x Mac date bug.  Call this function to
//  fix a date object prior to passing it to SetCookie.
//  IMPORTANT:  This function should only be called *once* for
//  any given date object!  See example at the end of this document.
//
function FixCookieDate (date) {
  var base = new Date(0);
  var skew = base.getTime(); // dawn of (Unix) time - should be 0
  if (skew > 0)  // Except on the Mac - ahead of its time
    date.setTime (date.getTime() - skew);
}
//
//  Function to return the value of the cookie specified by "name".
//    name - String object containing the cookie name.
//    returns - String object containing the cookie value, or null if
//      the cookie does not exist.
//
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 to create or update a cookie.
//
function SetCookie (name,value,expires,path,domain,secure) {
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

//  Function to delete a cookie. (Sets expiration date to start of epoch)
//
function DeleteCookie (name,path,domain) {
  if (GetCookie(name)) {
    document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}


//
//--------------------------------------
//--------------------------------------
//--------------------------------------
//--------------------------------------
//--------------------------------------
// PPP -  javascript - globals & cookies


//-- ======= be sure its loaded w/in the main frame =========== --
function setfhsteinbart() {
   //if (parent.document.title!="F.H. Steinbart Company - Ordering Our Products") {
   //   window.location="http://www.fhsteinbart.com/products/index.html"; 
   //}
}


function resetHdr() {
   top.prodbox.document.open("text/html","replace");
   top.prodbox.document.writeln("<html>");
   top.prodbox.document.writeln("<head>");
   top.prodbox.document.writeln('  <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">');
   top.prodbox.document.writeln('  <meta http-equiv="Content-Script-Type" content="javascript">');
   top.prodbox.document.writeln('  <meta name="ROBOTS" content="INDEX, FOLLOW">');
   top.prodbox.document.writeln('  <TITLE>F.H. Steinbart Company-Shopping Cart</TITLE>');
   top.prodbox.document.writeln('  <LINK REL=STYLESHEET TYPE="text/css" HREF="../stylesheet.css">');

   top.prodbox.document.writeln('  <script type="text/javascript" src="steinjs7.js">');
   top.prodbox.document.writeln('  </script>');

   top.prodbox.document.writeln('</head>');

   top.prodbox.document.writeln('<BODY TEXT="#000000" BGCOLOR="#FFFFFF"LINK="#770f05" VLINK="#770f05" ALINK="#000000">');
   top.prodbox.document.writeln('<A NAME="TopOfPage"></A>');
   top.prodbox.document.writeln('<DIV align="center">');
   top.prodbox.document.writeln('<table WIDTH="95%" BORDER=0 CELLSPACING=0 CELLPADDING= 0 ALIGN=CENTER>');
   top.prodbox.document.writeln(' <tr>');
   top.prodbox.document.writeln('  <td width="25%" align="left" valign="top">');
   top.prodbox.document.writeln('   &nbsp;');
   top.prodbox.document.writeln('  </td>');
   top.prodbox.document.writeln('  <td width="50%" align="center" valign="bottom">');
   top.prodbox.document.writeln('     <span class="BLD16">Your Shopping Cart</span>');
   top.prodbox.document.writeln('  </td>');
   top.prodbox.document.writeln('  <td width="25%" align="left">&nbsp;</td>');
   top.prodbox.document.writeln(' </tr>');
   top.prodbox.document.writeln('</table>');
   top.prodbox.document.writeln('<p>');
}


function shpDisplay() {
   ////UPS integration:
   var delFlag=0;
   numOfLines=0;
   var txtLines = new Array(); 
   cartHdr(top.itemCnt+1, txtLines);
   showAllItems(txtLines,delFlag);
   cartFtr(txtLines);
   writeCart(txtLines);
   setFields();
   top.orderstat=1;  

   var elementLen=top.prodbox.document.cartForm.elements.length;
   if (top.ppQtyOn) {
      //alert("shpDisplay():ppQtyOn...");
      //--- returning from PP? revert qty back to pre-PP, by reading back from on1_X pp variable; turn off.
      for (var j = top.itemCnt-1; j>=0; j--) {
         if (top.cartItems[j][2]<0) {
            //---gen form.field name
            updfld="on1_"+(top.itemCnt-j).toString();
            for (var k=0; k < elementLen; k++) {  //---look for this hidden field
               if (top.prodbox.document.cartForm.elements[k].name==updfld) {
                  //---read field value, parse fractional qty    
                  oldvalue=top.cartItems[j][4];
                  //alert(updfld+" value="+top.prodbox.document.cartForm.elements[k].value+"...");
                  ndxcue=(top.prodbox.document.cartForm.elements[k].value).indexOf(" ");
                  top.cartItems[j][4]=formatNum(top.prodbox.document.cartForm.elements[k].value.substring(0,ndxcue),3);
                  //alert("shpDisplay():ppQtyOn:cartitems[j][4] was "+oldvalue+" now="+top.cartItems[j][4]+"...");
               } //-- found it: reset fractional qty 
            } //-- loop thru forms.fields
         } //-- chk this ppqty-flagged item
      } //-- cycle thru all cartItems array elements
      top.ppQtyOn=false;
      //alert("shpDisplay: ppQtyOn="+top.ppQtyOn);
   } //-- chk for pp
} //-- end of shpDisplay()



function buyNow() {
   top.prodbox.document.cartForm.buyBtn.value="TRANSFERRING - Please wait...";
   //if prepPPwgts();
   //   top.ppQtyOn=true;
   //}
   prepPPwgts();
   top.prodbox.document.cartForm.buyBtn.click();
}


function confirmBuy() {
   //alert(top.buyCue);
   if (top.buyCue<1) {
      if (confirm("Submit your Order to F.H. Steinbart Company?")) {
         top.prodbox.location='http://www.fhsteinbart.com/products/confirmTerms.htm';
      } else {
        return false;
      }
   } else {
      top.buyCue=0;
      return true;
   }
}


//Total=sum of all special fees
function calcSpcFees() {
   var MnumOfItemInCart=top.itemCnt;
   var Mspcfee="";
   var Mtotal=0.00;
   var MspcStr="0.00";

   for (var i = 0; i < MnumOfItemInCart; i++) {
     //sum totprice
     Mspcfee= top.cartItems[i][2];
     Mspcfee= parseFloat(Mspcfee);
     //--- chk for lbs-oz qty flag (negative), chk for == -100 (-100=no real special fee, other negative #s set to abs())
     if ((Mspcfee>0) || (Mspcfee<0 && Math.abs(Mspcfee)!=100)) { 
        Mtotal=Mtotal+Math.abs(Mspcfee);
     } //---only total if this is non-negative or != -100 (using negative values to trigger $/lb PayPal custom qty handling field: -100=no special fee otherwise)
   }
   if (Mtotal>0.00) {
      MspcStr=formatNum(Mtotal,2);
      //alert("spcStr="+MspcStr+"...");
   } else {
      MspcStr="0.00";
   }
   //alert("returning MspcStr="+MspcStr+"...");
   return MspcStr;
}


function clearShip(cart) {  
   //---clear shipping fields, set to unselected
   //---and clear any promo entry, if ord-total under threshold
   top.shipChg=0.00;
   top.upsChg=-1.00;
   var ordtot=top.calcTotal();
   var clearPromo=false;

   if (cart) { //y/n: clear cart display
     var elementLen=top.prodbox.document.cartForm.elements.length;
     for (var i=0; i < elementLen; i++) {  //---1st reset to zero
        if (top.prodbox.document.cartForm.elements[i].name=="t_"+(top.itemCnt+1).toString()) {
          top.prodbox.document.cartForm.elements[i].value=formatNum(0,2);
        }
        if (top.prodbox.document.cartForm.elements[i].name=="amount_"+(top.itemCnt+1).toString()) {
          top.prodbox.document.cartForm.elements[i].value=formatNum(0,2);
        }
        if (top.prodbox.document.cartForm.elements[i].name=="ordertotal") {
          top.prodbox.document.cartForm.elements[i].value=formatNum(parseFloat(calcTotal()),2);
        }

        //--- chk for promo code discount, remove if order $ below threshold
        if (top.prodbox.document.cartForm.elements[i].name=="discount_amount_cart") {
           if (parseFloat(ordtot)+parseFloat(top.prodbox.document.cartForm.elements[i].value)<top.promoThrsh) {
              //--- order total $ now below promo threshold, remove it
              top.promoCode=' ';
              top.promoDesc=' ';
              top.promoChg=0.00;
              top.promoThrsh=0.00;
              clearPromo=true;
           }
        }
     }
   }
}

function getExlWgts() {
   var urlparms="";
   var prtno="";
   // --- build URL string ---
   for (var j = top.itemCnt-1; j>=0; j--) {
       prtno=repartnum(top.cartItems[j][0]);
       urlparms+="p="+txtTrim(prtno)+"&q="+top.cartItems[j][4]+"&";
   }
   //top.prodbox.location="http://www.fhsteinbart.com/getExclWgt/get_exclwgt?"+urlparms;
   top.prodbox.location="http://www.fhsteinbart.com/getUPSshpChg/getExclWgt?"+urlparms;
   //alert(urlparms);
   //alert("Your order contains "+(top.excWgt).toString()+"lbs that are excluded from free shipping promotions...");
   alert("Some items may be excluded from free shipping promotions...");
   return;
}


function getUPSchgs() {
   ////UPS integration:
  if (top.prodbox.document.cartForm.address1.value<2) {
     alert("'address 1' is a required field...");
     return false;
  } else {
    addrs1=top.prodbox.document.cartForm.address1.value;
  }
  if (top.prodbox.document.cartForm.city.value.length<2) {
     alert("'city' is a required field...");
     return false;
  } else {
    addcity=top.prodbox.document.cartForm.city.value;
  }
  if ((top.prodbox.document.cartForm.state.value.length<2) || (top.prodbox.document.cartForm.state.value=='Select a State')) {
     alert("'ship state' is a required field...");
     return false;
  } else {
    addst=top.prodbox.document.cartForm.state.value;
  }
  if (top.prodbox.document.cartForm.zip.value<2) {
     alert("'zip code' is a required field...");
     return false;
  } else {
    addzip=top.prodbox.document.cartForm.zip.value;
  } 

  top.prodbox.document.cartForm.calcBtn.value="Please wait...";

  clearShip(true);
  var totalStr=calcTotal();
  var spcfees=calcSpcFees();
  var upswgts=calcWeight();

  getExlWgts();

   //alert(top.excWgt);
   //if (top.excWgt>0) {
      //alert("Your order contains "+(top.excWgt).toString()+" lbs that are excluded from free shipping promotions...");
      //alert("Some select items may be excluded from free shipping promotions...");
   //}

  //---call server-side java servlet to retrieve shipping charge options:
  //top.prodbox.location="http://www.fhsteinbart.com/getUPSshpChg/getUPS?wgt="+top.prodbox.document.cartForm.orderweight.value+"&addr="+top.prodbox.document.cartForm.address1.value+"&city="+top.prodbox.document.cartForm.city.value+"&state="+top.prodbox.document.cartForm.state.value+"&zip="+top.prodbox.document.cartForm.zip.value+"&ordtotal="+totalStr+"&spc_fees="+spcfees;
    top.prodbox.location="http://www.fhsteinbart.com/getUPSshpChg/getUPS?wgt="+upswgts+"&xlwgt="+top.excWgt+"&addr="+addrs1+"&city="+addcity+"&state="+addst+"&zip="+addzip+"&ordtotal="+totalStr+"&spc_fees="+spcfees;
}


function getUPSchgCalc(strTot,spcfeestr) {
   //--- INDEPENDENT calls - for independent calculator (getShpChg.htm)
   ////UPS integration:
  if (document.cartForm.address1.value<2) {
     alert("'address 1' is a required field...");
     return false;
  }
  if (document.cartForm.city.value.length<2) {
     alert("'city' is a required field...");
     return false;
  }
  //if (document.cartForm.state.value.length<2) {
  if ((document.cartForm.state.value.length<2) || (top.prodbox.document.cartForm.state.value=='Select a State')) {
     alert("'ship state' is a required field...");
     return false;
  }
  if (document.cartForm.zip.value<2) {
     alert("'zip code' is a required field...");
     return false;
  } 


  var totalStr=strTot;
  var spcfees=spcfeestr;

  //---call server-side java servlet to retrieve shipping charge options:
  top.prodbox.location="http://www.fhsteinbart.com/getUPSshpChg/getUPS?wgt="+top.prodbox.document.cartForm.orderweight.value+"&addr="+top.prodbox.document.cartForm.address1.value+"&city="+top.prodbox.document.cartForm.city.value+"&state="+top.prodbox.document.cartForm.state.value+"&zip="+top.prodbox.document.cartForm.zip.value+"&ordtotal="+totalStr+"&spc_fees="+spcfees;
}


function reLoadCart() {
   // called from cart onload...
   //alert(top.orderstat);
   if (top.orderstat==0) {
      top.location="http://www.fhsteinbart.com/products/fhs_cart.php";
   } //---reset to empty cart
}  //--- end of reLoadCart()


function getCartShip() {
   ////UPS integration:
   totStr=calcTotal();
}  //--- end of getCartShip()


function updShpChg(shpSel, shpDoc) {
    ////UPS integration:
    top.shipChg=parseFloat(shpSel);
    top.upsChg=parseFloat(shpSel);
    top.shipDoc=shpDoc;
}  //--- end of updShpChg()


function updWgts() {   //---testing
  var numItems=top.itemCnt+1;
  for (var i=0; i < numItems; i++) {  //---reformat weights
     top.cartItems[i][5]=formatNum(parseFloat(top.cartItems[i][5]),0);
  }
}  //--- end of updShpChg()


function steincart() {
   //  called from cart.htm.onload...

   var browserOk = (((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 4 )) || ((navigator.appName == "Microsoft Internet Explorer") && ((navigator.appVersion.indexOf("MSIE 5.5")>-1) || (navigator.appVersion.indexOf("MSIE 6")>-1)) ))
   //if (browserOk) {
     // DEPRECIATED BROWSER WARNING...
   //} else {
   //  alert("You may need a browser upgrade [from "+navigator.appName+" : "+navigator.appVersion+"] to view this site: the [Delete] buttons may not work properly.  (you can set the 'qty' to 0 to for items you don't want)...");
   //}

   var cookieStr=GetCookie("user");
   if (cookieStr==null) {
      top.userFirst=" ";
      top.userLast=" ";
      top.itemCnt=0;
      top.ckieCnt=0;
      top.ckieNdx=0;
   } else {
     //alert("steincart()user:"+cookieStr+"...");
     //! -- updated for packed cookies
      if (cookieStr.lastIndexOf('|')==-1) {
         top.userFirst=" ";
         top.userLast=" ";
         top.itemCnt=0;
         top.ckieCnt=0;
         top.ckieNdx=0;
      } else {
         var name2ndcue=cookieStr.lastIndexOf('$')+1;
         var name1stcue=cookieStr.lastIndexOf('|')+1;
         var itemCntcue=cookieStr.lastIndexOf('#')+1;
         var ckieNdxcue=cookieStr.lastIndexOf('!')+1;
         top.userLast=cookieStr.substring(name2ndcue,cookieStr.length);
         top.userFirst=cookieStr.substring(name1stcue,name2ndcue-1);
         top.itemCnt=parseInt(cookieStr.substring(itemCntcue,name1stcue-1), 10);
         top.ckieNdx=parseInt(cookieStr.substring(ckieNdxcue,itemCntcue-1), 10);
         top.ckieCnt=parseInt(cookieStr.substr(0,ckieNdxcue-1), 10);
         //alert("steincart()itemCnt="+top.itemCnt.toString()+" ckiendx="+top.ckieNdx.toString()+" ckieCnt="+top.ckieCnt.toString()+" name="+top.userFirst+" "+top.userLast+"...");
      } // failsafe this cookie
   }

   var cszStr=GetCookie("csz");     
   if (cszStr==null) {
      top.shipCity=" ";
      top.shipState=" ";
      top.shipZip=" ";
   } else {
      var zipcue=cszStr.lastIndexOf('$')+1;
      var statecue=cszStr.lastIndexOf('|')+1;
      top.shipZip=cszStr.substring(zipcue,cszStr.length);
      top.shipState=cszStr.substring(statecue,zipcue-1);
      top.shipCity=cszStr.substr(0,statecue-1);
   }

   var phoneStr=GetCookie("phone");
   if (phoneStr==null) {
      top.userPhoneA=" ";
      top.userPhoneB=" ";
      top.userPhoneC=" ";
   } else {
      var phnCcue=phoneStr.lastIndexOf('$')+1;
      var phnBcue=phoneStr.lastIndexOf('|')+1;
      top.userPhoneC=phoneStr.substring(phnCcue,phoneStr.length);
      top.userPhoneB=phoneStr.substring(phnBcue,phnCcue-1);
      top.userPhoneA=phoneStr.substr(0,phnBcue-1);
   }

   var addrStr=GetCookie("shipadd");
   if (addrStr==null) {
      top.shipAddr1=" ";
      top.shipAddr2=" ";
   } else {
      var addrcue=addrStr.lastIndexOf('$')+1;
      top.shipAddr2=addrStr.substring(addrcue,addrStr.length);
      top.shipAddr1=addrStr.substr(0,addrcue-1);
   }

   top.usermail=GetCookie("email");
   if (top.usermail==null) {
      top.usermail=" ";
   }
}  // end of steinCart()


function repartnum(text) {
   var charndx=text.indexOf("_");
   while (charndx>0) {
      text=text.substr(0,charndx)+"-"+text.substr(charndx+1);
      charndx=text.indexOf("_")
   }
   return text;
} // reconstitute proper part# format from field-name format


function txtTrim(text) {
   var firstspace=text.indexOf(" ");
   if (firstspace>0) {
      var txt=text.substr(0,firstspace);
      return txt;
   } else {
     return text;
   }
}  // trim to the first blank


function trimLeft(text) {
   if (text!=null) {
      var txtLen=text.length;
      var txt=text.toString();
      if (txtLen>0) {  // failsafe passing null strings
         for (var i=0; i<txtLen; i++) {
            if (text.substring(i,i+1)==" ") {
               // skip to the 1st non-blank char
            } else {
               txt=text.substr(i,txtLen)
               i=txtLen+1; //finished, at 1st char...
            }
         }
         return txt;
      } else {
         return text;
      } 
   } else {
     return text;
   } 
} // end of trim leading blanks


function setFields() {
  if (top.fieldset==0) {
     top.fieldset=1;
     top.prodbox.document.cartForm.first_name.value=trimLeft(top.userFirst);
     top.prodbox.document.cartForm.last_name.value=trimLeft(top.userLast);

     top.prodbox.document.cartForm.night_phone_a.value=trimLeft(top.userPhoneA);
     top.prodbox.document.cartForm.night_phone_b.value=trimLeft(top.userPhoneB);
     top.prodbox.document.cartForm.night_phone_c.value=trimLeft(top.userPhoneC);
     top.prodbox.document.cartForm.address1.value=trimLeft(top.shipAddr1);
     top.prodbox.document.cartForm.address2.value=trimLeft(top.shipAddr2);
     top.prodbox.document.cartForm.city.value=trimLeft(top.shipCity);
     top.prodbox.document.cartForm.state.value=trimLeft(top.shipState);
     top.prodbox.document.cartForm.getState.value=trimLeft(top.shipState);
     top.prodbox.document.cartForm.zip.value=trimLeft(top.shipZip);
     top.prodbox.document.cartForm.email.value=trimLeft(top.usermail);
  }
}


function setRows(rowSizes) {
   if (navigator.appVersion.indexOf("MSIE")>-1) {
      //---if browser is crap, use this  
      parent.document.getElementById('steincart').rows = rowSizes;
   } else {
      //---if browser is an honest browser, use this
      var f = parent.document.getElementById('steincart');
      rowSizes="'"+rowSizes+"'";
      f.setAttribute('rows', rowSizes);
   }
} 


function chkOptIn(thisItem) {
   if (thisItem.checked) {
      top.emailOptIn=true;
   } else {
      top.emailOptIn=false;
   }
}


function prepPPwgts(form) {
   //--- convert fractional wgts to "1", and flag current status as submitted to PP
   top.ppQtyOn=false;
   var elementLen=top.prodbox.document.cartForm.elements.length;
   for (var j = top.itemCnt-1; j>=0; j--) {
      if (top.cartItems[j][2]<0) {
         //---gen form.field name
         updfld="quantity_"+(top.itemCnt-j).toString();
         updfld2="amount_"+(top.itemCnt-j).toString();
         updTot=formatNum(parseFloat(top.cartItems[j][3])*parseFloat(top.cartItems[j][4]),2);
         for (var k=0; k < elementLen; k++) {  //---look for this hidden field
            if (top.prodbox.document.cartForm.elements[k].name==updfld) {
               //---read field value, parse fractional qty    
               oldvalue=top.prodbox.document.cartForm.elements[k].value;
               top.prodbox.document.cartForm.elements[k].value="1";
               //alert("prepPPwgts():"+updfld+" was "+oldvalue+" now="+top.prodbox.document.cartForm.elements[k].value+"...");
            } //-- found it: set fractional qty to "1"
         } //-- loop thru forms.fields for qty field to update

         for (var k=0; k < elementLen; k++) {  //---look for this hidden field
            if (top.prodbox.document.cartForm.elements[k].name==updfld2) {
               //---read field value, parse fractional qty    
               oldvalue=top.prodbox.document.cartForm.elements[k].value;
               top.prodbox.document.cartForm.elements[k].value=updTot;
               //alert("prepPPwgts():"+updfld2+" was "+oldvalue+" now="+top.prodbox.document.cartForm.elements[k].value+"...");
            } //-- found it: set fractional price to total for fractional qty
         } //-- loop thru forms.fields for price field to update
         top.ppQtyOn=true;
      } else {
         oldval=top.cartItems[j][4];
         top.cartItems[j][4]=formatNum(top.cartItems[j][4],0);
         //---gen form.field name
         updfld="quantity_"+(top.itemCnt-j).toString();
         for (var k=0; k < elementLen; k++) {  //---look for this hidden field
            if (top.prodbox.document.cartForm.elements[k].name==updfld) {
               //---read field value, parse fractional qty    
               oldvalue=top.prodbox.document.cartForm.elements[k].value;
               top.prodbox.document.cartForm.elements[k].value=formatNum(top.prodbox.document.cartForm.elements[k].value,0);
               //alert("prepPPwgts():"+updfld+" was "+oldvalue+" now="+top.prodbox.document.cartForm.elements[k].value+"...");
            } //-- found it: failsafe: set qty to integer
         } //-- loop thru forms.fields for qty field to update
      } //-- is flagged as ppQty / std item
   }
   return top.ppQtyOn;
} 


function gobottom(thisitem) {
   thisitem.form.bottomPage.focus();
}

function gotop(thisitem) {
   thisitem.form.topPage.focus();
}

function getVal(thisitem) {
   top.tempVar=thisitem.value;
}

function setVal(thisitem) {
   thisitem.value=top.tempVar;
}


function saveFields(form,failsafe) {
  // save current cookies for fhsteinbart.com...
  // called from submit button...
  // called from text fields' onBlur()...
  form.first_name.value=trimLeft(form.first_name.value);
  form.last_name.value=trimLeft(form.last_name.value);
  form.night_phone_a.value=trimLeft(form.night_phone_a.value);
  form.night_phone_b.value=trimLeft(form.night_phone_b.value);
  form.night_phone_c.value=trimLeft(form.night_phone_c.value);
  form.address1.value=trimLeft(form.address1.value);
  form.address2.value=trimLeft(form.address2.value);
  form.city.value=trimLeft(form.city.value);
  form.state.value=trimLeft(form.state.value);
  form.zip.value=trimLeft(form.zip.value);
  form.email.value=trimLeft(form.email.value);
  
  if ((form.first_name.value.length<2) && (failsafe)) {
     alert("'first name' is a required field...");
     return false;
  }
  if ((form.last_name.value.length<2) && (failsafe)) {
     alert("'last name' is a required field...");
     return false;
  }
  if ((form.email.value.length<2) && (failsafe)) {
     alert("'email' is a required field...");
     return false;
  }
  if ((form.night_phone_a.value.length<2) && (failsafe)) {
     alert("'area code' is a required field...");
     return false;
  }
  if ((form.night_phone_b.value.length<2) && (failsafe)) {
     alert("'phone prefix' is a required field...");
     return false;
  }
  if ((form.night_phone_c.value.length<2) && (failsafe)) {
     alert("'phone number' is a required field...");
     return false;
  }
  if ((form.city.value.length<2) && (failsafe)) {
     alert("'city' is a required field...");
     return false;
  }
  if (((form.state.value.length<2) || (form.state.value=='Select a State')) && (failsafe)) {
     alert("'ship state' is a required field...");
     return false;
  }
  if ((form.zip.value.length<2) && (failsafe)) {
     alert("'zip code' is a required field...");
     return false;
  }
  if ((top.upsChg<0) && (failsafe)) {
     alert("Before checkout, you must first select a shipping charge...");
     return false;
  }

  var expdate = new Date ();
  FixCookieDate (expdate); // Correct for Mac date bug - call only once for given Date object!
  expdate.setTime (expdate.getTime() + (90 * 24 * 60 * 60 * 1000)); // 90 days from now   

  top.userFirst=trimLeft(form.first_name.value);
  top.userLast=trimLeft(form.last_name.value);
  top.userPhoneA=form.night_phone_a.value;
  top.userPhoneB=form.night_phone_b.value;
  top.userPhoneC=form.night_phone_c.value;
  top.shipAddr1=trimLeft(form.address1.value);  top.shipAddr2=trimLeft(form.address2.value);
  top.shipCity=trimLeft(form.city.value);
  top.shipState=trimLeft(form.state.value);
  top.shipZip=trimLeft(form.zip.value);
  top.usermail=trimLeft(form.email.value);

  //! -- updated for packed cookies
  SetCookie ("user", top.ckieCnt.toString()+"!"+top.ckieNdx.toString()+"#"+top.itemCnt.toString()+"|"+top.userFirst+"$"+top.userLast, expdate);
  //alert("savefields set:"+top.ckieCnt.toString()+"!"+top.ckieNdx.toString()+"#"+top.itemCnt.toString()+"|"+top.userFirst+"$"+top.userLast);

  SetCookie ("phone", form.night_phone_a.value+"|"+form.night_phone_b.value+"$"+form.night_phone_c.value, expdate);
  SetCookie ("shipadd", form.address1.value+"$"+form.address2.value, expdate);
  SetCookie ("csz", form.city.value+"|"+form.state.value+"$"+form.zip.value, expdate);
  SetCookie ("email", form.email.value, expdate);

  return true;
} // end of saveFields()


function curCookie() {
  if ((top.itemCnt/3)<=1) {  //--- in the very first item cookie...
     top.ckieCnt=1;
  } else { 
     if ((top.itemCnt/3)-(parseInt((top.itemCnt/3).toString())) > 0  ) { //--- 2nd or 3rd item in this cookie...
       top.ckieCnt=parseInt((top.itemCnt/3).toString())+1;     
     } else {    //--- 1st item in this cookie... 
       top.ckieCnt=parseInt((top.itemCnt/3).toString());     
     }
  }
  return top.ckieCnt;  //--- currently building this item cookie (index of current item cookie)
}


function itemCookie(thisItem) {
  var itemCkie=1;
  if ((thisItem/3)<1) {
     if ((thisItem/3)<0.34) return "A"+itemCkie.toString();
     if ((thisItem/3)<0.68) return "B"+itemCkie.toString();
  } else { 
     if ((thisItem/3)-(parseInt((thisItem/3).toString())) > 0  ) {
       itemCkie=parseInt((thisItem/3).toString())+1;     
       if ((thisItem/3)-(parseInt((thisItem/3).toString()))<0.34) return "A"+itemCkie.toString();
       if ((thisItem/3)-(parseInt((thisItem/3).toString()))<0.68) return "B"+itemCkie.toString();
     } else {
       itemCkie=parseInt((thisItem/3).toString());     
       return "C"+itemCkie.toString();
     }
  }
  return itemCkie;
}


function rewriteCookie(thisItem) {
    //---clear, and remake this cookie
    var curIdx=0;
    var curCkie=itemCookie(thisItem);
    var thisCkie=parseInt(curCkie.substring(1,curCkie.length));
    if (curCkie.substring(0,1)=="A") curIdx=thisItem-1;
    if (curCkie.substring(0,1)=="B") curIdx=thisItem-2;
    if (curCkie.substring(0,1)=="C") curIdx=thisItem-3;
    //alert("rewriteC()thisItem="+thisItem.toString()+"/ itemCnt="+top.itemCnt.toString()+"/ curCkie="+curCkie+"/ curIdx="+curIdx.toString()+"/deleting "+thisCkie.toString()+"...");
    DeleteCookie("itm"+thisCkie.toString());

    //! -- rewrite this cookie
    var itemArray=new Array();
    for (var i = curIdx; (i<=(curIdx+2) && i<top.itemCnt); i++) {
      itemArray[0]=top.cartItems[i][0];
      itemArray[1]=top.cartItems[i][1];
      itemArray[2]=top.cartItems[i][2];
      itemArray[3]=top.cartItems[i][3];
      itemArray[4]=top.cartItems[i][4];
      itemArray[5]=top.cartItems[i][5];
      addItemCookie(itemArray,thisCkie);
    }
    updCookie();
}


function updCookie() {
  //--- update items/cookies count
  var curCkie=curCookie();
  var expdate = new Date ();
  FixCookieDate (expdate); // Correct for Mac date bug - call only once for given Date object!
  expdate.setTime (expdate.getTime() + (90 * 24 * 60 * 60 * 1000)); // 90 days from now
  //! -- updated for packed cookies
  SetCookie ("user", top.ckieCnt.toString()+"!"+top.ckieNdx.toString()+"#"+top.itemCnt.toString()+"|"+top.userFirst+"$"+top.userLast, expdate);
  //alert("updcookie set:"+top.ckieCnt.toString()+"!"+top.ckieNdx.toString()+"#"+top.itemCnt.toString()+"|"+top.userFirst+"$"+top.userLast);
} 


function addItemCookie(itemArray,ckieIdx) { 
//--- append this item to specified cookie - 78 chars per item/3 items per cookie
  var expdate = new Date ();
  FixCookieDate (expdate); // Correct for Mac date bug - call only once for given Date object!
  expdate.setTime (expdate.getTime() + (90 * 24 * 60 * 60 * 1000)); // 90 days from now   

  //---build this item's cookie---
  var itemStr=itemArray[0];  //--- add part# to itemStr
  var thisCnt=itemStr.length;
  for (var i = thisCnt; i < 10; i++) { //--- pad itemStr(part#) to 10 char
     itemStr=itemStr+" ";
  }

  itemStr=itemStr+itemArray[1];  //--- add part-desc to itemStr
  thisCnt=itemStr.length;
  if (thisCnt>50) {
     thisCnt=50;
     itemStr=itemStr.substr(0,50);
  } //--- failsafe: trim to 50
  for (var i = thisCnt; i < 50; i++) { //--- pad itemStr to 54 char total (part#:10 + desc:40)
     itemStr=itemStr+" ";
  }

  var priceStr=formatNum(itemArray[3],2); 
  thisCnt=priceStr.length;
  for (var i = thisCnt; i < 8; i++) { //--- pad price to 8 with leading zeros
     priceStr="0"+priceStr;
  }
  itemStr=itemStr+priceStr;  //--- add price to itemStr

  var qtyStr=itemArray[4];
  thisCnt=qtyStr.length;
  for (var i = thisCnt; i < 8; i++) { //--- pad qty to 8 with leading zeros
     qtyStr="0"+qtyStr;
  }
  itemStr=itemStr+qtyStr;  //--- add qty to itemStr

  var wgtStr=itemArray[5];
  thisCnt=wgtStr.length;
  for (var i = thisCnt; i < 6; i++) { //--- pad qty to 6, with leading zeros
     wgtStr="0"+wgtStr;
  }
  itemStr=itemStr+wgtStr;  //--- add wgt to itemStr 

  var spcStr=formatNum(itemArray[2],2);
  thisCnt=spcStr.length;
  if (thisCnt>6) {
     spcStr=spcStr.substr(0,6);
     thisCnt=6;
  } //--- failsafe: trim trailing chars if more than 6 chars

  if (parseFloat(spcStr)<0) { //--- if negative (lbs/oz qty flag), add zeros to end/ otherwise add to front
     for (var i = thisCnt; i < 6; i++) { //--- pad spc-fee to 6, with trailing zeros
        spcStr=spcStr+"0";
     }
  } else {
     for (var i = thisCnt; i < 6; i++) { //--- pad spc-fee to 6, with leading zeros
        spcStr="0"+spcStr;
     }
  }
  itemStr=itemStr+spcStr;  //--- add spc-fee to itemStr 

  //--- check existing cookie, add to it ---
  var itemname="itm"+ckieIdx.toString();
  var getcookieStr=GetCookie(itemname);
  if (getcookieStr!=null) itemStr=getcookieStr+itemStr;


  //---write this item's cookie---
  //alert("addItemCookie()cookie="+"itm"+ckieIdx.toString()+"/"+itemStr+"...");
  SetCookie ("itm"+ckieIdx.toString(), itemStr, expdate);
  return true;
}


function hdrDisplay() {
   //alert("hdrDisplay().top.orderstat="+top.orderstat.toString()+"...");
   if (top.orderstat==0) {
      steincart();
      //alert("hdrDisplay()itemCnt="+top.itemCnt.toString()+" ckieCnt="+top.ckieCnt.toString()+"...");
      var cookieStr=GetCookie("user");
      if (cookieStr==null) {
         top.userFirst=" ";
         top.userLast=" ";
         top.itemCnt=0;
         top.ckieCnt=0;
         top.ckieNdx=0;
      }

      var ordItems=top.itemCnt;
      if (ordItems>0) {
         //alert("hdrDisplay()user:"+cookieStr+"/ itemCnt="+top.itemCnt.toString()+"/ ckieCnt="+top.ckieCnt.toString()+"...");
         var itemtag="";
         var itemnum="";
         var itemdesc="";
         var itemprc="";
         var itemqty="";

         var thisItem=" ";
         var cookieCnt=curCookie();
         //alert("hdrDisplay()cookieCnt(curCookie() result):"+cookieCnt.toString()+"...");
         top.itemCnt=0;

         top.orderstat=1;

         top.ckieNdx=0;
         //alert("hdrDisplay()ckieCnt="+top.ckieCnt.toString()+"...");
         for (var i=1; i<=top.ckieCnt; i++) {
            //! -- updated for packed cookies
            itemtag="itm"+i.toString();
            thisItem=GetCookie(itemtag);
            if (thisItem!=null) {
               //alert("hdrDisplay()i="+i.toString()+" / "+itemtag+":"+thisItem+"...");
               addpartsC(thisItem);
            } //--- valid cookie, get and add items
         } //---get stored cookies
         var cookieCnt=curCookie();

         ////---print out retrieved cookies
         //numOfLines=0;
         //var txtLines = new Array(); 
         //var flag=1;
         //cartHdr(top.itemCnt,txtLines);
         //showAllItems(txtLines,flag);
         //cartFtr(txtLines);
         //writeCart(txtLines);
         //setFields();
         //alert(top.itemCnt.toString()+" selected items restored *** TO CREATE A NEW ORDER, please use the [Clear Order Form] button on the order form to clear all selections...");

         ////---reset cart's shipping fields
         //var elementLen=top.prodbox.document.cartForm.elements.length;
         //for (var i=0; i < elementLen; i++) {  //---1st reset ship chg to zero
         //   if (top.prodbox.document.cartForm.elements[i].name=="t_"+(top.itemCnt+1).toString()) {
         //     top.prodbox.document.cartForm.elements[i].value=formatNum(0,2);
         //   }
         //   if (top.prodbox.document.cartForm.elements[i].name=="amount_"+(top.itemCnt+1).toString()) {
         //     top.prodbox.document.cartForm.elements[i].value=formatNum(0,2);
         //   }
         //}
         //var totalStr=calcTotal();
         //for (var i=0; i < elementLen; i++) { //---now reset total
         //   if (top.prodbox.document.cartForm.elements[i].name=="ordertotal") {
         //     top.prodbox.document.cartForm.elements[i].value=totalStr;
         //     i=elementLen;
         //   }
         //}
         clearShip(false);
      } else {
         top.itemCnt=0;
         top.ckieCnt=0;
         top.ckieNdx=0;
         clearShip(false);
      } //--- get pending order's parts
      top.orderstat=1;
   } else {
     //alert("orderstat="+top.orderstat.toString()+"...");
   }
}

//--------------------------------------
// PPP -  javascript - cart


function sd(htmfile) {
   prtdetail=window.open(htmfile, 'part_details', 'menubar=no,directories=no,location=no,resizable=yes,toolbar=no,scrollbars=yes,status=no,width=600,height=200');
   prtdetail.focus();
}


function clickAlert(thisPoint) {
   thisPoint.blur();
   top.prodbox.focus();
   alert("Read-only field!...");
   return true;
}


function isEmpty(text) {
        if (text == null || text == "") {
                return true;
        }
        return false;
}


function delspace(text) {
        var trimtext="";
        var normtext="";
        var textLen=text.length;
        for (var i=0; i<textLen; i++) {
            if (text.substr(i,1)!=" ") {
               trimtext+=text.substr(i,1);
            } else {
               trimtext+="!";
            }
        }
        textLen=trimtext.length;  // remove .
        for (var i=0; i<textLen; i++) {
            if (trimtext.substr(i,1)!=".") {
               normtext+=trimtext.substr(i,1);
            }
        }
        return normtext;
}


// is a positive integer
function isPosInteger(inputStr) {
 for (var i = 0; i < inputStr.length; i++) {
   var oneChar = inputStr.substring(i, i + 1);
   if (oneChar < "0" || oneChar > "9") {
     return false;
   }
 }
 return true;
}


// function to check if the input is a valid positive integer
function isValidPosInteger(inputStr) {
  if (isEmpty(inputStr)) {
    alert("Invalid integer entered...");
    return false;
  } else {
    if (!isPosInteger(inputStr)) {
      alert("not a positive interger...");
      return false;
    } 
  }
  return true;
}


function formatNum(expr,decplaces) {
   var returnstr="0";
   var str = (Math.round(parseFloat(expr) * Math.pow(10,decplaces))).toString();
   while (str.length <= decplaces) {
      str = "0" + str;
   } 
   var decpoint = str.length - decplaces;
   if (decplaces==0) {
      returnstr=str;
   } else {
      returnstr=str.substring(0,decpoint) + "." + str.substring(decpoint,str.length);
   }
   return returnstr;
}


function writeCart(txtAry) {
    if ((top.prodbox==undefined) || (top.prodbox==null)) {
       window.location="http://www.fhsteinbart.com/products/index.php";
       return false;
    }
    top.prodbox.document.open("text/html","replace");
    for (var j = 0; j<=numOfLines; j++) {
       top.prodbox.document.writeln(txtAry[j]);
    }

    top.prodbox.document.close();
    top.fieldset=0;
}


function cartHdr(cnt, txtAry) {
   txtAry[numOfLines]="<HTML><HEAD>";
   txtAry[(++numOfLines)]="<STYLE type='text/css'>";
   txtAry[(++numOfLines)]="BODY, TABLE, TD, P { font: normal 9pt Arial}";
   txtAry[(++numOfLines)]="</STYLE>";
   txtAry[(++numOfLines)]="<META http-equiv='Content-Script-Type' content='text/javascript1.2'>";
   txtAry[(++numOfLines)]="</HEAD>";
   txtAry[(++numOfLines)]="<BODY TEXT='#000000' BGCOLOR='#FFFFFF' leftmargin=4 rightmargin=3 OnLoad='top.reLoadCart()'>";

   //---sandbox code:
   //txtAry[(++numOfLines)]="<form NAME='cartForm' action='https://www.sandbox.paypal.com/us/cgi-bin/webscr' target='_top' method='post'>";
   txtAry[(++numOfLines)]="<form NAME='cartForm' action='https://www.paypal.com/cgi-bin/webscr' target='_top' method='post'>";

   txtAry[(++numOfLines)]="<input type='hidden' name='cmd' value='_cart'>";
   txtAry[(++numOfLines)]="<input type='hidden' name='upload' value='1'>";
   txtAry[(++numOfLines)]="<input type='hidden' name='address_override' value=1>";
   //---sandbox code:
   //txtAry[(++numOfLines)]="<input type='hidden' name='business' value='seller_1236025519_per@fhsteinbart.com'>";
   txtAry[(++numOfLines)]="<input type='hidden' name='business' value='orders@fhsteinbart.com'>";

   txtAry[(++numOfLines)]="<input type='hidden' name='image_url' value='http://www.fhsteinbart.com/products/images/fhslogo.gif'>";
   txtAry[(++numOfLines)]="<input type='hidden' name='cpp_headerback_color' value='FFCC33'>";
   txtAry[(++numOfLines)]="<input type='hidden' name='cpp_headerborder_color' value='000000'>";
   txtAry[(++numOfLines)]="<input type='hidden' name='cpp_payflow_color' value='FFEEBB'>";
   txtAry[(++numOfLines)]="<input type='hidden' name='cpp_cart_border_color' value='FFCC33'>";
   txtAry[(++numOfLines)]="<input type='hidden' name='state' value=''>";
   txtAry[(++numOfLines)]="<input type='hidden' name='return' value='http://www.fhsteinbart.com/products/orderreceived.htm'>";
   txtAry[(++numOfLines)]="<input type='hidden' name='cancel_return' value='http://www.fhsteinbart.com/products/index.html'>";

   txtAry[(++numOfLines)]="<TABLE BORDER=0 WIDTH='97%' CELLSPACING=0 CELLPADDING=0>";
   txtAry[(++numOfLines)]="  <TR>";
   txtAry[(++numOfLines)]="    <TD COLSPAN=2 align='left'><B>Your order contains "+cnt.toString()+" items...</B></TD>";
   txtAry[(++numOfLines)]="    <TD COLSPAN=5 align='right'><INPUT TYPE='button' VALUE='Continue shopping...' TABINDEX=17 TITLE='continue shopping for more...' onClick='javascript: top.curTitle="+'"Product Specials"'+"; top.hdrbox.location.reload(); window.location="+'"http://www.fhsteinbart.com/products/SPECIALS.php"'+"';></TD>"
   txtAry[(++numOfLines)]="  </TR>";
   txtAry[(++numOfLines)]="  <TR>";
   txtAry[(++numOfLines)]="    <TH ALIGN=LEFT>Part #</TH>";
   txtAry[(++numOfLines)]="    <TH ALIGN=LEFT>Description</TH>";
   txtAry[(++numOfLines)]="    <TH ALIGN=LEFT>Price</TH>";
   txtAry[(++numOfLines)]="    <TH ALIGN=LEFT>Lbs</TH>";
   txtAry[(++numOfLines)]="    <TH ALIGN=LEFT>Qty</TH>";
   txtAry[(++numOfLines)]="    <TH ALIGN=LEFT>Total $</TH>";
   txtAry[(++numOfLines)]="    <TH ALIGN=LEFT>&nbsp;</TH>";
   txtAry[(++numOfLines)]="  </TR>";

   //return txt;
} //--- end of cartHdr()


function cartFtr(txtAry) {
   var totalstr=calcTotal();
   if (top.upsChg<0) {
      var totalstr=calcTotal();
   } else {
      var totalstr=formatNum((parseFloat(calcTotal())+top.shipChg),2);
   }
   var totalwgt=calcWeight();
   var spc_fees=parseFloat(calcSpcFees());

   txtAry[(++numOfLines)]="  <TR><TD COLSPAN=7><hr></TD></TR>";       
   txtAry[(++numOfLines)]="  <TR>";
   txtAry[(++numOfLines)]="    <TD COLSPAN=2 ALIGN='LEFT'><INPUT TYPE='button' VALUE='Clear order form...' TITLE='clear all items from this order form...' onClick='if(confirm("+'"Clear your order form entries?"'+")) {top.clearItems();}'> &nbsp; &nbsp; <INPUT TYPE='button' VALUE='Print order form' TITLE='print this order form...' onClick='javascript:print()';> &nbsp; <INPUT TYPE='TEXT' NAME='lblstatus' VALUE=' ' SIZE='15' STYLE='border-width: 0; border: none; font-weight: bold; color: #AA0000;' READONLY></TD>";
   txtAry[(++numOfLines)]="    <TD align='right'><B>Total Lbs:</B></TD>";
   txtAry[(++numOfLines)]="    <TD align='left'><INPUT TYPE=TEXT NAME='orderweight' VALUE="+totalwgt+" SIZE=6 readonly=true onFocus='top.clickAlert(this);'></TD>";
   txtAry[(++numOfLines)]="    <TD align='right'><B>Order Total$:</B></TD>";
   txtAry[(++numOfLines)]="    <TD align='left'><INPUT TYPE=TEXT NAME='ordertotal' VALUE="+totalstr+" SIZE=6 readonly=true onFocus='top.clickAlert(this);'></TD>";
   txtAry[(++numOfLines)]="    <TD>&nbsp;</TD>";
   txtAry[(++numOfLines)]="  </TR>";
   txtAry[(++numOfLines)]="  <TR><TD COLSPAN=7><HR>&nbsp;</TD></TR>";
   txtAry[(++numOfLines)]="  <TR>";
   txtAry[(++numOfLines)]="    <TD colspan=7 ALIGN=CENTER><FONT COLOR='#AA0000'><B> &nbsp;*To complete your order, enter <u>ALL</u> the required information below AND select a shipping option:</B></FONT></TD>";
   txtAry[(++numOfLines)]="    <TD colspan=3>&nbsp;</TD>";
   txtAry[(++numOfLines)]="  </TR>";
   txtAry[(++numOfLines)]="  <TR><TD COLSPAN=7>";
   txtAry[(++numOfLines)]="    <TABLE BORDER=0 WIDTH='100%' CELLSPACING=0 CELLPADDING=2>";
   txtAry[(++numOfLines)]="      <TR>";
   txtAry[(++numOfLines)]="        <TD ALIGN=RIGHT>*first,last name</TD>";
   txtAry[(++numOfLines)]="        <TD VALIGN=TOP ALIGN=LEFT><INPUT TYPE='TEXT' NAME='first_name' TABINDEX=1 SIZE=12 onBlur='top.saveFields(this.form,false);' 'onFocus='javascript:if (top.fieldset==0){top.setFields();}'> <INPUT TYPE='TEXT' NAME='last_name' TABINDEX=2 SIZE=15 onBlur='top.saveFields(this.form,false);' 'onFocus='javascript:if (top.fieldset==0){top.setFields();}'></TD>";
   txtAry[(++numOfLines)]="        <TD ALIGN=RIGHT>*email</TD>";
   txtAry[(++numOfLines)]="        <TD ALIGN=LEFT><INPUT TYPE='TEXT' NAME='email' TABINDEX=9 SIZE=25 onBlur='top.saveFields(this.form,false);'></TD>";
   txtAry[(++numOfLines)]="      </TR>";
   txtAry[(++numOfLines)]="      <TR>";
   txtAry[(++numOfLines)]="        <TD ALIGN=RIGHT>*address</TD>";
   txtAry[(++numOfLines)]="        <TD ALIGN=LEFT><INPUT TYPE='TEXT' NAME='address1' TABINDEX=3 SIZE=25 onBlur='top.saveFields(this.form,false);' 'onFocus='javascript:if (top.fieldset==0){top.setFields();}'></TD>";
   txtAry[(++numOfLines)]="        <TD ALIGN=RIGHT>*area code, prefix, phone #</TD>";
   txtAry[(++numOfLines)]="        <TD VALIGN=TOP ALIGN=LEFT><INPUT TYPE='TEXT' NAME='night_phone_a' TABINDEX=10 SIZE=3 onBlur='top.saveFields(this.form,false);'> <INPUT TYPE='TEXT' NAME='night_phone_b' TABINDEX=11 SIZE=3 onBlur='top.saveFields(this.form,false);'> <INPUT TYPE='TEXT' NAME='night_phone_c' TABINDEX=12 SIZE=4 onBlur='top.saveFields(this.form,false);'></TD>";
   txtAry[(++numOfLines)]="      </TR>";

   txtAry[(++numOfLines)]="      <TR>";
   txtAry[(++numOfLines)]="        <TD ALIGN=RIGHT>suite/apt#</TD>";
   txtAry[(++numOfLines)]="        <TD VALIGN=TOP ALIGN=LEFT><INPUT TYPE='TEXT' NAME='address2' TABINDEX=4 SIZE=25 onBlur='top.saveFields(this.form,false);'></TD>";
   txtAry[(++numOfLines)]="        <TD VALIGN=TOP ALIGN=RIGHT valign='top' colspan=2><INPUT TYPE='CHECKBOX' TABINDEX=13 NAME='on3_"+(top.itemCnt+1).toString()+"' VALUE='email opt-in'";
   if (top.emailOptIn) {
      txtAry[(++numOfLines)]=" checked onClick='top.chkOptIn(this);'> receive product &amp; informational emails from us</TD>";
   } else {
      txtAry[(++numOfLines)]=" onClick='top.chkOptIn(this);'> receive product &amp; informational emails from us</TD>";
   }
   txtAry[(++numOfLines)]="        <TD>&nbsp;</TD>";
   txtAry[(++numOfLines)]="      </TR>";
   txtAry[(++numOfLines)]="      <TR>";
   txtAry[(++numOfLines)]="        <TD ALIGN=RIGHT>*city,state,zip</TD>";
   txtAry[(++numOfLines)]="        <TD COLSPAN=3 VALIGN=TOP ALIGN=LEFT><INPUT TYPE='TEXT' NAME='city' TABINDEX=5 SIZE=20 onBlur='top.saveFields(this.form,false);top.clearShip(true);'> ";

   showStates(txtAry);

   txtAry[(++numOfLines)]="          <INPUT TYPE='TEXT' NAME='zip' TABINDEX=7 SIZE=10 onBlur='top.saveFields(this.form,false);top.clearShip(true);'> <INPUT TYPE='TEXT' NAME='country' TABINDEX=8 SIZE=2 VALUE='US' onBlur='top.saveFields(this.form,false);top.clearShip(true);'></TD>";
   txtAry[(++numOfLines)]="        <TD>&nbsp;</TD>";
   txtAry[(++numOfLines)]="      </TR>";
   txtAry[(++numOfLines)]="      <TR>";
   txtAry[(++numOfLines)]="        <TD align='right'>*</TD>";
   txtAry[(++numOfLines)]="        <TD COLSPAN=2 VALIGN=TOP ALIGN=LEFT>";
   txtAry[(++numOfLines)]="            <INPUT TYPE='button' TABINDEX=14 NAME='calcBtn' VALUE='Select a shipping option...' TITLE='REQUIRED: select a shipping charge option...' onClick='top.getUPSchgs();'>";
   txtAry[(++numOfLines)]="        </TD>";
   txtAry[(++numOfLines)]="      </TR>";

   txtAry[(++numOfLines)]="      <TR><TD COLSPAN=5><HR></TD></TR>";

   txtAry[(++numOfLines)]="      <TR>";
   txtAry[(++numOfLines)]="        <TD COLSPAN=3 VALIGN=TOP ALIGN=LEFT>";
   txtAry[(++numOfLines)]="        <INPUT TYPE='button' VALUE='Continue shopping...' TABINDEX=15 TITLE='continue shopping for more...' onClick='javascript: top.curTitle="+'"Product Specials"'+"; top.hdrbox.location.reload(); window.location="+'"http://www.fhsteinbart.com/products/SPECIALS.php"'+"';></TD>";
   txtAry[(++numOfLines)]="        <TD VALIGN='TOP'><INPUT TYPE='submit' NAME='buyBtn' TABINDEX=16 VALUE='Checkout and Purchase Order...' "+'title="Pay with credit or debit cards, even if you don'+"'"+'t have a PayPal account!"'+" onClick='if(!top.saveFields(this.form,true)){return false;};if(top.confirmBuy()){return true;}else{return false;}'></TD>";
   txtAry[(++numOfLines)]="        <TD VALIGN='TOP'><input type='image' src='http://www.paypal.com/en_US/i/btn/x-click-but01.gif' name='submit' "+'title="Pay with credit or debit cards, even if you don'+"'"+'t have a PayPal account!"'+" onClick='if(!top.saveFields(this.form,true)){return false;};if(top.confirmBuy()){return true;}else{return false;}'></TD>";
   txtAry[(++numOfLines)]="      </TR>";

   txtAry[(++numOfLines)]="      <TR>";
   txtAry[(++numOfLines)]="        <TD COLSPAN=3 VALIGN=TOP ALIGN='right'>Payments processed by PayPal. To pay with credit or debit cards<br>without signing up for a PayPal account,<br>"+'look for the "Pay with credit or debit card" link: &#8594;</TD>';
   txtAry[(++numOfLines)]="        <TD VALIGN='bottom'><input type='image' src='images/paypal_cards.jpg' width=246 height=40 border=0 title='Pay with credit or debit cards, without signing up for a PayPal account...' onClick='if(!top.saveFields(this.form,true)){return false;};if(top.confirmBuy()){return true;}else{return false;}'></TD>";
   txtAry[(++numOfLines)]="        <TD VALIGN='TOP'>&nbsp;</TD>";
   txtAry[(++numOfLines)]="      </TR>";

   txtAry[(++numOfLines)]="      <TR>";
   txtAry[(++numOfLines)]="        <TD colspan=7 ALIGN='center'><hr size=1><B>INTERNATIONAL ORDERS:<BR>* You MUST call us (800-638-2897) before placing an international order *</B></TD>";
   txtAry[(++numOfLines)]="      </TR>";
   txtAry[(++numOfLines)]="    </TABLE>";
   txtAry[(++numOfLines)]="  </TD></TR>";
   txtAry[(++numOfLines)]="</TABLE>";
   txtAry[(++numOfLines)]="</FORM>";

}  //--- end of cartFtr()


function showAllItems(txtAry, oldLeft) {
   //alert("showAllItems() called: top.itemCnt="+top.itemCnt.toString()+"...");
   var cart="";
   var txt ="";
   var fltprice=0.000;
   var intqty=0;
   var fltqty=0.00;
   var total=0;
   //---POS update: now name fields from bottom up, but still display from top down

   for (var j = top.itemCnt-1; j>=0; j--) {
     //zero column is part# with no link
     txtAry[(++numOfLines)]="  <TR>";
     txtAry[(++numOfLines)]="    <TD align=left VALIGN=top><INPUT TYPE=TEXT NAME=\'item_number_"+(top.itemCnt-j).toString()+"\' SIZE=10 value=\'"+top.cartItems[j][0]+"\' readonly=true onFocus='top.clickAlert(this);'></TD>";

     //1st column is part description
     txtAry[(++numOfLines)]="    <TD align=left VALIGN=top><INPUT TYPE=TEXT NAME=\'item_name_"+(top.itemCnt-j).toString()+"\' SIZE=50 value=\'"+top.cartItems[j][1]+"\' readonly=true></TD>";


     //The 2nd column is unit price. 
     txtAry[(++numOfLines)]="    <TD align=left><INPUT TYPE=TEXT NAME=\'amount_"+(top.itemCnt-j).toString()+"\' VALUE=\'"+top.cartItems[j][3]+"\' SIZE=6 readonly=true onFocus='top.clickAlert(this);'></TD>";

     //The 3rd column is weight
     txtAry[(++numOfLines)]="    <TD align=left><INPUT TYPE=text NAME=\'weights"+(top.itemCnt-j).toString()+"\' VALUE=\'"+top.cartItems[j][5]+"\' SIZE=6 readonly=true></TD>";

     //The the 4th column is the quantity
     txtAry[(++numOfLines)]="    <TD align=left><INPUT TYPE=text NAME=\'quantity_"+(top.itemCnt-j).toString()+"\' VALUE=\'"+top.cartItems[j][4]+"\' SIZE=3  readonly=true onFocus='top.clickAlert(this);'></TD>";

     //The 5th column is total price,  and The Xth hidden custom field(weight) /or/ and the Xth hidden custom field (qty x $=total)
     fltprice=parseFloat(top.cartItems[j][3]);
     //intqty=parseInt(top.cartItems[j][4]);
     //total=fltprice*intqty;
     fltqty=parseFloat(top.cartItems[j][4]);
     total=fltprice*fltqty;
     var totalstr=formatNum(total,2);
     txtAry[(++numOfLines)]="    <TD align=left><INPUT TYPE=TEXT align='right' NAME=\'t_"+(top.itemCnt-j).toString()+"\' VALUE=\'"+totalstr+"\' SIZE=6 readonly=true onFocus='top.clickAlert(this);'>";
     if (parseFloat(top.cartItems[j][2])<0) {
        //--- is fractional qty
        txtAry[(++numOfLines)]="    <INPUT TYPE='hidden' NAME=\'on0_"+(top.itemCnt-j).toString()+"\' VALUE=\'"+formatNum("1",2)+"\ lbs each'>";
        txtAry[(++numOfLines)]="    <INPUT TYPE='hidden' NAME=\'on1_"+(top.itemCnt-j).toString()+"\' VALUE=\'"+formatNum(top.cartItems[j][4],3)+"\ lbs @ $"+top.cartItems[j][3]+" per lb'>";
     } else {
        //--- std display
        txtAry[(++numOfLines)]="    <INPUT TYPE='hidden' NAME=\'on0_"+(top.itemCnt-j).toString()+"\' VALUE=\'"+formatNum(top.cartItems[j][5],2)+"\ lbs each'>";
        txtAry[(++numOfLines)]="    <INPUT TYPE='hidden' NAME=\'on1_"+(top.itemCnt-j).toString()+"\' VALUE=\'"+''+"\'>";
     }
     txtAry[(++numOfLines)]="    </TD>";

     //The 6th column is delete button
     txtAry[(++numOfLines)]="    <TD align=left><INPUT TYPE='BUTTON' NAME=\'d_"+(top.itemCnt-j).toString()+"\' VALUE='del' onClick='top.delItem(this);'></TD>";
     txtAry[(++numOfLines)]="  </TR>";
  }

  //---now add-in a last pseudo-part: "shipping and handling: 0.00"
     txtAry[(++numOfLines)]="  <TR>";
     txtAry[(++numOfLines)]="    <TD align=left><INPUT TYPE=TEXT NAME=\'item_number_"+(top.itemCnt+1).toString()+"\' SIZE=10 value='SHPCHG' readonly=true onFocus='top.clickAlert(this);'></TD>";

     if (top.upsChg<0) {   //--ship chg not seleted
        txtAry[(++numOfLines)]="    <TD align=left><INPUT TYPE=TEXT NAME=\'item_name_"+(top.itemCnt+1).toString()+"\' SIZE=50 value='Shipping and Handling' readonly=true onFocus='top.clickAlert(this);'></TD>";
        txtAry[(++numOfLines)]="    <TD align=left><INPUT TYPE=TEXT NAME=\'amount_"+(top.itemCnt+1).toString()+"\' VALUE='0.00' SIZE=6 readonly=true onFocus='top.clickAlert(this);'></TD>";
     } else {  
        txtAry[(++numOfLines)]="    <TD align=left><INPUT TYPE=TEXT NAME=\'item_name_"+(top.itemCnt+1).toString()+"\' SIZE=50 value='"+top.shipDoc+"' readonly=true onFocus='top.clickAlert(this);'></TD>";
        txtAry[(++numOfLines)]="    <TD align=left><INPUT TYPE=TEXT NAME=\'amount_"+(top.itemCnt+1).toString()+"\' VALUE='"+top.formatNum(top.shipChg,2)+"' SIZE=6 readonly=true onFocus='top.clickAlert(this);'></TD>";
     }

     txtAry[(++numOfLines)]="    <TD align=left><INPUT TYPE=text NAME=\'weights"+(top.itemCnt+1).toString()+"\' VALUE='1' SIZE=6 readonly=true></TD>";
     txtAry[(++numOfLines)]="    <TD align=left><INPUT TYPE=text NAME=\'quantity_"+(top.itemCnt+1).toString()+"\' VALUE='1' readonly=true SIZE=3></TD>";

     if (top.upsChg<0) {   //--ship chg not seleted
        txtAry[(++numOfLines)]="    <TD align=left><INPUT TYPE=TEXT align='right' NAME=\'t_"+(top.itemCnt+1).toString()+"\' VALUE='0.00' SIZE=6 readonly=true onFocus='top.clickAlert(this);'></TD>";
     } else {  
        txtAry[(++numOfLines)]="    <TD align=left><INPUT TYPE=TEXT align='right' NAME=\'t_"+(top.itemCnt+1).toString()+"\' VALUE='"+top.formatNum(top.shipChg,2)+"' SIZE=6 readonly=true onFocus='top.clickAlert(this);'></TD>";
     }

     if ((top.promoChg>0) && (txtTrim(top.promoCode).length>0)) {   //----- valid promotional code discount entered
        //--- capture promotional code#/desc as hidden fields (for PayPal), if one entered
        txtAry[(++numOfLines)]="    <TD><INPUT TYPE='hidden' NAME=\'on0_"+(top.itemCnt+1).toString()+"\' VALUE=\'PR_"+txtTrim(top.promoCode)+"\'>";
        txtAry[(++numOfLines)]="    <INPUT TYPE='hidden' NAME=\'on1_"+(top.itemCnt+1).toString()+"\' VALUE=\'"+txtTrim(top.promoDesc)+" Discount\'></TD>";
     } else {
        txtAry[(++numOfLines)]="    <TD>&nbsp;</TD>";
     }

     txtAry[(++numOfLines)]="  </TR>";

  //---now add-in a 2nd last pseudo-part - "Special handling fees: 0.00" - if some exist
     var spc_fees=parseFloat(calcSpcFees());
     //alert("top.upsChg="+top.upsChg.toString()+" : spc_fees="+spc_fees.toString()+"...");
     if ((top.upsChg>0) && (spc_fees>0.00)) {   //----- ship $chg selected(not 'pickup'), and some special fees
        txtAry[(++numOfLines)]="  <TR>";
        txtAry[(++numOfLines)]="    <TD><INPUT TYPE=TEXT NAME=\'item_number_"+(top.itemCnt+2).toString()+"\' SIZE=10 value='SPCFEE' readonly=true onFocus='top.clickAlert(this);'></TD>";
        txtAry[(++numOfLines)]="    <TD><INPUT TYPE=TEXT NAME=\'item_name_"+(top.itemCnt+2).toString()+"\' SIZE=50 value='Special Handling Fees' readonly=true onFocus='top.clickAlert(this);'></TD>";
        txtAry[(++numOfLines)]="    <TD><INPUT TYPE=TEXT NAME=\'amount_"+(top.itemCnt+2).toString()+"\' VALUE='"+top.formatNum(spc_fees,2)+"' SIZE=6 readonly=true onFocus='top.clickAlert(this);'></TD>";
        txtAry[(++numOfLines)]="    <TD><INPUT TYPE=text NAME=\'weights"+(top.itemCnt+2).toString()+"\' VALUE='1' SIZE=6 readonly=true></TD>";
        txtAry[(++numOfLines)]="    <TD><INPUT TYPE=text NAME=\'quantity_"+(top.itemCnt+2).toString()+"\' VALUE='1' readonly=true SIZE=3></TD>";
        txtAry[(++numOfLines)]="    <TD><INPUT TYPE=TEXT align='right' NAME=\'t_"+(top.itemCnt+2).toString()+"\' VALUE='"+top.formatNum(spc_fees,2)+"' SIZE=6 readonly=true onFocus='top.clickAlert(this);'></TD>";
        txtAry[(++numOfLines)]="    <TD>&nbsp;</TD>";
        txtAry[(++numOfLines)]="  </TR>";
     }

  //---now add-in a 3rd pseudo-part - "Promotional Code" - if one entered
     if ((top.promoChg>0) && (txtTrim(top.promoCode).length>0)) {   //----- valid promotional code discount entered
        txtAry[(++numOfLines)]="  <TR>";
        txtAry[(++numOfLines)]="    <TD><INPUT TYPE=TEXT NAME=\'"+txtTrim(top.promoCode)+"\' SIZE=10 value='"+txtTrim(top.promoCode)+"\' readonly=true onFocus='top.clickAlert(this);'></TD>";
        txtAry[(++numOfLines)]="    <TD><INPUT TYPE=TEXT NAME=\'"+txtTrim(top.promoCode)+"_desc\' SIZE=50 value='"+txtTrim(top.promoDesc)+" Discount\' readonly=true onFocus='top.clickAlert(this);'></TD>";
        txtAry[(++numOfLines)]="    <TD><INPUT TYPE=TEXT NAME=\'discount_amount_cart\' VALUE='"+formatNum(top.promoChg,2)+"' SIZE=6 readonly=true onFocus='top.clickAlert(this);'></TD>";
        txtAry[(++numOfLines)]="    <TD><INPUT TYPE=text NAME=\'promowgt\' VALUE='0' SIZE=6 readonly=true></TD>";
        txtAry[(++numOfLines)]="    <TD><INPUT TYPE=text NAME=\'promoqty\' VALUE='1' readonly=true SIZE=3></TD>";
        txtAry[(++numOfLines)]="    <TD><INPUT TYPE=TEXT align='right' NAME=\'promoTot\' VALUE='"+formatNum(top.promoChg*-1,2)+"' SIZE=6 readonly=true onFocus='top.clickAlert(this);'></TD>";
        txtAry[(++numOfLines)]="    <TD>&nbsp;</TD>";
        txtAry[(++numOfLines)]="  </TR>";
     }     
}  //--- end of showAllItems()


function addNewItem(itemArray, txtAry){
   //alert("addNewItem()...");
   top.cartItems[top.itemCnt]=new Array();
   top.cartItems[top.itemCnt][0]=itemArray[0];
   top.cartItems[top.itemCnt][1]=itemArray[1];
   top.cartItems[top.itemCnt][2]=itemArray[2];
   top.cartItems[top.itemCnt][3]=itemArray[3];
   top.cartItems[top.itemCnt][4]=itemArray[4];
   top.cartItems[top.itemCnt][5]=itemArray[5];
   //--- increment item count---
   top.itemCnt=top.itemCnt+1;
   var thiscookie=curCookie();
   //---add item to cookie list?---
   if (top.orderstat!=0) {
      addItemCookie(itemArray, thiscookie);
   }
   updCookie();
}  //--- end of addNewItem()


function getCartItem(flag, itemArray, txtArray) {                
        //alert("getCartItem() called: flag="+flag+"...");
        var delFlag=0;

        //cartHdr(top.itemCnt+1, txtArray);
        if ((flag=="addItem") || (flag=="firstItem")) {
           addNewItem(itemArray, txtArray);
        }
        //showAllItems(txtArray,delFlag);
        //cartFtr(txtArray);
}


function writeCartItem(flag, itemArray) {
    numOfLines=0;
    var txtLines = new Array(); 
   
    getCartItem(flag, itemArray, txtLines);
    //writeCart(txtLines);
}


function updQty(lbqty,oqty,prtqty) {
   //alert(lbqty.value);
   prtqty.value=parseFloat(lbqty.value)+parseFloat(oqty.value/16);
   if (prtqty.value<=0.0000) {
       alert("You must specify a positive quantity!...");
       return false;
   }
   //alert(prtqty.value);
   return true;
}


function intQty(prtqty) {
   prtqty.value=parseInt(prtqty.value);
   if (prtqty.value<=0) {
       alert("You must specify a positive integer quantity!...");
       prtqty.value=0;
       return false;
   }
   return true;
}

function isFloatNum(chkNum) {
   //---determine if the passed # is a float or integer
   chkRemain=chkNum-Math.floor(chkNum);
   if (chkRemain>0.00) {
       return true;
   }
   return false;
}

function addpartL(prtnum,prtdesc,prtwgt,unitlist,prtqty,spcfee) {
   //--- max limit of cookie capacity---
   if (top.itemCnt==top.maxItems) {
      alert("You have reached the Order Form's capacity - please submit the selected items as 'Part 1' and continue with a new Form...");
      return;
   }
   // add part - use price list, find selected price volume

   // set temp status=2 - adding part in process
   if (top.orderstat==2) {
      return;
   } else {
      top.orderstat=2;
   }

   var unittext="";
   var cookietxt="";
   var lastcue=-1;
   var pricetxt="100.00";
   var codetxt="";
   var selfound=false;
   var rngtxt="";
   var rngLow=0;
   var rngHi=0;
   var rngcue=0;
   var itmSpcFee=formatNum(parseFloat(spcfee),2);
   var Mcodetxt="";

   var qtyPrt=prtqty.value;

   for (var i=0; i<unitlist.length; i++) {
      unittext=unitlist.options[i].text;
      if ((unitlist.options[i].selected) && (unittext.lastIndexOf('/')>-1)) {
         Mcodetxt=unittext.substring(unittext.lastIndexOf('/')+1,unittext.length);
         break;
      }
   }

   for (var i=0; i<unitlist.length; i++) {
      unittext=unitlist.options[i].text;
      lastcue=unittext.lastIndexOf('@');
      
      if (lastcue==0) { //---only one price presented
         //---if this one selected, or last one and no others selected, take it
         if ((unitlist.options[i].selected) || ((i==unitlist.length-1) && (selfound==false))) {
            if (unitlist.options[i].selected) {
               selfound=true;
            }
            pricetxt=unittext.substring(lastcue+1,unittext.length);
            if (pricetxt.lastIndexOf('/')>-1) { //---parse out price from the any code txt
               codetxt=pricetxt.substring(pricetxt.lastIndexOf('/')+1,pricetxt.length);
               pricetxt=pricetxt.substr(0,pricetxt.lastIndexOf('/'));
            }
         }
      } else {  //---look for price matched to qty
         rngtxt=unittext.substring(0,parseInt(lastcue));
         rngcue=rngtxt.lastIndexOf('-');
         //alert("unittext="+unittext+"...");

         if (rngcue>-1) {
            rngLow=parseInt(rngtxt.substring(0,rngcue));
            if (rngLow==1) rngLow=0;  //--- force 1st range to begin at 0, for lb/oz calculations
            rngHi=parseInt(rngtxt.substring(rngcue+1,rngtxt.length));
            if ((parseFloat(qtyPrt)>=rngLow) && (parseFloat(qtyPrt)<=rngHi)) {
               rawpricetxt=unittext.substring(lastcue+1,unittext.length);
               //alert("within range: rawpricetxt="+rawpricetxt+"...");
               if (rawpricetxt.lastIndexOf('/')>-1) { //---parse out price from any code txt
                  rawcodetxt=rawpricetxt.substring(rawpricetxt.lastIndexOf('/')+1,rawpricetxt.length);
                  //alert("rawcodetxt="+rawcodetxt+"...");
                  if (rawcodetxt==Mcodetxt) {  //--- matches user's optional code selection
                     pricetxt=rawpricetxt.substr(0,rawpricetxt.lastIndexOf('/'));
                     codetxt=rawcodetxt;
                     //alert("rawcodetxt="+rawcodetxt+" : pricetxt="+pricetxt+" : Mcodetxt="+Mcodetxt+" matched...");
                     break;
                  } 
               } else { //--- no optional code available, take this price
                 //alert("pricetxt="+pricetxt+" : no opt cue found...");
                 pricetxt=rawpricetxt;
                 break;
               }
            } else {
              //alert("debug: qty not in range...");
            }  //---qty is in this range, get price
         } else {  //--- for '10+' upper ranges...
            rngcue=rngtxt.lastIndexOf('+');
            if (rngcue>-1) {
              //alert("plus found...");
              rngHi=parseInt(rngtxt.substring(0,rngcue));
              if (parseInt(qtyPrt)>=rngHi) {
                 rawpricetxt=unittext.substring(lastcue+1,unittext.length);
                 //alert("rawpricetxt="+rawpricetxt+"...");
                 if (rawpricetxt.lastIndexOf('/')>-1) { //---parse out price from any code txt
                    rawcodetxt=rawpricetxt.substring(rawpricetxt.lastIndexOf('/')+1,rawpricetxt.length);
                    //alert("rawcodetxt="+rawcodetxt+"...");
                    if (rawcodetxt==Mcodetxt) {   //--- matches user's optional code selection
                       //alert("rawpricetxt="+rawpricetxt+": rawcodetxt="+rawcodetxt+" : Mcodetxt="+Mcodetxt+" + matched...");
                       pricetxt=rawpricetxt.substr(0,rawpricetxt.lastIndexOf('/'));
                       codetxt=rawcodetxt;
                       break;
                    }
                 } else {  //--- no optional code available, take this price                  
                    //alert("pricetxt="+pricetxt+" : no + opt cue found...");
                    pricetxt=rawpricetxt;
                    break;
                 }
              }  //---qty is in this range, get price
            }  //---'+' exists
         }  //---check each price for in range/ last (#+) price range
      } //---end of flat price range / multiple qty discount pricing
   }  //--- chk all options in price selection for in qty range, and matching (optional) code

   if (codetxt.length>0) {  //---append code text to front of description
      prtdesc=codetxt+":"+prtdesc;
   } 

   cookietxt="itm"+(top.itemCnt+1).toString();

   pricetxt=formatNum(parseFloat(pricetxt),2)
   var flag="firstItem";
   itemArray=new Array();
   itemArray[0]=prtnum;
   itemArray[1]=prtdesc.substr(0,44);
   itemArray[2]=itmSpcFee;
   itemArray[3]=pricetxt;
   itemArray[4]=qtyPrt;
   itemArray[5]=formatNum(prtwgt,2);

   if (top.itemCnt==0) {
        //--This is the 1st item in the cart.
     writeCartItem("firstItem", itemArray);
   } else {    
     if (top.itemCnt != 0 ) {
         flag=" ";
         var numItems=top.itemCnt;
         var repeatItem=false;
         for (var i = 0; i < numItems; i++) {
           if  (itemArray[0]==txtTrim(top.cartItems[i][0])) {
             //check if the new item is already in the cart...
             alert("This item is already in your shopping cart! you must delete it and change the quantity, before clicking the [add to cart] button ...");
             repeatItem=true;
           }
         }
         if (!repeatItem) {
            //the newly added item is NOT already in the shopping cart: add it...
            clearShip(false);
            writeCartItem("addItem", itemArray);
         }
     } else {
         alert("error: unable to add this item to your cart...");
     }
   }
   //setFields();
   top.hdrbox.location.reload();
   top.orderstat=1;
} //--- end of addpartL()


function addpartsC(thisCookieStr) {
   //--- add parts recalled from this stored cookie,
   //--- updated for packed cookies - 78 chars per item/up to 3 items per cookie
   //alert("addpartsC().thisCookieStr="+thisCookieStr+"...");
   var thisItem=" ";
   var numNdx=0;
   if ((thisCookieStr.length>0) && (thisCookieStr.length<79)) numNdx=1;
   if ((thisCookieStr.length>79) && (thisCookieStr.length<157)) numNdx=2;
   if (thisCookieStr.length>157) numNdx=3;
   //alert("addpartsC():thisCookieStr.length="+(thisCookieStr.length).toString()+" / numNdx="+numNdx+"...");

   for (var k=1; k<=numNdx; k++) {
       thisItem=thisCookieStr.substring(0,78)
       //alert(thisItem);
       var prtnum=thisItem.substring(0,10);
       var prtdesc=thisItem.substring(10,50);
       var pricetxt=thisItem.substring(50,58);
       var prtqty=thisItem.substring(58,66);
       var prtwgt=thisItem.substring(66,72);
       var itmSpcFee=thisItem.substring(72,78);

       var unittext="itm"+k.toString()
       var qtyPrt=prtqty;

       top.cartItems[top.itemCnt]=new Array();
       top.cartItems[top.itemCnt][0]=prtnum;
       top.cartItems[top.itemCnt][1]=prtdesc;
       top.cartItems[top.itemCnt][2]=itmSpcFee;
       top.cartItems[top.itemCnt][3]=formatNum(pricetxt,2);
       top.cartItems[top.itemCnt][4]=formatNum(qtyPrt,4);
       top.cartItems[top.itemCnt][5]=formatNum(prtwgt,2);
       //--- increment item count---
       top.itemCnt=top.itemCnt+1;
       if (thisCookieStr.length>78) {
          thisCookieStr=thisCookieStr.substring(78,thisCookieStr.length);
       } // --- front trim by 78 chars (one item's data)
   }
} //--- end of addPartsC()


//--total price for each item = unit price*quantity, and weights totals
function totprice(thisPoint, thisForm) {
  var numOfUnits=top.itemCnt;
  var itemNdx=-1;
  var displayRow=-1;
  var qty="";

  if (numOfUnits==0) {
     var txt="Your Order is currently empty...";
     writeCart(txt);
     return false;
  }  // reset  
    
  if (!isValidPosInteger(thisPoint.value)) {
    //invalid qty        
      top.prodbox.focus();       
  } else {  // ---locate this control in the current form...
    for (var i = 1; i <=numOfUnits; i++) {
      if ("quantity_"+i.toString()==thisPoint.name){ 
        itemNdx=top.itemCnt-i;
        displayRow=i;
        i=numOfUnits;
      }
    }

    var partnum=top.cartItems[itemNdx][0];
    var itmSpcFee=top.cartItems[itemNdx][2];
    var price=top.cartItems[itemNdx][3];
    var partwgt=top.cartItems[itemNdx][5];

    price = parseFloat(price);
    partwgt = parseFloat(partwgt);

    qty=thisPoint.value;
    top.cartItems[itemNdx][4]=qty;
    qty= parseFloat(qty);

    var total=price*qty;
    var totalstr=formatNum(total,2);

    var totwgt=partwgt*qty;
    var weightstr=formatNum(totwgt,2);

    var elementLen=thisForm.elements.length;
    var totout=false;

    if (total !=0.00) {
       for (var i=0; i < elementLen; i++) {
          if (thisForm.elements[i].name=="t_"+displayRow.toString()) {
            thisForm.elements[i].value=totalstr;
            totout=true;
          }
          if (totout==true) {
             i=elementLen;
          }
       }
       //--- get cumulative weight total:
       var wgttotal=calcWeight();
       thisForm.orderweight.value=wgttotal;
    
       //--- get cumulative $price total:
       var totalstr=calcTotal();
       thisForm.ordertotal.value=totalstr;

       rewriteCookie(itemNdx+1);
    } else {
      //---remove this one...
       var j=-1;
       for (var i=0; i < elementLen; i++) {
          if (thisForm.elements[i].name=="t_"+displayRow.toString()) {
            j=i;
            i=elementLen;
          }
       }
       if (j>=0) {
          delItem(thisForm.elements[j]);
       } // failsafe
    }
  } 
  //--- reset shipping chgs to zero
  clearShip(true);
  return false;  
}  // end of totprice


//Total=sum of all totprice
function calcTotal() {
   var numOfItemInCart=top.itemCnt;
   var price="";
   var qty="";
   var total=0.00;
   var totalStr="";

   for (var i = 0; i < numOfItemInCart; i++) {
     //sum totprice
     price= top.cartItems[i][3];
     price= parseFloat(price);
     qty= top.cartItems[i][4];
     qty= parseFloat(qty);
     total=total+(price*qty);
   }

   var spc_fees=parseFloat(calcSpcFees());
   if ((spc_fees>0.00) && (top.upsChg>0)) { //--- there are fees, and some +$ship option selected)
     total=total+spc_fees;
   }

   if ((top.promoChg>0.00) && (txtTrim(top.promoCode).length>0)) { //--- there is a valid promotional code entered
     total=total-top.promoChg;
   } //--- subtract promotional code discount

   totalstr=formatNum(total,2);
   //alert("totalstr="+totalstr+"...");
   return totalstr;
}


//Total=sum of all weights
function calcWeight() {
   var numOfItemInCart=top.itemCnt;
   var wgt="";
   var qty="";
   var totalwgt=0.00;
   //---track/split shpmt weights over the max
   top.totwgt1=0;
   top.totwgt2=0;
   var wgtSplit=false;
   var halfwgt=0;
   var firsthalf=0;
   var otherhalf=0;
   var spillover=false;
   var spillqty=0;

   var weightStr="";

   for (var i = 0; i < numOfItemInCart; i++) {
     //sum totprice
     qty= top.cartItems[i][4];
     qty= parseFloat(qty);
     wgt= top.cartItems[i][5];
     //alert("item wgt="+wgt+" / qty="+qty+"...")
     wgt= parseFloat(wgt);

     if ((totalwgt+(wgt*qty)) > top.maxWgt) {      
        wgtSplit=true;
     }
     totalwgt=totalwgt+(wgt*qty);
   }

   totalwgt=Math.ceil(totalwgt);

   if (wgtSplit) {
      halfwgt=Math.ceil((totalwgt/2));
      for (var i = 0; i < numOfItemInCart; i++) {
        qty= top.cartItems[i][4];
        qty= parseFloat(qty);
        wgt= top.cartItems[i][5];
        wgt= parseFloat(wgt);
        //firsthalf=firsthalf+(wgt*qty);
        //if (firsthalf>halfwgt) {
        if (firsthalf+(wgt*qty) <= halfwgt) {
           firsthalf=firsthalf+(wgt*qty);
        } else {
           //---if still in 1st half:
           if (!spillover) {
              //--- look within this line item for the wgt split point:
              if ((firsthalf+wgt) <= halfwgt) {
                 //---isolate spillover pt---
                 spillqty=1;
                 while ((firsthalf+(wgt*spillqty) <= halfwgt) && (spillqty < qty)) {               
                    spillqty++;   
                 }
                 firsthalf=firsthalf+(wgt * (spillqty-1));
                 otherhalf=wgt * (qty-(spillqty-1));
              } else {
                 //---failsafe: all on the 2nd half:
                 otherhalf=wgt * qty;
              }  
              spillover=true;
           } else { 
              otherhalf=otherhalf+(wgt*qty);
           } // --- first time across the threshold
        } //---still in 1st half
      } //---re-parse the weights, looking for ~ even split
      top.totwgt1=formatNum(firsthalf,0);
      top.totwgt2=formatNum(otherhalf,0);
   } else {
      top.totwgt1=formatNum(totalwgt,0);
      top.totwgt2="0";
   } //---need to calc split for wgts

   if (totalwgt<1.000) {
      totalwgt=1.000;
      top.totwgt1=1.000;
   } //---force minimum 1.0 lb ship chg

   weightstr=formatNum(totalwgt,0);
   //alert("weightstr="+weightstr+"/ 1sthalf="+top.totwgt1+" : 2ndhalf="+top.totwgt2+"...");
   return weightstr;
}


function delItem(thisItem) { 
  if (top.orderstat==2) {
     return;  //---don't interrupt active state
  } else {
    top.orderstat=2;
  }
  var numOfUnits=top.itemCnt;
  var delFlag=1;

  if (numOfUnits==0) {
     var txt="Your Order is currently empty...";
     writeCart(txt);
     top.orderstat=1;
     return false;
  }  // reset  

  var j=-1;
  var qty="";
  for (var i = 1; i <=numOfUnits; i++) {
    //alert("delItem: d_"+i.toString()+": thisItem.name="+thisItem.name+"...");
    if (("t_"+i.toString()==thisItem.name) || ("d_"+i.toString()==thisItem.name)) { 
      j=numOfUnits-i;
      i=numOfUnits;
    }
  }
  
  if (j>=0) {
     var remove=top.cartItems.splice(j,1);
     top.itemCnt=top.itemCnt-1;

     var itemArray=new Array();
     var curIdx=0;
     var firstIdx=j;
     var curCkie=itemCookie(j+1); 
     //alert("delItem()curCkie="+curCkie+"...");
     var thisCkie=parseInt(curCkie.substring(1,curCkie.length));
     if (curCkie.substring(0,1)=="A") firstIdx=j;
     if (curCkie.substring(0,1)=="B") firstIdx=j-1;
     if (curCkie.substring(0,1)=="C") firstIdx=j-2;
     DeleteCookie("itm"+thisCkie.toString());  
     //alert("delItem()thisCkie="+thisCkie.toString()+"/ firstIdx="+firstIdx.toString()+"...");
     //--- rewrite out all cookies after deletion pt.
     for (var i = firstIdx; i<top.itemCnt; i++) {
       rewriteCookie(i+1);
       i=i+2;
     }

     updCookie();

     numOfLines=0;
     var txtLines = new Array(); 

     clearShip(true);
     top.orderstat=1;
     top.prodbox.document.cartForm.lblstatus.value="PLEASE WAIT...";
     if (top.itemCnt==0) clearItems();

     top.hdrbox.location="http://www.fhsteinbart.com/products/FHS_header.php";
     top.prodbox.location="http://www.fhsteinbart.com/products/fhs_cart.php";

     //cartHdr(top.itemCnt,txtLines);
     //showAllItems(txtLines,delFlag);
     //cartFtr(txtLines);
     //writeCart(txtLines);
     //if (top.itemCnt>0) clearShip();
     //setFields();
     //top.orderstat=1;
     //top.hdrbox.location.reload();
     //if (top.itemCnt==0) clearItems();
  } //  failsafe: match found
}  //--- end of DelItem()


function reDisplay(index,subindex) {
      //--debug
      top.prodhead.document.catalog.catagory.selectedIndex=index;
      top.prodhead.showSubList();
      top.prodhead.document.catalog.subcat.selectedIndex=subindex;
}


function clearItems() {
  if (top.orderstat==2) {
     return;
  } else {
     top.orderstat=2;
     //! -- updated for packed cookies
     //---clear, and remake all item cookies
     var cookieCnt=curCookie();
     //alert("clearItems()cookie cnt:"+cookieCnt+"...");
     for (var i = 1; i <=top.ckieCnt; i++) {
       DeleteCookie("itm"+i.toString());
     }
     top.itemCnt=0;
     top.ckieCnt=0;
     top.ckieNdx=0;

     top.cartItems = new Array();
     top.location="http://www.fhsteinbart.com/products/index.php";
     var expdate = new Date ();
     FixCookieDate (expdate); // Correct for Mac date bug - call only once for given Date object!
     expdate.setTime (expdate.getTime() + (90 * 24 * 60 * 60 * 1000)); // 90 days from now   
     //SetCookie ("user", "0@"+top.userLast, expdate);
     SetCookie ("user", "0!0#0@"+top.userFirst+" "+top.userLast, expdate);
     top.orderstat=1;
  }
}  //--- end of clearItems()


function steinInfo(htmlName) {
   infoWin=open(htmlName, "steinInfoWin", "menubar=no,resizable=yes,toolbar=yes,scrollbars=yes,height=400,width=400");
   infoWin.focus();
}


function copyrightyr() {
     brsrType=navigator.appName;
     brsrMSIE=(navigator.appName == "Microsoft Internet Explorer");
     brsrNS=(navigator.appName == "Netscape");
     var timestamp=document.lastModified;
     var timesecs=Date.parse(timestamp)
     var datetime=new Date();
     datetime.setTime(timesecs);
     if (brsrMSIE) {
        document.write(datetime.getYear());     
     } else {
        document.write(datetime.getYear()+1900);
     }
}  // end of copyrightyr()


function showMainUL(ulid) {
   if (ulid=="") return;
   var obj= document.getElementById(ulid);   

   if (obj.style.visibility != "visible") {
      obj.style.visibility = "visible";
      lastUL=ulid;
      lastLI="products";
   }
}


function hideMainUL(e,ulid) {
   if (ulid=="") return;
   var obj= document.getElementById(ulid);
   if (!e) var e = window.event;
   if (e==undefined) return;

   var tg = (window.event) ? e.srcElement : e.target;
   //if (ulid=="products" && lastLI=="products") {
   if (ulid=="products") {
      //var lastobj= document.getElementById(top.lastUL);
      //if (lastobj!=null) lastobj.style.visibility = "hidden";
      obj.style.visibility = "hidden";
      return;  
   } //---bailing out on top
}


function showUL(e,ulid) {
   if (ulid=="") return;
   top.ulObj = document.getElementById(ulid);
   top.timerUL=ulid;

   if (top.ulObj.style.visibility != "visible") {
      setTimeout("dispUL(top.ulObj,top.timerUL)",450);
   }
}

function dispUL(dispObj,dispUL) {
    dispObj.style.visibility = "visible";
    top.lastUL=dispUL;
}


function callHideLastUL(e,ulCalled) {
   if (ulCalled=="") return;
   top.lastE=e;
   top.calledUL=ulCalled;

   top.timerID=setTimeout("hideLastUL(top.lastE)",400);
}

function hideLastUL(e) {
   if (top.lastUL=="") return;
   lastLI="";   
   var lastObj= document.getElementById(top.lastUL);
   if (lastObj==null) return;

   if (!e) var e = window.event;

   if (e!=undefined) {
      var tg = (window.event) ? e.srcElement : e.target;
      if (tg.nodeName != "A") return;
      var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
      while (reltg.nodeName != "A" && reltg.nodeName != 'BODY') {           
        reltg= reltg.parentNode;     
        if (reltg.nodeName=="UL" && reltg==lastObj) {
           return;
        } // if this is an anchor in the same UL as the last opened, don't hide
      } // stop mouseout event if triggered by last opened UL

      if (reltg.nodeName=="A") {
         var parenttg=reltg.parentNode;
         while ((parenttg.nodeName != "UL") && (reltg.nodeName != 'BODY')) {           
            parenttg= parenttg.parentNode;
            if ((parenttg.nodeName=="UL") && (parenttg==lastObj)) {
               return;
            } // if this is an Anchor in the same UL as the last opened, don't hide
         } //---chk for anchor in the last opened UL
      }
   }   
   if (top.calledUL==top.lastUL) {
     return;
   }  // don't hide caller's own UL
 
   // Mouseout took place when mouse actually left one anchor, and entered another
   if (lastObj.style.visibility == "visible") {
      lastObj.style.visibility = "hidden";
   }
}


function hideUL(e,ulid) {
   if (ulid=="") return;
   var obj= document.getElementById(ulid);
   if (!e) var e = window.event;

   //if (e!=undefined) {
      var tg = (window.event) ? e.srcElement : e.target;
      if (ulid=="products" && lastLI=="products") {
         obj.style.visibility = "hidden";
         return;  
      } //---bailing out on top

      if (tg.nodeName != "UL") return;
      var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
      while (reltg != tg && reltg.nodeName != 'BODY')
         reltg= reltg.parentNode
      if (reltg== tg) return;
   //}

   // Mouseout took place when mouse actually left UL
   if (obj.style.visibility == "visible") {
      obj.style.visibility = "hidden";
   }
}



function steinImg(imgurl) {
   window.open(imgurl, imgurl, 'menubar=no,directories=no,location=no,resizable=yes,toolbar=no,scrollbars=yes,status=no,width=600,height=400');
}

function validState(vform) {  //--- process status selection
   vform.state.value=vform.getState.value;
}



function showStates(txtAry) {
   txtAry[(++numOfLines)]='         <select name="getState" id="getState" tabindex=6 onChange="javascript:top.validState(this.form);" onBlur="top.saveFields(this.form,false);top.clearShip(true);">';
   txtAry[(++numOfLines)]='          <option value="Select a State" selected="selected" >Select a State</option>';
   txtAry[(++numOfLines)]='          <option value="AB"  >Alberta</option>';

   txtAry[(++numOfLines)]='          <option value="AK"  >Alaska</option>';
   txtAry[(++numOfLines)]='          <option value="AL"  >Alabama</option>';
   txtAry[(++numOfLines)]='          <option value="AR"  >Arkansas</option>';
   txtAry[(++numOfLines)]='          <option value="AZ"  >Arizona</option>';
   txtAry[(++numOfLines)]='          <option value="BC"  >British Columbia</option>';
   txtAry[(++numOfLines)]='          <option value="CA"  >California</option>';

   txtAry[(++numOfLines)]='          <option value="CO"  >Colorado</option>';
   txtAry[(++numOfLines)]='          <option value="CT"  >Connecticut</option>';
   txtAry[(++numOfLines)]='          <option value="DC"  >District of Columbia</option>';
   txtAry[(++numOfLines)]='          <option value="DE"  >Deleware</option>';
   txtAry[(++numOfLines)]='          <option value="FL"  >Florida</option>';
   txtAry[(++numOfLines)]='          <option value="GA"  >Georgia</option>';

   txtAry[(++numOfLines)]='          <option value="HI"  >Hawaii</option>';
   txtAry[(++numOfLines)]='          <option value="IA"  >Iowa</option>';
   txtAry[(++numOfLines)]='          <option value="ID"  >Idaho</option>';
   txtAry[(++numOfLines)]='          <option value="IL"  >Illinois</option>';
   txtAry[(++numOfLines)]='          <option value="IN"  >Indiana</option>';
   txtAry[(++numOfLines)]='          <option value="KS"  >Kansas</option>';

   txtAry[(++numOfLines)]='          <option value="KY"  >Kentucky</option>';
   txtAry[(++numOfLines)]='          <option value="LA"  >Louisiana</option>';
   txtAry[(++numOfLines)]='          <option value="MA"  >Massachusetts</option>';
   txtAry[(++numOfLines)]='          <option value="MB"  >Manitoba</option>';
   txtAry[(++numOfLines)]='          <option value="MD"  >Maryland</option>';
   txtAry[(++numOfLines)]='          <option value="ME"  >Maine</option>';

   txtAry[(++numOfLines)]='          <option value="MI"  >Michigan</option>';
   txtAry[(++numOfLines)]='          <option value="MN"  >Minnesota</option>';
   txtAry[(++numOfLines)]='          <option value="MO"  >Missouri</option>';
   txtAry[(++numOfLines)]='          <option value="MS"  >Mississippi</option>';
   txtAry[(++numOfLines)]='          <option value="MT"  >Montana</option>';
   txtAry[(++numOfLines)]='          <option value="NB"  >New Brunswick</option>';

   txtAry[(++numOfLines)]='          <option value="NC"  >North Carolina</option>';
   txtAry[(++numOfLines)]='          <option value="ND"  >North Dakota</option>';
   txtAry[(++numOfLines)]='          <option value="NE"  >Nebraska</option>';
   txtAry[(++numOfLines)]='          <option value="NH"  >New Hampshire</option>';
   txtAry[(++numOfLines)]='          <option value="NJ"  >New Jersey</option>';
   txtAry[(++numOfLines)]='          <option value="NF"  >Newfoundland/Labrador</option>';

   txtAry[(++numOfLines)]='          <option value="NM"  >New Mexico</option>';
   txtAry[(++numOfLines)]='          <option value="NS"  >Nova Scotia</option>';
   txtAry[(++numOfLines)]='          <option value="NT"  >Nunavut Territory</option>';
   txtAry[(++numOfLines)]='          <option value="NV"  >Nevada</option>';
   txtAry[(++numOfLines)]='          <option value="NY"  >New York</option>';
   txtAry[(++numOfLines)]='          <option value="OH"  >Ohio</option>';

   txtAry[(++numOfLines)]='          <option value="OK"  >Oklahoma</option>';
   txtAry[(++numOfLines)]='          <option value="ON"  >Ontario</option>';
   txtAry[(++numOfLines)]='          <option value="OR"  >Oregon</option>';
   txtAry[(++numOfLines)]='          <option value="PA"  >Pennsylvania</option>';
   txtAry[(++numOfLines)]='          <option value="PE"  >Prince Edward Island</option>';
   txtAry[(++numOfLines)]='          <option value="QC"  >Quebec</option>';

   txtAry[(++numOfLines)]='          <option value="RI"  >Rhode Island</option>';
   txtAry[(++numOfLines)]='          <option value="SC"  >South Carolina</option>';
   txtAry[(++numOfLines)]='          <option value="SD"  >South Dakota</option>';
   txtAry[(++numOfLines)]='          <option value="SK"  >Saskatchewan</option>';
   txtAry[(++numOfLines)]='          <option value="TN"  >Tennessee</option>';
   txtAry[(++numOfLines)]='          <option value="TX"  >Texas</option>';

   txtAry[(++numOfLines)]='          <option value="UT"  >Utah</option>';
   txtAry[(++numOfLines)]='          <option value="VA"  >Virginia</option>';
   txtAry[(++numOfLines)]='          <option value="VT"  >Vermont</option>';
   txtAry[(++numOfLines)]='          <option value="WA"  >Washington</option>';
   txtAry[(++numOfLines)]='          <option value="WI"  >Wisconsin</option>';
   txtAry[(++numOfLines)]='          <option value="WV"  >West Virginia</option>';

   txtAry[(++numOfLines)]='          <option value="WY"  >Wyoming</option>';
   txtAry[(++numOfLines)]='          <option value="YT"  >Yukon Territory</option>';
   txtAry[(++numOfLines)]='         </select>';
   return;
}


//------contractable drop down layering------------------------------
/***********************************************
* Contractible Headers script- © Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for legal use. Last updated Mar 23rd, 2004.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

function getElementbyClass(classname){
ccollect=new Array()
var inc=0
var alltags=document.all? document.all : document.getElementsByTagName("*")
for (i=0; i<alltags.length; i++){
if (alltags[i].className==classname)
ccollect[inc++]=alltags[i]
}
}

function contractcontent(omit){
var inc=0
while (ccollect[inc]){
if (ccollect[inc].id!=omit)
ccollect[inc].style.display="none"
inc++
}
}

function expandcontent(cid){
if (typeof ccollect!="undefined"){
if (collapseprevious=="yes")
contractcontent(cid)
document.getElementById(cid).style.display=(document.getElementById(cid).style.display!="block")? "block" : "none"
}
}

function revivecontent(){
contractcontent("omitnothing")
selectedItem=getselectedItem()
selectedComponents=selectedItem.split("|")
for (i=0; i<selectedComponents.length-1; i++)
document.getElementById(selectedComponents[i]).style.display="block"
}

function get_cookie(Name) { 
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) { 
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}

function getselectedItem(){
if (get_cookie(window.location.pathname) != ""){
selectedItem=get_cookie(window.location.pathname)
return selectedItem
}
else
return ""
}

function saveswitchstate(){
var inc=0, selectedItem=""
while (ccollect[inc]){
if (ccollect[inc].style.display=="block")
selectedItem+=ccollect[inc].id+"|"
inc++
}

document.cookie=window.location.pathname+"="+selectedItem
}

function do_onload(){
uniqueidn=window.location.pathname+"firsttimeload"
getElementbyClass("switchcontent")
if (enablepersist=="on" && typeof ccollect!="undefined"){
document.cookie=(get_cookie(uniqueidn)=="")? uniqueidn+"=1" : uniqueidn+"=0" 
firsttimeload=(get_cookie(uniqueidn)==1)? 1 : 0 //check if this is 1st page load
if (!firsttimeload)
revivecontent()
}
}


function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp('(^|\\\\s)'+searchClass+'(\\\\s|$)');
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}


function showOptions(partNo,partDesc) {
  FHSwin=window.open("http://www.fhsteinbart.com/phpapps/fhs_showoptions.php?partno="+partNo+"&partdesc="+partDesc, "FHSinfoWin", "dependent=yes,menubar=no,resizable=yes,toolbar=yes,scrollbars=yes,height=400,width=400");
  FHSwin.focus();
}


function showPromos() {
  FHSwin=window.open("http://www.fhsteinbart.com/phpapps/fhs_showpromos.php", "FHSinfoWin", "dependent=yes,menubar=no,resizable=yes,toolbar=yes,scrollbars=yes,height=400,width=400");
  FHSwin.focus();
}

