function rrGetCMTag(l) {
	var t = "";
	if(typeof(R3_COMMON)!=="undefined"){
		var rrPT = R3_COMMON.placementTypes;
		if (typeof(rrPT) != "undefined"){
			if (rrPT.indexOf("item") > 0) {
				if (l.indexOf("pa=content1") > 0) {t = "2000000351";}
				else if (l.indexOf("pa=content2") > 0) {t = "2000000352";}
				else if (l.indexOf("pa=content3") > 0) {t = "2000000353";}
				else if (l.indexOf("pa=content4") > 0) {t = "2000000354";}
			}else if (rrPT.indexOf("category") > 0) {
				if (l.indexOf("pa=content1") > 0) {t = "2000000361";}
				else if (l.indexOf("pa=content2") > 0) {t = "2000000362";}
				else if (l.indexOf("pa=content3") > 0) {t = "2000000363";}
				else if (l.indexOf("pa=content4") > 0) {t = "2000000364";}
			}else if (rrPT.indexOf("search") > 0) {
				if (l.indexOf("pa=content1") > 0) {t = "2000000371";}
				else if (l.indexOf("pa=content2") > 0) {t = "2000000372";}
				else if (l.indexOf("pa=content3") > 0) {t = "2000000373";}
			} else if (rrPT.indexOf("add") > 0) {
				if (l.indexOf("pa=content1") > 0) {t = "2000000381";}
				else if (l.indexOf("pa=content2") > 0) {t = "2000000382";}
			}else if (rrPT.indexOf("cart") > 0) {
				if (l.indexOf("pa=content1") > 0) {t = "2000000391";}
				else if (l.indexOf("pa=content2") > 0) {t = "2000000392";}
				else if (l.indexOf("pa=content3") > 0) {t = "2000000393";}
			}else if (rrPT.indexOf("purchase") == 1) {
				if (l.indexOf("pa=content1") > 0) {t = "2000000401";}
				else if (l.indexOf("pa=content2") > 0) {t = "2000000402";}
			}else if (rrPT.indexOf("error") > 0) {
				if (l.indexOf("pa=content1") > 0) {t = "2000000411";} 
				else if (l.indexOf("pa=content2") > 0) {t = "2000000412";}
			}
		}
	}
	return t;
}

function populatePrices(a) {
  for(var b=0,d=a.prices.length;b<d;b++){
      rrPriceBlock = []; // set a price object
      pid = a.prices[b].pid; // get the pid from the data prices object
      thisItem = 'rrItemInfoId-' + a.prices[b].pid; // get the item id from the data object placeholder from the item iteration
      rrCT = rrItemInfo[thisItem].ct; // customize tag
      rrUOM = rrItemInfo[thisItem].uom; // unit of measure
      rrLink = rrItemInfo[thisItem].link; // link
      rrItemInfo[thisItem].pid = a.prices[b].pid; // add pid to object
      rrItemInfo[thisItem].pidForDisplay = a.prices[b].pidForDisplay; // add pid for display to object

			if (a.prices[b].valid == "true") { // if JSON response object item is valid
				var bulkStr = "";
				if (a.prices[b].hasBulkPricingAvailable === "true") { // if has bulk pricing messaging
					bulkStr = rrStr.asLowAs;
				} else {
					bulkStr = rrStr.yourPrice;
				}
				if (a.prices[b].pid !== a.prices[b].pidForDisplay) { // if pid/pidfor display are different, update the sku
					$(".rrSKU" + a.prices[b].pid).html(rrStr.item + a.prices[b].pidForDisplay);
				}
			  if (a.prices[b].priceWithTax !== undefined && a.prices[b].price !== undefined) { // if there's tax, show it
					rrPriceBlock.push('<label class="price_title">' + bulkStr + '</label>');
					if (a.prices[b].price !== undefined && a.prices[b].price !== "") { // if there's a price 
						rrPriceBlock.push('<span class="untaxedAmount price">' + a.prices[b].price + ' ' + rrStr.beforeTax + rrUOM + '</span>');
					}
					rrPriceBlock.push('<span class="taxedAmount">');
					if (rrStr.wrapTax === "true") { // if wrap in parenthesis based on localization value
						rrPriceBlock.push("(" + a.prices[b].priceWithTax + ' ' + rrStr.incTax + ")");
					} else {
						rrPriceBlock.push(a.prices[b].priceWithTax + ' ' + rrStr.incTax);
					}
					rrPriceBlock.push('</span>');
				} else if (a.prices[b].priceWithTax !== undefined && a.prices[b].price == undefined) { // if tax, show tax as price
					rrPriceBlock.push('<span class="merchPrice"><label class="price_title">' + bulkStr + '</label>');
					rrPriceBlock.push('<span class="main_price">' + a.prices[b].priceWithTax + '</span>' + rrUOM + '</span>');
				} else if (a.prices[b].price !== undefined && a.prices[b].priceWithTax == undefined) { // if no tax, just show price
					rrPriceBlock.push('<span class="merchPrice"><label class="price_title">' + bulkStr + '</label>');
					rrPriceBlock.push('<span class="main_price">' + a.prices[b].price + '</span>' + rrUOM + '</span>');
				}
				rrPriceBlock.push('<input type="hidden" value="'+rrGetCMTag(rrLink)+'" name="trackingCategory">'); // add CM input tag to form for tracking
				$(".rrPriceElement" + a.prices[b].pid).html(rrPriceBlock.join('')); // join the elements of the array
				$(".item_atc_rrSKU" + a.prices[b].pid).html(a.prices[b].pidForDisplay); // update the pid for display
				if (rrCT !== "") { 
				$("div.moduleStructContent .rrCustomBtn" + a.prices[b].pid).show(); // if there's a customize button show it
			} else { // show the regular pricing data
				$(".rrAddCartBtnDisplay" + a.prices[b].pid).val(rrStr.atc); // get the localized string for add to cart
				$("ul.rrAddCartBtn" + a.prices[b].pid).show(); // show the add to cart button
			}
		} else {
			$(".item_atc_rrSKU" + a.prices[b].pid).html(a.prices[b].pidForDisplay); // update the pid for display
			$(".rrPriceElement" + a.prices[b].pid).html('<div class="skuAvailability">' + rrStr.skuAvailability + '</div>'); // show localized availability message
		}
	}
	if (typeof(odCarousel)=="function"){odCarousel();} // if carousel is on page, call it after pricing fires off
}

function setQtyChange(){
  if (typeof jQuery != 'undefined') {
    $("div.moduleStruct div.moduleStructContent ul.products li.merch_block ul.quantity_box input.input").change(function () {
      if($(this).val()>0){
        attrStr="";
          attrStr = $(this).attr("id").replace("rrQtyBoxATC_", "");  // if the new format, use the new class name          
          rrClick = [];
          rrClick[1] = new Image();
          rrClick[1].src = rrItemInfo['rrItemInfoId-' + attrStr].link; // use the new link value
      }
    });
  }
}
            
function rrSetLink(pid) {
  if (typeof(rrItemInfo['rrItemInfoId-' + pid].pid) !== "undefined") {
    pid = rrItemInfo['rrItemInfoId-' + pid].pid;
    pidForDisplay = rrItemInfo['rrItemInfoId-' + pid].pidForDisplay;
    ct = rrItemInfo['rrItemInfoId-' + pid].ct;
    link = rrItemInfo['rrItemInfoId-' + pid].link;
    link = link.replace('id%3D' + pid, 'id%3D' + pidForDisplay);
    if (ct !== "") {
      link += "%26configurableItemType%3D" + ct;
    }
    link += "%26cm_cat%3D" + rrGetCMTag(link);
    return link;
  }
}
						