/**
 * Bath and Bodywork Tracking 
 * Revision: 04/24/2008 9:46AM
 */

var subClientID = "90026971";
var productParam = "productId|rolloverKey";

// helpers
function getTagParam(paramName, url) {
    var urlParts = url.split('?', 2);
    var paramNameList = paramName.split('|');
    var query;
    if (urlParts.length < 2) {
        query = url;
    } else {
        query = urlParts[1];
    }
    
    for (n = 0; n < paramNameList.length; ++n) {
        var keyIdx = url.indexOf("&" + paramNameList[n] + "=");
        if (-1 == keyIdx) {
            keyIdx = url.indexOf("?" + paramNameList[n] + "=");
        }
        if (-1 == keyIdx) {
            continue;
        }
        var valueStartIdx = key + 2 + paramNameList[n].length;
        var valueEndIdx = url.indexOf("&", valueStartIdx);
        if (valueEndIdx < 1) {
            valueEndIdx = url.length;
        }
        return url.substring(valueStartIdx, valueEndIdx);
    }
    
    var params = query.split('&');
    for (idx = 0; idx < params.length; ++idx) {
        var keyValue = params[idx].split('=');
        for (jdx = 0; jdx < paramNameList.length; ++jdx) {
            if (keyValue[0] == paramNameList[jdx]) {
              // parameter found
              return keyValue[1];
            }
        }
    }
    // not found
    return "";
}

function localDecode(encodedString) {
    return decodeURIComponent(decodeURI(encodedString));
}

var currentPageId = "";
var currentSearchTerm = null;
function s7Tag(eventInfo)
{
    var eventParams = eventInfo.split(",", 3);
    if (eventParams.length < 1) {
        return;  // should not happen
    }
    var eventType = eventParams[0].toString();
    var eventData = "";
    if (eventParams.length > 1) {
        eventData = localDecode(eventParams[1].toString());
    }

    if (eventType == "PAGE") {
        currentPageId = catalogName;
        if (eventParams.length > 2) {
            currentPageId += "_"+"PAGE"+localDecode(eventParams[1].toString());
        } else {
            currentPageId += "_"+"PAGE"+eventData;
        }
        cmCreatePageviewTag(currentPageId, currentSearchTerm, currentPageId, subClientID);
        currentSearchTerm = null;
    } else if (eventType == "ZOOM") {
        cmCreatePageviewTag(currentPageId + "_ZOOM " + eventData, null, currentPageId + "_ZOOM ", subClientID);
    } else if (eventType == "PAN") {
        cmCreatePageviewTag(currentPageId + "_PAN ", null, currentPageId + "_PAN ", subClientID);
    } else if (eventType == "ITEM") {
        // ROLLOVER EVENT
        var p = getTagParam(productParam, eventData);
        if (p != "") {
            createProductviewTag(p, p, currentPageId + "_PRODUCTS_ROLLOVER", subClientID);
        }
    } else if (eventType == "HREF") {
        // CLICK EVENT
        var p = getTagParam(productParam, eventData);
        if (p != "") {
            createProductviewTag(p, p,currentPageId + "_PRODUCTS_CLICK", subClientID);
        }
    } else if (eventType == "SEARCH") {
        currentSearchTerm = eventData;
    } 
	else if (eventType == "NAV"){
		cmCreatePageviewTag(catalogName+"_"+eventData, null, catalogName+"_"+eventData, subClientID);        
	}
}// end s7Tag;

function createProductviewTag(productID, pageID, categoryID, clientId) 
{
    var cm = new _cm("tid", "5", "vn2", "e4.0");

    // 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.cg = categoryID;
    cm.pc = "N";
    cm.pi = pageID;
    cm.ci = clientId;
    cm.writeImg();	
}

//
// UNCOMMENT the following line when the site goes live - this causes data to 
// go into live databases. (cmSetProduction() is what needs to be run.)
//
cmSetProduction();
if(typeof setHost != "undefined")
	setHost();
cmCreateTechPropsTag("CATALOG INIT", "CATALOG", subClientID);

function init() {
}
 

