<!--
/*
 * cmdatatagutils.js
 * $Revision: 93781 $
 * $Id: cmdatatagutils - MASTER.txt 93781 2008-07-24 12:30:27Z abrink $
 * Coremetrics Tag v3.1, 2/28/2002
 * COPYRIGHT 1999-2002 COREMETRICS, INC. 
 * ALL RIGHTS RESERVED. U.S.PATENT PENDING
 *
 * The following functions aid in the creation of Coremetrics data tags.
 * Date			Modifier		Description
 * 112606		ETowb			Added Endeca Tags
 * 110907		MOCHOA			BlackList: ui=
 * 120307		HHall			Added manual mmc parameters
 * 121807     	OIvasiv    		Added cmCreateConversionEventTag,
 *                              cmCreatePageElementTag and cmCreateProductElementTag functions  
 * 031808		MOCHOA			Enabled manual_cm_mmc function    
 * 								Modified First Party subdomain from w44.decoratetoday.com to w44.americanblinds.com                            	 
 * 040108		HWHITE			Modified document.URL for proper case
 * 040408		HWHITE			Added cmTrackLink, cmTrackImpressions values
 * 053008		HWHITE			Standardize manual_cm_mmc to only pass parameters, not cm_mmc= string
 * 072408       ABRINK			Add logic for automated Tech Props tag
 */	

//NOTE:  Client will set cm_clientID from html page

var cm_TrackLink="A";
var cm_TrackImpressions="";

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";

/*
 * Calling this function points tags to the production database
 */
function cmSetProduction(){
	cm_HOST="w44.americanblinds.com/eluminate?"; 
}

// TAG GENERATING FUNCTIONS ---------------------------------------------------

/* 
 * Creates a Conversion Event tag.
 */
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();
 }

/* 
 * Creates a Page Element tag.
 */
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();
}

/* 
 * Creates a Product Element tag.
 */
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();
}


/*
 * Variables and functions to support capturing Endeca search data
 */
var cmEndecaSearchTerm = new Array();
var cmEndecaDimension = new Array();
var cmEndecaDimensionValue = new Array();
var cmEndecaCounter = 0;
 
function cmCreateEndecaSearch(searchTerm, dimension, dimensionValue) {
            cmEndecaSearchTerm[cmEndecaCounter] = searchTerm;
            cmEndecaDimension[cmEndecaCounter] = dimension;
            cmEndecaDimensionValue[cmEndecaCounter] = dimensionValue;
            cmEndecaCounter++;
}
 
function cmDisplayEndecaSearch() {
            var i;
 
            var datestamp = new Date();
            var stamp = (Math.floor(Math.random() * 11111111)) + datestamp.valueOf();
 
            for(i=0; i<cmEndecaCounter;i++){
                        var cm = new _cm("tid", "7", "vn2", "e4.0");
 
                        cm.li = 10100;
                        cm.ps1 = cmEndecaSearchTerm[i];
                        cm.ps2 = cmEndecaDimension[i];
                        cm.ps3 = cmEndecaDimensionValue[i];
                        cm.ps4 = stamp;
                        cm.writeImg();
            }
 
            cmEndecaCounter = 0;
}
 
function cmCreateEndecaClick(searchTerm, dimension, dimensionValue) {
            cmEndecaSearchTerm[cmEndecaCounter] = searchTerm;
            cmEndecaDimension[cmEndecaCounter] = dimension;
            cmEndecaDimensionValue[cmEndecaCounter] = dimensionValue;
            cmEndecaCounter++;
}
 
function cmDisplayEndecaClick() {
            var i;
 
            var datestamp = new Date();
            var stamp = (Math.floor(Math.random() * 11111111)) + datestamp.valueOf();
 
            for(i=0; i<cmEndecaCounter;i++){
                        var cm = new _cm("tid", "7", "vn2", "e4.0");
 
                        cm.li = 10101;
                        cm.ps1 = cmEndecaSearchTerm[i];
                        cm.ps2 = cmEndecaDimension[i];
                        cm.ps3 = cmEndecaDimensionValue[i];
                        cm.ps4 = stamp;
                        cm.writeImg();
            }
            cmEndecaCounter = 0;
}

function cmConvertMMC(url){

	newURL=unescape(url);
	
	if (this.cm_manualMMC || this.manual_cm_mmc){
		var mmcparm;
		if (this.cm_manualMMC){
			mmcparm=this.cm_manualMMC;
		}
		if (this.manual_cm_mmc){
			mmcparm="cm_mmc="+this.manual_cm_mmc;
		}
		if (mmcparm && (newURL.toLowerCase().indexOf("cm_ven")==-1) && (newURL.toLowerCase().indexOf("cm_mmc")==-1)) { 
			if (newURL.indexOf("?")>0){
				newURL=newURL+"&"+mmcparm;
			}
			else{
				newURL=newURL+"?"+mmcparm;
			}
		} 
		return newURL;
	}
	
	if (newURL.toLowerCase().indexOf("cm_ven=")>-1 || newURL.toLowerCase().indexOf("cm_mmc=")<0){
		return newURL;
	}
	var s = newURL;
	var begin = s.indexOf("cm_mmc");
	var end = s.indexOf("&", begin);

	if (end == -1) {
		end = s.length;
	}

	var middle = s.indexOf("=", begin);

	var mmcString = s.substring(middle + 1, end);
	var cmVen, cmCat, cmPla, cmIte;
	if (mmcString.indexOf("*") > 0)
	{
		var tempArray = mmcString.split("*");
	} else {
		var tempArray = mmcString.split("-_-");
	}
	cmVen = tempArray[0];
	cmCat = tempArray[1];
	cmPla = tempArray[2];
	cmIte = tempArray[3];

//remove cm_mmc from the url and add old formatted mmc parameters

	var beginMMCString = newURL.substr(0,begin);
	var endMMCString;
	if (end != newURL.length) {
		endMMCString = newURL.substr(end,newURL.length);
	} else {
		endMMCString = 0;
	}

	var finalMMCString;
	if (endMMCString != 0) {
		finalMMCString = beginMMCString + 'cm_ven=' + cmVen + '&cm_cat=' + cmCat + '&cm_pla=' + cmPla + '&cm_ite=' + cmIte + endMMCString;
	} else {
		finalMMCString = beginMMCString + 'cm_ven=' + cmVen + '&cm_cat=' + cmCat + '&cm_pla=' + cmPla + '&cm_ite=' + cmIte;
	}

	return finalMMCString;
}
/*
 *	cm.ul=cmConvertMMC(document.URL)
 *	cm.addTP();
 *	cm.writeImg();
 */
 



/*
 * Pulls the email address from the cm_lm variable in the URL.
 * This function handles the case where the email address is prefixed
 * with a string like "cm:" (i.e. anything followed by a colon).
 */
 
 if (cmIndexOfParameter("cm_lm") != -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];
        }

        cmSetProduction();
        cmCreateRegistrationTag(emailAddress,emailAddress);
}

function cmIndexOfParameter (parameter) {
        return document.URL.indexOf(parameter);
}
 



/*
 * 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 = document.URL;
		parent.cm_set_mmc = false;
	}
	if (cm.rf){
		cm.rf=cmConvertMMC(cm.rf);
	} else {
		cm.rf=cmConvertMMC(document.referrer);
	}
	cm.ul=cmConvertMMC(document.URL)
	document.cookie = "cmTPSet=Y; path=/";	
	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, adCode, searchString, searchResults, YASearchEngine, YASearchTerm) {
	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;
	}

	cm.pv1 = adCode;

	// if available, override the referrer with the frameset referrer
	if (parent.cm_ref != null) {
		cm.rf = parent.cm_ref;
		parent.cm_ref = document.URL;
	}

	var mmcTest = true;
	// 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; 	
		mmcTest = false;
	}

	if (YASearchEngine && mmcTest)
	{
		cm.ul = document.location.href + "?cm_mmc=YA-_-" + YASearchEngine + "-_-null-_-" + YASearchTerm;
	}
	cm.ul=cmConvertMMC(document.URL)
	if (cm.rf){
		cm.rf=cmConvertMMC(cm.rf);
	} else if (document.referrer){
		cm.rf=cmConvertMMC(document.referrer);
	}
	if (cI("cmTPSet") != 'Y') {
		cm.tid = "6";
		cm.pc = "Y";
		cm.addTP();
		document.cookie = "cmTPSet=Y; path=/";
	}	
	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 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 = "";
	}

	// 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.pr = productID;
	cm.pm = productName;
	cm.cg = categoryID;

	cm.pc = "Y";
	cm.pi = "PRODUCT: " + productName + " (" + productID + ")";
	cm.ul=cmConvertMMC(location.href)
	if (cm.rf){
		cm.rf=cmConvertMMC(cm.rf);
	} else {
		cm.rf=cmConvertMMC(document.referrer);
	}
	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 cmShopDiscount1   = new Array();
var cmShopDiscount2   = new Array();
var cmShopDiscount3   = new Array();
var cmShopDiscountPrice1   = new Array();
var cmShopDiscountPrice2   = new Array();
var cmShopDiscountPrice3   = new Array();
var cmShopTax		  = new Array();
var cmShopShipping	  = new Array();
var cmShopProcessing  = 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(productID, productName, productQuantity, productPrice, categoryID) {

	productID = productID.toUpperCase();

	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);
		cmShopCounter++;

	}

	cmShopSKUs = cmGetOSK();

}

/* 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(  productID
								, productName
								, productQuantity
								, productPrice
								, customerID
								, orderID
								, orderTotal
								, categoryID
								, discountField1
								, discountPrice1
								, discountField2
								, discountPrice2
								, discountField3
								, discountPrice3
								) {

	productID = productID.toUpperCase();

	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);
		cmShopQtys[index] = newQty;

		cmShopDiscount1[cmShopCounter]  = discountField1; 
		cmShopDiscount2[cmShopCounter]  = discountField2;
		cmShopDiscount3[cmShopCounter]  = discountField3;
		cmShopDiscountPrice1[cmShopCounter]   = discountPrice1;
		cmShopDiscountPrice2[cmShopCounter]   = discountPrice2;
		cmShopDiscountPrice3[cmShopCounter]   = discountPrice3;

		cmShopCounter++;
	}
	cmShopSKUs = cmGetOSK();

}


/* 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 = cmShopDiscount1[i];
		cm.sx2 = cmShopDiscountPrice1[i];
		cm.sx3 = cmShopDiscount2[i];
		cm.sx4 = cmShopDiscountPrice2[i];
		cm.sx5 = cmShopDiscount3[i];
		cm.sx6 = cmShopDiscountPrice3[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(orderID
						, orderTotal
						, orderShipping
						, customerID
						, customerCity
						, customerState
						, customerZIP
						, tax
						, processingFee
						, discountField1
						, discountPrice1
						, discountField2
						, discountPrice2
						, discountField3
						, discountPrice3
						, adCode
						) {
	
		var cm = new _cm("tid", "3", "vn2", "e4.0");
		cm.on = orderID;
		cm.tr = orderTotal;
		cm.osk = cmShopSKUs;
		cm.sg = orderShipping;
		cm.cd = customerID;
		cm.sa = customerState;
		cm.ct = customerCity;
		cm.zp = customerZIP;

		cm.or1 = tax;
		cm.or2 = processingFee;
		cm.or3 = discountField1;
		cm.or4 = discountPrice1;
		cm.or5 = discountField2;
		cm.or6 = discountPrice2;
		cm.or7 = discountField3;
		cm.or8 = discountPrice3;
		cm.or9 = adCode;

		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(customerID, customerEmail, customerCity,
				customerState, customerZIP, prevRegistration, newsletterName, 
				subscribe) {
	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 = prevRegistration;
	cm.ul=cmConvertMMC(location.href)	
	if (cm.rf){
		cm.rf=cmConvertMMC(cm.rf);
	} else {
		cm.rf=cmConvertMMC(document.referrer);
	}
	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;
	}

	// 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.pc = "Y";
	if(pageID == null) {
		cm.pi = cmGetDefaultPageID();
	} else {
		cm.pi = pageID;
	}
	cm.cg = categoryID;
	cm.ul=cmConvertMMC(document.URL)
	if (cm.rf){
		cm.rf=cmConvertMMC(cm.rf);
	} else {
		cm.rf=cmConvertMMC(document.referrer);
	}
	cm.writeImg();
}


// CUSTOM HARMONY TAG -------------------------
/* This tag is to link visitor and session information to the harmony business model.
Because there will be single operators that place orders for numerous customers - we will 
not get session and visitor specific information.  This tag is to help aide in the effor for
future customizations that will spec out visitor and session information based on the callers
and not the operators.

This tag should be thrown on the landing page - after the operator keys in the callers 
unique identifier.  American Blinds states that the uniquness of the caller is the number
they are calling from.  

This tag contains one parameter - the phone number the user is calling from - in a 10 digit
format. IE:  xxxxxxxxxx.  No spaces, dashes or () should be passed in this field.

The goal of this tag is to allow the parameter to serve as the unique customer ID (similar
to what we use our permanent cookie id for in tracking visitors and return visitors).  
The number of times this tag is thrown will indicate the number of sessions - the parameter
will help to reconcile repeat visitors/activity to the same caller. */

function cmCreateCustomVisitorTag(callerID){

	var cm = new _cm("tid", "7", "vn2", "e4.0");  //DO NOT CHANGE THESE PARAMETERS

	cm.li = 2;
	cm.ps1 = callerID;

	// 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;
	}
	if (cm.rf){
		cm.rf=cmConvertMMC(cm.rf);
	} else {
		cm.rf=cmConvertMMC(document.referrer);
	}
	cm.ul=cmConvertMMC(document.URL)
	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 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;

    if (isHref) {	
		if(url.toLowerCase().indexOf("http://") == 0 || url.toLowerCase().indexOf("https://") == 0) {
			newURL = newURL.substring(newURL.indexOf("://")+3);
			
			var urlArray = newURL.split("/");
	
			if(urlArray[0].toLowerCase().indexOf("americanblinds.com") < 0) {
				newURL = url;
			} else if (urlArray.length == 1) {
				newURL = "/";
			} else if (urlArray.length == 2) {
				newURL = "/"+urlArray[1];
			} else if (urlArray.length >= 3) {
				newURL = "";
				var start_pt = 2;
				if(urlArray[1].toLowerCase().indexOf("about_us") >= 0 || 
				   urlArray[1].toLowerCase().indexOf("affiliates") >= 0) {
					start_pt = 1;
				}

				for(var ci = start_pt; ci < urlArray.length; ci++) {
					newURL += "/" + urlArray[ci];
				}
			}
		}
	    var blackList = ["ui="];
	    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;
    }
}


//-->