var discnt = 0;   // no default percent discount
        var freeShipping = false;   // no default percent discount
        
        // http://www.easycalculation.com/ascii-hex.php
        
        var freeShipCodes = new Array (  // place to put free shipping codes
          "66 69 66 69 80 65 76 85 90 90 65", //uppercase
          "98 101 98 101 112 97 108 117 122 122 97 ", //lowercase
                     
          "66 73 71 67 73 84 89 77 79 77 83", 
          "98 105 103 99 105 116 121 109 111 109 115", 

           "78 83 87 79 66 71 89 78",
           "110 115 119 111 98 103 121 110",

           "78 87 72 79 66 71 89 78",
           "110 119 104 111 98 103 121 110",  
          
           "115 112 114 111 117 116 102 105 116",
           "83 80 82 79 85 84 70 73 84",

          "77 85 83 84 83 72 79 80",
          "109 117 115 116 115 104 111 112",

          "82 69 80 69 65 84",
          "114 101 112 101 97 116",

          "70 82 69 69 83 72 73 80",
          "102 114 101 101 115 104 105 112",
               
          "66 85 77 80 67 76 85 66",
          "98 117 109 112 99 108 117 98"

        );
        
        var coupons = new Array (  // place to put coupon codes
          "",                 // 1st coupon value - comma seperated
          "",                 // 2nd coupon value - add all you want
          "",                  // 3rd coupon value
          "",
          ""
        );
        
        var coupdc  = new Array (  // place to put discounts for coupon vals
          0,
          0,
          0,
          0,
          0
        );
        
        var codeval = ""; // what user entered as coupon code
        var discnt = 0;              // assume the worst
        
        function ascii_value (str)
        {
          var res = '';
          for (i=0;i < str.length; i++) {
              res += str.charCodeAt(i) + ' ';
          }
          res = res.substr(0, res.length - 1);
          return res;
        }


        function ChkCoup (obj1) {      // check user coupon entry
          var i;
          codeval=obj1.coupcode.value;
          if (codeval == '') {
            alert ("Please enter a coupon code before clicking the 'Apply' button.");
            return;  
          }
          for (i=0; i<coupons.length; i++) {
            if (ascii_value(codeval) == coupons[i]) {
              discnt = coupdc[i];  // remember the discount amt
              alert ("Valid coupon number! \n\n" + discnt + "% discount now in effect.");
              return;
            }
          }
          for (i=0; i<freeShipCodes.length; i++) {      
            if (ascii_value(codeval) == freeShipCodes[i]) {
              freeShipping = true;
              alert ("Valid coupon number! \n\n" +  "Free shipping is now in effect!");
              return;   
            }  
          }  
          alert ("Sorry. '" + codeval + "'  is not a valid code!");
        }
        
        function Dollar (val) {      // force to valid dollar amount
          var str,pos,rnd=0;
          if (val < .995) rnd = 1;  // for old Netscape browsers
          str = escape (val*1.0 + 0.005001 + rnd);  // float, round, escape
          pos = str.indexOf (".");
          if (pos > 0) str = str.substring (rnd, pos + 3);
          return str;
        }
        
        function ReadForm (obj1) {  // apply the discount
          var amt,des;
          amt = obj1.baseamt.value*1.0;       // base amount
          des = obj1.basedes.value;           // base description
          
          if (discnt > 0) {                   // only if discount is active
            amt = Dollar (amt - (amt * discnt/100.0));
            des = des + " [" + discnt + "% off]";
            obj1.amount.value = Dollar (amt);
          }
          if (freeShipping == true){
              var shippingElem = document.createElement("input"); 
              shippingElem.type = "hidden";
              shippingElem.value = "0";
              shippingElem.id = "shipping";
              shippingElem.name = "shipping";
              document.getElementById('FormElemHolder').appendChild(shippingElem);
              des = des + " [Free Shipping]";
              //document.getElementById('basedes').value += " [Free Shipping]";
          }
         obj1.item_name.value = des;
        }
