/*JavaScript source file, GameVicio */
function makeObject(){
	var x;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer"){
		x = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		x = new XMLHttpRequest();
	}
	return x;
}
var keepAlive = new Object();

keepAlive = {
	DISABLED: true,
	request: makeObject(),
	lastCheck: 0,
	start: function(){
		if (keepAlive.DISABLED){
			return;
		}
		keepAlive.cookie.read();
		keepAlive.timer.start();
	},
	cookie: {
		write: function(){
			global.cookie.Write("keepalive",keepAlive.lastCheck,24*30,"/",".gamevicio.com.br",false);
		},
		read: function(){
			var s = global.cookie.Read("keepalive");
			keepAlive.lastCheck = (parseInt(s)>1 ? parseInt(s) : 0);
		}
	},
	update: function () {
		keepAlive.request.open('get', RelativeRoot() + 'misc/ajax/keepalive.php');
    	keepAlive.request.send('');
    	var d = new Date();
    	keepAlive.lastCheck = Math.round(d.getTime()/1000);
    	keepAlive.cookie.write();
	},
	needUpdate: function () {
		var d = new Date();
		return (keepAlive.lastCheck < (Math.round(d.getTime()/1000) - 600) );
	},
	timer : {
		id: null,
		start: function(){
			keepAlive.timer.run();
		},
		stop: function (){
			clearTimeout(keepAlive.timer.id);
		},
		run: function (){
			if (keepAlive.needUpdate()){
				keepAlive.update();
			}
			keepAlive.timer.id = self.setTimeout("keepAlive.timer.run()", (3 * 60 * 1000));
		}
	}
}

keepAlive.start();
