// JavaScript Document
function xitpop_sample()
{
	open('http://www.click2sell.eu/buy?extremeext1');
}

salesAgent = {
	startMsg: "Hello, my name is Anna. Thank you for visiting our website. How are you doing today?  ",
	defaultMsg: new Array("For more information, please e-mail our support team <a target=\"_blank\" href=\"http://www.extremegamecopy.com/Contact.php\">here</a> and they'll be glad to assist you.","Thank you for talking to me and have a nice day!","I am authorized to offer you our software for only <b>$29.95 </b> <span style=\"color:red;font-weight:bold\">saving you 40%</span> (regular price $49.95)!<br /><br />"+
"To take advantage of this <b>limited promotion</b> please <a href =\"javascript:xitpop_sample()\" style=\"font-size:14px;color:blue;font-weight:bold\"> CLICK HERE</a>","Please keep in mind that this offer might not be available tomorrow. "),
	messages: new Array("I am very well, thank you for asking.","I am very well, thank you for asking","I see that you are leaving, is there anything I can help you with?","I see that you are leaving, is there anything I can help you with?"),
	keywords: new Array("how are you?","you?","fine","good"),
	offer: 1,
	agentName:'<b>Anna says:&nbsp;</b>',
	waiting: false,
	lives:1,
	clock:false,
	typing:false,
	chat : document.getElementById('chatWindow'),
	agentType: document.getElementById('typing'),
	init: function (){
		hop = document.getElementById('hop').value;
		
		if(salesAgent.lives ==1) {
			document.getElementById('agent').src = "images/anna.png";
			document.getElementById('mainContainer').style.display = 'block';
			document.getElementById('fullpage').style.display = 'block';
			salesAgent.type(salesAgent.startMsg);
			/*exit = confirm( 	"WAIT!!"+' \n\n'+
					'Before you go...' +' \n\n'+
					'A live agent would like you offer you a SPECIAL DISCOUNT.\n\n'+
					'Simply click the OK button below to speak with her or cancel to exit this website.');
			if(!exit) 
				if (window.home) window.home();
				else window.location.href = "about:home";*/
			salesAgent.lives = 0;
			return "A live agent would like to speak to you about a SPECIAL DISCOUNT "
		}
		
	},
	wait: function(msg){
		clearTimeout(salesAgent.waiting);
		word = msg;
		salesAgent.waiting = setTimeout("salesAgent.chat.innerHTML +=salesAgent.agentName+word+'<br /><br />';salesAgent.agentType.style.display = 'none';salesAgent.chat.scrollTop = salesAgent.chat.scrollHeight;if(word == salesAgent.defaultMsg[2]) salesAgent.offer=0;",4500);	
	},
	type: function(msg){
		function delay(){
				document.getElementById('typing').style.display = 'block';
				salesAgent.wait(msg);
		}
			countDown = setTimeout(delay,2000);
	},
	captureMsg: function(userMsg){
		if(userMsg!='' && userMsg!= ' '){
			document.getElementById('userInput').value='';		
			salesAgent.you(userMsg);
			userMsg = userMsg.toLowerCase();
			salesAgent.agentType.style.display = 'none';
			function delay2(){
				
					keyFound = false;
					for(i=0;i<salesAgent.keywords.length;i++)
							if(userMsg.indexOf(salesAgent.keywords[i])!=-1){
								keyID = i;
								keyFound = true;
								break;
							}
					if(keyFound){
							setTimeout("salesAgent.type(salesAgent.messages[keyID])",0)
							if(keyID==0 || keyID==1) setTimeout("salesAgent.type(salesAgent.messages[3])",6600);
							keyFound = false;
							return false;
					}
					else{
							if(salesAgent.offer==1){
								setTimeout("salesAgent.type(salesAgent.defaultMsg[2])",0);
								setTimeout("salesAgent.type(salesAgent.defaultMsg[3])",6600);
								return false;
							}
							else{
									setTimeout("salesAgent.type(salesAgent.defaultMsg[0])",0);
									setTimeout("salesAgent.type(salesAgent.defaultMsg[1])",6600);
									return false;
							}
					}
				
			}
			salesAgent.clock = setTimeout(delay2,1000);
		}
	},
	you: function(say){
		salesAgent.chat.innerHTML+="<span style='color:#CC6600'><b>You:&nbsp;&nbsp;</b>"+say+"</span><br /><br />";
		salesAgent.chat.scrollTop = salesAgent.chat.scrollHeight;
	},
	isTyping: function(event){
		if(event.keycode!=13) clearTimeout(salesAgent.clock);
	}
}
//$(document).hover( function () {}, function () {if(salesAgent.lives ==1) salesAgent.init();salesAgent.lives = 0});
$('#userInput').keypress( function(event) { salesAgent.isTyping(event); } );
window.onbeforeunload = salesAgent.init;
document.onclick = function() {window.onbeforeunload = null}
document.onmouseout = function(){window.onbeforeunload = salesAgent.init;}

