
function setCrossSellCookie(name, value, expires) {
	document.cookie = name + "=" + escape(value) + "; path=/" + ((expires == null) ? "" : "; expires=" + expires);
	document.cookie=name+"="+value+"; expires=Mon,06Jun2022:00:00:00; path=/ domain=officedesigns.com;";
}

/*
 * Product Page Zone 1
 */
function product_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";
   var html = "...";

   if (symbolic !== '_NR_'){
      // attribute indicies for example
      var i_description = 0;
      var i_image_url   = 2;
      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 = "";

      var div_recs    = '';
      var n_recs      = a_product_ids.length;
      var div_title   = target_header_txt + '';
      var div_table   = '<div class="io_recs_table">';
      var image_table = '';
      var lines       = [];
      var width       = 100 / n_recs;

      // 0 product description 
      // 1 price
      // 2 image path
      // 3 not defined
      // 4 not defined

      // 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 selected_href     = 'http://www.officedesigns.com/product-exec/product_id';                                  // 
         var price             = '$' + rec_attributes[ii][1];         // 
         var n_stars           = 2 + Math.floor(Math.random() * 3);   // 
         var category          = rec_attributes[ii][1];               // 
         var image_url         = rec_attributes[ii][i_image_url];     // image url
         var alt_description   = image_description;
         var prod_id_row       = '';

         if (b_display_target){
            prod_id_row = rec_prod_id;                                                                                                                                                                                              

            if (ii === 0){
               image_description = 'Targeter Item' + image_description;
            }                                                           
         }

         if (!rec_attributes[ii][2]){
            alt_description   = 'No Image Available';
         }
        
		lines.push('<div style="float:left; padding:0 5px 0 5px; width:170px; text-align:center;"><a class="cross-sell-link" onclick="javascript:setCrossSellCookie(\'crossSell\', \'' + rec_prod_id + '\', \'6000\');" href="' + selected_href + '/' + rec_prod_id + '/pn/' + image_description + '"><IMG SRC="' + image_url + '" ALT="' + alt_description + '" height="60" style="border: medium none; cursor: pointer;" /><br />' + image_description + ' ' + price + '</a></div>');
		
      }

      // make a text string 
      html = div_recs + div_title + div_table + image_table + lines.join("\n") + '<\/div\>';
   }

   document.getElementById(div_id).innerHTML= html;
}



/*
 * Shopping Cart Zone 1
 */
function cart_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";
   var html = "...";

   if (symbolic !== '_NR_'){
      // attribute indicies for example
      var i_description = 0;
      var i_image_url   = 2;
      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 Might Also Consider";

      var div_recs    = '';
      var n_recs      = a_product_ids.length;
      var div_title   = target_header_txt + '<br /><br />';
      var div_table   = '<div class="io_recs_table">';
      var image_table = '';
      var lines       = [];
      var width       = 100 / n_recs;

      // for Chris
      if (b_display_target){
         rec_attributes.unshift(target_attributes);
         n_recs++;
      }

      // Recommendations
	  // 0 product description 
      // 1 price
      // 2 image path
      // 3 not defined
      // 4 not defined
      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 selected_href     = 'http://www.officedesigns.com/product-exec/product_id';                                  // 
         var price             = '$' + rec_attributes[ii][1];         // 
         var n_stars           = 2 + Math.floor(Math.random() * 3);   // 
         var category          = rec_attributes[ii][1];               // 
         var image_url         = rec_attributes[ii][i_image_url];     // image url
         var alt_description   = image_description;
         var prod_id_row       = '';

         if (b_display_target){
            prod_id_row = rec_prod_id;                                                                                                                                                                                              

            if (ii === 0){
               image_description = 'Targeter Item' + image_description;
            }                                                           
         }

         if (!rec_attributes[ii][2]){
            alt_description   = 'No Image Available';
         }

         lines.push('<div style="float:left; padding:0 15px 0 15px; width:150px; text-align:center;"><a class="product_results_title" onclick="javascript:setCrossSellCookie(\'upSell\',\'' + rec_prod_id + '\', \'6000\');" href="' + selected_href + '/' + rec_prod_id + '/pn/' + image_description + '"><IMG SRC="' + image_url + '" ALT="' + alt_description + '" height="100" style="border: medium none; cursor: pointer;" /><br /><br />' + image_description + ' ' + price + '</a></div>');
      }

      // make a text string
      html = div_recs + div_title + div_table + image_table + lines.join("\n") + '<\/div\><br />';
   }

   document.getElementById(div_id).innerHTML= html;
}

function ProdPage_zp(a,b,c,d,e,f,g,h){
   product_zpf(a,b,c,d,e,f,g,h,'io_zone_1',false); 
}

function CartPage_zp(a,b,c,d,e,f,g,h)  {
   cart_zpf(a,b,c,d,e,f,g,h,'io_zone_2',false); 
}
