
var url_script_add_cart 	= "";
var url_script_comment 		= "";
var txt_error_ajout_panier 	= "";
var current_product_wfcode	= "";

window.addEvent('domready', function(){
	
	initFieldQuantityProduct();
	
	if($('commentaires')){
		ChargeContenu(url_script_comment + '&wfec_product_comment_product_wfcode=' + current_product_wfcode,'idDest:commentaires');
	}
	
});

/* initialisation des champs quantité de la fiche produit */
function initFieldQuantityProduct(){
	
	$$('.field_product_quantity_slug').addEvent('keydown',function(evt){
		if(evt.event.keyCode) { 
			if( !(evt.event.keyCode >= 44 && evt.event.keyCode <= 57 ) && !(evt.event.keyCode >= 96 && evt.event.keyCode <= 105 ) && !(evt.event.keyCode == 46)&& !(evt.event.keyCode == 8)){
				return false;
			}
		}; 
		if(evt.event.which) {
			if( !(evt.event.which >= 44 && evt.event.which <= 57 ) && !(evt.event.which >= 96 && evt.event.which <= 105 ) && !(evt.event.which == 46)&& !(evt.event.which == 8)){
				return false;
			}
		}
		return true;
	});
	
	$$('.field_product_quantity_slug').addEvent('blur',function(){
		if( !(Number(this.value)) ){this.value = 1};
	});
	
}

/* modifie la quantité du champ en ajoutant la quantité en parrmètre */
function changeQuantityFieldProduct(idField, quantity){
	
	$(idField).value = parseInt($(idField).value) + quantity;
	if($(idField).value < 1){
		$(idField).value = 1;
	}
}

/* Ajout au panier de l'article */
function ajout_panier(idFieldQty, packQuantity, itm){
	var qty = 1 ;
	if($(idFieldQty)){
		qty = $(idFieldQty).value;
	}
	var opts = {modal:true,displayNav:false,handleOversize:'none'}; 
	var init = {
					player:     'iframe',
					content:    url_script_add_cart+'&ac=add&itm='+itm+'&qty='+qty+'&pq='+packQuantity,
					width:      390,
					height:     204
				};
	Shadowbox.open(init,opts);
}

/* Ajout d'un commentaire */
function addComment(product_wfcode){
	var opts = {modal:true,displayNav:false,handleOversize:'none'}; 
	var init = {
		player:     'iframe',
		content:    url_script_comment + '&ac=ad&wfec_product_comment_product_wfcode='+product_wfcode,
		width:      510,
		height:     300
	};
	Shadowbox.open(init,opts);
}
