var ratediv = false;
var gameid;


function getChoice(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function saveRate()
{
	var ajax = new sack();
	hideRate();
	showProgress("Processing...");
	var form = document.getElementById('rateform');
	var rtvalue = getChoice(form.rtvalue);
	ajax.setVar("gameid", form.gameid.value);
	ajax.setVar("rtvalue", rtvalue);
    ajax.setVar("gametitle",form.gametitle.value);
    ajax.setVar("gametype",form.gametype.value);
    ajax.setVar("gamescat",form.gamescat.value);	
	ajax.requestFile = "/js/ratelib.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 rate form
function setupRateForm(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("gscat", gscat);
	ajax.requestFile = "/js/rateform.php";
	ajax.method = "POST";	
	ajax.onCompletion = function() {
		div.innerHTML = ajax.response;
		hideProgress();
	};
	ajax.runAJAX();
	return false;
}

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

function showRateForm(ratelink, gid, gttl, gtype, gscat)
{
	showProgress("Loading...");
	if (!ratediv)
	{
		ratediv = document.createElement('DIV');
		ratediv.id = 'ratediv';
		ratediv.className = 'floatdiv';
		ratediv.style.display='none';
		setupRateForm(ratediv,gid,gttl,gtype,gscat);
		document.body.appendChild(ratediv);
	}
	
	setTimeout("SlideRate()",1000);
	
	gameid = gid;
	ratediv.style.left = getLeftPos(ratelink) - 85 + 'px';
	//ratediv.style.top = getTopPos(ratelink) + ratelink.offsetHeight + 2 + 'px';
	ratediv.style.top = getTopPos(ratelink) - 90 + 'px';
	ratediv.style.position = 'absolute';	
	ratediv.style.zIndex = '1000';
	
	/*if (ratediv.style.display=='none')
		ratediv.style.display='block';*/
}

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

function hideRate()
{
	SlideRate();
	/*if (ratediv)
		ratediv.style.display='none';*/
}
