/************************************************************************************/
/* $Revision: $
 * $Id: $
 *
 * Author: Coremetrics/PSD 
 * Coremetrics  v1.2, 11/21/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_CUR_PAGEID = "PS_CURPAGEID";

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_SEP="-_-";

/*========================= END GLOBAL VARIABLES =============================*/

/*=========================== BEGIN NAVIGATION ===============================*/
// Navigation logic should go here!
if (psIsSearchView()==true)
{
	psSendPageViewTag_Search();
}
if(psGetUrlPath().indexOf("allejewelry.com")>=0)
{
if (psIsProductView()==true)
{
	psSendProductViewTag();
	psRegisterListener_Add2Cart();
}
else if (psIsCartView())
{
	var pageId="Shopping cart";
	var catId="cart";
	psCreatePageviewTag(pageId, catId);
	psSendShop5ActionTags();
}
else if (psIsOrderView())
{
	var pageId="checkout3";
	var catId="checkout";
	
	psCreatePageviewTag(pageId, catId);
	psSendShop9ActionTags();
}
else 
{
	psSendPageViewTag();
	psRegisterListener_Login_Checkout();
	psRegisterListener_Register_Checkout();
	psSendRegistrationTag_Checkout();
	psSaveBillingInfo();
	//psCreatePageviewTag(G_PS_PATHNAME, "ADD URL"); // Other pages go to "ADD URL" category
}

}
/*
 * Determine if the page is the search result page
 */
function psIsSearchView()
{
	//
	// TO-Do: Your logic to determine the search page goes here
	//
	if(psCheckElementExist(SLI_SEARCH_PAGE)==true)
	{
		return true;
	}
	return false;
}

/*
 * Determine if the page is the product detail page
 */
function psIsProductView()
{
	//
	// TO-Do: Your logic to determine the product detail page goes here
	//
	if(G_PS_PATHNAME.indexOf("/product.cfm")>=0)
	{
		return true;
	}
	return false;
}

/*
 * Determine if the page is the shopping cart page
 */
function psIsCartView()
{
	//
	// TO-Do: Your logic to determine the shopping cart page goes here
	//
	if(G_PS_PATHNAME.indexOf("/basket.cfm")>=0)
	{
		return true;
	}
	return false;
}

/*
 * Determine if the page is the thank you page
 */
function psIsOrderView()
{
	//
	// TO-Do: Your logic to determine the receipt page goes here
	//
	if(G_PS_PATHNAME.indexOf("/thankyou.cfm")>=0)
	{
		return true;
	}	
	return false;
}
/*============================ END NAVIGATION ================================*/


/* 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; 
	
	//return (pPageId != null) ? pPageId.replace(/[\n\t\v\r�\"]/gi, "") : null; 
}

function psRemoveTradeMark(pProductName)
{
	pProductName=pProductName.toLowerCase();
	var temp=pProductName.indexOf("geneve");	
	if(temp>=0)
	{		
		temp=pProductName.substring(temp);		
		if(temp.length==7)
		{
			pProductName=pProductName.replace(temp, "geneve");
		}
	}
	else
	{
		temp=pProductName.indexOf("kinetic");	
		if(temp>=0)
		{		
			temp=pProductName.substring(temp);		
			if(temp.length==8)
			{
				pProductName=pProductName.replace(temp, "kinetic");
			}
		}
	}
	
	
	return pProductName;
}

function psCleanProductName(pProductName)
{
	if(pProductName!=null)
	{
		pProductName=psRemoveTradeMark(pProductName);
	}
	return (pProductName != null) ? pProductName.replace(/[\n\t\v\r�\'\"\�]/gi, "") : null; 
	//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: 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;

	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);
	// 
	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, pNewsletter, pSubscribe) 
{
    if (G_PS_DEBUG_MODE == 1 || G_PS_DEBUG_MODE == 3)
        alert("cmCreateRegistrationTag(" + pCusID + ", " + pCustEmail + ", " + pCusCity + ", " + pCusState + ", " + pCusZip + ", " + pNewsletter + ", " + pSubscribe + ")");
    if (G_PS_DEBUG_MODE == 2 || G_PS_DEBUG_MODE == 3)
        cmCreateRegistrationTag(pCusID, pCustEmail, pCusCity, pCusState, pCusZip, pNewsletter, pSubscribe);
}

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 ==================*/

/*===========================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 psCleanText(pText)
{
	var temp=pText;
	temp=temp.replace(/[\n]/g, "");	
	temp=psTrim(temp);
	return psTrim(temp);
}

function psGetUrlPath()
{
	return G_PS_URL_PATH.toLowerCase();
}

function psGetParentNode(pElement)
{	
	var temp=pElement.parentNode;	
	if(psCheckElementExist(temp)==false)
	{
		temp=pElement.parentElement;
		if(psCheckElementExist(temp)==false)
		{
			return null;
		}
	}
	
	return temp;
}

function psSaveCurCatID2Ck(pCurCatID)
{
	pCurCatID=pCurCatID.replace(/[$]/g, "@");
	psSetValueToCookie(G_PS_CK_ALL, G_PS_CUR_CATID, pCurCatID);
}

function psGetCurCatID()
{
	var temp=psGetValueFromCookie(G_PS_CK_ALL, G_PS_CUR_CATID);
	if(psCheckElementExist(temp)==false)
	{
		temp="Bookmark";
	}
	temp=temp.replace(/[@]/g, "$");
	return temp;
}

function psSaveCurPageID2Ck(pCurPageID)
{
	if(psCheckElementExist(pCurPageID)==false)
	{
		pCurPageID=psGetPageIDfrUrl_1();
	}
	pCurPageID=pCurPageID.replace(/[$]/g, "@");
	psSetValueToCookie(G_PS_CK_ALL, G_PS_CUR_PAGEID, pCurPageID);
}

function psGetCurPageID()
{
	var temp=psGetValueFromCookie(G_PS_CK_ALL, G_PS_CUR_PAGEID);
	if(psCheckElementExist(temp)==false)
	{
		temp=psGetCurCatID();
		if(psCheckElementExist(temp)==false)
		{
			temp=psGetPageIDfrUrl_1();
		}
	}
	temp=temp.replace(/[@]/g, "$");
	return temp;
}

function psIsBookmark()
{
	if (G_PS_URL_REFERRER!=""){
		if (psGetDomain(G_PS_URL_REFERRER).indexOf("allejewelry.com")>=0)
		{
			return false;
		}
	}
	
	return true;
}

function psGetEdit_Id()
{
	var temp=psGetValueFromUrl(psGetUrlPath(), "edit_id");
	if(psCheckElementExist(temp)==false)
	{
		return null;
	}
	return temp;
}

function psGetMenu()
{
	var temp=psGetValueFromUrl(psGetUrlPath(), "menu");
	if(psCheckElementExist(temp)==false)
	{
		return null;
	}
	return temp;
}

function psGetH1()
{
	var arrTemp=document.getElementsByTagName("h1");
	if(psCheckArrayExist(arrTemp)==false)
	{
		return null;
	}
	temp=arrTemp[0];
	
	temp=psGetInnerText(temp);
	temp=temp.replace(/[\n]/gi, "");	
	//temp=psHtmlDecode(temp);
	temp=psTrim(temp);	
	return temp;
}

function psGetPageNumber()
{
	var arrTemp=psGetElementsByClassName(document, "td", "blacklnk");
	if(psCheckArrayExist(arrTemp)==false)
	{
		return "0";
	}
	
	for(var i=0;i<arrTemp.length;i++)
	{
		var temp=arrTemp[i];
		temp=temp.innerHTML;
		
		if(temp.indexOf("[&nbsp;")>=0 && temp.indexOf("&nbsp;]")>=0)
		{
			var temp1=temp.indexOf("[&nbsp;");
			var temp2=temp.indexOf("&nbsp;]");
			temp=temp.substring(temp1, temp2);
			temp=temp.replace("&nbsp;]", "");
			temp=temp.replace("[&nbsp;", "");			
			return temp;
		}		
	}
	
	return "0";
}

function psGetProdid()
{
	var temp=psGetValueFromUrl(psGetUrlPath(), "prodid");
	if(psCheckElementExist(temp)==false)
	{
		return null;
	}
	return temp;
}


function psSendPageViewTag()
{
	var pageId="Home";
	var catId="Home";
	if(G_PS_PATHNAME=="/" || G_PS_PATHNAME=="/default.cfm" )
	{
		pageId=document.title;
		catId="Home";
	}
	else
		if(G_PS_PATHNAME.indexOf("/finejewelry.cfm")>=0)		
	{
		pageId=document.title;
		catId=psGetEdit_Id();
	}
	else
		if(G_PS_PATHNAME.indexOf("/jewelry.cfm")>=0)		
	{
		pageId=psGetH1();		
		
		var temp=psGetPageNumber();
		if(temp!="0")
		{
			pageId+=" page "+temp;
		}
		catId=psGetMenu();
		if(psCheckElementExist(catId)==false)
		{
			catId="Home";
		}
		
		if(catId=="24" || catId=="33" || catId=="34" || catId=="25" || catId=="26" || catId=="27" || catId=="28" || catId=="29" || catId=="30" || catId=="31" || catId=="32" || catId=="35" || catId=="36" || catId=="37" || catId=="38" || catId=="39" || catId=="40" || catId=="41" || catId=="42" || catId=="43" || catId=="44" || catId=="45" || catId=="46")
		{
			catId="menu"+catId;
		}
		
		if(psCheckElementExist(G_PS_URL_REFERRER)==true && G_PS_URL_REFERRER!="")
		{			
			if(G_PS_URL_REFERRER=="http://www.allejewelry.com/" || G_PS_URL_REFERRER=="http://www.allejewelry.com/default.cfm" || G_PS_URL_REFERRER.indexOf("http://www.allejewelry.com/default.cfm")>=0 || G_PS_URL_REFERRER.indexOf("http://www.allejewelry.com/?")>=0)
			{
				catId="Home";
			}
		}
	}
	else
		if(G_PS_PATHNAME.indexOf("/amazonresults.cfm")>=0)		
	{
		pageId=psGetH1();		
		if(psCheckElementExist(pageId)==false)
		{
			pageId="Men's Jewelry";
		}
		
		var temp=psGetPageNumber();
		if(temp!="0")
		{
			pageId+=" page "+temp;
		}
		catId=psGetProdid();
		if(psCheckElementExist(catId)==false)
		{
			catId="Home";
		}
		
		if(psCheckElementExist(G_PS_URL_REFERRER)==true && G_PS_URL_REFERRER!="")
		{			
			if(G_PS_URL_REFERRER=="http://www.allejewelry.com/" || G_PS_URL_REFERRER=="http://www.allejewelry.com/default.cfm" || G_PS_URL_REFERRER.indexOf("http://www.allejewelry.com/default.cfm")>=0 || G_PS_URL_REFERRER.indexOf("http://www.allejewelry.com/?")>=0)
			{
				catId="Home";
			}
		}
	}
	else
		if(G_PS_PATHNAME.indexOf("/checkout1.cfm")>=0)
	{
		pageId="checkout1";
		catId="checkout";
	}
	else
		if(G_PS_PATHNAME.indexOf("/checkout3.cfm")>=0)
	{
		pageId="checkout2";
		catId="checkout";
	}
	else
		if(G_PS_PATHNAME.indexOf("/thankyou.cfm")>=0)
	{
		pageId="checkout3";
		catId="checkout";
	}
	else
	{
		pageId=document.title;
		catId=psGetCurCatID();
		if(psCheckElementExist(catId)==false)
		{
			catId="Home";
		}
	}
	if(psCheckElementExist(catId)==false)
	{
		catId="Home";
	}
	
	psSaveCurCatID2Ck(catId);	
	psCreatePageviewTag(pageId, catId);
}


function psSendPageViewTag_Search()
{
	var pageId="search unsuccessful";
	var catId="search";
	if(typeof(SLI_DEFAULT_PAGE) != "undefined" && SLI_DEFAULT_PAGE != null)
	{
		pageId="search default page";
		catId="search - default";
		var searchString=null;	
		var searchResult=null;	
	}
	else
	{
		if(typeof(SLI_KEYWORD) != "undefined" && SLI_KEYWORD != null)
		{
			var searchString=SLI_KEYWORD;
		}
		else
		{
			var searchString=null;
		}
		var searchResult="0";	
		if(typeof(SLI_NUM_RESULTS) != "undefined" && SLI_NUM_RESULTS != null)
		{
			pageId="search successful";
			
			var temp=SLI_PAGE_NUM;
			if(temp!="0")
			{
				pageId+=" page "+temp;
			}
			searchResult=SLI_TOTAL_RECORDS;		
		}
	}
	psSaveCurCatID2Ck(catId);
	psCreatePageviewTag(pageId, catId, searchString, searchResult);
	
}

function psGetPrCatIDfrReferral()
{
	if(psCheckElementExist(G_PS_URL_REFERRER)==true && G_PS_URL_REFERRER!="")
	{
		if(G_PS_URL_REFERRER.indexOf("/product.cfm")>=0)
		{
			return "crosssell";
		}
		
		var temp=psGetValueFromUrl(G_PS_URL_REFERRER, "menu");
		if(psCheckElementExist(temp)==true)
		{
			var catId=temp;			
			
			if(catId=="24" || catId=="33" || catId=="34" || catId=="25" || catId=="26" || catId=="27" || catId=="28" || catId=="29" || catId=="30" || catId=="31" || catId=="32" || catId=="35" || catId=="36" || catId=="37" || catId=="38" || catId=="39" || catId=="40" || catId=="41" || catId=="42" || catId=="43" || catId=="44" || catId=="45" || catId=="46")
			{
				catId="menu"+catId;
			}
			return catId;
		}
	}
	
	return null;
}

function psSendProductViewTag()
{
	var prID=psGetProdid();
	var prName=psGetH1();
	var catId="Home";
	
	if(psIsBookmark()==true)
	{
		catId="Bookmark";
	}
	else
	{
		var temp=psGetCurCatID();
		if(psCheckElementExist(temp)==true)
		{
			if(temp=="search")
			{
				catId="search";
			}
			else
			{
				catId=psGetPrCatIDfrReferral();
				if(psCheckElementExist(catId)==false)
				{
					catId=temp;
				}
				else
				{
					psSaveCurCatID2Ck(catId);
				}
			}
		}
		else
		{
			catId=psGetPrCatIDfrReferral();
			if(psCheckElementExist(catId)==false)
			{
				catId="Home";
			}
			else
			{
				psSaveCurCatID2Ck(catId);
			}
		}
	}
	
	psCreateProductviewTag(prID, prName, catId);
}

function psSavePr2Ck()
{
	var prID=psGetProdid();	
	var catId="Home";
	
	if(psIsBookmark()==true)
	{
		catId="Bookmark";
	}
	else
	{
		var temp=psGetCurCatID();
		if(psCheckElementExist(temp)==true)
		{
			if(temp=="search")
			{
				catId="search";
			}
			else
			{
				catId=psGetPrCatIDfrReferral();
				if(psCheckElementExist(catId)==false)
				{
					catId=temp;
				}				
			}
		}
		else
		{
			catId=psGetPrCatIDfrReferral();
			if(psCheckElementExist(catId)==false)
			{
				catId="Home";
			}			
		}
		
	}
	psSetValueToCookie(G_PS_COOKIE_PROD_CATID, prID, catId);	
}

function psRegisterListener_Add2Cart()
{
	var temp=psGetElementByName(document, "form","form");
	if(psCheckElementExist(temp)==false)
	{
		return;
	}
	temp.oldFunc=temp.onsubmit;
	
	temp.onsubmit=function()
	{
		psSavePr2Ck();
		if(psCheckElementExist(this.oldFunc)==true)
		{			
			return this.oldFunc();
		}
	}	
}

function psSaveCustInfo2Ck()
{
	var temp1=document.getElementById("frm_shopperinfo");
	if(psCheckElementExist(temp1)==false)
	{
		return;
	}
	var temp=psGetElementByName(temp1, "input","email", "text");
	if(psCheckElementExist(temp)==false)
	{
		return;
	}
	
	var email=temp.value;
	
	temp=psGetElementByName(temp1, "input","bill_city", "text");
	if(psCheckElementExist(temp)==false)
	{
		return;
	}
	
	var city=temp.value;
	
	temp=psGetElementByName(temp1, "input","bill_zip", "text");
	if(psCheckElementExist(temp)==false)
	{
		return;
	}
	
	var zip=temp.value;
	
	var state="unknown";
	temp=psGetElementByName(temp1, "select", "bill_state");
	if(psCheckElementExist(temp)==false)
	{
		temp=psGetElementByName(temp1, "select", "BILL_STATE");
		if(psCheckElementExist(temp)==true)
		{
			state=temp.options[temp.selectedIndex].value;
		}		
	}
	else
	{
		state=temp.options[temp.selectedIndex].value;		
	}
	
	temp=email+G_PS_SEP+city+G_PS_SEP+state+G_PS_SEP+zip;
	psSetValueToCookie(G_PS_CK_ALL, G_PS_COOKIE_PROFILE, temp);	
}

function psRegisterListener_Register_Checkout()
{
	if(G_PS_PATHNAME.indexOf("/checkout1.cfm")<0)
	{
		return;
	}
	var temp=document.getElementById("frm_shopperinfo");
	if(psCheckElementExist(temp)==false)
	{
		return;
	}
	
	temp.oldFunc=temp.onsubmit;
	temp.onsubmit=function()
	{		
		psSaveCustInfo2Ck();
		psSetValueToCookie(G_PS_CK_ALL, G_PS_CK_SIGNIN, "false");
		if(psCheckElementExist(this.oldFunc)==true)
		{
			return this.oldFunc();
		}
	}
}

function psSaveCustInfo2Ck_Login_Checkout(pElement)
{
	var temp=psGetElementByName(pElement, "input","email", "text");
	
	if(psCheckElementExist(temp)==false)
	{
		return;
	}
	
	temp=temp.value;
	psSetValueToCookie(G_PS_CK_ALL, G_PS_COOKIE_PROFILE, temp);
}

function psRegisterListener_Login_Checkout()
{
	if(G_PS_PATHNAME.indexOf("/checkout1.cfm")<0)
	{
		return;
	}
	var temp="";
	var arrTemp=document.getElementsByTagName("form");
	if(psCheckArrayExist(arrTemp)==false)
	{
		arrTemp=document.getElementsByTagName("FORM");
		if(psCheckArrayExist(arrTemp)==false)
		{
			return;
		}
	}
	for(var i=0;i<arrTemp.length;i++)
	{
		if(arrTemp[i].action.indexOf("checkout2.cfm")>=0)
		{
			temp=arrTemp[i];
			break;
		}
	}
	if(psCheckElementExist(temp)==false || temp=="")
	{
		return;
	}
		
	temp.oldFunc=temp.onsubmit;
	temp.onsubmit=function()
	{
		psSaveCustInfo2Ck_Login_Checkout(this);
		psSetValueToCookie(G_PS_CK_ALL, G_PS_CK_SIGNIN, "false");
		if(psCheckElementExist(this.oldFunc)==true)
		{
			return this.oldFunc();
		}
	}
}


function psSendRegistrationTag_Checkout()
{
	if(G_PS_PATHNAME.indexOf("/checkout3.cfm")>=0 || G_PS_PATHNAME.indexOf("/checkout2.cfm")>=0)
	{	
		var temp=psGetValueFromCookie(G_PS_CK_ALL, G_PS_CK_SIGNIN);
		if(psCheckElementExist(temp)==false || temp=="false")
		{
			temp=psGetValueFromCookie(G_PS_CK_ALL, G_PS_COOKIE_PROFILE);
			if(psCheckElementExist(temp)==false)
			{
				return;
			}
			
			if(temp.indexOf(G_PS_SEP)>=0)
			{
				var arrTemp=temp.split(G_PS_SEP);
				if(arrTemp.length<4)
				{
					temp=arrTemp[0];
					psCreateRegistrationTag(temp, temp);
				}
				else
				{					
					var email=arrTemp[0];
					var cusId=email;
					var city=arrTemp[1];
					var state=arrTemp[2];
					var zip=arrTemp[3];
					psCreateRegistrationTag(cusId, email, city, state, zip);
				}
				psSetValueToCookie(G_PS_CK_ALL, G_PS_CK_SIGNIN,"true");
			}
		}
	}
}

function psGetCartTable()
{
	var temp=psGetElementByName(document, "form", "form");
	if(psCheckElementExist(temp)==false)
	{
		return null;
	}
	var arrTemp=temp.getElementsByTagName("table");
	if(psCheckArrayExist(arrTemp)==false)
	{
		return null;
	}
	for(var i=0;i<arrTemp.length;i++)
	{
		var temp=arrTemp[i];
		var row=temp.rows[0];
		if(psCheckElementExist(row)==true)
		{
			var cell=row.cells[1];
			if(psCheckElementExist(cell)==true)
			{
				temp=psGetInnerText(cell);
				temp=temp.toLowerCase();
				if(temp.indexOf("item description")>=0)
				{
					return arrTemp[i];
				}
			}
		}		
	}
	return null;
}

function psGetPrID_Shop5(pCell)
{
	var arrTemp=pCell.getElementsByTagName("a");
	if(psCheckArrayExist(arrTemp)==false)
	{
		return null;
	}
	var temp=arrTemp[0];
	if(psCheckElementExist(temp.href)==false)
	{
		return null;
	}
	temp=temp.href;
	temp=psGetValueFromUrl(temp, "prodid");
	if(psCheckElementExist(temp)==false)
	{
		return null;
	}
	
	return temp;
}

function psGetPrName_Shop5(pCell)
{
	var temp=pCell.innerHTML;
	temp=temp.toLowerCase();
	if(temp.indexOf("<br>")>=0)
	{
		var arrTemp=temp.split("<br>");
		temp=arrTemp[0];
		temp=psTrim(temp);
	}
	return temp;
}

function psGetQuan_Shop5(pCell)
{
	var arrTemp=pCell.getElementsByTagName("input");
	if(psCheckArrayExist(arrTemp)==false)
	{
		return null;
	}
	var temp=arrTemp[0];
	temp=temp.value;	
	return temp;
}

function psGetPrice_Shop5(pCell)
{
	var temp=psGetInnerText(pCell);
	temp=temp.replace("$","").replace(/[\n]/gi, "");
	temp=psTrim(temp);
	return temp;
}

function psGetPrCatIDfrPrId(pPrID)
{
	var temp=psGetValueFromCookie(G_PS_COOKIE_PROD_CATID, pPrID);
	if(psCheckElementExist(temp)==false)
	{
		return "unknown";
	}
	
	return temp;
}

function psRegisterListener_SetCat_Shop5(pCell, pCatId)
{
	var arrTemp=pCell.getElementsByTagName("a");
	if(psCheckArrayExist(arrTemp)==false)
	{
		return null;
	}
	var temp=arrTemp[0];
	temp.oldFunc=temp.onclick;
	temp.onclick=function()
	{		
		psSaveCurCatID2Ck(pCatId);
		if(psCheckElementExist(this.oldFunc)==true)
		{
			return this.oldFunc();
		}
	}
}

function psSendShop5Tags(arrPrID, arrPrName, arrPrQuan, arrPrPrice, arrPrCatID)
{
	psSetCookie(G_PS_CK_SHOP5, "temp", "delete" );
	for(var i=0;i<arrPrPrice.length;i++)
	{		
		psCreateShopAction5Tag(arrPrID[i], arrPrName[i], arrPrQuan[i], arrPrPrice[i], arrPrCatID[i]);
		psSetValueToCookie(G_PS_CK_SHOP5, arrPrID[i], arrPrCatID[i]);
	}
	if(arrPrPrice.length>0)
	{
		psDisplayShop5s();
	}
}

function psSendShop5ActionTags()
{
	var temp=psGetCartTable();
	if(psCheckElementExist(temp)==false)
	{
		return null;
	}	
	
	var arrPrID=new Array();
	var arrPrName=new Array();
	var arrPrCatID=new Array();
	var arrPrQuan=new Array();
	var arrPrPrice=new Array();
	var arrIndex=0;
	
	var index=2;
	var next=true;
	while(next==true)
	{
		var row=temp.rows[index];
		if(psCheckElementExist(row)==false)
		{
			next=false;
			break;
		}
		
		var cell=row.cells[0];
		if(psCheckElementExist(cell)==false)
		{
			next=false;
			break;
		}
		arrPrID[arrIndex]=psGetPrID_Shop5(cell);
		
		arrPrCatID[arrIndex]=psGetPrCatIDfrPrId(arrPrID[arrIndex]);
		psRegisterListener_SetCat_Shop5(cell, arrPrCatID[arrIndex]);
		
		if(psCheckElementExist(arrPrID[arrIndex])==false)
		{
			next=false;
			break;
		}
		
		cell=row.cells[1];
		if(psCheckElementExist(cell)==false)
		{
			next=false;
			break;
		}
		arrPrName[arrIndex]=psGetPrName_Shop5(cell);
		
		cell=row.cells[2];
		if(psCheckElementExist(cell)==false)
		{
			next=false;
			break;
		}
		
		arrPrQuan[arrIndex]=psGetQuan_Shop5(cell);		
		if(psCheckElementExist(arrPrQuan[arrIndex])==false)
		{
			next=false;
			break;
		}
		
		cell=row.cells[3];
		if(psCheckElementExist(cell)==false)
		{
			next=false;
			break;
		}
		arrPrPrice[arrIndex]=psGetPrice_Shop5(cell);		
		
		arrIndex++;		
		index+=2;		
	}
	
	psSendShop5Tags(arrPrID, arrPrName, arrPrQuan, arrPrPrice, arrPrCatID);
}

function psGetOrderID()
{
	var temp=psGetValueFromUrl(psGetUrlPath(), "purchord");
	if(psCheckElementExist(temp)==false)
	{
		return "unknown";
	}
	return temp;
}

function psGetCartTable_S9()
{
	var arrTemp=document.getElementsByTagName("table");
	if(psCheckArrayExist(arrTemp)==false)
	{
		return null;
	}	
	for(var i=0;i<arrTemp.length;i++)
	{
		if(arrTemp[i].width=="600" && arrTemp[i].cellSpacing=="2" && arrTemp[i].cellPadding=="2" && arrTemp[i].border=="1")
		{
			return arrTemp[i];
		}
	}
	
	return null;
}

function psGetPrID_Shop9(pElement)
{
	var temp=psGetInnerText(pElement);
	temp=psCleanText(temp);
	return temp;
}

function psGetPrName_Shop9(pElement)
{
	var temp=pElement.innerHTML;
	temp=temp.toLowerCase();
	if(temp.indexOf("<br>")>=0)
	{
		var arrTemp=temp.split("<br>");
		temp=arrTemp[1];
	}
	temp=psGetInnerText(temp);
	temp=psHtmlDecode(temp);
	temp=psCleanText(temp);
	return temp;
}

function psGetPrQuan_Shop9(pElement)
{
	var temp=psGetInnerText(pElement);
	temp=psCleanText(temp);

	return temp;
}

function psGetPrPrice_Shop9(pElement)
{
	var temp=psGetInnerText(pElement);
	temp=psCleanText(temp);
	temp=temp.replace("$","");
	return temp;
}

function psGetPrCatIDfrPrId_Sh9(pPrID)
{
	var temp=psGetValueFromCookie(G_PS_CK_SHOP5, pPrID);	
	if(psCheckElementExist(temp)==false)
	{
		return "unknown";
	}
	
	return temp;
}

function psSendShop9Tags(arrPrID, arrPrName, arrPrQuan, arrPrPrice, cusID, orderID, orderTotal, arrPrCatID)
{
	for(var i=0;i<arrPrID.length;i++)
	{
		psCreateShopAction9Tag(arrPrID[i], arrPrName[i], arrPrQuan[i], arrPrPrice[i], cusID, orderID, orderTotal, arrPrCatID[i]);
	}
	
	if(arrPrID.length>0)
	{
		psDisplayShop9s();
	}
}

function psSendShop9ActionTags()
{
	var temp=psGetOrderID();
	var orderID=temp;
	if(psCheckElementExist(orderID)==false)
	{
		return;
	}

	temp=psGetValueFromCookie(G_PS_CK_ALL, G_PS_CK_SHOP9);
	if(psCheckElementExist(temp)==false)
	{
		return;
	}
	if(temp.indexOf(G_PS_SEP)<0)
	{
		return;
	}
	
	var arrTemp=temp.split(G_PS_SEP);
	if(arrTemp.length<6)
	{
		return;
	}
	var cusID=arrTemp[0];
	var city=arrTemp[1];
	var state=arrTemp[2];
	var zip=arrTemp[3];
	var orderTotal=arrTemp[4];
	var orderShipping=arrTemp[5];
	
	temp=psGetCartTable_S9();
	if(psCheckElementExist(temp)==false)
	{
		return;
	}
	
	var arrPrID=new Array();
	var arrPrName=new Array();
	var arrPrCatID=new Array();
	var arrPrQuan=new Array();
	var arrPrPrice=new Array();
	var arrIndex=0;
	var next=true;
	var index=1;		
	
	while(next==true)
	{
		var row=temp.rows[index];
		if(psCheckElementExist(row)==false)
		{
			next=false;
			break;
		}
		
		var cell=row.cells[0];
		if(psCheckElementExist(cell)==false)
		{
			next=false;
			break;
		}
		
		var temp1=psGetPrID_Shop9(cell);
		if(psCheckElementExist(temp1)==false)
		{
			next=false;
			break;
		}
		arrPrID[arrIndex]=temp1;
		
		cell=row.cells[1];
		if(psCheckElementExist(cell)==false)
		{
			next=false;
			break;
		}
		
		arrPrQuan[arrIndex]=psGetPrQuan_Shop9(cell);
		
		cell=row.cells[2];
		if(psCheckElementExist(cell)==false)
		{
			next=false;
			break;
		}
		
		arrPrName[arrIndex]=psGetPrName_Shop9(cell);		
		
		cell=row.cells[3];
		if(psCheckElementExist(cell)==false)
		{
			next=false;
			break;
		}
		
		arrPrPrice[arrIndex]=psGetPrPrice_Shop9(cell);		
		arrPrCatID[arrIndex]=psGetPrCatIDfrPrId_Sh9(arrPrID[arrIndex]);		
		arrIndex++;		
		index++;		
	}
	
	psSendShop9Tags(arrPrID, arrPrName, arrPrQuan, arrPrPrice, cusID, orderID, orderTotal, arrPrCatID);
	
	psCreateOrderTag(orderID, orderTotal, orderShipping, cusID, city, state, zip);
}

function psGetTable_Checkout2()
{
	var temp=psGetElementByName(document, "form", "form");
	if(psCheckElementExist(temp)==false)
	{
		return;
	}	
	var arrTemp=temp.getElementsByTagName("table");
	if(psCheckArrayExist(arrTemp)==false)
	{
		return null;
	}
	
	for(var i=0;i<arrTemp.length;i++)
	{
		if(arrTemp[i].width=="600" && arrTemp[i].cellSpacing=="2" && arrTemp[i].cellPadding=="2" && arrTemp[i].border=="1")
		{
			return arrTemp[i];
		}
	}
	
	return null;
}

function psGetLastRow(pElement)
{
	var temp=pElement;
	var next=true;
	var index=0;
	while(next==true)
	{
		var row=temp.rows[index];
		if(psCheckElementExist(row)==false)
		{
			next=false;
			break;
		}		
		index++;
	}
	
	index--;
	return index;
}

function psGetSubTotal_Shipping()
{
	var temp=psGetTable_Checkout2();
	if(psCheckElementExist(temp)==false)
	{
		return null;
	}
	
	var temp1=psGetLastRow(temp);	
	
	var index=temp1;
	index--;
	var row=temp.rows[index];
	if(psCheckElementExist(row)==false)
	{
		return null;
	}
	
	var cell=row.cells[2];
	if(psCheckElementExist(cell)==false)
	{
		return null;
	}
	var total=psGetPrice_Shop5(cell);
	total=total.replace(/[,]/gi, "");	
	
	index--;
	row=temp.rows[index];
	if(psCheckElementExist(row)==false)
	{
		return null;
	}
	
	cell=row.cells[2];
	if(psCheckElementExist(cell)==false)
	{
		return null;
	}
	var shipping=psGetPrice_Shop5(cell);
	shipping=shipping.replace(/[,]/gi, "");	
	var subTotal=parseFloat(total)-parseFloat(shipping);	
	temp= subTotal+G_PS_SEP+shipping;
	return temp;	
}

function psGetBillingAddressTable()
{
	var arrTemp=document.getElementsByTagName("table");
	if(psCheckArrayExist(arrTemp)==false)
	{
		return null;
	}
	
	for(var i=0;i<arrTemp.length;i++)
	{
		if(arrTemp[i].width=="600" && arrTemp[i].align=="center" && arrTemp[i].border=="0")
		{
			return arrTemp[i];
		}
	}
	
	return null;
}

function psGetCityStateZip_Checkout3(pText)
{
	var temp=pText;	
	var arrTemp=temp.split(",");
	var city=psCleanText(arrTemp[0]);	
	temp=psCleanText(psGetInnerText(arrTemp[1]));	
	arrTemp=temp.split("	");
	if(arrTemp.length==1)
	{
		arrTemp=temp.split(" ");
	}
	var state=psCleanText(arrTemp[0]);	
	var zip=psCleanText(arrTemp[arrTemp.length-1]);	
	temp=city+G_PS_SEP+state+G_PS_SEP+zip;	
	return temp;
}

function psGetBillingAddress()
{
	var temp=psGetBillingAddressTable();
	if(psCheckElementExist(temp)==false)
	{
		return null;
	}
	
	var row=temp.rows[3];
	if(psCheckElementExist(row)==false)
	{
		return null;
	}
	
	var cell=row.cells[0];
	if(psCheckElementExist(cell)==false)
	{
		return null;
	}
	
	temp=cell.innerHTML;
	temp=temp.toLowerCase();
	var arrTemp=temp.split("<br>");
	var cusId=psCleanText(psGetInnerText(arrTemp[arrTemp.length-1]));
	
	temp=arrTemp[arrTemp.length-3];
	temp=psGetCityStateZip_Checkout3(temp);
	temp=cusId+G_PS_SEP+temp;
	return temp;
}

function psSaveBillingInfo()
{
	if(G_PS_PATHNAME.indexOf("/checkout3.cfm")<0)
	{
		return;
	}
	var temp=psGetSubTotal_Shipping();
	if(psCheckElementExist(temp)==false)
	{
		return null;
	}
	
	var temp1= psGetBillingAddress();
	if(psCheckElementExist(temp1)==false)
	{
		return null;
	}
	temp=temp1+G_PS_SEP+temp;
	psSetValueToCookie(G_PS_CK_ALL, G_PS_CK_SHOP9, temp);	
}