<!--
/*
 * cmdatatagutils.js  rev.51729 - Mon Apr 16 14:13:08 CDT 2007
 *
 * Coremetrics Tag v3.1, 2/28/2002
 * COPYRIGHT 1999-2002 COREMETRICS, INC. 
 * ALL RIGHTS RESERVED. U.S.PATENT PENDING
 *
 * The following functions aid in the creation of Coremetrics data tags.
 * Date			Imp. Eng.		Desc.
 * 6/9/2006		Hutch White		Added Code to create mmc tags if siteid= present in url
 * 08/08/06		Hutch White		Add manual link click tags and Liveview Normalization
 * 03/23/07		Hutch White		Add outfitID parameter to productview & Shop tags 
 *								- productview generates custom outfitID tag (li=4)
 * 4/15/07		W.Bird			Add ProdID+"^"+CategoryID Aggregation Exception Logic
 *								Add element tags, conversion tag
 *								Add new cmJv logic
 *	092107		MOCHOA			Add ExtraField to Shop9Tag for giftService 
 * 110807		MOCHOA			Add Extra Field 3-6 for Shop 5/9
 *								Add Extra Field 6 for productview
 * 111407		MOCHOA			Updated the giftservice parameter to suuport 3 vaules - giftmessage, giftkit, giftbox
 */

var cmJv = "1.0";
if (typeof(isNaN) == "function") cmJv = "1.1";
if (typeof(isFinite) == "function") cmJv = "1.2";
if (typeof(NaN) == "number") cmJv = "1.3";
if (typeof(decodeURI) == "function") cmJv = "1.5";
if (typeof(Array.forEach) == "function") cmJv = "1.6";
if (typeof(Iterator) == "object") cmJv = "1.7";

// TAG GENERATING FUNCTIONS ---------------------------------------------------

/*
 * Calling this function points tags to the production database
 */
function cmSetProduction(){
	cm_HOST="1901.nordstrom.com/eluminate?"; 
}

function cmCreatePageElementTag(elementID, elementCategory, pageID, pageCategoryID, elementLocation) {
	var cm=new _cm("tid", "15", "vn2", "e4.0");
	cm.eid=elementID;
	cm.ecat=elementCategory;
	cm.pflg="0";
	cm.pid=pageID;
	cm.pcat=pageCategoryID;
	cm.eloc=elementLocation;
	cm.writeImg();
}

function cmCreateProductElementTag(elementID, elementCategory, productID, productCategoryID, elementLocation) {
	var cm=new _cm("tid", "15", "vn2", "e4.0");
	cm.eid=elementID;
	cm.ecat=elementCategory;
	cm.pflg="1";
	cm.pid=productID;	
	cm.pcat=productCategoryID;
	cm.eloc=elementLocation;
	cm.writeImg();
}

function cmCreateConversionEventTag(eventID, actionType, categoryID, points) {
	var cm = new _cm("tid", "14", "vn2", "e4.0");
	cm.cid = eventID;
	cm.cat = actionType;
	cm.ccid = categoryID;
	cm.cpt = points;
	cm.writeImg();
}

function cmCreateManualLinkClickTag(href,name,pageID) {	
	if (cmCreateLinkTag == null && cM != null) {
		var cmCreateLinkTag = cM;
	}
	if (cmCreateLinkTag != null) {		
		var dt = new Date();
		cmLnkT3 = dt.getTime();
		cmCreateLinkTag(cm_ClientTS, cmLnkT3, name, href, false, pageID);
	}
}

function cmCreateManualImpressionTag(pageID, trackSP, trackRE) {
		var cm = new _cm("tid","9","vn2","4.0");
		cm.pi = pageID;
		if (trackSP){
			cm.cm_sp = trackSP;
		}
		if (trackRE){
			cm.cm_re = trackRE;
		}		
		cm.st = cm_ClientTS;
        cm.writeImg();
}

/* manual PageviewTag for off site page tagging.  Allows client to supply URL and Referring URL
*/
function cmCreateManualPageviewTag(pageID, categoryID,DestinationURL,ReferringURL) {
	if (pageID == null) {
		pageID = cmGetDefaultPageID();
	}

	var cm = new _cm("tid", "1", "vn2", "e4.0");
	cm.pi = pageID;
	if (categoryID) {
		cm.cg = categoryID;
	}

	// if available, override the referrer with the frameset referrer
	if (parent.cm_ref != null) {
		cm.rf = parent.cm_ref;
		parent.cm_ref = document.URL;
	}
	if (ReferringURL) {
		cm.rf = ReferringURL;
	}
	// if parent had mmc variables and this is the first pageview, add mmc to this url
	if(parent.cm_set_mmc) {
		cm.ul = document.location.href + 
				((document.location.href.indexOf("?") < 0) ? "?" : "&") + 
				parent.cm_mmc_params; 
		parent.cm_ref = cm.ul;
		parent.cm_set_mmc = false;
	}
	if (DestinationURL) {
		cm.ul = DestinationURL;
	}
	cm.writeImg();
}

// CM_EM Email Capture Code

function cmIndexOfParameter (parameter) {
	return document.URL.indexOf(parameter);
}

function cmCheckCMEM() {
	if (cmIndexOfParameter("cm_em") != -1){

		var s = document.URL.toLowerCase();
		var begin = s.indexOf("cm_em");
		var end = s.indexOf("&", begin);
		if (end == -1) {
			end = s.length;
		}
		var middle = s.indexOf("=", begin);

		var emailAddress = s.substring(middle + 1, end);

		if (emailAddress.indexOf(":") != -1){
			var tempArray = emailAddress.split(":");
			emailAddress = tempArray[1];
		}

		cmCreateRegistrationTag(emailAddress,emailAddress);
	}
}
/*
*	cmCheckCMEM();  Add this to appropriate pages before writeImg
*/

/*
 * Creates a Tech Props tag.
 * pageID		: required. Page ID to set on this Pageview tag
 */
function cmCreateTechPropsTag(pageID, categoryID) {
	if (pageID) {
		var cm=new _cm("tid", "6", "vn2", "e3.1");
		cm.pc="Y";
		cm.pi = pageID;
		cm.cg = categoryID;
		// if available, override the referrer with the frameset referrer
		if (parent.cm_ref != null) {
			cm.rf = parent.cm_ref;
			parent.cm_ref = document.URL;
		}
		cm.ul=cmConvertMMC(location.href);
		cm.addTP();
		cmCheckCMEM();
		cm.writeImg();
	}
}

/*
 * Creates a Pageview tag with the given Page ID
 *
 * pageID		: required. Page ID to set on this Pageview tag
 * searchString	: optional. Internal search string enterred by user to reach
 *				  this page.
 * categoryID	: optional. Category ID to set on this Pageview tag
 *
 * returns nothing, causes a document.write of an image request for this tag.
 */
function cmCreatePageviewTag(pageID, searchString, categoryID, numSearchResults, template) {
	if (pageID == null) {
		pageID = getDefaultPageID();
	}

	var cm = new _cm("tid", "1", "vn2", "e3.1");
	cm.pi = pageID;
	if (searchString) {
		cm.se = searchString;
		cm.sr = numSearchResults;
	}
	if (categoryID) {
		cm.cg = categoryID;
	}

	// if available, override the referrer with the frameset referrer
	if (parent.cm_ref != null) {
		cm.rf = parent.cm_ref;
		parent.cm_ref = document.URL;
	}

	cm.li = 3;
	cm.ps1 = pageID;
	cm.ps2 = template;
	cm.ul=cmConvertMMC(location.href);
	cmCheckCMEM();
	cm.writeImg();
}

/*
 * Creates a Pageview tag with the default value for Page ID. 
 * Format of Page ID is "x/y/z/MyPage.asp"
 *
 * returns nothing, causes a document.write of an image request for this tag.
 */
function cmCreateDefaultPageviewTag() {
	cmCreatePageviewTag(getDefaultPageID(), null, null);
}

/*
 * Creates a Productview Tag
 * Also creates a Pageview Tag by setting pc="Y"
 * Format of Page ID is "PRODUCT: <Product Name> (<Product ID>)"
 *
 * productID	: required. Product ID to set on this Productview tag
 * productName	: required. Product Name to set on this Productview tag
 * categoryID	: optional. Category ID to set on this Productview tag 
 *
 * returns nothing, causes a document.write of an image request for this tag.
 */
function cmCreateProductviewTag(productID, productName, categoryID, pageID, outfitID, PickupInStore) {
	var cm = new _cm("tid", "5", "vn2", "e3.1");

	if (productName == null) {
		productName = "";
	}

	// if available, override the referrer with the frameset referrer
	if (parent.cm_ref != null) {
		cm.rf = parent.cm_ref;
		parent.cm_ref = document.URL;
	}

	cm.pr = productID;
	cm.pm = productName;
	cm.cg = categoryID;
	
	cm.pc = "N";
	cm.pi = pageID;
	cm.ul=cmConvertMMC(location.href);
	if (outfitID){
		cm.li=4;
		cm.ps1=productID;
		cm.ps2=productName;
		cm.ps3=categoryID;
		if (pageID){
			cm.ps4=pageID;
		}
		cm.ps5=outfitID;
		cm.ps6=PickupInStore;
	}
	
	cmCheckCMEM();
	cm.writeImg();
}

/*
 * Variables and Arrays to support Lineitem Aggregation
 */

var cmShopProducts = new Array();
var cmShopIds = new Array();
var cmShopCats = new Array();
var cmShopQtys = new Array();
var cmShopPrices = new Array();
var cmShopCounter = 0;
var cmShopOrderIds = new Array();
var cmShopCustomerIds = new Array();
var cmShopOrderPrices = new Array();
var cmShopOrderOutfitID = new Array();
var cmShopOrdergiftServices = new Array();
var cmShopOrderBacktoBag = new Array();
var cmShopOrderPickupInStore = new Array();
var cmShopOrderstoreID = new Array();
var cmShopOrdertimeStamp = new Array();
var cmShopSKUs = "";

var cmShopProductCat = new Array();

/* Internal, to support aggregation */
function cmGetProductIndex(id){
	var i =0;
	for (i=0; i<cmShopCounter; i++)
	{
		if (id==cmShopProductCat[i])
		{
			return i;
		}
	}
	return -1;
}

/*
 * Creates a Shop tag with Action 5 (Shopping Cart)
 *
 * productID	: required. Product ID to set on this Shop tag
 * quantity	: required. Quantity to set on this Shop tag
 * productPrice	: required. Price of one unit of this product
 * categoryID	: optional. Category to set on this Shop tag
 *
 * returns nothing, causes a document.write of an image request for this tag.
 */
function cmCreateShopAction5Tag(productID, productName, productQuantity, productPrice, categoryID, outfitID, giftServices, BacktoBag, PickupInStore, storeID, timeStamp) {

	productID = productID.toUpperCase();
	
	var productCat = productID + "^" + categoryID;

	var index = cmGetProductIndex(productCat);
	if(index!=-1){
		var oldPrice = cmShopPrices[index];
		var oldQty = cmShopQtys[index];
		var newQty = oldQty + parseInt(productQuantity);
		var newPrice = (oldPrice*oldQty + parseInt(productQuantity)*parseFloat(productPrice))/(newQty);

		cmShopPrices[index] = newPrice;
		cmShopQtys[index] = newQty;

	} else {
		if (!categoryID) {
			categoryID = "";
		}

		cmShopProductCat[cmShopCounter] = productCat;
		cmShopProducts[cmShopCounter] = productName;
		cmShopIds[cmShopCounter] = productID;
		cmShopCats[cmShopCounter] = categoryID;
		cmShopQtys[cmShopCounter] = parseInt(productQuantity);
		cmShopPrices[cmShopCounter] = parseFloat(productPrice);
		if (outfitID){
			cmShopOrderOutfitID[cmShopCounter] = outfitID;		
		} else {
			cmShopOrderOutfitID[cmShopCounter] = "";			
		}
		if (giftServices){
			cmShopOrdergiftServices[cmShopCounter] = giftServices;		
		}
		if (BacktoBag){
			cmShopOrderBacktoBag[cmShopCounter] = BacktoBag;		
		}
		if (PickupInStore){
			cmShopOrderPickupInStore[cmShopCounter] = PickupInStore;		
		} 
		if (storeID){
			cmShopOrderstoreID[cmShopCounter] = storeID;		
		} 
		if (timeStamp){
			cmShopOrdertimeStamp[cmShopCounter] = timeStamp;		
		}		
		cmShopCounter++;
	}

	cmShopSKUs = cmGetOSK();
}

/* render the aggregated cart lineitems with Shop 5 tags*/
function cmDisplayShop5s(){
	var i;
	for(i=0; i<cmShopCounter;i++){
		var cm = new _cm("tid", "4", "vn2", "e3.1");
		var pcProdCat = cmShopProductCat[i].split("^");
		cm.at = "5";
		cm.pr = pcProdCat[0];
		cm.pm = cmShopProducts[i];
		cm.cg = pcProdCat[1];
		cm.qt = cmShopQtys[i] ;
		cm.bp = cmShopPrices[i];
		cm.sx1= cmShopOrderOutfitID[i];
		cm.sx2= cmShopOrdergiftServices[i];
		cm.sx3 = cmShopOrderBacktoBag[i];
		cm.sx4 = cmShopOrderPickupInStore[i];
		cm.sx5 = cmShopOrderstoreID[i];
		cm.sx6 = cmShopOrdertimeStamp[i]
		cm.pc = "N";
		cm.writeImg();
	}
	cmShopSKUs = cmGetOSK();
	cmShopCounter=0;
}

/*
 * Creates a Shop tag with Action 9 (Order Receipt / Confirmed)
 *
 * productID	: required. Product ID to set on this Shop tag
 * productName	: required. Product Name to set on this Shop tag
 * quantity	: required. Quantity to set on this Shop tag
 * productPrice	: required. Price of one unit of this product
 * customerID	: required. ID of customer making the purchase
 * orderID	: required. ID of order this lineitem belongs to
 * orderTotal	: required. Total price of order this lineitem belongs to
 * categoryID	: optional. Category to set on this Shop tag
 *
 * returns nothing, causes a document.write of an image request for this tag.
 */
function cmCreateShopAction9Tag(productID, productName, productQuantity,
				productPrice, customerID, orderID,
				orderTotal, categoryID, outfitID, giftServices, BacktoBag, PickupInStore, storeID, timeStamp) {

	productID = productID.toUpperCase();
	
	var productCat = productID + "^" + categoryID;

	var index = cmGetProductIndex(productCat);
	if(index!=-1){
		var oldPrice = cmShopPrices[index];
		var oldQty = cmShopQtys[index];
		var newQty = oldQty + parseInt(productQuantity);
		var newPrice = (oldPrice*oldQty + parseInt(productQuantity)*parseFloat(productPrice))/(newQty);

		cmShopPrices[index] = newPrice;
		cmShopQtys[index] = newQty;
	} else {
		if (!categoryID) {
			categoryID = "";
		}
		
		cmShopProductCat[cmShopCounter] = productCat;
		cmShopProducts[cmShopCounter] = productName;
		cmShopIds[cmShopCounter] = productID;			
		cmShopOrderIds[cmShopCounter] = orderID;
		cmShopOrderPrices[cmShopCounter] = orderTotal;
		cmShopCustomerIds[cmShopCounter] = customerID;
		cmShopCats[cmShopCounter] = categoryID;
		cmShopQtys[cmShopCounter] = parseInt(productQuantity);
		cmShopPrices[cmShopCounter] = parseFloat(productPrice);
		if (outfitID){
			cmShopOrderOutfitID[cmShopCounter] = outfitID;		
		} else {
			cmShopOrderOutfitID[cmShopCounter] = "";			
		}	
		if (giftServices){
			cmShopOrdergiftServices[cmShopCounter] = giftServices;		
		}
		if (BacktoBag){
			cmShopOrderBacktoBag[cmShopCounter] = BacktoBag;		
		} 
		if (PickupInStore){
			cmShopOrderPickupInStore[cmShopCounter] = PickupInStore;		
		} 
		if (storeID){
			cmShopOrderstoreID[cmShopCounter] = storeID;		
		} 
		if (timeStamp){
			cmShopOrdertimeStamp[cmShopCounter] = timeStamp;		
		}
		cmShopCounter++;
	}
	cmShopSKUs = cmGetOSK();
}

/* render the aggregated order lineitems with Shop 9 tags*/
function cmDisplayShop9s(){
	var i;
	for(i=0; i<cmShopCounter;i++){
		var cm = new _cm("tid", "4", "vn2", "e3.1");
		var pcProdCat = cmShopProductCat[i].split("^");
		cm.at = "9";
		cm.pr = pcProdCat[0];
		cm.pm = cmShopProducts[i];
		cm.cg = pcProdCat[1];
		cm.qt = cmShopQtys[i] ;
		cm.bp = cmShopPrices[i];
		cm.cd = cmShopCustomerIds[i];
		cm.on = cmShopOrderIds[i];
		cm.tr = cmShopOrderPrices[i];
		cm.sx1=	cmShopOrderOutfitID[i];
		cm.sx2= cmShopOrdergiftServices[i];
		cm.sx3 = cmShopOrderBacktoBag[i];
		cm.sx4 = cmShopOrderPickupInStore[i];
		cm.sx5 = cmShopOrderstoreID[i];
		cm.sx6 = cmShopOrdertimeStamp[i];
		cm.pc = "N";
		cm.writeImg();
	}
	cmShopSKUs = cmGetOSK();
	cmShopCounter=0;
}

/*
 * Creates an Order tag
 *
 * orderID			: required. Order ID of this order
 * orderTotal		: required. Total of this order (minus tax and shipping)
 * orderShipping	: required. Shipping charge for this order
 * customerID		: required. Customer ID that placed this order
 * customerCity		: optional. City of Customer that placed this order
 * customerState	: optional. State of Customer that placed this order
 * customerZIP		: optional. Zipcode of Customer that placed this order
 *
 * returns nothing, causes a document.write of an image request for this tag.
 */
function cmCreateOrderTag(orderID, orderTotal, orderShipping, customerID, 
			  customerCity, customerState, customerZIP) {
	if (orderID && orderTotal && customerID) {
		var cm = new _cm("tid", "3", "vn2", "e3.1");
		cm.on = orderID;
		cm.tr = orderTotal;
		cm.osk = cmShopSKUs;
		cm.sg = orderShipping;
		cm.cd = customerID;
		cm.sa = customerState;
		cm.ct = customerCity;
		cm.zp = customerZIP;

		cm.writeImg();
	}
}

function cmGetOSK() {
	var i =0;
	var result = "";
	for (i=0; i<cmShopCounter; i++)
	{
		result += "|" + cmShopIds[i] + "|" + cmShopPrices[i] + "|" + cmShopQtys[i] + "|";
	}
	return result;
}

/*
 * Creates a Registration tag and/or a Newsletter tag
 *
 * customerID		: required for Registration. ID of Customer to register.
 * customerEmail	: required for Newsletters. Optional for Registration.
 * customerCity		: optional. City of Customer that placed this order
 * customerState	: optional. State of Customer that placed this order
 * customerZIP		: optional. Zipcode of Customer that placed this order
 * newsletterName	: required for Newsletters. The name of the Newsletter.
 * subscribe		: required for Newsletters. Either "Y" or "N"
 *
 * returns nothing, causes a document.write of an image request for this tag.
 */
function cmCreateRegistrationTag(customerID, customerEmail, customerCity,
				customerState, customerZIP, newsletterName, 
				subscribe) {
	var cm = new _cm("tid", "2", "vn2", "e3.1");
	cm.cd = customerID;
	cm.em = customerEmail;
	cm.sa = customerState;
	cm.ct = customerCity;
	cm.zp = customerZIP;

	if (newsletterName && subscribe) {
		cm.nl = newsletterName;
		cm.sd = subscribe;
	}
	
	cm.writeImg();
}

/* Creates an Error Tag
 *
 * returns nothing, causes a document.write of an image request for this tag.
 */
function cmCreateErrorTag() {
	var cm=new _cm("tid", "404", "vn2", "e3.1");  //DO NOT CHANGE THESE PARAMETERS
	
	// get the referrer from the frameset
	if (parent.cm_ref != null) {
		cm.rf = parent.cm_ref;
		parent.cm_ref = document.URL;
	}

	cm.pc = "Y";
	cm.pi = getDefaultPageID();
	cm.ul=cmConvertMMC(location.href);
	cmCheckCMEM();
	cm.writeImg();
}

function cmSearchResultFollowed(searchString,productID) {
	var cm=new _cm("tid", "7", "vn2", "e3.1");  //DO NOT CHANGE THESE PARAMETERS
	cm.li="1";
	cm.ps1=searchString;
	cm.ps2=productID;
		
	cm.writeImg();
}

function cmRelatedItemInfo(productID,categoryID,refProductID,refCategoryID) {
	var cm=new _cm("tid", "7", "vn2", "e3.1");  //DO NOT CHANGE THESE PARAMETERS
	cm.li="2";
	cm.ps1=productID;
	cm.ps2=categoryID;
	cm.ps3=refProductID;
	cm.ps4=refCategoryID;
		
	cm.writeImg();
}

function cmLIVEviewClick(href,name) {	
	if (cmHandleLinkClick == null && C9 != null) {
		var cmHandleLinkClick = C9;
	}
	if (cmHandleLinkClick != null) {		
		var link = new Object();
		link.tagName = "A";
		link.name = name; 
		link.href = href; 
		cmHandleLinkClick(link);
	}	
}


// HELPER FUNCTIONS -----------------------------------------------------------
/* These functions are used by the tag-generating functions and/or may be used
 * in in general as convenience functions
 */

/*
 * Creates an acceptable default Page ID value to use for Pageview tags.
 * The default Page ID is based on the URL, and consists of the path and
 * filename (without the protocol, domain and query string).
 * 
 * example:
 * returns "x/y/MyPage.asp" for the URL http://www.mysite.com/x/y/MyPage.asp
 */
function getDefaultPageID() { 
	var pageName = window.location.pathname; 

	// eliminates everything after "?" (for Opera browswers)
	var tempIndex1 = pageName.indexOf("?");
	if (tempIndex1 != -1) {
		pageName = pageName.substr(0, tempIndex1);
	}
	// eliminates everything after "#" (for Opera browswers)
	var tempIndex2 = pageName.indexOf("#");
	if (tempIndex2 != -1) {
		pageName = pageName.substr(0, tempIndex2);
	}
	// eliminates everything after ";"
	var tempIndex3 = pageName.indexOf(";");
	if (tempIndex3 != -1) {
		pageName = pageName.substr(0, tempIndex3);
	}

	var slashPos = pageName.lastIndexOf("/");
	if (slashPos == pageName.length - 1) {
		pageName = pageName + "default.asp"; /****************** SET TO DEFAULT DOC NAME */
	}

	while (pageName.indexOf("/") == 0) {
		pageName = pageName.substr(1,pageName.length);
	}

	return(pageName); 
} 

if (defaultNormalize == null) { var defaultNormalize = null; }

/* This normalization function takes a list of parameters and parses out
   all url parameters that ARE in that list.  This only handles the simple case of 
   basic url parameters in the query string.  */
function myNormalizeURL(url, isHref) {
    var newURL = url;
    if (isHref) {
		//Javascript code
		if (newURL.toLowerCase().indexOf("GuidedNavigationSetQuery")!=-1){
			newURL="javascript:GuidedNavigationSetQuery();";
		} else {
			//whitelist code
			var mapflag = newURL.indexOf("/MapPoint/");
			var catflag = newURL.indexOf("/catalogonline/");
			if ((mapflag != -1) || (catflag != -1)){
				// map pages whitelist
				if (mapflag != -1){
					var whiteList = ["bizid="];
					var paramString;
					var paramIndex = newURL.indexOf("?");
					var params;
					var keepParams = new Array();
					
					if (paramIndex > 0) {
					paramString = newURL.substring(paramIndex+1);
					newURL = newURL.substring(0, paramIndex);
					params = paramString.split("&");
					for(var i=0; i<params.length; i++) {
						for(var j=0; j<whiteList.length; j++) {
							if (params[i].indexOf(whiteList[j]) == 0) {
								keepParams[keepParams.length] = params[i];
							}
						}
					}
				
					newURL += "?" + keepParams.join("&");
				
					}
				} else { // catalog pages whitelist
					var whiteList = ["ver=", "p="];
					var paramString;
					var paramIndex = newURL.indexOf("?");
					var params;
					var keepParams = new Array();
					
					if (paramIndex > 0) {
					paramString = newURL.substring(paramIndex+1);
					newURL = newURL.substring(0, paramIndex);
					params = paramString.split("&");
					for(var i=0; i<params.length; i++) {
						for(var j=0; j<whiteList.length; j++) {
							if (params[i].indexOf(whiteList[j]) == 0) {
								keepParams[keepParams.length] = params[i];
							}
						}
					}
				
					newURL += "?" + keepParams.join("&");
				
					}
				}
			} else {
			//blacklist code
				var paramString;
				var paramIndex = newURL.indexOf("?");
				var styleFlag = newURL.indexOf("styleid=");
				var searchFlag=document.URL.indexOf("/SR?");
				var blackList = ["AddressID=", "URL=", "basketitemid=", "promocode=", "startNum=", "styleNum=", "shopper=", "ordernum=", "PrevStyleID=", "NextStyleID=", "boutique=", "refsid=", "refcat=", "slotid=", "SourceID=", "sourcecode=", "offercode=", "SearchType=", "Search=", "CatID=", "q=", "sort=", "bd=", "sa=", "hn=", "kf=", "brand=", "size=", "width=", "color=", "pricelow=", "pricehigh=", "catname=", "mediumthumbnail=", "cattext=", "PriceRange=", "sizename=", "widthname=", "brandlabelid=", "findertype=", "findertypename=", "pricerangename=", "sizename=", "widthname=", "brandlabelid=", "findertype=", "findertypename=", "pricerangename=", "origquery=", "CatID2=", "CatID3=", "catname1=", "catname2=", "catname3=", "navstate=", "gn=", "initsearch=", "ProductFinder=", "pfindid=", "category="];
				if (styleFlag != -1) {
					blackList[blackList.length]="category="
				}
				if (searchFlag!=-1){
					blackList[blackList.length]="origin="
					blackList[blackList.length]="searchorigin="
					blackList[blackList.length]="keyword="
					blackList[blackList.length]="giftfinder="
					blackList[blackList.length]="mode="
				}
				var params;
				var keepParams = new Array();
				var goodParam;
				var newURL;
			
				if (paramIndex > 0) {
				paramString = newURL.substring(paramIndex+1);
				newURL = newURL.substring(0, paramIndex);
				params = paramString.split("&");
			
				for(var i=0; i<params.length; i++) {
					goodParam = true;
					for(var j=0; j<blackList.length; j++) {
						if (params[i].toLowerCase().indexOf(blackList[j].toLowerCase()) == 0) {
							goodParam = false;
						}
					}
					if(goodParam == true) {
						keepParams[keepParams.length] = params[i];
					}
				}
				
				newURL += "?" + keepParams.join("&");
			
				}
			}

			if (newURL.toLowerCase().indexOf("store.nordstrom.com")==-1){
				newURL = newURL.split('http://shop.nordstrom.com').join('');
				newURL = newURL.split('https://shop.nordstrom.com').join('');
			} else {
				newURL = newURL.split('http://store.nordstrom.com').join('');
				newURL = newURL.split('https://store.nordstrom.com').join('');
			}

		 
			if (defaultNormalize != null) {
				newURL = defaultNormalize(newURL, isHref);
			}
		}
	}	
    return newURL;
}

// install normalization

if (document.cmTagCtl != null) {
    var func = "" + document.cmTagCtl.normalizeURL;
    if (func.indexOf('myNormalizeURL') == -1) {
        defaultNormalize = document.cmTagCtl.normalizeURL;
        document.cmTagCtl.normalizeURL = myNormalizeURL;
    }
}

// find instance of siteid= in url.  Use first 11 characters after = sign to make mmc parameter
function cmConvertMMC(url) {
	var newURL = url.toLowerCase();
	var paramIndex = newURL.indexOf("siteid=");
		if (paramIndex > 0) {
			var preCon=newURL.substring(paramIndex+7,paramIndex+7+11);	
			if (newURL.indexOf("?")>0){
				newURL=newURL+"&cm_mmc=Linkshare-_-"+preCon+"-_-null-_-null";
			}
			else{
				newURL=newURL+"?cm_mmc=Linkshare-_-"+preCon+"-_-null-_-null";
			}
		}	
	return newURL;
}
//-->

