function strEndsWith(str, suffix) {
    return str.match(suffix+"$")==suffix;
}


function test_zpfs(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)      //      indicates whether target will be displayed

{

   var n_recs      = a_product_ids.length;
   var lines       = [];
   var html        = '';

   if (symbolic !== '_NR_')
   {
      // Recommendations
      for (var ii=0; ii < n_recs; ii++)
      {
         var rec_prod_id    =  a_product_ids[ii];
         var productName    =  rec_attributes[ii][0];
         var imageUrl       =  rec_attributes[ii][1];         
         var price          =  parseFloat(rec_attributes[ii][4]);       
         var listPrice      =  parseFloat(rec_attributes[ii][5]);
         var minPrice       =  parseFloat(rec_attributes[ii][6]);
         var maxPrice       =  parseFloat(rec_attributes[ii][7]);
                 
         if(strEndsWith(rec_prod_id,'WC')) {
           rec_prod_id=rec_prod_id.substr(0,(rec_prod_id.length-2))
         }
         
         if(isNaN(price)) price=0.0;
         if(isNaN(listPrice)) listPrice=0.0;
         if(isNaN(minPrice)) minPrice=0.0;
         if(isNaN(maxPrice)) maxPrice=0.0;
         if (location.protocol == 'https:') {
	   imageUrl=imageUrl.replace("http", "https");
         }
         
         
         var productUrl     =  'http://'+location.hostname + '/outdoor/gear/Product___'+rec_prod_id+'?cm_vc='+zone;
	
	 //lines.push('<TD valign="top" class="borderedRollover" width=' + width + '%><div class="bordered_Rollover"><TABLE ALIGN="center" WIDTH=' + width + '%>');
	 lines.push('<div class="x_prod"><p><a href="'+productUrl+'"><img src="'+imageUrl+'" alt="'+ productName +'" border="0" height="116" width="107" /></a></p>');
	 lines.push('<p><a href="'+productUrl+'">'+productName+'</a></p>');
	 lines.push('<p>Item #: '+rec_prod_id+'</p>');
	 lines.push('<p>Our Price:');
	 
	 if( minPrice < maxPrice) {	     
	     lines.push('$'+minPrice.toFixed(2) + ' - ' + '$'+maxPrice.toFixed(2)+'</p>');
	 } else {
	     lines.push('$'+price.toFixed(2) +'</p>');
	     if(listPrice>price) {
	       lines.push('<p>Regular Price:$'+listPrice.toFixed(2) +'</p>');
	       lines.push('<p>Savings:$'+ (listPrice - price).toFixed(2) + '</p>');	           
	     }
	 }
	 	
	 lines.push('<\/div>');	 		
      }
      // make a text string
      html = lines.join("\n");
    }
    
    document.getElementById('io_pdpz1').innerHTML= html;
}


function pdpz2_zpfs(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)      //      indicates whether target will be displayed

{

   var n_recs      = a_product_ids.length;
   var lines       = [];
   var html        = '';

   if (symbolic !== '_NR_')
   {
      lines.push('<br/><table cellpadding="0" cellspacing="0" border="0"><tbody><tr class="first"></tr><tr class="first"><td><h2>Accessories</h2></td></tr>')
      
      // Recommendations
      for (var ii=0; ii < n_recs; ii++)
      {
         var rec_prod_id    =  a_product_ids[ii];
         var productName    =  rec_attributes[ii][0];
         var imageUrl       =  rec_attributes[ii][1];         
         var price          =  parseFloat(rec_attributes[ii][4]);       
         var listPrice      =  parseFloat(rec_attributes[ii][5]);
         var minPrice       =  parseFloat(rec_attributes[ii][6]);
         var maxPrice       =  parseFloat(rec_attributes[ii][7]);
         
         if(strEndsWith(rec_prod_id,'WC')) {
           rec_prod_id=rec_prod_id.substr(0,(rec_prod_id.length-2))
         }         
         
         if(isNaN(price)) price=0.0;
         if(isNaN(listPrice)) listPrice=0.0;
         if(isNaN(minPrice)) minPrice=0.0;
         if(isNaN(maxPrice)) maxPrice=0.0;
         if (location.protocol == 'https:') {
	   imageUrl=imageUrl.replace("http", "https");
         }
         
         var productUrl     =  'http://'+location.hostname + '/outdoor/gear/Product___'+rec_prod_id+'?cm_vc='+zone;
		 
	 lines.push('<tr><td class="thumb"><div class="thumb_prod"><a href="'+ productUrl+'"><img width="65" height="70" border="0" alt="'+productName+ '" src="'+imageUrl+'"/></a></div></td>');	 
	 lines.push('<td><a href="'+productUrl+'">'+productName+'</a><br/>Item #: '+ rec_prod_id+'<br/>');
	 	 	 	
	 lines.push('<b>Our Price:');
	 
	 if( minPrice < maxPrice) {	     
	     lines.push('$'+minPrice.toFixed(2) + ' - ' + '$'+maxPrice.toFixed(2)+'</b><br/>');
	 } else {
	     lines.push('$'+price.toFixed(2) +'</b><br/>');
	     if(listPrice>price) {
	       lines.push('Regular Price:$ '+listPrice.toFixed(2) +'<br/>');
	       lines.push('Savings:$ '+ (listPrice - price).toFixed(2) + '<br/>');	           
	     }
	 }	 	
	 lines.push('</td></tr>');	 		
      }
      lines.push('</tbody></table>');
      // make a text string
      html = lines.join("\n");
    }
    
    document.getElementById('io_pdpz2').innerHTML= html;
}

// !!CLIENT DEPENDENT!!
// Add a function named ZoneID_zp (where ZoneID is the actual zone id) for all zones the test zone population function should be called for 
function PDPZ1_zp(a,b,c,d,e,f,g,h,i)  
{
   test_zpfs(a,b,c,d,e,f,g,h,i);
}
function PDPZ2_zp(a,b,c,d,e,f,g,h,i)  
{
   pdpz2_zpfs(a,b,c,d,e,f,g,h,i);
}
function CARTZ1_zp(a,b,c,d,e,f,g,h,i)
{
   test_zpfs(a,b,c,d,e,f,g,h,i);
}
function HomeZ1_zp(a,b,c,d,e,f,g,h,i)
{
   test_zpfs(a,b,c,d,e,f,g,h,i);
}

