/************************************************************* * Copyright Kevin Lam * VirtualSalesBot.com *************************************************************/// the time before the first message is posted// also this is the time after user posts the message// and before the "Agent is Typing" appearsvar TimeInit = 500;// this is the time before agent begin typing the next// post in automatic welcome mode.var TimeBeforeNewPost = 1000;// time which agent is "typing" the messagevar TimeDelay = 6500;// Name of agent usedvar AgentName = 'Heather';// array of welcome messagesvar MessagesWelcome = new Array(				"Hey, wait! I found a practicing lawyer who can tell you how to handle a claim yourself.",				"That's right, this guy decided to spill the beans on insider stuff to save you lawyer fees!",				"And if you hurry, you can check this out before he comes to his senses and takes it down <a href=\"http://goo.gl/mjU0d\" target=\"_blank\">going here</a>.",				"Please continue to the site above before it's gone.",								"",				"",				"",				""				);// array of messages used to answer users' postsvar MessagesDiscussion = new Array(				"Unfortunately, I can't answer that right now.",				"All of the information you need is provided on the website. If you need further assistance, please contact the admin.",				"I am here to help, but I can't answer that for you. I will try to find out from my supervisor.",				"I'm only a support rep and cannot answer anything technical. Please email the website admin.",				"Please contact the website admin. Support is now closed for the day."				);var oDiscusson = document.getElementById("commentdiv");var oUserMessages = document.getElementById("typediv");var oAgentTyping = document.getElementById("divAgentIsTyping");var tAgent = null;var tPost = null;var bConversationStarted = false;var iPrevMessageId = -1;var iCurrentWelcomeMessage = -1;function GetRandomString(source){	var iNewMessageId = Math.floor(Math.random()*source.length);	if ((iPrevMessageId == iNewMessageId) && (source.length>1))		return GetRandomString(source);	iPrevMessageId = iNewMessageId;	return source[iNewMessageId];}function onUserMessage(){	if (oUserMessages.value!='')	{		setAgentTypingOff();		clearTimeout(tAgent);		clearTimeout(tPost);		tAgent = setTimeout ( "setAgentTypingOn()", TimeInit );		tPost = setTimeout ( "postMessage('discussion')", TimeInit + TimeDelay);		if (oDiscusson.innerHTML!='')			oDiscusson.innerHTML = oDiscusson.innerHTML + '<br><br>';		oDiscusson.innerHTML = oDiscusson.innerHTML + '<span class="messageUser"><b>You:</b> ' + oUserMessages.value + '</span>';		oUserMessages.value = '';		oDiscusson.scrollTop = oDiscusson.scrollHeight;	}}function GetNextWelcomeMessage(){	if (iCurrentWelcomeMessage < MessagesWelcome.length-1)	{		iCurrentWelcomeMessage++;		return MessagesWelcome[iCurrentWelcomeMessage];	}	return '';}function postMessage(sMessageType){	if (sMessageType == 'discussion')	{		var sMessage = GetRandomString(MessagesDiscussion);	}else{		var sMessage = GetRandomString(MessagesWelcome);		var sMessage = GetNextWelcomeMessage();		if (!bConversationStarted && sMessage!='')		{			tAgent = setTimeout ( "setAgentTypingOn()", TimeBeforeNewPost);			tPost = setTimeout ( "postMessage('" + sMessageType + "')", TimeBeforeNewPost + TimeDelay);		}	}	if (sMessage!='')	{		if (oDiscusson.innerHTML!='')			oDiscusson.innerHTML = oDiscusson.innerHTML + '<br><br>';		oDiscusson.innerHTML = oDiscusson.innerHTML + '<span class="messageAgent"><b>' + AgentName + ':</b> ' + sMessage + '</span>';	}	setAgentTypingOff();	oDiscusson.scrollTop = oDiscusson.scrollHeight;}function setAgentTypingOn(){	oAgentTyping.innerHTML = AgentName + ' Is Typing...';}function setAgentTypingOff(){	oAgentTyping.innerHTML = '&nbsp;';}window.onload = function(){	setAgentTypingOff();	tAgent = setTimeout ( "setAgentTypingOn()", 0);	tPost = setTimeout ( "postMessage('welcome')", TimeInit);}
