/*
 * 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 ---------------------------------------------------

/*
 * Calling this function points tags to the production database
 */
function cmSetProduction(){
	cm_HOST="data.coremetrics.com/eluminate?"; 
}

/*
 * Creates a Tech Props tag.
 * pageID		: required. Page ID to set on this Pageview tag
 */
function cmCreateTechPropsTag(pageID) {
	if (pageID) {
		var cm=new _cm("tid", "6", "vn2", "e3.1");
		cm.pc="N";
		cm.pi = 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;
		}
		cm.addTP();
		cm.writeImg();
	}
}

/*
 * 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, searchString, categoryID, categoryName, productName, productID, pageName) {
	if (pageID == null) {
		pageID = getDefaultPageID();
	}

	var cm = new _cm("tid", "1", "vn2", "e3.1");
	cm.pi = pageID;
	
	if (searchString) {
		cm.se = searchString;
	}
	if (categoryID) {
		cm.cg = categoryID;
	}
	
	if (categoryName) {
		cm.cl = categoryName;
	}	
	
	if (productName) {
		cm.pm = productName;
	}
	
	if (productID) {
		cm.pr = productID;
	}
	
	if (pageName) {
		cm.pn = pageName;
	}
	
	

	// 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();
}

/*
 * 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);
}

// HELPER FUNCTIONS -----------------------------------------------------------
/* These functions are used by the tag-generating functions and/or may be used
 * in in general as convenience functions
 */

/*
 * Creates an acceptable default Page ID value to use for Pageview tags.
 * The default Page ID is based on the URL, and consists of the path and
 * filename (without the protocol, domain and query string).
 * 
 * example:
 * returns "x/y/MyPage.asp" for the URL http://www.mysite.com/x/y/MyPage.asp
 */
function getDefaultPageID() { 
	var pageName = window.location.pathname; 

	// eliminates everything after "?" (for Opera browswers)
	var tempIndex1 = pageName.indexOf("?");
	if (tempIndex1 != -1) {
		pageName = pageName.substr(0, tempIndex1);
	}
	// eliminates everything after "#" (for Opera browswers)
	var tempIndex2 = pageName.indexOf("#");
	if (tempIndex2 != -1) {
		pageName = pageName.substr(0, tempIndex2);
	}
	// eliminates everything after ";"
	var tempIndex3 = pageName.indexOf(";");
	if (tempIndex3 != -1) {
		pageName = pageName.substr(0, tempIndex3);
	}

	var slashPos = pageName.lastIndexOf("/");
	if (slashPos == pageName.length - 1) {
		pageName = pageName + "default.aspx"; /****************** SET TO DEFAULT DOC NAME */
	}

	while (pageName.indexOf("/") == 0) {
		pageName = pageName.substr(1,pageName.length);
	}

	return(pageName); 
} 


/*
 * 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, categoryName) {
	var cm = new _cm("tid", "5", "vn2", "e3.1");

	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;
	}

	cm.pr = productID;
	cm.pm = productName;
	cm.cg = categoryID;
	cm.cl = categoryName;

	cm.pc = "Y";
	cm.pi = "PRODUCT: " + productName + " (" + productID + ")";

	cm.writeImg();
}

/*
 * Creates a Registration tag and/or a Newsletter tag
 *
 * customerID		: required for Registration. ID of Customer to register.
 * customerEmail	: required for Newsletters. Optional for Registration.
 * customerCity		: optional. City of Customer that placed this order
 * customerState	: optional. State of Customer that placed this order
 * customerZIP		: optional. Zipcode of Customer that placed this order
 * newsletterName	: required for Newsletters. The name of the Newsletter.
 * subscribe		: required for Newsletters. Either "Y" or "N"
 *
 * returns nothing, causes a document.write of an image request for this tag.
 */
function cmCreateRegistrationTag(customerID, customerEmail, customerCity,
				customerState, customerZIP, newsletterName, 
				subscribe) {
	var cm = new _cm("tid", "2", "vn2", "e3.1");
	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.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 cmShopSKUs = new Array();
var cmShopCounter = 0;
var cmShopOrderIds = new Array();
var cmShopCustomerIds = new Array();
var cmShopOrderPrices = new Array();

/* Internal, to support aggregation */
function cmGetProductIndex(id){
	var i =0;
	for (i=0; i<cmshopcounter; i++)="" {="" if="" (id="=cmShopIds[i])" {="" return="" i;="" }="" }="" return="" -1;="" }="" *="" creates="" a="" shop="" tag="" with="" action="" 5="" (shopping="" cart)="" *="" *="" productid="" :="" required.="" product="" id="" to="" set="" on="" this="" shop="" tag="" *="" quantity="" :="" required.="" quantity="" to="" set="" on="" this="" shop="" tag="" *="" productprice="" :="" required.="" price="" of="" one="" unit="" of="" this="" product="" *="" categoryid="" :="" optional.="" category="" to="" set="" on="" this="" shop="" tag="" *="" *="" returns="" nothing,="" causes="" a="" document.write="" of="" an="" image="" request="" for="" this="" tag.="" */="" function="" cmcreateshopaction5tag(productid,="" productname,="" productquantity,="" productprice,="" categoryid)="" {="" 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++;="" }="" }="" render="" the="" aggregated="" cart="" lineitems="" with="" shop="" 5="" tags*/="" function="" cmdisplayshop5s(){="" var="" i;="" for(i="0;"></cmshopcounter;><cmshopcounter;i++){ var="" cm="new" _cm("tid",="" "4",="" "vn2",="" "e3.1");="" cm.at="5" ;="" cm.pr="cmShopIds[i];" cm.pm="cmShopProducts[i];" cm.cg="cmShopCats[i];" cm.cl="cmShopCats[i];" cm.qt="cmShopQtys[i]" ;="" cm.bp="cmShopPrices[i];" cm.pc="N" ;="" cm.writeimg();="" }="" cmshopcounter="0;" }="" *="" creates="" a="" shop="" tag="" with="" action="" 9="" (order="" receipt="" confirmed)="" *="" *="" productid="" :="" required.="" product="" id="" to="" set="" on="" this="" shop="" tag="" *="" productname="" :="" required.="" product="" name="" to="" set="" on="" this="" shop="" tag="" *="" quantity="" :="" required.="" quantity="" to="" set="" on="" this="" shop="" tag="" *="" productprice="" :="" required.="" price="" of="" one="" unit="" of="" this="" product="" *="" customerid="" :="" required.="" id="" of="" customer="" making="" the="" purchase="" *="" orderid="" :="" required.="" id="" of="" order="" this="" lineitem="" belongs="" to="" *="" ordertotal="" :="" required.="" total="" price="" of="" order="" this="" lineitem="" belongs="" to="" *="" categoryid="" :="" optional.="" category="" to="" set="" on="" this="" shop="" tag="" *="" *="" returns="" nothing,="" causes="" a="" document.write="" of="" an="" image="" request="" for="" this="" tag.="" */="" function="" cmcreateshopaction9tag(productid,="" productname,="" productquantity,="" productprice,="" customerid,="" orderid,="" ordertotal,="" categoryid)="" {="" 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;" cmshopskus[index]="|" +="" productid="" +="" "|"="" +="" newprice="" +="" "|"="" +="" 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);" cmshopskus[cmshopcounter]="|" +="" productid="" +="" "|"="" +="" productprice="" +="" "|"="" +="" productquantity="" +="" "|";="" cmshopcounter++;="" }="" }="" render="" the="" aggregated="" order="" lineitems="" with="" shop="" 9="" tags*/="" function="" cmdisplayshop9s(){="" var="" i;="" for(i="0;"></cmshopcounter;i++){><cmshopcounter;i++){ var="" cm="new" _cm("tid",="" "4",="" "vn2",="" "e3.1");="" cm.at="9" ;="" cm.pr="cmShopIds[i];" cm.pm="cmShopProducts[i];" cm.cg="cmShopCats[i];" cm.cl="cmShopCats[i];" cm.qt="cmShopQtys[i]" ;="" cm.bp="cmShopPrices[i];" cm.cd="cmShopCustomerIds[i];" cm.on="cmShopOrderIds[i];" cm.tr="cmShopOrderPrices[i];" cm.pc="N" ;="" cm.writeimg();="" }="" cmshopcounter="0;" }="" *="" creates="" an="" order="" tag="" *="" *="" orderid="" :="" required.="" order="" id="" of="" this="" order="" *="" ordertotal="" :="" required.="" total="" of="" this="" order="" (minus="" tax="" and="" shipping)="" *="" ordershipping="" :="" required.="" shipping="" charge="" for="" this="" order="" *="" customerid="" :="" required.="" customer="" id="" that="" placed="" this="" order="" *="" customercity="" :="" optional.="" city="" of="" customer="" that="" placed="" this="" order="" *="" customerstate="" :="" optional.="" state="" of="" customer="" that="" placed="" this="" order="" *="" customerzip="" :="" optional.="" zipcode="" of="" customer="" that="" placed="" this="" order="" *="" *="" returns="" nothing,="" causes="" a="" document.write="" of="" an="" image="" request="" for="" this="" tag.="" */="" function="" cmcreateordertag(orderid,="" ordertotal,="" ordershipping,="" customerid,="" customercity,="" customerstate,="" customerzip)="" {="" if="" (orderid="" &&="" ordertotal="" &&="" ordershipping="" &&="" customerid)="" {="" var="" cm="new" _cm("tid",="" "3",="" "vn2",="" "e3.1");="" cm.on="orderID;" cm.tr="orderTotal;" cm.osk="getOSK();" cm.sg="orderShipping;" cm.cd="customerID;" cm.sa="customerState;" cm.ct="customerCity;" cm.zp="customerZIP;" cm.writeimg();="" }="" }="" function="" getosk()="" {="" var="" i="0;" var="" result="" ;="" for="" (i="0;"></cmshopcounter;i++){><cmshopcounter; i++)="" {="" result="" +="cmShopSKUs[i];" }="" return="" result;="" }="" creates="" an="" error="" tag="" *="" *="" returns="" nothing,="" causes="" a="" document.write="" of="" an="" image="" request="" for="" this="" tag.="" */="" function="" cmcreateerrortag()="" {="" 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" ;="" cm.pi="getDefaultPageID();" cm.writeimg();="" }="" helper="" functions="" -----------------------------------------------------------="" these="" functions="" are="" used="" by="" the="" tag-generating="" functions="" and/or="" may="" be="" used="" *="" in="" in="" general="" as="" convenience="" functions="" */="" *="" creates="" an="" acceptable="" default="" page="" id="" value="" to="" use="" for="" pageview="" tags.="" *="" the="" default="" page="" id="" is="" based="" on="" the="" url,="" and="" consists="" of="" the="" path="" and="" *="" filename="" (without="" the="" protocol,="" domain="" and="" query="" string).="" *="" *="" example:="" *="" returns="" "x/y/mypage.asp"="" for="" the="" url="" http://www.mysite.com/x/y/mypage.asp="" */="" function="" getdefaultpageid()="" {="" var="" pagename="window.location.pathname;" eliminates="" everything="" after="" "?"="" (for="" opera="" browswers)="" var="" tempindex1='pageName.indexOf("?");' if="" (tempindex1="" !="-1)" {="" pagename="pageName.substr(0," tempindex1);="" }="" eliminates="" everything="" after="" "#"="" (for="" opera="" browswers)="" var="" tempindex2='pageName.indexOf("#");' if="" (tempindex2="" !="-1)" {="" pagename="pageName.substr(0," tempindex2);="" }="" eliminates="" everything="" after="" ";"="" var="" tempindex3='pageName.indexOf(";");' if="" (tempindex3="" !="-1)" {="" pagename="pageName.substr(0," tempindex3);="" }="" var="" slashpos='pageName.lastIndexOf("/");' if="" (slashpos="=" pagename.length="" -="" 1)="" {="" pagename="pageName" +="" "default.asp";="" *****************="" set="" to="" default="" doc="" name="" */="" }="" while="" (pagename.indexof("/")="=" 0)="" {="" pagename="pageName.substr(1,pageName.length);" }="" return(pagename);="" }="" helper="" functions="" -----------------------------------------------------------="" these="" functions="" are="" used="" by="" the="" tag-generating="" functions="" and/or="" may="" be="" used="" *="" in="" in="" general="" as="" convenience="" functions="" */="" *="" checks="" to="" see="" if="" a="" parameter="" exists="" in="" the="" request="" search="" string.="" *="" returns="" -1="" if="" not="" found="" or="" the="" index="" of="" the="" first="" character="" of="" the="" *="" name="" in="" the="" name-value="" pair="" if="" found.="" */="" function="" cmindexofparameter="" (parameter)="" {="" return="" document.url.indexof(parameter);="" }="" *="" extracts="" the="" value="" of="" a="" name-value="" pair="" in="" the="" request="" search="" string.="" */="" function="" cmextractparameter="" (parameter)="" {="" if="" (cmindexofparameter(parameter)="=" -1)="" {="" return="" "";="" }="" var="" s="location.search;" var="" begin="s.indexOf(parameter);" var="" end='s.indexOf("&",' begin);="" if="" (end="=" -1)="" {="" end="s.length;" }="" var="" middle='s.indexOf("=",' begin);="" return="" s.substring(middle="" +="" 1,="" end);="" }="" new="" tags="" for="" onclick="" start="" here="" -="" tauno="" 09.04.2004="" *="" 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="" ---------------------------------------------------="" function="" cmgetpageviewtagsrc(pageid,="" categoryid){="" if="" (pageid)="" {="" var="" cm="new" _cm("tid",="" "1",="" "vn2",="" "e3.1");="" cm.pi="pageID;" if="" (categoryid)="" {="" cm.cg="categoryID;" }="" cm.rf="window.location.href;" return="" cm.getimgsrc();="" }="" else="" {="" return="" "";="" }="" }="" *="" this="" function="" serves="" as="" an="" onclick="" handler="" for="" external="" links="" */="" function="" cmpageviewonclick(pageid,="" categoryid)="" {="" var="" imgrequest="new" image();="" load="" the="" image="" getting="" tag="" src,="" passing="" pageid,="" ul="" and="" rf="" var="" tsrc="cmGetPageViewTagSrc(pageID," categoryid);="" imgrequest.src="tsrc;" return="" true;="" }="" dynamicaly="" register="" custom="" events="" to="" event="" dispatchers="" function="" addevent(fname,="" eventhandle)="" {="" if(eventhandle){="" var="" event="eventHandle.toString();" if(event.indexof(fname)="=" -1)="" {="" fname='fName+";"+event.substring(event.indexOf("{"),event.length);' newfunc="new" function(fname);="" return="" newfunc;="" }="" else="" {="" return="" eventhandle;="" }="" }="" else="" {="" return="" new="" function(fname);="" }="" }="" auto-attach="" onclick="" handler="" to="" links="" with="" particular="" extensions.="" this="" version="" preserves="" pre-existing="" onclick="" handlers.="" this="" functoin="" should="" be="" called="" in="" the="" body="" onload="" event="" handler.="" function="" cmsetlinksonclick()="" {="" var="" doc="window.document;" for="" (var="" i="0;" i=""></cmshopcounter;>< doc.links.length;i++)="" {="" var="" lnk="doc.links[i];" var="" filetype="lnk.pathname.substr(lnk.pathname.length-3,3);" if="" ((filetype="=" "exe")="" ||="" (filetype="=" "zip"))="" {="" lnk.onclick='addEvent("cmPageviewOnClick('DOWNLOAD:' "="" +="" lnk.pathname="" +="" "');",lnk.onclick);="" }="" }="" }="" new="" tags="" for="" onclick="" end="" here="" -="" tauno="" 09.04.2004*/="" --="">
</product></product>