function same_as_billing()
{
   var checkbox_status = document.forms[0].elements['same'].checked

   if ( !checkbox_status )
   {
      document.forms[0].elements['same'].checked = checkbox_status
      document.forms[0].elements['nameFirst_ship'].value = ''
      document.forms[0].elements['nameLast_ship'].value = ''
      document.forms[0].elements['email_ship'].value = ''
      document.forms[0].elements['email2_ship'].value = ''
      document.forms[0].elements['phone_ship'].value = ''
      document.forms[0].elements['company_ship'].value = ''
      document.forms[0].elements['address1_ship'].value = ''
      document.forms[0].elements['address2_ship'].value = ''
      document.forms[0].elements['suburb_ship'].value = ''
      document.forms[0].elements['state_ship'].value = ''
      document.forms[0].elements['postcode_ship'].value = ''
      document.forms[0].elements['country_ship'].value = ''
   }
   else
   {
      document.forms[0].elements['same'].checked = checkbox_status
      document.forms[0].elements['nameFirst_ship'].value = document.forms[0].elements['nameFirst'].value
      document.forms[0].elements['nameLast_ship'].value =  document.forms[0].elements['nameLast'].value
      document.forms[0].elements['email_ship'].value =  document.forms[0].elements['email'].value
      document.forms[0].elements['email2_ship'].value =  document.forms[0].elements['email2'].value
      document.forms[0].elements['phone_ship'].value =  document.forms[0].elements['phone'].value
      document.forms[0].elements['company_ship'].value =  document.forms[0].elements['company'].value
      document.forms[0].elements['address1_ship'].value =  document.forms[0].elements['address1'].value
      document.forms[0].elements['address2_ship'].value =  document.forms[0].elements['address2'].value
      document.forms[0].elements['suburb_ship'].value =  document.forms[0].elements['suburb'].value
      document.forms[0].elements['state_ship'].value =  document.forms[0].elements['state'].value
      document.forms[0].elements['postcode_ship'].value =  document.forms[0].elements['postcode'].value
      document.forms[0].elements['country_ship'].value =  document.forms[0].elements['country'].value
   }
}

function countryUpdate()
{
   if(document.forms[0].elements['country'].value == "AU")
   {
      // add PAYPAL option if missing
      if(document.forms[0].elements['payment'].options.length == 2)
      {
         var optn = document.createElement("OPTION");
         optn.text = "PayPal";
         optn.value = "PP";
         document.forms[0].elements['payment'].options[2] = optn;
      }
   
      // add EXPRESS FREIGHT option if missing
      if(document.forms[0].elements['shipping'].options[1].value != "EF")
      {
         if(document.forms[0].elements['shipping'].options.length == 2)
         {
            var optn = document.createElement("OPTION");
            optn.text = document.forms[0].elements['shipping'].options[1].text;
            optn.value = document.forms[0].elements['shipping'].options[1].value;
            document.forms[0].elements['shipping'].options[2] = optn;
         }
         
         var optn = document.createElement("OPTION");
         optn.text = "Express freight";
         optn.value = "EF";
         document.forms[0].elements['shipping'].options[1] = optn;
      }
   }
   else if(document.forms[0].elements['country'].value == "NZ")
   {
      // add PAYPAL option if missing
      if(document.forms[0].elements['payment'].options.length == 2)
      {
         var optn = document.createElement("OPTION");
         optn.text = "PayPal";
         optn.value = "PP";
         document.forms[0].elements['payment'].options[2] = optn;
      }
   
      // remove EXPRESS FREIGHT option if there
      if(document.forms[0].elements['shipping'].options[1].value == "EF")
      {
         document.forms[0].elements['shipping'].remove(1);
         shippingUpdate();
      }
   }
   else
   {
      // remove PAYPAL option if there
      if(document.forms[0].elements['payment'].options.length == 3)
      {
         document.forms[0].elements['payment'].remove(2);
         paymentUpdate();
      }
   
      // remove EXPRESS FREIGHT option if there
      if(document.forms[0].elements['shipping'].options[1].value == "EF")
      {
         document.forms[0].elements['shipping'].remove(1);
         shippingUpdate();
      }
   }
}

function paymentUpdate()
{
   if(document.forms[0].elements['payment'].value == "PP")
   {
      document.forms[0].elements['submitButton'].value = "Continue: Review your order";
      document.getElementById("divDescription").innerHTML = "<p>PayPal is the safer, easier way to pay and get paid online. The service allows anyone to pay in any way they prefer, including through credit cards, bank accounts, buyer credit or account balances, without sharing financial information.</p>";

      if(document.forms[0].elements['shipping'].value == "OT")
      {
         document.forms[0].elements['shipping'].value = "FF";
         shippingUpdate(document.forms[0].elements['totalPrice'].value, document.forms[0].elements['expressPrice'].value);
      }

      if(document.forms[0].elements['shipping'].options.length == 3)
      {
         document.forms[0].elements['shipping'].remove(2);
      }
   }
   else
   {
      document.forms[0].elements['submitButton'].value = "Continue: Personal details";
      if(document.forms[0].elements['shipping'].options[document.forms[0].elements['shipping'].options.length-1].value != "OT")
      {
         var optn = document.createElement("OPTION");
         optn.text = "Other";
         optn.value = "OT";
         document.forms[0].elements['shipping'].options[document.forms[0].elements['shipping'].options.length] = optn;
      }

      if(document.forms[0].elements['payment'].value == "DD")
      {
         document.getElementById("divDescription").innerHTML = "<p>Direct deposit is a free, fast and secure method of payment. Our relevant details can be found <a href=http://headphones.com.au/payment/ target=new>on our payment page</a>. You will receive an order confirmation via email during business hours including your order total.</p><p>Please don't arrange direct deposit <em>until you have received order confirmation</em>, unless otherwise arranged with us.</p>";
      }
      else if(document.forms[0].elements['payment'].value == "CC")
      {
         document.getElementById("divDescription").innerHTML = "<p>Unfortunately due to high fraud rates, we do not have an online credit card processing facility and we ask that you send your details via another means. Please check <a href=http://headphones.com.au/payment/ target=new>our payment page</a> for full details on how to pay via credit card with us <em>before finalising your order</em>.</p><p><b>IMPORTANT:</b> We <b>do not</b> ship credit card orders to PO Box addresses.</p>";
      }
   }
}

function shippingUpdate(prodPrice, expressPrice)
{
   if(document.forms[0].elements['shipping'].value == "FF")
   {
      if(prodPrice < 100)
      {
         document.getElementById("divInsured").firstChild.nodeValue = "No";
      }
      else
      {
         document.getElementById("divInsured").firstChild.nodeValue = "Yes";
      }

      document.getElementById("divDelivery").firstChild.nodeValue = "3-8 working days";
      document.getElementById("divCost").firstChild.nodeValue = "Free";
      document.forms[0].elements['shippingPrice'].value = 0;
   }
   else if(document.forms[0].elements['shipping'].value == "EF")
   {
      document.getElementById("divInsured").firstChild.nodeValue = "Yes";
      document.getElementById("divDelivery").firstChild.nodeValue = "2 working days";

      if(prodPrice < 100)
      {
         document.getElementById("divCost").firstChild.nodeValue = "$7 for orders under $100";
         document.forms[0].elements['shippingPrice'].value = 7;
      }
      else
      {
         document.getElementById("divCost").firstChild.nodeValue = (expressPrice < 0) ? "Express delivery is available on all products. The price will vary depending on your location and the size of the item, an exact price will be emailed to you after you submit your order." : ("$" + expressPrice);
         document.forms[0].elements['shippingPrice'].value = expressPrice;
      }
   }
   else
   {
      document.getElementById("divInsured").firstChild.nodeValue = "Check";
      document.getElementById("divDelivery").firstChild.nodeValue = "Check";
      document.getElementById("divCost").firstChild.nodeValue = "Check";
      document.forms[0].elements['shippingPrice'].value = -1;

      if(document.forms[0].elements['payment'].value == "PP")
      {
         document.forms[0].elements['payment'].value = "DD";
      }
   }
}

