/*
 * cmdatatagutils.js 
 * $Id: cmcustom-10041546-90043274-021711.txt 165480 2011-02-17 19:31:35Z whbird $
 * $Revision: 165480 $
 *
 * Version 4.1.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.
 *
 *Date			Name			Description
 *4/24/06		Hutch White		Add cm_lm code
 *11/14/07		Hutch White		Add Motion Point Language Prepend to pageID, catID and Search Term
 *03/16/2009		CRoberts		Added Manual link click and impression tags and maketag to support them.
 *						Also added element and conversion event.
 *07/08/2009		KNaquin			Switched Productview to support attributes for BV tracking
 *08/10/2009		JBowser			Moved vars from eluminate to cmdatatagutils.
 *						Converted to maketag.
 *11/12/09		RNaik			Updated library to match the recent version of cmdatatagutils.js and added multi client code.
 *11/13/09              RNaik			Set "pc" = "N" in productView tag as per support ticket request on # 10005371
 *12/28/09		RNaik			Included code for Ad Target activation. Updated to eluminate version 4.2.11-AT.
 *03/19/10		AAB			updated code block at top of cmdatatagutils, updated eluminate to 4.2.15-AT
 *11/09/10		YHUNT			Turned off track impressions per ticket 10043971 
 *02/17/10		WHBIRD			Converted to cmcustom for hosted update 
 */
 
var cm_Language="";
var cm_exAttr=new Array();  
var cm_TrackLink = "A";
var cm_TrackImpressions = "";
var cm_tempHost;

var cmCheckCMEMFlag = true;

function cmCheckCMLM() {
	if (cmIndexOfParameter("cm_lm", document.URL) != -1){

		var s = document.URL;
		var begin = s.indexOf("cm_lm");
		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);
	}
}

function cmCreatePageviewTag(pageID, searchString, categoryID, numberOfSearchResults, attributes) {
	if (pageID == null) { pageID = cmGetDefaultPageID(); }
	if (searchString) {
		searchString = cm_Language+searchString;
	}
	if (categoryID) {
		var categoryID = cm_Language+categoryID;
	}

	if (attributes){
		var cm_exAttr=new Array;
		cm_exAttr=attributes.split("-_-");
	}	
    cmCheckCMLM();	
	cmMakeTag(["tid","1","pi",cm_Language+pageID,"cg",categoryID,"se",searchString,"sr",numberOfSearchResults,"cm_exAttr",cm_exAttr]);
}

function cmCreateShopAction5Tag(productID,productName,productQuantity,productPrice,categoryID, multiCurrency, attributes) {
	var pattern = /[^\-0-9\.]/gi;
    productPrice = productPrice.toString().replace(pattern, "");
	var cm_slotNum;
	if (attributes){
		__ex=attributes.split("-_-");
	} else {
	__ex=new Array();
	}	

	cmAddShop(["pr",productID,"pm",productName,"qt",productQuantity,"bp",productPrice,"cg",categoryID,"cc",multiCurrency,"ha1",attributes ? cm_hex_sha1(attributes) : null,"at","5","tid","4","pc","N"]);
}

function cmCreateShopAction9Tag(productID,productName,productQuantity,productPrice,customerID,orderID,orderTotal,categoryID,multiCurrency,attributes) {
	var cm_slotNum;
	var pattern = /[^\-0-9\.]/gi;
	var pattern1 = /^\s+|\s+$/gi;
    productPrice = productPrice.toString().replace(pattern, "");
	orderTotal = orderTotal.toString().replace(pattern, "");
	productID = productID.toString().replace(pattern1, "");
	if (attributes){
		__ex=attributes.split("-_-");
	} else {
	__ex=new Array();
	}
	
	cmAddShop(["pr",productID,"pm",productName,"qt",productQuantity,"bp",productPrice,"cg",categoryID,"cc",multiCurrency,"ha1",attributes ? cm_hex_sha1(attributes) : null,"cd",customerID,"on",orderID,"tr",orderTotal,"at","9","tid","4","pc","N"]);
	cmCalcSKUString();
}

function cmCreateOrderTag(orderID,orderTotal,orderShipping,customerID,customerCity,customerState,customerZIP,multiCurrency,attributes) {
	var pattern = /[^\-0-9\.]/gi;
    orderShipping = orderShipping.toString().replace(pattern, "");
	orderTotal = orderTotal.toString().replace(pattern, "");
	if (attributes){
		var cm_exAttr=new Array;
		cm_exAttr=attributes.split("-_-");
	}	
	cmMakeTag(["tid","3","osk",__skuString,"on",orderID,"tr",orderTotal,"sg",orderShipping,"cd",customerID,"ct",customerCity,"sa",customerState,"zp",customerZIP,"cc",multiCurrency,"cm_exAttr",cm_exAttr]);
	__skuString = "";
}

/*
 * 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"
 *
 */
function cmCreateRegistrationTag(customerID, customerEmail, customerCity,
				customerState, customerZIP, newsletterName, 
				subscribe, attributes) {
 	if (attributes){
		var cm_exAttr=new Array;
		cm_exAttr=attributes.split("-_-");
	}
	cmMakeTag(["tid","2","cd",customerID,"em",customerEmail,"ct",customerCity,"sa",customerState,"zp",customerZIP,"nl",newsletterName,"sd",subscribe,"cm_exAttr",cm_exAttr]);
}
