<!--
/*
 * 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.
 * DATE			NAME			MODIFICATIONS
 *	030807		MOCHOA			Adding TechProps Custom Field for searchWord
 *  013008      OIVASIV         Updated myNornalizeURL function
 *  05/15/08	1800			Added normalization logic
 *  06/20/08    LHIBBARD        Added conversion and element tags
 *  10/08/08    RNAIK           Enabled cm_TrackImpressions
 *  01/05/09	HWHITE			Disable Impressions for Site Promotions
 *  01/05/10	ETOWB		Changed data collection domain from data.coremetrics.com to blooms.1800flowers.com
 *  01/08/10	ETOWB		Added code to resend Source of Business event in case of session timeout
 */

var cm_productPageID = "";
var cm_ClientID = "90074784";
var cm_PartnerDataClientIDs ="90074784";
var cm_Production_HOST="blooms.1800flowers.com";
var cm_TrackLink = "A";
var cm_TrackImpressions = "R";
var cm_JSFEnabled = false;

var cm_JSFPCookieMigrate = true;
var cm_JSFPForceMigrateCookies = false;
var cm_JSFPMigrationDomainWhitelist = "";
var cm_JSFPMigrationOtherCookies = "cmOrigSource,cmFlags";
var cm_JSFPMigrationOtherCookiesExpireTimes = {"cmFlags":(1000 * 60 * 30)}

if (window.location.hostname.indexOf("1800flowers.com") > -1) {
	cm_JSFPMigrationDomainWhitelist = ".1800baskets.com";
	cm_JSFPCookieDomain = ".1800flowers.com";
}
else if (window.location.hostname.indexOf("1800baskets.com") > -1) {
	cm_JSFPMigrationDomainWhitelist = ".1800flowers.com";
	cm_JSFPCookieDomain = ".1800baskets.com";
}
else {
	cm_JSFPCookieDomain = window.location.hostname;
}

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";

// TAG GENERATING FUNCTIONS ---------------------------------------------------
/*
 * Calling this function points tags to the production database
 */
function cmSetProduction(){
	cm_HOST="blooms.1800flowers.com/cm?";
	if (cm_JSFPCookieMigrate && typeof(cm_JSFPCookieMigrateSessionID)!="undefined") {
		var tempClientIDList = cm_ClientID.split(";");
		var tempSessionID = new Object;
		for (var i = 0; i < tempClientIDList.length; ++i) {
			var tempValue = cmExtractParameter(cm_JSFPCookieMigrateSessionID + "_" + tempClientIDList[i], window.location.href);
			if (tempValue) {
				tempSessionID[tempClientIDList[i]] = tempValue;
			}
		}
		var tempOtherCookieList = cm_JSFPMigrationOtherCookies.split(",");
		var otherCookies = new Object;
		for (var j = 0; j < tempOtherCookieList.length; ++j ) {
			var tempValue = cmExtractParameter("cm_mc_" + tempOtherCookieList[j], window.location.href);
			if (tempValue) {
				otherCookies[tempOtherCookieList[j]] = tempValue;
			}
		}
		cmJSFPMigrateCookies(cmExtractParameter(cm_JSFPCookieMigrateVisitorID, window.location.href), tempSessionID, otherCookies);
	}
}
if (typeof cmLoad == 'function') {
	cmLoad();
}

function cmSendSource() {
	var origSource = cI("cmOrigSource");
	var sourceSent = cI("cmFlags");
	var tempDate = new Date();
	tempDate.setTime(tempDate.getTime() + (1000 * 60 * 30));
	if (origSource && !sourceSent) {
		CB("cmFlags", "Y", tempDate.toGMTString(), cm_JSFPCookieDomain);
		cmCreateConversionEventTag(origSource, "2", "SOURCE OF BUSINESS", null);
		
	}
	else if (origSource && sourceSent) {
		CB("cmFlags", "Y", tempDate.toGMTString(), cm_JSFPCookieDomain);
	}
}

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();
	
	if (categoryID == "SOURCE OF BUSINESS") {
		var origSource = cI("cmOrigSource");
		if (!origSource) {
			// set this as a session cookie
			CB("cmOrigSource", eventID, null, cm_JSFPCookieDomain);
			var tempDate = new Date();
			tempDate.setTime(tempDate.getTime() + (1000 * 60 * 30));
			CB("cmFlags", "Y", tempDate.toGMTString(), cm_JSFPCookieDomain);
		}
	}
 }

function cmCreatePageElementTag(elementID, elementCategory) {
	var cm=new _cm("tid", "15", "vn2", "e4.0");
	
	cm.eid=elementID;
	cm.ecat=elementCategory;
	cm.pflg=0;
	cm.writeImg();
}

/*
 * Creates a Tech Props tag.
 * pageID		: required. Page ID to set on this Pageview tag
 */

function cmCreateTechPropsTag(pageID, categoryID, searchWord) {
	if (pageID) {
		var cm=new _cm("tid", "6", "vn2", "e4.0");
		cm.pc="Y";
		cm.pi = pageID;
		cm.cg = categoryID;
		cm.se = searchWord;
		cm.addTP();
		var catPrefix = categoryID.split("|");
		if (cm.pi.indexOf(catPrefix[0]) != 0) {
			cm.pi = catPrefix[0] + "-" + cm.pi;
		}
		cm.ul = cmProcessEONMMCParams();
		cmCheckEmParameter();
		cm.writeImg();
        plugin_dotomi(cm);
	}
	cmSendSource();
}

/*
 * Creates a Pageview tag with the given Page ID
 *
 * pageID		: required. Page ID to set on this Pageview tag
 * searchString	: optional. Internal search string enterred by user to reach
 *				  this page.
 * categoryID	: optional. Category ID to set on this Pageview tag
 *
 * returns nothing, causes a document.write of an image request for this tag.
 */

function cmCreatePageviewTag(pageID, categoryID, searchString, num_search_results) {
	if (pageID == null) {
		pageID = getDefaultPageID();
	}
	var cm = new _cm("tid", "1", "vn2", "e4.0");
	cm.pi = pageID;
	if (searchString) {
		cm.se = searchString;
	}
	if (num_search_results) {
		cm.sr = num_search_results;
	}
	if (categoryID) {
		cm.cg = categoryID;
	}
	var catPrefix = categoryID.split("|");
	if (cm.pi.indexOf(catPrefix[0]) != 0) {
		cm.pi = catPrefix[0] + "-" + cm.pi;
	}
	cm.ul = cmProcessEONMMCParams();
	cm_productPageID =cm.pi;
	cmCheckEmParameter();
	cm.writeImg();
	plugin_dotomi(cm);
	cmSendSource();
}

/*
 * 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() {
	cmCheckEmParameter();
	cmCreatePageviewTag(getDefaultPageID(), null, null);
}

/*
 * 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) {
	var cm = new _cm("tid", "5", "vn2", "e4.0");
	if (productName == null) {
		productName = "";
	}
	cm.pr = productID;
	cm.pm = productName;
	cm.cg = categoryID;
	cm.pc = "Y";
	if (cm_productPageID) {
		cm.pi = cm_productPageID;
	}
	else {
		cm.pi = "PRODUCT: " + productName + " (" + productID + ")";
	}
	cmCheckEmParameter();
	cm.writeImg();
	plugin_dotomi(cm);
	cmSendSource();
}

/*
 * 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 cmShopSKU = "";
var cmShopCounter = 0;
var cmShopOrderIds = new Array();
var cmShopCustomerIds = new Array();
var cmShopOrderPrices = new Array();
var cmParentSKUs = new Array();
var cmFGDate = new Array();
var cmFGZIP = new Array();

/* 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(productID, productName, productQuantity, 
								productPrice, categoryID, parentSKU) {
	var index = cmGetProductIndex(productID);
	if(index!=-1){
		var oldPrice = cmShopPrices[index];
		var oldQty = cmShopQtys[index];
		var newQty = oldQty + parseInt(productQuantity);
		var newPrice = (oldPrice*oldQty + parseInt(productQuantity)*parseFloat(productPrice))/(newQty);
		cmShopPrices[index] = newPrice;
		cmShopQtys[index] = newQty;
	} else {
		if (!categoryID) {
			categoryID = "";
		}
		cmShopProducts[cmShopCounter] = productName;
		cmShopIds[cmShopCounter] = productID;
		cmShopCats[cmShopCounter] = categoryID;
		cmShopQtys[cmShopCounter] = parseInt(productQuantity);
		cmShopPrices[cmShopCounter] = parseFloat(productPrice);
		cmParentSKUs[cmShopCounter] = parentSKU;
		cmShopCounter++;
	}
}

/* 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.sx1 = cmParentSKUs[i];
		cm.pc = "N";
		cm.writeImg();
	}
	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(productID, productName, productQuantity,
				productPrice, customerID, orderID,
				orderTotal, categoryID, parentSKU, fastGiftDate, fastGiftZIP) {
	var index = cmGetProductIndex(productID);
	if(index!=-1){
		var oldPrice = cmShopPrices[index];
		var oldQty = cmShopQtys[index];
		var newQty = oldQty + parseInt(productQuantity);
		var newPrice = (oldPrice*oldQty + parseInt(productQuantity)*parseFloat(productPrice))/(newQty);
		cmShopPrices[index] = newPrice;
		cmShopQtys[index] = newQty;
	} else {
		if (!categoryID) {
			categoryID = "";
		}
		cmShopProducts[cmShopCounter] = productName;
		cmShopIds[cmShopCounter] = productID;			
		cmShopOrderIds[cmShopCounter] = orderID;
		cmShopOrderPrices[cmShopCounter] = orderTotal;
		cmShopCustomerIds[cmShopCounter] = customerID;
		cmShopCats[cmShopCounter] = categoryID;
		cmShopQtys[cmShopCounter] = parseInt(productQuantity);
		cmShopPrices[cmShopCounter] = parseFloat(productPrice);
		cmParentSKUs[cmShopCounter] = parentSKU;
		cmFGDate[cmShopCounter] = fastGiftDate;
		cmFGZIP[cmShopCounter] = fastGiftZIP;
		cmShopCounter++;
	}
}

/* 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.sx1 = cmParentSKUs[i];
		cm.sx2 = cmFGDate[i];
		cm.sx3 = cmFGZIP[i];
		cmShopSKU += "|" + cm.pr + "|" + cm.bp + "|" + cm.qt + "|";
		cm.pc = "N";
		cm.writeImg();
	}
	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(orderID, orderTotal, orderShipping, customerID, 
			  customerCity, customerState, customerZIP, checkoutType,
			  registerFlag, loginFlag, paymentType, errorType) {
	
		var cm = new _cm("tid", "3", "vn2", "e4.0");
		cm.on = orderID;
		cm.tr = orderTotal;
		cm.osk = cmShopSKU;
		cm.sg = orderShipping;
		cm.cd = customerID;
		cm.sa = customerState;
		cm.ct = customerCity;
		cm.zp = customerZIP;
		cm.or1 = checkoutType;
		cm.or2 = registerFlag;
		cm.or3 = loginFlag;
		cm.or4 = paymentType;
		cm.or5 = errorType;
		cm.writeImg();
		plugin_dotomi(cm);

}

/*
 * 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(customerID, customerEmail, customerCity,
				customerState, customerZIP, newsletterName, 
				subscribe, loginRegisterFlag) {
	var cm = new _cm("tid", "2", "vn2", "e4.0");
	cm.cd = customerID;
	cm.em = customerEmail;
	cm.sa = customerState;
	cm.ct = customerCity;
	cm.zp = customerZIP;
	if (newsletterName && subscribe) {
		cm.nl = newsletterName;
		cm.sd = subscribe;
	}
	cm.rg11 = loginRegisterFlag;
	cm.li = 100;
	cm.ps1 = customerID;
	cm.ps2 = loginRegisterFlag;
	
	cm.writeImg();
}

/*
 * Creates a newsletter tag
 */

function cmCreateNewsletterTag(customerEmail, newsletterName, subscribe) {
	var cm = new _cm("tid", "2", "vn2", "e4.0");
	cm.em = customerEmail;
	cm.nl = newsletterName;
	cm.sd = subscribe;
	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
	cm.pi = pageID;
	cm.cg = categoryID;
	cm.pc = "Y";
	cmCheckEmParameter();
	cm.writeImg();
}

function cmCreateEndecaFilterTag(collection, filterType, filterSelection) {
	var cm = new _cm("tid", "7", "vn2", "e4.0");
	cm.li = "1010";
	cm.ps1 = collection;
	cm.ps2 = filterType;
	cm.ps3 = filterSelection;
	cm.writeImg();
}

function cmCreateFastGiftTag(occasion, giftDate, giftZIP) {
	var cm = new _cm("tid", "7", "vn2", "e4.0");
	cm.li = "1020";
	cm.ps1 = occasion;
	cm.ps2 = giftDate;
	cm.ps3 = giftZIP;
	cm.writeImg();
}

// HELPER FUNCTIONS -----------------------------------------------------------
/* These functions are used by the tag-generating functions and/or may be used
 * in in general as convenience functions
 */

/*
 * 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 getDefaultPageID() { 
	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); 
}

/*
 * Creates a custom Endeca Tag
 * dimension                  : Optional. Endeca Dimension Name
 * addRemove                : Optional. Whether the Dimension was Added, Removed or No Action was taken
.
 *                                                  Either an 'A', 'R' or 'N'
 * numItems                   : Optional. Number of items displayed on the page
 * sortPrefs                    : Optional. The user's sorting preference
 * catValue                    : Optional. The value of the category if dimension is category
 */

function cmEndecaSearch(dimension,addRemove,numItems,sortPrefs,catValue){
            var cm = new _cm("tid", "7", "vn2", "e4.0");
            cm.li  = 1;
            cm.ps1 = dimension;
            cm.ps2 = addRemove;
            cm.ps3 = numItems;
            cm.ps4 = sortPrefs;
            cm.ps5 = catValue;
            cm.ps15 = cmTimeStamp;
            cm.writeImg();
}

if (defaultNormalize == null) { var defaultNormalize = null; }

function myNormalizeURL(url, isHref){
     
    var newURL = url;
    if (isHref) {
	    var paramIndex1 = newURL.toLowerCase().indexOf("1800flowers.com/");
	    if (paramIndex1 > -1) {
	    	if(newURL.toLowerCase().indexOf("ww")+4==newURL.toLowerCase().indexOf("1800flowers.com/") || newURL.toLowerCase().indexOf("://")+3==newURL.toLowerCase().indexOf("1800flowers.com/") ||newURL.toLowerCase().indexOf("ww")+5==newURL.toLowerCase().indexOf("1800flowers.com/")){
	    		if(newURL.length > (paramIndex1 + 16))
	    		{
			        var u = newURL.substring(paramIndex1 + 15);
			        newURL = u;
		        }
	        }
	    }

	    var blackList = ["placeblacklistparamhere"];
	    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;
    }
}
function cmCheckEmParameter() {
	if (cmIndexOfParameter("cm_em") != -1){
		var s = document.location.href;
		var begin = s.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];
		}
		cmCreateRegistrationTag(emailAddress,emailAddress);
	}
}

// helper functions

/*
 * 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 cmIndexOfParameter (parameter) {
	return document.location.href.indexOf(parameter);
}

/*

 * Extracts the value of a name-value pair in the request search string.

 */

function cmExtractParameter (parameter) {
    if (cmIndexOfParameter(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);
}

/*
 * Looks for source and keyword parameters from EON Media links
 */

function cmProcessEONMMCParams() {
	var newURL = window.location.href;
	var source = cmExtractParameter("source");
	var keyword = cmExtractParameter("keyword");
	if ((source != "") && (keyword != "")) {
		newURL += "&cm_ven=" + source + "&cm_ite=" + keyword;
	}
	return newURL;
}



//start dmtag.js
//
// dtmtag.js
// Dotomi ReConnect Integration Script
// (c) 2007 Dotomi, Inc.
// ver 1.10
//

//
// Call the plugin_dotomi(cm) function, passing the value of the cm variable at the end of your tag writing functions.
// See SamplePage.html for function calls Dotomi has tested. See these functions above to see where we integrated the plugin call. 
//


function _DTMTAG(cid,cmgk,fid,com) {
    var me=arguments.callee;

    var dtjs = document.getElementById("dtmjs");
    	
    me.dtm_cid=cid;
    me.dtm_cmagic=cmgk;
    me.dtm_fid=fid || 101;
    me.dtm_com=com || 28;

    var doc=document,id="dtmdiv",style="display:none",typ="text/javascript";
	var rulesUrl,prot=window.location.protocol;
	rulesUrl = prot + "//a248." + (prot == "http:" ? "g" : "e") + ".akamai.net/7/248/14564/20070731/dotomi.download.akamai.com/14564/rules/" + cid + "/rules.js";

	// load the activation rules
	var dv=crEl(doc,"div");
	if(dv){
		dv.setAttribute("id", id);
		dv.style.cssText = style;

		var ifrm=crEl(doc,'script');
		ifrm.setAttribute("type", typ );
		ifrm.setAttribute("src", rulesUrl );
		dv.appendChild(ifrm);

		if(!dtjs)
			dtjs=doc.getElementsByTagName("body")[0].firstChild;
			
		if(dtjs)
			dtjs.parentNode.insertBefore(dv,dtjs);
	} else {
		doc.write('<div id="' + id + '" style="' + style + '"><scr'+'ipt type="' + typ + '" src="' + rulesUrl + '"></scr'+'ipt></div>');
	}	
    return me;
}

_DTMTAG.qryParse=function(q) {
    q = q || window.location.search;
    
    var r={};
    if(q && q!= "") {
    q = q.substr(1);
    var splt = q.split("&");
    for(var i=0;i<splt.length;i++){
        splt[i] = (splt[i]).split("=");
        r[(splt[i][0]).toLowerCase()] = splt[i][1];
    }
    }
    return r;
}

function crEl(doc,el) {
	// create a DOM element
	if (typeof doc.createElementNS != 'undefined') return doc.createElementNS('http://www.w3.org/1999/xhtml',el);
	if (typeof doc.createElement != 'undefined') return doc.createElement(el);
	return false;
}

_DTMTAG.write=function(rules) {
	if (!rules)
		return;

	// process the rules
	var r=rules.vars,
	    promo=null;

	function isempty(v) { return (v==undefined || v==null || v=="");}
	
	var qry = _DTMTAG.qryParse();

	for( var i=0,l=r.length; i<l; i++) {
		var rule=r[i],ok=true;
		var vname = rule[0];

		if( vname.indexOf("?") == 0) {
		    vname = vname.substr(1);
		    val = qry[vname];
		} else {
		    vname=vname.split(".");
            
            for(var j=0,val=window; j<vname.length; j++) {
                val=val[vname[j]];
            }
		}
		if (isempty(val))
			continue;

		if( rule[2] ) {
			// use RegExp to extract value from var
			var extractRe = new RegExp( rule[2] );
			val = extractRe.exec( val );
			if (isempty(val))
				continue;
			for(j=1; j<val.length; j++) {
			    if( !isempty(val[j]) ) {
        			val = val[j];
        			break;
			    }
			}	
		}

		// test if the value is in an acceptabl;e range
		var testRe;
		// test for inclusion
		if( rule[3] && rule[3][0] && rule[3][0]!="") {
			testRe = new RegExp( rule[3][0] ); 
			ok = testRe.test( val );
		}
		// test for exclusion
		if(rule[4] && rule[4]!="") {
		    testRe = new RegExp( rule[4] ); 
		    if(testRe.test( val )) {
				promo=null;
				break;
			}
		}
		
		if(ok) {
			// if name is mapped, keep the value
			if( rule[1] )
				this[rule[1]] = val;
			
			// does this variable determine promo_id?
			var pmap = rules.promo[rule[1] || rule[0]];
			if( pmap ) {
			    var tmp = val.split(" ").join("");
			    promo= pmap[tmp];
			}
		} else {
			// if this must match, but does not, fail
			if(rule[3] && rule[3][1]) {
				promo=null;
				break;
			}	
		}
	}
	
	// check url overrides
	var r=rules.uris.include,purl=document.location.href;
	for( i=0,l=r.length; i<l; i++) {
		rule=r[i];
		if( purl.indexOf( rule[0] ) != -1 ) {
			promo = rule[1];
			break;
		}
	}
	r=rules.uris.exclude;
	for( i=0,l=r.length; i<l; i++) {
		rule=r[i];
		if( purl.indexOf( rule[0] ) != -1 ) {
			promo = null;
			break;
		}
	}
		
	if(promo!=null) {
		// particular URIs can override the promo_id
		
		// write the tag
		this['cli_promo_id']=promo;
		if(document.referrer)
			this['ref'] = document.referrer;
		
	    var tmOut = arguments.callee["timeOutMillisecs"] || 4000;
	    var doc=document,baseUrl=window.location.protocol;
	    baseUrl += "//login.dotomi.com/ucm/UCMController?dtm_format=5";

	    if( this["dtmc_transaction_id"] ) {
	        this.dtm_com=29;
	        if( this["dtm_fid"]==101 )
				this.dtm_fid=102;
	        this.cli_promo_id=100;
	    }

	    // build URL using cusrom field values
	    for(var attr in this){
	        var to,itm=this[attr];
	        to=typeof itm;
	        if(to!="function" && to!="object")
	            baseUrl += "&" + attr + "=" + escape(itm);
	    }

	    // write the tag markup or DOM
		setTimeout('timeOutDotomi()',tmOut);
		var dv=doc.getElementById("dtmdiv");
		if(dv){
			var ifrm=crEl(doc,"iframe");
			ifrm.setAttribute("src", baseUrl);
			dv.appendChild(ifrm);
		} else {
			doc.write('<div id="dtmdiv" style="display:none"><iframe src="'+baseUrl+'"></iframe></div>');
		}
	}
};
_DTMTAG.write.timeOutMillisecs=4000;

function timeOutDotomi(){ try{document.getElementById("dtmdiv").innerHTML = "";}catch(ex){}}

function plugin_dotomi(cm) {
   dt_cm=cm;

   try {
      _DTMTAG(2014,"cee8d6");
   } catch(e) {
   }
}

var dt_cm=null;

// END dtmtag.js



//-->

