<!--
/*
 * cmdatatagutils.js
 *
 * Coremetrics Tag v4.0, 4/18/2004
 * COPYRIGHT 1999-2002 COREMETRICS, INC. 
 * ALL RIGHTS RESERVED. U.S.PATENT PENDING
 *
 * The following functions aid in the creation of Coremetrics data tags.
 *
 *
 *
 *	CHANGE LOG:
 *
 *
 *  20060905:			Added Normalization code for:  MSCSProfile=, code=, sid=
 *							COMPLETED BY:  L. CONWELL
 *
 *	20060905:			Changed the product view tag to add a flag to turn of the page
 *							view tag functionality.  This will be for temporary use until the
 *							end of 2006 when Hanover will go to one product view per 
 *							product view page.
 *							COMPLETED BY:  L. CONWELL
 *  20061221:			Added function calls for manual link click tagging, provided by
 *							Chris Luton and implemented by Joel Macaluso
 *	2/25/2008			Hutch White		Consolidate all Hanover Libraries.  Set logic for
													cmClient and cmHost variables to set client settings
 */

// TAG GENERATING FUNCTIONS ---------------------------------------------------
var	pageURL = document.URL.toLowerCase();
var im=0;

cm_TrackLink="A";
cm_TrackImpressions="RS";

if (typeof(cmClient) == "undefined" && typeof(cmHost) == "undefined"){
	if (pageURL.indexOf("domestications.com") >= 0)
	{
		cm_ClientID = "30000088";
		cm_HOST = "www11.domestications.com/eluminate?";
	}
	else if ((pageURL.indexOf("csdevdomestications") >= 0) || (pageURL.indexOf("csqadomestications") >= 0) || (pageURL.indexOf("css2domestications") >= 0))
	{
		cm_ClientID = "30000088";
		cm_HOST = "test.coremetrics.com/eluminate?";
	}
	else if (pageURL.indexOf("internationalmale.com") >= 0)
	{
		cm_ClientID = "10000117";
		cm_HOST = "www11.internationalmale.com/eluminate?";
		im=1;
	}
	else if ((pageURL.indexOf("csdevim") >= 0) || (pageURL.indexOf("csqainternationalmale") >= 0) || (pageURL.indexOf("css2internationalmale") >= 0))
	{
		im=1;
		cm_ClientID = "10000117";
		cm_HOST = "test.coremetrics.com/eluminate?";
	}
	else if (pageURL.indexOf("scandiadown.com") >= 0)
	{
		cm_ClientID = "90112733";
		cm_HOST = "www11.scandiadown.com/eluminate?";
	}
	else if ((pageURL.indexOf("csdevscandia") >= 0) || (pageURL.indexOf("csqascandia") >= 0) || (pageURL.indexOf("css2scandia") >0))
	{
		cm_ClientID = "90112733";
		cm_HOST = "test.coremetrics.com/eluminate?";
	}
	else if (pageURL.indexOf("silhouettes.com") >= 0) 
	{
		cm_ClientID = "30000090";
		cm_HOST = "www11.silhouettes.com/eluminate?";
	}
	else if ((pageURL.indexOf("csdevsilhouettes") >= 0) || (pageURL.indexOf("csqasilhouettes") >= 0) || (pageURL.indexOf("css2silhouettes") >= 0))
	{
		cm_ClientID = "30000090";
		cm_HOST = "test.coremetrics.com/eluminate?";
	}
	else if (pageURL.indexOf("thecompanystore.com") >= 0)
	{
		cm_ClientID = "30000089";
		cm_HOST = "www11.thecompanystore.com/eluminate?";
	}
	else if ((pageURL.indexOf("csdevtcs") >= 0) || (pageURL.indexOf("csqatcs") >= 0) || (pageURL.indexOf("css2tcs") >= 0))
	{
		cm_ClientID = "30000089";
		cm_HOST = "test.coremetrics.com/eluminate?";
	}
	else if (pageURL.indexOf("undergear.com") >= 0) 
	{
		cm_ClientID = "10000119";
		cm_HOST = "www11.undergear.com/eluminate?";
	}
	else if ((pageURL.indexOf("csdevundergear") >= 0) || (pageURL.indexOf("csqaundergear") >= 0) || (pageURL.indexOf("css2undergear") >= 0))
	{
		cm_ClientID = "10000119";
		cm_HOST = "test.coremetrics.com/eluminate?";
	}
	else
	{
		cm_ClientID = "99999999";
		cm_HOST = "test.coremetrics.com/eluminate?";
	}
} else {
	cm_ClientID=cmClient;
	cm_HOST=cmHost;
}

function cmSetProduction(){
	if (pageURL.indexOf("domestications.com") >= 0)
	{
		cm_ClientID = "30000088";
		cm_HOST = "www11.domestications.com/eluminate?";
	}
	else if ((pageURL.indexOf("csdevdomestications") >= 0) || (pageURL.indexOf("csqadomestications") >= 0) || (pageURL.indexOf("css2domestications") >= 0))
	{
		cm_ClientID = "30000088";
		cm_HOST = "test.coremetrics.com/eluminate?";
	}
	else if (pageURL.indexOf("internationalmale.com") >= 0)
	{
		cm_ClientID = "10000117";
		cm_HOST = "www11.internationalmale.com/eluminate?";
		im=1;
	}
	else if ((pageURL.indexOf("csdevim") >= 0) || (pageURL.indexOf("csqainternationalmale") >= 0) || (pageURL.indexOf("css2internationalmale") >= 0))
	{
		im=1;
		cm_ClientID = "10000117";
		cm_HOST = "test.coremetrics.com/eluminate?";
	}
	else if (pageURL.indexOf("scandiadown.com") >= 0)
	{
		cm_ClientID = "90112733";
		cm_HOST = "www11.scandiadown.com/eluminate?";
	}
	else if ((pageURL.indexOf("csdevscandia") >= 0) || (pageURL.indexOf("csqascandia") >= 0) || (pageURL.indexOf("css2scandia") >0))
	{
		cm_ClientID = "90112733";
		cm_HOST = "test.coremetrics.com/eluminate?";
	}
	else if (pageURL.indexOf("silhouettes.com") >= 0) 
	{
		cm_ClientID = "30000090";
		cm_HOST = "www11.silhouettes.com/eluminate?";
	}
	else if ((pageURL.indexOf("csdevsilhouettes") >= 0) || (pageURL.indexOf("csqasilhouettes") >= 0) || (pageURL.indexOf("css2silhouettes") >= 0))
	{
		cm_ClientID = "30000090";
		cm_HOST = "test.coremetrics.com/eluminate?";
	}
	else if (pageURL.indexOf("thecompanystore.com") >= 0)
	{
		cm_ClientID = "30000089";
		cm_HOST = "www11.thecompanystore.com/eluminate?";
	}
	else if ((pageURL.indexOf("csdevtcs") >= 0) || (pageURL.indexOf("csqatcs") >= 0) || (pageURL.indexOf("css2tcs") >= 0))
	{
		cm_ClientID = "30000089";
		cm_HOST = "test.coremetrics.com/eluminate?";
	}
	else if (pageURL.indexOf("undergear.com") >= 0) 
	{
		cm_ClientID = "10000119";
		cm_HOST = "www11.undergear.com/eluminate?";
	}
	else if ((pageURL.indexOf("csdevundergear") >= 0) || (pageURL.indexOf("csqaundergear") >= 0) || (pageURL.indexOf("css2undergear") >= 0))
	{
		cm_ClientID = "10000119";
		cm_HOST = "test.coremetrics.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();
}

/*
 * Takes the URL of the current page and removes its extension
 * and web site/directory.  For example, this function will
 * return the string "MyPage" for the URL
 * http://www.mysite.com/directory1/directory2/MyPage.jsp"
 */
function getFileNameFromURL() { 
	var pageName = window.location.pathname; 

	// Hanover does not need the extension removed
	/*
	var extensionPos = pageName.lastIndexOf("."); 
	if (extensionPos != -1) { 
			pageName = pageName.substr(0, extensionPos); 
	} 
	*/

	var parentDirPos = pageName.lastIndexOf("/"); 
	if (parentDirPos != -1) { 
			pageName = pageName.substr(parentDirPos + 1, pageName.length - parentDirPos - 1); 
	} 

	return(pageName); 
}

/*
 * Checks to see if a parameter exists in the request search string.
 * Returns -1 if not found, or the index of the first character of the 
 * name in the name-value pair if found.
 */
function indexOfParameter (parameter) {
	return document.URL.indexOf(parameter);
}

/*
 * Extracts the value of a name-value pair in the request search string.
 */
function extractParameter (parameter) {
    if (indexOfParameter(parameter) == -1) {
        return "";
    }
	var s = location.search;
	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);
}

/*
 * Creates a Tech Props tag.
 * pageID		: required. Page ID to set on this Pageview tag
 */
function cmCreateTechPropsTag(pageID, categoryID) {

	if(pageID == null) {
		pageID = cmGetDefaultPageID();
	}

	var cm=new _cm("tid", "6", "vn2", "e4.0");
	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;
	}

	// 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;
	}
	cm.ul=document.URL;
	//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;
	}	
	cm.addTP();
	cm.writeImg();
	
}
/*
 * Creates a Pageview tag with the given Page ID
 *
 * pageID	: required. Page ID to set on this Pageview tag
 * categoryID	: optional. Category ID to set on this Pageview tag
 * searchString	: optional. Internal search string enterred by user to reach
 *				  this page.
 *
 * returns nothing, causes a document.write of an image request for this tag.
 */
function cmCreatePageviewTag(pageID, categoryID, searchString, searchResults) {
	if (pageID == null) {
		pageID = cmGetDefaultPageID();
	}

	var cm = new _cm("tid", "1", "vn2", "e4.0");
	cm.pi = pageID;
	if (searchString) {
		cm.se = searchString;
	}
	cm.sr = searchResults;
	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.ul=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; 
		parent.cm_ref = cm.ul;
		parent.cm_set_mmc = false;
	}
	//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;
	}
	cm.writeImg();
}

/*
 * Creates a category tag with the following format:
 *
 * Page ID = CATEGORY: <dept_name> (<dept_id>)
 * Category = <dept_name> (<dept_id>)
 *
 * Page count = Y
 */
function cmCreateCategoryTag(dept_name, dept_id) {
	var cm = new _cm("tid", "1", "vn2", "e4.0");
	// get the referrer from the frameset
	if (parent.cm_ref != null) {
		cm.rf = parent.cm_ref;
		parent.cm_ref = document.URL;
	}
    var cm_pagenumber = extractParameter("page");
    if (cm_pagenumber != "") {
        if (cm_pagenumber != "1") {
            cm.pi = "CATEGORY:" + dept_name + " (" + dept_id + ")" + " PG" + cm_pagenumber;
        }
        else {
            cm.pi = "CATEGORY:" + dept_name + " (" + dept_id + ")";
        }
    }
    else {
        cm.pi = "CATEGORY:" + dept_name + " (" + dept_id + ")";
    }
	cm.cg = dept_name + " (" + dept_id + ")";
	cm.cl = cm.cg;
	cm.ul=document.URL;	
	//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;
	}	
	cm.writeImg();
}


function cmCreateCategoryTag_Catalog() {
	var cm = new _cm("tid", "1", "vn2", "e4.0");
	// get the referrer from the frameset
	if (parent.cm_ref != null) {
		cm.rf = parent.cm_ref;
		parent.cm_ref = document.URL;
	}
 	cm.pi = getFileNameFromURL();
	cm.cg =  "catalog view";
	cm.cl = cm.cg;
	cm.ul=document.URL;
	//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;
	}	
	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(categoryID) {
	cmCreatePageviewTag(cmGetDefaultPageID(), categoryID, null);
}


/*
 * Creates a product tag in the following format:
 *
 * Page ID = PRODUCT: <dept_name> (<dept_id>):<prod_name> (<prod_id>)
 * Product ID = <prod_id>
 * Product Name = <prod_name> (<prod_id>)
 * Category = <dept_name> (<dept_id>)
 *
 * Page count = Y
 */
function cmCreateProductTag(dept_name, dept_id, prod_name, prod_id, search, count) {
	var cm = new _cm("tid", "5", "vn2", "e4.0");
	// get the referrer from the frameset	
	if (parent.cm_ref != null) {
		cm.rf = parent.cm_ref;
	}
	cm.pi = "PRODUCT:" + dept_name + " (" + dept_id + "):" + prod_name + " (" + prod_id + ")";
	cm.pr = prod_id;
	cm.pm = prod_name + " (" + prod_id + ")";
	cm.cg = dept_name + " (" + dept_id + ")";
	cm.se = search;
	cm.pc = count;
	cm.ul=document.URL;	
	//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;
	}	
	cm.writeImg();
}

/*
 * 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, pageFlag) {
	var cm = new _cm("tid", "5", "vn2", "e4.0");

	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.ul=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; 
		parent.cm_ref = cm.ul;
		parent.cm_set_mmc = false;
	}
	//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;
	}
	cm.pr = productID;
	cm.pm = productName;
	cm.cg = categoryID;

	if (pageFlag == 'Y')
	{
		cm.pc = "Y";
	}
	else if (pageFlag != 'Y')
	{
		cm.pc = "N";
	}
	
	cm.pi = "PRODUCT: " + productName + " (" + productID + ")";

	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 cmShopSKUs = "";

/* Internal, to support aggregation */
function cmGetProductIndex(id){
	var i =0;
	for (i=0; i<cmShopCounter; i++)
	{
		if (id==cmShopIds[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(_p1, _p2, _p3, _p4, categoryID) {
	if (im!=1)	{
		/*
		 * Parameter values for traditional shop 5
		 *
		 * productID=_p1
		 * productName=_p2
		 * productQuantity=_p3
		 * productPrice=_p4
		 */

		_p1 = _p1.toUpperCase();

		var index = cmGetProductIndex(_p1);
		if(index!=-1){
			var oldPrice = cmShopPrices[index];
			var oldQty = cmShopQtys[index];
			var newQty = oldQty + parseInt(_p3);
			var newPrice = (oldPrice*oldQty + parseInt(_p3)*parseFloat(_p4))/(newQty);

			cmShopPrices[index] = newPrice;
			cmShopQtys[index] = newQty;
		} else {
			if (!categoryID) {
				categoryID = "";
			}

			cmShopProducts[cmShopCounter] = _p2;
			cmShopIds[cmShopCounter] = _p1;
			cmShopCats[cmShopCounter] = categoryID;
			cmShopQtys[cmShopCounter] = parseInt(_p3);
			cmShopPrices[cmShopCounter] = parseFloat(_p4);
			cmShopCounter++;

		}

		cmShopSKUs = cmGetOSK();
		cmDisplayShop5s();
	} else {
		/*
		 * Parameter values for IM shop 5
		 *
		 * productID=_p1
		 * productName=_p4
		 * productQuantity=_p2
		 * productPrice=_p3
		 */

		var cm = new _cm("tid", "4", "vn2", "e4.0");
		cm.pr = _p1;
		cm.pm = _p4;
		cm.cg = categoryID;
		cm.at = "5";
		cm.qt = _p2;
		cm.bp = _p3;
		cm.pc = "N";
		cm.writeImg();
	}
}

/* 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", "e4.0");
		cm.at = "5";
		cm.pr = cmShopIds[i]; 
		cm.pm = cmShopProducts[i];
		cm.cg = cmShopCats[i];
		cm.qt = cmShopQtys[i] ;
		cm.bp = cmShopPrices[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(_p1, _p2,  _p3, _p4,  _p5,  _p6, _p7,  _p8) {
	if (im!=1)	{
		/*
		 * Parameter values for traditional shop 9
		 *
		 * productID=_p1
		 * productName=_p2
		 * productQuantity=_p3
		 * productPrice=_p4
		 * customerID=_p5
		 * orderID=_p6
		 * orderTotal=_p7
		 * categoryID=_p8
		 */
		_p1 = _p1.toUpperCase();

		var index = cmGetProductIndex(_p1);
		if(index!=-1){
			var oldPrice = cmShopPrices[index];
			var oldQty = cmShopQtys[index];
			var newQty = oldQty + parseInt(_p3);
			var newPrice = (oldPrice*oldQty + parseInt(_p3)*parseFloat(_p4))/(newQty);

			cmShopPrices[index] = newPrice;
			cmShopQtys[index] = newQty;
		} else {
			if (!_p8) {
				_p8 = "";
			}
			cmShopProducts[cmShopCounter] = _p2;
			cmShopIds[cmShopCounter] = _p1;			
			cmShopOrderIds[cmShopCounter] = _p6;
			cmShopOrderPrices[cmShopCounter] = _p7;
			cmShopCustomerIds[cmShopCounter] = _p5;
			cmShopCats[cmShopCounter] = _p8;
			cmShopQtys[cmShopCounter] = parseInt(_p3);
			cmShopPrices[cmShopCounter] = parseFloat(_p4);
			cmShopQtys[index] = newQty;
			cmShopCounter++;
		}
		cmShopSKUs = cmGetOSK();
		cmDisplayShop9s();
	} else {
		/*
		 * Parameter values for IM shop 9
		 *
		 * productID=_p5
		 * productName=_p4
		 * productQuantity=_p7
		 * productPrice=_p8
		 * customerID=_p2
		 * orderID=_p1
		 * orderTotal=_p3
		 * categoryID=_p6
		 */
		var cm = new _cm("tid", "4", "vn2", "e4.0");
		cm.at = "9";
		cm.pr = _p5;
		cm.pm = _p4;
		cm.cg = _p6;
		cm.qt = _p7;
		cm.bp = _p8;
		cm.cd = _p2;
		cm.on = _p1;
		cm.tr = _p3;
		cm.pc = "N";
		cm.writeImg();
	}
}


/* 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", "e4.0");
		cm.at = "9";
		cm.pr = cmShopIds[i]; 
		cm.pm = cmShopProducts[i];
		cm.cg = cmShopCats[i];
		cm.qt = cmShopQtys[i] ;
		cm.bp = cmShopPrices[i];
		cm.cd = cmShopCustomerIds[i];
		cm.on = cmShopOrderIds[i];
		cm.tr = cmShopOrderPrices[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(_p1, _p2, _p3, _p4, _p5,_p6, _p7,_p8) {
	var cm = new _cm("tid", "3", "vn2", "e4.0");

	if (im!=1)	{
		/*
		 * Parameter values for traditional order tag
		 *
		 * orderID=_p1
		 * orderTotal=_p2
		 * orderShipping=_p3
		 * customerID=_p4
		 * customerCity=_p5
		 * customerState=_p6
		 * customerZip=_p7
		 */
		cm.on = _p1;
		cm.tr = _p2;
		cm.osk = cmShopSKUs;
		cm.sg = _p3;
		cm.cd = _p4;
		cm.sa = _p6;
		cm.ct = _p5;
		cm.zp = _p7;
	} else {
		/*
		 * Parameter values for IM order tag
		 *
		 * orderID=_p1
		 * orderTotal=_p3
		 * orderShipping=_p8
		 * customerID=_p2
		 * customerCity=_p5
		 * customerState=_p6
		 * customerZip=_p7
		 * sku_data=_p4
		 */
		cm.pi = "Order Confirmation";
		cm.cd = _p2;
		cm.on = _p1;
		cm.tr = _p3;
		cm.osk = _p4;
		cm.sa = _p6;
		cm.ct = _p5;
		cm.zp = _p7;
		cm.sg = _p8;
		cm.pc = "Y";
	}
	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(_p1, _p2, _p3,	_p4, _p5, _p6,_p7, _p8, _p9, _p10, _p11, _p12, _p13) {
	var cm = new _cm("tid", "2", "vn2", "e4.0");
	if (im!=1)	{
		/*
		 * Parameter values for traditional order tag
		 *
		 * customerID=_p1
		 * customerEmail=_p2
		 * customerCity=_p3
		 * customerState=_p4
		 * customerZIP=_p5
		 * newsletterName=_p6
		 * subscribe=_p7
		 * country=_p8
		 * extra1=_p9
		 * extra2=_p10
		 * extra3=_p11
		 * extra4=_p12
		 * extra5=_p13
		 */
		cm.cd = _p1;
		cm.em = _p2;
		cm.sa = _p4;
		cm.ct = _p3;
		cm.zp = _p5;

		if (_p6 && _p7) {
			cm.nl = _p6;
			cm.sd = _p7;
		}

		cm.cy =_p8;
		cm.rg11 = _p9;	// Hanover Opt Status
		cm.rg12 = _p10;	// Hanover Registration Status
		cm.rg13 = _p11;	// Buyers Club Member Flag
		cm.rg14 = _p12;	// Source Code
		cm.rg15 = _p13;	// Private Label Credit Card Flag
	} else {
		/*
		 * Parameter values for traditional order tag
		 *
		 * reg_name=_ps1
		 * cust_first_name=_ps2
		 * cust_zip=_ps3
		 * cust_id=_ps4
		 * cust_email=_ps5
		 * subscribed_flag=_ps6
		 * count_page_flag=_ps7
		 */
		cm.pc = _ps7;
		cm.pi = _ps1;
		cm.cd = _ps4;
		cm.sd = _ps6;
		cm.nl = _ps1;
		cm.em = _ps5;
		cm.fn = _ps2;
		cm.zp = _ps3;
	}
	cm.ul=document.URL;	
	//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;
	}	
	cm.writeImg();
}

/* Creates an Error Tag
 *
 * returns nothing, causes a document.write of an image request for this tag.
 */
function cmCreateErrorTag(pageID, categoryID) {
	var cm=new _cm("tid", "404", "vn2", "e4.0");  //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.ul=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; 
		parent.cm_ref = cm.ul;
	//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;
	}		
		parent.cm_set_mmc = false;
	}

	cm.pc = "Y";
	if(pageID == null) {
		cm.pi = cmGetDefaultPageID();
	} else {
		cm.pi = pageID;
	}
	cm.cg = categoryID;
	cm.writeImg();
}

// HELPER FUNCTIONS -----------------------------------------------------------
/* These functions are used by the tag-generating functions and/or may be used
 * in in general as convenience functions
 */

//  Manual Impression Tag

function cmCreateImpressionTag(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();
}


/*
 * 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 cmGetDefaultPageID() { 
	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; }

function myNormalizeURL(url, isHref) { 
  
     var newURL = url; 
     var blackList = ["MSCSProfile=","code=", "sid=","param1="]; 
     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++) { 
                if (params[i].indexOf(blackList[j]) == 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;
    }
}
//-->