/************************************************************************************/
/* $Revision: 1.19 $
 * $Id: cmtaggingservices.js,v 1.19 2009/06/11 18:31:02 wc55admin Exp $
 *
 * Author: Coremetrics/PSD 
 * Coremetrics  v2.0, 01/12/2009
 * COPYRIGHT 1999-2008 COREMETRICS, INC. 
 * ALL RIGHTS RESERVED. U.S.PATENT PENDING
 * Disclaimer: Coremetrics is not responsible for hosting or maintenance of this file
 *
 */
/************************************************************************************/
//Production data warehouse flag
cmSetProduction();
/*===========================GLOBAL VARIABLES ===============================*/
// current page url
var G_PS_PATHNAME = document.location.pathname.toLowerCase();
var G_PS_QUERYSTRING = document.location.search.toLowerCase();
var G_PS_URL_REFERRER = document.referrer.toLowerCase();
var G_PS_COOKIE_LIFETIME = 31536000; // 365*24*60*60 = 365 days
// cookie name
var G_PS_COOKIE_LAST_CATID = "PS_LAST_CATID";
var G_PS_COOKIE_CATID = "PS_CATID";
var G_PS_COOKIE_PROD_CATID = "PS_PROD_CATID";
var G_PS_COOKIE_PROD_NAME = "PS_PROD_NAME";
var G_PS_COOKIE_PROFILE = "PS_PROFILE";
var G_PS_COOKIE_FLAG = "PS_FLAG";		// used as a "session" variable to handle events between pages
// current category ID while browsing/searching/refining, etc
var G_PS_CUR_CATID = null;
// function pointers
var onsubmitAddToCartPtr = null;
var onsubmitSignInPtr = null;
var onsubmitRegisterPtr = null;
var onclickSearchPtr = null;
var onclickItemDetailPtr = null;
var onclickAddToCartPtr = null;

// options for debug mode when sending tag:
// 1: only alert
// 2: only send tag
// 3: alert & send tag
var G_PS_DEBUG_MODE = 2;
/*========================= END GLOBAL VARIABLES =============================*/

/*=========================== BEGIN NAVIGATION ===============================*/
if ((document.body != null) 
	&& (document.body.innerHTML.search(/We\'re sorry! We cannot find that page/gi)>=0
		|| document.body.innerHTML.search(/The page cannot be found/gi)>=0))
{
	var pageId = "";
	if (G_PS_PATHNAME.indexOf("/newsroom")>=0)
	{
		pageId = "Newsroom";
		G_PS_CUR_CATID = "AboutSwanson";		
	}
	else
	{
		pageId = "Page Not Found";
		G_PS_CUR_CATID = "Home";
	}
	// Throw error tag
	psCreateErrorTag(pageId, G_PS_CUR_CATID);
}
//
// product view 
else if (G_PS_PATHNAME.indexOf("itemdetail")>=0)
{
	//G_PS_CUR_CATID = "ProductDetail";
	//psPostProductView();
}
// shop5 view
else if (G_PS_PATHNAME.indexOf("shoppingbag")>=0)
{
	//G_PS_CUR_CATID = "ShoppingBag";
	//psPostCartView();
}
// check out pages (intermediate steps)
else if (G_PS_PATHNAME.search(/orderrecap/i)>=0)
{
	// only page views for checkout steps
	G_PS_CUR_CATID = "Checkout";
	psCreatePageviewTag(psGetPageId(), G_PS_CUR_CATID);
	// Hijack checkout button to resend shop5 tags
	var inputs = document.getElementsByTagName("input");
	for (var i = 0; i < inputs.length; i++)
	{
		if (inputs[i].src.search(/ContinueCheckout_Btn.gif/gi)>=0)
		{
			inputs[i].oldCMClick = inputs[i].onclick;
			inputs[i].onclick = function()
			{
				psPostCartView(); // Resend shop5 tags
				if (this.oldCMClick != null)
					return this.oldCMClick();
			}
			break;
		}
	}
}
// shop9 view
else if (G_PS_PATHNAME.search(/ThankYou/gi)>=0)
{
	//G_PS_CUR_CATID = "ThankYou";
	//psPostOrderView();
}
// login views
else if (G_PS_PATHNAME.search(/\/SignonForm/gi)>=0 || G_PS_PATHNAME.search(/\/loginForm/gi)>=0)
{
	G_PS_CUR_CATID = "LoginForm";
	psSubscribeSignInPages();
}
// profile views
else if (G_PS_PATHNAME == "/register")
{
	G_PS_CUR_CATID = "Register";
	psSubscribeProfilePages();
}
else if (G_PS_PATHNAME.indexOf("/registercheckout")>=0)
{
	G_PS_CUR_CATID = "Checkout Register";
	pageId = "Checkout Register";
	psSubscribeProfilePages();
}
else if (G_PS_PATHNAME.indexOf("/billingguest")>=0)
{
	G_PS_CUR_CATID = "Billing Guest";
	pageId = "Billing Guest";
	psSubscribeProfilePages();
}
else if (G_PS_PATHNAME == "/profile" || G_PS_PATHNAME == "/billinguser")
{
	G_PS_CUR_CATID = "Edit Profile";
	psSubscribeProfilePages();
}
// search views
else if (psGetCookie(G_PS_COOKIE_FLAG) == "P") // shop by product
{
	G_PS_CUR_CATID = "Shop By Product";
	psCreatePageviewTag("SEARCH:" + psGetValueFromUrl(G_PS_QUERYSTRING, "keyword"), G_PS_CUR_CATID);
	psSetCookie(G_PS_COOKIE_FLAG, "", "delete");
}
else if (psGetCookie(G_PS_COOKIE_FLAG) == "B") // shop by brand
{
	G_PS_CUR_CATID = "Shop By Brand";
	psCreatePageviewTag("SEARCH:" + psGetSearchTerm(), G_PS_CUR_CATID);
	psSetCookie(G_PS_COOKIE_FLAG, "", "delete");
}
else if (psGetCookie(G_PS_COOKIE_FLAG) == "S" 
	|| G_PS_QUERYSTRING.indexOf("&ntt")>=0
	|| G_PS_QUERYSTRING.indexOf("keyword")>=0) // standard search
{
	//G_PS_CUR_CATID = "Search";
	//psPostSearchView();
	//psSetCookie(G_PS_COOKIE_FLAG, "", "delete");
} 
// categories views
else if (G_PS_PATHNAME.indexOf("healthconcern")>=0)
{
	G_PS_CUR_CATID = "HealthConcern";
	psCreatePageviewTag(psGetPageId(), G_PS_CUR_CATID);
}
else if (G_PS_QUERYSTRING.indexOf("?n=")>=0
	|| G_PS_QUERYSTRING.indexOf("&n=")>=0) // Need to test all cases to find out a better identifier
{
	G_PS_CUR_CATID = psGetCatIdFromUrl();
	psCreatePageviewTag(psGetSearchTerm(), G_PS_CUR_CATID);
}
// other page views
else
{
	psPostPageView();
}
if (G_PS_CUR_CATID != null)
	psSetCookie(G_PS_COOKIE_LAST_CATID, psCleanCatId(G_PS_CUR_CATID)); // Back up
//
// check to send registration tags as user logged in or created/updateds ucessfully
// (use G_PS_COOKIE_FLAG cookie to track instead of referer URL)
psPostSignInView();
psPostUpdateProfileView();
//
// Hijack AddToCart buttons on current page if there is any button
psHijackAddToCartButtons();
// Hijack links to item detail on the current page if there are any
psHijackItemDetailLinks();
// Hijack "go", "shop by product", and "shop by brand" buttons
psHijackSearchButtons();
psHijackLinkLogout();
/*============================ END NAVIGATION ================================*/


/*===================== BEGIN TAGGING BUSSINESS LOGIC ========================*/
/*
 * Process to post page views
 */
function psPostPageView()
{
	var pageId = null;

	if (document.location.hostname.search(/swansonvitamins.blogs.com/gi)>=0)
	{
		G_PS_CUR_CATID = "Swansonvitamins Web Blogs";
		pageId = document.title;
	}
	else if (G_PS_PATHNAME.indexOf("/emailsignup" )>=0
		|| G_PS_PATHNAME.indexOf("/customerreviewguide")>=0
		|| G_PS_PATHNAME.indexOf("/shpnews_links")>=0
		|| G_PS_PATHNAME.indexOf("/askdrdesilva")>=0
		|| G_PS_PATHNAME.indexOf("/aquamin")>=0		
		|| G_PS_PATHNAME.indexOf("/vendor/p267")>=0
		)
	{
		G_PS_CUR_CATID = "HOME";
		pageId = psGetPageId();
	}
	else if (G_PS_PATHNAME.indexOf("/health-library") >= 0)
	{
		G_PS_CUR_CATID = "Health-Library";
		pageId = psGetPageId();
	}
	else if (G_PS_PATHNAME.indexOf("/offers") >= 0)
	{
		G_PS_CUR_CATID = "Offers Directory";
		pageId = psGetPageId();
	}	
	else if (G_PS_PATHNAME.indexOf("/shippingguest")>=0)
	{
		G_PS_CUR_CATID = "Shipping Guest";
		pageId = "Shipping Guest";
		
	}
	else if (G_PS_PATHNAME.indexOf("/billinguser")>=0)
	{
		G_PS_CUR_CATID = "Billing User";
		pageId = "Billing User";
	}
	else if (G_PS_PATHNAME.indexOf("/shippinguser")>=0)
	{
		G_PS_CUR_CATID = "Shipping User";
		pageId = "Shipping User";
	}
	else if (G_PS_PATHNAME.indexOf("/onsalenow")>=0)
	{
		G_PS_CUR_CATID = "OnSaleNow";
		pageId = "OnSaleNow";
	}
	else if (G_PS_PATHNAME.indexOf("/healtharticles")>=0
		|| (G_PS_PATHNAME.indexOf("askourexperts")>=0))
	{
		G_PS_CUR_CATID = "HealthArticles";
		pageId = "HealthArticles";
	}
	else if (G_PS_PATHNAME.indexOf("/aboutswanson")>=0
		|| G_PS_PATHNAME.indexOf("/shpaboutus_main")>=0
		)
	{
		G_PS_CUR_CATID = "AboutSwanson";
		pageId = "About Us";
	}
	else if (G_PS_PATHNAME.indexOf("/community")>=0)
	{
		G_PS_CUR_CATID = "AboutSwanson";
		pageId = "Community";
	}
	else if (G_PS_PATHNAME.indexOf("/newsroom")>=0)
	{
		G_PS_CUR_CATID = "AboutSwanson";
		pageId = "Newsroom";
	}
	else if (G_PS_PATHNAME.indexOf("/shp")>=0)
	{
		G_PS_CUR_CATID = "SHP";
		pageId = G_PS_PATHNAME.substr(G_PS_PATHNAME.lastIndexOf("/"));
		pageId = pageId.replace("/shp_", "").replace(".html", "").replace(".htm", "");
	}
	else if (G_PS_PATHNAME.indexOf("/vitaminsandsupplements")>=0
		|| G_PS_PATHNAME.indexOf("/spotlight")>=0)		
	{
		G_PS_CUR_CATID = "VitaminsAndSupplements";
		pageId = "VitaminsAndSupplements";
	}
	else if (G_PS_PATHNAME.indexOf("/brands")>=0)
	{
		G_PS_CUR_CATID = "Brands";
		pageId = "Brands";
	}
	else if (G_PS_PATHNAME.indexOf("/newproducts")>=0)
	{
		G_PS_CUR_CATID = "NewProducts";
		pageId = "NewProducts";
	}
	else if (G_PS_PATHNAME.indexOf("/favorites")>=0)
	{
		G_PS_CUR_CATID = "Favorites";
		pageId = "Favorites";
	}
	else if (G_PS_PATHNAME.indexOf("/quickbuy")>=0)
	{
		G_PS_CUR_CATID = "QuickBuy";
		pageId = "QuickBuy";
	}
	else if (G_PS_PATHNAME.indexOf("/help")>=0)
	{
		G_PS_CUR_CATID = "Help";
		pageId = "Help";
	}
	else if (G_PS_PATHNAME.search(/AskOurExperts/gi)>=0)
	{
		G_PS_CUR_CATID = "AskOurExperts";
		pageId = "AskOurExperts";
	}
	else if (G_PS_PATHNAME.search(/PromoCode/gi)>=0)
	{
		G_PS_CUR_CATID = "PromoCode";
		pageId = "PromoCode";
	}
	else if (G_PS_PATHNAME == "/html/shpshippinginfo1.html")
	{
		G_PS_CUR_CATID = "Shipping Standard";
		pageId = "Shipping Policies at Swansonvitamins.com";
	}
	else if (G_PS_PATHNAME == "/catalogrequest")
	{
		G_PS_CUR_CATID = "Catalog Request";
		pageId = psGetPageId();
	}
	else if (G_PS_PATHNAME.indexOf("/gs_7basic")>=0)
	{
		G_PS_CUR_CATID = "7 Basic Supplements for Good Health";
		pageId = psGetPageId();
	}
	else if (G_PS_PATHNAME.indexOf("/html/gs_")>=0)
	{
		G_PS_CUR_CATID = "Product Guides";
		pageId = psGetPageId();
	}
	else if (G_PS_PATHNAME.indexOf("/lnd/")>=0)
	{
		G_PS_CUR_CATID = "Product-Related Articles";
		pageId = psGetPageId();
	}
	else if (G_PS_PATHNAME.indexOf("/html/videoarchive.html")>=0)
	{
		G_PS_CUR_CATID = "HOME";
		pageId = psGetPageId();
	}
	else if (G_PS_PATHNAME.indexOf("/forgotpassword")>=0)
	{
		G_PS_CUR_CATID = "Forgot Password";
		pageId = "Forgot Password";
	}
	else if (G_PS_PATHNAME.indexOf("/outletmall")>=0)
	{
		G_PS_CUR_CATID = "OutletMall";
		pageId = "OutletMall";
	}
	else if (G_PS_PATHNAME.indexOf("/addressbook")>=0
		|| G_PS_PATHNAME.indexOf("viewcworderstatus")>=0
		|| G_PS_PATHNAME.indexOf("cworderstatuscheckcmd")>=0
		|| G_PS_PATHNAME.indexOf("/account")>=0
		|| G_PS_PATHNAME.indexOf("/orderstatusform")>=0
		|| G_PS_PATHNAME.indexOf("/orderhistory")>=0
		)
	{
		G_PS_CUR_CATID = "My Account";
		pageId = psGetPageId();
	}
	else if (G_PS_PATHNAME == "/payment")
	{
		G_PS_CUR_CATID = "Payment";
		pageId = "Payment";
	}
	else if (G_PS_PATHNAME.indexOf("/")>=0)
	{
		G_PS_CUR_CATID = "Home";
		pageId = "Home";
	}
	else
	{
		G_PS_CUR_CATID = null;
		pageId = null;
	}
	// post page view tag
	if (pageId != null)
		psCreatePageviewTag(pageId, G_PS_CUR_CATID);
}

/*
 * Process to post page views for search pages
 */
function psPostSearchView()
{
	var pageId, catId, searchTerm, searchResult;

	searchTerm = psGetSearchTerm();
	searchResult = psGetSearchResult();
	//
	// Generate pageId
	if (searchResult > 0)
	{
		pageId = "SEARCH SUCCESSFULL PAGE ";
		if (document.body.innerHTML.toUpperCase().indexOf("PAGE:") == -1)
			pageId += '1';
		else
		{
			// Extract current page number
			var str = document.body.innerHTML.toUpperCase().split("PAGE:")[1];
			str = str.split("</FONT>")[0];
			pageId += str.substr(str.lastIndexOf(">") + 1);
		}
	}
	else
		pageId = "SEARCH UNSUCCESSFULL";
	if (G_PS_PATHNAME.indexOf("referencesearch")>=0 || G_PS_PATHNAME.indexOf("healtharticles")>=0)
		catId = "REFERENCE SEARCH";
	else
		catId = "SEARCH";
	// Post page view for search result
	psCreatePageviewTag(pageId, catId, searchTerm, searchResult);
	
}

/*
 * Process to post productview tag for the item in product detail
 */
function psPostProductView()
{
	var prd = new psProduct();
	prd.getProduct();
	// Post product view tag
	psCreateProductviewTag(prd.id, prd.name, prd.catId);
}

/*
 * Process to post shop5tags for items in shopping cart
 */
function psPostCartView()
{
	// post pageviewtag for cart view
	psCreatePageviewTag(psGetPageId(), G_PS_CUR_CATID, null);

	var cartTbl = null;
	var tables = document.getElementsByTagName("table");
	if (G_PS_PATHNAME.search(/shoppingbag/i)>=0)
	{
		if (tables.length < 22) // Exception occured?
			return;
		cartTbl = tables[21];
	}
	else if (G_PS_PATHNAME.search(/OrderRecap/i)>=0)
	{
		if (tables.length < 24) // Exception occured?
			return;
		cartTbl = tables[23];		
	}
	else // exception
		return;

	var rows = cartTbl.rows; // use rows variable for optimization
	var prd = new psProduct();

	for (var r = 0; r < rows.length; r++) // item for each row
	{
		if ((rows[r].innerHTML.search(/\/itemdetail/i) < 0) || (rows[r].innerHTML.indexOf("FREE")>=0)) // Skip rows not containing item (identified by the term "/ItemDetail")
			continue;
		
		prd.getItem5(rows[r]);
		// post shop5tag
		psCreateShopAction5Tag(prd.id, prd.name, prd.quantity, prd.price, prd.catId);
		// remove item from temp cookie
		psSetValueToCookie(G_PS_COOKIE_CATID, prd.id, null);
	}
	// Make sure to have actual postings
	psDisplayShop5s();
}

/*
 * Process to post shop9tags for items purchased
 */
function psPostOrderView()
{
	// post pageviewtag for cart view
	cmCreatePageviewTag("ThankYou", G_PS_CUR_CATID, null);
	var tables = document.getElementsByTagName("table");
	if (tables.length < 13)
		return;
	
	var rows = tables[12].rows; // use rows variable for optimization
	var ord = new psOrder();
	var prd = new psProduct();

	ord.getOrder(); // Get order info from source code
	// Post Pageviewtag as cartview
	for (var r = 0; r < rows.length; r++) // item for each row
	{
		if ((rows[r].innerHTML.search(/receiptList/gi) >= 0) && (rows[r].cells.length == 5))
		{
			prd.getItem9(rows[r]);
			// Post shop9tag
			psCreateShopAction9Tag(prd.id, prd.name, prd.quantity, prd.price, ord.cusId, ord.id, ord.subtotal, prd.catId);
		}
		/*
		// IGNORE & wait for update from Swanson site
		else if (rows[r].innerHTML.search(/added as free items/gi) >= 0) // free items
		{
			var prdIds = rows[r].cells[0].innerHTML.replace(/added as free items/gi, "");
			if (prdIds != null)
			{
				prdIds = psTrim(prdIds.replace(/items/gi, "").replace(".", ""));
				prdIds = prdIds.split(",");
				for (var index = 0; index < prdIds.length; index++)
				{
					prd.getFreeItem9(prdIds[index]);
					// Post shop9tag
					psCreateShopAction9Tag(prd.id, prd.name, prd.quantity, prd.price, ord.cusId, ord.id, ord.subtotal, prd.catId);
				}
			}
		}
		*/
	}
	//
	// Make sure to have actual postings
	psDisplayShop9s();
	// Post order tag finally
	psCreateOrderTag(ord.id, ord.subtotal, ord.shipping, ord.cusId, ord.city, ord.state, ord.zipCode);
	// For exceptional checkout flows that the code failed to capture
	psCreateRegistrationTag(ord.cusId, ord.cusId, ord.city, ord.state, ord.zipCode);
	// Delete cookies after checking successfully
	//psSetCookie(G_PS_COOKIE_CATID, "", "delete");
	psSetCookie(G_PS_COOKIE_PROD_CATID, "", "delete");
}

/*
 * Subscribe login form to capture user profile
 */
function psSubscribeSignInPages()
{
	// post page view tag
	psCreatePageviewTag("LoginForm", G_PS_CUR_CATID, null);
	// subscribe submit function in order to capture user profile information as the user submits
	var frm = null;
	if (G_PS_PATHNAME.search(/\/LoginForm/gi)>=0)
		frm = document.getElementsByName("LogonPrompt")[0];
	else if (G_PS_PATHNAME.search(/\/SignonForm/gi)>=0)
		frm = document.getElementById("frmLogin");

	if (frm != null)
	{
		onsubmitSignInPtr = frm.onsubmit; // back up original function
		frm.onsubmit = function()
		{
			var uP = new psProfile();
			// get email
			if (G_PS_PATHNAME.indexOf("/login")>=0)
				uP.email = document.getElementById("logonId").value;
			else 
				uP.email = document.getElementById("fldEmailReg").value;

			// store profile on cookie
			uP.writeProfile();
			// mark as signed in successfully for the next step to post registration
			psSetCookie(G_PS_COOKIE_FLAG, "signed in");
			//
			// Invoke original function
			if (onsubmitSignInPtr != null)
				return onsubmitSignInPtr();
		}
	}
}

/*
 * Process to post registration tags as user signs in
 */
function psPostSignInView()
{
	if (psGetCookie(G_PS_COOKIE_FLAG) == "signed in")
	{
		if ((G_PS_PATHNAME.search(/loginform/gi)<0) && (G_PS_PATHNAME.search(/signonform/gi)<0))
		{
			var uP = new psProfile();
			uP.readProfile(); // get user profile from cookie
			// post registration tag for login page
			psCreateRegistrationTag(uP.email, uP.email);
		}
		psSetCookie(G_PS_COOKIE_FLAG, "", "delete"); // turn off flag
	}
}

/*
 * Subscribe updating profile form to capture user profile
 */
function psSubscribeProfilePages()
{
	// post page view tag
	psCreatePageviewTag(psGetPageId(), G_PS_CUR_CATID, null);
	// subscribe submit form in registration page, profile page, or billing page to capture user profile
	var frm = null;
	if (G_PS_PATHNAME.search(/\/register/gi)>=0)
		frm = document.getElementById("register");
	else if (G_PS_PATHNAME.search(/\/profile/gi)>=0)
		frm = document.getElementsByName("changeRegistration")[1];
	else if (G_PS_PATHNAME.search(/\/billinguser/gi)>=0)
		frm = document.getElementById("frmBillingShipping");
	else if (G_PS_PATHNAME.search(/\/billingguest/gi)>=0)
		frm = document.getElementById("frmBillingShipping2");
	else // Exception -> jump out
		return;

	if (frm != null)
	{
		onsubmitRegisterPtr = frm.onsubmit; // backup original function
		frm.onsubmit = function()
		{
			var uP = new psProfile();
			if (G_PS_PATHNAME.search(/\/billingguest/gi)>=0){
				uP.email = document.getElementById("email1").value;
				uP.city = document.getElementById("city").value;
				uP.state = document.getElementById("state");
				if (uP.state != null)
					uP.state = psGetInnerText(uP.state.options[uP.state.selectedIndex]);
				uP.zipcode = document.getElementById("zip").value;					
			}
			else{
				if ((G_PS_PATHNAME.search(/\/register/gi)>=0) || (G_PS_PATHNAME.search(/\/profile/gi)>=0))
				{
					uP.email = document.getElementById("email").value;
					uP.city = document.getElementById("city").value;
					
					if (G_PS_PATHNAME.search(/\/register/gi)>=0)
						uP.state = document.getElementById("state");
					else
						uP.state = document.getElementById("stateSelect");
					if (uP.state != null)
						uP.state = psGetInnerText(uP.state.options[uP.state.selectedIndex]);
					if (G_PS_PATHNAME == "/register")
						uP.zipcode = document.getElementById("zipcode").value;
					else if (G_PS_PATHNAME == "/registercheckout")
						uP.zipcode = document.getElementById("zip").value;
					else
						uP.zipcode = document.getElementsByName("zipCode")[0].value;
				}
				else
				{
					uP.email = document.getElementById("fldBillingEmail").value;
					uP.city = document.getElementById("fldBillingCity").value;
					uP.state = document.getElementById("fldBillingState");
					uP.state = psGetInnerText(uP.state.options[uP.state.selectedIndex]);
					uP.zipcode = document.getElementById("fldBillingZip").value;
				}
			}
			// store on cookie
			uP.writeProfile();			
			// set cookie to mark the status of creating user profile
			psSetCookie(G_PS_COOKIE_FLAG, "updated");
			//
			// Invoke original function
			if (onsubmitRegisterPtr != null)
				return onsubmitRegisterPtr();
		}
	}
}

/*
 * Process to post registration tag as user updated profile successfully
 */
function psPostUpdateProfileView()
{
	if (psGetCookie(G_PS_COOKIE_FLAG) == "updated") // navigated from create or update profile pages
	{
		if (((G_PS_PATHNAME != "/register") && (G_PS_PATHNAME != "/profile") && (G_PS_PATHNAME != "/registercheckout")) || 
			(document.body.innerHTML.search(/thank you for registering/gi) >= 0))
		{
			// Only send when user successfully updated profile. By this we avoid posting registration tag
			// as the user cancel update
			var uP = new psProfile();
			uP.readProfile(); // get user profile from cookie
			// post registration tag for update profile page
			psCreateRegistrationTag(uP.email, uP.email, uP.city, uP.state, uP.zipcode);
		}
		psSetCookie(G_PS_COOKIE_FLAG, "", "delete"); // turn off flag
	}
}

/*====================== END TAGGING BUSSINESS LOGIC =========================*/


/*======================= GENERAL UTILITY FUNCTION ===========================*/
function psHijackLinkLogout()
{
	var tagA = document.getElementsByTagName("A");
	if (tagA!=null){
		for(var i=0; i < tagA.length; i++)
		{
			if (tagA[i].href.indexOf("j_acegi_logout")>=0){
				tagA[i].oldFunc= tagA[i].onclick;				
				tagA[i].onclick=function()
				{
					psSetCookie(G_PS_COOKIE_PROFILE, "", "delete"); // turn off flag					
					if (this.oldFunc!=null)
					return this.oldFunc();
				}
				break;
			}
		}
	}
}
/*
 * Hijack AddToCart image buttons in order to capture productId and catId to 
 * store in cookie for use later
 */
function psHijackAddToCartButtons()
{
	if (G_PS_PATHNAME.search(/quickbuy/gi)>=0)
	{
		var frm = document.getElementById("quickbuy");
		if (frm != null)
		{
			onsubmitAddToCartPtr = frm.onsubmit; // backup original function
			frm.onsubmit = function()
			{
				psAddToOrderOnClick(this);
				//
				// Invoke original function
				if (onsubmitAddToCartPtr != null)
					return onsubmitAddToCartPtr();
			}
		}
	}
	else
	{
		var items = null;

		if ((G_PS_PATHNAME.search(/itemdetail/gi)>=0)
			|| (G_PS_PATHNAME.search(/favorites/gi)>=0))
		{
			items = document.getElementsByTagName("input");
		}
		else
			items = document.images;
		// hijack addtoorder images
		for (var i = 0; i < items.length; i++)
		{
			if ((items[i].src.search(/AddToOrder/gi)>=0)
				|| (items[i].src.search(/AddToBag/gi)>=0)
				|| (items[i].src.search(/AddOrder/gi)>=0)
				)
			{
				onclickAddToCartPtr = items[i].onclick; // backup original function
				items[i].onclick = function()
				{
					psAddToOrderOnClick(this);
					//
					// Invoke original function
					if (onclickAddToCartPtr != null)
						return onclickAddToCartPtr();
				}
			}
		}
	}
}

/*
 * Extract product id along with categoryId (from cookie) as the user click "add to order"
 */
function psAddToOrderOnClick(clickedItem)
{
	if (G_PS_PATHNAME.search(/quickbuy/gi)>=0) // add items from quickbuy page?
	{
		var tables = document.getElementsByTagName("table");
		if (tables.length < 21) // Exception?
			return;

		var rows = new Array();
		var index = 0;
		for (var i = 0; i < tables[19].rows.length; i++)
		{
			rows[index++] = tables[19].rows[i];
		}
		for (var i = 0; i < tables[20].rows.length; i++)
		{
			rows[index++] = tables[20].rows[i];
		}
		var inputs;
		for (index = 0; index < rows.length; index++)
		{
			if (rows[index].innerHTML.search(/qbItemNo/gi) < 0) // skip rows not containing items
				continue;
			
			inputs = rows[index].getElementsByTagName("input");
			if ((inputs[0].value != "") && (inputs[1].value > 0))
				psSetValueToCookie(G_PS_COOKIE_PROD_CATID, inputs[0].value, G_PS_CUR_CATID);
		}
	}
	else if (G_PS_PATHNAME.search(/itemdetail/gi)>=0) // add item to cart from product detail page?
	{
		// save to cookie productId along with the catId for use later in shop5 and shop9
		var prdId = psGetPrdIdFromUrl(G_PS_PATHNAME);
		psSetValueToCookie(G_PS_COOKIE_PROD_CATID, prdId, psGetValueFromCookie(G_PS_COOKIE_CATID, prdId));
	}
	else if (G_PS_PATHNAME.search(/favorites/gi)>=0) // add items to cart from Favorites?	
	{
		// Iterate through rows of table 18th to store product information into cookie if the item is checked
		var tables = document.getElementsByTagName("table");
		if (tables.length < 18) // Exception?
			return;

		var rows = tables[17].rows;
		var chkObj = null;

		for (var r = 0; r < rows.length; r++)
		{
			if (rows[r].innerHTML.search(/quantityArray/gi)>=0) // The row contains item?
			{
				chkObj = rows[r].getElementsByTagName("input")[2]; // the last input in the row
				if (chkObj.checked) // item checked?
					psSetValueToCookie(G_PS_COOKIE_PROD_CATID, chkObj.value, G_PS_CUR_CATID);
			}
		}
	}
	else // From elsewhere
	{
		var node = clickedItem;
		while (node.innerHTML.search(/endecaRecordId=/gi) < 0)
		{
			node = node.parentNode;
		}
		// get productId from associated hyperlink
		var re = new RegExp("endecaRecordId=([^&]*)", "gi");
		if (node.innerHTML.search(re)>=0)
			psSetValueToCookie(G_PS_COOKIE_PROD_CATID, RegExp.$1, G_PS_CUR_CATID);
	}
}

/*
 * Hijack links to item detail page in order to capture productId and catId 
 * to store in cookie for use later
 */
function psHijackItemDetailLinks()
{
	var itemLinks = document.links;
	for (var i =0; i < itemLinks.length; i++)
	{
		if (itemLinks[i].href.search(/itemdetail/gi)>=0)
		{
			onclickItemDetailPtr = itemLinks[i].onclick; // backup original function
			itemLinks[i].onclick = function() 
			{
				var prdId = psGetPrdIdFromUrl(this.href);
				// save current catId to cookie for use in the next step on product detail page
				if (G_PS_PATHNAME.search(/shoppingbag/gi)>=0) // view product detail from shopping cart? -> use the original catId
					psSetValueToCookie(G_PS_COOKIE_CATID, prdId, psGetValueFromCookie(G_PS_COOKIE_PROD_CATID, prdId));
				else
					psSetValueToCookie(G_PS_COOKIE_CATID, prdId, psCleanCatId(G_PS_CUR_CATID));
				//
				// Invoke original function
				if (onclickItemDetailPtr != null)
					return onclickItemDetailPtr();
			}
		}
	}
}

/*
 * Hijack search buttons to determine what kind of search 
 * (standard search, shop by product, shop by brand) that the user selected
 */
function psHijackSearchButtons()
{
	// hijack "go" button
	var objects = document.getElementsByTagName("input");
	for (var i = 0; i < objects.length; i++)
	{
		if (objects[i].src.search(/go_button.jpg/i) >= 0)
		{
			onclickSearchPtr = objects[i].onclick; // backup original function
			objects[i].onclick = function()
			{
				psSetCookie(G_PS_COOKIE_FLAG, "S"); // Search is active
				//
				// Invoke original function
				if (onclickSearchPtr != null)
					return onclickSearchPtr();								
			}
			break;			
		}
	}
	// hijack go textbox
	var txtGo = document.getElementById("keyword");
	if (txtGo != null)
	{
		txtGo.onkeyup = function()
		{
			if (event.keyCode == 13)
			{
				psSetCookie(G_PS_COOKIE_FLAG, "S"); // Search is active
			}
		}
	}
	// hijack Shop By Product combobox
	objects = document.getElementsByName("keyword");
	if (objects.length >=2)
	{
		objects[1].onchange = function()
		{
			if (this.options[this.selectedIndex].innerHTML.toUpperCase() != "SHOP BY PRODUCT")
			{
				psSetCookie(G_PS_COOKIE_FLAG, "P"); // shop by Product is active
			}
			document.getElementsByTagName("form")[1].submit();
		}
	}
	// hijack Shop By Brand combobox
	objects = document.getElementsByName("n");
	if (objects.length >= 3)
	{
		objects[2].onchange = function()
		{
			if (this.options[this.selectedIndex].innerHTML.toUpperCase() != "SHOP BY BRAND")
			{
				psSetCookie(G_PS_COOKIE_FLAG, "B"); // shop by Brand is active
			}
			document.getElementsByTagName("form")[3].submit();
		}
	}
}

/*
 * Extract categoryId from URL
 */
function psGetCatIdFromUrl()
{
	var catId = psGetValueFromUrl(G_PS_QUERYSTRING, "n");
	if (catId == null)
		catId = psGetValueFromUrl(G_PS_URL_REFERRER, "n");
	if (catId == null)
		return null;

	var start = catId.lastIndexOf("+");
	if (start < 0)
		start = catId.lastIndexOf(" ");
	catId = catId.substr(start + 1);
	return catId;
}

/*
 * Extract search term from source code (to be used as search term or pageId)
 */
function psGetSearchTerm()
{
	var term = '';
	var h1 = document.getElementsByTagName("h1");
	if (h1.length == 0) // reference search?
	{
		term = document.body.innerHTML.toUpperCase().split("SEARCH:")[1];
		if (term == null || typeof(term) == "undefined")
			return null;

		term = term.split("</A>")[0];
		term = term.substr(term.lastIndexOf(">") + 1);
	}
	else
	{
		term = psHtmlDecode(psGetInnerText(h1[0]));
		var i = term.lastIndexOf('>');
		if (i >= 0)
			term = term.substr(i+1);
		else
		{
			i = term.toUpperCase().lastIndexOf("SEARCH:");
			if (i >= 0)
				term = term.substr(i + "SEARCH:".length);
			else
				return null;
		}
	}
	return psTrim(term);
}

/*
 * Extract search result from source code: 
 */
function psGetSearchResult()
{
	var result = document.body.innerHTML.toUpperCase().split("SEARCH RESULTS");
	if (G_PS_PATHNAME.indexOf("referencesearch")>=0)
		result = result[2];
	else
		result = result[1];

	if (result == null || typeof(result) == "undefined")
		return null;

	result = result.split("ITEMS</SPAN>")[0];
	result = result.substr(result.lastIndexOf(">") + 1);
	return psTrim(result);
}

/*
 * Extract pageId from title (first part separated by '-')
 */
function psGetPageId()
{
	var pageId = '';
	if (document.title.indexOf(" - ")>=0)
		pageId = document.title.substr(0, document.title.indexOf(" - "));
	else
		pageId = document.title;

	return pageId.replace(/[\n\t\v\r\?\'\"]/gi, "")
}

/*
 * Extract product id from URL
 */
function psGetPrdIdFromUrl(pUrl)
{
	pUrl = pUrl.toUpperCase();
	pUrl = pUrl.substring(0, pUrl.indexOf("/ITEMDETAIL"));
	return pUrl.substr(pUrl.lastIndexOf("/")+1);
}

/* PURPOSE: constructor for product
 * Note: you can add more methods to psProduct in its prototype
 * RETURN: none
 */
function psProduct()
{
    this.id = null;
    this.name = null;
    this.catId = null;
    this.price = null;
    this.quantity = null;
	/*
	 * Extracting product info from source code for posting productview tag
	 */
	this.getProduct = function()
	{
		// get product id from URL
		this.id = psGetPrdIdFromUrl(G_PS_PATHNAME);
		// get product h1 element from source code
		this.name = psHtmlDecode(psGetInnerText(document.getElementsByTagName("h1")[0]));
		// get catId frotmm cookie set in the previous step
		if (psGetCookie(G_PS_COOKIE_FLAG) == "P") // shop by product?
			this.catId = "Shop By Product";
		else if (psGetCookie(G_PS_COOKIE_FLAG) == "B") // shop by brand?
			this.catId = "Shop By Brand";
		else if (psGetCookie(G_PS_COOKIE_FLAG) == "S") // standard search?
			this.catId = "SEARCH";
		else
		{
			this.catId = psGetValueFromCookie(G_PS_COOKIE_CATID, this.id);
			if (this.catId == null) // not found -> get the last catId from back-up cookie
				this.catId = psGetCookie(G_PS_COOKIE_LAST_CATID);
			if (this.catId == null) // not found -> get catId from Url (worse choice)
				this.catId = psGetCatIdFromUrl();
			if (this.catId == null) // not found -> get catId from Url (the worst choice)
				this.catId = "BOOKMARK";			
		}
		psSetValueToCookie(G_PS_COOKIE_CATID, this.id, this.catId); // Update temp cookie
		psSetCookie(G_PS_COOKIE_FLAG, "", "delete"); // clear flag cookie
	}
	/*
	 * Extracting product info from source code specified by the "current" row
	 * of items table in the shopping cart
	 */
	this.getItem5 = function(itemRow)
	{
		// get product id and product name from rows[r].cells[0]
		var hrefs = itemRow.cells[0].getElementsByTagName("a");
		this.id = psGetPrdIdFromUrl(hrefs[0].href);
		if (itemRow.innerHTML.indexOf("FREE")>=0) // Buy 1 get 1 free exception?
		{
			this.name = psHtmlDecode(hrefs[0].innerHTML);
			this.price = 0;
			this.quantity = psGetInnerText(psHtmlDecode(itemRow.cells[2].innerHTML));
			if (this.quantity != null)
				this.quantity = this.quantity.replace("qty", "");
		}
		else
		{
			this.name = psHtmlDecode(hrefs[1].innerHTML);
			// get price from rows[r].cells[1]
			this.price = itemRow.cells[1].innerHTML.split("SWANSON")[1]; // the last string contains product price
			if (this.price != null)
			{
				this.price = psTrim(this.price.substring(0, this.price.indexOf("<")));
				if (this.price != null)
					this.price = this.price.replace("$", "");
			}
			// get quantity from rows[r].cells[2]
			this.quantity = itemRow.cells[2].getElementsByTagName("input")[0];
			if (this.quantity != null)
				this.quantity = this.quantity.value;
		}
		// get catId from cookie G_PS_COOKIE_PROD_CATID
		this.catId = psGetValueFromCookie(G_PS_COOKIE_PROD_CATID, this.id);
	}
	/*
	 * Extracting product info from source code specified by the "current" row
	 * of items table in the receipt page
	 */
	this.getItem9 = function(itemRow)
	{
		this.id = psGetInnerText(itemRow.cells[0]);
		this.name = null;
		this.quantity = psGetInnerText(itemRow.cells[2]);
		this.price = psGetInnerText(itemRow.cells[3]);
		if (this.price != null)
			this.price = this.price.replace("$", "");
		// get catId from cookie G_PS_COOKIE_PROD_CATID		
		this.catId = psGetValueFromCookie(G_PS_COOKIE_PROD_CATID, this.id);
		
	}
	/*
	 * Compose product info for free items in receipt page
	 */
	this.getFreeItem9 = function(prdId)
	{
		this.id = prdId;
		this.name = null;
		this.quantity = 1;
		this.price = 0;
		// get catId from cookie G_PS_COOKIE_PROD_CATID
		this.catId = psGetValueFromCookie(G_PS_COOKIE_PROD_CATID, this.id);
	}

}

/* PURPOSE: constructor for profile
 * Note: you can add more methods to psProfile in its prototype
 * RETURN: none
 */
function psProfile()
{
    this.email = null;
    this.city = null;
    this.state = null;
    this.zipcode = null;
	/*
	 * Get user profile from cookie
	 */
	this.readProfile = function()
	{
		// get user profile from cookie
		this.email = psGetCookie(G_PS_COOKIE_PROFILE);
		if (this.email != null)
		{
			var buf = this.email.split('|');
			this.email = buf[0];
			this.city = buf[1];
			this.state = buf[2];
			this.zipcode = buf[3];
		}
	}
	/*
	 * set user profile to cookie
	 */
	this.writeProfile = function()
	{
		if (this.email == null)
			return;
		// make sure that the data contains 4 parts separated by 3 '|'
		var data = this.email + '|' + this.city + '|' + this.state + '|' + this.zipcode;
		// store on cookie
		psSetCookie(G_PS_COOKIE_PROFILE, data);
	}
}

/*
 * Order object encapsulates order Id, subtotal, shipping and customer Id
 * This design is aimed at code resuse and easy readability
 */
function psOrder()
{
	this.id = null;
	this.subtotal = null;
	this.shipping = null;
	this.cusId = null;
	this.city = null;
	this.state = null;
	this.zipCode = null;
	/*
	 * get order info from source code
	 */
	this.getOrder = function()
	{
		this.id = document.body.innerHTML.toUpperCase().split("ORDER NUMBER:")[1];
		this.id = this.id.substring(0, this.id.indexOf("</TD>"));
		this.id = psTrim(this.id.substr(this.id.indexOf(">")+1));
		// get discount amount
		var discount = 0;
		if (document.body.innerHTML.search(/DISCOUNT \/ PROMOTION:/gi)>=0)
		{
			discount = document.body.innerHTML.toUpperCase().split("DISCOUNT / PROMOTION:")[1];
			discount = discount.split("$")[1];
			discount = discount.substring(0, discount.indexOf("<"));
		}
		// get subtotal from source code
		this.subtotal = document.body.innerHTML.toUpperCase().split("SUBTOTAL:")[2];
		this.subtotal = this.subtotal.split("$")[1];
		this.subtotal = this.subtotal.substring(0, this.subtotal.indexOf("<"));
		this.subtotal = Math.round((this.subtotal - discount)*100)/100;
		// get shipping from source code
		this.shipping = document.body.innerHTML.toUpperCase().split("SHIPPING (STANDARD):")[1];
		this.shipping = this.shipping.split("$")[1];
		this.shipping = this.shipping.substring(0, this.shipping.indexOf("<"));
		// get customer Id from cookie
		this.cusId = psGetCookie(G_PS_COOKIE_PROFILE);
		if (this.cusId != null)
			this.cusId = this.cusId.split('|')[0]; // email is the customer id
		// get customer city, state, and zipcode
		var table = document.getElementsByTagName("table");
		if (table.length > 11)
		{
			var buffer = table[11].rows[2].cells[0].innerHTML.toUpperCase().split("<BR")[3];
			buffer = buffer.substr(buffer.indexOf(">")+1);
			buffer = buffer.split(",");
			this.city = buffer[0];
			buffer = psTrim(buffer[1]).split(" ");
			this.state = buffer[0];
			this.zipCode = buffer[1];
			//Don Modified 2009/01/12
			if (this.cusId == null){
				var profileStr = table[11].rows[2].cells[0].innerHTML;
				var arrProfile = profileStr.toLowerCase().split("<br>");
				this.cusId = arrProfile[arrProfile.length-1];
			}
		}
	}
}

/* PURPOSE: Get inner text of an object or clean remove html tags of a particular string
 * RETURN: resultant string or null object
 */
function psGetInnerText(pTagOjb)
{
	if (pTagOjb != null)
	{
		if (typeof(pTagOjb) == "object")
			return psTrim(pTagOjb.innerHTML.replace(/\<+.+?\>+/g, ""));
		else
			return psTrim(pTagOjb.replace(/\<+.+?\>+/g, ""));
	}
	return null;
}

/* PURPOSE: Remove all unaccepted characters in categoryid, including
 * RETURN: string
 */
function psCleanCatId(pCatId)
{
    return (pCatId != null) ? pCatId.replace(/[\'\":,]/g, "") : null;
}

function psCleanPageId(pPageId)
{
	return (pPageId != null) ? pPageId.replace(/[\n\t\v\r’\'\"]/gi, "") : null; 
}

function psCleanProductName(pProductName)
{
	return (pProductName != null) ? pProductName.replace(/[\n\t\v\r’\'\"]/gi, "") : null; 
}

/* PURPOSE: Remove all leading & trailing spaces of a string
 * Note: [&nbsp;] is also considered as a space
 * Two ways to call: as a string's built-in method 
 * or as an independent function
 * RETURN: string
 */
function psTrim(pStr)
{
	if (pStr == null || typeof(pStr) == "undefined")
		return pStr;

	return pStr.replace(/&nbsp;/gi, ' ').replace(/^\s+|\s+$/g, '');
}

/* PURPOSE: extract value from the URL
 * in format of http://xxx.com/page.ext?key1=value1&key2=value2
 * RETURN: string value of the parameter
 */
function psGetValueFromUrl(pUrl, pKey)
{
    var re = new RegExp("[?&]" + pKey + "=([^&$]*)", "i");
    if (pUrl.search(re) == -1)
		return null;
    return unescape(RegExp.$1);
}

/* PURPOSE: convert special HTML characters to normal character
 * Note: for each project, this function needs to be updated
 * RETURN: decoded string
 */
function psHtmlDecode(pValue)
{
    if (pValue)
    {
        pValue = pValue.replace(/&nbsp;/gi, " ");
        pValue = pValue.replace(/&quot;/gi, '"');
        pValue = pValue.replace(/&amp;/gi, "&");
        pValue = pValue.replace(/&lt;/gi, "<");
        pValue = pValue.replace(/&gt;/gi, ">");
    }

    return pValue;
}

/* PURPOSE: retrieve cookie value
 * RETURN: string
 */
function psGetCookie(pCookieName)
{
    if (!pCookieName)
		return null;

    var start = document.cookie.indexOf(pCookieName + "=");
    if (start > -1)
    {
        start = start + pCookieName.length + 1; 
        end = document.cookie.indexOf(";", start);
        if (end == -1)
            end = document.cookie.length;
        return unescape(document.cookie.substring(start, end));
    }
    return null;
}

/* PURPOSE: set cookie value
 * Note: if the designated cookie is too big, the old items will be removed
 * because cookie size is limited to 4K
 * @pLifeTime in seconds
 * pDomain: don't specify if using current domain
 * RETURN: boolean
 */
function psSetCookie(pCookieName, pCookieValue, pLifeTime, pDomain)
{
    if (!pCookieName)
		return false;

	if(pLifeTime == "delete") 
    {         
        CC(pCookieName);//delete cookie by calling coremetrics's cookie function
        return true;
    }
    // set cookie by calling coremetrics's cookie function
    var expire = (pLifeTime) ? (new Date((new Date()).getTime() + (1000 * pLifeTime))).toGMTString() : null;
    
    return CB(pCookieName, escape(pCookieValue), expire, pDomain);
}

/* PURPOSE: set value in cookie in format of #key1~value1#key2~value2
 * NOTE: to remove a pare (key?value), use null or '' for pValue
 */
function psSetValueToCookie(pCookieName, pKey, pValue)
{
	// "normalize" input parameters
	pCookieName = psTrim(pCookieName);
	pKey = psTrim(pKey);
	// 
	var catCookie = psGetCookie(pCookieName);
	if (catCookie == null)
		catCookie = '';

	if (catCookie.indexOf(pKey) >=0) // Store before -> remove the old value
	{
        var reg = new RegExp("#" + pKey + "~([^#]*)", "gi");
        catCookie = catCookie.replace(reg, "");
	}
	// remove the last items (eldest items) until cookie size < 3500	
	if (pValue != null && pValue != '')
	{
		catCookie = "#" + pKey + "~" + pValue + catCookie;
		var cookieArray = null;
		while (catCookie.length > 3500)
		{
			cookieArray = catCookie.split("#");
			cookieArray.pop();
			catCookie = cookieArray.join("#");
		}
	}
	// Save to cookie
	psSetCookie(pCookieName, catCookie, G_PS_COOKIE_LIFETIME);
}

/* PURPOSE: get value stored in cookie in format of:
 * #key1~value1#key2~value2
 * RETURN: string
 */
function psGetValueFromCookie(pCookieName, pKey)
{
	// "normalize" input parameters
	pCookieName = psTrim(pCookieName);
	pKey = psTrim(pKey);
	// extract catId associated with the specified key (pKey)
    var catCookie = psGetCookie(pCookieName);
    if (catCookie != null)
    {
        var re = new RegExp("#" + pKey + "~([^#]+)", "i");
		if (catCookie.search(re) == -1)
			return null;

        return RegExp.$1;
    }
    return null;
}

/********************************************************/
/* WRAPPER FOR COREMETRICS' TAG FUNCTIONS               */
/********************************************************/
function psCreatePageviewTag(pageID, categoryID, searchString, searchResults) 
{
	pageID = psCleanPageId(pageID);
	categoryID = psCleanCatId(categoryID);	
    if (G_PS_DEBUG_MODE == 1 || G_PS_DEBUG_MODE == 3)
        alert("cmCreatePageviewTag(" + pageID + ", " + categoryID + ", " + searchString + ", " + searchResults + ")");
    if (G_PS_DEBUG_MODE == 2 || G_PS_DEBUG_MODE == 3)
        cmCreatePageviewTag(pageID, categoryID, searchString, searchResults);
}

function psCreateProductviewTag(productID, productName, categoryID) 
{
	productName = psCleanProductName(productName);
	categoryID = psCleanCatId(categoryID);
    if (G_PS_DEBUG_MODE == 1 || G_PS_DEBUG_MODE == 3)
        alert("cmCreateProductviewTag(" + productID + ", " + productName + ", " + categoryID + ")");
    if (G_PS_DEBUG_MODE == 2 || G_PS_DEBUG_MODE == 3)
        cmCreateProductviewTag(productID, productName, categoryID);
        
}

function psCreateShopAction5Tag(productID, productName, productQuantity, productPrice, categoryID) 
{
	productName = psCleanProductName(productName);
	categoryID = psCleanCatId(categoryID);
    if (G_PS_DEBUG_MODE == 1 || G_PS_DEBUG_MODE == 3)
        alert("cmCreateShopAction5Tag(" + productID + ", " + productName + ", " + productQuantity + ", " + productPrice + ", " + categoryID + ")");
    if (G_PS_DEBUG_MODE == 2 || G_PS_DEBUG_MODE == 3)
        cmCreateShopAction5Tag(productID, productName, productQuantity, productPrice, categoryID);    
}

function psCreateShopAction9Tag(productID, productName, productQuantity, productPrice, customerID, orderID, orderTotal, categoryID) 
{
	productName = psCleanProductName(productName);
	categoryID = psCleanCatId(categoryID);
    if (G_PS_DEBUG_MODE == 1 || G_PS_DEBUG_MODE == 3)
        alert("cmCreateShopAction9Tag(" + productID + ", " + productName + ", " + productQuantity + ", " + productPrice + ", " + customerID + ", " + orderID + ", " + orderTotal + ", " + categoryID + ")");
    if (G_PS_DEBUG_MODE == 2 || G_PS_DEBUG_MODE == 3)
        cmCreateShopAction9Tag(productID, productName, productQuantity, productPrice, customerID, orderID, orderTotal, categoryID);
}

function psCreateOrderTag(orderID, orderTotal, orderShipping, customerID, customerCity, customerState, customerZIP) 
{
    if (G_PS_DEBUG_MODE == 1 || G_PS_DEBUG_MODE == 3)
        alert("cmCreateOrderTag(" + orderID + ", " + orderTotal + ", " + orderShipping + ", " + customerID + ", " + customerCity + ", " + customerState + ", " + customerZIP + ")");
    if (G_PS_DEBUG_MODE == 2 || G_PS_DEBUG_MODE == 3)
        cmCreateOrderTag(orderID, orderTotal, orderShipping, customerID, customerCity, customerState, customerZIP);
}

function psCreateConversionEventTag(eventID, actionType, categoryID, points) 
{
	categoryID = psCleanCatId(categoryID);
    if (G_PS_DEBUG_MODE == 1 || G_PS_DEBUG_MODE == 3)
        alert("cmCreateConversionEventTag(" + eventID + ", " + actionType + ", " + categoryID + ", " + points + ")");
    if (G_PS_DEBUG_MODE == 2 || G_PS_DEBUG_MODE == 3)
        cmCreateConversionEventTag(eventID, actionType, categoryID, points);
}

function psCreateRegistrationTag(customerID, customerEmail, customerCity,
				customerState, customerZIP, newsletterName, 
				subscribe) 
{
    if (G_PS_DEBUG_MODE == 1 || G_PS_DEBUG_MODE == 3)
        alert("cmCreateRegistrationTag(" + customerID + ", " + customerEmail + ", " + customerCity + ", " + customerState + ", " + customerZIP + ", " + newsletterName + ", " + subscribe + ")");
    if (G_PS_DEBUG_MODE == 2 || G_PS_DEBUG_MODE == 3)
        cmCreateRegistrationTag(customerID, customerEmail, customerCity, customerState, customerZIP, newsletterName, subscribe);
}

function psCreateErrorTag(pageID, categoryID) 
{
	pageID = psCleanPageId(pageID);
	categoryID = psCleanCatId(categoryID);
    if (G_PS_DEBUG_MODE == 1 || G_PS_DEBUG_MODE == 3)
        alert("cmCreateErrorTag(" + pageID + ", " + categoryID + ")");
    if (G_PS_DEBUG_MODE == 2 || G_PS_DEBUG_MODE == 3)
        cmCreateErrorTag(pageID, categoryID);
}

function psDisplayShop5s()
{
    if (G_PS_DEBUG_MODE == 1 || G_PS_DEBUG_MODE == 3)
        alert("cmDisplayShop5s()");
    if (G_PS_DEBUG_MODE == 2 || G_PS_DEBUG_MODE == 3)
        cmDisplayShop5s();
}

function psDisplayShop9s()
{
    if (G_PS_DEBUG_MODE == 1 || G_PS_DEBUG_MODE == 3)
        alert("cmDisplayShop9s()");
    if (G_PS_DEBUG_MODE == 2 || G_PS_DEBUG_MODE == 3)
        cmDisplayShop9s();
}
/*===========================END GENERAL UTILITY FUNCTION ==================*/