<!--
// $Id: cmdatatagutils.js 70399 2008-08-27 21:22:20Z cbwilliams $
//Copyright 2000-2004,Coremetrics 4.0.18 $Revision: 94450 $
//CMX Version for all sites 

// This function gets the rf field for a cm object, based on either the cmrf
// url parameter (which is present after a flash-detection redirect) or the 
// document referrer.
// The following functions aid in the creation of Coremetrics data tags.
//
// Date         Modifier        Description
// 05-Jan-07    Andy Cabezas    Gomez traffic blocking
// 09-Jan-07    Hutch White     Add cm_ref detection for Referring URL forwarding
// 18-Jan-07    Tim Gilbert     Falling back to cmrf if cm_ref not found - this 
//                              is needed for Flash redirection which uses cmrf.
// 30-Jan-07    Tim Gilbert     Using cm_ref for redirects again; misc cleanup.
// 20-Feb-07	Hutch White     Make ParseRef check for cm_ref case insensitive
// 08-Jun-07	Hutch White	    Added conversion, element, all manual tags, trackimpressions RS
// 30-Oct-07	C Williams	    Added code to ProductTag to prevent duplicate viewset prefixes
//                              eg, E:E:ABC. This code is maintained by WSI to handle Akamai 
//                              caching issues.
// 04-30-08		MOCHOA          Enabled MovieTime Tagging Function
//                              Disable Impression Tracking
// 05/16/08		HWHITE          Add cm_em parameter checking
// 07/29/08		WBIRD           set cm.ul=document.URL; as appropriate (5377-6058708; CI-14492)
// 07/30/08		LHIBBARD        Corrected cm_em to not be a page view
// 07/31/08 	LHIBBARD        Added Bazaarvoice tagging
// 

var cm_TrackLink = "A";
var cm_TrackImpressions = "";

function cmCheckEmParameter() {
	var emParam
	if (cmIndexOfParameter("cm_em") != -1){
		var emParam="cm_em";
	}
	if (cmIndexOfParameter("cm_lm") != -1){
		var emParam="cm_lm";
	}
	if (emParam){
		var s = document.URL;
		var begin = s.toLowerCase().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];
		}

		var cm = new _cm("tid", "2", "vn2", "e4.0");
		cm.pi = "EMAIL ENTRY";
		cm.cd = emailAddress;
		cm.em = emailAddress;
		cm.ul = document.URL;
		cm.pc = "N"
		if (cmGomezKeynoteFlag == "0") {
		cm.writeImg();
    	}	
	}
}

function cmIndexOfParameter (parameter) {
	return document.location.href.toLowerCase().indexOf(parameter.toLowerCase());
}

/*		
 * cmMovieTime = Custom Tag to Track Time Viewing Movies		
 * MovieID is the Movie Identifier, unique to domain		
 * status denotes start and stop.
 *
 * MovieID - unique movie identifier (required)
 * status  - track status, "0"=start, "1"=pause,	"2"=play, "3"=end (required)
 * stamp   - time stamp	(required)
 * pageID  - pageID value from pageview tag
 * playerID- identifier for player type -  0=Flash, 1=Windows Media Player, 2= Real Player, 3= Quicktime, 4=other
 */		
		
function cmMovieTime(MovieID, status,pageID,playerID) {		
	var datestamp = new Date();	
	var stamp = (Math.floor(Math.random() * 11111111)) + datestamp.valueOf();	
	var cm = new _cm("tid", "7", "vn2", "e4.0");	
		
	cm.li = 500;	
	cm.ps1 = MovieID;	
	cm.ps2 = status;	
	cm.ps3 = datestamp.getTime();
	cm.ps4 = pageID;
	cm.ps5 = playerID;
	cm.ps6 = stamp;
	cm.ul=document.URL;

	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.ul=document.URL;

	cm.writeImg();
 }
 
 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.ul=document.URL;
	
	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.ul=document.URL;
	
	cm.writeImg();
}
 
 function cmCreateManualImpressionTag(pageID, trackSP, trackRE) {
		var cm = new _cm("tid","9","vn2","e4.0");
		cm.pi = pageID;
		cm.cm_sp = trackSP;
		cm.cm_re = trackRE;
		cm.st = cm_ClientTS;
		cm.ul=document.URL;

		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);
	}
}

/* manual PageviewTag for off site page tagging.  Allows client to supply URL and Referring URL
*/
function cmCreateManualPageviewTag(pageID, categoryID,DestinationURL,ReferringURL,searchTerm) {
	var cm = new _cm("tid","1","vn2","e4.0");
	cm.pi = pageID;
	cm.cg = categoryID;
	cm.ul = DestinationURL;
	cm.rf = ReferringURL;
	if (searchTerm) {
		cm.se=searchTerm;
	}
	cm.ul=document.URL;

	cm.writeImg();			  
}

var cmGomezKeynoteFlag = "0";

if (cGN.indexOf("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; GomezAgent 2.0)") >= 0)
{
    var cmGomezKeynoteFlag = "1";
}

function ParseRef (url) {
    var cm_ref;
    if (url.toLowerCase().indexOf("cm_ref=") >= 0) {
        var start = url.toLowerCase().indexOf("cm_ref=") + 7;
        var stop = url.indexOf("&", start);
        if (stop < 0) {
            stop = url.length;
        }
        cm_ref = unescape(url.substring(start, stop));
    }
    // Fall back to document.referrer if nothing is in the URL
    if (!cm_ref && document.referrer) {
        return document.referrer;
    }
    return cm_ref;
}

function cmCreateTechPropsTag(pageID) {
    var cm=new _cm("tid", "6", "vn2", "e3.1");
    cm.ul = resetVCPIVariables(document.URL);
    cm.pi=pageID;
    cm.pc="Y";

    cm.addTP();
    cm.rf=ParseRef(document.URL);
    if (cmGomezKeynoteFlag == "0")
    {
		cmCheckEmParameter();
        cm.writeImg();
    }
}
function getFileNameFromURL() { 
    var pageName = window.location.pathname; 
    // eliminates everything after "?" (for Opera browswers)
    var queryPos = pageName.lastIndexOf("?");
    if (queryPos != -1) {
        pageName = pageName.substr(0, queryPos);
    }
    var slashPos = pageName.lastIndexOf("/");
    if (slashPos == pageName.length - 1) {
        pageName = pageName + "index.cfm"; //***********Default Page Name
    }
    while (pageName.indexOf("/") == 0) {
        pageName = pageName.substring(1);
    }
    var pos = pageName.indexOf("//"); 
    while (pos>-1) { 
        pageName= "" + pageName.substring(0, pos) + "/" + pageName.substring(pos + 2);
        pos = pageName.indexOf("//");
    }
    return(pageName); 
}

function indexOfParameter (parameter) {
    return document.URL.indexOf(parameter);
}

function custIDcheck(cust_id) {
    var id_value;
    id_value = cI("cmCustID");
    if (id_value == null) {
        var foreverDate = new Date();
        foreverDate.setFullYear(foreverDate.getFullYear() + 50);
        id_value = (Math.round(Math.random() * 1000000000000)) + (foreverDate.getTime()%1000);
        document.cookie = "cmCustID=" + id_value + "; expires=" + foreverDate.toGMTString() + ";path=/;";
    }
    return id_value;
}

function getUrlParameters(urlStr)
{
    var parameters = new Object();
    var paramStart = urlStr.indexOf('?');
    if (paramStart < 0)
    {
        return parameters;
    }
    
    var paramEnd = urlStr.indexOf('#');
    if (paramEnd < 0)
    {
        paramEnd = urlStr.length;
    }
    
    var paramList = urlStr.substring(paramStart+1).split('&');
    for (var i = 0; i < paramList.length; ++i)
    {
        paramList[i] = paramList[i].split('=');
        parameters[unescape(paramList[i][0])] = unescape(paramList[i][1]);
    }
    
    return parameters;
}

function getViewsetFromCategory(category)
{
    var colon = category.indexOf(':');
    if (colon < 0)
    {
        return "E";
    }

    return category.substring(0, colon);
}

function getCategoryOverride(bannercookiename)
{
    var params = getUrlParameters("" + location.href);
    
    if (typeof params.bnrid == "string" && params.bnrid.length > 0)
    {
        return "Campaign";
    }
    
    if (typeof params.cm_src == "string" &&
        params.cm_src.length > 0 &&
        params.cm_src != "None" )
    {
        return params.cm_src;
    }
    
    return null;
}

function writeCmSrc()
{
    //alert(cmCategoryId);
    document.write('<input type="hidden" name="u_cmsrc" value="' + cmCategoryId + '">');
}

function cmCreatePageViewTag(page_id, search_term, search_results, customer_service_flag, registry_flag, unused_referrer_param, category) {
    var cm = new _cm("tid", "1", "vn2", "e3.1");
    cm.ul = resetVCPIVariables(document.URL);
    if (page_id) {
        cm.pi = page_id;
    } 
    else {
        cm.pi = getFileNameFromURL();
    }
    if (search_term) {
        cm.se = search_term;
        cm.li = "1";
        cm.ps1 = search_term;
        cm.ps2 = search_results;
        cm.sr = search_results;    
    }
    
    
    if (customer_service_flag) {
        cm.pv2 = "CS";
    }
    if (registry_flag) {
        cm.pv4 = "Registry";
    }
    if (category) {
        cm.cg = category;
    }
    cm.ul=cmConvertMMC(cm.ul);
    cm.rf=ParseRef(document.URL);

    if (cmGomezKeynoteFlag == "0")
    {
		cmCheckEmParameter();
        cm.writeImg();
    }
}

function cmCreateCategoryTag(cat_name, cat_id, page_num, registry_flag) {
    var cm = new _cm("tid", "1", "vn2", "e3.1");
    cm.ul = resetVCPIVariables(document.URL);
    cm.pi = "CATEGORY: " + cat_name + " (" + cat_id + ")";
    if (page_num) {
        if ((page_num != "") && (page_num != "1")) {
            cm.pi = cm.pi + " PG " + page_num;
        }
    }
    cm.cg = cat_id;
    if (registry_flag) {
        cm.pv4 = "Registry";
    }
    cm.rf=ParseRef(document.URL);

    if (cmGomezKeynoteFlag == "0")
    {
		cmCheckEmParameter();
        cm.writeImg();
    }
}

var cmCategoryId = null;

function cmCreateProductTag(cat_id, prod_name, prod_id, count_page, registry_flag, bannercookiename,totalReviewCount,avgRating,ratingsOnlyRV,buyAgainPerc) {
    var cm = new _cm("tid", "5", "vn2", "e3.1");
    var old_cat_id = cat_id;
    var url_cat_id = getCategoryOverride(bannercookiename);
    if (url_cat_id != null)
    {
    	if (url_cat_id.charAt(1) == ":") 
    	{
        	cat_id = url_cat_id;
        } else {
        	cat_id = getViewsetFromCategory(old_cat_id) + ":" + url_cat_id;
        }
    }
    
    if (cmCategoryId == null)
    {
		cmCheckEmParameter()
        cmCategoryId = cat_id;
    }
    
    if (totalReviewCount || avgRating){
		cm.li=10300;
		cm.ps1 = prod_id;
		cm.ps2 = prod_name;
		cm.ps3 = cat_id;
		if (totalReviewCount){
			cm.ps4=totalReviewCount;      
		}
		if (avgRating){
			cm.ps5=avgRating;      
		}
		if (ratingsOnlyRV){
			cm.ps6=ratingsOnlyRV;
		}
		if (buyAgainPerc){
			cm.ps7=buyAgainPerc;
		}
	}

    cm.ul = resetVCPIVariables(document.URL);
    cm.pi = "PRODUCT: " + prod_name + " (" + prod_id + ")";
    cm.pr = prod_id;
    cm.pm = prod_name.toUpperCase();
    cm.cg = cat_id.toUpperCase();
    cm_pc = "Y";
    if (registry_flag) {
        cm.pv4 = "Registry";
    }
 
    if (count_page)
    {
        cm.pc = "Y";
    } else {
        cm.pc = "N";
    }
    cm.rf=ParseRef(document.URL);
    cm.ul=cmConvertMMC(cm.ul);
    if (cmGomezKeynoteFlag == "0")
    {
        cm.writeImg();
    }
}

//Throw this tag when user views reviews
function cmCreateBazaarViewTag(productID, productName,categoryID) {
    var cm = new _cm("tid", "7", "vn2", "e4.0");
    cm.li=10301;
    cm.ps1 = productID;
    cm.ps2 = productName;
	cm.ps3 = categoryID;
    cm.writeImg();
}

function cmGetProductIndex(id){
    var i =0;
    for (i=0; i<cmShopCounter; i++)
    {
        if (id==cmShopProducts[i])
        {
            return i;
        }
    }
    return -1;
}

var cmShopProducts = new Array();
var cmShopProductNames = new Array();
var cmShopIds = new Array();
var cmShopQtys = new Array();
var cmShopPrices = new Array();
var cmShopCategory = new Array();
var cmShopSKUs = new Array();
var cmShopCounter = 0;
var cmShopOrderIds = new Array();
var cmShopCustomerIds = new Array();
var cmShopOrderPrices = new Array();
var cmShopShipOthers = new Array();
var cmShopGiftWrap = new Array();
var cmShopSKUName = new Array();
var cmShopRegNumber = new Array();
var cmShopCompletionFlag = new Array();

function cmCreateShopAction5Tag(prod_id, prod_qty, prod_price, 
                sku, category, prod_name, ship_other_count, gift_wrap_count) {
    var index = cmGetProductIndex(prod_id);
    if(index!=-1){
        cmShopPrices[index] = (cmShopPrices[index]*cmShopQtys[index] + parseInt(prod_qty)*parseFloat(prod_price))/(cmShopQtys[index]+parseInt(prod_qty));
        cmShopQtys[index] += parseInt(prod_qty);
        cmShopSKUs[index] += "|" + sku + "|" + prod_price + "|" + prod_qty + "|";
        cmShopShipOthers[index] = parseInt(ship_other_count) + parseInt(cmShopShipOthers[index]);
        cmShopGiftWrap[index] = parseInt(gift_wrap_count) + parseInt(cmShopGiftWrap[index]);
    } else {
        cmShopProducts[cmShopCounter] = prod_id;
        cmShopIds[cmShopCounter] = prod_id;
        cmShopQtys[cmShopCounter] = parseInt(prod_qty);
        cmShopPrices[cmShopCounter] = parseFloat(prod_price);
        cmShopShipOthers[cmShopCounter] = ship_other_count;
        cmShopGiftWrap[cmShopCounter] = gift_wrap_count;
        if (category)
        {
            cmShopCategory[cmShopCounter] = category;
        } else {
            cmShopCategory[cmShopCounter] = "";
        }
        
        // for gift certificates 
        if (prod_name) 
        {
            cmShopProductNames[cmShopCounter] = prod_name;
        } else {
            cmShopProductNames[cmShopCounter] = "";
        }
        cmShopSKUs[cmShopCounter] = "|" + sku + "|" + prod_price + "|" + prod_qty + "|";
        cmShopCounter++;
    }        
}

function cmDisplayShop5s(){
    var i;
    for(i=0; i<cmShopCounter;i++){
        var cm = new _cm("tid", "4", "vn2", "e3.1");
        cm.at = "5";
        cm.pr = cmShopIds[i]; 
        cm.qt = cmShopQtys[i] ;
        cm.cg = cmShopCategory[i];
        cm.pm = cmShopProductNames[i];
        cm.bp = cmShopPrices[i];
        cm.sx4 = cmShopShipOthers[i];
        cm.sx5 = cmShopGiftWrap[i];
        cm.sx6 = cmShopSKUName[i];
        var maxlength = 100;
        var length = cmShopSKUs[i].length;
        if (length<=maxlength)
        {
            cm.sx11 = cmShopSKUs[i];
        } else {
            cm.sx11 = cmShopSKUs[i].substring(0,maxlength);
            if (length<=2*maxlength)
            {
                cm.sx12 = cmShopSKUs[i].substring(maxlength,length);
            } else {
                cm.sx12 = cmShopSKUs[i].substring(maxlength,2*maxlength);
                if (length<=3*maxlength)
                {
                    cm.sx13 = cmShopSKUs[i].substring(2*maxlength,length);
                } else {
                    cm.sx13 = cmShopSKUs[i].substring(2*maxlength,3*maxlength);
                    if (length<=4*maxlength)
                    {
                        cm.sx14 = cmShopSKUs[i].substring(3*maxlength,length);
                    } else {
                        cm.sx14 = cmShopSKUs[i].substring(3*maxlength,4*maxlength);
                        cm.sx15 = cmShopSKUs[i].substring(4*maxlength,length);
                    }                        
                }    
            }
        }
        cm.pc = "N";
        
        if (cmGomezKeynoteFlag == "0")
        {
	        cm.ul=document.URL;
            cm.writeImg();
        }
    }
    cmShopCounter=0;
}

function cmCreateShopAction9Tag(prod_id, prod_qty, prod_price, sku, order_id, cust_id, order_price, ship_other_count, gift_wrap_count, category, prod_name, reg_number, completion_flag) {
    var index = cmGetProductIndex(prod_id + "_" + order_id);
    if(index!=-1){
        cmShopPrices[index] = (cmShopPrices[index]*cmShopQtys[index] + parseInt(prod_qty)*parseFloat(prod_price))/(cmShopQtys[index]+parseInt(prod_qty));
        cmShopQtys[index] += parseInt(prod_qty);
        cmShopSKUs[index] += "|" + sku + "|" + prod_price + "|" + prod_qty + "|";
        cmShopShipOthers[index] = parseInt(ship_other_count) + parseInt(cmShopShipOthers[index]);
        cmShopGiftWrap[index] = parseInt(gift_wrap_count) + parseInt(cmShopGiftWrap[index]);
    } else {
        cmShopProducts[cmShopCounter] = prod_id + "_" + order_id;
        cmShopIds[cmShopCounter] = prod_id;
        cmShopQtys[cmShopCounter] = parseInt(prod_qty);
        cmShopPrices[cmShopCounter] = parseFloat(prod_price);
        if (category)
        {
            cmShopCategory[cmShopCounter] = category;
        } else {
            cmShopCategory[cmShopCounter] = "";
        }
        // for gift certificates
        if (prod_name) 
        {
            cmShopProductNames[cmShopCounter] = prod_name;
        } else {
            cmShopProductNames[cmShopCounter] = "";
        }
        cmShopSKUs[cmShopCounter] = "|" + sku + "|" + prod_price + "|" + prod_qty + "|";
        cmShopOrderIds[cmShopCounter] = order_id;
        cmShopCustomerIds[cmShopCounter] = custIDcheck(cust_id);
        cmShopOrderPrices[cmShopCounter] = order_price;
        cmShopShipOthers[cmShopCounter] = ship_other_count;
        cmShopGiftWrap[cmShopCounter] = gift_wrap_count;
        cmShopRegNumber[cmShopCounter] = reg_number;
        cmShopCompletionFlag[cmShopCounter] = completion_flag;
        cmShopCounter++;
    }    
}

function cmDisplayShop9s(){
    var i;
    for(i=0; i<cmShopCounter;i++){
        var cm = new _cm("tid", "4", "vn2", "e3.1");
        cm.at = "9";
        cm.pr = cmShopIds[i];
        cm.qt = cmShopQtys[i];
        cm.bp = cmShopPrices[i];
        cm.cg = cmShopCategory[i];
        cm.pm = cmShopProductNames[i];
        cm.sx4 = cmShopShipOthers[i];
        cm.sx5 = cmShopGiftWrap[i];
        cm.sx6 = cmShopSKUName[i];
        cm.sx7 = cmShopRegNumber[i];
        cm.sx8 = cmShopCompletionFlag[i];
        cm.cd = cmShopCustomerIds[i];
        cm.on = cmShopOrderIds[i];
        cm.tr = cmShopOrderPrices[i];

        var maxlength = 100;
        var length = cmShopSKUs[i].length;
        if (length<=maxlength)
        {
            cm.sx11 = cmShopSKUs[i];
        } else {
            cm.sx11 = cmShopSKUs[i].substring(0,maxlength);
            if (length<=2*maxlength)
            {
                cm.sx12 = cmShopSKUs[i].substring(maxlength,length);
            } else {
                cm.sx12 = cmShopSKUs[i].substring(maxlength,2*maxlength);
                if (length<=3*maxlength)
                {
                    cm.sx13 = cmShopSKUs[i].substring(2*maxlength,length);
                } else {
                    cm.sx13 = cmShopSKUs[i].substring(2*maxlength,3*maxlength);
                    if (length<=4*maxlength)
                    {
                        cm.sx14 = cmShopSKUs[i].substring(3*maxlength,length);
                    } else {
                        cm.sx14 = cmShopSKUs[i].substring(3*maxlength,4*maxlength);
                        cm.sx15 = cmShopSKUs[i].substring(4*maxlength,length);
                    }                        
                }    
            }
        }
        cm.pc = "N";
        if (cmGomezKeynoteFlag == "0")
        {
	        cm.ul=document.URL;
            cm.writeImg();
        }

    }
    cmShopCounter=0;
}

function cmCreateOrderTag(order_id, cust_id, subtotal, shipping_charge, sku_data, 
city, state, zip, logged_in_flag, registry_flag) {
    var cm = new _cm("tid", "3", "vn2", "e3.1");
    cm.cd = custIDcheck(cust_id);
    cm.on = order_id;
    cm.tr = subtotal;
    cm.osk = sku_data;
    cm.sg = shipping_charge;
    cm.sa = state;
    cm.ct = city;
    cm.zp = zip;
    cm.or1 = "N"; // default
    if (logged_in_flag) { 
        cm.or1 = "Y";    
    }
    if (registry_flag) {
        cm.or2 = "Registry";
    }
    cm.pc = "N";

    if (cmGomezKeynoteFlag == "0")
    {
	    cm.ul=document.URL;
        cm.writeImg();
    }
}

function cmCreateRegistrationTag(page_id, cust_id, email, newsletter_name, subscribed, 
city, state, zip, registry_flag, category, age, relation, shopping_for, cats_requested) {
    var cm = new _cm("tid", "2", "vn2", "e3.1");
    cm.ul = resetVCPIVariables(document.URL);
    cm.cd = custIDcheck(cust_id);
    cm.em = email;
    if (page_id) {
        cm.pi = page_id;
    } 
    else {
        cm.pi = getFileNameFromURL();
    }
    if (subscribed) {
        cm.sd = "Y";
        cm.nl = newsletter_name;
    } else {
        cm.sd = "N";
        cm.nl = newsletter_name;
    }
    if (city) { 
        cm.ct = city; 
        cm.sa = state;
    }
    if (zip) {
        cm.zp = zip;
    }
    if (registry_flag) {
        cm.rg11 = "Y";
    }
    if (category) {
        cm.cg = category;
    }
    /** PT age
    actual age if the customer enters their age
    if they are logged in, it defaults to 0 
    if they are under 13, age = 12 **/
    if (age) {
        cm.ag = age;
    }
    // PT relationship to customer
    if (relation) {
        cm.rg12 = relation;
    }
    // PT shopping for (young adult, boy, girl, etc.)
    if (shopping_for) {
        cm.rg13 = shopping_for;
    }
    // PT catalogs requested (brands selected, separated by pipe PT|PB|PK)
       if (cats_requested) {
        cm.pv3 = cats_requested;
    }
    cm.ul=cmConvertMMC(cm.ul);
    cm.pc = "Y";
    if (cmGomezKeynoteFlag == "0")
    {
        cm.writeImg();
    }
}

function cmCreateErrorTag(error_type) {
    var cm=new _cm("tid", "404", "vn2", "e3.1");
    cm.li = 100;
    cm.ps1 = document.URL;
    cm.ps3 = error_type;
    cm.rf=ParseRef(document.URL);
    cm.ps2=ParseRef(document.URL);

    if (cmGomezKeynoteFlag == "0")
    {
		cmCheckEmParameter();
	    cm.ul=document.URL;
        cm.writeImg();
    }
}

function cmCreateCustomTag(line_number, ps1, ps2, ps3, ps4, ps5, ps6, ps7, ps8, ps9, ps10, ps11, ps12, ps13, ps14, ps15) {
    var cm=new _cm("tid", "7", "vn2", "e3.1");
    cm.ul = resetVCPIVariables(document.URL);
    cm.li = line_number;
    // for aggregate pip report, extract values from url
    if (cm.li == 2) { 
        //handle escaped underscores
        var pattern = /cm%5Flid/ig;
        var new_url = document.location.href;
        new_url = new_url.replace(pattern, "cm_lid");
        
        //handle escaped "="
        pattern = /cm_lid%3D/ig;
        new_url = new_url.replace(pattern, "cm_lid=");
    
        pattern = /pgid%3D/ig;
        new_url = new_url.replace(pattern, "pgid=");
    
        // indeces
        var iGid = new_url.indexOf("pgid");
        var iLid = new_url.indexOf("cm_lid");

        if (iLid > 0) {
            // values
            ps3 = cmExtractParameter("pgid",new_url);
            ps4 = cmExtractParameter("cm_lid",new_url);
        }
    }
    if (ps1) { cm.ps1 = ps1; }
    if (ps2) { cm.ps2 = ps2; }
    if (ps3) { cm.ps3 = ps3; }
    if (ps4) { cm.ps4 = ps4; }
    if (ps5) { cm.ps5 = ps5; }
    if (ps6) { cm.ps6 = ps6; }
    if (ps7) { cm.ps7 = ps7; }
    if (ps8) { cm.ps8 = ps8; }
    if (ps9) { cm.ps9 = ps9; }
    if (ps10) { cm.ps10 = ps10; }
    if (ps11) { cm.ps11 = ps11; }
    if (ps12) { cm.ps12 = ps12; }
    if (ps13) { cm.ps13 = ps13; }
    if (ps14) { cm.ps14 = ps14; }
    if (ps15) { cm.ps15 = ps15; }
    cm.ul=cmConvertMMC(cm.ul);
    cm.rf=ParseRef(document.URL);

    if (cmGomezKeynoteFlag == "0")
    {
        cm.writeImg();    
    }
}

if (defaultNormalize == null) { var defaultNormalize = null; }

function myNormalizeURL(url, isHref)
{
    var newURL = url;
    if (isHref)
    {
        // parse out domain from url
        if (url.indexOf("http://") == 0 || url.indexOf("https://") == 0)
        {
            newURL = newURL.substring(newURL.indexOf("://")+3);
            newURL = newURL.substring(newURL.indexOf("/"));
        }
    
        var blackList = ["cm_src=","cmsrc=","flash=","bnrid="];
        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;
    }
}
//-->