// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
HarmonyYarn = {};
HarmonyYarn.Checkout = {};
HarmonyYarn.Checkout.toggleShippingFields = function(el) {
  
  if(typeof el == 'undefined') {
    el = $('order_ship_to_different');
  }
  
  if(el.checked) {
    $$('fieldset.ShippingContact').each(function(fieldset) {
      fieldset.show();
    });
    
  } else {
    
    
    $$('fieldset.ShippingContact').each(function(fieldset) {
      fieldset.hide();
    });
    
    
    [ 'first_name', 'last_name', 'company', 'address', 'address2', 'city', 'state', 'postal_code' ].each(function(suffix,index) {
      src_field = $("order_bill_to_" + suffix);
      dst_field = $("order_ship_to_" + suffix);
      dst_field.value = src_field.value;
    });
  }
};

HY = HarmonyYarn;