
   // Set the order ID
   function setOID() {
      d = new Date;
      s = d.getTime().toString();
      document.orderForm.oid.value = s.substring(s.length-6,s.length);
   }

   // This function runs anytime anyone changes any quantity on the form
   // It also runs when someone changes the total box, so that noone can
   // monkey with it.
   function changeTotal() {

      // Declare and clear variables
      var count    = 0;
      var total    = 0;
      var subtotal = 0;
      var shipping = 0;
      var tax      = 0;
	  
	    // Fix incorrect quantity value for Bernadette
      var tshirtS = parseInt(document.orderForm.tshirtS.value);
      if (tshirtS > 0) {
         // good, we have a positive integer value.  let's reset 
         // the field value in case parseInt cleared off any junk
         document.orderForm.tshirtS.value = tshirtS;
      } else {
         // anything else we clear out to zero
         document.orderForm.tshirtS.value = 0;
         tshirtS = 0;
      }
	    var tshirtM = parseInt(document.orderForm.tshirtM.value);
      if (tshirtM > 0) {
         // good, we have a positive integer value.  let's reset 
         // the field value in case parseInt cleared off any junk
         document.orderForm.tshirtM.value = tshirtM;
      } else {
         // anything else we clear out to zero
         document.orderForm.tshirtM.value = 0;
         tshirtM = 0;
      }
	    var tshirtL = parseInt(document.orderForm.tshirtL.value);
      if (tshirtL > 0) {
         // good, we have a positive integer value.  let's reset 
         // the field value in case parseInt cleared off any junk
         document.orderForm.tshirtL.value = tshirtL;
      } else {
         // anything else we clear out to zero
         document.orderForm.tshirtL.value = 0;
         tshirtL = 0;
      }
	  
	    var tshirtXL = parseInt(document.orderForm.tshirtXL.value);
      if (tshirtXL > 0) {
         // good, we have a positive integer value.  let's reset 
         // the field value in case parseInt cleared off any junk
         document.orderForm.tshirtXL.value = tshirtXL;
      } else {
         // anything else we clear out to zero
         document.orderForm.tshirtXL.value = 0;
         tshirtXL = 0;
      }
	  
	   // Fix incorrect quantity value for Bernadette
      var judah = parseInt(document.orderForm.judahQty.value);
      if (judah > 0) {
         // good, we have a positive integer value.  let's reset 
         // the field value in case parseInt cleared off any junk
         document.orderForm.judahQty.value = judah;
      } else {
         // anything else we clear out to zero
         document.orderForm.judahQty.value = 0;
         judah = 0;
      }
	  
	  
	   // Fix incorrect quantity value for Bernadette
      var bern = parseInt(document.orderForm.bernQty.value);
      if (bern > 0) {
         // good, we have a positive integer value.  let's reset 
         // the field value in case parseInt cleared off any junk
         document.orderForm.bernQty.value = bern;
      } else {
         // anything else we clear out to zero
         document.orderForm.bernQty.value = 0;
         bern = 0;
      }
	  

      // Fix incorrect quantity value for Amen
      var amen = parseInt(document.orderForm.amenQty.value);
      if (amen > 0) {
         // good, we have a positive integer value.  let's reset 
         // the field value in case parseInt cleared off any junk
         document.orderForm.amenQty.value = amen;
      } else {
         // anything else we clear out to zero
         document.orderForm.amenQty.value = 0;
         amen = 0;
      }

      // ... and fix incorrect quantity value for Child
      var child = parseInt(document.orderForm.childQty.value);
      if (child > 0) {
         document.orderForm.childQty.value = child;
      } else {
         document.orderForm.childQty.value = 0;
         child = 0;
      }

      // ... and fix incorrect quantity value for Grace
      var grace = parseInt(document.orderForm.graceQty.value);
      if (grace > 0) {
         document.orderForm.graceQty.value = grace;
      } else {
         document.orderForm.graceQty.value = 0;
         grace = 0;
      }

      // ... and fix incorrect quantity value for Sacred
      var sacred = parseInt(document.orderForm.sacredQty.value);
      if (sacred > 0) {
         document.orderForm.sacredQty.value = sacred;
      } else {
         document.orderForm.sacredQty.value = 0;
         sacred = 0;
      }

      // add up the total quantity
      count1 = judah + amen + child + grace + sacred;
	  count2 = bern;
	  count3 = tshirtS + tshirtM + tshirtL + tshirtXL;
	  count = bern + judah + amen + child + grace + sacred + tshirtS + tshirtM + tshirtL + tshirtXL;

      // $14.95 per CD
      subtotal1 = count1 * 14.95;
	  subtotal2 = count2 * 11.95;
	  subtotal3 = count3 * 17.95;
	  taxable = subtotal1 + subtotal2;
	  nontaxable = subtotal3;
	  subtotal = subtotal1 + subtotal2 + subtotal3;

      // Calculate for Shipping
      // 1-CD would be $1.50, 2- CDs would be $2.50,
      // 3-CDs would be $3.00, 4-CD's or more and the shipping is free.
		if (subtotal <= 20) {
			shipping = 0;
		} else if (subtotal <= 35) {
			shipping = 0;
		} else if (subtotal <= 49) {
			shipping  = 0;
		} else if (subtotal <= 59) {
		 	shipping = 0;	 
		} else if (subtotal >= 59.01) {
		 	shipping = 0;
		}

      if (document.orderForm.bstate.value == 'PA') {
         if (document.orderForm.tax.value) {
            oldtax = document.orderForm.tax.value;
         } else {
            oldtax = 0;
         }

         tax = taxable * 0.06;
         total = subtotal + shipping + tax;

         if (oldtax != dollarFormat(tax)) {
            alert ("6% Sales Tax is applied to residents of Pennsylvania.\r\n" +
                   "Your Tax is: $" + dollarFormat(tax) + "\r\n" +
                   "Your new Total is:  $" + dollarFormat(total)); 
         }
      } else {
         total = subtotal + shipping;
      }
      
      // and set the total
      document.orderForm.chargetotal.value = dollarFormat(total);
      document.orderForm.subtotal.value    = dollarFormat(subtotal);
      document.orderForm.shipping.value    = dollarFormat(shipping);
      document.orderForm.tax.value         = dollarFormat(tax);

      return(true);
   }

   function dollarFormat(value) {
      if (Math.ceil(value) == 0) {
         return "0.00";
      } else {
         var Fixed = '';
         value = Math.round(value*100).toString();
         if (value.length <= 2) {
            Fixed += '0' + '.';
         } else {
            Fixed += value.substring(0,value.length-2) + '.';
         }

         if (value.length == 1) {
            Fixed += '0';
         }

         Fixed += value.substring(value.length-2,value.length);
         return Fixed;
      }
   }

   function checkFields () {
      changeTotal();

      if (document.orderForm.chargetotal.value == 0) {
         alert ("Please enter a quantity for an Album.");
         document.orderForm.amenQty.focus();
         return(false);
      }

      if (document.orderForm.bname.value.length == 0) {
         alert ("Please enter a Billing Name.");
         document.orderForm.bname.focus();
         return(false);
      }

      if (document.orderForm.email.value.length == 0) {
         alert ("Please enter a Billing Email Address.");
         document.orderForm.email.focus();
         return(false);
      }

      if (document.orderForm.baddr1.value.length == 0) {
         alert ("Please enter a Billing Street Address.");
         document.orderForm.baddr1.focus();
         return(false);
      }

      if (document.orderForm.bcity.value.length == 0) {
         alert ("Please enter a Billing City.");
         document.orderForm.bcity.focus();
         return(false);
      }

      if (document.orderForm.bstate.value.length == 0) {
         alert ("Please enter a Billing State.");
         document.orderForm.bstate.focus();
         return(false);
      }

      if (document.orderForm.bzip.value.length == 0) {
         alert ("Please enter a Billing Zip Code.");
         document.orderForm.bzip.focus();
         return(false);
      }

      if (document.orderForm.phone.value.length == 0) {
         alert ("Please enter your Phone Number.");
         document.orderForm.phone.focus();
         return(false);
      }

      if (document.orderForm.cardnumber.value.length == 0) {
         alert ("Please enter a Credit Card Number.");
         document.orderForm.cardnumber.focus();
         return(false);
      }

      if (document.orderForm.cctype.selectedIndex == 0) {
         alert ("Please enter a Credit Card Type.");
         document.orderForm.cctype.focus();
         return(false);
      }

      if (document.orderForm.expmonth.selectedIndex == 0) {
         alert ("Please enter a Credit Card Expiration Month.");
         document.orderForm.expmonth.focus();
         return(false);
      }

      if (document.orderForm.expyear.selectedIndex == 0) {
         alert ("Please enter a Credit Card Expiration Year.");
         document.orderForm.expyear.focus();
         return(false);
      }

      if (document.orderForm.sname.value.length == 0) {
         alert ("Please enter a Shipping Name.");
         document.orderForm.sname.focus();
         return(false);
      }

      if (document.orderForm.semail.value.length == 0) {
         alert ("Please enter a Shipping Email Address.");
         document.orderForm.semail.focus();
         return(false);
      }

      if (document.orderForm.saddr1.value.length == 0) {
         alert ("Please enter a Shipping Street Address.");
         document.orderForm.saddr1.focus();
         return(false);
      }

      if (document.orderForm.scity.value.length == 0) {
         alert ("Please enter a Shipping City.");
         document.orderForm.scity.focus();
         return(false);
      }

      if (document.orderForm.sstate.value.length == 0) {
         alert ("Please enter a Shipping State.");
         document.orderForm.sstate.focus();
         return(false);
      }

      if (document.orderForm.szip.value.length == 0) {
         alert ("Please enter a Shipping Zip Code.");
         document.orderForm.szip.focus();
         return(false);
      }

      if (document.getElementById('SummarySpace').style.display == 'none') {
         var text = "" +
                  "<table name='SummaryTable' id='SummaryTable'>" +
                  "<tr><td>" +
                    "<table name='SummaryBillingTable' id='SummaryBillingTable' cellspacing=1 cellpadding=1>" +

                    "<tr><td colspan=2>" +
                    "<strong>Billing Address:</strong>" +
                    "</td></tr>" +

                    "<tr><td>" +
                    "Street Address:" +
                    "</td><td>" +
                    document.orderForm.baddr1.value +
                    " " +
                    document.orderForm.baddr2.value +
                    "</td></tr>" +

                    "<tr><td>" +
                    "City:" +
                    "</td><td>" +
                    document.orderForm.bcity.value +
                    "</td></tr>" +

                    "<tr><td>" +
                    "State:" +
                    "</td><td>" +
                    document.orderForm.bstate.value +
                    "</td></tr>" +

                    "<tr><td>" +
                    "Zip Code:" +
                    "</td><td>" +
                    document.orderForm.bzip.value +
                    "</td></tr>" +

                    "<tr><td>" +
                    "Country:" +
                    "</td><td>" +
                    document.orderForm.bcountry.value +
                    "</td></tr>" +

                    "</table>" +
                  "</td></tr>" +
                  "<tr><td>" +
                    "<table name='SummaryShippingTable' id='SummaryShippingTable' cellspacing=1 cellpadding=1>" +

                    "<tr><td colspan=2>" +
                    "<strong>Shipping Address:</strong>" +
                    "</td></tr>" +

                    "<tr><td>" +
                    "Street Address:" +
                    "</td><td>" +
                    document.orderForm.saddr1.value +
                    " " +
                    document.orderForm.saddr2.value +
                    "</td></tr>" +

                    "<tr><td>" +
                    "City:" +
                    "</td><td>" +
                    document.orderForm.scity.value +
                    "</td></tr>" +

                    "<tr><td>" +
                    "State:" +
                    "</td><td>" +
                    document.orderForm.sstate.value +
                    "</td></tr>" +

                    "<tr><td>" +
                    "Zip Code:" +
                    "</td><td>" +
                    document.orderForm.szip.value +
                    "</td></tr>" +

                    "</table>" +
                  "</td></tr>" +
                  "<tr><td>" +
                    "<table name='SummaryQuantityTable' id='SummaryQuantityTable'>" +

                    "<tr><td colspan=2>" +
                    "<strong>Order Summary:</strong>" +
                    "</td></tr>" +

                    "<tr><td>" +
                    "# of 'The Lion in the Tribe of Judah' CDs: " +
                    "</td><td>" +
                    document.orderForm.judahQty.value +
                    "</td></tr>" +
					
					"<tr><td>" +
                    "# of 'Songs for Bernadette' CDs: " +
                    "</td><td>" +
                    document.orderForm.bernQty.value +
                    "</td></tr>" +
					
					"<tr><td>" +
                    "# of 'Amen' CDs: " +
                    "</td><td>" +
                    document.orderForm.amenQty.value +
                    "</td></tr>" +

                    "<tr><td>" +
                    "# of 'A Child Shall Lead' CDs: " +
                    "</td><td>" +
                    document.orderForm.childQty.value +
                    "</td></tr>" +
 
                    "<tr><td>" +
                    "# of 'Amazing Grace' CDs: " +
                    "</td><td>" +
                    document.orderForm.graceQty.value +
                    "</td></tr>" +

                    "<tr><td>" +
                    "# of 'Sacred Songs & Hymns' CDs: " +
                    "</td><td>" +
                    document.orderForm.sacredQty.value +
                    "</td></tr>" +
					
					"<tr><td>" +
                    "# of Small T Shirts: " +
                    "</td><td>" +
                    document.orderForm.tshirtS.value +
                    "</td></tr>" +
					
					"<tr><td>" +
                    "# of Medium T Shirts: " +
                    "</td><td>" +
                    document.orderForm.tshirtM.value +
                    "</td></tr>" +
					
					"<tr><td>" +
                    "# of Large T Shirts: " +
                    "</td><td>" +
                    document.orderForm.tshirtL.value +
                    "</td></tr>" +
					
					"<tr><td>" +
                    "# of Extra Large T Shirts: " +
                    "</td><td>" +
                    document.orderForm.tshirtXL.value +
                    "</td></tr>" +

//                    "<tr><td>" +
//                    "Total # of CDs: " +
//                    "</td><td>" +
//                    (parseInt(document.orderForm.amenQty.value) +
//                     parseInt(document.orderForm.childQty.value) +
//                     parseInt(document.orderForm.graceQty.value) +
//                     parseInt(document.orderForm.sacredQty.value));
//                    "</td></tr>" +

                    "</table>" +
                  "</td></tr>" +
                  "<tr><td>" +
                    "<table name='SummaryReceiptTable' id='SummaryReceiptTable'>" +

                    "<tr><td colspan=2>" +
                    "<strong>Charge Summary:</strong>" +
                    "</td></tr>" +

                    "<tr><td>" +
                    "Subtotal: " +
                    "</td><td>" +
                    document.orderForm.subtotal.value +
                    "</td></tr>" +

                    "<tr><td>" +
                    "Shipping: " +
                    "</td><td>" +
                    document.orderForm.shipping.value +
                    "</td></tr>" +

                    "<tr><td>" +
                    "Sales Tax: " +
                    "</td><td>" +
                    document.orderForm.tax.value +
                    "</td></tr>" +

                    "<tr><td>" +
                    "Total: " +
                    "</td><td>" +
                    document.orderForm.chargetotal.value +
                    "</td></tr>" +

                    "</table>" +
                  "</td></tr>" +
                  "<tr><td>" +
                    "<table name='SummarySubmitTable' id='SummarySubmitTable'>" +

                    "<tr><td>" +
                    '<img src="../images/global/arrow.gif" width="66" height="20" align="absmiddle">' +
                    '<input type="button" name="Submit" value="Confirm Order" onClick="document.orderForm.submit();">' +
                    '<input type="button" name="Reset" value="Modify Order" onClick="redisplayOrder();">';
                    "</td></tr>" +

                    "</table>" +
                  "</td></tr>" +
                  "</table>";

         document.getElementById('SummaryContent').innerHTML = '';
         document.getElementById('SummaryContent').innerHTML = text;

         document.getElementById('OrderSpace').style.display = 'none';
         document.getElementById('SummarySpace').style.display = 'block';
         return(false);
      }

      return(true);
   }

   function redisplayOrder() {
      document.getElementById('OrderSpace').style.display = 'block';
      document.getElementById('SummarySpace').style.display = 'none';
   }

   function bill2ship() {
      if (document.orderForm.sameAsBilling.checked == true) {
         document.orderForm.sname.value  = document.orderForm.bname.value;
         document.orderForm.semail.value = document.orderForm.email.value;
         document.orderForm.saddr1.value = document.orderForm.baddr1.value;
         document.orderForm.saddr2.value = document.orderForm.baddr2.value;
         document.orderForm.scity.value  = document.orderForm.bcity.value;
         document.orderForm.sstate.value = document.orderForm.bstate.value;
         document.orderForm.szip.value   = document.orderForm.bzip.value;
      }

      return(true);
   }

