// Date last modified = 20090116
// Modified by = RA

var lpMTagConfig = {
        "lpServer" : "sales.liveperson.net",
        "lpNumber" : "74453203",
        "lpProtocol" : (document.location.toString().indexOf("https:")==0) ? "https" : "http"
	}
function lpAddMonitorTag(src){if(typeof(src)=="undefined"||typeof(src)=="object"){src=lpMTagConfig.lpMTagSrc?lpMTagConfig.lpMTagSrc:"/hcp/html/mTag.js";}if(src.indexOf("http")!=0){src=lpMTagConfig.lpProtocol+"://"+lpMTagConfig.lpServer+src+"?site="+lpMTagConfig.lpNumber;}else{if(src.indexOf("site=")<0){if(src.indexOf("?")<0)src=src+"?";else src=src+"&";src=src+"site="+lpMTagConfig.lpNumber;}};var s=document.createElement("script");s.setAttribute("type","text/javascript");s.setAttribute("charset","iso-8859-1");s.setAttribute("src",src);document.getElementsByTagName("head").item(0).appendChild(s);}
if (window.attachEvent) window.attachEvent("onload",lpAddMonitorTag);
else window.addEventListener("load",lpAddMonitorTag,false);

//Variables Arrays - By Scope
if (typeof(lpMTagConfig.pageVar)=="undefined") {lpMTagConfig.pageVar = new Array();}
if (typeof(lpMTagConfig.sessionVar)=="undefined") {lpMTagConfig.sessionVar = new Array();}
if (typeof(lpMTagConfig.visitorVar)=="undefined") {lpMTagConfig.visitorVar = new Array();}
//Extra actions to be taken once the code executes
if (typeof(lpMTagConfig.onLoadCode)=="undefined") {lpMTagConfig.onLoadCode = new Array();}
//Dynamic Buttons Array
if(typeof(lpMTagConfig.dynButton)=="undefined") {lpMTagConfig.dynButton=new Array();}

// Function that sends variables to LP - By Scope
function lpAddVars(scope,name,value) {
	if (name.indexOf('OrderTotal')!=-1 && (value=='' || value==0)) {   // pass 0 value to all but OrderTotal
		return;
	}
	
	value=lpTrimSpaces(value.toString());
	switch (scope){
		case "page": lpMTagConfig.pageVar[lpMTagConfig.pageVar.length] = escape(name)+"="+escape(value); break;
		case "session": lpMTagConfig.sessionVar[lpMTagConfig.sessionVar.length] = escape(name)+"="+escape(value); break;
		case "visitor": lpMTagConfig.visitorVar[lpMTagConfig.visitorVar.length] = escape(name)+"="+escape(value); break;
	}	
}

// Preventing long cookie transfer for IE based browsers.
function onloadEMT() { 
	var LPcookieLengthTest=document.cookie;
	if (lpMTag.lpBrowser == "IE" && LPcookieLengthTest.length>1900){
		lpMTagConfig.sendCookies=false;
	}
}

//The Trim function returns a text value with the leading and trailing spaces removed
function lpTrimSpaces(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
// Immediate Data submission function
function lpSendData(varscope,varname,varvalue){
	if(typeof(lpMTag)!="undefined" && typeof(lpMTag.lpSendData)!="undefined") {
		lpMTag.lpSendData(varscope.toUpperCase() +"VAR!"+ varname + "=" + varvalue, true);
	}
}

// The unit variable purpose is to route the chat or call to the designated skill. <LOB> should be replaced with the skill name, i.e. : sales
try{
	if (typeof(lpUnit)=='undefined')	var lpUnit='fivetothrive-sales';
	if(typeof(lpAddVars)!="undefined")	lpAddVars('page','unit',lpUnit);
	if (typeof(lpLanguage)=='undefined')	var lpLanguage='english';
	if(typeof(lpAddVars)!="undefined")	lpAddVars('session','language',lpLanguage);
	lpMTagConfig.defaultInvite = "chat-" + lpUnit + "-" + lpLanguage;
	lpMTagConfig.defaultVoiceInvite = "voice-" + lpUnit + "-" + lpLanguage;
	}catch(e){}

lpMTagConfig.onLoadCode[lpMTagConfig.onLoadCode.length] = onloadEMT;

// LivePerson Chat Buttons With db1 override - image based buttons
if(typeof(lpMTagConfig.dynButton)!="undefined") {
	lpMTagConfig.dynButton[lpMTagConfig.dynButton.length] = {"name":"chat-"+lpUnit+"-"+lpLanguage+"-assesment","pid":"fivetothrive-assesment-chat-DIV",'ovr':'lpMTagConfig.db1'};
}
if(typeof(lpMTagConfig.dynButton)!="undefined") {
	lpMTagConfig.dynButton[lpMTagConfig.dynButton.length] = {"name":"chat-"+lpUnit+"-"+lpLanguage+"-home","pid":"fivetothrive-home-chat-DIV",'ovr':'lpMTagConfig.db1'};
}
if(typeof(lpMTagConfig.dynButton)!="undefined") {
	lpMTagConfig.dynButton[lpMTagConfig.dynButton.length] = {"name":"chat-"+lpUnit+"-"+lpLanguage+"-hardoffers","pid":"fivetothrive-hardoffers-chat-DIV",'ovr':'lpMTagConfig.db1'};
}
// LivePerson Chat Buttons With db2 override - text based buttons
if(typeof(lpMTagConfig.dynButton)!="undefined") {
	lpMTagConfig.dynButton[lpMTagConfig.dynButton.length] = {"name":"chat-"+lpUnit+"-"+lpLanguage+"-sub","pid":"fivetothrive-sub-chat-DIV",'ovr':'lpMTagConfig.db2'};
}
// LivePerson Voice Buttons With db3 override - image based buttons
if(typeof(lpMTagConfig.dynButton)!="undefined") {
	lpMTagConfig.dynButton[lpMTagConfig.dynButton.length] = {"name":"voice-"+lpUnit+"-"+lpLanguage+"-home","pid":"fivetothrive-home-voice-DIV",'ovr':'lpMTagConfig.db3'};
}
if(typeof(lpMTagConfig.dynButton)!="undefined") {
	lpMTagConfig.dynButton[lpMTagConfig.dynButton.length] = {"name":"voice-"+lpUnit+"-"+lpLanguage+"-hardoffers","pid":"fivetothrive-hardoffers-voice-DIV",'ovr':'lpMTagConfig.db3'};
}
if(typeof(lpMTagConfig.dynButton)!="undefined") {
	lpMTagConfig.dynButton[lpMTagConfig.dynButton.length] = {"name":"voice-"+lpUnit+"-"+lpLanguage+"-sub","pid":"fivetothrive-sub-voice-DIV",'ovr':'lpMTagConfig.db3'};
}


// function that creates an override for busy and offline clicks
lpMTagConfig.lpDynButtonAction = function(objName, state){
	objRef = eval(objName);
	if (state =="Busy"){
		var chatWinURL = objRef.getActionURL("Busy");
		chatWinURL = chatWinURL.replace(/forceOffline/,"SESSIONVAR%21BusyClickOverride");
	}
	else{
		var chatWinURL = objRef.getActionURL("Offline");
	}
	try{
		window.open(chatWinURL,'chat'+lpMTagConfig.lpNumber,'width=472,height=320,status=0,resizable=0,menubar=no,scrollbars=no,location=no');
		}
	catch(e){}	
};

// db1 Button overrides for busy and offline image based chat buttons to be clickable
if (typeof(lpMTagConfig.db1)=='undefined') {
    lpMTagConfig.db1 = new Object(); // needed if does not already exist
};

// db2 Button overrides for busy and offline text based chat buttons to be clickable
if (typeof(lpMTagConfig.db2)=='undefined') {
    lpMTagConfig.db2 = new Object(); // needed if does not already exist
};

// db3 array initialization
if (typeof(lpMTagConfig.db3)=='undefined') {
    lpMTagConfig.db3 = new Object(); // needed if does not already exist
};

lpMTagConfig.db1.busyAction = function (objName) {
	lpMTagConfig.lpDynButtonAction(objName, "Busy");
};
//overriding offline action
lpMTagConfig.db1.offlineAction = function (objName) {
	lpMTagConfig.lpDynButtonAction(objName, "Offline");
};

//overriding busy action
lpMTagConfig.db2.busyAction = function (objName) {
    lpMTagConfig.lpDynButtonAction(objName, "Busy");
};
//overriding offline action
lpMTagConfig.db2.offlineAction = function (objName) {
    lpMTagConfig.lpDynButtonAction(objName, "Offline");
};

// function that sends VS the event's text message 
lpMTagConfig.lpSendEventToVS = function(msg){
	try{
		vs_makeLivePersonSubmit(msg);
	}
	catch(e){}	
};

// Visual Science tracking for clicking image based chat buttons - db1
lpMTagConfig.db1.dbClicked = function (objName, buttonState) {
    objRef = eval(objName);
	if (buttonState=='online') {
		lpMTagConfig.lpSendEventToVS("Click to chat online");
	}
	if (buttonState=='busy') {
		lpMTagConfig.lpSendEventToVS("Click to chat offline");
	}
	if (buttonState=='offline') {
		lpMTagConfig.lpSendEventToVS("Click to chat offline");
	}
return true;
};

// Visual Science tracking for clicking text based chat buttons - db2
lpMTagConfig.db2.dbClicked = function (objName, buttonState) {
    objRef = eval(objName);
	if (buttonState=='online') {
		lpMTagConfig.lpSendEventToVS("Click with us Now Link online");
	}
	if (buttonState=='busy') {
		lpMTagConfig.lpSendEventToVS("Click with us Now Link offline");
	}
	if (buttonState=='offline') {
		lpMTagConfig.lpSendEventToVS("Click with us Now Link offline");
	}
return true;
};

// Visual Science tracking for clicking image based voice buttons - db3
lpMTagConfig.db3.dbClicked = function (objName, buttonState) {
    objRef = eval(objName);
	if (buttonState=='online') {
		lpMTagConfig.lpSendEventToVS("Click to talk online");
	}
return true;
};

// Visual Science tracking for clicking chat invitation
lpMTagConfig.inviteChatAccept = function(objName) {
	lpMTagConfig.lpSendEventToVS("Proactive chat invite");
	return true;
};
// Visual Science tracking for clicking voice invitation
lpMTagConfig.inviteVoiceAccept = function(objName) {
	lpMTagConfig.lpSendEventToVS("Proactive talk invite");
    return true;
};

// Visual Science tracking for clicking multichannel invitation
lpMTagConfig.inviteMultiChannelAccept = function(objName, channel) {
 	objRef = eval(objName);
	if (channel == 'web') {
		lpMTagConfig.lpSendEventToVS("Proactive MC chat invite");
	}
	if (channel == 'voice') {
		lpMTagConfig.lpSendEventToVS("Proactive MC talk invite");
	}
	return true;
};


// Additional Visual Sciences tracking parameters
var vs_getdomain="";
var vs_filename = vs_getdomain + "/swa/j/zag2_vs_log1.asc?Log=1";

function vs_makeLivePersonSubmit(text) {  
	var method = "GET";    
	var lname = "&linktext=" + escape(text);  
	var dref = "&title=" + document.title;  
	var dlink = "&basepage=" + window.location.href;  
	var cb = "&cb=" + (new Date()).getTime();  
	var url = vs_filename + lname + dref + dlink + cb; 

	// branch for native XMLHttpRequest object  
	if (window.XMLHttpRequest)   {    
		req = new XMLHttpRequest();    
		req.onreadystatechange = null;    
		req.open(method, url, false);    
		req.send(null);  
		}
		// branch for IE/Windows ActiveX version     
		else if (window.ActiveXObject)   {    
			req = new ActiveXObject("Microsoft.XMLHTTP");    
			if (req)     {        
				req.open(method, url, false);        
				req.send();    
			}  
		}
}
