/************************************************************************************/
/* $Revision: 101819 $
 * $Id: cmtaggingservices.js.txt 101819 2008-10-14 15:54:32Z abrink $
 *
 * Author: Coremetrics/PSD 
 * Coremetrics  v1.4, 09/30/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_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 = "PS_CURCATID";

var G_PS_CK_ALL="PS_ALL";
var G_PS_CK_CUSID="PS_CK_CUSID";
var G_PS_CK_SIGNIN="PS_CK_SIGNIN";
var G_PS_CK_SHOP9="PS_CK_SHOP9";
var G_PS_CK_SHOP5="PS_CK_SHOP5";
//var G_PS_CK_SHOP5_1="PS_CK_SHOP5_1";

/*========================= END GLOBAL VARIABLES =============================*/

/*=========================== BEGIN NAVIGATION ===============================*/
// Navigation logic should go here!

if(psGetUrlPath().indexOf("metrouniforms.com")>=0)
{
//alert(document.cookie);
if(psIsProductPage()==true)
{
	psSendProductPageViewTag();
	psRegisterListener_Add2Cart();
}
else
if(psIsSearchPage()==true)
{
	psSendPageViewTag_Search();
}
else
{
	psSendPageViewTag();
	psSendShop5Tags();

	if(G_PS_PATHNAME.indexOf("/register.php")>=0)
	{
		psRegisterListner_Submit_Registration();
		if(psRegisterSuccessful()==true)
		{
			psSendRegistrationTag_Register();
		}
		else
			if(psUpdateProfileSuccessful()==true)
			{
				psSendRegistrationTag_Register();
			}
	}
	else
		if(G_PS_PATHNAME.indexOf("/secure_login.php")>=0)
	{
		psRegisterListner_Submit_Login_1();
	}
	else	
		if(G_PS_PATHNAME.indexOf("/cart.php")>=0 )
	{
		var mode=psGetModeValue();
		if(psCheckElementExist(mode)==true)
		{
			if(mode.indexOf("checkout")>=0)
			{
				psRegisterListner_Submit_Login();
				psRegisterListner_Submit_Registration_Checkout();
				psRegisterListner_Submit_Login_2();
				
				if(G_PS_URL_PATH.indexOf("registered")>=0&&psRegisterSuccessful()==true)
				{
					psSendRegistrationTag_Register();
				}
				else
				if(G_PS_URL_PATH.indexOf("registered")>=0&&psUpdateProfileSuccessful()==true)
				{
					psSendRegistrationTag_Register();
				}
				
				var flag=psGetValueFromCookie(G_PS_CK_ALL, G_PS_FLAG);			
				if(flag=="true")
				{
					psSendRegistrationTag_2();
					psSetValueToCookie(G_PS_CK_ALL, G_PS_FLAG, "false");
				}			
			}
			else
				if(mode=="order_message")
			{
				psWriteShop92Ck();
			}
		}
		else
		{
			var flag=psGetValueFromCookie(G_PS_CK_ALL, G_PS_FLAG);
			if(flag=="true")
			{
				psSendRegistrationTag_2();
				psSetValueToCookie(G_PS_CK_ALL, G_PS_FLAG, "false");
				
			}		
			psRegisterListener_CatID_ShoppingCart();
			//psSendShop5Tags();
		}
	}
	psSendRegistrationTag_1();

}


}
/*============================ END NAVIGATION ================================*/



/*======================= GENERAL UTILITY FUNCTION ===========================*/

/* 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;
	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) == "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: 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: 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; 
        var 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
 * 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 = 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 (searchResults != null)
        searchResults += "";
    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 ==================*/

/*===========================FUNCTIONS BY DUC NGUYEN==================*/
/* 	#SECTION : 	Methods that can be reused in other project		 */

// Find element by name
function psGetElementsByClassName(psDocument, psElementTagName, psClassName)
{
    var arrResult = new Array();
    var index = 0;
    var arrInputs = psDocument.getElementsByTagName(psElementTagName);
    if(arrInputs == null)
    {
        return null;
    }
    for(var i = 0; i < arrInputs.length; i ++ )
    {
        if(arrInputs[i].className.toLowerCase() == psClassName.toLowerCase())
        {
            arrResult[index ++ ] = arrInputs[i];
        }
    }
    return arrResult;
}

// Find element by name
function psGetElementByName(psDocument, psElementTagName, psElementName, psElementType)
{
    // Find all elements that tag name is specified
    var arrInputs = psDocument.getElementsByTagName(psElementTagName);
    if(arrInputs == null)
    {
        return null;
    }
    for(var i = 0; i < arrInputs.length; i ++ )
    {
        // Find one that has specified name
        if(arrInputs[i].name.toLowerCase() == psElementName.toLowerCase())
        {
            // If element type is provided
            if(typeof(psElementType) != "undefined" && psElementType != "")
            {
                // Find it
                if(arrInputs[i].type.toLowerCase() == psElementType)
                {
                    return arrInputs[i];
                }
            }
            else
            {
                return arrInputs[i];
            }
        }
    }
    return null;
}

// Get elements which name is known
function psGetElementsByName(psDocument, psElementTagName, psElementName, psElementType)
{
    var arrResult = new Array();
    var index = 0;
    // Find all elements that tag name is specified
    var arrInputs = psDocument.getElementsByTagName(psElementTagName);
    if(arrInputs == null)
    {
        return null;
    }
    for(var i = 0; i < arrInputs.length; i ++ )
    {
        // Find one that has specified name
        if(arrInputs[i].name.toLowerCase() == psElementName.toLowerCase())
        {
            // If element type is provided
            if(typeof(psElementType) != "undefined" && psElementType != "")
            {
                // Find it
                if(arrInputs[i].type.toLowerCase() == psElementType)
                {
                    arrResult[index] = arrInputs[i];
                    index ++ ;
                }
            }
            else
            {
                arrResult[index] = arrInputs[i];
                index ++ ;
            }
        }
    }

    return arrResult;
}

/* 	#SECTION : Methods to check element exist or not */
// Check if array is exist or not
function psCheckArrayExist(pArrElement)
{
    if(typeof(pArrElement) == "undefined" || pArrElement == null || pArrElement.length <= 0)
    {
        return false;
    }

    return true;
}

// Check an element exist or not
function psCheckElementExist(pElement)
{
    if(typeof(pElement) == "undefined" || pElement == null)
    {
        return false;
    }

    return true;
}


function psGetSectionValue()
{
	var temp=psGetValueFromUrl(G_PS_URL_PATH, "section");
	if(psCheckElementExist(temp)==true)
	{
		temp=temp.toLowerCase();
	}
	
	return temp;
}

function psGetModeValue()
{
	return psGetValueFromUrl(G_PS_URL_PATH, "mode");
}

function psGetQValue()
{
	return psGetValueFromUrl(G_PS_URL_PATH, "q");
}


function psGetCatValue()
{
	return psGetValueFromUrl(G_PS_URL_PATH, "cat");
}

function psGetManufactureridValue()
{
	return psGetValueFromUrl(G_PS_URL_PATH, "manufacturerid");
}

function psGetPageID_Content()
{
	var arr=G_PS_PATHNAME.split("/");
	if(psCheckArrayExist(arr)==false)
	{
		return null;
	}
	
	var temp=arr[arr.length-1];	
	temp=temp.substring(0, temp.length-5);	
	temp=temp.replace(/[-_]/g, " ");
	
	return temp;	
}

function psGetUrlPath()
{
	return G_PS_URL_PATH.toLowerCase();
}

function psGetCatID_BottomLinks(pAHref)
{
	var temp=pAHref;
	var con=true;
	while(con==true)
	{
		temp=temp.parentNode;
		if(psCheckElementExist(temp)==false)
		{
			temp=temp.parentElement;
			if(psCheckElementExist(temp)==false)
			{
				return null;
			}
		}
		if(temp.tagName.toLowerCase()=="ul")
		{			
			var arrTemp= temp.getElementsByTagName("li");
			if(psCheckElementExist(arrTemp)==false)
			{
				return null;
			}
			temp=arrTemp[0];
			
			if(psCheckElementExist(temp)==false)
			{
				return null;
			}
			temp=psGetInnerText(temp);
			
			return temp;			
		}
		else 
			if(temp.tagName.toLowerCase()=="li")
		{
			
		}
		else
		{
			con=false;
		}
		
	}
	
	return null;
}

function psSendPageViewTag_BottomLinks()
{
	var pageID="Home";
	var catId="Home";
	
	var temp=psGetElementsByClassName(document, "table", "bottomlinks");
	if(psCheckArrayExist(temp)==false)
	{
		return false;		
	}
	temp=temp[0];
	var arrTemp=temp.getElementsByTagName("a");
	if(psCheckArrayExist(arrTemp)==false)
	{
		return false;
	}
	
	for(var i=0;i<arrTemp.length;i++)
	{
		if(psGetUrlPath().indexOf(arrTemp[i].href.toLowerCase())>=0)
		{
			pageID=psGetInnerText(arrTemp[i]);			
			catId=psGetCatID_BottomLinks(arrTemp[i]);
			if(psCheckElementExist(catId)==false)
			{
				return false;
			}
			if(catId.toLowerCase()=="departments")
			{
				return false;
			}
			psCreatePageviewTag(pageID, catId);
			psSaveCurCatID(catId);
			return true;
		}
	}
	
	return false;
}

function psIsErrorPage()
{
	var arrTemp= document.getElementsByTagName("h3");
	if(psCheckArrayExist(arrTemp)==false)
	{
		return false;
	}
	for(var i=0;i<arrTemp.length;i++)
	{
		var temp=psGetInnerText(arrTemp[i]);
		if(psCheckElementExist(temp)==true)
		{
			if(temp.toLowerCase().indexOf("page not found")>=0)
			{
				return true;
			}
		}
	}
	
	return false;
}

function psSendPageViewTag_TopMenu()
{
	var pageID="Home";
	var catId="Home";
	if(psGetUrlPath().indexOf("/cart.php")>=0)
	{
		return false;
	}
	var temp=psGetElementsByClassName(document, "table", "topmenu");
	if(psCheckArrayExist(temp)==false)
	{
		return false;		
	}
	temp=temp[0];
	var arrTemp=temp.getElementsByTagName("a");
	if(psCheckArrayExist(arrTemp)==false)
	{
		return false;
	}
	
	for(var i=0;i<arrTemp.length;i++)
	{
		if(psGetUrlPath().indexOf(arrTemp[i].href.toLowerCase())>=0)
		{
			pageID=psGetInnerText(arrTemp[i]);
			
			catId=pageID;		
			
			psCreatePageviewTag(pageID, catId);
			
			psSaveCurCatID(catId);
			
			return true;
		}
	}
	
	return false;
}


function psSendPageViewTag_QuickLinks()
{
	var pageID="Home";
	var catId="Home";
	var temp=psGetElementsByClassName(document, "td", "grn-tab-head");
	if(psCheckArrayExist(temp)==false)
	{
		return false;		
	}
	temp=temp[0];
	pageID=psTrim(psGetInnerText(temp));
	
	temp=psGetElementsByClassName(document, "td", "quicklinks-in");
	if(psCheckArrayExist(temp)==false)
	{
		return false;		
	}
	temp=temp[0];
	
	var arrTemp=temp.getElementsByTagName("li");
	if(psCheckArrayExist(arrTemp)==false)
	{
		return false;
	}
	
	var arrTemp1=new Array();
	var index=0;
	
	for(var i=0;i<arrTemp.length;i++)
	{
		if(psCheckElementExist(arrTemp[i].className)==true && arrTemp[i].className.indexOf("active")>=0)
		{
			arrTemp1[index]=arrTemp[i];
			index++;
		}
	}
	
	if(index>0)
	{
		for(var i=0;i<arrTemp1.length;i++)
		{
			arrTemp=arrTemp1[i].getElementsByTagName("a");
			if(psCheckArrayExist(arrTemp)==true)
			{
				temp=arrTemp[0];
				pageID+=":"+psHtmlDecode(psGetInnerText(temp));
			}
		}
		pageID=pageID.replace(/[\n]/g, "").replace(/[']/g, "");		
		catId=pageID;		
		psCreatePageviewTag(pageID, catId);
		psSaveCurCatID(catId);
		return true;
	}
	
	return false;
}

function psSaveCurCatID(pCatId)
{
	psSetValueToCookie(G_PS_CK_ALL, G_PS_CUR_CATID, pCatId);
}

function psSendPageViewTag()
{
	
	var pageID="Home";
	var catId="Home";
	
	if(psIsErrorPage()==true)
	{
		pageID=G_PS_PATHNAME;
		catId="ADD URL";
	}
	else
		if(psSendPageViewTag_TopMenu()==true)
	{
		return;
	}
	else
		if(psSendPageViewTag_QuickLinks()==true)
	{
		return;
	}
	else
		if(psSendPageViewTag_BottomLinks()==true)
	{
		return;
	}
	else
		if(G_PS_PATHNAME=="/" || G_PS_PATHNAME=="/home.php")
	{
		var cat=psGetCatValue();
		if(psCheckElementExist(cat)==false)
		{		
			pageID="Home";
			catId="Home";
		}
	}		
	else
		if(G_PS_PATHNAME=="/help.php")
	{
		
		catId="customer service";
		var section=psGetSectionValue();
		if(psCheckElementExist(section)==false)
		{
			pageID=catId;
		}
		else
			if(section=="password_recovery")
		{
			pageID="password_recovery";
			catId="My account";
		}
		else
		{
			pageID=section.replace(/[-_]/g, " ");			
		}
	}
	else
		if(G_PS_PATHNAME.indexOf("/cart.php")>=0)
	{		
		pageID="View cart";
		catId="cart";
		var mode=psGetModeValue();
		if(psCheckElementExist(mode)==true)
		{
			if(mode=="checkout")
			{
				pageID="checkout";
				catId="checkout";				
				//var payment=psGetValueFromCookie(G_PS_URL_PATH, "paymentid");
				
				if(G_PS_URL_PATH.indexOf("paymentid=")>=0)
				{
					pageID="payment";
					psRegisterListener_CatID_ShoppingCart();
				}
			}
			else
				if(mode=="order_message")
			{
				catId="checkout";
				
				//var payment=psGetValueFromCookie(G_PS_URL_PATH, "orderids");
				
				if(G_PS_URL_PATH.indexOf("orderids=")>=0)
				{
					pageID="confirmation";
				}
			}
		}
	}
	else
		if(G_PS_PATHNAME.indexOf("/content/")>=0)
	{
		catId="customer service";
		if(G_PS_PATHNAME.indexOf("/content/metrouniforms-coupons.html")>=0)
		{
			pageID="metro uniforms coupons";
		}
		else
		{
			pageID=psGetPageID_Content();
		}
	}
	else
		if(G_PS_PATHNAME.indexOf("/orders.php")>=0)
	{
		pageID="orders";
		catId="My account";
	}
	else
		if(G_PS_PATHNAME.indexOf("/returns.php")>=0)
	{
		pageID="returns";
		catId="My account";    
	}
	else
		if(G_PS_PATHNAME.indexOf("/_search.php")>=0 && psGetModeValue()=="advanced")
	{		
		pageID="advanced search";
		catId="search";    //"search";
	}
	else
		if(G_PS_PATHNAME.indexOf("testimonials.php")>=0)
	{
		catId="testimonials";    //"testimonials";
		var mode=psGetModeValue();
		if(psCheckElementExist(mode)==false)
		{
			pageID="testimonials";
		}
		else
		{
			mode=mode.toLowerCase();
			if(mode=="view_all")
			{
				pageID="testimonials: view all";
			}
			else
				if(mode=="new_form")
			{
				pageID="testimonials: add new";
			}
			else
			{
				pageID=mode;
			}
		}
	}
	else
		if(G_PS_PATHNAME.indexOf("view_reviews.php")>=0)
	{
		pageID="product reviews: view";
		catId="reviews";  
	}
	else
		if(G_PS_PATHNAME.indexOf("error_message.php")>=0 && psGetUrlPath().indexOf("login_incorrect")>=0)
	{
		pageID="Login_incorrect";
		catId="My account";
	}
	else if(G_PS_PATHNAME.indexOf("error_message.php")>=0)
	{
		pageID=G_PS_PATHNAME;
		catId="911";  
	}
	else
		if(G_PS_PATHNAME.indexOf("manufacturers.php")>=0)
	{
		var temp=psGetManufactureridValue();		
		pageID="manufacturers";
		catId="manufacturers";
		if(psCheckElementExist(temp)==false)
		{
			pageID="manufacturers";
			catId="manufacturers";
		}
		else
		{
			pageID=document.title;
			pageID="manufacturers"+":"+psCleanPageId(pageID);
			
			catId=pageID;
		}
	}
	else if(psUseFriendlyUrl()==true)
	{
		//pageID=psGetPageID_SideBar();			
		//if(psCheckArrayExist(pageID)==false)
		pageID=document.title;
		catId=pageID;
	}	
	else if(G_PS_PATHNAME.indexOf("secure_login.php")>=0)
	{
		pageID="secure login";
		catId="my account";    //"login";
	}	
	else if(G_PS_PATHNAME.indexOf("register.php")>=0)
	{
		var mode=psGetModeValue();
		if(psCheckElementExist(mode)==false || mode!="delete")
		{
			pageID="create/modify profile";
		}
		else
			if(mode=="delete")
		{
			pageID="delete profile";
		}		
		
		catId="My account";    //"login";
	}	
	else
	{
		pageID=G_PS_PATHNAME;
		
		var temp=pageID;
		if(temp.indexOf("/")>=0)
		{
			if(temp.lastIndexOf("/")==temp.length-1)
			{
				temp=temp.substring(0, temp.length-2);				
			}
			
			var arr=temp.split("/");
			if(psCheckElementExist(arr)==true && arr.length>1)
			{
				temp=arr[arr.length-1];
				pageID=temp.replace(".htm", "").replace(".html", "").replace(".php", "");;
			}
		}
		catId="ADD URL";
	}	
	
	psCreatePageviewTag(pageID, catId);
	psSaveCurCatID(catId);
}

function psIsProductPage()
{
	if(G_PS_PATHNAME.indexOf("/products/")>=0)
	{
		return true;
	}
	
	return false;
}

function psSendProductPageViewTag()
{
	//var temp=psGetElementByName(document, "input", "productname", "hidden");	
	var prName=psNameDecode(G_PS_PATHNAME);

	temp=psGetElementByName(document, "input", "productid", "hidden");
	if(psCheckElementExist(temp)==false)
	{
		return;
	}
	var prID=psGetElementValue(temp);
	
	temp=psGetValueFromCookie(G_PS_CK_ALL, G_PS_CUR_CATID);
	if((psCheckElementExist(temp)==false)||temp=="Home")
	{
		temp="DIRECT LOAD";
	}
	
	var prCatID=temp;
	
	psCreateProductviewTag(prID, prName, prCatID);
}

function psIsSearchPage()
{
	if(G_PS_PATHNAME.indexOf("search.php")>=0)
	{
		return true;
	}
	
	return false;
}

function psGetSearchNumber()
{
	var arrTemp=document.getElementsByTagName("td");
	if(psCheckArrayExist(arrTemp)==false)
	{
		return null;
	}
	
	for(var i=0;i<arrTemp.length;i++)
	{
		if(arrTemp[i].height=="30")
		{			
			var temp=psTrim(psGetInnerText(arrTemp[i]).replace(/[\n]/g, ""));			
			if(temp.length>0 && temp.toLowerCase().indexOf("results")>=0)
			{
				var arrTemp1=temp.split(" ");
				if(arrTemp1[0]=="0")
				{
					temp="0";
				}
				else
				{				
					temp=arrTemp1[3];
				}
				
				return temp;
			}
		}
	}
	return null;
}

function psGetSearchNumber_1()
{
	var temp=psGetElementByName(document, "a", "results");
	if(psCheckElementExist(temp)==false)
	{
		return null;
	}
	
	temp=temp.parentNode;
	if(psCheckElementExist(temp)==false)
	{
		temp=temp.parentElement;
		if(psCheckElementExist(temp)==false)
		{
			return null;
		}
	}
	temp=psTrim(psGetInnerText(temp).replace(/[\n]/g, ""));
	var arrTemp=temp.split(" ");
	if(psCheckArrayExist(arrTemp)==false)
	{
		return null;
	}
	temp=arrTemp[0];
	return temp;	
}

function psGetSearchString()
{
	var temp=psGetElementByName(document, "input", "q", "text");
	if(psCheckElementExist(temp)==false)
	{
		return null;
	}
	
	return psGetElementValue(temp);	
}

function psSendPageViewTag_Search()
{
	var pageID="Search";
	var catId="Search";
	var searchString=null;
	var searchResults="0";
	
	searchResults=psGetSearchNumber();
	var temp=psGetQValue();
	if(psCheckElementExist(temp)==true)
	{
		searchString=temp;
		if(searchResults=="0")
		{
			pageID="Search - no success";
		}
		else
		{
			pageID="Search - success";
		}
	}
	else
	{
		temp=psGetModeValue();
		if(psCheckElementExist(temp)==true)
		{
			if(temp=="search")
			{
				searchResults=psGetSearchNumber_1();
				if(psCheckElementExist(searchResults)==false || searchResults=="0")
				{
					pageID="Easy search - No success";
					searchResults="0";
				}
				else
				{
					pageID="Easy Search - success";
				}
			}
			else
				if(temp=="advanced")
			{
				pageID="advanced search";
			}
		}
		else
		{			
			searchString=psGetSearchString();			
			pageID="advanced search";
		}
	}
	
	psCreatePageviewTag(pageID, catId, searchString, searchResults);
	psSaveCurCatID(catId);
}

function psSaveItem2Ck()
{
	var temp=psGetElementByName(document, "input", "productid", "hidden");
	if(psCheckElementExist(temp)==false)
	{
		return;
	}
	var prID=psGetElementValue(temp);
	temp=psGetValueFromCookie(G_PS_CK_ALL, G_PS_CUR_CATID);
	if(psCheckElementExist(temp)==false)
	{
		temp="Unknown";
	}
	
	var prCatID=temp;
	psSetValueToCookie(G_PS_COOKIE_PROD_CATID, prID, prCatID);
}

//Unneeded
function psWriteItem2Ck()
{
	var prID=null;
	var temp=psGetElementByName(document, "input", "productid", "hidden");
	if(psCheckElementExist(temp)==false)
	{
		return;
	}
	prID=temp.value;
	var prName=document.title;
	
	psSetValueToCookie(G_PS_COOKIE_PROD_NAME, prName, prID);
}

function psRegisterListener_Add2Cart()
{
	var arrTemp=document.getElementsByTagName("IMG");
	if(psCheckArrayExist(arrTemp)==false)
	{
		return;
	}
	for(var i=0;i<arrTemp.length;i++)
	{
		if(arrTemp[i].src.indexOf("metrouni-add.gif")>=0)
		{
			var oldFunc=arrTemp[i].onclick;
			arrTemp[i].onclick=function()
			{
				var validated = FormValidation();
				if(validated)
				{
					psSaveItem2Ck();
					
					//Unneeded
					psWriteItem2Ck();
				}
				if(psCheckElementExist(oldFunc)==true)
				{
					return oldFunc();
				}
			}
		}
	}
}

function psGetProductNames_Shop5(pTable)
{	
	var arrFont_PrName=psGetElementsByClassName(pTable, "font", "producttitle");
	if(psCheckArrayExist(arrFont_PrName)==false)
	{
		return null;
	}
	
	var arrPrName=new Array();
	
	for(var i=0;i<arrFont_PrName.length;i++)
	{
		arrPrName[i]=psTrim(psGetInnerText(arrFont_PrName[i]).replace(/[\n]/g, " "));		
	}
	
	return arrPrName;
}


function psGetProductIDs_Shop5(pTable)
{	
	var arrPrID=new Array();
	var arrImg=pTable.getElementsByTagName("img");
	if(psCheckArrayExist(arrImg)==false)
	{
		return null;
	}
	
	var index=0;
	for(var i=0;i<arrImg.length;i++)
	{
		if(arrImg[i].src.indexOf("/image.php?type=")>=0)
		{
			arrPrID[index]=psGetValueFromUrl(arrImg[i].src, "id");
			index++;
		}
	}
	
	return arrPrID;
}

function psGetProductQuantities_Shop5(pTable)
{
	var arrPrQuan=new Array();
	var arrInputs=pTable.getElementsByTagName("input");
	if(psCheckArrayExist(arrInputs)==false)
	{
		return null;
	}
	var index=0;
	for(var i=0;i<arrInputs.length;i++)
	{
		if(arrInputs[i].name.indexOf("productindexes")>=0)
		{
			arrPrQuan[index]=arrInputs[i].value;
			index++;
		}
	}
	
	return arrPrQuan;
}

function psGetProductPrices_Shop5(pTable)
{
	var index=0;
	var arrPrPrices=new Array();
	var arrFonts=psGetElementsByClassName(pTable, "font", "productpriceconverting");
	if(psCheckArrayExist(arrFonts)==false)
	{
		return null;
	}
	
	for(var i=0;i<arrFonts.length;i++)
	{
		var oSpan=arrFonts[i].getElementsByTagName("span");
		if(psCheckElementExist(oSpan)==false)
		{
		}
		else
		{
			oSpan=oSpan[0];
			arrPrPrices[index]=psGetInnerText(oSpan).replace("$","");			
			index++;
		}
	}
	
	return arrPrPrices;
}

function psGetProductCatFromPrID(pPrID)
{
	var temp=psGetValueFromCookie(G_PS_COOKIE_PROD_CATID, pPrID);
	if(psCheckElementExist(temp)==false)
	{
		return "Unknown";
	}
	
	return temp;
}

function psSendShop5Tags()
{
	if(G_PS_PATHNAME.indexOf("/cart.php")<0)
	{
		return;
	}
	var cartForm=psGetElementByName(document, "form", "cartform");
	if(psCheckElementExist(cartForm)==false)
	{
		return;
	}
	
	var arrTable=cartForm.getElementsByTagName("table");
	if(psCheckElementExist(arrTable)==false)
	{
		return;
	}	
	var oTable=arrTable[0];
	
	var arrPrName=psGetProductNames_Shop5(oTable);
	if(psCheckArrayExist(arrPrName)==false)
	{
		return;
	}
	
	var arrPrID=psGetProductIDs_Shop5(oTable);
	if(psCheckArrayExist(arrPrID)==false)
	{
		return;
	}
	
	var arrPrQuan=psGetProductQuantities_Shop5(oTable);
	if(psCheckArrayExist(arrPrQuan)==false)
	{
		return;
	}
	
	var arrPrPrices=psGetProductPrices_Shop5(oTable);
	if(psCheckArrayExist(arrPrPrices)==false)
	{
		return;
	}
	
	var arrPrCatID=new Array();
	for(var i=0;i<arrPrID.length;i++)
	{
		arrPrCatID[i]=psGetProductCatFromPrID(arrPrID[i]);
	}
	
	psSetValueToCookie(G_PS_CK_SHOP5, " ", "delete");
	for(var i=0;i<arrPrID.length;i++)
	{
		psCreateShopAction5Tag(arrPrID[i], arrPrName[i], arrPrQuan[i], arrPrPrices[i], arrPrCatID[i]);
		
		//psSetValueToCookie(G_PS_CK_SHOP5, arrPrName[i], arrPrID[i]);
		psSetValueToCookie(G_PS_CK_SHOP5, arrPrName[i], arrPrID[i]+"-_-"+arrPrCatID[i]);
	}
	
	psDisplayShop5s();
}








function psIsAddressError()
{
	var arrTd=psGetElementsByClassName(document, "td", "dialogtitle");
	if(psCheckArrayExist(arrTd)==false)
	{
		return;
	}
	
	for(var i=0;i<arrTd.length;i++)
	{
		if(psGetInnerText(arrTd[i]).toLowerCase()=="address error")
		{
			return true;
		}
	}
	
	return false;
}

function psRegisterListener_UseSuggestion()
{
	var arrFonts=psGetElementsByClassName(document, "font", "button");
	if(psCheckArrayExist(arrFonts)==false)
	{
		return;
	}
	
	for(var i=0;i<arrFonts.length;i++)
	{
		if(psGetInnerText(arrFonts[i]).toLowerCase().indexOf("use suggestion")>=0)
		{
			arrFonts[i].onclick=function()
			{
				psWriteAddress2Ck();
			}
		}
	}
}

function psWriteAddress2Ck()
{
	var iState=psGetElementByName(document, "select", "rank");
	var state=null;
	var city=null;
	var zip=null;
	var temp=null;
	if(psCheckElementExist(iState)==false)
	{
		temp="Unknown";
	}
	else
	{
		temp=iState.options[iState.selectedIndex].text;		
		var arr=temp.split(",");
		city=arr[0];
		temp=psTrim(arr[1]).split(" ");
		state=temp[0];
		zip=temp[1];
		
		temp=psGetCookie(G_PS_COOKIE_PROFILE);
		
		var sep="|";
		
		if(psCheckElementExist(temp)==false)
		{
			return;
		}
		var arr=temp.split(sep);
		arr[2]=city;
		arr[3]=state;
		arr[4]=zip;		
		var strCookie=arr[0]+sep+ arr[1]+sep+ arr[2]+sep+ arr[3]+sep+ arr[4]
		psSetCookie(G_PS_COOKIE_PROFILE, strCookie);
	}	
}

function psIsBillingAddressTable(pTable)
{
	var row=pTable.rows[0];
	if(psCheckElementExist(row)==false)
	{
		return false;
	}
	
	var cell=row.cells[0];
	if(psCheckElementExist(cell)==false)
	{
		return false;
	}
	
	if(psGetInnerText(cell).toLowerCase()=="billing address")
	{
		cell=row.cells[2];
		if(psCheckElementExist(cell)==false)
		{
			return false;
		}
		
		if(psGetInnerText(cell).toLowerCase()=="shipping address")
		{
			return true;
		}		
	}
	
	return false;	
}

function psGetBillingAddressInfoTable()
{
	var arrTable=document.getElementsByTagName("table");
	if(psCheckArrayExist(arrTable)==false)
	{
		return;
	}
	
	for(var i=0;i<arrTable.length;i++)
	{
		if(psIsBillingAddressTable(arrTable[i])==true)
		{	
			
			var temp=arrTable[i].rows[3].cells[0];			
			temp=temp.getElementsByTagName("table");
			if(psCheckArrayExist(temp)==true)
			{
				return temp[0];
			}
			
		}
	}
	
	return null;
}

function psWriteBillingInfor2Ck()
{
	var oTable=psGetBillingAddressInfoTable();	
	if(psCheckElementExist(oTable)==false)
	{
		return;
	}
	var city=null;
	var state=null;
	var zip=null;
	
	var temp=oTable.rows[1];
	if(psCheckElementExist(temp)==true)
	{
		temp=temp.cells[0];
		if(psCheckElementExist(temp)==true)
		{
			if(psTrim(psGetInnerText(temp).toLowerCase())=="city:")
			{
				city=psGetInnerText(oTable.rows[1].cells[1]);				
			}
			else
			{
				city=psGetInnerText(oTable.rows[2].cells[1]);				
			}
		}
	}
	
	temp=oTable.rows[2];
	if(psCheckElementExist(temp)==true)
	{
		temp=temp.cells[0];
		if(psCheckElementExist(temp)==true)
		{
			if(psTrim(psGetInnerText(temp).toLowerCase())=="state:")
			{
				state=psGetInnerText(oTable.rows[2].cells[1]);				
			}
			else
			{
				state=psGetInnerText(oTable.rows[3].cells[1]);				
			}
		}
	}
	
	temp=oTable.rows[4];
	if(psCheckElementExist(temp)==true)
	{
		temp=temp.cells[0];
		if(psCheckElementExist(temp)==true)
		{			
			if(psTrim(psGetInnerText(temp).toLowerCase())=="zip/postal code:")
			{
				zip=psGetInnerText(oTable.rows[4].cells[1]);				
			}
			else
			{
				zip=psGetInnerText(oTable.rows[5].cells[1]);				
			}
		}
	}	
	var sep="|";
	var strCookie=city+sep+state+sep+zip;
	return strCookie;
}

function psIsPlaceOrder()
{
	var temp=document.getElementsByTagName("h3");
	if(psCheckElementExist(temp)==false)
	{
		return false;
	}
	
	temp=temp[0];	
	if(psGetInnerText(temp).toLowerCase()=="place order")
	{		
		return true;
	}
	return false;
}


function psGetSubtotal()
{
	var oTable=psGetSubTotalTable();	
	if(psCheckElementExist(oTable)==false)
	{
		return null;
	}
	
	var subTotal=null;
	var shipping=null;
	
	subTotal=psGetInnerText(oTable.rows[0].cells[1]).replace("$","").replace(/[&nbsp;]/g, "");
	shipping=psGetInnerText(oTable.rows[1].cells[1]).replace("$","").replace(/[&nbsp;]/g, "");
	var sep="|";
	var result=subTotal+sep+shipping;	
	return result;
}

function psGetPaymentDetailTable()
{
	var arrTable=document.getElementsByTagName("table");
	if(psCheckArrayExist(arrTable)==false)
	{
		return null;
	}
	
	for(var i=0;i<arrTable.length;i++)
	{
		var temp=arrTable[i].rows[0];
		if(psCheckElementExist(temp)==true)
		{
			temp=temp.cells[0];
			if(psCheckElementExist(temp)==true)
			{
				if(psGetInnerText(temp).toLowerCase()=="products ordered")
				{
					return arrTable[i+1];
				}
			}
		}
	}
	
	return null;
}

function psGetOrderID()
{
	return psGetValueFromUrl(G_PS_URL_PATH, "orderids");
}

function psGetProductIDfromPrName_Shop9(pPrName)
{
	var temp=psGetValueFromCookie(G_PS_CK_SHOP5, pPrName);
	var sep="-_-";
	if(psCheckElementExist(temp)==true)
	{
		if(temp.indexOf(sep)>=0)
		{
			var arrTemp=temp.split(sep);
			return arrTemp[0];
		}
		return temp;
	}
	else
	{
		temp=psGetValueFromCookie(G_PS_COOKIE_PROD_NAME, pPrName);
		
		if(psCheckElementExist(temp)==true)
		{
			return temp;
		}
		else
		{
			return "Unknown";
		}
	}
	return "Unknown";
}

function psGetProductCatIDfromPrName_Shop9(pPrName)
{
	var temp=psGetValueFromCookie(G_PS_CK_SHOP5, pPrName);
	var sep="-_-";
	if(psCheckElementExist(temp)==true)
	{
		if(temp.indexOf(sep)>=0)
		{
			var arrTemp=temp.split(sep);
			return arrTemp[1];
		}
		return temp;
	}
	
	return "Unknown";
}

function psWriteShop92Ck()
{
	var oTable=psGetPaymentDetailTable();
	if(psCheckElementExist(oTable)==false)
	{
		return;
	}
	
	var stop=false;
	var row=null;
	var cell=null;
	var index=1;
	var temp=null;
	var arrTemp=null;
	
	var arrPrID=new Array();
	var arrPrCatID=new Array();
	var arrPrName=new Array();
	var arrPrQuans=new Array();
	var arrPrPrices=new Array();
	var arrIndex=0;
	
	while(!stop)
	{		
		row=oTable.rows[index];
		if(psCheckElementExist(row)==false)
		{
			stop=true;
			break;
		}
		else
		{			
			cell=row.cells[1];
			temp=cell.getElementsByTagName("font");
			if(psCheckArrayExist(temp)==true)
			{
				temp=temp[0];				
				arrPrName[arrIndex]=psGetInnerText(temp);
			}
			else
			{
				stop=true;
			}
			
			cell=row.cells[2];
			arrPrPrices[arrIndex]=psGetInnerText(cell).replace("$","").replace(/[&nbsp;]/g, "");			
			cell=row.cells[3];
			arrPrQuans[arrIndex]=psGetInnerText(cell).replace("$","");
			
			arrPrID[arrIndex]=psGetProductIDfromPrName_Shop9(arrPrName[arrIndex]);
			arrPrCatID[arrIndex]=psGetProductCatIDfromPrName_Shop9(arrPrName[arrIndex]);
			
			arrIndex++;
		}
		index++;
	}
	
	var sep="|";
	temp=psGetSubtotal();
	var subTotal=temp.split(sep)[0];
	var shipping=temp.split(sep)[1];
	
	var orderID=psGetOrderID();
	var cusId=psGetValueFromCookie(G_PS_CK_ALL, G_PS_CK_CUSID);
		
	psSendShop9Tags(arrPrID, arrPrName, arrPrQuans, arrPrPrices, cusId, orderID, subTotal, arrPrCatID);
	
	temp=psWriteBillingInfor2Ck()
	if(psCheckElementExist(temp)==false)
	{
		return;
	}
	var arr=temp.split(sep);
	var city=arr[0];
	var state=arr[1];
	var zip=arr[2];
	psCreateOrderTag(orderID, subTotal, shipping, cusId, city, state, zip);
}

function psSendShop9Tags(arrPrID, arrPrName, arrPrQuan, arrPrPrices, cusId, orderID, subTotal, arrPrCatID )
{
	for(var i=0;i<arrPrID.length;i++)
	{
		psCreateShopAction9Tag(arrPrID[i], arrPrName[i], arrPrQuan[i], arrPrPrices[i], cusId, orderID, subTotal, arrPrCatID[i]);
	}
	
	psDisplayShop9s();
}

function psHtmlDecode_1(pValue)
{
    if (pValue)
    {
		pValue = pValue.replace(/&amp;/gi, "");
		pValue = pValue.replace(/&#039;/gi, "'");
		pValue = pValue.replace(/#039;/gi, "'");
        pValue = pValue.replace(/&nbsp;/gi, " ");
        pValue = pValue.replace(/&quot;/gi, '"');        
        pValue = pValue.replace(/&lt;/gi, "<");
        pValue = pValue.replace(/&gt;/gi, ">");		
    }

    return pValue;
}

function psRegisterListner_Submit_Login_2()
{
	var arrImg=document.getElementsByTagName("IMG");
	if(psCheckArrayExist(arrImg)==false)
	{
		return;
	}
	
	for(var i=0;i<arrImg.length;i++)
	{
		if(arrImg[i].src.toLowerCase().indexOf("/skin1/images/customer_images/submit.gif")>=0)
		{
			arrImg[i].onclick=function()
			{
				psWriteCusID2Ck();
				psSetValueToCookie(G_PS_CK_ALL, G_PS_FLAG, "true");				
			}
			return;
		}
	}
}

function psGetSubTotalTable()
{
	var arrTable=document.getElementsByTagName("table");
	for(var i=0;i<arrTable.length;i++)
	{
		var temp=arrTable[i].rows[0];
		if(psCheckElementExist(temp)==true)
		{
			temp=temp.cells[0];
			if(psCheckElementExist(temp)==true)
			{
				if(psTrim(psGetInnerText(temp).toLowerCase())=="subtotal:")
				{
					return arrTable[i];
				}
			}
		}
	}
	
	return null;
}





function psWriteUserInfo2Ck()
{
	var userName="";
	var email="";
	var state="";
	var city="";
	var zip="";
	
	//var iUserName=document.getElementById("uname");
	var iUserName=psGetElementByName(document,"input", "uname");
	if(psCheckElementExist(iUserName)==false)
	{
		userName="Unknown";
	}
	else
	{
		userName=iUserName.value;
	}
	
	email=document.getElementById("email").value;
	city=document.getElementById("b_city").value;
	var iState=document.getElementById("b_state");
	if(psCheckElementExist(iState)==false)
	{
		state="Unknown";
	}
	else
	{
		state=iState.options[iState.selectedIndex].value;
	}
	
	zip=document.getElementById("b_zipcode").value;
	
	if(psCheckElementExist(userName)==false)
	{
		userName=email;
	}
	else
		if(userName=="" || psTrim(userName).length==0)
	{
		userName=email;
	}
	
	var sep = "|";
    var strCookie =userName+sep+email + sep + city + sep + state + sep + zip;	
	psSetCookie(G_PS_COOKIE_PROFILE, strCookie);
	psSetValueToCookie(G_PS_CK_ALL, G_PS_CK_CUSID, userName);
    psSetValueToCookie(G_PS_CK_ALL, G_PS_CK_SIGNIN, false);
}

function psRegisterListner_Submit_Registration()
{
	var arrImg=document.getElementsByTagName("IMG");
	if(psCheckArrayExist(arrImg)==false)
	{
		return;
	}
	
	for(var i=0;i<arrImg.length;i++)
	{
		if(arrImg[i].src.toLowerCase().indexOf("/skin1/images/customer_images/submit.gif")>=0)
		{
			arrImg[i].onclick=function()
			{
				psWriteUserInfo2Ck();
			}
			return;
		}
	}
}


function psIsRegisterPage()
{
	var arrTd=psGetElementsByClassName(document, "td", "dialogbox");
	if(psCheckArrayExist(arrTd)==false)
	{
		return true;
	}
	
	return false;
}

function psRegisterSuccessful()
{
	var arrTd=psGetElementsByClassName(document, "td", "dialogbox");
	if(psCheckArrayExist(arrTd)==false)
	{
		return false;
	}
	
	oTd=arrTd[0];
	if(psGetInnerText(oTd).toLowerCase().indexOf("profile has been successfully created")>=0)
	{
		return true;
	}
	if(psGetInnerText(oTd).toLowerCase().indexOf("your personal details have been successfully accepted")>=0)
	{
		return true;
	}
	return false;
}

function psSendRegistrationTag_Register()
{
	var sep="|";
	var profile=psGetCookie(G_PS_COOKIE_PROFILE);
	if(psCheckElementExist(profile)==false)
	{
		return;
	}
	var arr=profile.split(sep);	
	psCreateRegistrationTag(arr[0], arr[1], arr[2], arr[3], arr[4]);
	psSetValueToCookie(G_PS_CK_ALL, G_PS_CK_SIGNIN, true);
}


function psUpdateProfileSuccessful()
{
	var arrTd=psGetElementsByClassName(document, "td", "dialogbox");
	if(psCheckArrayExist(arrTd)==false)
	{
		return false;
	}
	
	oTd=arrTd[0];
	if(psGetInnerText(oTd).toLowerCase().indexOf("profile has been successfully updated")>=0)
	{
		return true;
	}
	
	return false;
}


function psWriteCusID2Ck()
{
	var userName="";
	var email="";
	var state="";
	var city="";
	var zip="";
	
	//var iUserName=document.getElementById("uname");
	var iUserName=psGetElementByName(document,"input", "username");
	if(psCheckElementExist(iUserName)==false)
	{
		userName="Unknown";
	}
	else
	{
		userName=iUserName.value;
	}
	
	psSetValueToCookie(G_PS_CK_ALL, G_PS_CK_CUSID, userName);
	psSetValueToCookie(G_PS_CK_ALL, G_PS_CK_SIGNIN, false);
}

function psRegisterListner_Submit_Login()
{
	var arrAHref=psGetElementsByClassName(document, "a", "button"); 
	if(psCheckArrayExist(arrAHref)==false)
	{
		return;
	}
	
	for(var i=0;i<arrAHref.length;i++)
	{
		arrAHref[i].onclick=function()
		{
			psWriteCusID2Ck();			
		}		
	}
}

function psRegisterListner_Submit_Login_1()
{
	var arrAHref=psGetElementsByClassName(document, "a", "button"); 
	if(psCheckArrayExist(arrAHref)==false)
	{
		return;
	}
	
	for(var i=0;i<arrAHref.length;i++)
	{
		arrAHref[i].onclick=function()
		{
			psWriteCusID2Ck();
			psSetValueToCookie(G_PS_CK_ALL, G_PS_FLAG, "true");
		}		
	}
}

function psIsSignedIn()
{
	var arr=psGetElementsByClassName(document, "font","topmenusmalllink");
	if(psCheckArrayExist(arr)==false)
	{
		return false;
	}
	for(var i=0;i<arr.length; i++)
	{
		if(psGetInnerText(arr[i]).toLowerCase()=="log out")
		{
			return true;
		}
	}
	return false;	
}

function psSendRegistrationTag_1()
{
	if(psIsSignedIn()==true)
	{
		if(G_PS_PATHNAME.indexOf("/register.php")>=0)
		{
			if(psIsAddressError()==true)
			{
				psRegisterListener_UseSuggestion();
				return;
			}
		}		
		
		psSendRegistrationTag_2();		
	}
}

function psSendRegistrationTag_2()
{
	var signIn=psGetValueFromCookie(G_PS_CK_ALL, G_PS_CK_SIGNIN);
	if(psCheckElementExist(signIn)==false || signIn==false)
	{
		var cusId=psGetValueFromCookie(G_PS_CK_ALL, G_PS_CK_CUSID);
		if(psCheckElementExist(cusId)==false)
		{
			return;
		}
		psCreateRegistrationTag(cusId);
		psSetValueToCookie(G_PS_CK_ALL, G_PS_CK_SIGNIN, true);
	}
}
function psRegisterListner_Submit_Registration_Checkout()
{
	var arrImg=document.getElementsByTagName("IMG");
	if(psCheckArrayExist(arrImg)==false)
	{
		return;
	}
	
	var count=0;
	for(var i=0;i<arrImg.length;i++)
	{
		if(arrImg[i].src.toLowerCase().indexOf("/skin1/images/customer_images/submit.gif")>=0)
		{
			if(count==1)
			{
				arrImg[i].onclick=function()
				{
					psWriteUserInfo2Ck();
				}
			}
			
			count++;
			if(count==2)
			{
				return;
			}
		}
	}
}

function psUseFriendlyUrl()
{
	var path=G_PS_PATHNAME;	
	if(path.lastIndexOf("/")==path.length-1 && path.indexOf("/shop/")>=0)
	{		
		return true;
	}
	else
		if(path.indexOf("/index")>=0 &&path.indexOf("/shop/")>=0)
	{		
		return true;
	}
	
	return false;
}

function psGetBackOriginalCat(pAHref)
{
	var temp=pAHref;
	temp=psGetValueFromUrl(temp.href, "productid");	
	temp=psGetProductCatFromPrID(temp);
	
	if(psCheckElementExist(temp)==false)
	{
		temp="Unknown";
	}
	return temp;
}

function psRegisterListener_CatID_ShoppingCart()
{
	var arrTemp=document.getElementsByTagName("a");
	if(psCheckArrayExist(arrTemp)==false)
	{
		return;
	}
	
	for(var i=0;i<arrTemp.length;i++)
	{
		if(psCheckElementExist(arrTemp[i].href)>=0)
		{
			if(arrTemp[i].href.indexOf("/product/")>=0)
			{
				var oldFunc=arrTemp[i].onclick;
				arrTemp[i].onclick=function()
				{
					var temp=psGetBackOriginalCat(this);
					psSaveCurCatID(temp);
					if(psCheckElementExist(oldFunc)==true)
					{
						return oldFunc();
					}
				}
			}
		}
	}
}

/* PURPOSE: clean URL to get product name
 * RETURN: productname
 */
function psNameDecode(pValue)
{
    if (pValue)
    {
		pValue = pValue.substr(10,100);
        pValue = pValue.replace(/-/gi, " ");
		pValue = pValue.replace(/.html/gi, "");
		pValue = pValue.replace(/.php/gi, " ");
    }

    return pValue;
}

/*===========================END FUNCTIONS==================*/