<!--
/*
 * cmdatatagutils.js
 *
 * 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.
 *
 */

// TAG GENERATING FUNCTIONS ---------------------------------------------------

var cm_ClientID="90010394";
document.hitImage = new Array();
var cm_hitImageIndex = 0;


function cmSetProduction(){
	cm_HOST="data.coremetrics.com/eluminate?";
}

function cmSetStaging() {
	cmSetProduction();
	cm_ClientID="90026697";
}

function cmRemoveWhiteSpace(str){
	while (str.substring(0,1) == ' ') str = str.substring(1);
    while (str.substring(str.length-1,str.length) == ' ') str = str.substring(0,str.length-1);
	var check = true;
	while (check) {
		var pos = str.indexOf('  ');
		if (pos>-1){
			str = str.substring(0,pos) + str.substring(pos+1,str.length);
    	} else {
			check = false;
		}
	}
    return(str);
}



/*
 * Creates a Shop tag with Action 5 (Shopping Cart)
 *
 * 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
 * manufacturerID	: optional. Manufacturer ID to set on this Shop tag 
 * 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, categoryID, state, productType, singleProductFlag){
	
	var cm = new _cm("tid", "4", "vn2", "e3.1");
	cm.at = "5";
	cm.pr = productID;
	cm.pm = productName;
	cm.qt = "1";
	cm.bp = "1";
	if (categoryID) {
		cm.cg = categoryID;
	}
	if (productType) {
		cm.cg += ": " + productType;
	}
	if (singleProductFlag) {
		cm.sx15 = singleProductFlag;
	}
	cm.sx14 = productType;
	
	cm.writeImg();
}

function cmCreateShopAction5TagInMemory(productID, productName, categoryID, state, productType, singleProductFlag){
	
	var cm = new _cm("tid", "4", "vn2", "e3.1");
	cm.at = "5";
	cm.pr = productID;
	cm.pm = productName;
	cm.qt = "1";
	cm.bp = "1";
	if (categoryID) {
		cm.cg = categoryID;
	}
	if (productType) {
		cm.cg += ": " + productType;
	}
	if (singleProductFlag) {
		cm.sx15 = singleProductFlag;
	}
	cm.sx14 = productType;
	cm.sx3 = state;
	cm.loadImg();
}

/*
 * 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
 * cust_id		: required. ID of customer making the purchase
 * orderID		: required. ID 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, cust_id, orderID, categoryID, cm_overdraft, cm_funding, cm_state, productType, singleProductFlag) {
	var cm = new _cm("tid", "4", "vn2", "e3.1");
	cm.at = "9";
	cm.pr = productID;
	cm.pm = productName;
	cm.qt = "1";
	cm.bp = "1";
	cm.cd = cust_id;
	cm.on = orderID;
	cm.tr = "1";
	if (categoryID) {
		cm.cg = categoryID;
	}

	cm.sx1 = cm_overdraft;
	cm.sx2 = cm_funding;
	cm.sx3 = cm_state;
	if (productType) {
		cm.cg += ": " + productType;
	}
	if (singleProductFlag) {
		cm.sx15 = singleProductFlag;
	}
	cm.sx14 = productType;
	cm.writeImg();
}

function cmCreateShopAction9TagInMemory(productID, productName, cust_id, orderID, categoryID, cm_overdraft, cm_funding, cm_state, productType, singleProductFlag) {
	var cm = new _cm("tid", "4", "vn2", "e3.1");
	cm.at = "9";
	cm.pr = productID;
	cm.pm = productName;
	cm.qt = "1";
	cm.bp = "1";
	cm.cd = cust_id;
	cm.on = orderID;
	cm.tr = "1";
	if (categoryID) {
		cm.cg = categoryID;
	}

	cm.sx1 = cm_overdraft;
	cm.sx2 = cm_funding;
	cm.sx3 = cm_state;
	if (productType) {
		cm.cg += ": " + productType;
	}
	if (singleProductFlag) {
		cm.sx15 = singleProductFlag;
	}
	cm.sx14 = productType;

	cm.loadImg();
}

/*
 * Creates an Order tag
 *
 * orderID		: required. Order ID of this order
 * orderTotal		: required. Total price/quantity (they are equal) of this order
 * orderSKUData		: required. String representation of all lineitems
 * customerID		: required. Customer ID that placed this order
 * customerState	: optional. State of Customer that placed this order
 *
 * returns nothing, causes a document.write of an image request for this tag.
 */
function cmCreateOrderTag(orderID, orderTotal, orderSKUData, cust_id, state) {
	var cm = new _cm("tid", "3", "vn2", "e3.1");
	cm.on = orderID;
	cm.tr = orderTotal;
	cm.osk = orderSKUData;
	cm.sg = "0";
	cm.cd = cust_id;
	cm.sa = state;

	cm.writeImg();
}

function cmCreateOrderTagInMemory(orderID, orderTotal, orderSKUData, cust_id, state) {
	var cm = new _cm("tid", "3", "vn2", "e3.1");
	cm.on = orderID;
	cm.tr = orderTotal;
	cm.osk = orderSKUData;
	cm.sg = "0";
	cm.cd = cust_id;
	cm.sa = state;

	cm.loadImg();
}

/*
 * 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, templateName, searchString, categoryID, help, error, errormsg, tool, flash, adlink, merchantlink, adlob ) {
	var cm = new _cm("tid", "1", "vn2", "e3.1");
	if (pageID) {
		cm.pi = pageID;
	} else {
		cm.pi = getDefaultPageID(templateName);
	}
	if (searchString) {
		cm.se = searchString;
	}
	if (categoryID) {
		cm.cg = categoryID;
	}	
	if (help) {
		cm.pv4 = "HELP";
	}
	if (tool) {
		cm.pv4 = "TOOL";
	}
	if (error) {
		cm.pv4 = "ERROR";
	}
	
	if (errormsg) {
		cm.pv5 = errormsg;
	}

	if (adlink) {
		cm.pv6 = adlink;
	}

	if (merchantlink) {
		cm.pv7 = merchantlink;
	}
	
	if (adlob) {
		cm.pv8 = adlob;
	}
	
	cmFillAdStrings(cm);
        // alert("Coremetrics DEBUG: category=" + categoryID + " page=" + pageID);
	
	// 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 (flash) {
		cm.loadImg();
	} else {
		cm.writeImg();
	}
}

/*
 * Creates a Pageview tag with the given Page ID
 *
 * pageID		: required. Page ID to set on this Pageview tag
 *
 * returns nothing, causes an in memory load of an image request for this tag.
 */
function cmCreateInMemoryPageviewTag(pageID) {
	if (pageID) {
		var cm = new _cm("tid", "1", "vn2", "e3.1");
		cm.pi = pageID;
		cmFillAdStrings(cm);
		// 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.loadImg();
	}
}

function cmGetAppStepName(){
	//alert(document["cmutils"].src);
	
	//var array = document.plugins; 
	//for (var i=0;i<array.length; i++){
		//if (array[i].src.indexOf("image.cfm")>-1){
		//	alert(array[i].src);
		//}
	//}
	cmAppStepName = "test";
}

function cmGetDefaultOrderID(){
	var dt = new Date();
	var randomOrderID = Math.round(Math.random() * 1000 );
	// alert( dt.getTime()%10000000 + '' + randomOrderID );
	return dt.getTime()%10000000 + '' + randomOrderID;
}

function cmCreateFormFieldTag(appName, appStepNumber, appStepName, appCategory, fieldName){
	var cm = new _cm("tid", "7", "vn2", "e3.1");
	var dt = new Date();
	var cmRand = dt.getTime()%10000000;

	cm.li  = 2;
	cm.ps1 = appName;
	cm.ps2 = appStepNumber;
	cm.ps3 = appStepName;
	cm.ps4 = cmRand;
	cm.ps5 = fieldName;
	cm.ps6 = appCategory;
	
	
	//document.hitImage[cm_hitImageIndex] = new Image();
	//document.hitImage[cm_hitImageIndex].src = cm.getImgSrc();
	//cm_hitImageIndex++;
	cm.writeImg();

}

var cmRandom;
var cmAppName;
var cmAppStepName;
var cmAppStepNumber;
var cmAppCategory;

/*
 *  Application Tags
 */
function cmCreateApplicationTags( pageID, appName, appStepNumber, appStepName, help, error, errormsg, tool, category, 
	first, last, saved, state, productID, custID, orderID, adlink, adlob, cm_overdraft, cm_funding, cm_instantDecision, 
	cm_resumed, productName, productType ) {
	
	
	var cm = new _cm("tid", "1", "vn2", "e3.1");
	if (appStepName) {
		cmAppStepName = appStepName;
	} else {
		cmGetAppStepName();
	}
	if (appName) {
		appName = cmRemoveWhiteSpace(appName);
		cm.pv1 = appName;
	}
	if (pageID) {
		cm.pi = pageID;
	} else {
		cm.pi = getDefaultApplicationPageID(appName, appStepName, appStepNumber );
	}
	
	if (category){
		cm.cg = category;
	} else {
		category = appName + ":" + state;
		cm.cg = category; 
	}
	
	cm.pv3 = cmAppStepName;
	
	if (appStepNumber) {
		cm.pv2 = appStepNumber;
	}
	
	if (help) {
		cm.pv4 = "HELP";
	}
	if (tool) {
		cm.pv4 = "TOOL";
	}
	if (error) {
		cm.pv4 = "ERROR";
	}
	if (errormsg) {
		cm.pv5 = errormsg;
	}

	//  Pass productID as comma delimited list
	if ( productID ) {
	
		productArray = productID.split(',');
		productNameArray = new Array();
		productTypeArray = new Array();
		if ( productName ) {
			productNameArray = productName.split(',');
		}
		if ( productType ) {
			productTypeArray = productType.split(',');
		}
		
		var orderSKUData = '';
		var orderTotal = 0;
		
	// Begin DEL by GDC Dev Team for WR13795
	
	//	if (!orderID) {
	//		orderID = cmGetDefaultOrderID();
	//	}	
	
	// End DEL by GDC Dev Team for WR13795
		
	// Begin ADD by GDC Dev Team for WR13795
	// To prevent duplication of Order IDs in the last step of an application, set a cookie and access it whenever a new Order ID generation is not required  
		// setCookie - function to set the cookie
		function setCookie(name,value,path,domain) {
			var strCookieAssign = name + "=" + escape (value) + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "");
	  		document.cookie = strCookieAssign;
		}
		
		function deleteCookie(name,path,domain)
		{
		    if (getCookie(name))
		    {
		        document.cookie = name + "=" + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
		    }
		}
	
		// getCookie - function to get the cookie
		function getCookie (name) {
			var dcookie = document.cookie;
			var cname = name + "=";
			var clen = dcookie.length;
			var cbegin = 0;
			while (cbegin < clen) {
				var vbegin = cbegin + cname.length;
				if (dcookie.substring(cbegin, vbegin) == cname) {
					var vend = dcookie.indexOf (";", vbegin);
					if (vend == -1) vend = clen;
					return unescape(dcookie.substring(vbegin, vend));
				}
				cbegin = dcookie.indexOf(" ", cbegin) + 1;
				if (cbegin == 0) break;
			}
		return null;
		}
	
		if (first) {
			deleteCookie("OrderIDcookie","/",".bankofamerica.com");			
		}
			
		if (last) {
			if ((getCookie ("OrderIDcookie") == undefined) || ((getCookie ("OrderIDcookie"))&&(getCookie ("OrderIDcookie") == ""))) {
				orderID = cmGetDefaultOrderID();
				setCookie("OrderIDcookie",orderID,"/",".bankofamerica.com");
			}
			orderID = getCookie ("OrderIDcookie");			
		}
		
	// End ADD by GDC Dev Team for WR13795
		
		
		for (var i=0; i < productArray.length; i++) {
			if ((first)&&(productArray[i])) {
				// alert("FIRST: " +productArray[i]);
				var tempName = appName;
				if ((productNameArray[i] != null) && (productNameArray[i] != "")) {
					tempName = productNameArray[i];
				}
				var singleProductFlag = 0;
				var tempProductType = productTypeArray[i];
				if (productTypeArray.length > 1) { singleProductFlag = 1; }
				if (!tempProductType) { tempProductType = null };
				cmCreateShopAction5Tag(productArray[i], tempName, category, state, tempProductType, singleProductFlag);
			}
			if ((last)&&(productArray[i])) {
				// alert("LAST: " + productArray[i]);
				var tempName = appName;
				if ((productNameArray[i] != null) && (productNameArray[i] != "")) {
					tempName = productNameArray[i];
				}
				var singleProductFlag = 0;
				var tempProductType = productTypeArray[i];
				if (productTypeArray.length > 1) { singleProductFlag = 1; }
				if (!tempProductType) { tempProductType = null };
				cmCreateShopAction9Tag(productArray[i], tempName, custID, orderID, category, cm_overdraft, cm_funding, state, tempProductType, singleProductFlag);
				orderSKUData = orderSKUData + '|' + productArray[i] + '|1|1|';
				orderTotal++;
			}
		}
		
		if ((last) && (orderSKUData)){
			// alert( '[orderSKUData=' + orderSKUData + '][custID=' + custID + '][orderTotal=' 
			//      + orderTotal + '][orderID=' + orderID + ']');
			cmCreateOrderTag(orderID, orderTotal, orderSKUData, custID, state);
		}
	}

	if (adlink) {
		cm.pv6 = adlink;
	}
	
	if (adlob) {
		cm.pv8 = adlob;
	}

	cmFillAdStrings(cm);
	
	// 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.writeImg();
	cmAppName = appName;
	cmAppStepNumber = appStepNumber;
	cmAppCategory = category;
	cmSetupApplicationTextBoxTags(category, first, last, saved, cm_overdraft, cm_funding, cm_instantDecision, cm_resumed, state);
}

function cmCreateApplicationTagsInMemory( pageID, appName, appStepNumber, appStepName, help, error, errormsg, tool, category, 
	first, last, saved, state, productID, custID, orderID, adlink, adlob, productName, productType ) {
	
	
	var cm = new _cm("tid", "1", "vn2", "e3.1");
	if (appStepName) {
		cmAppStepName = appStepName;
	} else {
		cmGetAppStepName();
	}
	if (appName) {
		appName = cmRemoveWhiteSpace(appName);
		cm.pv1 = appName;
	}
	if (pageID) {
		cm.pi = pageID;
	} else {
		cm.pi = getDefaultApplicationPageID(appName, appStepName, appStepNumber );
	}
	
	if (category){
		cm.cg = category;
	} else {
		category = appName + ":" + state;
		cm.cg = category; 
	}
	
	cm.pv3 = cmAppStepName;
	
	if (appStepNumber) {
		cm.pv2 = appStepNumber;
	}
	
	if (help) {
		cm.pv4 = "HELP";
	}
	if (tool) {
		cm.pv4 = "TOOL";
	}
	if (error) {
		cm.pv4 = "ERROR";
	}
	if (errormsg) {
		cm.pv5 = errormsg;
	}

	//  Pass productID as comma delimited list
	if ( productID ) {
	
		productArray = productID.split(',');
		productNameArray = new Array();
		productTypeArray = new Array();
		if ( productName ) {
			productNameArray = productName.split(',');
		}
		if ( productType ) {
			productTypeArray = productType.split(',');
		}
		
		var orderSKUData = '';
		var orderTotal = 0;

		if (!orderID) {
			orderID = cmGetDefaultOrderID();
		}	
		
		for (var i=0; i < productArray.length; i++) {
			if ((first)&&(productArray[i])) {
				// alert("FIRST: " +productArray[i]);
				var tempName = appName;
				if ((productNameArray[i] != null) && (productNameArray[i] != "")) {
					tempName = productNameArray[i];
				}
				var singleProductFlag = 0;
				var tempProductType = productTypeArray[i];
				if (productTypeArray.length > 1) { singleProductFlag = 1; }
				if (!tempProductType) { tempProductType = null };
				cmCreateShopAction5TagInMemory(productArray[i], tempName, category, state, tempProductType, singleProductFlag);
			}
			if ((last)&&(productArray[i])) {
				// alert("LAST: " + productArray[i]);
				var tempName = appName;
				if ((productNameArray[i] != null) && (productNameArray[i] != "")) {
					tempName = productNameArray[i];
				}
				var singleProductFlag = 0;
				var tempProductType = productTypeArray[i];
				if (productTypeArray.length > 1) { singleProductFlag = 1; }
				if (!tempProductType) { tempProductType = null };
				cmCreateShopAction9TagInMemory(productArray[i], tempName, custID, orderID, category, cm_overdraft, cm_funding, state, tempProductType, singleProductFlag);
				orderSKUData = orderSKUData + '|' + productArray[i] + '|1|1|';
				orderTotal++;
			}
		}
		
		if ((last) && (orderSKUData)){
			// alert( '[orderSKUData=' + orderSKUData + '][custID=' + custID + '][orderTotal=' 
			//      + orderTotal + '][orderID=' + orderID + ']');
			cmCreateOrderTagInMemory(orderID, orderTotal, orderSKUData, custID, state);
		}
	}

	if (adlink) {
		cm.pv6 = adlink;
	}
	
	if (adlob) {
		cm.pv8 = adlob;
	}


	cmFillAdStrings(cm);
	
	// 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.loadImg();
	cmAppName = appName;
	cmAppStepNumber = appStepNumber;
	cmSetupApplicationTextBoxTagsInMemory(category, first, last, saved);
}

/* Creates Tag to track Business Selector Tool
*/
function cmCreateToolTag(pageID, toolName, toolStepNum, toolStepName, group, category, first, last, update, prodRec) {

	cmCreatePageviewTag(pageID, null, null, category);

	var cm = new _cm("tid", "7", "vn2", "e3.1");
	cm.li  = 3;
	cm.ps1 = toolName;
	cm.ps2 = toolStepNum;
	cm.ps3 = toolStepName;
	if(group) {
		cm.ps4 = group;
	}
	cm.ps5 = category;
	if(first) {
		cm.ps6 = "FIRST";
	}
	if(last) {
		cm.ps7 = "LAST";
	}
	if(update) {
		cm.ps8 = "UPDATE";
	}
	if(prodRec) {
		cm.ps9 = prodRec;
	}

	cm.writeImg();

}

/*
 * Creates an acceptable default Page ID value to use for Pageview tags.
 */
function getDefaultPageID(templateName) { 
	if (!templateName){
		templateName ="";
	}
	var cmTitle = document.title;
	
	var tempIndex1 = cmTitle.indexOf("Bank of America |");
	if (tempIndex1 == 0) {
		cmTitle = cmTitle.substr(17);
	} else if ( cmTitle.indexOf("Banc of America Investment Services, Inc. |") == 0 ) {
		cmTitle = cmTitle.substr(43);
	}
	cmTitle = cmTitle + " (" + templateName + ")";
	return(cmTitle);
}

/*
 * PageView Tag for OnClick Events.
 */
function cmPageviewOnClick(pageID,theURL,category) {
	if (pageID && pageID != "")
    {
		var cm = new _cm("tid", "1", "vn2", "e3.1");
        cm.pi = pageID;
        if (theURL && theURL != "")
		{
        	cm.ul = theURL;
		}
		
		if(category) {
			cm.cg = category;
		}
		
	 	// 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 imgRequest = new Image();
        imgRequest.src = cm.getImgSrc();
	}
	return true;
}


/*
 * Creates an acceptable default Page ID value to use for Pageview tags.
 */
function getDefaultApplicationPageID(appName, appStepName, appStepNumber){ 

	// alert( "stepname: " + appStepName + " stepnum: " + appStepNumber );
	var	cmPageID = "Application: " + appName + " Step: " + appStepNumber + " (" + appStepName + ")";
	return(cmPageID);
}

/*
 * 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(templateName) {
	cmCreatePageviewTag(getDefaultPageID(templateName), null, null);
}

function cmGetAdString(){
	var linkCt = document.links.length;
	var lurl;
	var i;
	var adString = "";
	var ndx;
	var ad;
	for (i = 0; i < linkCt; i++) {
		try
		{
			lurl = document.links[i].href;
			ndx = lurl.lastIndexOf("adlink=");
			ndx2 = lurl.lastIndexOf("/adtrack/");
			if ((ndx >= 0) && (ndx2>0)) {
				ad = lurl.substring(ndx+7, lurl.length).toLowerCase();
				if (ad.indexOf("&amp;") >= 0){
					ad = ad.substring(0, ad.indexOf("&amp;"));
				}
				adString += "|" + ad + "|";
			}
		}
		catch(e)
		{
			//alert(e);
		}
		
	}
	return adString;
}

/*
 *  WSuayan: Pull the stepName from Jeff Tucker's Fast Track.
 */
 
function cmGetQueryParam( paramName, urlString ) {
	var strValue = "";
	var ndx;
	
	ndx = urlString.lastIndexOf( paramName + "=" );
	if ( ndx >= 0 ) {
		strValue = urlString.substring( ndx + paramName.length + 1, urlString.length).toLowerCase();
		if ( strValue.indexOf("&") >= 0 ){
			strValue = strValue.substring(0, strValue.indexOf("&"));
		}
	}
	return strValue;	
}

function cmGetStepID( urlString ){
	var stepID = "";
	var ndx;
	
	var stepIdName = cmGetQueryParam("page", urlString );
	ndx = stepIdName.indexOf("_");
	if ( ndx >= 0 ) {
		stepID = stepIdName.substring( 0, ndx ).toLowerCase();
	}
	return stepID;
}

function cmGetStepName( urlString ){
	var stepName = "";
	var ndx;
	var stepIdName = cmGetQueryParam("page", urlString );
	ndx = stepIdName.indexOf("_");
	if ( ndx >= 0 ) {
		stepName = stepIdName.substring( ndx + 1, urlString.length ).toLowerCase();
	} else {
		stepName = stepIdName;
	}
	return stepName;
}

/* WSuayan  END */
 

function cmFillAdStrings(cm){
	var adString = cmGetAdString();
	var maxlength = 100;
	var length = adString.length;
	if (length<=maxlength)
	{
		cm.pv11 = adString;
	} else {
		cm.pv11 = adString.substring(0,maxlength);
		if (length<=2*maxlength){
			cm.pv12 = adString.substring(maxlength,length);
		} else {
			cm.pv12 = adString.substring(maxlength,2*maxlength);
			if (length<=3*maxlength){
				cm.pv13 = adString.substring(2*maxlength,length);
			} else {
				cm.pv13 = adString.substring(2*maxlength,3*maxlength);
				if (length<=4*maxlength){
					cm.pv14 = adString.substring(3*maxlength,length);
				} else {
					cm.pv14 = adString.substring(3*maxlength,4*maxlength);
					cm.pv15 = adString.substring(4*maxlength,length);
				}						
			}	
		}
	}
}

/*
 * Creates a registration tag
 *
 * Page Count = "Y"
 */
function cmCreateRegistrationTag(pageID, templateName, cust_id, olb_customer,  state, advisorInfo, categoryID, firm, 
								 adlink, adlob, homelink, officelink) {
	var cm = new _cm("tid", "2", "vn2", "e3.1");		
	cm.cd = cust_id;
	cm.sa = state;
	if (pageID) {
		cm.pi = pageID;
	} else {
		cm.pi = getDefaultPageID(templateName);
	}
	cm.cg  = categoryID;
	cm.pv6 = adlink;
	cm.pv8 = adlob;
	cm.rg1 = cust_id;
	cm.rg2 = advisorInfo;
	cm.rg11 = olb_customer;
	
	if(olb_customer) {
		cm.rg12 = state;
	}
	
	if(firm) {
		cm.rg3 = firm;
	}
	
	if(homelink) {
		cm.rg4 = homelink;
	}
	if(officelink) {
		cm.rg5 = officelink;
	}

	// if available, override the referrer with the frameset referrer
	if (parent.cm_ref != null) {
		cm.rf = parent.cm_ref;
		parent.cm_ref = document.URL;
	}

	cmFillAdStrings(cm);
	cm.pc="Y";
	cm.writeImg();
}

function cmCreateTechProps(pageID, categoryID, templateName, adlink, adlob){
	var cm = new _cm("tid", "6", "vn2", "e3.1");
	cm.addTP();
	if (pageID) {
		cm.pi = pageID;
	} else {
		cm.pi = getDefaultPageID(templateName);
	}
	
	// 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.cg = categoryID;
	cm.pv6 = adlink;
	cm.pv8 = adlob;
	cmFillAdStrings(cm);
	cm.pc = "Y";
	cm.writeImg();
}


//Even though the event parameter is not used, it must remain since Netscape will 
//automatically send it as the first parameter, the rest of the time it will be null
function cmSendFormFieldTag(name, write){
	var cm = new _cm("tid", "7", "vn2", "e3.1");
	cm.li  = 2;
	cm.ps1 = cmAppName;
	cm.ps2 = cmAppStepNumber;
	cm.ps3 = cmAppStepName;
	cm.ps4 = cmRandom;
	cm.ps5 = name;
	cm.ps6 = cmAppCategory;
	
	//if (write)
	//{
	cm.writeImg();
	//} else {
	//	var image1 = new Image();
	//	image1.src = cm.getImgSrc();
	//}
}

function cmCreateFormEventTag(appName, appStepNumber, appStepName, appCategory, elementName, elementState) {
	var cm = new _cm("tid", "7", "vn2", "e3.1");
	cm.li  = 4;
	cm.ps1 = appName;
	cm.ps2 = appStepNumber;
	cm.ps3 = appStepName;
	cm.ps4 = elementName;
	cm.ps5 = elementState;
	cm.ps6 = appCategory;

	//document.hitImage[cm_hitImageIndex] = new Image();
	//document.hitImage[cm_hitImageIndex].src = cm.getImgSrc();
	//cm_hitImageIndex++;
	cm.writeImg();
}

var cmFormEventCounter = 0;
var cmFormEventElement = new Array();
var cmFormEventPointer = new Array();
var cmFormEventFirst   = new Array();

function cmSetEvent(elem) {
	cmFormEventElement[cmFormEventCounter] = elem;
	if(elem.type == "text" || elem.type == "textarea") {
		//cmFormEventPointer[cmFormEventCounter] = elem.onchange;
		//cmFormEventFirst[cmFormEventCounter] = true;
		cmFormEventElement[cmFormEventCounter].cm_oldOnChange = elem.onchange;
		cmFormEventFirst[cmFormEventCounter] = true;
		elem.onchange = new Function("cmMultipleEvents("+cmFormEventCounter+");");
	} else {
		//cmFormEventPointer[cmFormEventCounter] = elem.onclick;
		cmFormEventElement[cmFormEventCounter].cm_oldOnChange = elem.onclick;
		elem.onclick = new Function("cmMultipleEvents("+cmFormEventCounter+");");
	}

	cmFormEventCounter++;

}

function cmMultipleEvents(id){
	var cm_elem = cmFormEventElement[id];
	var cm_val;
	if(cm_elem.type == "radio") { 
		cmCreateFormEventTag(cmAppName, cmAppStepNumber, cmAppStepName, cmAppCategory, cm_elem.name, cm_elem.value);
	} else if(cm_elem.type == "checkbox") { 
		cm_val = cm_elem.checked ? "T":"F";
		cmCreateFormEventTag(cmAppName, cmAppStepNumber, cmAppStepName, cmAppCategory, cm_elem.name, cm_val);
	} else if(cm_elem.type == "text" || cm_elem.type == "textarea") {
		if(cmFormEventFirst[id] == true ){
			cmCreateFormFieldTag(cmAppName, cmAppStepNumber, cmAppStepName, cmAppCategory, cm_elem.name);
			cmFormEventFirst[id] = false;
		}
	}
	if (cm_elem.cm_oldOnChange != null){
		cm_elem.cm_oldOnChange();
	}
}

function cmSetupApplicationTextBoxTags(category, first, last, saved, cm_overdraft, cm_funding, cm_instantDecision, cm_resumed, state){
	var dt=new Date();
	cmRandom = dt.getTime()%10000000;

	var cm = new _cm("tid", "7", "vn2", "e3.1");
	cm.li = 1;
	cm.ps1= cmAppName;
	cm.ps2 = cmAppStepNumber;
	cm.ps3 = cmAppStepName;
	cm.ps4 = cmRandom;
	cm.ps5= category;
	if (first){
		cm.ps6="FIRST";
	}
	if (last){
		cm.ps7="LAST";
	}
	if (saved){
		cm.ps8="SAVED";
	}
	cm.ps9 = cm_overdraft;
	cm.ps10 = cm_funding;
	cm.ps11 = cm_instantDecision;
	if(cm_resumed) {
		cm.ps12 = "RESUMED";
	}
	cm.ps13 = state;

	cm.writeImg();


	var cm_val;

	for (var i=0;i<document.forms.length; i++){
		for (var j=0;j<document.forms[i].elements.length; j++)
		{
			var el = document.forms[i].elements[j];
			if (el.type=="checkbox")
			{
				cm_val = el.checked ? "T":"F";
				cmCreateFormEventTag(cmAppName, cmAppStepNumber, cmAppStepName, cmAppCategory, el.name, cm_val);
				cmSetEvent(el);
			}
			else if (el.type=="radio") {
				if(el.checked == true) {
					cmCreateFormEventTag(cmAppName, cmAppStepNumber, cmAppStepName, cmAppCategory, el.name, el.value);
				}
				cmSetEvent(el);
			}
			else if (el.type == "text" || el.type == "textarea") {
				if(el.value==""){
					cmSetEvent(el);
				} else {
					cmCreateFormFieldTag(cmAppName, cmAppStepNumber, cmAppStepName, cmAppCategory, el.name);
				}
			}
		}
	}
}

function cmSetupApplicationTextBoxTagsInMemory(category, first, last, saved){
	var dt=new Date();
	cmRandom = dt.getTime()%10000000;

	var cm = new _cm("tid", "7", "vn2", "e3.1");
	cm.li = 1;
	cm.ps1= cmAppName;
	cm.ps2 = cmAppStepNumber;
	cm.ps3 = cmAppStepName;
	cm.ps4 = cmRandom;
	cm.ps5= category;
	if (first){
		cm.ps6="FIRST";
	}
	if (last){
		cm.ps7="LAST";
	}
	if (saved){
		cm.ps8="SAVED";
	}
	cm.loadImg();
	
}

function cmCreateAppSubmitTimingStart() {
	var cm = new _cm("tid", "7", "vn2", "e3.1");
	cm.li = 600;
	cm.writeImg();
}

function cmCreateAppSubmitTimingEnd() {
	var cm = new _cm("tid", "7", "vn2", "e3.1");
	cm.li = 601;
	cm.writeImg();
}
//-->
