/************************************************************************************/
/* $Revision: 106172 $
 * $Id: cmtaggingservices - 6503805 - 90225482 - 103108.txt 106172 2008-12-18 16:56:01Z rnaik $
 *
 * Author: Coremetrics/PSD 
 * Coremetrics  v1.12, 12/18/2008
 * COPYRIGHT 1999-2008 COREMETRICS, INC. 
 * ALL RIGHTS RESERVED. U.S.PATENT PENDING
 * Disclaimer: Coremetrics is not responsible for hosting or maintenance or this file
 *
 */
/************************************************************************************/
//Production data warehouse flag
cmSetProduction();
/*===========================GLOBAL VARIABLES ===============================*/
// options for debug mode when sending tag:
// 1: only alert
// 2: only send tag
// 3: alert & send tag
var G_PS_DEBUG_MODE = 2;

// current page url
var G_PS_URL_PATH = "" + document.location;
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 = 432000; // 5*24*60*60 = 5 days
// cookie name
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_TOP_MENU = "PS_TOP_MENU";
var G_PS_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;
/*========================= END GLOBAL VARIABLES =============================*/

/*=========================== BEGIN NAVIGATION ===============================*/
psHijackLeftMenus();

// Navigation logic should go here!
if(G_PS_URL_PATH.toUpperCase().indexOf("GO.PIONEERLINENS.COM/SEARCH")>-1)
{
	psPostSearchView();
}
else if(G_PS_URL_PATH.toUpperCase().indexOf("GO.PIONEERLINENS.COM")>-1)
{
	if(G_PS_PATHNAME == "/")
	{
		psCreatePageviewTag("Popular searches","SEARCH",null,null);
	}
	else
	{
		psPostSearchView_1();
	}
}
else if(G_PS_PATHNAME == "/")
{
	psCreatePageviewTag("Pioneerlinens Home Page","HOME",null,null);
	psSetCookie(G_PS_COOKIE_CATID,"HOME");
}
else if(G_PS_URL_PATH.toLowerCase().indexOf("linenwashforbedroom")>-1)
{
	psCreatePageviewTag("Linen care","Linen wash for bedroom",null,null);
	psSetCookie(G_PS_COOKIE_CATID,"Linen wash for bedroom");
}
else if(G_PS_URL_PATH.toLowerCase().indexOf("index.cfm?fuseaction=bedroom.showicons&productgroup_id=3375")>-1)
{
	psCreatePageviewTag("Silver care","Silver care for bed");
	psSetCookie(G_PS_COOKIE_CATID,"Silver care for bed");
}
else if(G_PS_URL_PATH.toLowerCase().indexOf("linenwashforbath")>-1)
{
	psCreatePageviewTag("Linen care","Linen wash for Bath");
	psSetCookie(G_PS_COOKIE_CATID,"Linen wash for Bath");
}
else if(G_PS_URL_PATH.toUpperCase().indexOf("INDEX.CFM?FUSEACTION=BATHROOM.SHOWICONS&PRODUCTGROUP_ID=3374")>-1)
{
	psCreatePageviewTag("Silver care","Silver care for Bath");
	psSetCookie(G_PS_COOKIE_CATID,"Silver care for Bath");
}
else if(G_PS_URL_PATH.toUpperCase().indexOf("LINENWASHFORTABLE")>-1)
{
	psCreatePageviewTag("Linen care","Linen wash for Table");
	psSetCookie(G_PS_COOKIE_CATID,"Linen wash for Table");
}
else if(G_PS_URL_PATH.toUpperCase().indexOf("SILVERCAREFORTABLE")>-1)
{
	psCreatePageviewTag("Silver care","Silver care for Table");
	psSetCookie(G_PS_COOKIE_CATID,"Silver care for Table");
}
else if(G_PS_URL_PATH.toUpperCase().indexOf("LINENWASHFORHOMEDECOR")>-1)
{
	psCreatePageviewTag("Linen care","Linen wash for Home decor");
	psSetCookie(G_PS_COOKIE_CATID,"Linen wash for Home decor");
}
else if(G_PS_URL_PATH.toUpperCase().indexOf("INDEX.CFM?FUSEACTION=HOMEDECOR.SHOWICONS&PRODUCTGROUP_ID=3377")>-1)
{
	psCreatePageviewTag("Silver care","Silver care for Home decor");
	psSetCookie(G_PS_COOKIE_CATID,"Silver care for Home decor");
}

else if(G_PS_PATHNAME.toUpperCase() == "/YACHTS")
{
	psCreatePageviewTag("Yachts","HOME",null,null);
	psSetCookie(G_PS_COOKIE_CATID,"Yacht");
}
else if(G_PS_URL_PATH.toUpperCase().indexOf("PIONEERLINENS.COM/CATALOG")>-1)
{
	psCreatePageviewTag("Catalog","HELP",null,null);
}
else if(G_PS_URL_PATH.toUpperCase().indexOf("PIONEERLINENS.COM/INDEX.CFM?FUSEACTION=FORMS.REQUESTCATALOG")>-1)
{
	psCreatePageviewTag("Request Catalog","HOME",null,null);
}
else if(G_PS_URL_PATH.toUpperCase().indexOf("PIONEERLINENS.COM/INDEX.CFM?FUSEACTION=FORMS.THANKYOUELIST&&CFID=12819815&CFTOKEN=28538757")>-1)
{
	psCreatePageviewTag("Thank you Elist","HOME",null,null);
}
else if(G_PS_URL_PATH.toUpperCase().indexOf("PIONEERLINENS.COM/CUSTOMERSERVICE")>-1
		|| G_PS_URL_PATH.toUpperCase().indexOf("PIONEERLINENS.COM/INDEX.CFM?FUSEACTION=SERVICE.MAIN")>-1)
{
	psCreatePageviewTag("Customer Service","HELP",null,null);
}
else if(G_PS_URL_PATH.toUpperCase().indexOf("INDEX.CFM?FUSEACTION=MYACCOUNT.MAIN")>-1)
{
	psCreatePageviewTag("My account","Account",null,null);
}
else if(G_PS_URL_PATH.toUpperCase().indexOf("INDEX.CFM?FUSEACTION=SECURE.ADDRESSFORM&ADDRESS_ID=")>-1)
{
	psCreatePageviewTag("Edit profile","Account",null,null);
}

else if(G_PS_URL_PATH.toUpperCase().indexOf("INDEX.CFM?FUSEACTION=SECURE.ADDRESSFORM")>-1)
{
	psCreatePageviewTag("Add profile","Account",null,null);
}
else if(G_PS_URL_PATH.toUpperCase().indexOf("INDEX.CFM?FUSEACTION=SITEMAP.MAIN")>-1
		|| G_PS_URL_PATH.toUpperCase().indexOf("PIONEERLINENS.COM/SITEMAP")>-1)
{
	psCreatePageviewTag("Sitemap","HELP",null,null);
	psSetCookie(G_PS_COOKIE_CATID,"SITEMAP");
}
else if(G_PS_URL_PATH.toUpperCase().indexOf("INDEX.CFM?FUSEACTION=SECURE.ADDRESSBOOK")>-1)
{
	if(G_PS_URL_REFERRER.toUpperCase().indexOf("INDEX.CFM?FUSEACTION=SECURE.SIGNIN")>-1)
	{
		var profile = new psProfile();
		profile.readProfile();
		psCreateRegistrationTag(profile.email,profile.email,null,null,null,null,null,null,null,null);
	}
	psCreatePageviewTag("AddressBook","Account",null,null);
}
else if(G_PS_URL_PATH.toUpperCase().indexOf("INDEX.CFM?FUSEACTION=")>-1 && G_PS_URL_PATH.toUpperCase().indexOf(".MAIN")>-1)
{
	var pageId = psGetValueFromUrl(G_PS_URL_PATH,"fuseaction");
	pageId = pageId.substring(0,pageId.indexOf("."));
	psCreatePageviewTag(pageId,"HELP",null,null);
}
else if(G_PS_URL_PATH.toUpperCase().indexOf("INDEX.CFM?FUSEACTION=SERVICE")>-1)
{
	var pageId = psGetValueFromUrl(G_PS_URL_PATH,"fuseaction");
	pageId = pageId.replace("."," ");
	psCreatePageviewTag(pageId,"CUSTOMER SERVICE",null,null);
}

else if(G_PS_URL_PATH.toUpperCase().indexOf("PIONEERLINENS.COM/FAQS")>-1)
{
	psCreatePageviewTag("service faq","CUSTOMER SERVICE",null,null);
}
else if(G_PS_URL_PATH.toUpperCase().indexOf("PIONEERLINENS.COM/ELITESHOPPER")>-1)
{
	psCreatePageviewTag("elite shopper","CUSTOMER SERVICE",null,null);
}
else if(G_PS_URL_PATH.toUpperCase().indexOf("INDEX.CFM?FUSEACTION=PRODUCTASSISTANCE.INFO_LINENCARE")>-1)
{
	psCreatePageviewTag("Caring For Your Investment","HELP",null,null);
}
else if(G_PS_URL_PATH.toUpperCase().indexOf("PIONEERLINENS.COM/CONTACTUS")>-1)
{
	psCreatePageviewTag("Contact & Store Location","HELP",null,null);
}
else if(psIsProductView())
{
	if(G_PS_URL_REFERRER.toUpperCase().indexOf("WWW.PIONEERLINENS.COM")>-1)
	{
		G_PS_CUR_CATID = psGetCookie(G_PS_COOKIE_CATID);
		G_PS_CUR_CATID = psHtmlDecode(G_PS_CUR_CATID);
	}
	else if (psIsEqual(psGetDomain(G_PS_URL_REFERRER), "GO.PIONEERLINENS.COM"))
	{
		G_PS_CUR_CATID = psGetCookie(G_PS_COOKIE_CATID);
		G_PS_CUR_CATID = psHtmlDecode(G_PS_CUR_CATID);
	}
	
	if(G_PS_CUR_CATID == null || G_PS_CUR_CATID.toUpperCase() == "HELP")
	{
		G_PS_CUR_CATID = psGetCategoryId();
	}
	if(G_PS_CUR_CATID != null)
	{
		G_PS_CUR_CATID = G_PS_CUR_CATID.toUpperCase();
	}
	var pageId = psGetPageIdForProductView();
	var searchTerm = null;
	var searchResult = null;
	if(!psIsNoItem())
	{
		psCreatePageviewTag(pageId, G_PS_CUR_CATID, searchTerm, searchResult);
		psPostProductView(G_PS_CUR_CATID);
		psHijackForProductViewPage(G_PS_CUR_CATID);
	}
	else
	{
		psCreatePageviewTag("NO ITEM", G_PS_CUR_CATID, searchTerm, searchResult);
	}
}
else if(G_PS_URL_PATH.toUpperCase().indexOf("PIONEERLINENS.COM/CLEARANCE")>-1)
{
	psCreatePageviewTag("CLEARANCE", "HOME", null, null);
	psSetCookie(G_PS_COOKIE_CATID,"OUTLET");
}
else if(G_PS_URL_PATH.toUpperCase().indexOf("FUSEACTION=SALE")>-1)
{
	psCreatePageviewTag("CLEARANCE", "HOME", null, null);
	psSetCookie(G_PS_COOKIE_CATID,"OUTLET");
}
else if(G_PS_URL_PATH.toUpperCase().indexOf("INDEX.CFM?FUSEACTION=SECURE.VIEWCART")>-1)
{
	if(G_PS_URL_REFERRER.toUpperCase().indexOf("INDEX.CFM?FUSEACTION=SECURE.SIGNIN")>-1)
	{
		var profile = new psProfile();
		profile.readProfile();
		psCreateRegistrationTag(profile.email,profile.email,null,null,null,null,null,null,null,null);
	}
	else if(G_PS_URL_REFERRER.toUpperCase().indexOf("INDEX.CFM?FUSEACTION=SECURE.REGISTER")>-1)
	{
		var profile = new psProfile();
		profile.readProfile();
		psCreateRegistrationTag(profile.email,profile.email,profile.city,profile.state,profile.zipcode,profile.country,null,null,profile.referredBy,null);
	}
	psCreatePageviewTag("View cart","Checkout",null,null);
	psPostCartView();
}
else if(G_PS_URL_PATH.toUpperCase().indexOf("INDEX.CFM?FUSEACTION=SECURE.SHIPPING")>-1)
{
	if(G_PS_URL_REFERRER.toUpperCase().indexOf("INDEX.CFM?FUSEACTION=SECURE.SIGNIN")>-1)
	{
		var profile = new psProfile();
		profile.readProfile();
		if(profile.email != null)
		{
			psCreateRegistrationTag(profile.email,profile.email,null,null,null,null,null,null,null,null);
		}
	}
	psCreatePageviewTag("Shipping","Checkout",null,null);
	psHijackForShippingPage();
}
else if(G_PS_URL_PATH.toUpperCase().indexOf("INDEX.CFM?FUSEACTION=SECURE.ORDEROPTIONS")>-1)
{
	psCreatePageviewTag("Order options","Checkout",null,null);
	if(G_PS_URL_REFERRER.toUpperCase().indexOf("INDEX.CFM?FUSEACTION=SECURE.SHIPPING")>-1)
	{
		var profile = new psProfile();
		profile.readProfile();
		psCreateRegistrationTag(profile.email,profile.email,profile.city,profile.state,profile.zipcode,profile.country,profile.newsletter,profile.subscribe,profile.referredBy,profile.purchasingFor);
	}
}
else if(G_PS_URL_PATH.toUpperCase().indexOf("INDEX.CFM?FUSEACTION=SECURE.BILLING")>-1)
{
	psCreatePageviewTag("Billing","Checkout",null,null);
}
else if(G_PS_URL_PATH.toUpperCase().indexOf("INDEX.CFM?FUSEACTION=SECURE.CONFIRMATION")>-1)
{
	psCreatePageviewTag("Order confirmation","Checkout",null,null);
	psPostOrderView();
}
else if(G_PS_URL_PATH.toUpperCase().indexOf("INDEX.CFM?FUSEACTION=SECURE.SIGNIN")>-1)
{
	psCreatePageviewTag("Signin","Account",null,null);
	psHijackSignin();
}
else if(G_PS_URL_PATH.toUpperCase().indexOf("INDEX.CFM?FUSEACTION=SECURE.SIGNOUT")>-1)
{
	psCreatePageviewTag("Signout","Account",null,null);
}
else if(G_PS_URL_PATH.toUpperCase().indexOf("INDEX.CFM?FUSEACTION=SECURE.REGISTER")>-1)
{
	psCreatePageviewTag("Register","Account",null,null);
	psHijackRegister();
}

else if(G_PS_URL_PATH.toUpperCase().indexOf("INDEX.CFM?FUSEACTION=SECURE.FORGOTPASSWORD")>-1)
{
	psCreatePageviewTag("Forgot password","Account",null,null);
}
else if(G_PS_URL_PATH.toUpperCase().indexOf("INDEX.CFM?FUSEACTION=SECURE.CHANGEPASSWORD")>-1)
{
	if(G_PS_URL_REFERRER.toUpperCase().indexOf("INDEX.CFM?FUSEACTION=SECURE.CHANGEPASSWORD")>-1)
	{
		var profile = new psProfile();
		profile.readProfile();
		psCreateRegistrationTag(profile.email,profile.email,null,null,null,null,null,null,null,null);
	}
	psCreatePageviewTag("Change password","Account",null,null);
	psHijackSigninForChangePassword();
}
else if(G_PS_URL_PATH.toUpperCase().indexOf("INDEX.CFM?FUSEACTION=SECURE.HISTORY")>-1)
{
	psCreatePageviewTag("My Order History(Current Quarter)","Account",null,null);
	if(G_PS_URL_REFERRER.toUpperCase().indexOf("INDEX.CFM?FUSEACTION=SECURE.SIGNIN")>-1)
	{
		var profile = new psProfile();
		profile.readProfile();
		psCreateRegistrationTag(profile.email,profile.email,null,null,null,null,null,null,null,null);
	}
}
else if(G_PS_URL_PATH.toUpperCase().indexOf("INDEX.CFM?FUSEACTION=SECURE.TRACKINGFORM")>-1)
{
	psCreatePageviewTag("Tracking Form","Account",null,null);
}
else if(psIsTopMenuPage())
{
	G_PS_CUR_CATID = "HOME";
	var pageId = psGetPageId(true);
	psCreatePageviewTag(pageId, G_PS_CUR_CATID, null, null);
	psSetCookie(G_PS_COOKIE_CATID,psGetCategoryId());
}
else if(psIsDesignerPage())
{
	G_PS_CUR_CATID = "DESIGNERS";
	var pageId = psGetPageId(false);
	psCreatePageviewTag(pageId,G_PS_CUR_CATID,null,null);
	psSetCookie(G_PS_COOKIE_CATID,psGetCategoryId());
}
else if(G_PS_URL_PATH.toUpperCase().indexOf("PIONEERLINENS.COM/LINENCARE")>-1)
{
	psCreatePageviewTag("Caring For Your Investment", "HELP", null, null);
}
else if(G_PS_URL_PATH.toUpperCase().indexOf("PIONEERLINENS.COM/FORTHEBATH")>-1)
{
	psCreatePageviewTag("Product Assistance: For The Bath", "HELP", null, null);
}
else if(G_PS_URL_PATH.toUpperCase().indexOf("PIONEERLINENS.COM/FORTHETABLE")>-1)
{
	psCreatePageviewTag("Product Assistance: For The Table", "HELP", null, null);
}
else if(G_PS_URL_PATH.toUpperCase().indexOf("PIONEERLINENS.COM/INDEX.CFM?FUSEACTION=PRODUCTASSISTANCE.PA_DOWNFEATHERBEDS")>-1)
{
	psCreatePageviewTag("Product Assistance: For The Bed:Featherbeds", "HELP", null, null);
}
else if(G_PS_URL_PATH.toUpperCase().indexOf("PIONEERLINENS.COM/INDEX.CFM?FUSEACTION=PRODUCTASSISTANCE.PA_DOWNPILLOWS")>-1)
{
	psCreatePageviewTag("Product Assistance: For The Bed:Down Pillows", "HELP", null, null);
}
else if(G_PS_URL_PATH.toUpperCase().indexOf("PIONEERLINENS.COM/INDEX.CFM?FUSEACTION=PRODUCTASSISTANCE.PA_PILLOWPROTECTORS")>-1)
{
	psCreatePageviewTag("Product Assistance: For The Bed:Pillow Protectors", "HELP", null, null);
}
else if(G_PS_URL_PATH.toUpperCase().indexOf("PIONEERLINENS.COM/INDEX.CFM?FUSEACTION=PRODUCTASSISTANCE.PA_BATHACCESSORIES")>-1
		|| G_PS_URL_PATH.toUpperCase().indexOf("PIONEERLINENS.COM/BATHACCESSORIES")>-1)
{
	psCreatePageviewTag("Product Assistance: For The Bath:Bathroom Accessories", "HELP", null, null);
}
else if(G_PS_URL_PATH.toUpperCase().indexOf("PIONEERLINENS.COM/INDEX.CFM?FUSEACTION=PRODUCTASSISTANCE.PA_SHOWERLINERS")>-1
		|| G_PS_URL_PATH.toUpperCase().indexOf("PIONEERLINENS.COM/SHOWERLINERS")>-1)
{
	psCreatePageviewTag("Product Assistance: For The Bath:Shower Liner", "HELP", null, null);
}
else if(G_PS_URL_PATH.toUpperCase().indexOf("PIONEERLINENS.COM/INDEX.CFM?FUSEACTION=PRODUCTASSISTANCE.PA_BATHTOWELS")>-1)
{
	psCreatePageviewTag("Product Assistance: For The Bath:Bath Towels", "HELP", null, null);
}
else if(G_PS_URL_PATH.toUpperCase().indexOf("PIONEERLINENS.COM/INDEX.CFM?FUSEACTION=PRODUCTASSISTANCE.PA_NAPKINFOLDING")>-1
		|| G_PS_URL_PATH.toUpperCase().indexOf("PIONEERLINENS.COM/NAPKINFOLDING")>-1)
{
	psCreatePageviewTag("Product Assistance: For The Table:Napkin Folding", "HELP", null, null);
}
else if(G_PS_URL_PATH.toUpperCase().indexOf("PIONEERLINENS.COM/INDEX.CFM?FUSEACTION=PRODUCTASSISTANCE.PA_RUNNER")>-1)
{
	psCreatePageviewTag("Product Assistance: For The Table:Table Runner", "HELP", null, null);
}
else if(G_PS_URL_PATH.toUpperCase().indexOf("PIONEERLINENS.COM/INDEX.CFM?FUSEACTION=PRODUCTASSISTANCE.PA_TABLEPADDING")>-1)
{
	psCreatePageviewTag("Product Assistance: For The Table:Table Padding", "HELP", null, null);
}
else if(G_PS_URL_PATH.toUpperCase().indexOf("PIONEERLINENS.COM/HARDTOFIND")>-1
		|| G_PS_URL_PATH.toUpperCase().indexOf("PIONEERLINENS.COM/INDEX.CFM?FUSEACTION=PRODUCTASSISTANCE.PA_HARDTOFIND")>-1)
{
	psCreatePageviewTag("Information: Hard To Find Items For Your Home", "HELP", null, null);
}
else if(G_PS_URL_PATH.toUpperCase().indexOf("PIONEERLINENS.COM/MONOGRAMMING")>-1)
{
	psCreatePageviewTag("Monogramming and Personalization", "HELP", null, null);
}
else if(G_PS_URL_PATH.toUpperCase().indexOf("PIONEERLINENS.COM/ELABORATEMONOGRAMS")>-1)
{
	psCreatePageviewTag("Elaboratemonograms", "HELP", null, null);
}
else if(G_PS_URL_PATH.toUpperCase().indexOf("PIONEERLINENS.COM/ODDSIZE")>-1)
{
	psCreatePageviewTag("Oddsize", "HELP", null, null);
}
else if(G_PS_URL_PATH.toUpperCase().indexOf("INDEX.CFM?FUSEACTION=FORMS.CONTACTUS")>-1)
{
	psCreatePageviewTag("Contact & Store Location", "HELP", null, null);
}
else if(G_PS_URL_PATH.toUpperCase().indexOf("PIONEERLINENS.COM/INDEX.CFM?")>-1)
{
	if(G_PS_URL_REFERRER.toUpperCase().indexOf("INDEX.CFM?FUSEACTION=SECURE.ADDRESSFORM&ADDRESS_ID=")>-1)
	{
		psCreatePageviewTag("Edit profile","Account",null,null);
	}
	else if(G_PS_URL_REFERRER.toUpperCase().indexOf("INDEX.CFM?FUSEACTION=SECURE.ADDRESSFORM")>-1)
	{
		psCreatePageviewTag("Add profile","Account",null,null);
	}
}
else if(psIsNoProductPage())
{
	G_PS_CUR_CATID = psGetCategoryId();
	var pageId = "NO PRODUCTS";
	var searchTerm = null;
	var searchResult = null;
	psCreatePageviewTag(pageId, G_PS_CUR_CATID, searchTerm, searchResult);
}
else if(psIsProductAssistancePage() || psIsCustomShopPage())
{
	var pageId = psGetPageId_1();
	psCreatePageviewTag(pageId, "HELP", null, null);
}
else if(G_PS_URL_PATH.toUpperCase().indexOf("PIONEERLINENS.COM/COLOR")>-1)
{
	psCreatePageviewTag("Design Guide: Color", "HELP", null, null);
}
else if(psIsDesignGuidePage())
{
	var pageId = psGetPageId_2();
	psCreatePageviewTag(pageId, "HELP", null, null);
}
else
{
	G_PS_CUR_CATID = psGetCategoryId();
	var pageId = psGetPageId(false);
	var searchTerm = null;
	var searchResult = null;
	psCreatePageviewTag(pageId, G_PS_CUR_CATID, searchTerm, searchResult);
	if(G_PS_URL_PATH.toUpperCase().indexOf("PIONEERLINENS.COM/EGYPTIANCOTTONSHEETS")>-1)
	{
		psSetCookie(G_PS_COOKIE_CATID,psGetCategoryId());
	}
	else
	{
		psHijackContent();
	}
}

/*============================ END NAVIGATION ================================*/

/*===================== BEGIN TAGGING BUSSINESS LOGIC ========================*/

function psHijackSigninForChangePassword()
{
	var inputList = document.getElementsByTagName("input");
	var inputItem = null;
	for(var i = 0; i < inputList.length; i ++ )
	{
		if(inputList[i].value.toUpperCase() == "SIGN IN")
		{
			inputItem = inputList[i];
			break;
		}
	}
	if(inputItem != null)
	{
		inputItem.oldCMFunc = inputItem.onclick();
		inputItem.onclick = function()
		{
			var profile = new psProfile();
			var objList = document.getElementsByName("username");
			profile.email = psGetElementValue(objList[0],false);
			profile.writeProfile();
			if (this.oldCMFunc != null)
			{
				return this.oldCMFunc();
			}
		}
	}
}

function psGetPageId_2()
{
	var pageId = null;
	var objList = document.getElementsByTagName("div");
	var objItem = null;
	for(var i = 0; i < objList.length; i ++ )
	{
		objItem = objList[i];
		if(objItem.className.toUpperCase() == "INTERNALCONTENTWRAPPER")
		{
			var spanList = objItem.getElementsByTagName("span");
			var spanItem = null;
			for(var j = 0; j < spanList.length; j ++ )
			{
				spanItem = spanList[j];
				if(spanItem.className.toUpperCase() == "HEADING")
				{
					pageId = psGetElementValue(spanItem,false);
				}
				if(spanItem.className.toUpperCase() == "SUBHEADING")
				{
					pageId = pageId + ":" + psGetElementValue(spanItem,false);
					break;
				}
			}
			break;
		}
	}
	return pageId;
}

function psIsDesignGuidePage()
{
	var divItem = document.getElementById("LeftMenuContainer");
	if(divItem != null)
	{
		var objList = document.getElementsByTagName("h1");
		var objItem = null;
		for(var i = 0; i < objList.length; i ++ )
		{
			objItem = objList[i];
			if(psGetInnerText(objItem) == "Creating Beautiful Beds")
			{
				return true;
			}
		}
	}
	return false;
}

/*
 * Determine if the page is the product detail page
 */
function psIsProductView()
{
	var inputList = document.getElementsByTagName("input");
	var inputItem = null;
	for(var i = 0; i < inputList.length; i ++ )
	{
		inputItem = inputList[i];
		if(inputItem.type == "hidden" && inputItem.value == "secure.addmultipleProduct")
		{
			return true;
		}
	}
	return false;
}

function psIsNoProductPage()
{
	var divList = document.getElementsByTagName("div");
	var divItem = null;
	for(var i = 0; i < divList.length; i ++ )
	{
		divItem = divList[i];
		if(divItem.className.toUpperCase() == "INTERNALCONTENTWRAPPER")
		{
			if (divItem.innerHTML.toUpperCase().indexOf("THERE ARE NO PRODUCTS AVAILABLE IN THIS GROUP.")>-1)
			return true;
		}
	}
	return false;
}

function psIsCustomShopPage()
{
	var divItem = document.getElementById("LeftMenuContainer");
	if(divItem != null)
	{
		var h1List = divItem.getElementsByTagName("h1");
		var h1Item = null;
		var lefMenuTitle = null;
		if(h1List.length == 2)
		{
			h1Item = h1List[0];
			lefMenuTitle = psGetInnerText(h1Item);
			if(lefMenuTitle.toUpperCase() == "MONOGRAMMING")
			{
				return true;
			}
		}
	}
	return false;
}

function psGetValue_1(pTagObj)
{
	var spanParentList = pTagObj.getElementsByTagName("span");
	var objItem = spanParentList[0];
	var objTitle = pTagObj;
	var objList = null;
	var spanList = null;
	while(objItem != null)
	{
		objTitle = objItem;
		spanList = objItem.getElementsByTagName("span");
		objItem = spanList[0];
	}
	if(objTitle != null)
	{
		var fontList = objTitle.getElementsByTagName("font");
		objItem = fontList[0];
		if(objItem != null)
		{
			objTitle = objItem;
			objList = objItem.getElementsByTagName("strong");
			objItem = objList[0];
			if(objItem != null)
			{
				return psGetInnerText(objItem);
			}
			else
			{
				var temp = psGetInnerText(objTitle);
				objItem = fontList[1];
				if(objItem != null)
				{
					return temp + psGetInnerText(objItem);
				}
				else
				{
					return temp;
				}
			}
		}
		else
		{
			objList = objTitle.getElementsByTagName("strong");
			objItem = objList[0];
			if(objItem!=null)
			{
				return psGetInnerText(objItem);
			}
			else
			{
				var temp = psGetElementValue(objTitle,false);
				objItem = null;
				if(objTitle.className != pTagObj.className)
				{
					objItem = objTitle.parentNode;
					spanParentList = objItem.getElementsByTagName("span");
					objItem = spanParentList[1];
				}
				if(objItem != null)
				{
					return temp + psGetElementValue(objItem,false);
				}
				else
				{
					return temp;
				}
			}
		}
	}
	return psGetElementValue(objTitle,false);
}

function psGetPageId_1()
{
	var pageId = null;
	var objList = document.getElementsByTagName("div");
	var objItem = null;
	var spanList = null;
	var spanItem = null;
	for(var i = 0; i < objList.length; i ++ )
	{
		objItem = objList[i];
		if(objItem.className.toUpperCase() == "INTERNALCONTENTWRAPPER")
		{
			spanList = objItem.getElementsByTagName("span");
			for(var j = 0; j < spanList.length; j ++ )
			{
				spanItem = spanList[j];
				if(spanItem.className.toUpperCase() == "HEADING")
				{
					pageId = psGetValue_1(spanItem);
					break;
				}
			}
			
			var bqList = objItem.getElementsByTagName("blockquote");
			var bqItem = bqList[0];
			if(bqItem != null)
			{
				spanList = bqList[0].getElementsByTagName("span");
				var spanSubTitle = null;
				for(var j = 0; j < spanList.length; j ++ )
				{
					spanItem = spanList[j];
					if(spanItem.className.toUpperCase() == "SUBHEADING")
					{
						spanSubTitle = spanList[j];
						break;
					}
				}
				
				if(spanSubTitle != null)
				{
					pageId = pageId + ":" + psGetValue_1(spanSubTitle);
				}
			}
			break;
		}
	}
	if(pageId == null)
	{
		pageId = G_PS_PATHNAME;
	}
	return pageId;
}

function psIsProductAssistancePage()
{
	var divItem = document.getElementById("LeftMenuContainer");
	if(divItem != null)
	{
		var h1List = divItem.getElementsByTagName("h1");
		var h1Item = null;
		var lefMenuTitle = null;
		if(h1List.length == 1)
		{
			h1Item = h1List[0];
			lefMenuTitle = psGetInnerText(h1Item);
			if(lefMenuTitle.toUpperCase() == "PRODUCT ASSISTANCE")
			{
				return true;
			}
		}
	}
	return false;
}

function psHijackRegister()
{
	var objList = document.getElementsByTagName("input");
	var objItem = null;
	var btnItem = null;
	for(var i = 0; i < objList.length; i ++ )
	{
		objItem = objList[i];
		if(objItem.value.toUpperCase() == "SUBMIT REGISTRATION INFORMATION")
		{
			btnItem = objItem;
			break;
		}
	}
	if(btnItem != null)
	{
		var oldCMFunc = btnItem.onclick();
		btnItem.onclick = function()
		{
			var profile = new psProfile();
			profile.email = psGetElementValueById("email",false);
			profile.city = psGetElementValueById("City",false);
			objList = document.getElementsByName("CountryOption");
			var isUsa = false;
			for(var i = 0; i < objList.length; i ++ )
			{
				objItem = objList[i];
				if(objItem.checked)
				{
					if (objItem.value.toUpperCase() == "USA")
					{
						isUsa = true;
					}
					break;
				}
			}
			if(isUsa)
			{
				profile.country = "USA";
				profile.state = psGetElementValue(document.getElementsByName("selectState")[0],true);
			}
			else
			{
				profile.country = psGetElementValue(document.getElementsByName("Country")[0],false);
				profile.state = psGetElementValue(document.getElementsByName("State")[0],false);
			}
			profile.zipcode = psGetElementValueById("ZIP",false);
			profile.referredBy = psGetElementValue(document.getElementsByName("referred_by")[0],true);
			profile.writeProfile();
			if (oldCMFunc != null)
			{
				return oldCMFunc();
			}
		}
	}
}

function psHijackSignin()
{
	var btnList = document.getElementsByTagName("button");
	var btnItem = null;
	var btnSignin = null;
	for(var i = 0; i < btnList.length; i ++ )
	{
		btnItem = btnList[i];
		if(btnItem.className.toUpperCase()=="SUBMITBTN" && btnItem.value.toUpperCase().indexOf("SIGN IN AND CHECKOUT")>-1)
		{
			btnSignin = btnItem;
			break;
		}
	}
	if (btnSignin != null)
	{
		var oldCMFunc = btnSignin.onclick();
		btnSignin.onclick = function()
		{
			var profile = new psProfile();
			var objList = document.getElementsByName("username");
			var objItem = objList[i];
			profile.email = psGetElementValue(objItem,false);
			profile.writeProfile();
			if (oldCMFunc != null)
			{
				return oldCMFunc();
			}
		}
	}
}

/*
 * Process to post shop9tags for items purchased
 */
function psPostOrderView()
{
	//send Registration tag
	var profile = new psProfile();
	profile.readProfile();
	psCreateRegistrationTag(profile.email,profile.email,profile.city,profile.state,profile.zipcode,profile.country,profile.newsletter,profile.subscribe,profile.referredBy,profile.purchasingFor);
	
	var orderId = null;
	var orderSubtotal = 0;
	var orderShipping = null;
	var orderCusId = null;
	
	//Get orderId
	var tblItem_1 = null;
	var cellList = document.getElementsByTagName("td");
	var cellItem = null;
	var rowItem = null;
	for(var i = 0; i < cellList.length; i ++ )
	{
		if(psGetInnerText(cellList[i]).toUpperCase() == "ORDER CONFIRMATION")
		{
			cellItem = cellList[i];
			break;
		}
	}
	if(cellItem != null)
	{
		rowItem = cellItem.parentNode;
		cellItem = rowItem.cells[1];
		orderId = psGetInnerText(cellItem);
		var se = /Order\s*#\s*(\d*)/gi;
		orderId = (orderId.search(se)>-1)? RegExp.$1:orderId;
	}
	
	//Get orderShipping
	var strongList = document.getElementsByTagName("strong");
	var strongItem = null;
	for(var i = 0; i < strongList.length; i ++ )
	{
		if(psGetInnerText(strongList[i]).toUpperCase() == "SHIPPING TOTAL:")
		{
			strongItem = strongList[i];
			break;
		}
	}
	if(strongItem != null)
	{
		cellItem = strongItem.parentNode;
		rowItem = cellItem.parentNode;
		cellItem = rowItem.cells[rowItem.cells.length-1];
		orderShipping = psGetInnerText(cellItem);
		orderShipping = orderShipping.replace("$","");
		orderShipping = psCleanPrice(orderShipping);
	}
	
	//Get orderSubtotal
	strongItem = null;
	for(var i = 0; i < strongList.length; i ++ )
	{
		if(psGetInnerText(strongList[i]).toUpperCase() == "ORDER TOTAL:")
		{
			strongItem = strongList[i];
			break;
		}
	}
	if(strongItem != null)
	{
		cellItem = strongItem.parentNode;
		rowItem = cellItem.parentNode;
		cellItem = rowItem.cells[1];
		orderSubtotal = psGetInnerText(cellItem);
		orderSubtotal = orderSubtotal.replace("$","");
		orderSubtotal = psCleanPrice(orderSubtotal);
		orderSubtotal = parseFloat(orderSubtotal) - parseFloat(orderShipping);
	}
	
	//Send shop9 tags
	cellItem = null;
	for(var i = 0; i < cellList.length; i ++ )
	{
		if(psGetInnerText(cellList[i]).toUpperCase() == "QUANTITY")
		{
			cellItem = cellList[i];
			break;
		}
	}
	if(cellItem != null)
	{
		rowItem = cellItem.parentNode;
		tblItem_1 = rowItem.parentNode;
		var productIdList = new Array();
		var productNameList = new Array();
		var quantityList = new Array();
		var priceList = new Array();
		var objList = null;
		var objItem = null;
		var temp = null;
		rowItem = null;
		cellItem = null;
		rowItem = tblItem_1.rows[tblItem_1.rows.length-3];
		if(rowItem != null)
		{
			cellItem = rowItem.cells[rowItem.cells.length - 2];
		}
		if(psGetInnerText(cellItem).toUpperCase().indexOf("ELITE SHOPPER DISCOUNT:")>-1)
		{
			temp = tblItem_1.rows.length-3;
		}
		else
		{
			rowItem = tblItem_1.rows[tblItem_1.rows.length-2];
			cellItem = rowItem.cells[rowItem.cells.length - 2];
			var strTemp = psGetInnerText(cellItem);
			if(strTemp.toUpperCase().indexOf("ELITE SHOPPER DISCOUNT:")>-1
				|| strTemp.toUpperCase().indexOf("PROMOTION")>-1)
			{
				temp = tblItem_1.rows.length-2;
			}
			else
			{
				temp = tblItem_1.rows.length-1;
			}
		}
		for(var i = 1; i < temp; i ++ )
		{
			rowItem = tblItem_1.rows[i];
			cellItem = rowItem.cells[0];
			var strongList = cellItem.getElementsByTagName("strong");
			productNameList.push(psGetInnerText(strongList[0]));
			cellItem = rowItem.cells[1];
			priceList.push(psGetInnerText(cellItem).replace("$",""));
			objList = cellItem.getElementsByTagName("input");
			objItem = objList[0];
			productIdList.push(psGetElementValue(objItem,false));
			cellItem = rowItem.cells[2];
			quantityList.push(psGetInnerText(cellItem));
		}
		
		var productIdList_1 = new Array();
		var productNameList_1 = new Array();
		var quantityList_1 = new Array();
		var priceList_1 = new Array();
		var productId = null;
		for(var i = 0; i < productIdList.length; i ++ )
		{
			productId = productIdList[i];
			var itemTemp = null;
			var isDuplicate = false;
			var index = null;
			for(var j = 0; j < productIdList_1.length; j ++ )
			{
				itemTemp = productIdList_1[j];
				if(itemTemp == productId)
				{
					index = j;
					isDuplicate = true;
					break;
				}
			}
			if(isDuplicate)
			{
				quantityList_1[index] = parseInt(quantityList_1[index]) + parseInt(quantityList[i]);
			}
			else
			{
				productIdList_1.push(productIdList[i]);
				productNameList_1.push(productNameList[i]);
				quantityList_1.push(quantityList[i]);
				priceList_1.push(priceList[i]);
			}
		}
		var catId = null;
		for(var i = 0; i < productIdList_1.length; i ++ )
		{
			productId = productIdList_1[i];
			catId = psGetValueFromCookie(G_PS_COOKIE_PROD_CATID,productId);
			psCreateShopAction9Tag(productIdList_1[i], productNameList_1[i], quantityList_1[i], priceList_1[i], profile.email, orderId, orderSubtotal, catId);
		}
		
		// Make sure to have actual postings
		psDisplayShop9s();
		// Post order tag finally
		psCreateOrderTag(orderId, orderSubtotal, orderShipping, profile.email, profile.city, profile.state, profile.zipcode);
		// Delete cookie after checking successfully
		psSetCookie(G_PS_COOKIE_PROD_CATID, "", "delete");
	}
}

function psStoreProfileOnShippingPage()
{
	var inputItem = document.getElementById("sameAddressYes");
	if(inputItem!=null)
	{
		var profile = new psProfile();
		var profile_1 = new psProfile();
		profile_1.readProfile();
		if(profile_1.email == null || profile_1.email == "")
		{
			profile.email = psGetElementValueById("email",false);
		}
		else
		{
			profile.email = profile_1.email;
		}
		var selectItem = null;
		var objList  = null;
		var objItem = null;
		if(inputItem.checked)
		{	
			profile.city = psGetElementValueById("ShipCity",false);
			var isUsa = false;
			objList = document.getElementsByName("ShipCountryOption");
			for(var i = 0; i < objList.length; i ++ )
			{
				objItem = objList[i];
				if(objItem.checked)
				{
					if(psGetElementValue(objItem,false).toUpperCase()=="USA")
					{
						isUsa = true;
					}
					break;
				}
			}
			if(isUsa)
			{
				profile.country = "USA";
				selectItem = document.getElementsByName("selectShipState")[0];
				profile.state = psGetElementValue(selectItem,true);
			}
			else
			{
				profile.country = psGetElementValueById("ShipCountry",false);
				profile.state = psGetElementValueById("ShipState",false);
			}
			profile.zipcode = psGetElementValueById("ShipZIP",false);
		}
		else
		{
			profile.city = psGetElementValueById("City",false);
			var isUsa = false;
			objList = document.getElementsByName("CountryOption");
			for(var i = 0; i < objList.length; i ++ )
			{
				objItem = objList[i];
				if(objItem.checked)
				{
					if(psGetElementValue(objItem,false)=="USA")
					{
						isUsa = true;
					}
					break;
				}
			}
			if(isUsa)
			{
				profile.country = "USA";
				selectItem = document.getElementsByName("selectState")[0];
				profile.state = psGetElementValue(selectItem,true);
			}
			else
			{
				profile.country = psGetElementValueById("Country",false);
				profile.state = psGetElementValueById("State",false);
			}
			profile.zipcode = psGetElementValueById("ZIP",false);
		}
		profile.referredBy = psGetElementValueById("referred_by",true);
		objList = document.getElementsByName("PurchasingFor");
		for(var i = 0; i < objList.length; i ++ )
		{
			objItem = objList[i];
			if(objItem.checked)
			{
				profile.purchasingFor = psGetElementValue(objItem,false);
				break;
			}
		}
		profile.newsletter = "e-mail from Pioneer Linens about special offers, sales, new products, and promotions";
		var subscribe = document.getElementById("subscribe");
		if(subscribe != null)
		{
			profile.subscribe = subscribe.checked ? "Y":"N";
		}
		profile.writeProfile();
	}
}

function psHijackForShippingPage()
{
	var btnItem = document.getElementById("ContinueCheckoutButton");
	if(btnItem != null)
	{
		var oldCMFunc = btnItem.onclick();
		btnItem.onclick = function()
		{
			psStoreProfileOnShippingPage();
			if (oldCMFunc != null)
			{
				return oldCMFunc();
			}
		}
	}
}

/*
 * Process to post shop5tags for items in shopping cart
 */
function psPostCartView()
{
	var productId = null;
	var productName = null;
	var price = null;
	var quantity = null;
	var catId = null;
	
	var divList = null;
	var inputList = null;
	var inputItem = null;
	var objList = null;
	var objItem = null;
	
	var productIdList = new Array();
	var productNameList = new Array();
	var quantityList = new Array();
	var priceList = new Array();
	
	objList = document.getElementsByName("product_id");
	for(var i = 0; i < objList.length; i ++ )
	{
		objItem = objList[i];
		productIdList.push(psGetElementValue(objItem,false));
	}
	
	objList = document.getElementsByTagName("div");
	for(var i = 0; i < objList.length; i ++ )
	{
		objItem = objList[i];
		if(objItem.className.toUpperCase() == "PRODUCTTITLE")
		{
			productNameList.push(psGetInnerText(objItem));
		}
	}
	
	objList = document.getElementsByTagName("td");
	
	var index = 0;
	for(var i = 0; i < objList.length; i ++ )
	{
		objItem = objList[i];
		if(objItem.className.toUpperCase() == "CARTITEM PRICE")
		{
			if (index%2 == 0)
			{
				priceList.push(psGetInnerText(objItem).replace("$",""));
			}
			index++;
		}
		else if(objItem.className.toUpperCase() == "CARTITEM QUANTITY")
		{
			inputList = objItem.getElementsByTagName("input");
			quantityList.push(psGetElementValue(inputList[0],false));
		}
	}
	
	var productIdList_1 = new Array();
	var productNameList_1 = new Array();
	var quantityList_1 = new Array();
	var priceList_1 = new Array();
	for(var i = 0; i < productIdList.length; i ++ )
	{
		productId = productIdList[i];
		var itemTemp = null;
		var isDuplicate = false;
		var index = null;
		for(var j = 0; j < productIdList_1.length; j ++ )
		{
			itemTemp = productIdList_1[j];
			if(itemTemp == productId)
			{
				index = j;
				isDuplicate = true;
				break;
			}
		}
		if(isDuplicate)
		{
			quantityList_1[index] = parseInt(quantityList_1[index]) + parseInt(quantityList[i]);
		}
		else
		{
			productIdList_1.push(productIdList[i]);
			productNameList_1.push(productNameList[i]);
			quantityList_1.push(quantityList[i]);
			priceList_1.push(priceList[i]);
		}
	}
	
	
	for(var i = 0; i < productIdList_1.length; i ++ )
	{
		productId = productIdList_1[i];
		catId = psGetValueFromCookie(G_PS_COOKIE_PROD_CATID,productId);
		if(catId == null)
		{
			catId = "UNKNOWN";
		}
		psCreateShopAction5Tag(productId, productNameList_1[i], quantityList_1[i], priceList_1[i], catId);
	}
	
	// Make sure to have actual postings
	psDisplayShop5s();
}

// Store categoryId when add product to cart in the product view page
function psStoreCatId(pCatId)
{
	var arrProductId = new Array();
	var inputList = document.getElementsByTagName("input");
	var productIdList = new Array();
	var quantityList = new Array();
	var inputItem = null;
	for(var i = 0; i < inputList.length; i ++ )
	{
		inputItem = inputList[i];
		if(inputItem.name.toUpperCase() == "PRODUCT_ID")
		{
			productIdList.push(psGetElementValue(inputItem,false));
		}
		else if(inputItem.className.toUpperCase() == "QUANTYBOX")
		{
			quantityList.push(psGetElementValue(inputItem,false));
		}
	}
	for(var i = 0; i < productIdList.length; i ++ )
	{
		if(quantityList[i] > 0)
		{
			psSetValueToCookie(G_PS_COOKIE_PROD_CATID,productIdList[i],pCatId);
		}
	}
}

//Hijack the "Add to cart" button 
function psHijackForProductViewPage(pCatId)
{
	var formList = document.getElementsByTagName("form");
	var formItem = null;
	for(var i = 0; i < formList.length; i ++ )
	{
		formItem = formList[i];
		if(formItem.name.toUpperCase() == "FRM")
		{
			formItem.onsubmit = function()
			{
				if(checkQty(this))
				{
					psStoreCatId(pCatId);
					return true;
				}
				else
				{
					return false;
				}
			}
			break;
		}
	}
}

function psIsNoItem()
{
	var inputList = document.getElementsByTagName("input");
	var inputItem = null;
	for(var i = 0; i < inputList.length; i ++ )
	{
		inputItem = inputList[i];
		if(inputItem.name.toUpperCase() == "PRODUCT_ID")
		{
			return false;
		}
	}
	return true;
}
/*
 * Process to post productview tag for the item in product detail
 */
function psPostProductView(pCatId)
{
	var inputList = document.getElementsByTagName("input");
	var productIdList = new Array();
	var inputItem = null;
	for(var i = 0; i < inputList.length; i ++ )
	{
		inputItem = inputList[i];
		if(inputItem.name.toUpperCase() == "PRODUCT_ID")
		{
			productIdList.push(psGetElementValue(inputItem,false));
		}
	}
	
	var divList = document.getElementsByTagName("div");
	var productNameList = new Array();
	var divItem = null;
	for(var i = 0; i < divList.length; i ++ )
	{
		divItem = divList[i];
		if(divItem.className.toUpperCase() == "PRODUCTTITLE")
		{
			productNameList.push(psGetInnerText(divItem));
		}
	}
	var productId = null;
	var productName = null;
	for(var i = 0; i < productIdList.length; i ++ )
	{
		productId = productIdList[i];
		productName = productNameList[i];
		psCreateProductviewTag(productId,productName,pCatId);
	}
}

function psGetPageIdForProductView()
{
	var pPageId = null;
	var pList = document.getElementsByTagName("p");
	var pItem = null;
	for(var i = 0; i < pList.length; i ++ )
	{
		pItem = pList[i];
		if(pItem.className.toUpperCase() == "HEADING2")
		{
			pPageId = psGetInnerText(pItem);
			break;
		}
	}
	if(pPageId != null)
	{
		pPageId = pPageId.toUpperCase();
	}
	pPageId = psHtmlDecode(pPageId);
	return pPageId;
}

function psIsDesignerPage()
{
	var divItem = document.getElementById("LeftMenuContainer");
	if(divItem != null)
	{
		var h1List = divItem.getElementsByTagName("h1");
		var h1Item = null;
		var lefMenuTitle = null;
		if(h1List.length > 1)
		{
			return false;
		}
		else if(h1List.length == 1)
		{
			h1Item = h1List[0];
			lefMenuTitle = psGetInnerText(h1Item);
		}
		
		var divList = document.getElementsByTagName("div");
		var divItem = null;
		var divTitle = null;
		var pageTitle = null;
		for(var l = 0; l < divList.length; l ++ )
		{
			divItem = divList[l];
			if(divItem.className.toUpperCase() == "ALTSUBHEADING")
			{
				divTitle = divList[l];
				break;
			}
		}
		if(divTitle != null)
		{
			pageTitle = psGetInnerText(divTitle);
		}
		if(lefMenuTitle!=null && pageTitle!= null && lefMenuTitle == pageTitle)
		{
			return true;
		}
	}
	return false;
}

function psIsTopMenuPage()
{
	var divItem = document.getElementById("ProductImageWrapper");
	if(divItem != null)
	{
		return true;
	}
	return false;
}

function psGetCategoryId()
{
	var pCatId = null;
	var divItem = document.getElementById("LeftMenuContainer");
	if(divItem != null)
	{
		var h1List = divItem.getElementsByTagName("h1");
		var h1Item = null;
		var lefMenuTitle = null;
		if(h1List.length == 1)
		{
			h1Item = h1List[0];
			lefMenuTitle = psGetInnerText(h1Item);
			if(lefMenuTitle.toUpperCase() == "SHOP WITH CONFIDENCE")
			{
				pCatId = "Customer Service";
			}
			else if(lefMenuTitle.toUpperCase() == "ABOUT US" || lefMenuTitle.toUpperCase() == "PRODUCT ASSISTANCE")
			{
				pCatId = "Help";
			}
			else if(lefMenuTitle.toUpperCase() == "ON SALE")
			{
				pCatId = "Outlet";
			}
			else if(lefMenuTitle.toUpperCase() == "GIFT IDEAS")
			{
				pCatId = "Gifts";
			}
			else
			{
				pCatId = lefMenuTitle;
			}
		}
		else
		{
			for(var i = 0; i < h1List.length; i ++ )
			{
				h1Item = h1List[i];
				lefMenuTitle = psGetInnerText(h1Item);
				lefMenuTitle = psHtmlDecode(lefMenuTitle);
				if(lefMenuTitle.toUpperCase() == "BEDROOM ACCESSORIES")
				{
					pCatId = "Bed Linens";
					break;
				}
				else if(lefMenuTitle.toUpperCase() == "BATHROOM ACCESSORIES")
				{
					pCatId = "Bath";
					break;
				}
				else if(lefMenuTitle.toUpperCase() == "TABLECLOTHS")
				{
					pCatId = "Table";
					break;
				}
				else if(lefMenuTitle.toUpperCase() == "HOME ACCENTS")
				{
					pCatId = "Home Decor";
					break;
				}
				else if(lefMenuTitle.toUpperCase() == "HOME & DINING")
				{
					pCatId = "Yacht";
					break;
				}
			}
		}
	}
	if(pCatId == null)
	{
		var divItem = document.getElementById("SEOText");
		if(divItem != null)
		{
			if(psGetInnerText(divItem).toUpperCase().indexOf("YACHT LINENS DIVISION")>-1)
			{
				pCatId = "Yacht";
			}
		}
	}
	if(pCatId == null)
	{
		pCatId = psGetCookie(G_PS_COOKIE_CATID);
		psSetCookie(G_PS_COOKIE_CATID,"","delete");
	}
	if(pCatId == null)
	{
		pCatId = "HELP";
	}
	if(pCatId != null)
	{
		pCatId = pCatId.toUpperCase();
	}
	return pCatId;
}

function psHijackContent()
{
	var spanList = document.getElementsByTagName("span");
	var spanItem = null;
	var spanTitle = null;
	var cookieValue = null;
	for(var l = 0; l < spanList.length; l ++ )
	{
		spanItem = spanList[l];
		if(spanItem.className.toUpperCase() == "ALTSUBHEADING")
		{
			spanTitle = spanList[l];
			break;
		}
	}
	if(spanTitle != null)
	{
		cookieValue = psGetInnerText(spanTitle);
	}
	psSetCookie(G_PS_COOKIE_CATID,cookieValue);
}

function psGetPageId(pIsTopMenuPage)
{
	var pageId = null;
	if(pIsTopMenuPage)
	{
		pageId = G_PS_PATHNAME.toUpperCase().replace("/","");
	}
	else
	{
		var divList = null;
		var divItem = null;
		var divTitle = null;
		var spanList = document.getElementsByTagName("span");
		var spanItem = null;
		var spanTitle = null;
		for(var i = 0; i < spanList.length; i ++ )
		{
			spanItem = spanList[i];
			if(spanItem.className.toUpperCase() == "ALTSUBHEADING")
			{
				spanTitle = spanList[i];
				break;
			}
		}
		if(spanTitle != null)
		{
			pageId = psGetInnerText(spanTitle).toUpperCase();
		}
		if(pageId == null)
		{
			divList = document.getElementsByTagName("div");
			for(var i = 0; i < divList.length; i ++ )
			{
				divItem = divList[i];
				if(divItem.className.toUpperCase() == "ALTSUBHEADING")
				{
					divTitle = divList[i];
					break;
				}
			}
			if(divTitle != null)
			{
				pageId = psGetInnerText(divTitle);
			}
		}
		if(pageId == null)
		{
			divList = document.getElementsByTagName("div");
			for(var i = 0; i < divList.length; i ++ )
			{
				divItem = divList[i];
				if(divItem.className.toUpperCase() == "INTERNALCONTENTWRAPPER")
				{
					spanList = divItem.getElementsByTagName("span");
					pageId = psGetInnerText(spanList[0]);
					break;
				}
			}
		}
		if(pageId == null)
		{
			divItem = null;
			divItem = document.getElementById("ContentContainer");
			if(divItem != null)
			{
				spanList = divItem.getElementsByTagName("span");
				pageId = psGetInnerText(spanList[0]);
			}
		}
		if(pageId == null)
		{
			pageId = G_PS_PATHNAME;
		}
	}
	pageId = psHtmlDecode(pageId);
	return pageId;
}

function psHijackLeftMenus()
{
	if(G_PS_URL_PATH.toUpperCase().indexOf("GO.PIONEERLINENS.COM")>-1)
	{
		return false;
	}
	var menuDiv = document.getElementById("LeftMenuContainer");
	if(menuDiv != null)
	{
		var aList = menuDiv.getElementsByTagName("a");
		for(var i = 0; i < aList.length; i ++ )
		{
			var aItem = aList[i];
			if(aItem.href != "" || aItem.href != null)
			{
				aItem.oldCMFunc = aItem.onclick;
				aItem.onclick = function()
				{
					psSetCookie(G_PS_COOKIE_CATID,psGetCategoryId());
					if (this.oldCMFunc != null)
					{
						return this.oldCMFunc();
					}
				}
			}
		}
	}
}

function psPostSearchView_1()
{
	// Your logic of throwing pageview tag for search functionalities goes here
	G_PS_CUR_CATID = "SEARCH";
	var pageId = null;
	var searchTerm = null;
	var searchResult = null;
	var divList = document.getElementsByTagName("div");
	for(var i=0; i<divList.length; i++)
	{
		if(divList[i].className.toUpperCase() == "PRODUCTCONTENTAREA")
		{
			var objList = divList[i].getElementsByTagName("div");
			var divItem = objList[0];
			if(divItem != null)
			{
				var bList = divItem.getElementsByTagName("b");
				if(psCheckElementExist(bList[2]))
				{
					pageId = "SEARCH SUCCESSFUL";
					searchResult = psGetInnerText(bList[1]);
					searchTerm = psGetInnerText(bList[2]);
					objList = document.getElementsByTagName("span");
					for(var j=0; j<objList.length; j++)
					{
						if(psIsEqual(objList[j].className,"pageselectoractive"))
						{
							pageId = pageId + " Page " + psGetInnerText(objList[j]);
							break;
						}
					}
				}
			}
			break;
		}
		
	}
	if (pageId != null)
	{
		psCreatePageviewTag(pageId, G_PS_CUR_CATID, searchTerm, searchResult);
		psSetCookie(G_PS_COOKIE_CATID,G_PS_CUR_CATID);
	}
}

function psGetRefinementForSearch(pRefinementId)
{
	var divItem = document.getElementById(pRefinementId);
	if(divItem != null)
	{
		var divList = divItem.getElementsByTagName("div");
		for(var i=0; i<divList.length; i++)
		{
			if(psIsEqual(divList[i].className,"sli_facet_active"))
			{
				var refinement = psGetInnerText(divList[i],false);
				if(refinement.indexOf("(")>-1 && refinement.indexOf(")")>-1)
				{
					refinement = refinement.substring(0,refinement.indexOf("("));
				}
				return psTrim(refinement);
			}
		}
	}
	return null;
}

function psAdjustThreadcount(pThreacount)
{
	var result = pThreacount;
	var pattern = /([0-9]+)(thread)(count)/gi;
	if (pThreacount.search(pattern) > -1)
	{
		result = RegExp.$1 + " " + RegExp.$2 + " " + RegExp.$3;
	}
	return result;
}

function psPostSearchView()
{
	// Your logic of throwing pageview tag for search functionalities goes here
	G_PS_CUR_CATID = "SEARCH";
	var pageId = null;
	var searchTerm = psGetValueFromUrl(G_PS_QUERYSTRING,"w");
	var searchResult = null;
	var divList = document.getElementsByTagName("div");
	for(var i=0; i<divList.length; i++)
	{
		if(divList[i].className.toUpperCase() == "PRODUCTCONTENTAREA")
		{
			var objList = divList[i].getElementsByTagName("div");
			var divItem = objList[0];
			if(divItem != null)
			{
				var bList = divItem.getElementsByTagName("b");
				if(psCheckElementExist(bList[0]))
				{
					if(psGetInnerText(bList[0])== 0)
					{
						pageId = "SEARCH UNSUCCESSFUL";
						searchResult = 0;
					}
					else
					{
						pageId = "SEARCH SUCCESSFUL";
						if(psCheckElementExist(bList[1]))
						{
							searchResult = psGetInnerText(bList[1]);
						}
						var refinement = psGetValueFromUrl(G_PS_QUERYSTRING,"af");
						if(refinement!=null && refinement!="")
						{
							refinement = psHtmlDecode(refinement);
							refinement = refinement.split(" ");
							pageId = refinement[0];
							var priceAct = null;
							if(pageId.search(/price/)>-1)
							{
								priceAct = psGetRefinementForSearch("facet_price_static");
								var temp = pageId.split(":");
								temp = temp[1];
								if(temp!=null)
								{
									pageId = pageId.replace(temp,priceAct);
								}
							}
							
							refinement = refinement[0];
							if(refinement!=null)
							{
								refinement = refinement.split(":");
								if(refinement[0]!=null && psIsEqual(refinement[0],"price"))
								{
									refinement = priceAct;
								}
								else if(refinement[0]!=null && psIsEqual(refinement[0],"threadcount"))
								{
									if(psGetRefinementForSearch("facet_bedsize_static")==null)
									{
										refinement = "BedSize:All";
										pageId = "BedSize:All";
									}
									else
									{
										refinement = psGetRefinementForSearch("facet_bedsize_static") + ":" + psAdjustThreadcount(refinement[1]);
									}
								}
								else
								{
									refinement = refinement[1];
								}
							}
							
							if(refinement != null)
							{
							    if(pageId.toLowerCase().indexOf("threadcount")==0 || psIsEqual(pageId,"BedSize:All"))
								{
									G_PS_CUR_CATID = refinement;
								}
								else
								{
									G_PS_CUR_CATID = "Refinement:" + refinement;
								}
							}
						}
						objList = document.getElementsByTagName("span");
						for(var j=0; j<objList.length; j++)
						{
							if(psIsEqual(objList[j].className,"pageselectoractive"))
							{
								pageId = pageId + (psGetInnerText(objList[j])=="1" ? "":(" Page " + psGetInnerText(objList[j])));
								break;
							}
						}
						var temp = psGetValueFromUrl(G_PS_QUERYSTRING,"af");
						if((psIsEqual(psGetDomain(G_PS_URL_REFERRER), "GO.PIONEERLINENS.COM")&& (G_PS_URL_PATH.toUpperCase().indexOf("SEARCH?W=" + searchTerm.toUpperCase())<0) && G_PS_URL_REFERRER.toUpperCase().indexOf("W=" + searchTerm.toUpperCase())>-1)
							|| pageId.toUpperCase().indexOf("PAGE")>-1 || (temp!="" && temp!=null))
						{
							searchTerm = null;
							searchResult = null;
						}
					}
				}
			}
			break;
		}
		
	}
	if (pageId != null)
	{
		psCreatePageviewTag(pageId, G_PS_CUR_CATID, searchTerm, searchResult);
		psSetCookie(G_PS_COOKIE_CATID,G_PS_CUR_CATID);
	}
}

/*====================== END TAGGING BUSSINESS LOGIC =========================*/

/*======================= GENERAL UTILITY FUNCTION ===========================*/
/* 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;
	this.country = null;
	this.newsletter = null;
	this.subscribe = null;
	this.referredBy = null;
	this.purchasingFor = null;
	/*
	 * Get user profile from cookie
	 */
	this.readProfile = function()
	{
		try
		{
			this.email = psGetCookie(G_PS_COOKIE_PROFILE);
			if (this.email != null)
			{
				var buf = this.email.split('|');
				for (var i=0; i<buf.length; i++)
				{
					var tempVal = buf[i];
					// when NULL is written to cookie, it becomes string, not literal constant
					buf[i] = (tempVal=="null" ? null : tempVal); 
				}
				this.email = buf[0];
				this.city = buf[1];
				this.state = buf[2];
				this.zipcode = buf[3];
				this.country = buf[4];
				this.newsletter = buf[5];
				this.subscribe = buf[6];
				this.referredBy = buf[7];
				this.purchasingFor = buf[8];
			}
			return true;
		}
		catch (ex) { return false; }
	}
	/*
	 * 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 + '|' + this.country + '|' + this.newsletter + '|' + this.subscribe + '|' + this.referredBy + '|' + this.purchasingFor ;
		// store on cookie
		psSetCookie(G_PS_COOKIE_PROFILE, data);
	}
}

function psCheckElementExist(pElement)
{
    if(typeof(pElement) == "undefined" || pElement == null)
    {
        return false;
    }

    return true;
}

/* PURPOSE: Compare case-insensitive strings
 * RETURN: true: strings are not null and the same
 *         false: any of the string is null or not the same
 */

function psIsEqual()
{
	for (var i=0; i<arguments.length; i++)
	{
		if(arguments[0] == null || arguments[i] == null)
		{
			return false;
		}
		else if(arguments[0].toUpperCase() != arguments[i].toUpperCase())
		{
			return false;
		}
	}
	return true;
}


/* 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 pTagOjb.innerHTML.replace(/\<+.+?\>+/g, "");
		else
			return pTagOjb.replace(/\<+.+?\>+/g, "");
	}
	return null;
}

/* PURPOSE: Remove all unaccepted characters in categoryid, including
 * [, ', ", :, comma,]
 * 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
 * RETURN: string
 */
function psTrim(pStr)
{
	if (pStr == null || typeof(pStr) != "string")
					return pStr;
	return (pStr) ? pStr.replace(/&nbsp;|\u00A0/gi, ' ').replace(/^\s+|\s+$/g, '') : null;
}

/* 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: returns the value of an element based on element_id
 * @pValueFlag: TRUE means VALUE  attribute of SELECT object returned, not innerHTML
 * RETURN: 
 *  Normal tag: decoded innerHTML
 *  INPUT tag: value attribute
 *  SELECT tag: decoded label of the selected option
 */
function psGetElementValueById(pTagId, pValueFlag)
{
    var tag = document.getElementById(pTagId);
    return psGetElementValue(tag, pValueFlag);
}

/* PURPOSE: returns the value of an element based on element object
 * Note: this function returns decoded text
 * to avoid "double" decode, don't invoke psHtmlDecode on returned value again
 * @pValueFlag: TRUE means VALUE  attribute of SELECT object returned, not innerHTML
 * RETURN: 
 *  Normal tag: decoded innerHTML
 *  INPUT tag: value attribute
 *  SELECT tag: decoded label of the selected option
 *  NULL: if element not exist
 */
function psGetElementValue(pTagObj, pValueFlag)
{
    var tagValue = null;
    if (pTagObj != null)
    {
        if (pTagObj.tagName.search(/^INPUT$/i) > -1)
            tagValue = pTagObj.value;
        else if (pTagObj.tagName.search(/^SELECT$/i) > -1)
        {
            if (pValueFlag == true)
                tagValue = pTagObj.options[pTagObj.selectedIndex].value;
            else
                tagValue = psHtmlDecode(pTagObj.options[pTagObj.selectedIndex].innerHTML);// return label instead of value
        }
        else
            tagValue = psHtmlDecode(pTagObj.innerHTML);
    }

    return tagValue;
}

/* PURPOSE: validate email format
 * RETURN: boolean
 */
function psCheckEmail(pEmail) 
{
    if (pEmail)
    {
        var i = pEmail.search(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/);
        return (i > -1);
    }

    return false;
}

/* 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: extract domain part in the URL
 * RETURN: domain
 */
function psGetDomain(pUrl){
    var se = /^https*\:\/\/([^\/]+)/gi;
    return (pUrl.search(se) > -1) ? RegExp.$1 : null;
}

/* PURPOSE: remove unnecessary characters (dollar sign, comma, quote, minus, etc) 
 * from price to make it work properly with parseFloat/parseInt
 * RETURN: well-formed price
 */
function psCleanPrice(pPrice)
{
	var pattern = /[^0-9\.]/gi;
	return (pPrice != null ? pPrice.toString().replace(pattern, "") : null);
}



/* PURPOSE: retrieve cookie value
 * RETURN: string
 */
function psGetCookie(pCookieName)
{
	var cookies = document.cookie;
	if (!pCookieName || !cookies)
		return null;

	cookies = "; " + cookies.toLowerCase();
	var key = "; " + pCookieName.toLowerCase() + "=";
	var start = cookies.lastIndexOf(key);
	if (start >= 0)
	{
		start = start + key.length;
		var end = cookies.indexOf(";", start);
		if (end == -1)
			end = cookies.length;

		return unescape(cookies.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;
	pDomain = ".pioneerlinens.com";
	if(pLifeTime == "delete") 
    {         
        CC(pCookieName, pDomain);//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
 * RETURN: string
 * NOTE: Use null or '' for pValue to remove the pair specified by pKey
 */
function psSetValueToCookie(pCookieName, pKey, pValue)
{
	// "normalize" input parameters
	pCookieName = psTrim(pCookieName);
	pKey = (pKey != null ? psTrim(pKey).toLowerCase() : pKey); // instead of 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(pId, pCatId, pSrchTerm, pSrchResult) 
{
	pId = psCleanPageId(pId);
	pCatId = psCleanCatId(pCatId);
    if (pSrchResult != null)
        pSrchResult += "";
    if (G_PS_DEBUG_MODE == 1 || G_PS_DEBUG_MODE == 3)
        alert("cmCreatePageviewTag(" + pId + ", " + pCatId + ", " + pSrchTerm + ", " + pSrchResult + ")");
    if (G_PS_DEBUG_MODE == 2 || G_PS_DEBUG_MODE == 3)
        cmCreatePageviewTag(pId, pCatId, pSrchTerm, pSrchResult);
}

function psCreateProductviewTag(pId, pName, pCatId) 
{
	pName = psCleanProductName(pName);
	pCatId = psCleanCatId(pCatId);
    if (G_PS_DEBUG_MODE == 1 || G_PS_DEBUG_MODE == 3)
        alert("cmCreateProductviewTag(" + pId + ", " + pName + ", " + pCatId + ")");
    if (G_PS_DEBUG_MODE == 2 || G_PS_DEBUG_MODE == 3)
        cmCreateProductviewTag(pId, pName, pCatId);
}

function psCreateShopAction5Tag(pId, pName, pQuantity, pPrice, pCatId) 
{
	pName = psCleanProductName(pName);
	pCatId = psCleanCatId(pCatId);
    if (G_PS_DEBUG_MODE == 1 || G_PS_DEBUG_MODE == 3)
        alert("cmCreateShopAction5Tag(" + pId + ", " + pName + ", " + pQuantity + ", " + pPrice + ", " + pCatId + ")");
    if (G_PS_DEBUG_MODE == 2 || G_PS_DEBUG_MODE == 3)
        cmCreateShopAction5Tag(pId, pName, pQuantity, pPrice, pCatId);    
}

function psCreateShopAction9Tag(pId, pName, pQuantity, pPrice, pCusID, pOrderID, pOrderTotal, pCatId) 
{
	pName = psCleanProductName(pName);
	pCatId = psCleanCatId(pCatId);
    if (G_PS_DEBUG_MODE == 1 || G_PS_DEBUG_MODE == 3)
        alert("cmCreateShopAction9Tag(" + pId + ", " + pName + ", " + pQuantity + ", " + pPrice + ", " + pCusID + ", " + pOrderID + ", " + pOrderTotal + ", " + pCatId + ")");
    if (G_PS_DEBUG_MODE == 2 || G_PS_DEBUG_MODE == 3)
        cmCreateShopAction9Tag(pId, pName, pQuantity, pPrice, pCusID, pOrderID, pOrderTotal, pCatId);
}

function psCreateOrderTag(pId, pOrderTotal, pOrderShipping, pCusID, pCusCity, pCusState, pCusZip) 
{
    if (G_PS_DEBUG_MODE == 1 || G_PS_DEBUG_MODE == 3)
        alert("cmCreateOrderTag(" + pId + ", " + pOrderTotal + ", " + pOrderShipping + ", " + pCusID + ", " + pCusCity + ", " + pCusState + ", " + pCusZip + ")");
    if (G_PS_DEBUG_MODE == 2 || G_PS_DEBUG_MODE == 3)
        cmCreateOrderTag(pId, pOrderTotal, pOrderShipping, pCusID, pCusCity, pCusState, pCusZip);
}

function psCreateConversionEventTag(pId, pActionType, pCatID, pPoints) 
{
	pCatID = psCleanCatId(pCatID);
    if (G_PS_DEBUG_MODE == 1 || G_PS_DEBUG_MODE == 3)
        alert("cmCreateConversionEventTag(" + pId + ", " + pActionType + ", " + pCatID + ", " + pPoints + ")");
    if (G_PS_DEBUG_MODE == 2 || G_PS_DEBUG_MODE == 3)
        cmCreateConversionEventTag(pId, pActionType, pCatID, pPoints);
}

function psCreateRegistrationTag(pCusID, pCustEmail, pCusCity, pCusState, pCusZip,pCusCountry, 
								pNewsletter, pSubscribe, pReferredBy, pPurchasingFor) 
{
    if (G_PS_DEBUG_MODE == 1 || G_PS_DEBUG_MODE == 3)
        alert("cmCreateRegistrationTag(" + pCusID + ", " + pCustEmail + ", " + pCusCity + ", " + pCusState + ", " + pCusZip + ", " + pCusCountry + ", " + pNewsletter + ", " + pSubscribe + ", " + pReferredBy + ", " + pPurchasingFor + ")");
    if (G_PS_DEBUG_MODE == 2 || G_PS_DEBUG_MODE == 3)
        cmCreateRegistrationTag(pCusID, pCustEmail, pCusCity, pCusState, pCusZip,pCusCountry, 
								pNewsletter, pSubscribe, pReferredBy, pPurchasingFor);
}

function psCreateErrorTag(pPageID, pCatId) 
{
	pPageID = psCleanPageId(pPageID);
	pCatId = psCleanCatId(pCatId);
    if (G_PS_DEBUG_MODE == 1 || G_PS_DEBUG_MODE == 3)
        alert("cmCreateErrorTag(" + pPageID + ", " + pCatId + ")");
    if (G_PS_DEBUG_MODE == 2 || G_PS_DEBUG_MODE == 3)
        cmCreateErrorTag(pPageID, pCatId);
}

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 ==================*/