<!--
/*
 * cmdatatagutils.js
 *
 * $Id: cmdatatagutils - 9672588 - 90082867 - 05AUG09.txt 125684 2009-08-05 14:31:22Z abrink $
 * $Revision $
 * Coremetrics Tag v4.0, 4/18/2003
 * COPYRIGHT 1999-2002 COREMETRICS, INC. 
 * ALL RIGHTS RESERVED. U.S.PATENT PENDING
 *
 * The following functions aid in the creation of Coremetrics data tags.
 * Date	    Imp. Eng.	Desc.
 * 07/07/06 Hutch White	Add Safe Submit, Add Manual Tags, Add CM_LM, Sent with Eluminate VerB
 * 01/19/07 Hutch White	Remove selectedfilter from blacklist
 * 12/19/07 O.Ivasiv    Added extra parameters  (initialPaymentType,futurePaymentType) to the registration tag
 * 01/29/07 Hutch White	Reconcile library with previous version.  Add product view tag
 * 02/01/08 O.Ivasiv	Modified myNormalizeURL function, added "fips=" parameter to blackList array
 * 06/02/08 ABRINK	Added declare statement for cmReferrer in TechProps and PageView
 * 07/24/09 C.Roberts	Added conversion event and element tags.
 * 07/28/09 ABRINK	Provision IA - update to elum switch
 *			Provision RM - added MakeTag and Explore logic
 * 08/05/09 ABRINK	Trigger default pageId when empty string sent in tag
 */

/*
 ****************************************************************************************
 * TAG GENERATING FUNCTIONS																*
 ****************************************************************************************
 */

var cm_ClientID="90082867";
var cm_TrackLink="A";
var cm_TrackImpressions="RS";
var cm_JSFEnabled = false;
var cm_exAttr=new Array();  

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";}

var cmCheckCMEMFlag = true;

/*
 * 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="ww25.humana-medicare.com/eluminate?";
}

function cmCreateManualImpressionTag(pageID, trackSP, trackRE) {
		// insert code to get pageID from cmTagControl if pageID is null
		cmMakeTag(["tid","9","pi",pageID,"cm_sp",trackSP,"cm_re",trackRE,"st",cm_ClientTS]);
}

function cmCreateManualLinkClickTag(href,name,pageID) {	
	if (cmCreateLinkTag == null && cM != null) {
		var cmCreateLinkTag = cM;
	}
	if (cmCreateLinkTag != null) {		
		var dt = new Date();
		cmLnkT3 = dt.getTime();
		href=cG7.normalizeURL(href,true);
		cmCreateLinkTag(cm_ClientTS, cmLnkT3, name, href, false, pageID);
	}
}

/* manual PageviewTag for off site page tagging.  Allows client to supply URL and Referring URL
*/
function cmCreateManualPageviewTag(pageID, categoryID,DestinationURL,ReferringURL) {
	cmMakeTag(["tid","1","pi",pageID,"cg",categoryID,"ul",DestinationURL,"rf",ReferringURL]);
}

function cmCreatePageElementTag(elementID, elementCategory, pageID, pageCategoryID, elementLocation,attributes) {
	if (attributes){
		var cm_exAttr=new Array;
		cm_exAttr=attributes.split("-_-");
	}
	cmMakeTag(["tid","15","eid",elementID,"ecat",elementCategory,"pflg","0","pid",pageID,"pcat",pageCategoryID,"eloc",elementLocation,"cm_exAttr",cm_exAttr]);
}

function cmCreateProductElementTag(elementID, elementCategory, productID, productCategoryID, elementLocation,attributes) {
	if (attributes){
		var cm_exAttr=new Array;
		cm_exAttr=attributes.split("-_-");
	}
	cmMakeTag(["tid","15","eid",elementID,"ecat",elementCategory,"pflg","1","pid",productID,"pcat",productCategoryID,"eloc",elementLocation,"cm_exAttr",cm_exAttr]);
}

/*
 * Creates a Tech Props tag.
 * pageID		: required. Page ID to set on this Pageview tag
 */
function cmCreateTechPropsTag(pageID, categoryID,attributes) {
	if(pageID == null || pageID == "") { pageID = getDefaultPageID(); }
	if (attributes){
		var cm_exAttr=new Array();
		cm_exAttr=attributes.split("-_-");
	}	
	cmMakeTag(["tid","6","pi",pageID,"cg",categoryID,"pc","Y","cm_exAttr",cm_exAttr]);
}

/*
 * 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.
 * searchResults: optional. Number of search results from the internal search.
 * 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, searchResults, helpFlag, errorFlag, toolFlag, extraField1, extraField2, 
	extraField3, extraField5, extraField6, extraField7, extraField8, extraField9, extraField10,extraField11, extraField12, extraField13, 
	extraField14, extraField15, attributes) {

	if (pageID == null || pageID == "") { pageID = getDefaultPageID(); }
	if (attributes){
		var cm_exAttr=new Array;
		cm_exAttr=attributes.split("-_-");
	}

	/* HUMANA CUSTOM  */
	var extraField4 = null;
	if (helpFlag) {			extraField4 = "HELP";	}
	else if (toolFlag) {	extraField4 = "TOOL";	}
	else if (errorFlag) {	extraField4 = "ERROR";	}

	cmMakeTag(["tid","1","pi",pageID,"cg",categoryID,"se",searchString,"sr",searchResults,
	"pv1",extraField1,"pv2",extraField2,"pv3",extraField3,"pv4",extraField4,"pv5",extraField5,"pv6",extraField6,
	"pv7",extraField7,"pv8",extraField8,"pv9",extraField9,"pv10",extraField10,"pv11",extraField11,"pv12",extraField12,
	"pv13",extraField13,"pv14",extraField14,"pv15",extraField15,"cm_exAttr",cm_exAttr]);
}

/*
 * 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);
}

/*
 * 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 
 *
 * 
 */
function cmCreateProductviewTag(productID, productName, categoryID, QuoteIdentifer) {
	cmMakeTag(["tid","5","pi","PRODUCT: "+productName+"("+productID+")","pr",productID,"pm",productName,"cg",categoryID,"pa1",QuoteIdentifer,"pc","N"]);
}

/*
 * Creates a Conversion Event tag
 *
 * eventID			: required. Conversion event ID
 * actionType		: required. 1=conversion initiation, 2=conversion completion
 * categoryID		: optional. Category for the event
 * points			: optional. Point value to assign to conversion.
 */
 function cmCreateConversionEventTag(eventID, actionType, categoryID, points,attributes) {
 	if (attributes){
		var cm_exAttr=new Array;
		cm_exAttr=attributes.split("-_-");
	}
	cmMakeTag(["tid","14","cid",eventID,"cat",actionType,"ccid",categoryID,"cpt",points,"cm_exAttr",cm_exAttr]);
 }

/*
 * Creates a registration tag
 *
 * For any of the optional parameters below, pass in 'null' if no information is available
 * 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.
 * visitorEmail      : optional. Visitor's email address
 * visitorState      : optional. Visitor's state
 * visitorZip        : optional. Visitor's zip code
 * visitorGender     : optional. Visitor's gender
 * visitorAge        : optional. Visitor's age
 * applicantType	 : optional. Visitor's applicant type, values should be: Self, POA, TW. Where self indicates they are ordering for themselves, 
 *						POA indicates it is someone with the Power Of Attorney of the applicant, and TW indicates it is a translator/Witness
 * productType		 : optional. Visitor's product type, values should be: HMO, PPO, PFFS, or PDP
 * paymentType		 : optional. Visitor's payment type, values should be SS for social security check deduction, or PC for personal check
 * previousMed		 : optional. Did the visitor have previous medical coverage? Should be either 'Y' or 'N'
 * previousRx		 : optional. Did the visitor have previous prescription coverage? Should be either 'Y' or 'N'
 * language			 : optional. What is the visitor's preferred language? 

 */
function cmCreateRegistrationTag(pageID, categoryID, 
	visitorID,visitorEmail,visitorState,visitorZip,visitorGender,
	visitorAge,applicantType,productType,paymentType,previousMed,previousRx,
    language, initialPaymentType, futurePaymentType, attributes) {

 	if (attributes){
		var cm_exAttr=new Array;
		cm_exAttr=attributes.split("-_-");
	}
	cmMakeTag(["tid","2","cd",visitorID,"em",visitorEmail,"sa",visitorState,"zp",visitorZip,"gd",visitorGender,"ag",visitorAge,"rg11",applicantType,
		"rg12", productType,"rg13", paymentType,"rg14", previousRx,"rg15", language,"rg1",previousMed,"rg2",initialPaymentType,"rg3",futurePaymentType,
		"cm_exAttr",cm_exAttr]);
}

/* Creates an Error Tag
 *
 */
function cmCreateErrorTag(pageID, categoryID) {
	if(pageID == null || pageID == "") {
		pageID = getDefaultPageID();
	}
	cmMakeTag(["tid","404","pi",pageID,"cg",categoryID,"pc","Y"]);
}

function cmMakeTag(__v) {
	var cm = new _cm("vn2", "e4.0");
	var i;
	for (i = 0; i < __v.length; i += 2) {
		var _n = __v[i];
		var _v = __v[i + 1];
		cm[_n] = _v;
	}
	
	var datestamp = new Date();	
	var stamp = (Math.floor(Math.random() * 11111111)) + datestamp.valueOf();	
	cm.rnd = stamp;
	
	if (cm.tid == "6") {
		cm.addTP();
		document.cookie = "cmTPSet=Y; path=/";
	}

	if (cm.tid == "1") {
		if (cI("cmTPSet") != 'Y') {
			cm.tid = "6";
			cm.pc = "Y";
			cm.addTP();
			document.cookie = "cmTPSet=Y; path=/";
		}
	}

	if (cm.tid != "4" && typeof(cm.cm_exAttr)!="undefined"){
		switch(cm.tid){
			case "6":
				prefix="pv";
				break;
			case "1":
				prefix="pv";
				break;
			case "2":
				prefix="rg";
				break;
			case "5":
				prefix="pr";
				break;
			case "3":
				prefix="o";
				break;
			case "14":
				prefix="c";
				break;
			case "15":
				prefix="e";
				break;
			default:
				break;
		}		
		var attrNum=cm.cm_exAttr.length;
		if (attrNum>15){
			attrNum=15;
		}
		for (i=0;i<attrNum;i++){
			if (cm.tid=="2"){
				Attval=prefix+(i+1);
			} else {
				Attval=prefix+"_a"+(i+1);
			}
			cm[Attval]=cm.cm_exAttr[i];
		}
		cm.cm_exAttr=null;
	}	
	if ((cm.pi == null) && (cm.pc == "Y")) {
		cm.pi = getDefaultPageID();
	}

	try{
		if (parent.cm_ref != null) {
			cm.rf = parent.cm_ref;
			if (cm.pc == "Y") {
				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; 
			if (cm.pc == "Y") {
				parent.cm_ref = cm.ul;
				parent.cm_set_mmc = false;
			}
		}
	}
	catch(err){}

	if (cm.ul == null) {
		cm.ul = window.location.href;
	}

	//check for zero price and zero quantity
	cmSafeZero(cm,["qt","bp","tr","sg"]);

	//check for manual_cm_mmc parameter;
	if (this.manual_cm_mmc != null) {
		cm.ul = cm.ul + ((cm.ul.indexOf("&") == -1) ? ((cm.ul.indexOf("?") == -1) ? "?" : "&") : "&") + "cm_mmc=" + this.manual_cm_mmc;
	}

	// convert MMC parameters to lowercase;
	cm.ul = cm.ul.replace(/cm_mmc/gi,"cm_mmc");
	cm.ul = cm.ul.replace(/cm_ven/gi,"cm_ven");
	cm.ul = cm.ul.replace(/cm_cat/gi,"cm_cat");
	cm.ul = cm.ul.replace(/cm_pla/gi,"cm_pla");
	cm.ul = cm.ul.replace(/cm_ite/gi,"cm_ite");
	if (cmCheckCMEMFlag){cmStartTagSet();}
    cm.writeImg();
	if (cmCheckCMEMFlag) {
		cmCheckCMEMFlag = false;	
		cmCheckCMEM();
		cmSendTagSet();		
	}
}

// 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); 
} 

function cmIndexOfParameter (parameter, inString) {
	return inString.indexOf(parameter);
}

function cmExtractParameter (parameter, inString) {
    if (cmIndexOfParameter(parameter, inString) == -1) {
        return null;
    }
	var s = inString;
	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);
}

function cmRemoveParameter (parameter, inString) {
    if (cmIndexOfParameter(parameter, inString) == -1) {
        return inString;
    }
	var s = inString;
	var begin = s.indexOf(parameter);
	var start = (begin - 1);
	var end = s.indexOf("&", begin);
	if (end == -1) {
		end = s.length;
	}
	if (s.substring(start, begin) == "?") {    // retain leading "?"
		start = (start + 1);
		end = (end + 1);
	}
	return s.substring(0, start) + s.substring(end, s.length);
}

function cmSafeZero(cm, checkArray) {
	// put logic here to convert number 0 to string "0"
	for (var i = 0; i < checkArray.length; ++i) {
		if ((cm[checkArray[i]] != null) && (cm[checkArray[i]] == 0)) {
			cm[checkArray[i]] = "0";
		}
	}
}

function myNormalizeURL(url, isHref) { 

	 var newURL = url; 
	 var pageURL=document.URL; 
  
     var blackList = ["txtZipCode=","fips=","ErrMsg=","Mode=","PRODUCT=","FN1=","LN1=","D1=","M1=","Y1=","CT=","ST=","FN2=","LN2=","D2=","M2=","Y2="]; 
	 if (pageURL.toLowerCase().indexOf("seniorwizard/preference_filter_2007.asp")>-1){
		 blackList[blackList.length]="fips=";
		 blackList[blackList.length]="prodtype=";
		 blackList[blackList.length]="selectedfilter=";
		 blackList[blackList.length]="planyear=";
		 blackList[blackList.length]="sys="; 
 	 }
	 if (pageURL.toLowerCase().indexOf("planyearselection.asp")>-1){
		 blackList[blackList.length]="fips=";
		 blackList[blackList.length]="txtZipCode=";		 
		 blackList[blackList.length]="PlanYear="; 
 	 }
     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++) { 
               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;
    }
}

/*
 ****************************************************************************************
 * HUMANA CUSTOM FUNCTIONS														*
 ****************************************************************************************
 */

function cmCheckCMEM() {
	if (cmIndexOfParameter("cm_em",document.location.href) != -1){
		var emailAddress = cmExtractParameter("cm_em",document.location.href);
		if (emailAddress.indexOf(":")>-1){
			emailAddress=emailAddress.substring(emailAddress.indexOf(":")+1);
		}
		cmCreateRegistrationTag(null,null,emailAddress,emailAddress);
	}
	if (cmIndexOfParameter("cm_lm",document.location.href) != -1){
		var emailAddress = cmExtractParameter("cm_lm",document.location.href);
		if (emailAddress.indexOf(":")>-1){
			emailAddress=emailAddress.substring(emailAddress.indexOf(":")+1);
		}		
		cmCreateRegistrationTag(null,null,emailAddress,emailAddress);
	}
}
/*
 * 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", "e4.0");
	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", "e4.0");
	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", "e4.0");
	cm.on = orderID;
	cm.tr = "1";
	cm.osk = '|' + appName + '|1|1|';
	cm.sg = "0";
	cm.cd = customerID;

	cm.writeImg();
}

/*
 * Creates Form Field activity tags
 */
function cmSetupApplicationTextBoxTags(category, first, last){
	var dt=new Date();
	cmRandom = dt.getTime()%10000000;

	var cm = new _cm("tid", "7", "vn2", "e4.0");
	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";
	}
	cm.writeImg();

	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);
				}
			}
		}
	}
}

var cmRandom;
var cmAppName;
var cmAppStepName;
var cmAppStepNumber;
var cmOnChangeCounter = 0;
var cmOnChangeTextBoxName = new Array();
var cmOnChangePointer = new Array();
var cmOnChangeFirst = new Array();

// 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);
}

/*
 * HUMANA Custom version of standard cmGetDefaultPageID function
 * called in all places where cmGetDefaultPageID function was used.
 */
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){
	var cm = new _cm("tid", "7", "vn2", "e4.0");
	cm.li  = 2;
	cm.ps1 = cmAppName;
	cm.ps2 = cmAppStepNumber;
	cm.ps3 = cmAppStepName;
	cm.ps4 = cmRandom;
	cm.ps5 = name;
	
	if (write)
	{
		cm.writeImg();
	} else {
		var image1 = new Image();
		image1.src = cm.getImgSrc();
	}
}

function cmSafeFormSubmit(id) {
            CI();
            cO(id,"S");
            CA(1);
            CJ(1);
            CE();

            return true;
}

function cmMultipleOnChange(id){
	if (cmOnChangeFirst[id]){
		cmSendFormFieldTag(cmOnChangeTextBoxName[id], false);
		cmOnChangeFirst[id] = false;
	}
	if (cmOnChangePointer[id]!=null){
		cmOnChangePointer[id]();
	}
}

function cP(e){

            CI();
            if (typeof e == typeof e123_x) {
                        var e = this;
            }
            else {
                        var e=CG(e);
            }
            cO(e?e.cM1:-1,"S");
            CA(1);
            CJ(1);
            CE();
}

/*
 * 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) {

	var cm = new _cm("tid", "1", "vn2", "e4.0");
	if (pageID) {
		cm.pi = pageID;
	} else {
		cm.pi = getDefaultApplicationPageID(appName, appStepName, appStepNumber );
	}
	
	if (categoryID){
		cm.cg = categoryID;
	}
	
	if (appName) {
		appName = cmRemoveWhiteSpace(appName);
		cm.pv1 = appName;
	}
	if (appStepNumber) {
		cm.pv2 = appStepNumber;
	}	
	if (appStepName) {
		cm.pv3 = appStepName;
	}
	if (helpFlag) {
		cm.pv4 = "HELP";
	}
	if (toolFlag) {
		cm.pv4 = "TOOL";
	}
	if (errorFlag) {
		cm.pv4 = "ERROR";
	}

	if (!transactionID) {
		transactionID = cmGetDefaultOrderID();
	}
	cm.pv15 = transactionID;	//Set page view extra field 15 to the transactionID. Must be placed here, due to optionality of the parameter

	if ((firstStepFlag)&&(appName)) {
		cmCreateShopAction5Tag(appName, categoryID);
	}
	if ((lastStepFlag)&&(appName)) {
		cmCreateShopAction9Tag(appName, visitorID, transactionID, categoryID);
		cmCreateOrderTag(transactionID, appName, visitorID);
	}
	
	// if available, override the referrer with the frameset referrer
	if (parent.cm_ref != null) {
		cm.rf = parent.cm_ref;
		parent.cm_ref = document.URL;
	}
	cmCheckCMEM();
	cm.writeImg();
	cmAppName = appName;
	cmAppStepName = appStepName;
	cmAppStepNumber = appStepNumber;
	cmSetupApplicationTextBoxTags(categoryID, firstStepFlag, lastStepFlag);
}
//-->
