﻿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);
}

function initWindowChatg() {
	window.chatG = new chatGui( 
		{	divID: 'chat_window_container'
			//, width: 400 //chat window default width
			//, height: 310 //chat window default height
			, visitor: 'Visitor'
			, autoResumechat: true //resumes chat automatically
			, resizable: false //option to resize chat window
			, draggable: false //option to drag chat window
			, showTime: false //show the time of each message
			, rememberPosition: false
			, enableGoogleTranslate: false //enable Google translate
			//Language of the agent (for example: English)
			, googleTranslateAgentTargetLanguage: 'en'
			//Language of the visitor (for example: Russian)
			, googleTranslateVisitorTargetLanguage: 'sp'
			//Replace a specific pattern using regular expression
			//In this example, visitor's number with 16 digits will be replaced with *
			, maskVisitorDataRegExp: '[0-9]{16}'
			, maskVisitorDataReplace: '****************'
		}, 
		lpChatConfig);
	lpChatConfig.lpAddScript = function (src, ignore) { var c = lpChatConfig; if (typeof (c.lpProtocol) == 'undefined') { c.lpProtocol = (document.location.toString().indexOf("https:") == 0) ? "https" : "http"; } if (typeof (src) == 'undefined' || typeof (src) == 'object') { src = c.lpChatSrc ? c.lpChatSrc : '/hcp/html/lpChatAPI.js'; }; if (src.indexOf('http') != 0) { src = c.lpProtocol + "://" + c.lpServer + src + '?site=' + c.lpNumber; } else { if (src.indexOf('site=') < 0) { if (src.indexOf('?') < 0) src = src + '?'; else src = src + '&'; src = src + 'site=' + c.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); }
	lpChatConfig.lpAddScript();

	//chatboxtextarea_1
	jQuery('#chatboxtextarea_1').val(lpDefaultQuestionText);
	setTextBoxToggle('chatboxtextarea_1', lpDefaultQuestionText);

	//Popup clicks
	jQuery('#chat_window_container').click(function (event) {
		event.stopPropagation();
	});

//	//Agent is available?
//	if (window.lpc.chatAvailability())
//		alert('Yes');
//	else
//		alert('No');
}

function registerChatLinks() {
	//chatStartLinks
	jQuery.each(chatStartLinks, function(index, value)
	{
		jQuery('#' + value).click(function () {
			trigger_Overlay(function () {
				chatG.startChat();
			});
		});
	});
}

function lpAgentsOnline(availObj) {
	jQuery.each(chatStartLinks, function (index, value) {
		if (availObj.availability == true) {
			jQuery('#' + value).css({ display: 'block' });
		} else {
			jQuery('#' + value).css({ display: 'none' });
		}
	});
}
