salmon.namespace.addNamespace("boots.coremetrics");
boots.coremetrics = {
	pageViewTag: function(event){
		if(boots.coremetrics.enabled) {
			cmCreatePageviewTag(boots.coremetrics.pageName + ": " + event, boots.coremetrics.category, null, null, boots.coremetrics.storeId);
		}
	}
}

$(document).ready(function(){ 
		var cookieName = "CM_REG_CONV";	
		
		var cookieStr = unescape(boots.common.cookie.getCookie(cookieName));
		
		if ((typeof cookieStr != "undefined") && (cookieStr != "undefined") && (cookieStr != "")){
			var convParms = cookieStr.split("|");
			
			//replace the '+' symbols with a space
			var strTarget = '+';
			var strSubString = ' '; 
			var strText = convParms[0];
			
			var intIndexOfMatch = strText.indexOf( strTarget );
			  
			// Keep looping while an instance of the target string
			// still exists in the string.
			while (intIndexOfMatch != -1){
				// Relace out the current instance.
				strText = strText.replace( strTarget, strSubString )
			  
				// Get the index of any next matching substring.
				intIndexOfMatch = strText.indexOf( strTarget );
			}
			
			// cmCreateConversionEventTag is defined in cmdatatagutils.js
			// but I can not find any place that referes to cmdatatagutils.js. Maybe this is caused by running cormettrics disabled?
			if(typeof cmCreateConversionEventTag != 'undefined'){
				cmCreateConversionEventTag(strText, convParms[1], convParms[2]);
			}
			
			boots.common.cookie.removeCookie(cookieName);
		}
});

$(document).ready(function(){ 
		var cookieName = "CM_REG";	
		
		var cookieStr = unescape(boots.common.cookie.getCookie(cookieName));
		
		if ((typeof cookieStr != "undefined") && (cookieStr != "undefined") && (cookieStr != "")){
			var convParms = cookieStr.split("|");
			// cmCreateRegistrationTag is defined in cmdatatagutils.js
			// but I can not find any place that referes to cmdatatagutils.js. Maybe this is caused by running cormettrics disabled?
			
			if(typeof cmCreateRegistrationTag != 'undefined'){
				cmCreateRegistrationTag(convParms[0] == "null" ? null : convParms[0], 
					convParms[1] == "null" ? null : convParms[1], 
					convParms[2] == "null" ? null : convParms[2], 
					convParms[3] == "null" ? null : convParms[3], 
					convParms[4] == "null" ? null : convParms[4], 
					convParms[5] == "null" ? null : convParms[5], 
					convParms[6] == "null" ? null : convParms[6], 
					convParms[7] == "null" ? null : convParms[7], 
					convParms[8] == "null" ? null : convParms[8], 
					convParms[9] == "null" ? null : convParms[9], 
					convParms[10] == "null" ? null : convParms[10], 
					convParms[11] == "null" ? null : convParms[11], 
					convParms[12] == "null" ? null : convParms[12], 
					convParms[13] == "null" ? null : convParms[13], 
					convParms[14] == "null" ? null : convParms[14], 
					convParms[15] == "null" ? null : convParms[15], 
					convParms[16] == "null" ? null : convParms[16], 
					convParms[17] == "null" ? null : convParms[17], 
					convParms[18] == "null" ? null : convParms[18], 
					convParms[19] == "null" ? null : convParms[19]);
			}
			
		    boots.common.cookie.removeCookie(cookieName);
		}
});

//set the Coremetrics cookies
$(document).ready(function(){
	if ((typeof cm_data != "undefined") && (cm_data != "undefined")){			
		boots.common.cookie.setCookie("_bdccookie_cm_data", cm_data);	
	}
	
	if ((typeof cm_exploreAttributes != "undefined") && (cm_exploreAttributes != "undefined")){			
		boots.common.cookie.setCookie("_bdccookie_cm_explore", cm_exploreAttributes);	
	}
	
	//remove the cookies that will have been proccessed if they exist
	boots.common.cookie.removeCookie("_bdccookie_cm_newRefinement");
	
	boots.common.cookie.removeCookie("_bdccookie_cm_hostProductId");	
	
						
});

/*
	Explore attribute 1: is the Out of Stock flag, Y is out of stock, N is in stock	
	Explore attribute 2: is number of product reviews	
	Explore attribute 3: is the Product * rating											
	Explore attribute 4: is Cross Sell product	
	Explore attribute 5: category
	Explore attribute 6: sort option
	Explore attribute 7: page format
	Explore attribute 8: channel
	Explore attribute 9: view type
	Explore attribute 10: refinement
	Explore attribute 11: referral link type
*/
function ExploreAttribute(outOfStock, productReviewCount, productRating, crossSellId, category, sortOption, pageFormat, channel, viewType, refinement, referralLinkType, categoryId){
	this.outOfStock = outOfStock;
	this.productReviewCount = productReviewCount;
	this.productRating = productRating;
	this.crossSellId = crossSellId;
	this.category = category;
	this.sortOption = sortOption;
	this.pageFormat = pageFormat;
	this.channel = channel;
	this.viewType = viewType;
	this.refinement = refinement;
	this.referralLinkType = referralLinkType;
	this.categoryId = categoryId;
}

function setLinktype(linkType){
	boots.common.cookie.setCookie("_bdccookie_cm_linktype", linkType);
}

function setRefinement(refinement){
	boots.common.cookie.setCookie("_bdccookie_cm_newRefinement", refinement);
}

function setHostProductId(hostProductId){
	boots.common.cookie.setCookie("_bdccookie_cm_hostProductId", hostProductId);
}

