//
var docLoc;
var isValidate;
function frmAddGameCheckAndSubmit(errInfo)
{
	var F = document.forms["frmAddGame"];
	var F_STG = F["strTitle"];
	var F_SFG = F["fileGame"];
	var F_SLG = F["strLink"];
	var F_SFS = F["fileScreenShot"];
	var S_SLG = F_SLG["value"].substr(0,7);
	var S_HTTP = "http:\/\/";
	docLoc = false;

	if(!F_STG["value"] || F_STG["value"]["length"] < 2)
	{
		showErrorMessage(F_STG["name"]);
	}
	else
	{
		hideErrorMessage(F_STG["name"]);
	}
	if((!F_SLG["value"] || S_SLG != S_HTTP) && (!F_SFG["value"] || F_SFG["value"]["length"] < 6))
	{
		showErrorMessage(F_SLG["name"]);
		showErrorMessage(F_SFG["name"]);
	}
	else
	{
		hideErrorMessage(F_SLG["name"]);
		hideErrorMessage(F_SFG["name"]);
	}
	if(!F_SFS["value"] || F_SFS["value"]["length"] < 6)
	{
		showErrorMessage(F_SFS["name"]);
	}
	else
	{
		hideErrorMessage(F_SFS["name"]);
	}
	if(isValidate == true)
	{
		var req = mint.Request();
		req.method = "post";
		req.OnSuccess = function()
		{
			if(this.responseText == "true")
			{	// is spam, block for 2 minutes.
				alert(errInfo);
			}
			else
			{	// is ok, allow add game
				F.submit();
			}
		}
		req.Send("/gry/checkAddGameSpam.php");
	}
	//if(isValidate == true) F.submit();

}
function showErrorMessage(strID)
{
	isValidate = false;
	var frm = document.forms["frmAddGame"];
	if(strID.substr(0, 4) == "file") strID = "str" + strID;
	var divObj = $(strID);
	var spanObj = $(strID+"EI");
	divObj.className = "strError";
	spanObj.innerHTML = frm[strID+"EI"].value;
	if(docLoc == false)
	{
		docLoc = document.location='#'+strID;
		frm[strID].focus();
	}
	else
	{
		docLoc
	}
}
function hideErrorMessage(strID)
{
	isValidate = true;
	if(strID.substr(0, 4) == "file") strID = "str" + strID;
	var divObj = $(strID);
	var spanObj = $(strID+"EI");
	divObj.className = "strDefault";
	spanObj.innerHTML = "";
}

function addGameToFavourites(gameacro) {
	var req=mint.Request();
	req.OnSuccess = function() { alert(this.responseText); }
	req.Send("/gry/?/form/addtofavourites/"+gameacro+"/");
}

function removeGameFromFavourites(gameacro) {
	var req=mint.Request();
	req.OnSuccess = function() { alert(this.responseText); }
	req.Send("/gry/?/form/removefromfavourites/"+gameacro+"/");
}


//
// box play game
var showFrBox;
function showSendToFriend(object) {
	if(!showFrBox) {
		var cnm = $("stCnMn");
		var cn = $("stCon");
		var b = $("boxSendToFriend");
		var p = realPos(object);

		b.style.display='block';
		b.style.top=p[1]-cnm.offsetTop-cn.offsetTop+object.offsetHeight+'px';
		b.style.left=p[0]-realPos(cn)[0]-(b.offsetWidth-object.offsetWidth)+'px';
		document.forms['frmSendToFriend'].strEmails.focus();
		showFrBox=1;
	} else {
		var b = $("boxSendToFriend");
		b.style.display='none';
		showFrBox=0;
	}
}

function submitSendToFriends(successInfo, failedInfo, frmParseErrorInfo)
{
	var f = document.forms['frmSendToFriend'];
	var b = $("boxSendToFriend");

	var ok = false;
	//
	// check form here
	//
	// improwizowane sprawdzenie, zeby tylko wiedziec, ze moze byc dobrze, albo zle
	if(f.strEmails.value.length > 3) ok = true;
	if(ok)
	{
		req = mint.Request();

		req.OnSuccess = function() {
			if(!this.responseText)
			alert(successInfo);
			else
			alert(failedInfo);
			b.style.display='none';
			f.strEmails.value='';
			showFrBox=0;
		}

		req.SendForm(f);
	}
	else
	{
		alert(frmParseErrorInfo);
	}

	//return false;
}
// end: box play game
//