<!--
/*
 * cmdatatagutils.js
 *
 * Coremetrics Tag v4.0, 4/18/2004
 * COPYRIGHT 1999-2004 COREMETRICS, INC. 
 * ALL RIGHTS RESERVED. U.S.PATENT PENDING
 *
 * The following functions aid in the creation of Coremetrics data tags.
 *
 */

/*
 ****************************************************************************************
 * TAG GENERATING FUNCTIONS																*
 ****************************************************************************************
 */

cm_ClientID="90027519";

var cmDt = new Date();
var cmTimeStamp = cmDt.getTime();
var cmFormFieldsSet = false;
var cmAppName = new Array();
var cmAppStepName = new Array();
var cmAppStepNumber = new Array();
var cmAppCounter = 0;
var cmPageviewThrown = false;

document.hitImage = new Array();
var cm_hitImageIndex = 0;

/*	For Manual Link Click tags */

if (!cmHandleLinkClick) { var cmHandleLinkClick = C9; }


/*
 * Redirects tag traffic (by default, aimed at test servers) to Coremetrics production servers.
 * Should be called from and only from production environments.
 */
function cmSetProduction(){
	cm_HOST="data.coremetrics.com/eluminate?";
}

/*
 * Creates a Pageview tag with the given Page ID
 *
 * pageID		: required. Page ID to set on this Pageview tag.  If not populated,
				  default page ID is created.
 * categoryID	: optional. Category ID to set on this Pageview tag
 * searchString	: optional. Internal search string enterred by user to reach
 *				  this page.
 * helpFlag		: optional.  T/F to indicate if user is seeing a help message.
 * errorFlag	: optional.  T/F to indicate if user is seeing an error message.
 * toolFlag		: optional.  T/F to indicate if user is using a tool, calculator, etc.
 *
 * returns nothing, causes a document.write of an image request for this tag.
 */
function cmCreatePageviewTag(pageID, categoryID, searchString, helpFlag, errorFlag, toolFlag) {
	var cm = new _cm("tid", "1", "vn2", "e3.1");
	if (pageID) {
		cm.pi = pageID;
	} else {
		cm.pi = getDefaultPageID();
	}
	if (searchString) {
		cm.se = searchString;
	}
	if (categoryID) {
		cm.cg = categoryID;
	}	
	if (helpFlag) {
		cm.pv4 = "HELP";
	}
	if (toolFlag) {
		cm.pv4 = "TOOL";
	}
	if (errorFlag) {
		cm.pv4 = "ERROR";
	}
	
	cm.pv15 = cmTimeStamp;
	
	// 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();
	cmPageviewThrown = true;
}

/*
 * Creates a technical properties tag
 *
 * pageID		: required. Page ID to set on this tag.  If not populated,
				  default page ID is created.
 * categoryID	: optional. Category ID to set on this tag
 *
 * Page Count = "Y", so this tag also registers as a pageview.  No explicit
					pageview tag is necessary.
 */
function cmCreateTechPropsTag(pageID, categoryID){
	var cm = new _cm("tid", "6", "vn2", "e3.1");
	cm.addTP();
	if (pageID) {
		cm.pi = pageID;
	} else {
		cm.pi = getDefaultPageID();
	}
	
	if (categoryID) {
		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;
	}

	cm.pc = "Y";
	cm.writeImg();
}

/*
 * Creates a registration tag
 *
 * pageID		: required. Page ID to set on this tag.  If not populated,
				  default page ID is created.
 * categoryID	: optional. Category ID to set on this tag.
 * visitorID	: required.  Unique visitor ID for this user.
 *
 * Page Count = "Y", so this tag also registers as a pageview.  No explicit
					pageview tag is necessary.
 */
function cmCreateRegistrationTag(vId, email, city, state, zip, cobrand,
office, age, gender){


    var cm = new _cm("tid", "2", "vn2", "e3.1");

    if (vId)    {cm.cd=vId;}
    if (email)  {cm.em=email;}
    if (state)  {cm.sa=state;}
    if (city)   {cm.ct=city;}
    if (zip)    {cm.zp=zip;}
    if (cobrand){cm.rg11=cobrand;}
    if (office) {cm.rg12=office;}
    if (age) {cm.ag = age;}
    if (gender) {cm.gd = gender;}
	    
    cm.writeImg();

    cm = new _cm("tid", "7", "vn2", "e3.1");
    cm.li  = 3;
    cm.ps1 = vId;
    cm.writeImg();
		
}


/*
 * Creates application-related tags: 
 *		Pageview tag, application tag, any form field tags.
 *
 * pageID			: required.  Page ID to set on the embedded Pageview tag.  If not populated,
					  default application page ID is created.
 * categoryID		: optional.  Category ID to set on this tag.
 * appName			: required.  Name of application for this tag.
 * appStepNumber	: required.  Number of step in application.
 * appStepName		: required.  Name of step in application.
 * helpFlag			: optional.  T/F to indicate if user is seeing a help message in application flow.
 * errorFlag		: optional.  T/F to indicate if user is seeing an error message in application flow.
 * toolFlag			: optional.  T/F to indicate if user is using a tool, calculator, etc. in application flow.
 * firstStepFlag	: optional.  T/F to indicate if step is first step in application flow.
 * lastStepFlag		: optional.  T/F to indicate if step is last step in application flow.
 * visitorID		: required for last step in application.  Unique visitor ID for this user.
 * transactionID	: required for last step in application.  Unique transaction ID or order ID.
					  If not populated, unique ID is created.
 */
function cmCreateApplicationTags(pageID, categoryID, appName, appStepNumber, appStepName, helpFlag, errorFlag, 
	toolFlag, firstStepFlag, lastStepFlag, visitorID, transactionID) {

	if(!cmPageviewThrown) {
		if(!pageID) {
			pageID = getDefaultApplicationPageID(appName, appStepName, appStepNumber );
		}
		cmCreatePageviewTag(pageID, categoryID, null, helpFlag, errorFlag, toolFlag);
	}
	
	var acctSetupStr = "ACCOUNT SETUP ";
	if(appName.toUpperCase().indexOf(acctSetupStr) == 0) {
		if (!transactionID) {
			transactionID = cmGetDefaultOrderID();
		}
		if ((firstStepFlag)&&(appName)) {
			cmCreateShopAction5Tag(appName, categoryID);
		}
		if ((lastStepFlag)&&(appName)) {
			cmCreateShopAction9Tag(appName, visitorID, transactionID, categoryID);
			cmCreateOrderTag(transactionID, appName, visitorID);
		}
	}	
	
	cmCreateApplicationStepTag(appName, appStepNumber, appStepName, categoryID, firstStepFlag, lastStepFlag);

	if(!cmFormFieldsSet) {
		cmSetupFormFieldTags();
		cmFormFieldsSet = true;
	}
	
}

function cmResetApplicationTags() {

	cmPageviewThrown = false;
	cmDt = new Date();
	cmTimeStamp = cmDt.getTime();
	cmAppCounter = 0;
	
}

/* Creates an Error Tag
 *
 * pageID	: required.  If not populated, default page ID is created.
 *
 * returns nothing, causes a document.write of an image request for this tag.
 */
function cmCreateErrorTag(pageID) {
	var cm=new _cm("tid", "404", "vn2", "e3.1");  //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;
	}

	cm.pc = "Y";
	if (pageID) {
		cm.pi = pageID;
	} else {
		cm.pi = getDefaultPageID();
	}
	cm.writeImg();
}

/* Manually creates a Link Click tag for LIVEview */
function cmCreateManualLinkClickTag(in_href, in_link_name) {

	var e = new Object(); 
	e.tagName = "A";
	e.href = in_href; // normalization not necessary
	e.name = in_link_name;
	cmHandleLinkClick(e);

}

/*
 * 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() {
	cmCreatePageviewTag(getDefaultPageID(), null, null);
}

/*
 ****************************************************************************************
 * INTERNAL TAG-CREATING FUNCTIONS														*
 ****************************************************************************************
 */

var cmRandom;
var cmOnChangeCounter = 0;
var cmOnChangeTextBoxName = new Array();
var cmOnChangePointer = new Array();
var cmOnChangeFirst = new Array();

/*
 * Creates a Shop tag with Action 5 (First step in application)
 *
 * productID		: required. Product 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, categoryID){
	
	var cm = new _cm("tid", "4", "vn2", "e3.1");
	cm.at = "5";
	cm.pr = productID;
	cm.pm = productID;
	cm.qt = "1";
	cm.bp = "1";
	if (categoryID) {
		cm.cg = categoryID;
	}

	cm.writeImg();
}

/*
 * Creates a Shop tag with Action 9 (Application submitted page)
 *
 * productID		: required. Product ID 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, cust_id, orderID, categoryID) {
	var cm = new _cm("tid", "4", "vn2", "e3.1");
	cm.at = "9";
	cm.pr = productID;
	cm.pm = productID;
	cm.qt = "1";
	cm.bp = "1";
	cm.cd = cust_id;
	cm.on = orderID;
	cm.tr = "1";
	if (categoryID) {
		cm.cg = categoryID;
	}

	cm.writeImg();
}

/*
 * Creates an Order tag
 *
 * orderID			: required. Order ID of this order
 * appName			: required. Product applied for in this order
 * customerID		: required. Customer ID that placed this order
 *
 * returns nothing, causes a document.write of an image request for this tag.
 */
function cmCreateOrderTag(orderID, appName, customerID) {
	var cm = new _cm("tid", "3", "vn2", "e3.1");
	cm.on = orderID;
	cm.tr = "1";
	cm.osk = '|' + appName + '|1|1|';
	cm.sg = "0";
	cm.cd = customerID;

	cm.writeImg();
}

/*
 * Creates Application Step tag
 */
function cmCreateApplicationStepTag(appName, appStepNumber, appStepName, category, first, last){
	
	var dt=new Date();
	cmRandom = dt.getTime()%10000000;
	
	// add application step to global arrays
	cmAppName[cmAppCounter] = appName;
	cmAppStepNumber[cmAppCounter] = appStepNumber;
	cmAppStepName[cmAppCounter] = appStepName;
	cmAppCounter++;
	
	// throw application step tag
	var cm = new _cm("tid", "7", "vn2", "e3.1");
	cm.li = 1;
	cm.ps1= appName;
	cm.ps2 = appStepNumber;
	cm.ps3 = appStepName;
	cm.ps4 = cmRandom;
	cm.ps5= category;
	if (first){
		cm.ps6="FIRST";
	}
	if (last){
		cm.ps7="LAST";
	}
	cm.ps15 = cmTimeStamp;
	
	cm.writeImg();
}

/*
 * Creates Form Field activity tags
 */
function cmSetupFormFieldTags(){
	var dt=new Date();
	cmRandom = dt.getTime()%10000000;

	for (var i=0;i<document.forms.length; i++){
		for (var j=0;j<document.forms[i].elements.length; j++)
		{
			if (document.forms[i].elements[j].type=="text")
			{
				if(document.forms[i].elements[j].value==""){
					cmCheckForOnChange(document.forms[i].elements[j]);
				} else {
					cmSendFormFieldTag(document.forms[i].elements[j].name, true);
				}
			}
		}
	}
}

/*
 ****************************************************************************************
 * INTERNAL HELPER FUNCTIONS															*
 ****************************************************************************************
 */



// Removes beginning, ending, and double spaces from strings
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,str.length);
    	} else {
			check = false;
		}
	}
    return(str);
}

/*
 * 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() { 
	if (document.title) 
	{
		var doctitle = document.title;

		if (doctitle.length >= 100)
		{
			doctitle = doctitle.substring(0,90);
		}

		return doctitle;
	}

	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 an acceptable default Page ID value to use for Pageview tags.
 */
function getDefaultApplicationPageID(appName, appStepName, appStepNumber){
	var	cmPageID = "Application: " + appName + " Step: " + appStepNumber + " (" + appStepName + ")";
	return(cmPageID);
}

function cmGetDefaultOrderID(){
	var dt = new Date();
	var randomOrderID = Math.round(Math.random() * 1000 );
	// alert( dt.getTime()%10000000 + '' + randomOrderID );
	return dt.getTime()%10000000 + '' + randomOrderID;
}

function cmCheckForOnChange(textbox){
	cmOnChangeTextBoxName[cmOnChangeCounter] = textbox.name;
	cmOnChangePointer[cmOnChangeCounter] = textbox.onchange;
	cmOnChangeFirst[cmOnChangeCounter] = true;
	textbox.onchange = new Function("cmMultipleOnChange(" + cmOnChangeCounter + ");");
	cmOnChangeCounter++;
}
 
//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){
	
	for(var i = 0; i < cmAppCounter; i++) {
		//alert("sending: " + cmAppName[i] + " " + name);
		var cm = new _cm("tid", "7", "vn2", "e3.1");
		cm.li  = 2;
		cm.ps1 = cmAppName[i];
		cm.ps2 = cmAppStepNumber[i];
		cm.ps3 = cmAppStepName[i];
		cm.ps4 = cmRandom;
		cm.ps5 = name;
		cm.ps15 = cmTimeStamp;
		
		if (write)
		{
			cm.writeImg();
		} else {
			var cmImage = new Image();
			cmImage.src = cm.getImgSrc();
			document.hitImage[cm_hitImageIndex] = cmImage;
			cm_hitImageIndex += 1;
		}
	}
}

function cmMultipleOnChange(id){
	if (cmOnChangeFirst[id]){
		cmSendFormFieldTag(cmOnChangeTextBoxName[id], false);
		cmOnChangeFirst[id] = false;
	}
	if (cmOnChangePointer[id]!=null){
		cmOnChangePointer[id]();
	}
}

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("sharebuilder.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 = ["OrderNo=", "ConfirmNo=", "AchRequestNo=", "DisburseId=", "ActiveAccount=", 
		     "acc_random=", "pageid=", "site=", "generic=", "usergroup=", "freetrial="];
    var paramString;
    var paramIndex = newURL.indexOf("?");
    var params;
    var keepParams = new Array();
    var goodParam;

    if(isHref) {
	    params = newURL.split("/");
	    for(var i=0; i<params.length; i++) {
		goodParam = true;
		for(var j=0; j<blackList.length; j++) {
			if (params[i].indexOf(blackList[j]) == 0) {
				goodParam = false;
			}
		}
		if(goodParam == true) {
			keepParams[keepParams.length] = params[i];
		}
	    }

	    newURL = keepParams.join("/");
	    keepParams = new Array();
    }

    var paramIndex = newURL.indexOf("?");
    

    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++) {
			if (params[i].indexOf(blackList[j]) == 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;
    }
}
//-->
