<!--
/*
 * cmdatatagutils.js
 *
 * Coremetrics Tag v4.0, 4/18/2004
 * COPYRIGHT 1999-2002 COREMETRICS, INC. 
 * ALL RIGHTS RESERVED. U.S.PATENT PENDING
 *
 * The following functions aid in the creation of Coremetrics data tags.
 *
 *	032608		MOCHOA		Initial Library files (identical to 90120405 & 90120268)
 *							First Party Client Managed enabled
 * 07/03/08         Leslie Hibbard  Added Explore attributes
 * 08/05/08         Leslie Hibbard  Added sessionID to tech props and page view
 * 07/07/09	WBIRD	AdTarget provisioned
 */

// TAG GENERATING FUNCTIONS ---------------------------------------------------

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";

/*
 * Set client specific variables
 */
var cm_ClientID="90216731";
var cm_TrackImpressions="RS";   /* R=RealEstate, S=SitePromotions */
var cm_TrackLink="A";
var cm_JSFEnabled = true;
var cm_Production_HOST = "data.coremetrics.com";
var cm_PartnerDataClientIDs = "90216731";

cmLoad();

/*
 * Calling this function points tags to the production database
 */
function cmSetProduction(){
	cm_HOST = cm_Production_HOST + "/cm?";
	cm_JSFPCookieDomain = "mexico.com";
}

function cmCreatePageElementTag(elementID, elementCategory,attributes) {
	var cm=new _cm("tid", "15", "vn2", "e4.0");
	
	cm.eid=elementID;
	cm.ecat=elementCategory;
	cm.pflg=0;
	if (attributes){
		var Attr=attributes.split("-_-");
		var Attval;
		for (i=0;i<Attr.length;i++){
			Attval="c_a"+(i+1);
			cm[Attval]=Attr[i];
		}
	}
	cm.writeImg();
}

function cmCreateConversionEventTag(eventID, actionType, categoryID, points, attributes) {
	var cm = new _cm("tid", "14", "vn2", "e4.0");
	cm.cid = eventID;
	cm.cat = actionType;
	cm.ccid = categoryID;
	cm.cpt = points;
	if (attributes){
		var Attr=attributes.split("-_-");
		var Attval;
		for (i=0;i<Attr.length;i++){
			Attval="c_a"+(i+1);
			cm[Attval]=Attr[i];
		}
	}
	cm.writeImg();
 }
 
/*
 * Creates a Tech Props tag.
 * pageID		: required. Page ID to set on this Pageview tag
 */
function cmCreateTechPropsTag(pageID, categoryID,visitorSessionID,attributes) {
	
	if(pageID == null) {
		pageID = cmGetDefaultPageID();
	}

	var cm=new _cm("tid", "6", "vn2", "e4.0");
	cm.pc="Y";

	languagePrefix = cmCheckLanguage();
	cm.pi = languagePrefix + pageID;
	cm.cg = languagePrefix + 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 = cm.ul;
		parent.cm_set_mmc = false;
	}
	if (visitorSessionID){
		cmStartTagSet();
		cmCreateConversionEventTag(visitorSessionID, "2", "Client Session ID", "50")
	}
	if (attributes){
		var Attr=attributes.split("-_-");
		var Attval;
		for (i=0;i<Attr.length;i++){
			Attval="pv_a"+(i+1);
			cm[Attval]=Attr[i];
		}
	}
	cm.addTP();
	cmCheckCMLM();
	document.cookie = "cmTPSet=Y; path=/";
	cm.writeImg();
	if (visitorSessionID){
	cmSendTagSet();
	}
}
/*
 * 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, searchString, searchResults, sortType, searchCheckindate, searchNights, 
	searchRooms, searchChildren, searchAdults, searchHotel, searchRating, searchHotelResults,visitorSessionID,attributes) {

	if (pageID == null) {
		pageID = cmGetDefaultPageID();
	}
    var cm = new _cm("tid", "1", "vn2", "e4.0");   

	if (attributes){
        var exAttr=sortType+"-_-"+ searchCheckindate+"-_-"+ searchNights+"-_-"+ searchRooms+"-_-"+ searchChildren+"-_-"+ searchAdults+"-_-"+ searchHotel+"-_-"+ searchRating+"-_-"+ searchHotelResults+"-_-"+ attributes
    } else {
        var exAttr=sortType+"-_-"+ searchCheckindate+"-_-"+ searchNights+"-_-"+ searchRooms+"-_-"+ searchChildren+"-_-"+ searchAdults+"-_-"+ searchHotel+"-_-"+ searchRating+"-_-"
 	}	
    var Attr=exAttr.split("-_-");
	var Attval;
	for (i=0;i<Attr.length;i++){
		Attval="pv_a"+(i+1);
		cm[Attval]=Attr[i];
	}	
	cmStartTagSet();
	
	if (cI("cmTPSet") != 'Y') {
		cm.tid = "6";
		cm.pc = "Y";
		cm.addTP();
		if (visitorSessionID){
			cmCreateConversionEventTag(visitorSessionID, "2", "Client Session ID", "50")
		}
		document.cookie = "cmTPSet=Y; path=/";
	}
	
	if (searchHotelResults)	{								// Handles up to 26 "|" delimited hotel results
		resultsArray = searchHotelResults.split("|");
		var resultsArray1 = new Array();
		for(var i=0; i<13; i++) {
			resultsArray1[i] = resultsArray[i];
		}
		cmCustomHotelResults(pageID, categoryID, resultsArray1);
		if (resultsArray.length > 13) {							
			for(var i=13; i<26; i++) {
				var j = i - 13;
				resultsArray1[j] = resultsArray[i];
			}
			cmCustomHotelResults(pageID, categoryID, resultsArray1);
		}
	}

	

	languagePrefix = cmCheckLanguage();
	cm.pi = languagePrefix + pageID;
	cm.cg = languagePrefix + categoryID;

	if (searchString) {
		cm.se = searchString;
	}
	cm.sr = searchResults;

	// 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.pv1 = sortType;
	cm.pv2 = searchCheckindate;
	cm.pv3 = searchNights;
	cm.pv4 = searchRooms;
	cm.pv5 = searchChildren;
	cm.pv6 = searchAdults;
	cm.pv7 = searchHotel;
	cm.pv8 = searchRating;

	cm.pv_a1 = sortType;
	cm.pv_a2 = searchCheckindate;
	cm.pv_a3 = searchNights;
	cm.pv_a4 = searchRooms;
	cm.pv_a5 = searchChildren;
	cm.pv_a6 = searchAdults;
	cm.pv_a7 = searchHotel;
	cm.pv_a8 = searchRating;

	cmCheckCMLM();
	cm.writeImg();
	cmSendTagSet();
	
}
/*
 * 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, venue,attributes) {
	var cm = new _cm("tid", "5", "vn2", "e4.0");

    if (attributes){
		var Attr=attributes.split("-_-");
		var Attval;
		for (i=0;i<Attr.length;i++){
			Attval="pr_a"+(i+1);
			cm[Attval]=Attr[i];
		}
	}

	// 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.ps1 = productID;
	cm.pm = productName;

	languagePrefix = cmCheckLanguage();
	cm.cg = languagePrefix + categoryID;
	cm.ps2 = languagePrefix + categoryID;
	cm.pi = languagePrefix + "PRODUCT: " + productName + " (" + productID + ")";
	
	cm.ps3 = venue;
	cm.li  = "25";
	cm.pc = "Y";
	cmCheckCMLM();
	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 cmAttributes=new Array();
var cmShopType = new Array();
var	cmSKUlink = new Array();
var cmShopSKUs = "";

/* Internal, to support aggregation */
function cmGetProductIndex(id,convAttr){
	if (convAttr){
		var Attr=convAttr.split("-_-").toString();
	}
	var cmAttr;
	var i =0;
	for (i=0; i<cmShopCounter; i++)
	{
		if (cmAttributes[i]){cmAttr=cmAttributes[i].split("-_-").toString();}
		if (id==cmShopIds[i] && Attr==cmAttr)
		{
			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.
 */

var custom_shopLink = (dt.getTime()%10000000) + (Math.floor(Math.random()*10000));

function cmCreateShopAction5Tag(productID, productName, productQuantity, productPrice, categoryID, shopType, SKU, venue, convAttr) {

	productID = productID.toUpperCase();
    	
	
	if (SKU || venue)	{					// write SKU & venue custom tag, per shop	
		var cm = new _cm("tid", "7", "vn2", "e4.0");
		var exAttr = new Array;
		cm.li = "40";
		languagePrefix = cmCheckLanguage();
		cm.pm = productName;
		cm.ps1 = custom_shopLink;			// link to specific shop5
		cm.ps2 = "5";						// shop type
		cm.ps3 = productQuantity;		
		cm.ps4 = productID;	
		cm.ps5 = languagePrefix + categoryID;	
		if (SKU) {
			cm.ps6 = SKU;
		}
		if (venue) {
			cm.ps7 = venue;
		}
		cm.writeImg();
	}
    if (convAttr){
			var exAttr=SKU+"-_-"+ convAttr
    	} else {
        	var exAttr=SKU	    
 		}	
	var index = cmGetProductIndex(productID,exAttr);
	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 = "";
		}

		cmShopType[cmShopCounter] = shopType;
		if (SKU || venue) {
			cmSKUlink[cmShopCounter] = custom_shopLink;		// link the shop to the custom SKU record
		}
		cmShopProducts[cmShopCounter] = productName;
		cmShopIds[cmShopCounter] = productID;
		cmShopCats[cmShopCounter] = categoryID;
		cmShopQtys[cmShopCounter] = parseInt(productQuantity);
		cmShopPrices[cmShopCounter] = parseFloat(productPrice);
		cmAttributes[cmShopCounter]=exAttr;
		cmShopCounter++;

	}

	cmShopSKUs = cmGetOSK();

}

/* render the aggregated cart lineitems with Shop 5 tags*/
function cmDisplayShop5s(){
	languagePrefix = cmCheckLanguage();
	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 = languagePrefix + cmShopCats[i];
		cm.qt = cmShopQtys[i];
		cm.bp = cmShopPrices[i];
		cm.sx1 = cmShopType[i];
		cm.sx2 = cmSKUlink[i];				// link the shop to the custom SKU records
		if (cmAttributes[i]){
		var Attr=cmAttributes[i].split("-_-");
			var Attval;
		for (k=0;k<Attr.length;k++){
				Attval="s_a"+(k+1);
			cm[Attval]=Attr[k];
			}
		}
		cm.sn=(i+1).toString();		
		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, shopType, SKU, venue, convAttr) {

	productID = productID.toUpperCase();

	if (SKU || venue)	{					// write SKU & venue custom tag, per shop		
		var cm = new _cm("tid", "7", "vn2", "e4.0");
		cm.li = "40";
		languagePrefix = cmCheckLanguage();
		cm.pm = productName;
		cm.ps1 = custom_shopLink;			// link to specific shop5
		cm.ps2 = "9";						// shop type
		cm.ps3 = productQuantity;		
		cm.ps4 = productID;	
		cm.ps5 = languagePrefix + categoryID;	
		if (SKU) {
			cm.ps6 = SKU;
		}
		if (venue) {
			cm.ps7 = venue;
		}
		cm.writeImg();
	}
	if (convAttr){
			var exAttr=SKU+"-_-"+ convAttr
   	} else {
       	var exAttr=SKU	    
 	}	
	var index = cmGetProductIndex(productID,exAttr);
	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 = "";
		}

		cmShopType[cmShopCounter] = shopType;
		if (SKU || venue) {
			cmSKUlink[cmShopCounter] = custom_shopLink;		// link the shop to the custom SKU record
		}
		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;
		cmAttributes[cmShopCounter]=exAttr;
		cmShopCounter++;
	}
	cmShopSKUs = cmGetOSK();
}

/* render the aggregated order lineitems with Shop 9 tags*/
function cmDisplayShop9s(){
	languagePrefix = cmCheckLanguage();
	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 = languagePrefix + cmShopCats[i];
		cm.qt = cmShopQtys[i] ;
		cm.bp = cmShopPrices[i];
		cm.cd = cmShopCustomerIds[i];
		cm.on = cmShopOrderIds[i];
		cm.tr = cmShopOrderPrices[i];

		cm.sx1 = cmShopType[i];
		cm.sx2 = cmSKUlink[i];				// link the shop to the custom SKU records
		if (cmAttributes[i]){
		var Attr=cmAttributes[i].split("-_-");
			var Attval;
		for (k=0;k<Attr.length;k++){
				Attval="s_a"+(k+1);
			cm[Attval]=Attr[k];
			}
		}
		cm.sn=(i+1).toString();	
		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, convCharge, attributes) {
		
		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.or3 = convCharge;		// convenience or other non-shipping charges
		if (attributes){
			var Attr=attributes.split("-_-");
			var Attval;
			for (i=0;i<Attr.length;i++){
				Attval="o_a"+(i+1);
				cm[Attval]=Attr[i];
			}
		}
		cm.writeImg();
}

function cmGetOSK() {
	var i =0;
	var result = "";
	for (i=0; i<cmShopCounter; i++)
	{
		result += "|" + cmShopIds[i] + "|" + cmShopPrices[i] + "|" + cmShopQtys[i] + "|";
	}
	return result;
}


function cmCreateHotelViewTag(propertyCode, propertyName, categoryID, hotelBrand, siteBrand, siteCountry, language, ZIP, city, state, country, rating) {
	var cm = new _cm("tid", "5", "vn2", "e4.0");
	cm.li  = "2";
	cm.pr = propertyCode;
	cm.pm = propertyName;
	cm.ps1 = propertyCode;
	cm.ps2 = propertyName;
	cm.ps3 = hotelBrand;
	cm.ps4 = siteBrand;
	cm.ps5 = language;
	cm.ps6 = siteCountry;
	cm.ps7 = ZIP;
	cm.ps8 = city;
	cm.ps9 = state;
	cm.ps10 = country;
	cm.ps11 = rating;
	cm.pc = "Y";

	languagePrefix = cmCheckLanguage();
	cm.ps12 = languagePrefix + categoryID;
	cm.cg = languagePrefix + categoryID;
	cm.pi = languagePrefix + "HOTEL VIEW: " + propertyName + "(" + propertyCode + ")"; 

	cm.writeImg();
}

function cmCreateHotelSelectionTag(propertyCode, propertyName, hotelBrand, categoryID, siteBrand, siteCountry, language, ZIP, city, state, country, roomNights, adultRoomNights, childrenRoomNights, unitPrice, rateType, roomCode, reservationStartDate, numRooms, lowAvgRate, avgNightRate, rating, childAges) {
	var cm = new _cm("tid", "4", "vn2", "e4.0");
	
	cm.at = "5";
	cm.pr = propertyCode; 
	cm.pm = propertyName;
	cm.ps1 = propertyCode;
	cm.ps2 = propertyName;
	cm.sx1 = hotelBrand;
	cm.sx2 = siteBrand + "|" + siteCountry;
	cm.sx3 = language;
	cm.sx4 = ZIP;
	cm.sx5 = city;
	cm.sx6 = state;
	cm.sx7 = country;
	cm.qt = roomNights;
	cm.sx8 = adultRoomNights;
	cm.sx9 = childrenRoomNights;
	cm.bp = unitPrice;
	cm.sx10 = rateType;
	cm.sx11 = roomCode;
	cm.sx14 = reservationStartDate;
	cm.sx15 = numRooms;
	cm.pc = "N";
	cm.li = "10";
	cm.ps3 = lowAvgRate;
	cm.ps4 = avgNightRate;
	cm.ps5 = rating;
	cm.ps6 = childAges;

	languagePrefix = cmCheckLanguage();
	cm.ps7 = languagePrefix + categoryID;
	cm.cg = languagePrefix + categoryID;
	
	cm.writeImg();
}

function cmCreateHotelBookingTag(propertyCode, propertyName, hotelBrand, categoryID, siteBrand, siteCountry, language, ZIP, city, state, country, roomNights, adultRoomNights, childrenRoomNights, unitPrice, rateType, roomCode, travelType, bookingConfirmationNumber, bookingTotal, tax, usedCreditBypass, customerID, userEmail, userCity, userState, userCountry, userZIP, newsletterName, subscribe, userPhone, signinQuestion, reservationStartDate, numRooms, cancellationWaiver, paymentType) {
	var cm = new _cm("tid", "4", "vn2", "e4.0");
	
	cm.at = "9";
	cm.pr = propertyCode; 
	cm.pm = propertyName;
	cm.sx1 = hotelBrand;
	cm.sx2 = siteBrand + "|" + siteCountry;
	cm.sx3 = language;
	cm.sx4 = ZIP;
	cm.sx5 = city;
	cm.sx6 = state;
	cm.sx7 = country;
	cm.qt = roomNights;
	cm.sx8 = adultRoomNights;
	cm.sx9 = childrenRoomNights;
	cm.bp = unitPrice;
	cm.sx10 = rateType;
	cm.sx11 = roomCode;
	cm.on = bookingConfirmationNumber;
	cm.tr = bookingTotal;
	cm.sg = tax;
	cm.sx12 = usedCreditBypass;
	cm.cd = customerID;
	cm.sx14 = reservationStartDate;
	cm.sx15 = numRooms + "|" + travelType;
	
	languagePrefix = cmCheckLanguage();
	cm.cg = languagePrefix + categoryID;
	
	cm.pc = "N";
	cm.writeImg();

	var cm = new _cm("tid", "3", "vn2", "e4.0");
	cm.on = bookingConfirmationNumber;
	cm.tr = bookingTotal;
	cm.osk = "|" + propertyCode + "|" + unitPrice + "|" + roomNights + "|";
	cm.sg = tax;
	cm.cd = customerID;
	cm.sa = userState;
	cm.ct = userCity;
	cm.zp = userZIP;
	cm.or1 = travelType;
	cm.or2 = cancellationWaiver;
	cm.writeImg();
	
	var cm = new _cm("tid", "2", "vn2", "e4.0");
	cm.cd = customerID;
	cm.em = userEmail;
	cm.sa = userState;
	cm.ct = userCity;
	cm.zp = userZIP;
	if (newsletterName && subscribe) {
		cm.nl = newsletterName;
		cm.sd = subscribe;
	}
	cm.cy = userCountry;
	cm.rg11 = userPhone;
	cm.rg12 = signinQuestion;
	cm.rg13 = paymentType;

	cm.writeImg();
}

function cmCreateCartHotelBookingTag(propertyCode, propertyName, hotelBrand, categoryID, siteBrand, siteCountry, language, ZIP, city, state, country, 
	roomNights, adultRoomNights, childrenRoomNights, unitPrice, rateType, roomCode, travelType, bookingConfirmationNumber, bookingTotal, tax, usedCreditBypass, 
	customerID, reservationStartDate, numRooms) {
	var cm = new _cm("tid", "4", "vn2", "e4.0");
	
	cm.at = "9";
	cm.pr = propertyCode; 
	cm.pm = propertyName;
	cm.sx1 = hotelBrand;
	cm.sx2 = siteBrand + "|" + siteCountry;
	cm.sx3 = language;
	cm.sx4 = ZIP;
	cm.sx5 = city;
	cm.sx6 = state;
	cm.sx7 = country;
	cm.qt = roomNights;
	cm.sx8 = adultRoomNights;
	cm.sx9 = childrenRoomNights;
	cm.bp = unitPrice;
	cm.sx10 = rateType;
	cm.sx11 = roomCode;
	cm.on = bookingConfirmationNumber;
	cm.tr = bookingTotal;
	cm.sg = tax;
	cm.sx12 = usedCreditBypass;
	cm.cd = customerID;
	cm.sx14 = reservationStartDate;
	cm.sx15 = numRooms + "|" + travelType;
	
	languagePrefix = cmCheckLanguage();
	cm.cg = languagePrefix + categoryID;
	
	cm.pc = "N";

	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, userCountry, userPhone, signinQuestion, paymentType) {
	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.cy = userCountry;
	cm.rg11 = userPhone;
	cm.rg12 = signinQuestion;
	cm.rg13 = paymentType;

	cm.writeImg();
}

/* Creates an Error Tag
 *
 * returns nothing, causes a document.write of an image request for this tag.
 */
function cmCreateErrorTag(pageID, categoryID, attributes) {
	var cm=new _cm("tid", "404", "vn2", "e4.0");  //DO NOT CHANGE THESE PARAMETERS
	
	if (attributes){
			var Attr=attributes.split("-_-");
			var Attval;
			for (i=0;i<Attr.length;i++){
				Attval="pv_a"+(i+1);
				cm[Attval]=Attr[i];
			}
		}
	
	// 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;
	}
	languagePrefix = cmCheckLanguage();
	cm.pi = languagePrefix + pageID;
	cm.cg = languagePrefix + categoryID;

	cmCheckCMLM();
	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) {
			var blackList = [";jsessionid=","Values=","RawValues=","nameDD=","ratingDD="];
			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].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;
    }
}
function cmIndexOfParameter (parameter) {
	return document.URL.indexOf(parameter);
}
function cmCheckCMLM() {
	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];
		}

		cmCreateRegistrationTag(emailAddress,emailAddress);
	}
}
function cmCreateManualLinkClickTag(href, linkName) {  
            if (cmHandleLinkClick == null && C9 != null) {var cmHandleLinkClick = C9;}  
            if (cmHandleLinkClick != null) {  
                        var link = new Object();  
                        link.tagName = "A";  
                        link.name = linkName;  
                        link.href = href;  
                        cmHandleLinkClick(link);  
            }
		}
function cmCreateImpressionTag(pageID, trackSP, trackRE) {
		var cm = new _cm("tid","9","vn2","4.0");
		languagePrefix = cmCheckLanguage();
		cm.pi = languagePrefix + pageID;
		if (trackSP){
			cm.cm_sp = trackSP;
		}
		if (trackRE){
			cm.cm_re = trackRE;
		}		
		cm.st = cm_ClientTS;
        cm.writeImg();
}
function cmCheckLanguage() {
	if ((cmIndexOfParameter("espanol.") != -1) || (cmIndexOfParameter("lang=es") != -1)) {
		var languagePrefix = "es:";
		return(languagePrefix);
	} else {
		languagePrefix = "";
		return(languagePrefix);
	}
}
function cmCustomHotelResults(pageID, categoryID, results) {

	var cm = new _cm("tid", "7", "vn2", "e4.0");
	cm.li = "20";

	languagePrefix = cmCheckLanguage();
	cm.ps1 = languagePrefix + pageID;
	cm.ps2 = languagePrefix + categoryID;
	cm.ps3 = results[0];
	cm.ps4 = results[1];	
	cm.ps5 = results[2];	
	cm.ps6 = results[3];	
	cm.ps7 = results[4];	
	cm.ps8 = results[5];	
	cm.ps9 = results[6];	
	cm.ps10 = results[7];	
	cm.ps11 = results[8];	
	cm.ps12 = results[9];
	cm.ps13 = results[10];
	cm.ps14 = results[11];
	cm.ps15 = results[12];

	cm.writeImg();
}
//-->