function Juicy_PDP_zpf(a_product_ids,            // Array of recommended product IDs
                     zone,                  // Zone ID specified in the request (as entered on zone edit screen)
                     symbolic,              // Target type:
                                            //      _SP_  Specified Product ID
                                            //      _SC_  Specified Category ID
                                            //      _RVP_ Most Recently Viewed Product
                                            //      _RPP_ Most Recently Purchased Product
                                            //      _NR_  No Recommendations
                                            //      _LCP_ Last Carted Product
                                            //      _MPC_ Visitor's Most Popular Category
                                            //      _SS_  Specified Search Term
                     target_id,             // Target ID recommendations are based on
                     category,              // Category of Target ID - EPR Category ID if the Target ID is a product
                     rec_attributes,        // 2 dimensional array of attributes for each recommendation
                     target_attributes,     // Array of attribute for the target
                     target_header_txt,     // Header text (as entered on recommendation plan edit screen)
                     ab_test_id,            // String containing AB Test Name, a semicolon, AB test ID for the test element requested
                                            //      Null if no AB Test
                                            // 
                                            // The final 2 parameters are not standard parameters passed into zone population function
                                            // They ared added via the function calls at bottom of this file
                     div_id,                //      div id - must match desired div id in DW isml template
                     b_display_target)      //      indicates whether target will be displayed

{
	   //var html = zone + "_zp: No recommendations returned";
	   var html = " ";

	   if (symbolic !== '_NR_')
	   {
	      // !!CLIENT DEPENDENT!! - use the correct attribute for description (array indices are zero based so first attribute is index 0)
	      var i_description = 0;
	      // !!CLIENT DEPENDENT!! - use the correct attribute for image (array indices are zero based so first attribute is index 0)
	      var i_image_url   = 1;
	      // !!CLIENT DEPENDENT!! - image prefix
	      var image_prefix  = '';

	      var i_href        = undefined;
	      var i_score       = undefined;
	      var i_price       = undefined;

	      var div_recs    = '<div class="io_test_recs"\>';
	      var n_recs      = 4;
	      var div_title   = '<h2>' + target_header_txt + '<\/h2>';
	      var div_table   = '<div class="io_recs_table">';
	      var image_table = '<TABLE CELLSPACING="2" CELLPADDING="0" Align="center" style="border-color:white;"><TR>';
	      var lines       = [];
	      var width       = 100 / n_recs;
	      lines.push('<ul>');

	      // Recommendations
	      for (var ii=0; ii < n_recs; ii++)
	      {
	    	 try{
			         var rec_prod_id       = b_display_target ? (ii == 0 ? target_id : a_product_ids[ii - 1]) : a_product_ids[ii];
		
			         var selected_href     = image_prefix + rec_attributes[ii][2];                                                // - not passed - href for image
		
			         var image_description = rec_attributes[ii][i_description];                 // product description
			         var image_url         = image_prefix + rec_attributes[ii][i_image_url];    // image url
		
			         var alt_description   = image_description;
			         if (!image_description)
			         {
			            alt_description   = 'No Image Available';
			            image_description   = '&nbsp;';
			         }
			         var price = null;
			         var attr_1     = rec_attributes[ii][0] ? rec_attributes[ii][0] : '-';
			         var attr_2     = rec_attributes[ii][1] ? rec_attributes[ii][1] : '-';
			         var attr_3     = rec_attributes[ii][2] ? rec_attributes[ii][2] : '-';
			         var attr_4     = rec_attributes[ii][3] ? rec_attributes[ii][3] : '-';
			         var attr_5     = rec_attributes[ii][4] ? rec_attributes[ii][4] : '-';
			         var attr_6     = rec_attributes[ii][5] ? rec_attributes[ii][5] : '-';
			         var attr_7     = rec_attributes[ii][6] ? rec_attributes[ii][6] : '-';
			         var attr_8     = rec_attributes[ii][7] ? rec_attributes[ii][7] : '-';
			         var attr_9     = rec_attributes[ii][8] ? rec_attributes[ii][8] : '-';
			         var attr_10    = rec_attributes[ii][9] ? rec_attributes[ii][9] : '-';
			         var attr_11    = rec_attributes[ii][10] ? rec_attributes[ii][10] : '-';
			         var attr_12    = rec_attributes[ii][11] ? rec_attributes[ii][11] : '-';
			         var attr_13    = rec_attributes[ii][12] ? rec_attributes[ii][12] : '-';
			         var attr_14    = rec_attributes[ii][13] ? rec_attributes[ii][13] : '-';
			         var attr_15    = rec_attributes[ii][14] ? rec_attributes[ii][14] : '-';
	         
			
								
		
			         var showStandardPrice = "";
			         var showPriceRange = "";
			         var standardPrice = null;
			         var salePrice = null;
			         var PriceRange = null;	
			         // Display image and it's description
			         lines.push('<li><div class="image recommendation_image"><A HREF="' + selected_href +'&navid=xsellPDPYMAL'+'"><IMG SRC="' + image_url + '" + ALT="' + alt_description + '"><\/IMG><\/A><\/div>');
			         lines.push('<div class="name"><A STYLE="text-decoration:none" HREF="' + selected_href +'&navid=xsellPDPYMAL'+'">' + image_description + '<\/A><\/div>');
				 		var url = app.util.appendParamToURL(app.URLs.getPricing,"pid", a_product_ids[ii]);
						app.ajax.getJson({
							url: url,
							async	: false,
							callback: function(data) {
								if (!data) {
									return;
								}
								showStandardPrice = data.pricing.isShowStandardPrice;
								ShowPriceRange = data.pricing.isShowPriceRange;
								PriceRange = data.pricing.PriceRange;
								standardPrice =  data.pricing.standard;	
								salePrice =  data.pricing.sale;
							}
						});
						if(showStandardPrice==true){
							if(salePrice != "null" && salePrice != "$0.00" && standardPrice != "$null" && standardPrice != "$0.00"){
							lines.push('<div class="price"><div class="salesprice">'+salePrice+'<\/div><div class="standardprice">'+standardPrice+'<\/div><\/div><\/li>');
							}
						}
						else if(ShowPriceRange == false && showStandardPrice == false){
							if(standardPrice != "$null" && standardPrice != "$0.00"){
							lines.push('<div class="price"><div class="standardprice">'+standardPrice+'<\/div><\/div><\/li>');
							}
						}
						else if(ShowPriceRange==true){
							if(PriceRange != "$null - $null" && PriceRange != "$0.00 - $0.00"){
							lines.push('<div class="price"><div class="standardprice">'+PriceRange+'<\/div><\/div><\/li>');
							}
						}
			 }
	    	 catch(e){break;}
	    }

	      // make a text string
	      //html = lines.join("\n") + '<\/TR\><\/TABLE\><\/div\><\/div\>';
	      lines.push('<\/ul>');
	      html = div_title + lines.join("\n");
	   }
	   else
	   {   jQuery("div.productRecommendation").hide();
	   }
	   
	   document.getElementById(div_id).innerHTML= html;
}
function Juicy_SP_zpf(a_product_ids,            // Array of recommended product IDs
        zone,                  // Zone ID specified in the request (as entered on zone edit screen)
        symbolic,              // Target type:
                               //      _SP_  Specified Product ID
                               //      _SC_  Specified Category ID
                               //      _RVP_ Most Recently Viewed Product
                               //      _RPP_ Most Recently Purchased Product
                               //      _NR_  No Recommendations
                               //      _LCP_ Last Carted Product
                               //      _MPC_ Visitor's Most Popular Category
                               //      _SS_  Specified Search Term
        target_id,             // Target ID recommendations are based on
        category,              // Category of Target ID - EPR Category ID if the Target ID is a product
        rec_attributes,        // 2 dimensional array of attributes for each recommendation
        target_attributes,     // Array of attribute for the target
        target_header_txt,     // Header text (as entered on recommendation plan edit screen)
        ab_test_id,            // String containing AB Test Name, a semicolon, AB test ID for the test element requested
                               //      Null if no AB Test
                               // 
                               // The final 2 parameters are not standard parameters passed into zone population function
                               // They ared added via the function calls at bottom of this file
        div_id,                //      div id - must match desired div id in DW isml template
        b_display_target)      //      indicates whether target will be displayed

{
//var html = zone + "_zp: No recommendations returned";
var html = " ";

if (symbolic !== '_NR_')
{
// !!CLIENT DEPENDENT!! - use the correct attribute for description (array indices are zero based so first attribute is index 0)
var i_description = 0;
// !!CLIENT DEPENDENT!! - use the correct attribute for image (array indices are zero based so first attribute is index 0)
var i_image_url   = 1;
// !!CLIENT DEPENDENT!! - image prefix
var image_prefix  = '';

var i_href        = undefined;
var i_score       = undefined;
var i_price       = undefined;

var div_recs    = '<div class="io_test_recs"\>';
var n_recs      = 4;
var div_title   = '<h2><\/h2>';
var div_table   = '<div class="io_recs_table">';
var image_table = '<TABLE CELLSPACING="2" CELLPADDING="0" Align="center" style="border-color:white;"><TR>';
var lines       = [];
var width       = 100 / n_recs;
lines.push('<ul>');

// Recommendations
for (var ii=0; ii < n_recs; ii++)
{
try{
        var rec_prod_id       = b_display_target ? (ii == 0 ? target_id : a_product_ids[ii - 1]) : a_product_ids[ii];

        var selected_href     = image_prefix + rec_attributes[ii][2];                                                // - not passed - href for image

        var image_description = rec_attributes[ii][i_description];                 // product description
        var image_url         = image_prefix + rec_attributes[ii][i_image_url];    // image url

        var alt_description   = image_description;
        if (!image_description)
        {
           alt_description   = 'No Image Available';
           image_description   = '&nbsp;';
        }

        var attr_1     = rec_attributes[ii][0] ? rec_attributes[ii][0] : '-';
        var attr_2     = rec_attributes[ii][1] ? rec_attributes[ii][1] : '-';
        var attr_3     = rec_attributes[ii][2] ? rec_attributes[ii][2] : '-';
        var attr_4     = rec_attributes[ii][3] ? rec_attributes[ii][3] : '-';
        var attr_5     = rec_attributes[ii][4] ? rec_attributes[ii][4] : '-';
        var attr_6     = rec_attributes[ii][5] ? rec_attributes[ii][5] : '-';
        var attr_7     = rec_attributes[ii][6] ? rec_attributes[ii][6] : '-';
        var attr_8     = rec_attributes[ii][7] ? rec_attributes[ii][7] : '-';
        var attr_9     = rec_attributes[ii][8] ? rec_attributes[ii][8] : '-';
        var attr_10    = rec_attributes[ii][9] ? rec_attributes[ii][9] : '-';
        var attr_11    = rec_attributes[ii][10] ? rec_attributes[ii][10] : '-';
        var attr_12    = rec_attributes[ii][11] ? rec_attributes[ii][11] : '-';
        var attr_13    = rec_attributes[ii][12] ? rec_attributes[ii][12] : '-';
        var attr_14    = rec_attributes[ii][13] ? rec_attributes[ii][13] : '-';
        var attr_15    = rec_attributes[ii][14] ? rec_attributes[ii][14] : '-';
        


		// Display image and it's description
        var showStandardPrice = "";
        var showPriceRange = "";
        var standardPrice = null;
        var salePrice = null;
        var PriceRange = null;	

        lines.push('<li><div class="image recommendation_image"><A HREF="' + selected_href +'&navid=xsellSearchYMAL'+'"><IMG SRC="' + image_url + '" + ALT="' + alt_description + '"><\/IMG><\/A><\/div>');
        lines.push('<div class="name"><A STYLE="text-decoration:none" HREF="' + selected_href +'&navid=xsellSearchYMAL'+'">' + image_description + '<\/A><\/div>');

        var url = app.util.appendParamToURL(app.URLs.getPricing,"pid", a_product_ids[ii]);
		app.ajax.getJson({
			url: url,
			async	: false,
			callback: function(data) {
				if (!data) {
					return;
				}
				showStandardPrice = data.pricing.isShowStandardPrice;
				ShowPriceRange = data.pricing.isShowPriceRange;
				PriceRange = data.pricing.PriceRange;
				standardPrice =  data.pricing.standard;	
				salePrice =  data.pricing.sale;
			}
		});
		if(showStandardPrice == true){
			if(salePrice != "null" && salePrice != "$0.00" && standardPrice != "$null" && standardPrice != "$0.00"){
			lines.push('<div class="price"><div class="salesprice">'+salePrice+'<\/div><div class="standardprice">'+standardPrice+'<\/div><\/div><\/li>');
			}
		}
		else if(ShowPriceRange == false && showStandardPrice == false){
			if(standardPrice != "$null" && standardPrice != "$0.00"){
			lines.push('<div class="price"><div class="standardprice">'+standardPrice+'<\/div><\/div><\/li>');
			}
		}
		else if(ShowPriceRange == true){
			if(PriceRange != "$null - $null" && PriceRange != "$0.00 - $0.00"){
			lines.push('<div class="price"><div class="standardprice">'+PriceRange+'<\/div><\/div><\/li>');
			}
		}
}
catch(e){break;}
}

// make a text string
//html = lines.join("\n") + '<\/TR\><\/TABLE\><\/div\><\/div\>';
lines.push('<\/ul>');
html = div_title + lines.join("\n");
jQuery("#searchheadertext").show();
}
else
{  jQuery("div.productRecommendation").hide();
}

document.getElementById(div_id).innerHTML= html;
}

function Juicy_ATC_zpf(a_product_ids,            // Array of recommended product IDs
        zone,                  // Zone ID specified in the request (as entered on zone edit screen)
        symbolic,              // Target type:
                               //      _SP_  Specified Product ID
                               //      _SC_  Specified Category ID
                               //      _RVP_ Most Recently Viewed Product
                               //      _RPP_ Most Recently Purchased Product
                               //      _NR_  No Recommendations
                               //      _LCP_ Last Carted Product
                               //      _MPC_ Visitor's Most Popular Category
                               //      _SS_  Specified Search Term
        target_id,             // Target ID recommendations are based on
        category,              // Category of Target ID - EPR Category ID if the Target ID is a product
        rec_attributes,        // 2 dimensional array of attributes for each recommendation
        target_attributes,     // Array of attribute for the target
        target_header_txt,     // Header text (as entered on recommendation plan edit screen)
        ab_test_id,            // String containing AB Test Name, a semicolon, AB test ID for the test element requested
                               //      Null if no AB Test
                               // 
                               // The final 2 parameters are not standard parameters passed into zone population function
                               // They ared added via the function calls at bottom of this file
        div_id,                //      div id - must match desired div id in DW isml template
        b_display_target)      //      indicates whether target will be displayed

{
var html = " ";

if (symbolic !== '_NR_')
{
// !!CLIENT DEPENDENT!! - use the correct attribute for description (array indices are zero based so first attribute is index 0)
var i_description = 0;
// !!CLIENT DEPENDENT!! - use the correct attribute for image (array indices are zero based so first attribute is index 0)
var i_image_url   = 1;
// !!CLIENT DEPENDENT!! - image prefix
var image_prefix  = '';

var i_href        = undefined;
var i_score       = undefined;
var i_price       = undefined;

var div_recs    = '<div class="io_test_recs"\>';
var n_recs      = 2;
var qty = document.getElementById("qty").innerHTML;

if(qty == '"1"')
{
	n_recs = 4;	
}

var div_title   = '<h2>' + target_header_txt + '<\/h2>';
var div_table   = '<div class="io_recs_table">';
var image_table = '<TABLE CELLSPACING="2" CELLPADDING="0" Align="center" style="border-color:white;">';
var lines       = [];
var width       = 100 / n_recs;


// if true display the target (first) as well as the recommendations
if (b_display_target)
{
rec_attributes.unshift(target_attributes);         // push target onto front of rec_attributes array
n_recs++;
}

// Recommendations
for (var ii=0; ii < n_recs; ii++)
{
	 try{
		var rec_prod_id       = b_display_target ? (ii == 0 ? target_id : a_product_ids[ii - 1]) : a_product_ids[ii];
		
		var selected_href     = image_prefix + rec_attributes[ii][2];                                               // - not passed - href for image
		
		var image_description = rec_attributes[ii][i_description];                 // product description
		var image_url         = image_prefix + rec_attributes[ii][i_image_url];    // image url
		
		var alt_description   = image_description;
		if (!image_description)
		{
		   alt_description   = 'No Image Available';
		   image_description   = '&nbsp;';
		}
		
		var attr_1     = rec_attributes[ii][0] ? rec_attributes[ii][0] : '-';
		var attr_2     = rec_attributes[ii][1] ? rec_attributes[ii][1] : '-';
		var attr_3     = rec_attributes[ii][2] ? rec_attributes[ii][2] : '-';
		var attr_4     = rec_attributes[ii][3] ? rec_attributes[ii][3] : '-';
		var attr_5     = rec_attributes[ii][4] ? rec_attributes[ii][4] : '-';
		var attr_6     = rec_attributes[ii][5] ? rec_attributes[ii][5] : '-';
		var attr_7     = rec_attributes[ii][6] ? rec_attributes[ii][6] : '-';
		var attr_8     = rec_attributes[ii][7] ? rec_attributes[ii][7] : '-';
		var attr_9     = rec_attributes[ii][8] ? rec_attributes[ii][8] : '-';
		var attr_10    = rec_attributes[ii][9] ? rec_attributes[ii][9] : '-';
		var attr_11    = rec_attributes[ii][10] ? rec_attributes[ii][10] : '-';
		var attr_12    = rec_attributes[ii][11] ? rec_attributes[ii][11] : '-';
		var attr_13    = rec_attributes[ii][12] ? rec_attributes[ii][12] : '-';
		var attr_14    = rec_attributes[ii][13] ? rec_attributes[ii][13] : '-';
		var attr_15    = rec_attributes[ii][14] ? rec_attributes[ii][14] : '-';
		
		
		
		// Display image and it's description
        var showStandardPrice = "";
        var showPriceRange = "";
        var standardPrice = null;
        var salePrice = null;
        var PriceRange = null;	

		lines.push('<div class="rec"><A HREF="' + selected_href +'&navid=xsellCart'+'"><IMG SRC="' + image_url + '" + ALT="' + alt_description + '" + style="border: medium none; cursor: pointer;" />');
		lines.push('<A STYLE="text-decoration:none" HREF="' + selected_href +'&navid=xsellCart'+'">' + image_description + '<\/A>');
 		var url = app.util.appendParamToURL(app.URLs.getPricing,"pid", a_product_ids[ii]);
		app.ajax.getJson({
			dataType: "json",
			url: url,
			async	: false,
			callback: function(data) {
				if (!data) {
					return;
				}
				showStandardPrice = data.pricing.isShowStandardPrice;
				ShowPriceRange = data.pricing.isShowPriceRange;
				PriceRange = data.pricing.PriceRange;
				standardPrice =  data.pricing.standard;	
				salePrice =  data.pricing.sale;
			}
		});
		if(showStandardPrice==true){
			if(salePrice != "null" && salePrice != "$0.00" && standardPrice != "$null" && standardPrice != "$0.00"){
			lines.push('<div class="price"><div class="salesprice">'+salePrice+'<\/div><div class="standardprice">'+standardPrice+'<\/div><\/div>');
			}
		}
		else if(ShowPriceRange == false && showStandardPrice == false){
			if(standardPrice != "$null" && standardPrice != "$0.00"){
			lines.push('<div class="price"><div class="standardprice">'+standardPrice+'<\/div><\/div>');
			}
		}
		else if(ShowPriceRange==true){
			if(PriceRange != "$null - $null" && PriceRange != "$0.00 - $0.00"){
			lines.push('<div class="price"><div class="standardprice">'+PriceRange+'<\/div><\/div>');
			}
		}		
		lines.push('<\/div>');


	 } catch(e){break;}
}

// make a text string
	if(jQuery("h2").parents("#cartrecommendations_cross-sell").length > 0){	html = lines.join("\n");}
	else{html = div_title+ lines.join("\n");}
}
else
{
	jQuery("div#recommendationoncart").hide();
}
var listsize = jQuery("div.rec").size();
//alert(listsize);
if(listsize < 4){
	document.getElementById(div_id).innerHTML+= html;
}

}
// !!CLIENT DEPENDENT!! - add a function named ZoneID_zp (where ZoneID is the actual zone id) for all zones the Juicy zpf should be called for 
function PDPZ1_zp(a,b,c,d,e,f,g,h,i)  
{
   Juicy_PDP_zpf(a,b,c,d,e,f,g,h,i,'pdp_cross-sell',true);
}
function CPZ1_zp(a,b,c,d,e,f,g,h,i)  
{
   Juicy_ATC_zpf(a,b,c,d,e,f,g,h,i,'cartrecommendations_cross-sell',false);
}
function SPZ1_zp(a,b,c,d,e,f,g,h,i)  
{
   Juicy_SP_zpf(a,b,c,d,e,f,g,h,i,'pdp_cross-sell',false);
}
