var commentdiv = false;
var gameid;

function saveComment()
{
	var ajax = new sack();
	hideComment();
	showProgress("Processing...");
	var form = document.getElementById('commentform');
	ajax.setVar("gameid", form.gameid.value);
	ajax.setVar("comment", form.comment.value);
    ajax.setVar("gametitle",form.gametitle.value);
    ajax.setVar("gametype",form.gametype.value);
    ajax.setVar("gamescat",form.gamescat.value);
	ajax.requestFile = "/js/commentlib.php";
	ajax.method = "POST";
	ajax.onCompletion = function ()
	{
		defaultCompleteAction(ajax);
		if (!ajax.json_data['error'].length)
		{
			// if successed
			showJSMessage("", ajax.json_data['message']);
		}
	}
	ajax.runAJAX();
	return false;
}

// load and display commenting form
function setupCommentForm(div, gid, gTtl, gtype, gscat)
{
	var ajax = new sack();
	//showProgress("Loading form...");
	ajax.setVar("gid", gid);
	ajax.setVar("gTtl", gTtl);
    ajax.setVar("gtype", gtype);
    ajax.setVar("gttl", gTtl);
    ajax.setVar("gscat", gscat);
	ajax.requestFile = "/js/commentform.php";
	ajax.method = "POST";	
	ajax.onCompletion = function() {
		div.innerHTML = ajax.response;
		hideProgress();
	};
	ajax.runAJAX();
	return false;
}

function prepFormComm(gid, gTtl, gtype, gscat)
{
	if (!commentdiv)
	{
		commentdiv = document.createElement('DIV');
		commentdiv.id = 'commentdiv';
		commentdiv.className = 'floatdiv';
		commentdiv.style.display='none';
		setupCommentForm(commentdiv,gid,gTtl,gtype,gscat);
		document.body.appendChild(commentdiv);
	}
}

function showCommentForm(commentlink)
{	
	setTimeout("SlideRateComm();",500);
	
	/*gameTtl = gTtl;*/
	commentdiv.style.left = getLeftPos(commentlink) - 100 + 'px';
	commentdiv.style.top = getTopPos(commentlink) - 230 + 'px';
	commentdiv.style.position = 'absolute';
	commentdiv.style.zIndex = '1000';
	
	
	/*if (commentdiv.style.display=='none')
		commentdiv.style.display='block';*/
}

function SlideRateComm()
{
	var obj = commentdiv;//;document.getElementById('logindiv');
	
	if (obj.style.display == "block" || obj.style.display == "")
	{
		new Effect.Fade(obj);			
	}
	else
	{
		hideProgress();
		new Effect.Appear(obj);		
	}
	
}

function hideComment()
{
	if (commentdiv)
		SlideRateComm();
		//commentdiv.style.display='none';
}
