﻿//==============================================================================================================================
function createXMLHttps(){
	var ret = null;
	
	try{
		ret = new ActiveXObject('Msxml2.XMLHTTP');
	}catch(e){
		try{
			ret = new ActiveXObject('Microsoft.XMLHTTP');
		}catch (ee){
			ret = null;
		}
	}
	
	if(!ret && typeof XMLHttpRequest != 'undefined')
	ret = new XMLHttpRequest();
	
	return ret;
}
//==============================================================================================================================
function addFavorite(flashID){
	var userID = readCookie('userID');
	
	if(userID == ''){
		alert('Please login to add this game to your favourite games.');
	}else{
		var xmlhttp = createXMLHttps();
		
		xmlhttp.open("GET", '/ajax/favorite.php?userID=' + userID + '&flashID=' + flashID, true);
		xmlhttp.onreadystatechange = function(){
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200)	{
				alert('This game added to your favourite games.');
			}
		}
		
		xmlhttp.send(null);
	}
}
//==============================================================================================================================
function addComment(){
	var userID = document.frmComment.userID;
	var flashID = document.frmComment.flashID;
	var content = document.frmComment.content;
	
	if(userID.value == ''){
		alert('Please login to comment.');
		return false;
	}
	
	if(content.value == ''){
		alert('Please add contents.');
		content.focus();
		return false;
	}else{
		if(content.value.length > 100){
			alert('The contents cannot surpass 100 characters.');
		content.focus();
		return false;
		}
	}
	
	var xmlhttp = createXMLHttps();
	
	xmlhttp.open("GET", '/ajax/comment.php?userID=' + userID.value + '&flashID=' + flashID.value + '&content=' + content.value, true);
	xmlhttp.onreadystatechange = function(){
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200)	{
			alert('Comment added, we will check add approve the comment soon.');
			content.value = '';
		}
	}
	
	xmlhttp.send(null);
}
//==============================================================================================================================
