function buildProdUrl(prod_url){
	if (prod_url){
		var url = 'http://' + location.host + prod_url.substring(23);
		return url;
	}
}

function price_div (lines, mfrPrice, kgPrice, price, promo){
		 if (promo !== 'NA'){
			 lines.push('<div class="save-100 transparent clearfix">');
			 lines.push('<p class="save-copy">');
			 lines.push(promo);
			 lines.push('</p>');
			 lines.push('</div>');
		 }
		 
		 if (mfrPrice - kgPrice >0 && mfrPrice - price > 0){
			 lines.push('<div class="mfrPrice labelValueSet">');
			 lines.push('<div class="priceLabel">Compare at</div>');
			 lines.push('<div class="price">'+'$'+parseFloat(mfrPrice).toFixed(2)+'</div>');
		     lines.push('</div>');
		 }

		 if (kgPrice - price > 0){
		 	 lines.push('<div class="kgPrice labelValueSet">');
			 lines.push('<div class="priceLabel">K&amp;G price</div>');
			 lines.push('<div class="price">'+'$'+parseFloat(kgPrice).toFixed(2)+'</div>');
		     lines.push('</div>');
	     }
	     
		 lines.push('<div class="todayPrice labelValueSet">');
		 if (kgPrice - price > 0)
			 lines.push('<div class="priceLabel">Today\'s price</div>');
	     else 
	         lines.push('<div class="priceLabel">K&amp;G price</div>');
	         
	     if (price - 0 < 99999)    
			 lines.push('<div class="price">'+'$'+parseFloat(price).toFixed(2)+'</div>');
			 
	     lines.push('</div>');
	     
	     return lines;
}

function FB1_LP_zpf(a_product_ids,
                     zone,
                     symbolic,
                     target_id,
                     category,
                     rec_attributes,
                     target_attributes,
                     target_header_txt,
                     div_id,
                     b_display_target)
{
   var html = ""; //zone + "_zp: No recommendations returned";

   b_display_target = false;

   if (symbolic !== '_NR_')
   {
      // attribute indicies for example
      var i_description = 0;
      var i_image_url   = 4;
      var i_href        = undefined;
      var i_score       = undefined;
      var i_price       = undefined;

      // special case.  Over ride of the header text passed from the configuration file
      target_header_txt = "You May Also Like";

      var div_recs    = '<div class="contentR">';  
      var n_recs      = a_product_ids.length;
      var div_title   = '<h2 class="alsoLikeHeader">' + target_header_txt + '</h2>';
      var div_table   = '<div id="alsoLike">';  
      var image_table = '';  
      var lines       = [];
      var width       = 100 / n_recs;

      // for Chris
      if (b_display_target)
      {
         rec_attributes.unshift(target_attributes);
         n_recs++;
      }

      // Recommendations
      for (var ii=0; ii < 3; ii++)   //n_recs; ii++)
      {

         var rec_prod_id       = b_display_target ? (ii == 0 ? target_id : a_product_ids[ii - 1]) : a_product_ids[ii];
         var image_description = rec_attributes[ii][0];            // product description
         var alt_description   = image_description;

         var mfrPrice          = rec_attributes[ii][1];            // href for image
         var kgPrice           = rec_attributes[ii][2];            // price
         var price             = rec_attributes[ii][3];            
         var image_url         = rec_attributes[ii][4] + '?$grid$';            
         var prod_url          = rec_attributes[ii][5];
         var promo 			   = rec_attributes[ii][6];	

         prod_url = buildProdUrl(prod_url);
               
         if (b_display_target)
         {
            prod_id_row = rec_prod_id; 

            if (ii === 0)
            {
               image_description = '<B>TARGET:</B> ' + image_description;
            }                                                           
         }

         if (!rec_attributes[ii][4])
         {
            alt_description   = 'No Image Available';
         }
		
		 lines.push('<div class="gridProduct">');
		 lines.push('<div class="gridImgHolder"> ');
		 lines.push('<a href="' + prod_url + cm_vc +'">');
		 lines.push('<img src="' + image_url + '" width="229px" height="306px" alt="' + image_description + '" class="prodImg"/>'); 
 		 lines.push('</a>');
		 lines.push('</div>');
		 
		 lines.push('<div class="grid-product-details">');
		 lines.push('<p> <a href="' + prod_url + cm_vc + '" >' + image_description + '</a></p>');
//		 lines.push('<div class="divider"><!-- --></div> ');

		 lines = price_div(lines, mfrPrice, kgPrice, price, promo);
		 lines.push('</div>');
	 	 lines.push('</div>');
      }

      html_gridHeader = '<div class="gridHeader"><div class="gridTitle">Featured</div><div class="gridMore"></div></div>'
      html_gridProdHeader = '<div class="product-grid"><div class="grid-row">';;
      html_gridProdHeaderEnd = '</div></div>';
      
      html_prodSample = '<div class="gridProduct"><div class="gridImgHolder"><a class="quickViewLink" href="#"><img src="./images/placeholder_prod_grid_med1.png" width="229px" height="306px" alt="Product Name" class="prodImg"></a> </div></div>';
      
      
      html = //'<div id="contentT"><!-- &nbsp; --></div><div id="contentM">' 
      		 html_gridHeader  
      		 //+ html_gridProdHeader
      		 + html_gridProdHeader
      		 	+ lines.join("\n")
      		 + html_gridProdHeaderEnd
      		 ;
      		 //+ '</div><div id="contentB"><!-- --></div>';
   }

   document.getElementById(div_id).innerHTML= html;
}


function FB1_HM_zpf(a_product_ids,
                     zone,
                     symbolic,
                     target_id,
                     category,
                     rec_attributes,
                     target_attributes,
                     target_header_txt,
                     div_id,
                     b_display_target)
{
   var html = ''; //zone + "_zp: No recommendations returned";

   b_display_target = false;

   if (symbolic !== '_NR_')
   {
      // attribute indicies for example
      var i_description = 0;
      var i_image_url   = 4;
      var i_href        = undefined;
      var i_score       = undefined;
      var i_price       = undefined;

      // special case.  Over ride of the header text passed from the configuration file
      target_header_txt = "You May Also Like";

      var div_recs    = '<div class="contentR">';  
      var n_recs      = a_product_ids.length;
      var div_title   = '<h2 class="alsoLikeHeader">' + target_header_txt + '</h2>';
      var div_table   = '<div id="alsoLike">';  
      var image_table = '';  
      var lines       = [];
      var width       = 100 / n_recs;

      // for Chris
      if (b_display_target)
      {
         rec_attributes.unshift(target_attributes);
         n_recs++;
      }

      // Recommendations
      for (var ii=0; ii < 4; ii++)   //n_recs; ii++)
      {
         var rec_prod_id       = b_display_target ? (ii == 0 ? target_id : a_product_ids[ii - 1]) : a_product_ids[ii];
         var image_description = rec_attributes[ii][0];            // product description
         var alt_description   = image_description;

         var mfrPrice          = rec_attributes[ii][1];            // href for image
         var kgPrice           = rec_attributes[ii][2];            // price
         var price             = rec_attributes[ii][3];            
         var image_url         = rec_attributes[ii][4] + '?$grid$';            
         var prod_url          = rec_attributes[ii][5];
         
         var promo 			   = rec_attributes[ii][6];	
         
         prod_url = buildProdUrl(prod_url);
               
         if (b_display_target)
         {
            prod_id_row = rec_prod_id; 

            if (ii === 0)
            {
               image_description = '<B>TARGET:</B> ' + image_description;
            }                                                           
         }

         if (!rec_attributes[ii][4])
         {
            alt_description   = 'No Image Available';
         }
		
		 lines.push('<div class="gridProduct">');
		 //lines.push('<div class="alsoImgHolder"> ');
		 lines.push('<a href="' + prod_url + cm_vc + '">');
		 lines.push('<img src="' + image_url + '" width="229px" height="306px" alt="' + image_description + '" class="prodImg"/>'); 
 		 lines.push('</a>');
		 //lines.push('</div>');
		 
		 lines.push('<div class="grid-product-details">');
 		 lines.push('<p> <a href="' + prod_url + cm_vc + '" >' + image_description + '</a></p>'); //lines.push('<p>' + image_description + '</p>');
//		 lines.push('<div class="divider"><!-- --></div> ');

		 lines = price_div(lines, mfrPrice, kgPrice, price, promo);
	     
		 lines.push('</div>');
	 	 lines.push('</div>');
      }

      html_gridHeader = '<div class="gridHeader"><div class="gridTitle">Featured</div><div class="gridMore"></div></div>'
      html_gridProdHeader = '<div class="product-grid">';   //<div class="grid-row">';;
      html_gridProdHeaderEnd = '</div>';   //</div>';
      
      html_prodSample = '<div class="gridProduct"><div class="gridImgHolder"><a class="quickViewLink" href="#"><img src="./images/placeholder_prod_grid_med1.png" width="229px" height="306px" alt="Product Name" class="prodImg"></a> </div></div>';
      
      
      html = '<div id="contentT"><!-- &nbsp; --></div><div id="contentM">' 
      		 + html_gridHeader  
      		 + html_gridProdHeader
      		 	+ lines.join("\n")
      		 + html_gridProdHeaderEnd
      		 
      		 + '</div><div id="contentB"><!-- --></div>';
   }

   document.getElementById(div_id).innerHTML= html;
}


function PDPZ1_zpf(a_product_ids,
                     zone,
                     symbolic,
                     target_id,
                     category,
                     rec_attributes,
                     target_attributes,
                     target_header_txt,
                     div_id,
                     b_display_target)
{
   var html = ""; //zone + "_zp: No recommendations returned";
   b_display_target = false;

   if (symbolic !== '_NR_')
   {
      // attribute indicies for example
      var i_description = 0;
      var i_image_url   = 4;
      var i_href        = undefined;
      var i_score       = undefined;
      var i_price       = undefined;

      // special case.  Over ride of the header text passed from the configuration file
      target_header_txt = "You May Also Like";

      var div_recs    = '<div class="contentR">';  
      var n_recs      = a_product_ids.length;
      var div_title   = '<h2 class="alsoLikeHeader">' + target_header_txt + '</h2>';
      var div_table   = '<div id="alsoLike">';  
      var image_table = ''; 
      var lines       = [];
      var width       = 100 / n_recs;

      // for Chris
      if (b_display_target)
      {
         rec_attributes.unshift(target_attributes);
         n_recs++;
      }
      // Recommendations
      for (var ii=0; ii < n_recs; ii++)
      {

         var rec_prod_id       = b_display_target ? (ii == 0 ? target_id : a_product_ids[ii - 1]) : a_product_ids[ii];
         var image_description = rec_attributes[ii][0];            // product description
         var alt_description   = image_description;

         var mfrPrice          = rec_attributes[ii][1];            // href for image
         var kgPrice           = rec_attributes[ii][2];            // price
         var price             = rec_attributes[ii][3];            
         var image_url         = rec_attributes[ii][4] + '?$grid$';            
         var prod_url          = rec_attributes[ii][5];
         var promo 			   = rec_attributes[ii][6];	
         
         prod_url = buildProdUrl(prod_url);

         if (b_display_target)
         {
            prod_id_row = rec_prod_id;  

            if (ii === 0)
            {
               image_description = '<B>TARGET:</B> ' + image_description;
            }                                                           
         }

         if (!rec_attributes[ii][4])
         {
            alt_description   = 'No Image Available';
         }
	
		 lines.push('<div class="alsoProduct">');
		 lines.push('<div class="alsoImgHolder"> ');
		 lines.push('<a href="' + prod_url + cm_vc + '">');
		 lines.push('<img src="' + image_url + '" width="188" height="251" alt="' + image_description + '" class="prodImg"/>'); 
 		 lines.push('</a>');
//		 lines.push('<span class="tag-clearance transparent">&nbsp;</span>');
		 lines.push('</div>');
 		 lines.push('<p> <a href="' + prod_url + cm_vc + '" >' + image_description + '</a></p>'); 
		 lines.push('<div class="divider"><!-- --></div> ');
		 
		 //lines = price_div(lines, mfrPrice, kgPrice, price, promo);  // comment out to hide price diff from the day before.
		 
		 lines.push('</div>');
      }

      html = div_recs + div_title + div_table + image_table + lines.join("\n") + '<\/div\><\/div\>';
   }

   document.getElementById(div_id).innerHTML= html;
}

function CARTZ1_zpf(a_product_ids,
                     zone,
                     symbolic,
                     target_id,
                     category,
                     rec_attributes,
                     target_attributes,
                     target_header_txt,
                     div_id,
                     b_display_target)
{
   var html = ''; //zone + "_zp: No recommendations returned";

   b_display_target = false;

   if (symbolic !== '_NR_')
   {
      // attribute indicies for example
      var i_description = 0;
      var i_image_url   = 4;
      var i_href        = undefined;
      var i_score       = undefined;
      var i_price       = undefined;

      // special case.  Over ride of the header text passed from the configuration file
      target_header_txt = "You May Also Like";

      var div_recs    = '<div class="contentR">'; 
      var n_recs      = a_product_ids.length;
      var div_title   = '<h2 class="alsoLikeHeader">' + target_header_txt + '</h2>';
      var div_table   = '<div id="alsoLike">'; 
      var image_table = '';  
      var lines       = [];
      var width       = 100 / n_recs;

      // for Chris
      if (b_display_target)
      {
         rec_attributes.unshift(target_attributes);
         n_recs++;
      }

      // Recommendations
      for (var ii=0; ii < n_recs; ii++)
      {

         var rec_prod_id       = b_display_target ? (ii == 0 ? target_id : a_product_ids[ii - 1]) : a_product_ids[ii];
         var image_description = rec_attributes[ii][0];            // product description
         var alt_description   = image_description;

         var mfrPrice          = rec_attributes[ii][1];            // href for image
         var kgPrice           = rec_attributes[ii][2];            // price
         var price             = rec_attributes[ii][3];            
         var image_url         = rec_attributes[ii][4] + '?$grid$';            
         var prod_url          = rec_attributes[ii][5];
         var promo 			   = rec_attributes[ii][6];	
         
         prod_url = buildProdUrl(prod_url);
               
         https_prefix = 'https://a248.e.akamai.net/f/248/9086/10h/origin-';      
         image_url = https_prefix + image_url.substr(9);      
         if (b_display_target)
         {
            prod_id_row = rec_prod_id; 

            if (ii === 0)
            {
               image_description = '<B>TARGET:</B> ' + image_description;
            }                                                           
         }

         if (!rec_attributes[ii][4])
         {
            alt_description   = 'No Image Available';
         }
		
		 lines.push('<div class="alsoProduct">');
		 lines.push('<div class="alsoImgHolder"> ');
		 lines.push('<a href="' + prod_url + cm_vc + '">');
		 lines.push('<img src="' + image_url + '" width="188" height="251" alt="' + image_description + '" class="prodImg"/>'); 
 		 lines.push('</a>');
//		 lines.push('<span class="tag-clearance transparent">&nbsp;</span>');
		 lines.push('</div>');
 		 lines.push('<p> <a href="' + prod_url + cm_vc + '" >' + image_description + '</a></p>'); 
		 lines.push('<div class="divider"><!-- --></div> ');
		 
		 
		 // lines = price_div(lines, mfrPrice, kgPrice, price, promo);	 //comment out to hide price diff from the day before.
		 lines.push('</div>');
      }

      html = div_recs + div_title + div_table + image_table + lines.join("\n") + '<\/div\><\/div\>';
   }

   document.getElementById(div_id).innerHTML= html;
}

function FB1_zp(a,b,c,d,e,f,g,h)
{
	if (d == 'HOME'){
	    FB1_HM_zpf(a,b,c,d,e,f,g,h,'io_zone_1',true);
	}

	if (d == 'ERROR'){
	    FB1_HM_zpf(a,b,c,d,e,f,g,h,'io_zone_1',true);
	}

	if (   d == 'KNG_MENS'.toUpperCase() 
	    || d == 'kng_womens'.toUpperCase()
	    || d == 'kng_kids'.toUpperCase()){
	    FB1_LP_zpf(a,b,c,d,e,f,g,h,'io_zone_1',true);
	}
}

function PDPZ1_zp(a,b,c,d,e,f,g,h)
{
   if (cmioYMAL == 'on'){
   		PDPZ1_zpf(a,b,c,d,e,f,g,h,'io_zone_1',true);
   	}
}

function CARTZ1_zp(a,b,c,d,e,f,g,h)
{
   if (cmioYMAL == 'on')
   		CARTZ1_zpf(a,b,c,d,e,f,g,h,'io_zone_1',true);
}

function prodtest_zp(a,b,c,d,e,f,g,h)
{
   example_zpf(a,b,c,d,e,f,g,h,'io_zone_1',true);
}

function ProdTestQ_zp(a,b,c,d,e,f,g,h)
{
   example_zpf(a,b,c,d,e,f,g,h,'io_zone_1',true);
}
function CartTest_zp(a,b,c,d,e,f,g,h)
{
   example_zpf(a,b,c,d,e,f,g,h,'io_zone_1',true); 
}

function SiteTest_zp(a,b,c,d,e,f,g,h) 
{
   example_zpf(a,b,c,d,e,f,g,h,'io_zone_1',true); 
}

function EPRTest_zp(a,b,c,d,e,f,g,h) 
{
   example_zpf(a,b,c,d,e,f,g,h,'io_zone_1',true); 
}

function ProdPage_zp(a,b,c,d,e,f,g,h)  
{
   example_zpf(a,b,c,d,e,f,g,h,'io_zone_1',false); 
}

function CartPage_zp(a,b,c,d,e,f,g,h)  
{
   example_zpf(a,b,c,d,e,f,g,h,'io_zone_2',false); 
}
