/************************************************************************************/
/* $Revision: $
 * $Id: $
 *
 * Author: Coremetrics/PSD 
 * Coremetrics  v1.3, 11/26/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_COOKIE_LIFETIME = 432000; // 5*24*60*60 = 5 days
var G_PS_COOKIE_PAGEID = "PS_PAGEID";
// current category ID while browsing/searching/refining, etc
var G_PS_CUR_CATID = null;

var G_PS_URL_REFERRER = document.referrer.toLowerCase();
var G_PS_COOKIE_PROFILE = "PS_PROFILE";
var G_PS_CK_ALL="PS_ALL";
var G_PS_CK_SIGNIN="PS_CK_SIGNIN";
var G_PS_SEP="-_-";
/*========================= END GLOBAL VARIABLES =============================*/

/*=========================== BEGIN NAVIGATION ===============================*/

if (psIsDomainToTag())
{
	var pageId = psGetPageId();
	var catId = psGetCatId();

	if (document.body != null && document.body.innerHTML.search(/The resource cannot be found./gi)>=0)
	{
		psCreateErrorTag("System Error", "HOME");
	}
	else if (G_PS_PATHNAME == "/" || G_PS_PATHNAME == "" || G_PS_PATHNAME == "/home.aspx")
	{
		pageId = "Home";
		catId = "HOME";
	}
	else if (G_PS_PATHNAME == "/directories.aspx")
	{
		pageId = "Directories";
		catId = "HOME";
	}
	else if (G_PS_PATHNAME == "/contactus.aspx")
	{
		pageId = "Contact Us";
		catId = "HOME";
	}
	else if (G_PS_PATHNAME == "/sitemap.aspx")
	{
		pageId = "Site Map";
		catId = "HOME";
	}
	else if (G_PS_PATHNAME == "/privacypolicy.aspx")
	{
		pageId = "Privacy Policy";
		catId = "HOME";
	}
	else if (G_PS_PATHNAME == "/prescreen.aspx")
	{
		catId = "APPLICANT PRE-SCREEN";
		pageId = psGetCookie(G_PS_COOKIE_PAGEID); // DEBUG
		/*
		// These lines of code are supposed to be hosted in the pages:
		//	- http://legacy.celtic-net.com/prescreening/default.aspx
		//	- http://legacy.celtic-net.com/quikanswers/agentlogin.asp
		if (document.Form1 != null)
		{
			pageId = document.Form1.action;
			pageId = (pageId != null ? pageId.toLowerCase().replace(".aspx", "") : G_PS_PATHNAME);
		}
		*/
	}
	else if (G_PS_PATHNAME == "/billing.aspx")
	{
		catId = "BILLING INFORMATION";
		pageId = psGetCookie(G_PS_COOKIE_PAGEID); // DEBUG
		/*
		// These lines of code are supposed to be hosted in the pages:
		//	- http://legacy.celtic-net.com/prescreening/default.aspx
		//	- http://legacy.celtic-net.com/quikanswers/agentlogin.asp
		if (document.Form1 != null)
		{
			pageId = document.Form1.action;
			pageId = (pageId != null ? pageId.toLowerCase().replace(".aspx", "") : G_PS_PATHNAME);
		}
		*/
	}
	else if (G_PS_PATHNAME.search(/\/states\//gi)>=0)
		catId = "STATES";
	else if (G_PS_PATHNAME == "/interior_twocolumn_nopromo.aspx")
		catId = "ABOUTUS";
	else if (G_PS_PATHNAME == "/promonewagent.aspx")
		catId = "LEARNINGCENTER";
	else if (G_PS_PATHNAME == "/promonewagent.aspx")
		catId = "HOME";
	else if (G_PS_PATHNAME == "/health_savings_account.aspx")
	{
		catId = "LEARNINGCENTER";
		pageId += " page 1";
	}	
	else if (G_PS_PATHNAME == "/hsaresourcecenter2.aspx")
	{
		catId = "LEARNINGCENTER";
		pageId += " page 2";
	}
	else if (G_PS_PATHNAME == "/hsaresourcefaqs.aspx")
	{
		catId = "LEARNINGCENTER";
		pageId = "HSA Resource Center page 3";
	}
	else if (G_PS_PATHNAME == "/internalintegration.aspx")
	{
		catId = "DIRECTORIES";
		pageId = "Agent Directory";
	}
	else if (G_PS_PATHNAME == "/individual-major-medical-health-insurance.aspx") { catId = "INDIVIDUALHEALTHPLANS"; pageId = "Individual Major Medical Health Insurance"; }
	else if (G_PS_PATHNAME == "/webinarpresentations.aspx") { catId = "AGENTLEARNINGCENTER"; pageId = "Agent Sales Webinars"; }

	else if (G_PS_PATHNAME == "/individual-health-insurance-company.aspx") { catId = "About Us"; pageId = "About Us"; }
	else if (G_PS_PATHNAME == "/ohio-open-enrollment.aspx") { catId = "Customer Service"; pageId = "Ohio Open Enrollment"; }
	else if (G_PS_PATHNAME == "/wiproviders.aspx") { catId = "Home"; pageId = "Wisconsin Network Providers"; }
	else if (G_PS_PATHNAME == "/find-health-insurance.aspx") { catId = "Consumer"; pageId = "Find Health Insurance"; }
	else if (G_PS_PATHNAME == "/personal-health-insurance.aspx") { catId = "Consumer"; pageId = "Personal Health Insurance"; }
	else if (G_PS_PATHNAME == "/new-agent-kit.aspx") { catId = "Agent"; pageId = "New Agent Kit"; }
	else if (G_PS_PATHNAME == "/health-insurance-education.aspx") { catId = "Learning Center"; pageId = "Health Insurance Education"; }
	else if (G_PS_PATHNAME == "/x-marks-the-spot.aspx") { catId = "Agent"; pageId = "X Marks the Spot"; }
	else if (G_PS_PATHNAME == "/individual-health-coverage.aspx") { catId = "Learning Center"; pageId = "Individual Health Coverage"; }
	else if (G_PS_PATHNAME == "/short-term-health-insurance.aspx") { catId = "Individual Health Plans"; pageId = "Short Term Medical Insurance"; }
	else if (G_PS_PATHNAME == "/set-sail-with-celtic.aspx") { catId = "Agent"; pageId = "Set Sail with Celtic"; }
    else if (G_PS_PATHNAME == "/high-deductible-health-insurance.aspx") { catId = "Learning Center"; pageId = "HSA Resource Center"; }
    else if (G_PS_PATHNAME == "/shortcuts4q09.aspx") { catId = "Agent"; pageId = "4Q09 online edition of Shortcuts"; }
    else if (G_PS_PATHNAME == "/celtic-treasure-chest.aspx") { catId = "Agent"; pageId = "Celtic Treasure Chest"; }
    else if (G_PS_PATHNAME == "/affordable-student-medical-insurance.aspx") { catId = "Individual Health Plans"; pageId = "Affordable Student Health Insurance"; }
    else if (G_PS_PATHNAME == "/hsa-insurance.aspx") { catId = "Learning Center"; pageId = "HSA Insurance FAQs"; }
    else if (G_PS_PATHNAME == "/h1n1.aspx") { catId = "Customer Service"; pageId = "H1N1 Flu Virus Info"; }
    else if (G_PS_PATHNAME == "/aztopplans.aspx") { catId = "Agent"; pageId = "Arizona Top plans"; }
    else if (G_PS_PATHNAME == "/health-savings-accounts.aspx") { catId = "Learning Center"; pageId = "HSA Healthcare Links"; }
    else if (G_PS_PATHNAME == "/tx-rate-decrease.aspx") { catId = "Agent"; pageId = "Rate Decrease in Texas"; }
    else if (G_PS_PATHNAME == "/quikformswestvirginia.aspx") { catId = "Agent"; pageId = "QuikForms West Virginia"; }
    else if (G_PS_PATHNAME == "/shortcuts3q09.aspx") { catId = "Agent"; pageId = "3Q09 online edition of Shortcuts"; }
    else if (G_PS_PATHNAME == "/short-term-medical-insurance.aspx") { catId = "Individual Health Plans"; pageId = "Short Term Medical Insurance"; }
    else if (G_PS_PATHNAME == "/shoot-for-the-stars.aspx") { catId = "Agent"; pageId = "Shoot for the Stars"; }
    else if (G_PS_PATHNAME == "/mi-rate-decrease.aspx") { catId = "Agent"; pageId = "Rate Decrease in Michigan"; }
	
else if (G_PS_PATHNAME == "/low_cost_health_insurance.aspx") { catId = "ABOUTUS";  pageId = "LOW_COST_HEALTH_INSURANCE";}
else if (G_PS_PATHNAME == "/ambestrating.aspx") { catId = "ABOUTUS";  pageId = "AMBESTRATING";}
else if (G_PS_PATHNAME == "/quikforms_state_selection.aspx") { catId = "AGENT";  pageId = "QUIKFORMS__STATE_SELECTION";}
else if (G_PS_PATHNAME == "/outofthisworld.aspx") { catId = "AGENT";  pageId = "OUTOFTHISWORLD";}
else if (G_PS_PATHNAME == "/quikformsillinois.aspx") { catId = "AGENT";  pageId = "QUIKFORMS_ILLINOIS";}
else if (G_PS_PATHNAME == "/quikformsnorthcarolina.aspx") { catId = "AGENT";  pageId = "QUIKFORMS_NORTHCAROLINA";}
else if (G_PS_PATHNAME == "/quikformsmississippi.aspx") { catId = "AGENT";  pageId = "QUIKFORMS_MISSISSIPPI";}
else if (G_PS_PATHNAME == "/quikformsmichigan.aspx") { catId = "AGENT";  pageId = "QUIKFORMS_MICHIGAN";}
else if (G_PS_PATHNAME == "/quikformsflorida.aspx") { catId = "AGENT";  pageId = "QUIKFORMS_FLORIDA";}
else if (G_PS_PATHNAME == "/quikformsnewhampshire.aspx") { catId = "AGENT";  pageId = "QUIKFORMS_NEWHAMPSHIRE";}
else if (G_PS_PATHNAME == "/quikformspennsylvania.aspx") { catId = "AGENT";  pageId = "QUIKFORMS_PENNSYLVANIA";}
else if (G_PS_PATHNAME == "/quikformsmissouri.aspx") { catId = "AGENT";  pageId = "QUIKFORMS_MISSOURI";}
else if (G_PS_PATHNAME == "/quikformswyoming.aspx") { catId = "AGENT";  pageId = "QUIKFORMS_WYOMING";}
else if (G_PS_PATHNAME == "/quikformsgeorgia.aspx") { catId = "AGENT";  pageId = "QUIKFORMS_GEORGIA";}
else if (G_PS_PATHNAME == "/quikformstexas.aspx") { catId = "AGENT";  pageId = "QUIKFORMS_TEXAS";}
else if (G_PS_PATHNAME == "/quikformswisconsin.aspx") { catId = "AGENT";  pageId = "QUIKFORMS_WISCONSIN";}
else if (G_PS_PATHNAME == "/individual_health_insurance_policy.aspx") { catId = "AGENT";  pageId = "INDIVIDUAL_HEALTH_INSURANCE_POLICY";}
else if (G_PS_PATHNAME == "/quikformstennessee.aspx") { catId = "AGENT";  pageId = "QUIKFORMS_TENNESSEE";}
else if (G_PS_PATHNAME == "/quikformssouthcarolina.aspx") { catId = "AGENT";  pageId = "QUIKFORMS_SOUTHCAROLINA";}
else if (G_PS_PATHNAME == "/quikformsindiana.aspx") { catId = "AGENT";  pageId = "QUIKFORMS_INDIANA";}
else if (G_PS_PATHNAME == "/quikformskansas.aspx") { catId = "AGENT";  pageId = "QUIKFORMS_KANSAS";}
else if (G_PS_PATHNAME == "/quikformsconnecticut.aspx") { catId = "AGENT";  pageId = "QUIKFORMS_CONNECTICUT";}
else if (G_PS_PATHNAME == "/quikformsmaryland.aspx") { catId = "AGENT";  pageId = "QUIKFORMS_MARYLAND";}
else if (G_PS_PATHNAME == "/jackpot.aspx") { catId = "AGENT";  pageId = "JACKPOT";}
else if (G_PS_PATHNAME == "/quikformsnewmexico.aspx") { catId = "AGENT";  pageId = "QUIKFORMS_NEWMEXICO";}
else if (G_PS_PATHNAME == "/benefitmall.aspx") { catId = "AGENT";  pageId = "BENEFITMALL";}
else if (G_PS_PATHNAME == "/quikformscalifornia.aspx") { catId = "AGENT";  pageId = "QUIKFORMS_CALIFORNIA";}
else if (G_PS_PATHNAME == "/quikformsarkansas.aspx") { catId = "AGENT";  pageId = "QUIKFORMS_ARKANSAS";}
else if (G_PS_PATHNAME == "/quikformsalaska.aspx") { catId = "AGENT";  pageId = "QUIKFORMS_ALASKA";}
else if (G_PS_PATHNAME == "/celticrockstar.aspx") { catId = "AGENT";  pageId = "CELTICROCKSTAR";}
else if (G_PS_PATHNAME == "/quikformsalabama.aspx") { catId = "AGENT";  pageId = "QUIKFORMS_ALABAMA";}
else if (G_PS_PATHNAME == "/quikformscolorado.aspx") { catId = "AGENT";  pageId = "QUIKFORMS_COLORADO";}
else if (G_PS_PATHNAME == "/quikformsohio.aspx") { catId = "AGENT";  pageId = "QUIKFORMS_OHIO";}
else if (G_PS_PATHNAME == "/quikformslouisiana.aspx") { catId = "AGENT";  pageId = "QUIKFORMS_LOUISIANA";}
else if (G_PS_PATHNAME == "/quikformsarizona.aspx") { catId = "AGENT";  pageId = "QUIKFORMS_ARIZONA";}
else if (G_PS_PATHNAME == "/humanamarketpoint.aspx") { catId = "AGENT";  pageId = "HUMANAMARKETPOINT";}
else if (G_PS_PATHNAME == "/quikformsnebraska.aspx") { catId = "AGENT";  pageId = "QUIKFORMS_NEBRASKA";}
else if (G_PS_PATHNAME == "/quikformsiowa.aspx") { catId = "AGENT";  pageId = "QUIKFORMS_IOWA";}
else if (G_PS_PATHNAME == "/quikformsidaho.aspx") { catId = "AGENT";  pageId = "QUIKFORMS_IDAHO";}
else if (G_PS_PATHNAME == "/quikforms_virginia.aspx") { catId = "AGENT";  pageId = "QUIKFORMS__VIRGINIA";}
else if (G_PS_PATHNAME == "/quikformssouthdakota.aspx") { catId = "AGENT";  pageId = "QUIKFORMS_SOUTHDAKOTA";}
else if (G_PS_PATHNAME == "/nctopplans.aspx") { catid = "AGENT";  pageId = "NCTOPPLANS";}
else if (G_PS_PATHNAME == "/statelanding.aspx") { catid = "AGENT";  pageId = "STATELANDING";}
else if (G_PS_PATHNAME == "/freegift.aspx") { catid = "AGENT";  pageId = "FREEGIFT";}
else if (G_PS_PATHNAME == "/agentcash.aspx") { catid = "AGENT";  pageId = "AGENTCASH";}
else if (G_PS_PATHNAME == "/quikformsdelaware.aspx") { catId = "AGENT";  pageId = "QUIKFORMS_DELAWARE";}
else if (G_PS_PATHNAME == "/quikformsoklahoma.aspx") { catId = "AGENT";  pageId = "QUIKFORMS_OKLAHOMA";}
else if (G_PS_PATHNAME == "/mitopplans.aspx") { catid = "AGENT";  pageId = "MITOPPLANS";}
else if (G_PS_PATHNAME == "/cobra-insurance-coverage.aspx") { catId = "CONSUMER";  pageId = "COBRA-INSURANCE-COVERAGE";}
else if (G_PS_PATHNAME == "/txproviders.aspx") { catId = "CUSTOMERSERVICE";  pageId = "TXPROVIDERS";}
else if (G_PS_PATHNAME == "/carolinaproviders.aspx") { catId = "CUSTOMERSERVICE";  pageId = "CAROLINAPROVIDERS";}
else if (G_PS_PATHNAME == "/miproviders.aspx") { catId = "CUSTOMERSERVICE";  pageId = "MIPROVIDERS";}
else if (G_PS_PATHNAME == "/locate_a_doctor.aspx") { catId = "CUSTOMERSERVICE";  pageId = "LOCATE_A_DOCTOR";}
else if (G_PS_PATHNAME == "/home.aspx") { catid = "HOME";  pageId = "/HOME";}
else if (G_PS_PATHNAME == "/consumer-contact-request.ASPX") { catId = "HOME";  pageId = "CONSUMER-CONTACT-REQUEST";}
else if (G_PS_PATHNAME == "/celticareva.aspx") { catId = "INDIVIDUALHEALTHPLANS";  pageId = "CELTICAREVA";}
else if (G_PS_PATHNAME == "/celticarenv.aspx") { catId = "INDIVIDUALHEALTHPLANS";  pageId = "CELTICARENV";}
else if (G_PS_PATHNAME == "/shortcuts2q09.aspx") { catId = "LEARNINGCENTER";  pageId = "SHORTCUTS2Q09";}
else if (G_PS_PATHNAME == "/hsa-insurance-plans.aspx") { catId = "LEARNINGCENTER";  pageId = "HSA-INSURANCE-PLANS";}
else if (G_PS_PATHNAME == "/multi-line-producer.aspx") { catId = "LEARNINGCENTER";  pageId = "MULTI-LINE-PRODUCER";}
else if (G_PS_PATHNAME == "/shortcuts1q09.aspx") { catid = "LEARNINGCENTER";  pageId = "SHORTCUTS1Q09";}
else if (G_PS_PATHNAME == "/uploadedfiles/pdfs/agent_newsletters/shortcuts2q09.pdf") { catId = "LEARNINGCENTER";  pageId = "UPLOADEDFILES/PDFS/AGENT_NEWSLETTERS/SHORTCUTS2Q09.PDF";}
else if (G_PS_PATHNAME == "/agentnewsletterarchive.aspx") { catId = "LEARNINGCENTER";  pageId = "AGENTNEWSLETTERARCHIVE";}
else if (G_PS_PATHNAME == "/frequentlyasked.aspx") { catId = "LEARNINGCENTER";  pageId = "FREQUENTLYASKED";}
else if (G_PS_PATHNAME == "/beyond-hard-sell.aspx") { catId = "LEARNINGCENTER";  pageId = "BEYOND-HARD-SELL";}
else if (G_PS_PATHNAME == "/agentnotificationsarchive.aspx") { catId = "LEARNINGCENTER";  pageId = "AGENTNOTIFICATIONSARCHIVE";}
else if (G_PS_PATHNAME == "/affordable-individual-health-coverage.aspx") { catId = "LEARNINGCENTER";  pageId = "AFFORDABLE-INDIVIDUAL-HEALTH-COVERAGE";}
else if (G_PS_PATHNAME == "/uploadedfiles/pdfs/agent_newsletters/shortcuts4q08") { catId = "LEARNINGCENTER";  pageId = "UPLOADEDFILES/PDFS/AGENT_NEWSLETTERS/SHORTCUTS4Q08";}
else if (G_PS_PATHNAME == "/uploadedfiles/pdfs/agent_newsletters/shortcuts1q09.pdf") { catId = "LEARNINGCENTER";  pageId = "UPLOADEDFILES/PDFS/AGENT_NEWSLETTERS/SHORTCUTS1Q09.PDF";}
else if (G_PS_PATHNAME == "/shortcuts4q08.aspx") { catId = "LEARNINGCENTER";  pageId = "SHORTCUTS4Q08";}
else if (G_PS_PATHNAME == "/shortcuts3q08.aspx") { catId = "LEARNINGCENTER";  pageId = "SHORTCUTS3Q08";}
else if (G_PS_PATHNAME == "/shortcuts2q08.aspx") { catId = "LEARNINGCENTER";  pageId = "SHORTCUTS2Q08";}
else if (G_PS_PATHNAME == "/medical-insurance-quote.aspx") { catId = "QUOTE";  pageId = "MEDICAL-INSURANCE-QUOTES";}
	else if (catId == null) // Default pageId & catId
	{
		pageId = G_PS_PATHNAME;
		catId = "NO CATEGORY RULE FOUND";
	}
	//
	// Throw pageview at last
	G_PS_CUR_CATID = catId; // For use later
	
	if(psCheckElementExist(pageId)==true)
	{
		psCreatePageviewTag(pageId, G_PS_CUR_CATID, null, null); // Other pages go to "ADD URL" category
	}
}
else
{
	if (document.location.hostname.search(/legacy.celtic-net.com/gi)>=0)
	{
		if (document.Form1 != null)
		{
			var pageId = document.Form1.action;
			pageId = (pageId != null ? pageId.toLowerCase().replace(".aspx", "") : G_PS_PATHNAME);
			pageId = (pageId != null ? pageId.toLowerCase().replace(".asp", "") : G_PS_PATHNAME);
			psSetCookie(G_PS_COOKIE_PAGEID, pageId);
		}
	}
	
	psRegisterListener_Register();
	psRegisterListener_NewUser();
	psSendRegistrationTag_NewUser();
	psSendRegistrationTag_Login();
}

/*
 * Only tag the following domain
 * - www.celtic-net.com 
 * - 
 */
function psIsDomainToTag()
{
	var result = false;
	var domain = document.location.hostname.replace("www.", "").toLowerCase();
	result = (domain.search(/celtic-net.com/gi)>=0) && ((domain != "agent.celtic-net.com") && (domain != "legacy.celtic-net.com"));

	return result;
}

/*============================ END NAVIGATION ================================*/


/*===================== BEGIN TAGGING BUSSINESS LOGIC ========================*/
/*
 * Get general catId from source code
 * Look for id attribute of the first span of the dropmenudiv containing the current file name,
 * then exclude the leading "CTl00_MIDDLEMENU1_" and trailling "MENU" from the span id
 */
function psGetCatId()
{
	var fileName = G_PS_PATHNAME.substring(G_PS_PATHNAME.lastIndexOf("/")+1, G_PS_PATHNAME.length);
	var firstSpan = null;
	var catId = null;
	var menus = psGetElementsByClassName("dropmenudiv");
	
	for (var i = 0; i < menus.length; i++)
	{
		firstSpan = menus[i].getElementsByTagName("span");
		firstSpan = (firstSpan.length > 0 ? firstSpan[0] : null);
		if (firstSpan != null && firstSpan.innerHTML.toLowerCase().indexOf(fileName)>=0) // the right span (span containing the current hyperlink)?
		{
			catId = firstSpan.id;
			catId = (catId != null ? catId.toUpperCase().replace("CTL00_MIDDLEMENU1_", "") : null);
			catId = (catId != null ? catId.substring(0, catId.lastIndexOf("MENU")) : null);
			break;
		}
	}
	if (catId == null)
	{
		menus = psGetElementsByClassName("dropmenudiv RightMostMenu");
		for (var i = 0; i < menus.length; i++)
		{
			firstSpan = menus[i].getElementsByTagName("span");
			firstSpan = (firstSpan.length > 0 ? firstSpan[0] : null);
			if (firstSpan != null && firstSpan.innerHTML.toLowerCase().indexOf(fileName)>=0) // the right span (span containing the current hyperlink)?
			{
				catId = firstSpan.id;
				catId = (catId != null ? catId.toUpperCase().replace("CTL00_MIDDLEMENU1_", "") : null);
				catId = (catId != null ? catId.substring(0, catId.lastIndexOf("MENU")) : null);
				break;
			}
		}
	}

	return catId;
}

/*
 * Get general pageId from souce code
 * Get inner text of the first h1 tag
 */
function psGetPageId()
{
	var pageId = null;
	var h1s = document.getElementsByTagName("h1");
	if (h1s.length > 0)
		pageId = psTrim(psGetInnerText(h1s[0]));
	else
	{
		if (G_PS_PATHNAME == "/individual_health_insurance_policy.aspx")
			pageId = "QuikForms";
		else if (G_PS_PATHNAME == "/ratedownload.aspx")
			pageId = "PLEASE READ THIS CAREFULLY";
		else if (G_PS_PATHNAME == "/jackpot.aspx")
			pageId = "Hit the Jackpot!!!";
		else if (G_PS_PATHNAME == "/interior_twocolumn_nopromo.aspx")
			pageId = "Celtic Launches New Individual Health Plan";
		else
		{
			var headerDiv = document.getElementById("ctl00_Main_main");
			if (headerDiv != null)
				pageId = psTrim(psGetInnerText(headerDiv.getElementsByTagName("p")[0]));
		}
	}

	return pageId;
}

/*====================== END TAGGING BUSSINESS LOGIC =========================*/

/*======================= GENERAL UTILITY FUNCTION ===========================*/
/* PURPOSE: constructor for profile
 * Note: you can add more methods to psProfile in its prototype
 * RETURN: none
 */
function psProfile()
{
    this.email = null;
    this.city = null;
    this.state = null;
    this.zipcode = null;
	/*
	 * Get user profile from cookie
	 */
	this.readProfile = function()
	{
		try
		{
			this.email = psGetCookie(G_PS_COOKIE_PROFILE);
			if (this.email != null)
			{
				var buf = this.email.split('|');
				for (var i=0; i<buf.length; i++)
				{
					var tempVal = buf[i];
					// when NULL is written to cookie, it becomes string, not literal constant
					buf[i] = (tempVal=="null" ? null : tempVal); 
				}
				this.email = buf[0];
				this.city = buf[1];
				this.state = buf[2];
				this.zipcode = buf[3];
			}
			return true;
		}
		catch (ex) { return false; }
	}
	/*
	 * Set user profile to cookie
	 */
	this.writeProfile = function()
	{
		if (this.email == null)
			return;
		// make sure that the data contains 4 parts separated by 3 '|'
		var data = this.email + '|' + this.city + '|' + this.state + '|' + this.zipcode;
		// store on cookie
		psSetCookie(G_PS_COOKIE_PROFILE, data);
	}
}

/* PURPOSE: Compare case-insensitive strings
 * RETURN: true: strings are not null and the same
 *         false: any of the string is null or not the same
 */

function psIsEqual()
{
	for (var i=0; i<arguments.length; i++)
	{
		if(arguments[0] == null || arguments[i] == null)
		{
			return false;
		}
		else if(arguments[0].toUpperCase() != arguments[i].toUpperCase())
		{
			return false;
		}
	}
	return true;
}

/* PURPOSE: 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; 
}

/* 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: Get inner text of an object or clean remove html tags of a particular string
 * RETURN: resultant string or null object
 */
function psGetInnerText(node, ignorewhitespace)
{
	if (node == null)
		return "";

	var text = "";
	if (typeof(node) == "object")
	{
		if (node.hasChildNodes())
		{
			var children = node.childNodes;
			for(var i=0; i<children.length; i++)
			{
				if(children[i].nodeName == "#text")
				{
					if(ignorewhitespace)
					{
						if(!/^\s+$/.test(children[i].nodeValue))
							text = text.concat(children[i].nodeValue);
					}
					else
						text = text.concat(children[i].nodeValue);
				}
				else if(children[i].nodeName.search(/BR/i)>=0)
					text = text.concat(" "); // a break line for a <br> tag
				else
					text = text.concat(psGetInnerText(children[i])); // recursively get text
			}
		}
		else
		{
			if(node.nodeName == "#text")
				text = text.concat(node.nodeValue);
			else if(node.nodeName.search(/BR/i)>=0)
				text = text.concat(" "); // a break line for a <br> tag
		}
	}
	else
		text =  node.replace(/\<+.+?\>+/g, "");

	return text;
}

/*
 * Return the first element encountered by the class name
 */
function psGetElementsByClassName(pClassName, node)
{
	if (node == null)
		node = document;
	var allPageTags = node.getElementsByTagName("*");
	var elements = new Array();
	for (var k = 0; k < allPageTags.length; k++)
	{
		if (allPageTags[k].className.toLowerCase() == pClassName.toLowerCase())
			elements.push(allPageTags[k]);
	}
	return elements;
}

/* 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)
{
	var cookies = document.cookie;
	if (!pCookieName || !cookies)
		return null;

	cookies = "; " + cookies.toLowerCase();
	var key = "; " + pCookieName.toLowerCase() + "=";
	var start = cookies.lastIndexOf(key);
	if (start >= 0)
	{
		start = start + key.length;
		var end = cookies.indexOf(";", start);
		if (end == -1)
			end = cookies.length;

		return unescape(cookies.substring(start, end));
	}

    return null;
}

/* PURPOSE: set cookie value
 * Note: if the designated cookie is too big, the old items will be removed
 * because cookie size is limited to 4K
 * @pLifeTime in seconds
 * pDomain: don't specify if using current domain
 * RETURN: boolean
 */
function psSetCookie(pCookieName, pCookieValue, pLifeTime, pDomain)
{
    if (!pCookieName)
		return false;

	pDomain = ".celtic-net.com";
	if(pLifeTime == "delete") 
    {
        CC(pCookieName, pDomain);//delete cookie by calling coremetrics's cookie function
        return true;
    }
    // set cookie by calling coremetrics's cookie function
    var expire = (pLifeTime) ? (new Date((new Date()).getTime() + (1000 * pLifeTime))).toGMTString() : null;
    
    return CB(pCookieName, escape(pCookieValue), expire, pDomain);
}

/********************************************************/
/* WRAPPER FOR COREMETRICS' TAG FUNCTIONS               */
/********************************************************/
function psCreatePageviewTag(pId, pCatId, pSrchTerm, pSrchResult, pAttributes) 
{
	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 + ", " + pAttributes + ")");
    if (G_PS_DEBUG_MODE == 2 || G_PS_DEBUG_MODE == 3)
        cmCreatePageviewTag(pId, pCatId, pSrchTerm, pSrchResult, pAttributes);
}

function psCreateConversionEventTag(pId, pActionType, pCatID, pPoints, pAttributes) 
{
	pCatID = psCleanCatId(pCatID);
    if (G_PS_DEBUG_MODE == 1 || G_PS_DEBUG_MODE == 3)
        alert("cmCreateConversionEventTag(" + pId + ", " + pActionType + ", " + pCatID + ", " + pPoints + ", " + pAttributes + ")");
    if (G_PS_DEBUG_MODE == 2 || G_PS_DEBUG_MODE == 3)
        cmCreateConversionEventTag(pId, pActionType, pCatID, pPoints, pAttributes);
}

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);
}
/*===========================END GENERAL UTILITY FUNCTION ==================*/

/*===========================FUNCTIONS FROM DUC NGUYEN ==================*/
/* 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;
}

// 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;
}


/* 	#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 psGetUrlPath()
{
	return G_PS_URL_PATH.toLowerCase();
}


function psSaveProfile2Ck_Login()
{
	var temp=document.getElementById("txtUserName");
	if(psCheckElementExist(temp)==false)
	{
		return;
	}
	temp=temp.value;
	psSetValueToCookie(G_PS_CK_ALL, G_PS_COOKIE_PROFILE, temp);
	psSetValueToCookie(G_PS_CK_ALL, G_PS_CK_SIGNIN,"false");
}

function psRegisterListener_Register()
{
	if(psGetUrlPath().indexOf("legacy.celtic-net.com/quikanswers/agentlogin.asp")>=0 || psGetUrlPath().indexOf("legacy.celtic-net.com/prescreening/default.aspx")>=0)
	{
		var temp=document.getElementById("Form1");
		if(psCheckElementExist(temp)==false)
		{
			return;
		}
		
		temp.oldFunc=temp.onsubmit;
		temp.onsubmit=function()
		{
			psSaveProfile2Ck_Login();
			if(psCheckElementExist(this.oldFunc)==true)
			{
				return this.oldFunc();
			}
		}
	}
}

function psSendRegistrationTag()
{
	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);
			psCreateRegistrationTag(arrTemp[0], arrTemp[1], arrTemp[2], arrTemp[3], arrTemp[4]);
		}
		else
		{
			psCreateRegistrationTag(temp);
		}
		psSetValueToCookie(G_PS_CK_ALL, G_PS_CK_SIGNIN,"true");
	}
}

function psIsNewUserRegistrationPage()
{
	var arrTemp=document.getElementsByTagName("b");
	if(psCheckArrayExist(arrTemp)==false)
	{
		return false;
	}
	
	for(var i=0;i<arrTemp.length;i++)
	{
		var temp=psGetInnerText(arrTemp[i]);
		if(psCheckElementExist(temp)==true)
		{
			temp=temp.toLowerCase();
			if(temp.indexOf("new user information")>=0)
			{
				return true;
			}
		}
	}
	
	return false;
}

function psSaveProfile2Ck_NewUser()
{
	var temp=document.getElementById("txtUserName");
	if(psCheckElementExist(temp)==false)
	{
		return;
	}
	var userName=temp.value;
	
	temp=document.getElementById("txtEmail");
	if(psCheckElementExist(temp)==false)
	{
		return;
	}	
	var email=temp.value;
	
	temp=document.getElementById("txtCity");
	if(psCheckElementExist(temp)==false)
	{
		return;
	}	
	var city=temp.value;
	
	temp=document.getElementById("txtState");
	if(psCheckElementExist(temp)==false)
	{
		return;
	}	
	var state=temp.value;
	
	temp=document.getElementById("txtZip");
	if(psCheckElementExist(temp)==false)
	{
		return;
	}	
	var zip=temp.value;
	
	temp=userName+G_PS_SEP+email+G_PS_SEP+city+G_PS_SEP+state+G_PS_SEP+zip;	
	psSetValueToCookie(G_PS_CK_ALL, G_PS_COOKIE_PROFILE, temp);
	psSetValueToCookie(G_PS_CK_ALL, G_PS_CK_SIGNIN, "false");
}

function psRegisterListener_NewUser()
{
	if(psGetUrlPath().indexOf("legacy.celtic-net.com/quikanswers/agentnewuser.asp")>=0)
	{
		if(psIsNewUserRegistrationPage()==false)
		{
			return;
		}
		
		var temp=document.getElementById("Form1");
		if(psCheckElementExist(temp)==false)
		{
			return;
		}
		
		temp.oldFunc=temp.onsubmit;
		temp.onsubmit=function()
		{
			psSaveProfile2Ck_NewUser();
			if(psCheckElementExist(this.oldFunc)==true)
			{
				return this.oldFunc();
			}
		}
	}
	if(psGetUrlPath().indexOf("prescreening/adduser.aspx")>=0)
	{
		var temp=document.getElementById("Form1");
		if(psCheckElementExist(temp)==false)
		{
			return;
		}
		
		temp.oldFunc=temp.onsubmit;
		temp.onsubmit=function()
		{
			psSaveProfile2Ck_NewUser();
			if(psCheckElementExist(this.oldFunc)==true)
			{
				return this.oldFunc();
			}
		}
	}
}

function psSendRegistrationTag_NewUser()
{
	if(psGetUrlPath().indexOf("legacy.celtic-net.com/quikanswers/default.asp")>=0)
	{	
		if(psCheckElementExist(G_PS_URL_REFERRER)==true && G_PS_URL_REFERRER.indexOf("legacy.celtic-net.com/quikanswers/agentnewuser.asp")>=0)
		{
			psSendRegistrationTag();
		}	
	}
	
	if(psGetUrlPath().indexOf("legacy.celtic-net.com/prescreening/main.aspx")>=0)
	{		
		if(psCheckElementExist(G_PS_URL_REFERRER)==true && G_PS_URL_REFERRER.indexOf("legacy.celtic-net.com/prescreening/entry.aspx")>=0)
		{			
			psSendRegistrationTag();
		}	
	}
}

function psSendRegistrationTag_Login()
{	
	if(psGetUrlPath().indexOf("legacy.celtic-net.com/prescreening/default.aspx")>=0)
	{	
		if(psCheckElementExist(G_PS_URL_REFERRER)==false || G_PS_URL_REFERRER.indexOf("legacy.celtic-net.com/quikanswers/agentnewuser.asp")<0)
		{
			return;
		}
		
		psSendRegistrationTag();
	}
	
	if(psGetUrlPath().indexOf("legacy.celtic-net.com/quikanswers/products/billstatus.asp")>=0)
	{	
		if(psCheckElementExist(G_PS_URL_REFERRER)==false || G_PS_URL_REFERRER.indexOf("legacy.celtic-net.com/quikanswers/agentlogin.asp")<0)
		{
			return;
		}
		psSendRegistrationTag();
	}
	
	if(psGetUrlPath().indexOf("legacy.celtic-net.com/prescreening/main.aspx")>=0)
	{	
		if(psCheckElementExist(G_PS_URL_REFERRER)==false || G_PS_URL_REFERRER.indexOf("legacy.celtic-net.com/prescreening/entry.aspx")<0)
		{
			return;
		}
		
		psSendRegistrationTag();
	}
}

/*===========================END FUNCTIONS FROM DUC NGUYEN ==================*/

