function rateGame(myVote, theGameID){
	new Ajax.Request("http://www.wooglie.com/scripts/ajax/general.php",
	{
	method: "post",
	contentType: "application/x-www-form-urlencoded",
	encoding: "UTF-8",
	parameters: {action: 1, vote: myVote, gameID: theGameID},
	onSuccess: function( t) {
		eval(t.responseText);
	},
	on0: function( t) {		 	
	 	//Failed	
		 alert("There was a connection problem while trying to rate the game.");	 
	}
	}); 	
}

function countCaps(myText)  
{  
   	var regexp = /[A-Z]/g;  
   	var text = myText;
   	var matchList = text.match(regexp);     
   	var percentage = matchList.length/text.length * 100 ;      
	return percentage;   
}  


function postComment(myName, myComment, gameID){

	/*
	//if(countCaps(myName)>=50){
	//	myName = myName.toLowerCase(); 
	//}
	//if(countCaps(myComment)>=30){
	//	myComment = myComment.toLowerCase(); 
	//}
	*/
	
	new Ajax.Request("http://www.wooglie.com/scripts/ajax/general.php",
	{
	method: "post",
	contentType: "application/x-www-form-urlencoded",
	encoding: "UTF-8",
	parameters: {action: 2, myName: myName, myComment: myComment, gameID: gameID},
	onSuccess: function( t) {
		eval(t.responseText);
	},
	on0: function( t) {		 	
	 	//Failed	
		  alert("There was a connection problem while trying to post your comment.");	 
	}
	}); 	
}

function flagComment(commentID){
	new Ajax.Request("http://www.wooglie.com/scripts/ajax/general.php",
	{
	method: "post",
	contentType: "application/x-www-form-urlencoded",
	encoding: "UTF-8",
	parameters: {action: 3, commentID: commentID},
	onSuccess: function( t) {
		eval(t.responseText);
	},
	on0: function( t) {		 	
	 	//Failed	
		  alert("There was a connection problem while trying to flag the comment.");	 
	}
	}); 
}

var playingGame = 0;

function sendSignal(gameID){
		playingGame=gameID;
		new Ajax.Request("http://www.wooglie.com/scripts/ajax/general.php",
		{
		method: "post",
		contentType: "application/x-www-form-urlencoded",
		encoding: "UTF-8",
		parameters: {action: 4, gameID: gameID},
		onSuccess: function( t) {
			eval(t.responseText);
		},
		on0: function( t) {		 	
		 	//Failed	
			 // alert("There was a connection problem while trying to flag the comment.");	 
		}
		});	
}

function exitPage(){
	if(playingGame>0){
		sendSignal(playingGame);
	}
}

///////
function checkTotalGameHits(){
		new Ajax.Request("http://www.wooglie.com/scripts/ajax/general.php",
		{
		method: "post",
		contentType: "application/x-www-form-urlencoded",
		encoding: "UTF-8",
		parameters: {action: 5},
		onSuccess: function( t) {
			eval(t.responseText);
		}
		});	
}

function startCounter(newHits){
	var oldValue = parseInt($('totalGames').innerHTML);
	var diff = newHits-oldValue;
	var persecond = parseInt(diff/6);
	var refreshRate=1000;

	if(persecond<=1){
		if(persecond*3>=1){
			persecond=1;
			refreshRate=3000;
		}else{
			persecond=1;
			refreshRate=6000;
		}				
	}else if(persecond>=4){
		persecond = persecond/2;
		refreshRate =500;
	}
	setInterval('raiseCounter('+persecond+')', refreshRate);
}

function raiseCounter(amount){
	$('totalGames').innerHTML = amount+parseInt($('totalGames').innerHTML);
}
/////



function SetFeatured(nr){
	$('feat1').style.background="url('layout2/feat_blauw.png')";
	$('feat2').style.background="url('layout2/feat_blauw.png')";
	$('feat3').style.background="url('layout2/feat_blauw.png')";
	
	$('feat'+nr).style.background="url('layout2/feat_oranje.gif')";	
}



function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

