    function ssl_popup() {
	mywindow=window.open("http://www.chocolategifts.com/ssl.php", "", "width=500,height=150");
	mywindow.moveTo(0,0);
    }

    function continueShopping() {
      location="index.php";
    }

    function printThis() {
      window.print();
    }

      function handleViewCart() {
        if(viewcart.readyState==4) {
          if(viewcart.status==200) {
            var results=viewcart.responseText;
            //document.getElementById("cartcontents").innerHTML = results;
          }
        }
      }

      function requestViewCart() {
        viewcart.open("get", "viewcart.php", true);
        viewcart.onreadystatechange=handleViewCart;
        viewcart.send(null);
      }
      
      //window.onLoad=requestViewCart();

      function handleAddToCart() {
        if(addcart.readyState==4) {
          if(addcart.status==200) {
            setTimeout("requestViewCart()", 0);
            var results=addcart.responseText;
            location="https://www.chocolategifts.com/mycart.php";
          }
        }
      }

      function requestAddToCart(prodnum) {
      var prodnum;
      var qty=document.getElementById('qty'+prodnum).value;
      addcart.open("post", "addtocart.php", true);
      addcart.onreadystatechange=handleAddToCart;
      addcart.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
      addcart.send("stocknum="+prodnum+"&qty="+qty);
      }

      function handleCheckoutResponse() {
        if(checkout.readyState==4) {
          if(checkout.status==200) {
            var results=checkout.responseText;
            document.getElementById("shoppingform").innerHTML = results;
          }
        }
      }

      function requestCheckout() {
        var ordertotal=parseFloat(document.getElementById("grandtotal").value);
        if(ordertotal!=0) {
      	var personal_msg=document.getElementById("personal_msg");
      	var inc_msg=0;
        if(personal_msg.checked==true) {
		inc_msg=1;
		ordertotal=parseFloat(document.getElementById("grandtotal").value)+1;
	}
        var state=document.getElementById("state").value;
        checkout.open("post", "checkout.php", true);
        checkout.onreadystatechange=handleCheckoutResponse;
        checkout.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        checkout.send("ordertotal="+ordertotal+"&state="+state+"&pmsg="+inc_msg);
        } else {
            alert("Please select your state from the drop-down to calculate tax before continuing.");
        }
      }

      function handleProcessResponse() {
        if(process.readyState==4) {
          if(process.status==200) {
            var results=process.responseText;
            document.getElementById("shoppingform").innerHTML = results;
          }
        }
      }

      function requestProcessOrder() {
      document.getElementById("submitorder").disabled = true;
      document.getElementById("submitorder").value = " Submitting...One momment please ";
      var ordertotal=parseFloat(document.getElementById("ordertotal").value);
      //var ordertax=document.getElementById("taxcost").value;
      var billing_address=document.getElementById("billing_address").value;
      var billing_city=document.getElementById("billing_city").value;
      var billing_state=document.getElementById("billing_state").value;
      var billing_zip=document.getElementById("billing_zip").value;
      var billing_phone=document.getElementById("billing_phone").value;
      var email=document.getElementById("email").value;
      var shipping_address=document.getElementById("shipping_address").value;
      var shipping_city=document.getElementById("shipping_city").value;
      var shipping_state=document.getElementById("shipping_state").value;
      var shipping_zip=document.getElementById("shipping_zip").value;
      var shipping_phone=document.getElementById("shipping_phone").value;
      var billing_name=document.getElementById("billing_name").value;
      var billing_creditcard=document.getElementById("billing_creditcard").value;
      var card_expiremonth=document.getElementById("card_expiremonth").value;
      var card_expireyear=document.getElementById("card_expireyear").value;
      var billing_cardtype=document.getElementById("billing_cardtype").value;
      var billing_csv=document.getElementById("billing_csv").value;
      var sameasbilling=document.getElementById("sameasbilling");
      var month=document.getElementById("month").value;
      var day=document.getElementById("day").value;
      var year=document.getElementById("year").value;
      var giftmessage=document.getElementById("giftmessage").value;
      var addrtype=document.getElementById("adr1");
      var addrtype2=document.getElementById("adr2");
      if(addrtype.checked==true) { addrtype="Business Address"; } if(addrtype2.checked==true) { addrtype="Residential Address"; }
      var specialcode=document.getElementById("specialcode").value;
      var shipping_name=document.getElementById("shipping_name").value;
      var shiptobill=0;
      if(sameasbilling.checked==true) {
        shiptobill=1;
      }
      if(billing_address!="" && billing_city!="" && billing_state!="" && billing_zip!="" && billing_phone!="" && email!="" && billing_name!="" && billing_creditcard!="" && card_expiremonth!="" && card_expireyear!="" && billing_cardtype!="" && billing_csv!="") {
      if((shiptobill==1) || (shipping_address!="" && shipping_city!="" && shipping_state!="" && shipping_zip!="" && shipping_phone!="")) {
        process.open("post", "process.php", true);
        process.onreadystatechange=handleProcessResponse;
        process.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        process.send("ordertotal="+ordertotal+"&billing_address="+billing_address+"&billing_city="+billing_city+"&billing_state="+billing_state+"&billing_zip="+billing_zip+"&billing_phone="+billing_phone+"&email="+email+"&shipping_address="+shipping_address+"&shipping_city="+shipping_city+"&shipping_state="+shipping_state+"&shipping_zip="+shipping_zip+"&shipping_phone="+shipping_phone+"&billing_name="+billing_name+"&billing_creditcard="+billing_creditcard+"&card_expiremonth="+card_expiremonth+"&card_expireyear="+card_expireyear+"&billing_cardtype="+billing_cardtype+"&billing_csv="+billing_csv+"&shiptobill="+shiptobill+"&month="+month+"&day="+day+"&year="+year+"&giftmessage="+giftmessage+"&specialcode="+specialcode+"&shipping_name="+shipping_name+"&addrtype="+addrtype);
        } else {
            document.getElementById("submitorder").value = " Submit Order ";
            document.getElementById("submitorder").disabled = false;
            alert("You must enter shipping information.");
          }
        } else {
            document.getElementById("submitorder").value = " Submit Order ";
            document.getElementById("submitorder").disabled = false;
            alert("You are missing required billing fields.");
        }
      }

      function handleRemoveItem() {
        if(removeitem.readyState==4) {
          if(removeitem.status==200) {
            var results=removeitem.responseText;
            location="mycart.php";
          }
        }
      }

      function requestRemove(product) {
        var product;
        removeitem.open("get", "removeitem.php?product="+product, true);
        removeitem.onreadystatechange=handleRemoveItem;
        removeitem.send(null);
      }

      function getHTTPObject() {
      var xmlobj;
        if(window.XMLHttpRequest) {
          xmlobj=new XMLHttpRequest();
        } else if(window.ActiveXObject) {
            xmlobj=new ActiveXObject("Microsoft.XMLHTTP");
            if(!xmlobj) {
              xmlobj=new ActiveXObject("Msxml2.XMLHTTP");
            }
        }
      return xmlobj;
      }
      
      var addcart = getHTTPObject();
      var viewcart = getHTTPObject();
      var checkout = getHTTPObject();
      var process = getHTTPObject();
      var removeitem = getHTTPObject();

  function calculateTax() {
  var va='.05';
  var state=document.getElementById("state").value;
  var subtotal=document.getElementById("subtotal").value;
  var tax;
  var grandtotal=parseFloat(document.getElementById("runningtotal").value);
    if(state=="VA") {
      tax=subtotal*va;
    } else {
        tax=0;
    }
    var totalcost=grandtotal+tax;
    document.getElementById("total").innerHTML = "$"+formatAsMoney(totalcost);
    document.getElementById("taxcost").value = tax;
    document.getElementById("grandtotal").value = formatAsMoney(totalcost);
    document.getElementById("tax").innerHTML = "$"+formatAsMoney(tax);
    //document.getElementById("mytax").value = tax;
  }

function formatAsMoney(mnt) {
    mnt -= 0;
    mnt = (Math.round(mnt*100))/100;
    return (mnt == Math.floor(mnt)) ? mnt + '.00' 
              : ( (mnt*10 == Math.floor(mnt*10)) ? 
                       mnt + '0' : mnt);
}