/* 	
	ShopOnRails Scripts
	Pierre-Loïc Raynaud & Gwendal Roué - (c) 2006 Pierlis
        Thomas Lecavelier - © 2010 Pierlis
	http://www.pierlis.com
*/

function enableDeliveryAddressFields(inEnableFlag)
{
	var vFields = ['client_delivery_address', 'client_delivery_address2', 'client_delivery_cp', 'client_delivery_city', 'client_delivery_iso36611_entry_id'];
	for (var i = 0; i < vFields.length; i++)
	{
    	var element = $(vFields[i]);
    	element.disabled = ! inEnableFlag;
		if (inEnableFlag == false)
			element.value = '';
    }
}

function toggleCompany()
{
	new Effect.toggle($('hideable-client_billing_company'),'blind')
	$('client_billing_company').value=''
	$('client_delivery_company').value=''	
}

function lostpassword()
{
	var email = $F('ident_email');
	var emailfield = $('mdpEmail');
	emailfield.value = email;
	$('motdepasseform').submit();
}

function submitToRightPaymentSite()
{
	if($('payment_method_paybox').checked) {
		$$('#paybox_form form').first().submit();
	} else if($('payment_method_ekdo').checked) {
		$$('#ekdo_form form').first().submit();
	}
}

function ajouterAuxFavoris() {
  if (document.all) {
    window.external.AddFavorite("http://www.coteperso.com","Cote Perso");
  } else if (window.sidebar) {
    window.sidebar.addPanel("Cote Perso", "http://www.coteperso.com", "");
  }
}

function openSpecialOffer(event) {
  if (event.target.nodeName != 'A') {
    var link = $$('.main-special-offer a.savoir-plus')[0];
    if (link)
      location.href = link.href;
  }
}

var bind_third_level_menu = function() {
  $$('.menu-trigger').each(function(element) {
    var third = element.down('ul');
    if (!third) return;
    element.observe('mouseover', function() {
      third.show();
    });
    element.observe('mouseout', function() { 
      third.hide();
    });
  }); 
};
document.observe("dom:loaded", function() {
  var special_offer = $('special-offer')
  if (special_offer)
    special_offer.observe('click', openSpecialOffer);
  bind_third_level_menu();
});

// Called when a product is dropped into the promo code's gift zone
// Set the hidden field promo_code_gift_product_id 1 or 2 with the appropriate value
// Display the product's name and externalred int the droppable zone
function addProductToPromoCode(product, gift, event) {
  $('promo_code_' + gift.id).value = product.id.replace('pool_', '');
  gift.innerHTML = product.innerHTML;
  gift.highlight();
}
