/*
 * cmdatatagutils.js for IBM Websphere Commerce
 * $Id: cmdatatagutils - 10012449 - multiclient - 022310.js.txt 139563 2010-02-23 20:01:17Z jbowser $
 * $Revision: 139563 $
 *
 * Version 4.2.0
 *
 * Coremetrics Tag v4.0, 8/7/2006
 * COPYRIGHT 1999-2002 COREMETRICS, INC. 
 * ALL RIGHTS RESERVED. U.S.PATENT PENDING
 *
 * The following functions aid in the creation of Coremetrics data tags.
 *
 * 12/14/2009		JBowser		Initial multiclient library creation, with cmSetClientID
 * 02/09/2010		JBowser		Updated productViewTag, shopAction5 and shopAction9 categorization code to the follwing: 
 *											IF __cg value is provided (NOT NULL / NOT EMPTY / NOT ZERO) THEN use __cg value 
 *						   				ELSE IF catIDoverride NOT NULL THEN use catIDoverride
 *						   				ELSE use __cg
 * 02/23/2010		JBowser		Rolled existing library for 90252781 (fossil.com) into this multiclient library.
 *										Added latest IO code.
 *
 */

var cm_exAttr=new Array();  
var cm_ClientID = "99999999";
var cm_TrackLink = "A";
var cm_TrackImpressions = "RSCM";
var cm_JSFEnabled = false;
var cmCheckCMEMFlag = true;	
var cmSendOSLinkClickTag = true;
var cm_tempHost;
var cm_tempCookieDomain;
var cm_currencyCode;

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";}

// IO V4 Configuration
if (typeof(IORequest) == "function") {
   IORequest.client_id           = cm_ClientID;
   IORequest.encrypt_cats        = true;
   IORequest.encrypt_prds        = true;
   IORequest.conflict_resolution = true;
   IORequest.max_prd_length      = 25;
   IORequest.max_cat_length      = 25;
   IORequest.timeout             = [8000, 4000];
   IORequest.use_site_category   = false;
   if ((IORequest.ie_version() !== null) && (IORequest.ie_version() < 7.0)) {
      IORequest.a_max_elements = [3,3,5,3,3,3,3];
   }
   else {
      IORequest.a_max_elements = [3,3,5,3,3,7,7];
   }
   IORequest.required_attributes  = [0,0,0,0,0];
   IORequest.access_method             = 'json remote';
   IORequest.default_product_file = undefined;
}

/*
	clientID : REQUIRED: client id for particular site
	firstPartyCM : REQUIRED: true for Javascript First Party, false for 3rd party and 1st Party Subdomain
	hostDomain : REQUIRED for 1st PARTY:
			if firstPartyCM=true, set to site domain. 
			if firstPartyCM=false and site uses 1st party subdomain set to first party subdomain
			if firstPartyCM=false and hostDomain=null, automatically set to data.coremetrics.com
			cookieDomain : REQUIRED only for Delegated 1st party w/AdTarget - sets CoreAt in specified domain
 */
function cmSetClientID(clientID,firstPartyCM,hostDomain,cookieDomain){

	if (firstPartyCM==null || !firstPartyCM){
		cm_JSFEnabled=false;
	} else {
		cm_JSFEnabled=firstPartyCM;
	}
	cm_ClientID=clientID; 
	cm_tempHost = hostDomain;
	if ((!hostDomain && firstPartyCM==false) || (!hostDomain && !firstPartyCM)){
		cm_tempHost="data.coremetrics.com";
	}
// IO V4 case
	if (typeof(IORequest) == "function"){
		IORequest.client_id = cm_ClientID;
	}
// AdTarget case
	if (typeof cmLoad == 'function') {
		if (cookieDomain){	// Delegated 1st Party + AdTarget component
			cm_tempCookieDomain=cookieDomain;
		}
		cm_PartnerDataClientIDs = cm_ClientID; 
		if (cm_JSFEnabled==false) {
			cm_Production_HOST = cm_tempHost;
		} else {
			cm_Production_HOST = "data.coremetrics.com";
		}
		cmLoad();
	}
} 

/* TAG GENERATING FUNCTIONS */

/*
 * Calling this function points tags to the production database
 */
function cmSetProduction(){
	if (cm_JSFEnabled==false){
		cm_HOST=cm_tempHost+"/eluminate?";			
		if (cm_tempCookieDomain){	// Delegated 1st Party + AdTarget component
			cm_JSFPCookieDomain=cm_tempCookieDomain;
		}	
	} else {
		cm_HOST="data.coremetrics.com/eluminate?";
		cm_JSFPCookieDomain=cm_tempHost;
	}
}

function cmCreateManualImpressionTag(pageID, trackSP, trackRE) {
		// insert code to get pageID from cmTagControl if pageID is null
		cmMakeTag(["tid","9","pi",pageID,"cm_sp",trackSP,"cm_re",trackRE,"st",cm_ClientTS]);
}

function cmCreateManualLinkClickTag(href,name,pageID) {	
	if (cmCreateLinkTag == null && cM != null) {
		var cmCreateLinkTag = cM;
	}
	if (cmCreateLinkTag != null) {		
		var dt = new Date();
		cmLnkT3 = dt.getTime();
		href = cG7.normalizeURL(href, true);
		cmCreateLinkTag(cm_ClientTS, cmLnkT3, name, href, false, pageID);
	}
}

/*
 *  manual PageviewTag for off site page tagging. Allows client to supply URL and Referring URL
 */
function cmCreateManualPageviewTag(pageID, categoryID,DestinationURL,ReferringURL,attributes) {
    if (attributes) {
        var cm_exAttr=new Array();
		cm_exAttr=attributes.split("-_-");
	}
	cmMakeTag(["tid","1","pi",pageID,"cg",categoryID,"ul",DestinationURL,"rf",ReferringURL,"cm_exAttr",cm_exAttr]);
}

function cmCreateElementTag(elementID, elementCategory, attributes) {
	if (attributes){
		var cm_exAttr=new Array();
		cm_exAttr=attributes.split("-_-");
	}
	cmMakeTag(["tid","15","eid",elementID,"ecat",elementCategory,"cm_exAttr",cm_exAttr]);
}

/*
 *  cmCreatePageElementTag exists only for backwards compatibility
 */
function cmCreatePageElementTag(elementID, elementCategory, attributes) {
   cmCreateElementTag(elementID, elementCategory, attributes);
}

function cmCreateConversionEventTag(eventID, actionType, categoryID, points,attributes) {
 	if (attributes){
		var cm_exAttr=new Array();
		cm_exAttr=attributes.split("-_-");
	}
	cmMakeTag(["tid","14","cid",eventID,"cat",actionType,"ccid",categoryID,"cpt",points,"cm_exAttr",cm_exAttr]);
 }

function cmCreatePageviewTag(__pi,__cg,__se,__sr, store_id, attributes, catSearchTerm, catSearchResults) {
	if (catSearchTerm) {
		__se = catSearchTerm;
	}
	if (catSearchResults) {
		__sr = catSearchResults;
	}
	if (attributes){
		var cm_exAttr=new Array();
		cm_exAttr=attributes.split("-_-");
	}	
	cmMakeTag(["tid","1","pi",__pi,"cg",__cg,"se",__se,"sr",__sr,"pc","Y","pv11",store_id,"cm_exAttr",cm_exAttr]);
}

function cmCreateDefaultPageviewTag(__cg) {
	cmCreatePageviewTag(cmGetDefaultPageID(),__cg);
}

function cmCreateProductviewTag(__pi,__pr,__pm,__cg,store_id,pageCount,catIDoverride, attributes) {

	// custom code
	if (__cg != null && __cg != "" && __cg != "0") {
		(__cg);
	}
   else if (catIDoverride != null) {
		(__cg = catIDoverride);
   }
   else {
		(__cg);
   }
   // END custom code

	if ((pageCount == null) || pageCount == "") {
		pageCount = 'Y';
	}
	if ((__pi == null) || (__pi == "") || (pageCount == "N")) {
		__pi = cG7.cM0[cm_ClientID];
	}
	if (attributes){
		var cm_exAttr=new Array();
		cm_exAttr=attributes.split("-_-");
	}
   cmMakeTag(["tid","5","pi",__pi,"pr",__pr,"pm",__pm,"cg",__cg,"pc",pageCount,"pv11",store_id,"cm_vc",cmExtractParameter("cm_vc",document.location.href),"li",10,"ps1",__pi,"ps2",__cg,"ps3",cm_exAttr[0],"ps4",cm_exAttr[1],"cm_exAttr",cm_exAttr]);
}

var __sArray = new Array();
var __skuString = "";
var __ex=new Array();

function __cmGetPIPC(__pr,__cg) {
	var __pI, i;
	var cmAttr1=new Array();
	var cmAttr2=new Array();
	for (i=0;i<__ex.length;++i){
		cmAttr1=cmAttr1+__ex[i];
	}		
	for (__pI = 0; __pI < __sArray.length; ++__pI) {
		if (__ex.length>0){
			cmAttr2=new Array();		
			for (i=__sArray[__pI].length-__ex.length*2+1;i<__sArray[__pI].length;i=i+2){
				cmAttr2=cmAttr2+__sArray[__pI][i];
			}
	
			if (__pr == __sArray[__pI][1] && __cg == __sArray[__pI][9] && cmAttr1==cmAttr2){
				return __pI;
			}
		} else {
		if (__pr == __sArray[__pI][1] && __cg == __sArray[__pI][9]) return __pI;
	}
	}	
	return -1;
}

function cmAddShop(__v) {
	var __i = __cmGetPIPC(__v[1],__v[9]);
	if (__i == -1) {
		if (__ex.length>0){
			for (var i=0; i<__ex.length; ++i){
				__v[__v.length]="s_a"+(i+1);
				__v[__v.length]=__ex[i];
			}
		}
		__sArray[__sArray.length] = __v;
	}
	else {
		var __oQ = __sArray[__i][5];
		var __oP = __sArray[__i][7];
		__sArray[__i][5] = parseInt(__sArray[__i][5]) + parseInt(__v[5]);
		__sArray[__i][7] = (((__v[7]*__v[5])+(__oP*__oQ))/__sArray[__i][5]);
	}
}

function cmCreateShopAction5Tag(__pr,__pm,__qt,__bp,__cg, store_id, currency, catIDoverride,attributes) {
	var pattern = /[^\-0-9\.]/gi;
    __bp = __bp.toString().replace(pattern, "");
   // custom code
	if (__cg != null && __cg != "" && __cg != "0") {
		(__cg);
	}
	else if (catIDoverride != null) {
		(__cg = catIDoverride);
	}
	else {
		(__cg);
	}
   // END custom code

	if (attributes){
		__ex=attributes.split("-_-");
	} else {
	__ex=new Array();
	}	
	cmAddShop(["pr",__pr,"pm",__pm,"qt",__qt,"bp",__bp,"cg",__cg,"ha1",attributes ? cm_hex_sha1(attributes) : null,"at","5","tid","4","pc","N","sx11",store_id,"cc",currency]);
}

function cmCreateShopAction9Tag(__pr,__pm,__qt,__bp,__cd,__on,__tr,__cg, store_id, currency, account_name, contract_name, catIDoverride,attributes) {
	var pattern = /[^\-0-9\.]/gi;
	var pattern1 = /^\s+|\s+$/gi;
    __bp = __bp.toString().replace(pattern, "");
	__on = __on.toString().replace(pattern, "");
	__pr = __pr.toString().replace(pattern1, "");

	// custom code
	if (__cg != null && __cg != "" && __cg != "0") {
		(__cg);
	}
	else if (catIDoverride != null) {
		(__cg = catIDoverride);
	}
	else {
		(__cg);
	}
    // END custom code
	  
	if (attributes){
		__ex=attributes.split("-_-");
	} else {
	__ex=new Array();
	}
	cmAddShop(["pr",__pr,"pm",__pm,"qt",__qt,"bp",__bp,"cg",__cg,"cd",__cd,"ha1",attributes ? cm_hex_sha1(attributes) : null,"on",__on,"tr",__tr,"at","9","tid","4","pc","N","sx11",store_id,"cc",currency,"sx13",account_name,"sx14",contract_name]);
	cmCalcSKUString();
}

function cmDisplayShop5s() {
	cmDisplayShops();
}

function cmDisplayShop9s() {
	cmCalcSKUString();
	cmDisplayShops();
}

function cmCalcSKUString() {
	__skuString = "";
	var __skuStringArray = new Array();
	for (var i = 0; i < __sArray.length; ++i) {
		// aggregate
		var __skuStringArrayIndex = -1;
		for (var y = 0; y < __skuStringArray.length; ++y) {
			if (__sArray[i][1] == __skuStringArray[y][0] ) {
				__skuStringArrayIndex = y;
			}
		}
		if (__skuStringArrayIndex == -1) {
			// it doesn't exist, so add it
			var newArrayIndex = __skuStringArray.length;
			__skuStringArray[newArrayIndex] = new Array();
			__skuStringArray[newArrayIndex][0] = __sArray[i][1];
			__skuStringArray[newArrayIndex][1] = __sArray[i][7];
			__skuStringArray[newArrayIndex][2] = __sArray[i][5];
		}
		else {
			// it exists, so update it
			var __oP = __skuStringArray[__skuStringArrayIndex][1];
			var __oQ = __skuStringArray[__skuStringArrayIndex][2];
			__skuStringArray[__skuStringArrayIndex][2] = parseInt(__sArray[i][5]) + __oQ;
			__skuStringArray[__skuStringArrayIndex][1] = (__oP*__oQ+__sArray[i][7]*__sArray[i][5])/(parseInt(__sArray[i][5])+parseInt(__oQ));
		}
	}
	for (var x = 0; x < __skuStringArray.length; ++x) {
		__skuString += "|"+__skuStringArray[x][0]+"|"+__skuStringArray[x][1]+"|"+__skuStringArray[x][2]+"|";
	}
}

function cmDisplayShops() {
	var i;
	for (i = 0; i < __sArray.length; ++i) {
		cmMakeTag(__sArray[i]);
	}
	__sArray = new Array();
}

function cmCreateOrderTag(__on,__tr,__sg,__cd,__ct,__sa,__zp, store_id, currency, promotion_name, promotion_discount, promotion_code,attributes) {
	if (((promotion_code == null) || (promotion_code == "")) && promotion_name) { promotion_code = "No Code"; } 
	if (attributes){
		var cm_exAttr=new Array();
		cm_exAttr=attributes.split("-_-");
	}
	cmMakeTag(["tid","3","osk",__skuString,"on",__on,"tr",__tr,"sg",__sg,"cd",__cd,"ct",__ct,"sa",__sa,"zp",__zp,"or11",store_id,"cc",currency,"or13",promotion_name,"or14",promotion_discount,"or15",promotion_code,"cm_exAttr",cm_exAttr]);
}

function cmCreateRegistrationTag(__cd,__em,__ct,__sa,__zp,__nl,__sd, store_id, customer_country, age, gender, marital_status, num_children, num_in_household, company_name, hobbies, income,attributes) {
	 if (attributes){
		var cm_exAttr=new Array();
		cm_exAttr=attributes.split("-_-");
	}
// custom code - converts 'age' value
		switch(age){
			case "1":
				age="20";
				break;
			case "2":
				age="30";
				break;
			case "3":
				age="40";
				break;
			case "4":
				age="50";
				break;
			case "5":
				age="60";
				break;
			case "6":
				age="70";
				break; 
			default:
				break;
		}
// END custom code
	
	cmMakeTag(["tid","2","cd",__cd,"em",__em,"ct",__ct,"sa",__sa,"zp",__zp,"nl",__nl,"sd",__sd,
	"cy",customer_country,"ag",age,"gd",gender,"ml",income,"cm_exAttr",cm_exAttr]);
}

function cmCreateErrorTag(__pi,__cg, store_id,attributes) {	
	if (attributes){
		var cm_exAttr=new Array();
		cm_exAttr=attributes.split("-_-");
	}
	cmMakeTag(["tid","404","pi",__pi,"cg",__cg,"pc","Y","pv1",store_id,"cm_exAttr",cm_exAttr]);
}

function cmMakeTag(__v) {
	var cm = new _cm("vn2", "e4.0");
	var i;
	for (i = 0; i < __v.length; i += 2) {
		var _n = __v[i];
		var _v = __v[i + 1];
		cm[_n] = _v;
	}

	var datestamp = new Date();	
	var stamp = (Math.floor(Math.random() * 11111111)) + datestamp.valueOf();	
	cm.rnd = stamp;
	
	if (cm.tid == "6") {
		cm.addTP();
		document.cookie = "cmTPSet=Y; path=/";
	}

	if (cm.tid == "1") {
		if (cI("cmTPSet") != 'Y') {
			cm.tid = "6";
			cm.pc = "Y";
			cm.addTP();
			document.cookie = "cmTPSet=Y; path=/";
		}
	}

	if (cm.tid != "4" && typeof(cm.cm_exAttr)!="undefined"){
		switch(cm.tid){
			case "6":
				prefix="pv";
				break;
			case "1":
				prefix="pv";
				break;
			case "2":
				prefix="rg";
				break;
			case "5":
				prefix="pr";
				break;
			case "3":
				prefix="o";
				break;
			case "14":
				prefix="c";
				break;
			case "15":
				prefix="e";
				break;
			default:
				break;
		}		
		var attrNum=cm.cm_exAttr.length;
		if (attrNum>15){
			attrNum=15;
		}
		for (i=0;i<attrNum;i++){
			if (cm.tid == "2"){
				Attval=prefix+(i+1);
			} else {
				Attval=prefix+"_a"+(i+1);
			}
			cm[Attval]=cm.cm_exAttr[i];
		}
		cm.cm_exAttr=null;
	}	
	if ((cm.pi == null) && (cm.pc == "Y")) {
		cm.pi = cmGetDefaultPageID();
	}

	
	// code to auto-propagate attributes to extra_fields

		var exfPrefix = {'6':'pv','1':'pv','3':'or','4':'sx','5':'ps','14':'cx'};
		var attPrefix = {'6':'pv_a','1':'pv_a','3':'o_a','4':'s_a','5':'pr_a','14':'c_a'};

		if ((cm.tid != '2') && (cm.tid != '15')) {
		    for (var x = 1; x <= 15; ++x) {
				cm[exfPrefix[cm.tid] + "" + x] = cm[attPrefix[cm.tid] + "" + x];
		    }
		}


	try{
		if (parent.cm_ref != null) {
			cm.rf = parent.cm_ref;
			if (cm.pc == "Y") {
				parent.cm_ref = document.URL;
			}
		}
	
		// 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; 
			if (cm.pc == "Y") {
				parent.cm_ref = cm.ul;
				parent.cm_set_mmc = false;
			}
		}
	}
	catch(err){}
	
	if (cm.ul == null) {
		cm.ul = window.location.href;
	}
	if (cm.rf == null) {
		cm.rf = document.referrer;
	}

	cm.ul = cmRemoveParameter("krypto",cm.ul);
	cm.rf = cmRemoveParameter("krypto",cm.rf);

	//check for zero price and zero quantity
	cmSafeZero(cm,["qt","bp","tr","sg"]);

	//check for manual_cm_mmc parameter;
	if (this.manual_cm_mmc != null) {
		cm.ul = cm.ul + ((cm.ul.indexOf("&") == -1) ? ((cm.ul.indexOf("?") == -1) ? "?" : "&") : "&") + "cm_mmc=" + this.manual_cm_mmc;
	}

	// convert MMC parameters to lowercase;
	cm.ul = cm.ul.replace(/cm_mmc/gi,"cm_mmc");
	cm.ul = cm.ul.replace(/cm_ven/gi,"cm_ven");
	cm.ul = cm.ul.replace(/cm_cat/gi,"cm_cat");
	cm.ul = cm.ul.replace(/cm_pla/gi,"cm_pla");
	cm.ul = cm.ul.replace(/cm_ite/gi,"cm_ite");
	if (cmCheckCMEMFlag){cmStartTagSet();}
    cm.writeImg();
	if (cmCheckCMEMFlag) {
		cmCheckCMEMFlag = false;
		cmCheckCMEM();
		cmSendTagSet();	
	}

	//check to see if we fire link click for email campaign (cm_cr)
	if (cmSendOSLinkClickTag) {
		if ((window.location.href.indexOf("cm_cr=OS:") > -1) || (window.location.href.indexOf("cm_cr=OS%3A") > -1) || (window.location.href.indexOf("cm_cr=OS%3a") > -1)) {
			var tempHref = window.location.href;
			tempHref = tempHref.split("cm_cr=OS:").join("cm_cr=");
			tempHref = tempHref.split("cm_cr=OS%3A").join("cm_cr=");
			tempHref = tempHref.split("cm_cr=OS%3a").join("cm_cr=");
			tempHref = tempHref.split("-_-E-mail%20Activity-_-").join("-_-1-_-");
			tempHref = tempHref.split("-_-E-mail%2BActivity-_-").join("-_-1-_-");
			tempHref = tempHref.split("-_-E-mail%2bActivity-_-").join("-_-1-_-");
			cmCreateManualLinkClickTag(tempHref,null,"Email");
			cmSendOSLinkClickTag = false;
		}
	}
// IO V4 call
	if (typeof cm_ted_io == 'function') {
		cm_ted_io(cm);
	}
}

function cmGetDefaultPageID () {
	var __p = window.location.pathname;
	var __t1 = __p.indexOf("?");
	if (__t1 != -1) __p = __p.substr(0, __t1);
	var __t2 = __p.indexOf("#");
	if (__t2 != -1) __p = __p.substr(0, __t2);
	var __t3 = __p.indexOf(";");
	if (__t3 != -1) __p = __p.substr(0, __t3);
	var __sp = __p.lastIndexOf("/");
	if (__sp == __p.length - 1) {
		__p = __p + "default.asp"; /* SET TO DEFAULT DOC NAME */
	}
	while (__p.indexOf("/") == 0) {
		__p = __p.substr(1,__p.length);
	}
	return(__p);
}

function cmIndexOfParameter (parameter, inString) {
	return inString.indexOf(parameter);
}

function cmExtractParameter (parameter, inString) {
    if (cmIndexOfParameter(parameter, inString) == -1) {
        return null;
    }
	var s = inString;
	var begin = s.indexOf(parameter);
	var end = s.indexOf("&", begin);
	if (end == -1) {
		end = s.length;
	}
	var middle = s.indexOf("=", begin);
	return s.substring(middle + 1, end).split("#",1).join("");
}

function cmRemoveParameter (parameter, inString) {
    if (cmIndexOfParameter(parameter, inString) == -1) {
        return inString;
    }
	var s = inString;
	var begin = s.indexOf(parameter);
	var start = (begin - 1);
	var end = s.indexOf("&", begin);
	if (end == -1) {
		end = s.length;
	}
	if (s.substring(start, begin) == "?") {    // retain leading "?"
		start = (start + 1);
		end = (end + 1);
	}
	return s.substring(0, start) + s.substring(end, s.length);
}

function cmCheckCMEM() {
	if (cmIndexOfParameter("cm_em",document.location.href) != -1){
		var emailAddress = cmExtractParameter("cm_em",document.location.href);
		if (emailAddress.indexOf(":")>-1){
			emailAddress=emailAddress.substring(emailAddress.indexOf(":")+1);
		}	
		cmCreateRegistrationTag(emailAddress,emailAddress);
	}
	if (cmIndexOfParameter("cm_lm",document.location.href) != -1){
		var emailAddress = cmExtractParameter("cm_lm",document.location.href);
		if (emailAddress.indexOf(":")>-1){
			emailAddress=emailAddress.substring(emailAddress.indexOf(":")+1);
		}	
		cmCreateRegistrationTag(emailAddress,emailAddress);
	}
}

function cmSafeZero(cm, checkArray) {
	// put logic here to convert number 0 to string "0"
	for (var i = 0; i < checkArray.length; ++i) {
		if ((cm[checkArray[i]] != null) && (cm[checkArray[i]] == 0)) {
			cm[checkArray[i]] = "0";
	}
}
}

if (defaultNormalize == null) { var defaultNormalize = null; }

function myNormalizeURL(url, isHref) {
	if (cmIndexOfParameter("#",url) != -1) {
		newURL = (cmRemoveParameter ("cm_cr",url));
	} else {
		var newURL = url;
	}
    
    if (isHref) {
	    var blackList = ["krypto="];
	    var paramString;
	    var paramIndex = newURL.indexOf("?");
	    var params;
	    var keepParams = new Array();
	    var goodParam;
	
	    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++) {
			//This match is case insensitive.  Remove .toLowerCase() to add case sensitivity
				if (params[i].toLowerCase().indexOf(blackList[j].toLowerCase()) == 0) {
					goodParam = false;
				}
			}
			if(goodParam == true) {
				keepParams[keepParams.length] = params[i];
			}
		}
		newURL += "?" + keepParams.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;
    }
}

/*  hash functions that support shop aggregation with attributes */
function cm_hex_sha1(s)    { return cm_rstr2hex(cm_rstr_sha1(cm_str2rstr_utf8(s))); }

function cm_rstr_sha1(s)
{
  return cm_binb2rstr(cm_binb_sha1(cm_rstr2binb(s), s.length * 8));
}

function cm_rstr2hex(input)
{
  var hex_tab = 0 ? "0123456789ABCDEF" : "0123456789abcdef";
  var output = "";
  var x;
  for(var i = 0; i < input.length; i++)
  {
    x = input.charCodeAt(i);
    output += hex_tab.charAt((x >>> 4) & 0x0F)
           +  hex_tab.charAt( x        & 0x0F);
  }
  return output;
}

function cm_str2rstr_utf8(input)
{
  var output = "";
  var i = -1;
  var x, y;

  while(++i < input.length)
  {
    /* Decode utf-16 surrogate pairs */
    x = input.charCodeAt(i);
    y = i + 1 < input.length ? input.charCodeAt(i + 1) : 0;
    if(0xD800 <= x && x <= 0xDBFF && 0xDC00 <= y && y <= 0xDFFF)
    {
      x = 0x10000 + ((x & 0x03FF) << 10) + (y & 0x03FF);
      i++;
    }

    /* Encode output as utf-8 */
    if(x <= 0x7F)
      output += String.fromCharCode(x);
    else if(x <= 0x7FF)
      output += String.fromCharCode(0xC0 | ((x >>> 6 ) & 0x1F),
                                    0x80 | ( x         & 0x3F));
    else if(x <= 0xFFFF)
      output += String.fromCharCode(0xE0 | ((x >>> 12) & 0x0F),
                                    0x80 | ((x >>> 6 ) & 0x3F),
                                    0x80 | ( x         & 0x3F));
    else if(x <= 0x1FFFFF)
      output += String.fromCharCode(0xF0 | ((x >>> 18) & 0x07),
                                    0x80 | ((x >>> 12) & 0x3F),
                                    0x80 | ((x >>> 6 ) & 0x3F),
                                    0x80 | ( x         & 0x3F));
  }
  return output;
}

function cm_rstr2binb(input)
{
  var output = Array(input.length >> 2);
  for(var i = 0; i < output.length; i++)
    output[i] = 0;
  for(var i = 0; i < input.length * 8; i += 8)
    output[i>>5] |= (input.charCodeAt(i / 8) & 0xFF) << (24 - i % 32);
  return output;
}

function cm_binb2rstr(input)
{
  var output = "";
  for(var i = 0; i < input.length * 32; i += 8)
    output += String.fromCharCode((input[i>>5] >>> (24 - i % 32)) & 0xFF);
  return output;
}

function cm_binb_sha1(x, len)
{
  /* append padding */
  x[len >> 5] |= 0x80 << (24 - len % 32);
  x[((len + 64 >> 9) << 4) + 15] = len;

  var w = Array(80);
  var a =  1732584193;
  var b = -271733879;
  var c = -1732584194;
  var d =  271733878;
  var e = -1009589776;

  for(var i = 0; i < x.length; i += 16)
  {
    var olda = a;
    var oldb = b;
    var oldc = c;
    var oldd = d;
    var olde = e;

    for(var j = 0; j < 80; j++)
    {
      if(j < 16) w[j] = x[i + j];
      else w[j] = cm_bit_rol(w[j-3] ^ w[j-8] ^ w[j-14] ^ w[j-16], 1);
      var t = cm_safe_add(cm_safe_add(cm_bit_rol(a, 5), cm_sha1_ft(j, b, c, d)),
                       cm_safe_add(cm_safe_add(e, w[j]), cm_sha1_kt(j)));
      e = d;
      d = c;
      c = cm_bit_rol(b, 30);
      b = a;
      a = t;
    }

    a = cm_safe_add(a, olda);
    b = cm_safe_add(b, oldb);
    c = cm_safe_add(c, oldc);
    d = cm_safe_add(d, oldd);
    e = cm_safe_add(e, olde);
  }
  return Array(a, b, c, d, e);

}

function cm_sha1_ft(t, b, c, d)
{
  if(t < 20) return (b & c) | ((~b) & d);
  if(t < 40) return b ^ c ^ d;
  if(t < 60) return (b & c) | (b & d) | (c & d);
  return b ^ c ^ d;
}

function cm_sha1_kt(t)
{
  return (t < 20) ?  1518500249 : (t < 40) ?  1859775393 :
         (t < 60) ? -1894007588 : -899497514;
}

function cm_safe_add(x, y)
{
  var lsw = (x & 0xFFFF) + (y & 0xFFFF);
  var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
  return (msw << 16) | (lsw & 0xFFFF);
}

function cm_bit_rol(num, cnt)
{
  return (num << cnt) | (num >>> (32 - cnt));
}
