
// Date last modified =  20090101
// Modified by = Hadar Blutrich

var lpMTagConfig = {
        "lpServer" : "sales.liveperson.net",
        "lpNumber" : "17490713",
        "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);}

//creating dynamic button object - We use the same override button for all buttons, since the actions we're taking are the same
lpMTagConfig.dbBtOverride = new Object();
 
//function called when button starts
lpMTagConfig.dbBtOverride.dbStart = function (objName) {
        //save the button name, we need to delete the object it references later
        lpMTagConfig.lastBtName = objName;
                       
        objRef = eval(objName);
        if (objRef ==  null) return true;
        try {
               objRef.imgDefaultName = objRef.imgDefaultName + '?d=' + (new Date()).getTime();
        }
        catch (e) {
               if (lpConnLib.DebugDisplay) lpMTagDebug.Display('DynBut override failed setting default Image name' ,'ERROR');
        };
        
        return true;
};

/** 2 fileds **/
lpMTagConfig.db1 = new Object();
lpMTagConfig.db1.dbStateChange = function (objName, status) {
    var objRef = eval(objName);
    
    if (typeof(objRef.ver) == 'undefined') {
    	lpMTagConfig.lpdbVer = '8.1';
    }
    else {
    	lpMTagConfig.lpdbVer = objRef.ver;
    }
    
    if (typeof(objRef.bidCreated)=='undefined') objRef.bidCreated = false;
    if (status == 'online') {
        // do something the button status has just changed to online
        if (!objRef.bidCreated) {
            lpMTagConfig.lpCreateExtraInput(objRef.GetObj(objRef.divID));
			lpMTagConfig.bellSpecialNExtFieldName = objRef.phoneNumID + '-0';
            objRef.bidCreated = true;
        }
        else {
            var div = objRef.GetObj('lpBidP');
            div.style.visibility = 'visible';
        }
    }
    else {
        if (objRef.bidCreated) {
            var div = objRef.GetObj('lpBidP');
            div.style.visibility = 'hidden';
        }

    }
    return true;
};

lpMTagConfig.addNewStyle = function (newStyle) {
	var styleElement = document.getElementById('styles_js');
	if (!styleElement) {
		styleElement = document.createElement('style');
		styleElement.type = 'text/css';
		styleElement.id = 'styles_js';
		document.getElementsByTagName('head')[0].appendChild(styleElement);
	}
	
	
	
	if (lpMTag.lpBrowser == 'FF') {
		styleElement.appendChild(document.createTextNode(newStyle));
	} else {
		styleElement.styleSheet.cssText = newStyle;
	}
}


lpMTagConfig.lpCreateExtraInput = function (divRef) {
    var maxLength1 = 3;
    var maxLength2 = 3;
    var maxLength3 = 4;
    var posX =80;
    var posY = -60;
	if (lpMTag.lpBrowser == 'FF') {posX = 100; posY = -60;}
    var div = document.createElement("div");
    div.setAttribute('id','lpBidP');
    var text = document.createTextNode("");
    div.appendChild(text);

    var input = document.createElement('input');
	input.setAttribute('type','text');
	input.setAttribute('name','bid1');
	input.setAttribute('id','bid1');
	input.onkeyup = function () {lpMTagConfig.SetNextFocus(this,maxLength1)};
    input.setAttribute('maxLength',maxLength1);
    input.setAttribute('size',maxLength1);
    if (lpMTagConfig.lpdbVer!='8.1') {    	
    	input.style.font = '12px arial;';
    }
    div.appendChild(input);

    input = document.createElement('input');
	input.setAttribute('type','text');
	input.setAttribute('name','bid2');
	input.setAttribute('id','bid2');
    input.setAttribute('maxLength',maxLength2);
    input.setAttribute('size',maxLength2);
    input.onkeyup = function () {lpMTagConfig.SetNextFocus(this,maxLength2)};
    if (lpMTagConfig.lpdbVer!='8.1') {    	
    	input.style.font = '12px arial;';
    }
    div.appendChild(input);

    input = document.createElement('input');
	input.setAttribute('type','text');
	input.setAttribute('name','bid3');
	input.setAttribute('id','bid3');
    input.setAttribute('maxLength',maxLength3);
    input.setAttribute('size',maxLength3);
    input.onkeyup = function () {lpMTagConfig.SetNextFocus(this,maxLength3)};
    if (lpMTagConfig.lpdbVer!='8.1') {
    	input.style.font = '12px arial;';
    }
    div.appendChild(input);

    divRef.appendChild(div);

    div.style.zIndex= 302;
    div.style.position = 'relative';
	lpMTagConfig.addNewStyle('div#lpBidP { left: '+posX+'px !important;	top: '+posY+'px !important;}');
};


lpMTagConfig.SetNextFocus = function(field, maxLength) {
    if (field.value.length == maxLength) {
        var fieldName = field.name;
        var fieldNameSuffix = fieldName.substr(fieldName.length-1);
        var nextFieldNameSuffix = parseInt(fieldNameSuffix) + 1;
		var nextFieldName;
		if (nextFieldNameSuffix > 3) {
			nextFieldName = lpMTagConfig.bellSpecialNExtFieldName;
		}
		else {
			nextFieldName = fieldName.substr(0, fieldName.length-1) + nextFieldNameSuffix			
		}
		var nextField = document.getElementById(nextFieldName);
        if (nextField != null) {
            nextField.focus();
            nextField.select();
        }
    }
};


lpMTagConfig.db1.dbClicked = function (objName, status) {
    var checkMaximum = true;
    var checkMinimum = false;
    var minimumLength = 4;

    objRef = eval(objName);
    if (status == 'online') {
        // do something the button status has just changed to online
        var inValue = objRef.GetObj('bid1').value + '' + objRef.GetObj('bid2').value + '' + objRef.GetObj('bid3').value;
        if (isNaN(inValue)) {
            alert('Please input numeric values only');
            return false;
        }
		if (inValue.length > 10) {
            alert('Invalid input - the length can not be more than 10 chars');
            return false;
        }
        else if (inValue.length > 0 && inValue.length <10) {
		    alert('Invalid input - Please enter your 10 digits Billing Phone Number');
		    return false;
        }
        setTimeout("lpMTag.lpSendData('SESSIONVAR!BTN=" + inValue + "', true);",3000);
    }
    return true;
};

/** 2 fileds End **/
//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) 	{
	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(lpAddVars)!="undefined")	lpAddVars("page","unit",lpUnit);
	lpMTagConfig.defaultInvite ='chat' + '-' + lpUnit + "-" + lpLanguage;
	}catch(e){}

lpMTagConfig.onLoadCode[lpMTagConfig.onLoadCode.length] = onloadEMT;

if (window.attachEvent) window.attachEvent("onload",lpAddMonitorTag);
else window.addEventListener("load",lpAddMonitorTag,false);


lpMTagConfig.db2 = new Object();

//overriding busy action

lpMTagConfig.db2.busyAction = function (objName) {

      objRef = eval(objName);

      var chatWinURL = objRef.getActionURL('Busy');

      chatWinURL = chatWinURL.replace(/forceOffline/,'SESSIONVAR%21BusyClickOverride');

      window.open(chatWinURL,'Chat'+lpMTagConfig.lpNumber,'width=472,height=320,status=0,resizable=0,menubar=no,scrollbars=no,location=no');

};
//overriding offline action
lpMTagConfig.db2.offlineAction = function (objName) {
      objRef = eval(objName);
      var chatWinURL = objRef.getActionURL('Offline');
      window.open(chatWinURL,'Chat'+lpMTagConfig.lpNumber,'width=472,height=320,status=0,resizable=0,menubar=no,scrollbars=no,location=no');
};
lpMTagConfig.db2.dbStateChange = function (objName, status) {


    objRef = eval(objName); 
	  if (status == 'busy') {
		objRef.setCursorStyle(objRef.pointerStyle);

		if (typeof(objRef.ver)== 'undefined') { // version 8.0 or 8.1

			objRef.refImage.src = objRef.imageUrl + objRef.imgBusyName;

		}

		else {

			objRef.refImage.src = objRef.imgBusyName;

		}

		
		objRef.refImage.alt = '';

				
		if (typeof(objRef.overwriteObj.busyAction)!='undefined') {

			objRef.refImage.onclick = function () {lpMTagConfig.db2.busyAction(objName); return false; };

		}

		else {

			objRef.refImage.onclick = null;

		}

		return false;

    } 
if (status == 'offline') {
		objRef.setCursorStyle(objRef.pointerStyle);
		if (typeof(objRef.ver)== 'undefined') { // version 8.0 or 8.1
			objRef.refImage.src = objRef.imageUrl + objRef.imgOfflineName;
		}
		else {
			objRef.refImage.src = objRef.imgOfflineName;
		}			
		
		objRef.refImage.alt = '';
				
		if (typeof(objRef.overwriteObj.offlineAction)!='undefined') {
			objRef.refImage.onclick = function () {lpMTagConfig.db2.offlineAction(objName); return false; };
		}
		else {
			objRef.refImage.onclick = null;
		}
		return false;
    }
return true;

};

lpMTagConfig.db3 = new Object();

//overriding busy action

lpMTagConfig.db3.busyAction = function (objName) {

      objRef = eval(objName);

      var chatWinURL = objRef.getActionURL('Busy');

      chatWinURL = chatWinURL.replace(/forceOffline/,'SESSIONVAR%21BusyClickOverride');

      window.open(chatWinURL,'Chat'+lpMTagConfig.lpNumber,'width=472,height=320,status=0,resizable=0,menubar=no,scrollbars=no,location=no');

};

lpMTagConfig.db3.dbStateChange = function (objName, status) {


    objRef = eval(objName); 
	  if (status == 'busy') {
		objRef.setCursorStyle(objRef.pointerStyle);

		if (typeof(objRef.ver)== 'undefined') { // version 8.0 or 8.1

			objRef.refImage.src = objRef.imageUrl + objRef.imgBusyName;

		}

		else {

			objRef.refImage.src = objRef.imgBusyName;

		}

		
		objRef.refImage.alt = '';

				
		if (typeof(objRef.overwriteObj.busyAction)!='undefined') {

			objRef.refImage.onclick = function () {lpMTagConfig.db3.busyAction(objName); return false; };

		}

		else {
			objRef.refImage.onclick = null;
		}
		return false;
    } 
return true;

};