// The page that includes this must also include 'LivePerson_MonitorCode.js' as late as possible (*after* the point where the links & images are in the body.)


//	These are the functions used most often.
function fl_launchChat()
{
	var cm = fl_getChatManagerObj();
	cm.LaunchChat();
}

function fl_launchChatNoCookies()
{
	var cm = fl_getChatManagerObj();
	cm.LaunchChatNoCookies();
}





/*
<!-- BEGIN LivePerson Button Code --><div>
<a id="_lpChatBtn" href='https://server.iad.liveperson.net/hc/25817976/?cmd=file&file=visitorWantsToChat&site=25817976&byhref=1&SESSIONVAR!skill=Technical%20Support&imageUrl=https://server.iad.liveperson.net/hcp/Gallery/ChatButton-Gallery/English/General/1a/' target='chat25817976'>
<span style="font:normal 11px Arial, Helvetica, sans-serif;color:#0000ff">Live Chat</span></a></div><!-- END LivePerson Button code -->
From their site:  "In order to have multiple buttons on a single web page you need to copy the button code and change the element id "_lpChatBtn" by increments of one. For example: For button 1: "_lpChatBtn", For button 2: "_lpChatBtn1", For button 3: "_lpChatBtn2" and so on. "
*/


//	Implementation details...


// match http vs. https of the owner page
var bIsSSL = ('https:' == window.location.protocol);
var contentBase =  bIsSSL ?  'https://content.fiberlink.com/'  :  'http://content.maas360.com/';


// These values are determined by our relationship with the chat service.
FL_CHAT_CUSTOMER_ID      = '25817976';
FL_CHAT_LINK_ID          = '_lpChatBtn';
FL_CHAT_LINK_IMAGES_PATH = contentBase + 'www/globalHeader/Chat';
FL_CHAT_IMG_NAME         = 'hcIcon';
FL_CHAT_WINDOW_ID        = 'chat' + FL_CHAT_CUSTOMER_ID;


FL_CHAT_IMG_PARAMS = [];
FL_CHAT_IMG_PARAMS['cmd'] = 'repstate';
FL_CHAT_IMG_PARAMS['site'] = FL_CHAT_CUSTOMER_ID;
FL_CHAT_IMG_PARAMS['channel'] = 'web';
FL_CHAT_IMG_PARAMS['ver'] = '1';
FL_CHAT_IMG_PARAMS['skill'] = 'Technical Support';
FL_CHAT_IMG_PARAMS['imageUrl'] = FL_CHAT_LINK_IMAGES_PATH;

FL_CHAT_IMG_SRC          = window.location.protocol + '//server.iad.liveperson.net/hc/'+FL_CHAT_CUSTOMER_ID+'/?' + fl_buildQueryStringFromArray(FL_CHAT_IMG_PARAMS);
//FL_CHAT_IMG_SRC          = window.location.protocol + '//server.iad.liveperson.net/hc/'+FL_CHAT_CUSTOMER_ID+'/?cmd=repstate&site='+FL_CHAT_CUSTOMER_ID+'&channel=web&ver=1&skill=Technical%20Support&imageUrl=' + FL_CHAT_LINK_IMAGES_PATH;

FL_CHAT_LINK_PARAMS = [];
FL_CHAT_LINK_PARAMS['cmd'] = 'file';
FL_CHAT_LINK_PARAMS['file'] = 'visitorWantsToChat';
FL_CHAT_LINK_PARAMS['site'] = FL_CHAT_CUSTOMER_ID;
FL_CHAT_LINK_PARAMS['SESSIONVAR!skill'] = 'Technical Support';
FL_CHAT_LINK_PARAMS['imageUrl'] = FL_CHAT_LINK_IMAGES_PATH;

FL_CHAT_LINK_URL         = 'https://server.iad.liveperson.net/hc/'+FL_CHAT_CUSTOMER_ID+'/?' + fl_buildQueryStringFromArray(FL_CHAT_LINK_PARAMS);
//FL_CHAT_LINK_URL         = 'https://server.iad.liveperson.net/hc/'+FL_CHAT_CUSTOMER_ID+'/?cmd=file&file=visitorWantsToChat&site='+FL_CHAT_CUSTOMER_ID+'&SESSIONVAR!skill=Technical%20Support&imageUrl=' + FL_CHAT_LINK_IMAGES_PATH;



function FL_ChatManager()
{
	this.SetChatLink = FL_ChatManager_SetChatLink;
	this.SetChatIcon = FL_ChatManager_SetChatIcon;
	this.Init = FL_ChatManager_Init;
	this.LaunchChat = FL_ChatManager_LaunchChat;
	this.LaunchChatNoCookies = FL_ChatManager_LaunchChatNoCookies;
	this.GetChatBaseUrl = FL_ChatManager_GetChatBaseUrl;
	this.GetChatFullUrl = FL_ChatManager_GetChatFullUrl;

	this.linkElemIds = [];
	this.imgElem = null;
}

function FL_ChatManager_SetChatLink(elemIds)
{
	if (typeof(elemIds) == 'string')
		elemIds = [elemIds];
	this.linkElemIds = elemIds;
}

function FL_ChatManager_SetChatIcon(strElemId)
{
	this.imgElem = document.getElementById(strElemId);
}

function FL_ChatManager_Init()
{
	for (var i=0; i<this.linkElemIds.length; i++)
	{
		var elem = document.getElementById(this.linkElemIds[i]);
		if (null !== elem)
		{
			if (0 === i)  elem.id = FL_CHAT_LINK_ID;  // give the 1st one the script integration
			var tmpThis = this;
			elem.onclick = function() { tmpThis.LaunchChat(); return false; };
		}
	}

	if (this.imgElem)
	{
		this.imgElem.name = FL_CHAT_IMG_NAME;
		this.imgElem.src = FL_CHAT_IMG_SRC;
	}
}

function FL_ChatManager_LaunchChat()
{
	var chatUrl = this.GetChatFullUrl();
	window.open(chatUrl, FL_CHAT_WINDOW_ID, 'width=475,height=400,resizable=yes');
}

function FL_ChatManager_LaunchChatNoCookies()
{
	var chatUrl = this.GetChatBaseUrl();
	window.open(chatUrl, FL_CHAT_WINDOW_ID, 'width=475,height=400,resizable=yes');
}

function FL_ChatManager_GetChatBaseUrl()
{
	return FL_CHAT_LINK_URL;
}

function FL_ChatManager_GetChatFullUrl()
{
	var lpButtonCTTUrl = this.GetChatBaseUrl() + '&referrer=' + escape(document.location);

	if (typeof(lpAppendVisitorCookies) != 'undefined')
		lpButtonCTTUrl = lpAppendVisitorCookies(lpButtonCTTUrl);

	if (typeof(lpMTag) != 'undefined'  &&  typeof(lpMTag.addFirstPartyCookies) != 'undefined')
		lpButtonCTTUrl = lpMTag.addFirstPartyCookies(lpButtonCTTUrl);

	return lpButtonCTTUrl;
}



function fl_getChatManagerObj()
{
	if (null === window.__chatMgrObj)
	{
		window.__chatMgrObj = new FL_ChatManager();
	}
	return window.__chatMgrObj;
}
window.__chatMgrObj = null;


//	link href    = https://server.iad.liveperson.net/hc/25817976/?cmd=file&file=visitorWantsToChat&site=25817976&SESSIONVAR!skill=Technical%20Support&imageUrl=http%3A%2F%2Fcontent.maas360.com%2Fwww%2FglobalHeader%2FChat
//  onclick href = https://server.iad.liveperson.net/hc/25817976/?cmd=file&file=visitorWantsToChat&site=25817976&SESSIONVAR!skill=Technical%20Support&imageUrl=https://trials.maas360.com/hs/img/&referrer='+escape(document.location)

