// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

function add_to_cart(id) {
	Element.show('indicator_for_deliverable_'+id);
	var myAjax = new Ajax.Updater('cart-wrapper', '/cart/add/'+id, {
		method: 'get',
		onComplete: function() {
			Element.hide('indicator_for_deliverable_'+id);
			show_cart();
		}
	});
}

function remove_from_cart(id) {
	Element.show('big_cart_indicator');
	var myAjax = new Ajax.Updater('cart-wrapper', '/cart/remove_item/'+id, {
		onComplete: function() {
			Element.hide('big_cart_indicator');
		}
	});
}

function update_quantity(deliverable_id, quantity) {
	Element.show('big_cart_indicator');
	var params = "quantity=" + quantity;
	var myAjax = new Ajax.Updater('cart-wrapper', '/cart/update_quantity/'+deliverable_id, {
		method: 'post',
		parameters: params,
		onComplete: function() {
			Element.hide('big_cart_indicator');
		}
	});
}

function load_cart() {
	Element.show('indicator_cart');
	var myAjax = new Ajax.Updater('cart-wrapper', '/cart', {
		method: 'get',
		onComplete: function() {
			Element.hide('indicator_cart');
			show_cart();
		}
	});
}

function show_cart() {
	// set height of wrapper to height of content
	//var content_h = Element.getHeight('content-wrapper') + 40;
	//var window_h = getWindowHeight();
	//var cart_h = (content_h >= window_h) ? content_h : window_h;
	//$('cart-wrapper').style.height = cart_h + 'px';
	Effect.BlindDown('cart-wrapper', {
		duration: 0.8
	});
}

function hide_cart() {
	Effect.BlindUp('cart-wrapper', {
		duration: 0.4
	});
}

function update_shipping_same_as_billing() {

  var form_fields = $w('order_ship_to_name order_ship_to_address_1 order_ship_to_address_2 order_ship_to_city order_ship_to_state_id order_ship_to_region order_ship_to_postal_code order_ship_to_country_id');
  
  if ($F('order_shipping_same_as_billing')) {
    form_fields.each(function(item) {
      if ($(item)) {
        if (item == 'order_ship_to_state_id') {
          $(item).value = '--';
        }
        $(item).clear().disable();        
      }
    $$('span.change_shipping_zone_link').each(function(span) { span.hide(); } );    
    });
  } else {
    form_fields.each(function(item) {
      if ($(item)) {
        $(item).enable();        
      }
    });
    $$('span.change_shipping_zone_link').each(function(span) { span.show(); } );
  }
}