function rr_commonVar(){
	this.baseUrl;
	this.userid;
	this.sessionId;
	this.searsUrl;
	this.storeId;
	this.placementType;
	this.side;
}

function rr_common(R3_COMMON,commonObj) {
	R3_COMMON.setApiKey(commonObj.storeId);
	//alert("commonObj.storeId = "+commonObj.storeId);
	R3_COMMON.setSessionId(commonObj.sessionId);
	//alert("commonObj.sessionId = "+commonObj.sessionId);
	R3_COMMON.setUserId(commonObj.userid);
	//alert("commonObj.userid = "+commonObj.userid);
	R3_COMMON.setBaseUrl(commonObj.baseUrl);
	//alert("commonObj.baseUrl = "+commonObj.baseUrl);
	R3_COMMON.setClickthruServer(commonObj.searsUrl);
	//alert("commonObj.searsUrl = "+commonObj.searsUrl);
	if (typeof commonObj.side != 'undefined'){
		R3_COMMON.addPlacementType(commonObj.side);
		//alert("commonObj.side = "+commonObj.side);
	}
	R3_COMMON.addPlacementType(commonObj.placementType);
	//alert("commonObj.placementType = "+commonObj.placementType);

	if (gup('sbf') == 'Brand'){
		var sbv_Param= gup('sbv');
			if (sbv_Param != ''){
	    		if (typeof catVar != 'undefined'){
					R3_COMMON.setPageBrand(urlDecodeUrl(sbv_Param));
			}	
		}	
	}

}


function rr_productVar(){
	this.prodBrand; 
	this.partNumber;
	this.name;
	this.listPrice;
	this.salePrice;
	this.imageId;
	this.saveStory;
	this.sName;
	this.cName;
	this.vName;
	this.recommendable;
}
function rr_product(R3_ITEM, prodVar) {
	
	if (typeof prodVar.sName != 'undefined' && prodVar.sName != "") {
		R3_ITEM.addCategory(prodVar.vName+"_"+prodVar.cName+"_"+prodVar.sName,prodVar.sName);
	}else if (typeof prodVar.cName != 'undefined' && prodVar.cName != ""){
		R3_ITEM.addCategory(prodVar.vName+"_"+prodVar.cName,prodVar.cName);
	}else if(typeof prodVar.vName != 'undefined' && prodVar.vName != ""){
		R3_ITEM.addCategory(prodVar.vName,prodVar.vName);
	}
			
	R3_ITEM.setId(prodVar.partNumber);
	R3_ITEM.setName(prodVar.name);
	R3_ITEM.setPrice(prodVar.listPrice);
	R3_ITEM.setSalePrice(prodVar.salePrice);
	R3_ITEM.setImageId(prodVar.imageId);
	R3_ITEM.setBrand(prodVar.prodBrand);
	R3_ITEM.setRecommendable(prodVar.recommendable);
	R3_ITEM.addAttribute('SaveStory', prodVar.saveStory);
}

function rr_cartItems(){
	this.partNumber;
}


function rr_cart(R3_CART, cartItemArray) {
	
	for (var i=0; i < cartItemArray.length; i++){
		R3_CART.addItemId(cartItemArray[i].partNumber);
	}	
}

function rr_purchaseCompleteItems(){
	this.partNumber;
	this.qty;
	this.actualPrice
}

function rr_purchaseCompleteVar() {
	this.orderNumber;
}
	
function rr_purchaseComplete(R3_PURCHASED,pcVar,pcItemArray) {

	R3_PURCHASED.setOrderNumber(pcVar.orderNumber);
	// for each item purchased
	for (var i=0; i < pcItemArray.length; i++){
		R3_PURCHASED.addItemIdPriceQuantity(pcItemArray[i].partNumber, pcItemArray[i].actualPrice, pcItemArray[i].qty);
	}
}

function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

function trim( value ) {
	
	return LTrim(RTrim(value));
	
}

function rr_searcheItems(){
	this.partNumber;
}

function rr_searchVar() {
	this.keyword;
}


function rr_search(R3_SEARCH,ksVar,ksItemArray) {

	R3_SEARCH.setTerms(ksVar.keyword)
	//alert("keyword = "+ksVar.keyword);
	// for each item on the search page
	for (var i=0; i < ksItemArray.length; i++){
		R3_SEARCH.addItemId(ksItemArray[i].partNumber);
		//alert("partNumber["+i+"] = "+ksItemArray[i].partNumber);
	}
}

function rr_categoryVar(){
	this.parentId;
	this.Id;
	this.Name;
}

function rr_category(R3_CATEGORY, catVar) {
	R3_CATEGORY.setParentId(catVar.parentId);
	//alert("catVar.parentId = "+catVar.parentId);
	R3_CATEGORY.setId(catVar.Id);
	//alert("catVar.Id = "+catVar.Id);
	R3_CATEGORY.setName(catVar.Name);
	//alert("catVar.Name = "+catVar.Name);
}

/*This function replaces special character in the URL */
function urlDecodeUrl(str) {
    var string=str.split("%27").join("\'").split("+").join(" ").split("%2C").join(",").split("%26").join("&").split("%24").join("$").split("%20").join(" ").split("%28").join("(").split("%29").join(")").split("%5B").join("[").split("%5D").join("]").split("%5E").join("^").split("%3A").join(":").split("%2C").join(",").split("%2F").join("/");
    return string;
}
