/**
 * This script requires prototype and JQuery
 * 
 * @version 1.0
 * @author Xi ingénierie
 */


/**
 * Product quantity select add to cart functionnality
 * 
 * @param productId
 * @return
 */
function _addToCart(productId)
{
	if($('cartUrl'+productId))
	{
		var cartUrl = $('cartUrl'+productId).value;
		var qty = $('qty_'+productId).value;

		cartUrl += 'qty/'+qty;
		window.location = cartUrl;
	}
	else if($('qty') && $('product_addtocart_form'))
	{
		// product view so use form
		$('qty').value = $('qty_'+productId).value;
		productAddToCartForm.submit();
	}
}

/**
 * @GLOBAL Event listener
 * 
 * Closes quantity select if click is outside
 */
jQuery(document).bind('click', function(e) {

	
var $clicked=jQuery(e.target);

if(! $clicked.is('.prd-qte-select:visible') && ! $clicked.is('.button') && ! $clicked.parents().is('.prd-qte-select:visible') ) 
{ 
	jQuery('.prd-qte-select:visible').hide(); 
}

}); 


/**
 * Toggles quantity selectors on products
 * 
 * @param productId
 * @return
 */
function _togglePrdQtySelect(productId)
{
	jQuery('.prd-qte-select:visible').hide();
	$('prd-qty-select-list_'+productId).show();
}

function _togglePrdQtySelectionSelect(productId)
{
	jQuery('.prd-qte-select:visible').hide();
	var producActif = $('prd-qty-select-list_'+productId);
	jQuery(".region-selection").find( "#prd-qty-select-selection-list_" + productId ).show();
}


