// *********************************************************************************************************************************************
// AJAX - CUSTOMIZE ASSORTMENTS
// *********************************************************************************************************************************************

function getProductData(id_product, id_catp, id_cat, id_subcat, id_product_line, target) {
	
	if (id_product>0) {
		$.ajax({ 
			method: "get",
			url: "inc-pag/products/_getProductData.php",
			data: "id_product="+id_product+"&id_catp="+id_catp+"&id_cat="+id_cat+"&id_subcat="+id_subcat+"&id_product_line="+id_product_line+"&products_excluded_array="+products_excluded_array.join("-")+"&products_excluded_array_names="+products_excluded_array_names.join("-")+"&products_list_array="+products_list_array.join("-")+"", 
			
			beforeSend: function(){
				$('#preloader').show();
			}, //show loading just when event triggered
			
			complete: function(){
				$('#preloader').hide();
			}, //stop showing loading when the process is complete 
			
			success: function(html){ //so, if data is retrieved, store it in html 
				$(target).before(html); //show the html inside .content div 
				//$(target + "select").before(html); //show the html inside .content div 
				
				var productIdIndex = products_excluded_array.indexOf(parseInt(id_product));
				//alert(productIdIndex)
				products_excluded_array.splice(productIdIndex, 1);
				products_excluded_array_names.splice(productIdIndex, 1);
				products_list_array.push(id_product);
				
				populateExcludedProducts(products_excluded_array, products_excluded_array_names);
				
			} //
		}); //end $.ajax
	} // end IF (id_location is valid)
	
}


function populateExcludedProducts(arrayId, arrayNames) {
	if (arrayId.length>0) {
		var options = '<option value="0">Add product</option>';
		for (var i=0; i<arrayId.length; i++) {
			options += '<option value="' + arrayId[i] + '">' + arrayNames[i] + '</option>';
		}
		$(".add-product-block select").html(options);
		$(".add-product-block").slideDown(200);
	} else {
		$(".add-product-block").slideUp(200);
	}
}