var epoqRecommendationDiv = "epoqRecommendation";

// Epoq Recommendation init 
function epoqRecommendationInit(recommendationPids, recommendationId, data, pageId, ceUid, productId)
{
    var recWidgetFromShopURL = "index.php?id="+pageId+"&type=576&tx_nfcshop_pi1[action]=AJAX_EPOQRECOMMENDATION&tx_nfcshop_pi1[ce_uid]="+ceUid+"&tx_nfcshop_pi1[pid]="+recommendationPids;

    var className = jQuery('#'+epoqRecommendationDiv).attr('class');
    var productsId = productId;

	if(productsId.length > 0)
	{
		jQuery.ajax
		(
			{
				type: 'GET',
				url: recWidgetFromShopURL,
				data:
				{
					productsId: productsId,
					className: className
				},
				contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
				cache: false,
				async: false,
				success:
                    function (outputText, textStatus)
					{
                        var defaultLentghEmptyProduct = 213; // This is the default value for that recommendations that are empty.

                        if (outputText.length > defaultLentghEmptyProduct)
						{
							//show layer
                            jQuery('#'+epoqRecommendationDiv).append(outputText);
                            
                            /*
                             * At this point, it's possible that this function was executed twice. If this happened we need to
                             * distinguish (in the second call) if we have added before the eqreceqid to the links. In this 
                             * second call we are going to traverse again the same div so we need to prevent not adding the eqreceqid
                             * to the links of the first call. To do this, we are going to compare if the div.tx-nfcshop-pi1's sons 
                             * are inside of outputText (the HTML code returned by the second call).
                             */
                            jQuery('#'+epoqRecommendationDiv+' div.tx-nfcshop-pi1 > div').each(function(){
								if (outputText.indexOf(this.id) >= 0)
								{
									jQuery('#'+this.id+' a').each(function(){
										this.href = this.href + "?eqrecqid=" + recommendationId;
									});
								}
							});
						}
					},
                reccommands: {}
			}
		);
	}
}

// onload 
jQuery(document).ready(function()
	{
	}
);
