// LiveChat Initiation and Tracking
var showChat = true;

//tell Omniture
	function pingAndChat()
	{
		var pageName = (typeof(s_pageName)!="undefined" ? s_pageName : (typeof(s.pageName)!="undefined" ? s.pageName : "Unknown Page"))

		s_linkTrackVars='s_eVar15';
		s_linkTrackEvents='None';
		s_linkType='o';
		s_linkName='Live Chat'
		s_eVar15='Live Chat (Header) | ' + pageName; //make sure this works with dynamic pages: s.pageName?
		s_lnk=s_co(this);
		s_gs(s_account);
		if(typeof(onClickTrack)=='function') onClickTrack('Header Right | Chat');
	}


//Here's my array of Sales-specific pages. If somebody clicks on Live Chat from any of these pages, it will go to sales, 
//...regardless of any cookie value. 
var salesPages = new Array;
salesPages[0] = "showPackageSelection"
salesPages[1] = "submitPackageSelection"
salesPages[2] = "submitAltCustomerInfo"
salesPages[3] = "showPackageMatrix"
salesPages[4] = "Product-Page"

function pickSkill()
{
	//this is for debugging	
	if (readCookie("chatSkill")) chatSkill = readCookie("chatSkill");

	//this is for remarketing to drive prev. customers to Sales
	if(typeof(chatSkill)=="undefined")
	{
		if(readCookie('execDash'))
		{
			if(readCookie('execDash').indexOf('Re-engagement')>-1) 
				chatSkill = "Sales";
		}
	}
	
	//this is for specific pages to go to Sales
	if(typeof(chatSkill)=="undefined")
	{
		for(var i in salesPages)
		   {
			if(location.pathname.indexOf(salesPages[i])>-1) 
			   {
				chatSkill = "Sales";
			   }
		   }
		if(typeof(chatSkill)=="undefined")
		{
			//...or CSG, if it's a dynamic page (.do struts)
			if(location.pathname.indexOf(".do")>-1)
				chatSkill = "CSG";
			//..or Promo, if it's a promo products page
			else if(location.pathname.indexOf("/promotional-")>-1)
				chatSkill = "Promo";
			//...otherwise, previous customomers go to CSG
			else if (readCookie("LWCust")) chatSkill = "CSG";
			//... and Sales is the default.
			else chatSkill = "Sales"
		}
   }
}

//this determines which Skill to point to: Sales Group or CSG
   pickSkill();

	//should this be credited to Marketing?
	if(readCookie("execDash"))
	{
		var execReport = readCookie("execDash").split(" - ")
		if (execReport.length > 1 && execReport[1].indexOf("Onsite Offer")<0)
			marketChat = execReport[1].replace(" ","");
	}

   var chatHref = "https://hc2.humanclick.com/hc/73845567/?cmd=file&file=visitorWantsToChat&site=73845567&byhref=1" + (typeof(chatSkill)!="undefined" ? "&SESSIONVAR!skill=" + chatSkill : "") + "&VISITORVAR!Marketing=" + (typeof(marketChat)!="undefined" ? marketChat : "None") +"&imageUrl=https://hc2.humanclick.com/hcp/Gallery/ChatButton-Gallery/English/General/1a";
   var chatOnclick = "window.open('https://hc2.humanclick.com/hc/73845567/?cmd=file&file=visitorWantsToChat&site=73845567" + (typeof(chatSkill)!="undefined" ? "&SESSIONVAR!skill=" + chatSkill : "") +  (typeof(marketChat)!="undefined" ? "&VISITORVAR!Marketing=" + marketChat : "") +"&imageUrl=https://hc2.humanclick.com/hcp/Gallery/ChatButton-Gallery/English/General/1a&referrer='+escape(document.location),'chat73845567','width=475,height=400,resizable=yes');pingAndChat()"
