/*** PB/SC FUNCTIONS AREA ***/
/* Functions Petit Bateau / SiteCatalyst */
/* Copyright Petit Bateau - Juin 2009 */

/* Function looking for a string in current age */
/* Make sure to put the searched 'str' var within the header area */
/* Otherwise, it would be retrieved (inside the function call!) */
/*
function pb_searchThisPage(str) {
  var page = new String(document.body.innerHTML);
  return page.indexOf(str);
  }
*/

/* Function Identifying the Default Color Image */
/*
function  pb_getDefaultImage(kw) {
  return document.getElementById(kw).getElementsByTagName('script').innerHTML;
  }
*/

/* Function returning the Default Color of current product */
function pb_colorDefault(proData) { 
  return new String(proData.substring(22, 24));
  }

/* Function returning the Color of selected item */
function pb_color(proData) { 
   return new String(proData.substring(5, 7));
  }

/* Function returning the Size of the selected item */
  function pb_size(proData) { 
  return new String(proData.substring(7));
  }

/* Function formatting Order Items as required by SiteCatalyst */
/* ObjectVersion */
function pb_productItems(productItems) {
  var pb_orderItem = new String('');
  for (x in productItems) {
    if (productItems[x].productId) { var pb_orderItemRct = new String(productItems[x].productId); }
    else { var pb_orderItemRct   = new String(productItems[x].shift()); }
    if (productItems[x].quantity) { var pb_orderItemQty = new Number(productItems[x].quantity); }
    else { var pb_orderItemQty = new Number(productItems[x].pop()); }
    if (productItems[x].price) { var pb_orderItemPrice = new Number(productItems[x].price); }
    else { var pb_orderItemPrice = new Number(productItems[x].slice(3)); }
    var pb_orderItemColor = new String(pb_orderItemRct.substring(5,7));
    var pb_orderItemSize  = new String(pb_orderItemRct.substring(7));
    var pb_orderItemQtyPrice = new Number(pb_orderItemQty * pb_orderItemPrice);
    
    var pb_orderItem = pb_orderItem + new String(
      pb_orderItemRct + ';' + 
      pb_orderItemQty + ';' + 
      pb_orderItemQtyPrice + ';;eVar9=' +
      pb_orderItemSize + '|eVar10=' +
      pb_orderItemColor + ',;'
      );
    }
    return pb_orderItem;
  }

  /* Function returning the value of the Gift Service */
function pb_productItemsGift(productItems) {
  var pb_orderItemGift = new String('');    
  for (x in productItems) {
    if (productItems[x].productId) { var pb_orderItemRct = new String(productItems[x].productId); }
    else { var pb_orderItemRct  = new String(productItems[x].shift()); }
    if (productItems[x].quantity) { var pb_orderItemQty = new String(productItems[x].quantity); }
    else { var pb_orderItemQty = new String(productItems[x].pop()); }
    if (productItems[x].price) { var pb_orderItemPrice = new String(productItems[x].price); }
    else { var pb_orderItemPrice = new String(productItems[x].slice(3)); }
    if (pb_orderItemRct == 'kdo') { var pb_orderItemGift = '|event5=' + pb_orderItemPrice; break; }
    }
  return pb_orderItemGift;
  }
  
/* Function formatting Cart Item 
 * @param Array of seoDataCarItem 
 * @type String 
 */
 function pb_formatIdItems(seoDataCartItems) {
 	var idItemsStr = ";";
 	for(var i in seoDataCartItems) {
 		if (i > 0) idItemsStr = idItemsStr + ",;";
 		var seoDataCartItem = seoDataCartItems[i];
 		idItemsStr = idItemsStr + seoDataCartItem.productId;
 	}
 	return idItemsStr;
 }

/*** EO PB/SC FUNCTIONS AREA ***/