var xmlRequest = new xmlObj(false);


/* ------------------------------------------------------------------------------------------------ */
/* submitLogInForm 																					*/
/* ------------------------------------------------------------------------------------------------ */
function clearUserNameValue()
{
	document.getElementById("username").value = "";
}
function submitLoginForm()
{
	var formValidator = new Validator('theForm');
	formValidator.addValidation('username', 'required', 'יש להזין שם משתמש');
	formValidator.addValidation('password', 'required', 'יש להזין סיסמא');
	if (formValidator.validate ())
	{
		return true;
	}

	return false;
}

/* ------------------------------------------------------------------------------------------------ */
/* check date 																						*/
/* ------------------------------------------------------------------------------------------------ */
function isdate()
{
	var day, year, month;
	day=document.getElementById("form2_bday").value;
	month=document.getElementById("form2_bmonth").value;
	year=document.getElementById("form2_byear").value;
	if ((day!=00)&&(month!=00)&&(year!=0000))
	{
		if ((month==04)||(month==06)||(month==09)||(month==11))
		{
			if(day>30)
				{
					alert("בחודש "+month+" יש עד 30 ימים");
					return false;
				}
		}

		if(month==02)
		{
				if(day>28)
				{
					if (year % 4 != 0)
					{
						alert("בחודש "+month+" יש עד 28 ימים");
						return false;	
					}
				}
		}	
		
		if (year % 4 == 0)
		{
				if(month==02)
				{
					if(day>29)
					{
						alert("בחודש "+month+" יש עד 28 ימים");
						return false;	
					}
				}
		}
		document.getElementById("birthDate").value=year+"-"+month+"-"+day;
	}
	return true;
}

/* ------------------------------------------------------------------------------------------------ */
/* check password 																					*/
/* ------------------------------------------------------------------------------------------------ */
function checkGamerPassword () 	
{
	
	var password  = document.getElementById("password").value;
	var cNewPassword = document.getElementById("cNewPassword").value;
		if (password.value != cNewPassword.value)
		{
			alert("הסיסמא שהזנת שנית לא נכונה");
			cNewPassword.value = "";
			cNewPassword.focus();
			return false;
		}	
		if (password.value != "" && cNewPassword.value != "" && password.value != cNewPassword.value)
		{
			alert("הסיסמא שהזנת שנית לא נכונה");
			cNewPassword.value = "";
			cNewPassword.focus();
			return false;
		}	
		if ((password.value != "" && cNewPassword.value == "") || (password.value == "" && cNewPassword.value != ""))
		{
			alert("כדי לשנות סיסמא יש להזין סיסמא ולאמת אותה");
			password.value = "";
			cNewPassword.value = "";
			password.focus();
			return false;		
		}
	if (isdate() && isNumber("icq"))
		document.getElementById("formAddUsers").submit();	
	return false;
}

/* ------------------------------------------------------------------------------------------------ */
/* submitSiteRegisterForm 																			*/
/* ------------------------------------------------------------------------------------------------ */
function submitMembersForm ()
{
	var formValidator = new Validator('formAddUsers');

	oForm = document.getElementById("formAddUsers");

	var newPlatforms = "";
	var picName = "";
	var theNickname = oForm.nickname.value;
	setFilesNames("formAddUsers");
	formValidator.addValidation('email', 'required', 'יש להזין דואר אלקטרוני');
	formValidator.addValidation('email', 'email', 'יש להזין דואר אלקטרוני חוקי');
	formValidator.addValidation('newUsername', 'required', 'יש להזין שם משתמש');
	formValidator.addValidation('password', 'required', 'יש להזין סיסמא');
	formValidator.addValidation('cNewPassword', 'required', 'יש להזין סיסצא חוזרת');
	if (theNickname == "")
	{
		alert("יש להזין כנוי שיוצג באתר");
		 oForm.nickname.focus();
		return false;
	}
	if (oForm.agree.checked == false)
	{
		alert("חובה לאשר את ההסכמה לתנאי השימוש");
		oForm.agree.focus();
		return false;
	}
	if (formValidator.validate ())
	{
		newPlatforms = creatNewPlatforms ();
		if(newPlatforms == "")
		{
			alert("יש לבחור לפחות פלטפורמה אחת");
			return false;
		}
		document.getElementById("newPlatforms").value=newPlatforms;
		checkGamerPassword ();		 
	}

	return false; 
}

/* ------------------------------------------------------------------------------------------------ */
/* submitPopupMembersForm */
/* ------------------------------------------------------------------------------------------------ */
function submitPopupMembersForm (formName)
{
	oForm = document.getElementById(formName);
	oForm.nickname.value = oForm.username.value;

	var formValidator = new Validator(formName);
	
	formValidator.addValidation("email", 	"required", 	"יש להזין דואר אלקטרוני");
	formValidator.addValidation("email", 	"email", 		"יש להזין דואר אלקטרוני חוקי");
	formValidator.addValidation("username", "required", 	"יש להזין שם משתמש");

	if (formValidator.validate ())
	{
		if (oForm.agree.checked == false)
		{
			alert("חובה לאשר את ההסכמה לתנאי השימוש");
			oForm.agree.focus();
			return false;
		}
		else
		{
			return true;
		}
	}

	return false;
}

/* -------------------------------- */
/* deleteFriend					*/
/* -------------------------------- */
function deleteFriend (friendId)
{
	var del=confirm("האם אתה בטוח");
	if (del==true)
	{
  			xml = "<data>" +
						"<command>private.deleteFriend</command>" +
						"<friendId>"+friendId+"</friendId>"	+
				  "</data>";
	xmlRequest.init (xml);
	xmlRequest.sendAsyncRequest ("server.php", xmlRequest.obj, "afterDeleteFriend");
	}
	else
  	{
  		return;
  	}
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* afterDeleteFriend																											*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function afterDeleteFriend (i)
{
	xmlRequest.init(commonDecode(asyncHttpObjs[i].responseText));

	try
	{
		var returnValue = xmlRequest.getValue("success");
		if (returnValue == 1)
		{		
			alert ('מחיקת החבר הושלמה');
			window.location.reload();
		}
		else if (returnValue == 0)
			alert ('אין אפשרות למחוק חבר זה');
	}
	catch (e)
	{
		alert ("AJAX Error");
	}
}

/* -------------------------------- */
/* addFriend					*/
/* -------------------------------- */
function addFriend (friendId)
{
  	xml = "<data>" +
				"<command>private.addFriend</command>" +
				"<friendId>"+friendId+"</friendId>"	+
		 "</data>";
	xmlRequest.init (xml);
	xmlRequest.sendAsyncRequest ("server.php", xmlRequest.obj, "afterAddFriend");
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* afterAddFriend																											*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function afterAddFriend (i)
{
	xmlRequest.init(commonDecode(asyncHttpObjs[i].responseText));
	
	try
	{
		var returnValue = xmlRequest.getValue("success");
		if (returnValue == 1)
		{		
			alert ('החבר התווסף בהצלחה');
			window.location.reload();
		}
		else if (returnValue == 2)
			alert ('חבר זה כבר קיים אצלך ברשימה');
	}
	catch (e)
	{
		alert ("AJAX Error");
	}
}
/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* submitCompanyForm																											*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/

function submitCompanyForm()
{
	var nameENG = document.getElementById("nameENG").value;
	if (nameENG!="")
	{
		xml = "<data>" +
				"<command>private.checkCompany</command>" +
				"<nameENG>"+nameENG+"</nameENG>"	+
			 "</data>";
		xmlRequest.init (xml);
		xmlRequest.sendAsyncRequest ("server.php", xmlRequest.obj, "afterAddCompany");
	}
	else
	{
		alert("יש להזין את שם החברה באנגלית");
		document.getElementById("nameENG").focus();
	}
		
	return false;
}
/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* submitCompanyFormContinue																											*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function submitCompanyFormContinue()
{
	tinyMCE.triggerSave();

	var aboutCompany = document.getElementById("aboutCompany").value;
	var newGaners="";
	var newPlatforms = "";		
	if (aboutCompany != "")
	{
		newGaners=creatNewGaner();
		newPlatforms=creatNewPlatforms();
		document.getElementById("newGaners").value=newGaners;
		document.getElementById("newPlatforms").value = newPlatforms;
		if (isEnglish("החברה"))
		{
			setFilesNames("formAddCompany");
			document.getElementById("formAddCompany").submit();	
		}
	}
	else
	{
		alert("יש להזין את אודות החברה");
		document.getElementById("aboutCompany").focus();
	}
	return false;
}
/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* afterAddCompany																											*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function afterAddCompany (i)
{
	xmlRequest.init(commonDecode(asyncHttpObjs[i].responseText));
	
	try
	{
		var returnValue = xmlRequest.getValue("success");
		if (returnValue != 0)
		{		
			alert ('חברה זאת כבר קיימת באתר');
			window.location = "/index2.php?id="+returnValue;
		}
		else
		{
			submitCompanyFormContinue();
		}
	}
	catch (e)
	{
		alert ("AJAX Error");
	}
}
/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* displayPlatforns																											*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function displayPlatforms()
{
	document.getElementById("platformsOptions").style.display="block";
	document.getElementById("selectPlatform").style.display="none";
}
/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* 	creatNewGaner																									*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function creatNewGaner()
{
	var newGaners="";
	var chk=document.getElementsByName("ganers");
	for (var i = 0; i < chk.length; i++)
	{
		if (chk[i].checked == true)
		{
			if (newGaners!="")
				newGaners+=",";
			newGaners+=chk[i].value;	
		}
	}
	if (newGaners!="")
	{
		newGaners =","+newGaners+",";
	}
	return newGaners;
}
/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* 	creatNewPlatforms																									*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function creatNewPlatforms()
{
	var chk = document.getElementsByName("platforms");
	var newPlatforms="";
	for (i=0; i<chk.length; i++)
		{
			if (chk[i].checked == true)
			{
				if (newPlatforms != "")
					newPlatforms += ",";
				newPlatforms += chk[i].value;
			}
		}
	if (newPlatforms!="")
	{
		newPlatforms =","+newPlatforms+",";
	}
	return newPlatforms;
}
var popupOpenBorderId = null;
var popupOpenFormId = null;
var popupOpenHeight = null;
var popupOpenHeight1 = null;
/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* 	showPopup																									*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function openPopup(popupBorderId,popupFormId,popHeight,popHeight1)
{	
	if (popupOpenBorderId != null && popupOpenFormId != null)
	{
		document.getElementById(popupOpenBorderId).style.display="none";
		document.getElementById(popupOpenFormId).style.display="none";
	}
	
	popupOpenBorderId = popupBorderId;
	popupOpenFormId = popupFormId;
	popupOpenHeight = popHeight;
	popupOpenHeight1 = popHeight1;

	//--top position
	document.getElementById(popupFormId).style.top = popHeight+"px";
	document.getElementById(popupBorderId).style.top = popHeight1+"px";

	// right position
	if (document.getElementById(popupBorderId).className == "newPopupBorder")	// wide new popup
		popupWidth = 740;
	else
		popupWidth = 408;

	document.getElementById(popupFormId).style.right = (screen.availWidth-popupWidth)/2+"px"; 
	document.getElementById(popupBorderId).style.right = (screen.availWidth-popupWidth-40)/2+"px";
		
	//show popup
	document.getElementById(popupBorderId).style.display="block";
	document.getElementById(popupFormId).style.display="block";	
	
	//insert height to div border;
	divHeight= document.getElementById(popupFormId).offsetHeight;
	document.getElementById(popupBorderId).style.height = (divHeight+40)+"px";

}

var clickForAddNewEssay = false;

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/*  games_openAddEssayForm																										*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function games_openAddEssayForm (event)
{
	if (document.getElementById("popupFormAddNews") != undefined)
	{
		document.getElementById("addEssayWithPageId").value = "0";
	}

	clickForAddNewEssay = true;

	point_it ("popupBorderAddNews", "popupFormAddNews", "addNews",event);

	clickForAddNewEssay = false;
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* 	point_it																													*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function point_it(popupBorderId,popupFormId,divId,e)
{
	if (document.getElementById(popupFormId) != undefined)
	{
		oFader = document.getElementById("fader");
		if (oFader != undefined)
		{
			oFader.style.height = document.documentElement.scrollHeight + "px";
			oFader.style.width = "100%";
			oFader.style.display = "";
		}
		var mp = getMousePosition(e);  
		pos_y=mp.y;
		pos_y1 = pos_y-20;	

		if (document.getElementById("addEssayWithPageId") != undefined && !clickForAddNewEssay)	
			document.getElementById("addEssayWithPageId").value = "1";

		openPopup(popupBorderId,popupFormId,pos_y,pos_y1);	
	}
}
function getMousePosition(e) 
{ 
//	return e.pageX ? {'y':e.pageY} : {'y':e.clientY + document.documentElement.scrollTop + document.body.scrollTop}; 
	return e.pageX ? {'y': window.pageYOffset + 50} : {'y': document.documentElement.scrollTop + document.body.scrollTop + 50}; 
} 

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* 	closeWindow																									*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function closePopup(popupBorderId,popupFormId,formName)
{
	oFader = document.getElementById("fader");
	if (oFader != undefined)
	{
		oFader.style.display = "none";
	}
	document.getElementById(popupBorderId).style.display="none";
	document.getElementById(popupFormId).style.display="none";
}
/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* 	addPlatform																									*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function addPlaform(possible)
{
	var platformName = document.getElementsByName("morePlatforms");
	var subPlatform="";
	if (possible=="0")
	{
		alert("רק משתמשים רשומים יכולים להוסיף פלטפורמה");
		document.getElementById("morePlatforms").style.display="none";
		return;
	}
	for (var i=0; i<platformName.length;i++)
	{
		if (platformName[i].checked==true)
		{		
			subPlatform=platformName[i].value;
			break;
		}
	}

	xml = "<data>" +
				"<command>private.addPlatform</command>"+
				"<subPlatform>"+subPlatform+"</subPlatform>"+
			"</data>";

	xmlRequest.init (xml);
	xmlRequest.sendAsyncRequest ("server.php", xmlRequest.obj, "afterAddPlatform");	
}
/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* afterAddPlatform																										*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function afterAddPlatform (i)
{
	xmlRequest.init(commonDecode(asyncHttpObjs[i].responseText));
	
	try
	{
		var returnValue = xmlRequest.getValue("success");
		if (returnValue == 1)
		{		
			window.location.reload();
		}
		else
		{
			alert ('לא');
		}
	}
	catch (e)
	{
		alert ("AJAX Error");
	}
}
/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* showSubPlatform																										*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function showSubPlatform (check)
{
	if(check.checked == true)
	{
		document.getElementById("platformsOptions").style.display="block";	
	}
	else
	{
		document.getElementById("platformsOptions").style.display="none";
	}
	
}
/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* showSubGaners																												*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function showSubGaners (check)
{
	
	if(check.checked == true)
	{
		document.getElementById("ganersOptions").style.display="block";	
	}
	else
	{
		document.getElementById("ganersOptions").style.display="none";
	}
	
}
/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* submitGameForm																												*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function submitGameForm()
{
	tinyMCE.triggerSave();

	var formValidator = new Validator('formAddGames');
	var platformId 		= "";
	var newGaners		= "";
	var newNumPlayers 	= "";
	var NumPlayers		= document.getElementsByName("numPlayers");
	var platforms		= document.getElementsByName("platforms");

	var grade			= document.getElementById("startGrade").value;

	formValidator.addValidation('nameENG', 'required', 'יש להזין את שם המשחק באנגלית');
	formValidator.addValidation('fullDesc', 'required', 'יש להזין את התיאור של המשחק');

	if (formValidator.validate ())
	{
		if (grade == "selectGrade")
		{
			alert("יש לבחור ציון התחלתי למשחק");
			return false;
		}

		newGaners = creatNewGaner();
		if (newGaners == "")
		{
			alert("יש לבחור לפחות ז'אנר אחד");
			return false;
		}

		for (var i=0;i<platforms.length;i++)
		{
			if(platforms[i].checked == true)
			{
				platformId += platforms[i].value;
				break;
			}
		}

		if (platformId == "")
		{
			alert("יש לבחור פלטפורמה");
			return;
		}

		document.getElementById("newGaners").value	= newGaners;
		document.getElementById("platformId").value = platformId;

		for (var i=0;i<NumPlayers.length;i++)
		{
			if(NumPlayers[i].checked == true)
			{
				if(newNumPlayers!="")
				{
					newNumPlayers+=",";
				}
				newNumPlayers += NumPlayers[i].value;
			}
		}

		if (newNumPlayers != "")
		{
			newNumPlayers=","+newNumPlayers+",";
		}

		document.getElementById("newNumPlayers").value=newNumPlayers;
		if (isdate() && isEnglish("המשחק"))
		{
			gameExist(document.getElementById("nameENG").value,platformId);
		}
	}
	return false;
}
/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* isEnglish																													*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function isEnglish(type)
{
	var nameENG=document.getElementById("nameENG").value;
	var charpos = nameENG.search("[^A-Za-z0-9'\.:\\-& ]"); 
    if(nameENG.length > 0 &&  charpos >= 0) 
    { 
       	alert("שם " + type + " יכול להכיל רק אותיות באנגלית");
		document.getElementById("nameENG").focus();
		return false;
	}	
	return true;
}
/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* isNumber																														*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function isNumber(type)
{
	var value=document.getElementById(type).value;
	if (value != "")
	{
		var charpos = value.search("[^0-9]"); 
    	if(value.length > 0 &&  charpos >= 0) 
    	{ 
       		alert("שדה "+type+" יכול להכיל רק ספרות");
			document.getElementById(type).focus();
			return false;
		}
	}	
	return true;
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* gameExist																													*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function gameExist(nameENG,platformId)
{
	xml = "<data>" +
				"<command>private.gameExist</command>"+
				"<nameENG>"+nameENG+"</nameENG>"+
				"<platformId>"+platformId+"</platformId>"+
			"</data>";
	xmlRequest.init (xml);
	xmlRequest.sendAsyncRequest ("server.php", xmlRequest.obj, "afterGameExist");	
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* afterGameExist																												*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function afterGameExist(i)
{
	xmlRequest.init(commonDecode(asyncHttpObjs[i].responseText));
	
	try
	{
		var pageId 		= document.getElementById("pageId").value;
		var platformId 	= document.formAddGames.ganers.value;
		var returnValue = xmlRequest.getValue("success");

		if (returnValue == 0)
		{
			setFilesNames("formAddGames");	
			document.getElementById("formAddGames").submit();
		}
		else if (returnValue == 1)
		{
			setFilesNames("formAddGames");	
			document.getElementById("isExist").value="1";
			document.getElementById("formAddGames").submit();		
		}
		else
		{
			alert("משחק זה כבר קיים באתר");
			window.location = "/index2.php?id="+returnValue+"&lang=HEB";
		}
		
	}
	catch (e)
	{
		alert ("AJAX Error");
	}
}
/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* showAddToMyGame																												*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function showAddToMyGame()
{
	document.getElementById("addToMyGame").style.display="block";
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* setFilesNames																												*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function setFilesNames (formName)
{
	oForm = document.getElementById(formName);

	filesNamesStr = "";

	if (document.getElementById("picsTbl1") == undefined)
		tableName = "picsTbl";
	else
		tableName = "picsTbl1";

	oForm.filesNames.value = getFilesNamesFromTable (tableName);

	if (formName == "formAddGames")
	{
		oForm.bannerNames.value = getFilesNamesFromTable ("bannerTbl");
	}
}

function getFilesNamesFromTable (tableName)
{
	filesNamesStr = "";

	oTbl = document.getElementById(tableName).getElementsByTagName("tbody")[0];

	numPics = oTbl.rows.length;

	for (r=1; r<numPics; r++)
	{
		row = oTbl.rows[r];

		picName = row.cells[1].childNodes[1].id;

		if (filesNamesStr != "") filesNamesStr += " ";

		filesNamesStr += picName.replace(/\s/g, "_");
	}

	return filesNamesStr;
}

/* -------------------------------- */
/* addToMyGame					*/
/* -------------------------------- */
function addToMyGame ()
{
	var isFavorite, isForSale, isForBuy, isPlayingNow;
	var pageId = document.getElementById("pageId").value;
	isFavorite = "0";
	isForSale = "0";
	isForBuy = "0";
	isPlayingNow = "0";

	if (document.getElementById("isFavorite").checked==true) isFavorite="1";

	// This code should be removed
	try
	{
		if (document.getElementById("isForSale").checked==true) isForSale="1";
		if (document.getElementById("isForBuy").checked==true) isForBuy="1";
	}
	catch (e)
	{
	}

	if (document.getElementById("isPlayingNow").checked==true) isPlayingNow="1";

  	xml = "<data>" +
				"<pageId>"+pageId+"</pageId>"	+
				"<command>private.addToMyGame</command>" +
				"<isFavorite>"+isFavorite+"</isFavorite>"	+
				"<isForSale>"+isForSale+"</isForSale>"	+
				"<isForBuy>"+isForBuy+"</isForBuy>"	+
				"<isPlayingNow>"+isPlayingNow+"</isPlayingNow>"	+
		 "</data>";

	xmlRequest.init (xml);
	xmlRequest.sendAsyncRequest ("server.php", xmlRequest.obj, "afterAddToMyGame");
}

/* -------------------------------- */
/* addForSale						*/
/* -------------------------------- */
function addForSale (isMemberLogin, pageId, isFavorite, isForBuy, isPlayingNow)
{
	if (isMemberLogin == "0")
	{
		alert("ההוספה היא לגולשים רשומים בלבד.");
		return;
	}
	
  	xml = "<data>" +
				"<pageId>"+pageId+"</pageId>"	+
				"<command>private.addToMyGame</command>" +
				"<isFavorite>"+isFavorite+"</isFavorite>"	+
				"<isForSale>1</isForSale>"	+
				"<isForBuy>"+isForBuy+"</isForBuy>"	+
				"<isPlayingNow>"+isPlayingNow+"</isPlayingNow>"	+
		 "</data>";

	xmlRequest.init (xml);
	xmlRequest.sendAsyncRequest ("server.php", xmlRequest.obj, "afterAddToMyGame");
}
/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* afterAddToMyGame																												*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function afterAddToMyGame (i)
{
	xmlRequest.init(commonDecode(asyncHttpObjs[i].responseText));
	
	try
	{
		var returnValue = xmlRequest.getValue("done");

		if (returnValue == "not_login")
		{
			alert ("ההוספה היא לגולשים רשומים בלבד.");
			closePopup("addToMyGameBorder","addToMyGame","myGame");
			return;
		}

		var pageId = xmlRequest.getValue("pageId");
		var forSale = xmlRequest.getValue("forSale");
		var rowNum = xmlRequest.getValue("rowNum");

		if (forSale != 1)
		{		
			window.location.reload();
		}
		else
		{
			window.location = "/index2.php?id=117&page="+pageId+"&item="+rowNum;
		}
	}
	catch (e)
	{
		alert ("AJAX Error");
	}
}
/* -------------------------------- */
/* updateGameData		    	*/
/* -------------------------------- */
function updateGameData(tableName,rowId,nameField)
{
	tinyMCE.triggerSave();
	var fieldValue = "";
	var fieldValue1 = "";
	var theChangeType = "";

	switch (nameField)
	{
		case "companyId":
			fieldValue = document.editCompany.companies.value;
		break;
		case "exitDate":
			if (isdate())
			{
				fieldValue = document.getElementById("birthDate").value;
			}
			else
				return;
		break;
		case "ganers":
			var newGaners = "";
			newGaners = creatNewGaner();
			if (newGaners)
			{
				fieldValue = newGaners;
			}
			else
			{
				alert("יש לבחור לפחות ז'אנר אחד");
				return;
			}
		break;
		case "numPlayers":
			var newNumPlayers = "";
			var NumPlayers=document.getElementsByName("numPlayers");

			for(var i=0;i<NumPlayers.length;i++)
			{
				if(NumPlayers[i].checked == true)
				{
					if(newNumPlayers!="")
					{
						newNumPlayers+=",";
					}
					newNumPlayers += NumPlayers[i].value;
				}	
			}
			if (newNumPlayers!="")
			{
				newNumPlayers =","+newNumPlayers+",";
			}
			fieldValue=newNumPlayers;
		break;
		case "videoSource":
			var videoCode = document.getElementById("videoCode").value;
			if (videoCode == "" || videoCode == "Enter YouTube Embed code here")
			{
				alert("יש להזין קוד סרטון");
				return false;
			}
			if (videoCode.match("param name=\"movie\" value=\"http://www.youtube.com/v") == null &&
				videoCode.match("iframe title=\"YouTube video player") == null)
			{
				alert("הקוד לא זוהה כ-embed של YouTube");
				return false;
			}
			videoCode = videoCode.replace(/width=\"\d+\" height=\"\d+\"/g,"width=\"260\" height=\"210\"");
			fieldValue = videoCode;
		break;
		case "fullDesc":
			fieldValue 		= document.getElementById("fullDesc").value;
			fieldValue1 	= document.getElementById("shortDesc").value;
			theChangeType 	= document.getElementById("changeType").value;
		break;
		case "buildYear":
			fieldValue = document.getElementById("buildYear").value;
		break;
		case "description":
			fieldValue = document.getElementById("fullDescription").value;
		break;
		case "youKnowText":
			fieldValue = document.getElementById("youKnow").value;
		break;
		case "active":
			var statusCompaby = document.getElementsByName("statusCompany");
			for (var i=0; i<statusCompaby.length; i++)
			{
				if (statusCompaby[i].checked == true)
				{
					fieldValue = statusCompaby[i].value;
					break;
				}
			}
			if (fieldValue == "enactive")
			{
				fieldValue += "," + document.getElementById("dismantlingYear").value; 
			}
		break;
		case "platforms":
			fieldValue = creatNewPlatforms();
		break;
		case "LinksTo":
			fieldValue = document.getElementById("LinksTo").value;
		break;
		default:
		window.location.reload();
	}
	
	if (nameField != "picFile")
	{
		xml = "<data>" +
				"<command>private.updateGameData</command>" +
				"<fieldValue><![CDATA["+fieldValue+"]]></fieldValue>" +
				"<fieldValue1><![CDATA["+fieldValue1+"]]></fieldValue1>" +
				"<changeType>"+theChangeType+"</changeType>"+
				"<tableName>"+tableName+"</tableName>" +
				"<rowId>"+rowId+"</rowId>" +
				"<nameField>"+nameField+"</nameField>" +
		 "</data>";
		xmlRequest.init (xml);
		xmlRequest.sendAsyncRequest ("server.php", xmlRequest.obj, "afterUpdateGameData");
	}
  	
}
/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* afterUpdateGameData																										*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function afterUpdateGameData (i)
{
	xmlRequest.init(commonDecode(asyncHttpObjs[i].responseText));
	try
	{
		var returnValue = xmlRequest.getValue("success");
		if (returnValue == "ok")
		{
			document.getElementById(popupOpenBorderId).style.display="none";
			document.getElementById(popupOpenFormId).style.display="none"; 
			openPopup('popupAfterSend','popupText',popupOpenHeight,popupOpenHeight1);
		}
		else if (returnValue == "noting_to_update")
		{
			alert ("לא עודכנו פרטים");
			return;
		}
	}
	catch (e)
	{
		alert ("AJAX Error");
	}
}
/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* uploadGameData																										*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function uploadGameData (tableName,rowId,nameField)
{
	var filesNames, dirName;

	setFilesNames("addScreanshot");
	filesNames = document.getElementById("filesNames").value;
	dirName = document.getElementById("filesDir").value;
	picDesc = document.getElementById("picDesc").value;

	if (filesNames == "")
	{
		alert("יש להוסיף תמונה");
		return;
	}
	if (picDesc == "")
	{
		alert("יש להזין תיאור לתמונה");
		document.getElementById("picDesc").focus();
		return;
	}

	xml = "<data>" +
			"<command>private.uploadGameData</command>" +
			"<filesNames>"+filesNames+"</filesNames>" +
			"<tableName>"+tableName+"</tableName>" +
			"<rowId>"+rowId+"</rowId>" +
			"<nameField>"+nameField+"</nameField>" +
			"<dirName>"+dirName+"</dirName>" +
			"<picDesc>"+picDesc+"</picDesc>" +
		 "</data>";
	xmlRequest.init (xml);
	xmlRequest.sendAsyncRequest ("server.php", xmlRequest.obj, "afterUploadGameData");

}
/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* afterUploadGameData																										*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function afterUploadGameData (i)
{
	xmlRequest.init(commonDecode(asyncHttpObjs[i].responseText));
	
	try
	{
		var returnValue = xmlRequest.getValue("success");
		if (returnValue == "ok")
		{		
			document.getElementById(popupOpenBorderId).style.display="none";
			document.getElementById(popupOpenFormId).style.display="none"; 
			openPopup('popupAfterSend','popupText',popupOpenHeight,popupOpenHeight1);
		}
	}
	catch (e)
	{
		alert ("AJAX Error");
	}
}
/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* clearAreaAddMovie																										*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function clearAreaAddMovie()
{
	
	var videoCode = document.getElementById("videoCode").value;

	if (videoCode == "Enter YouTube Embed code here")
	{
		videoCode = "";
		document.getElementById("videoCode").value = videoCode;
	}
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* updateGameDetails																											*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function updateGameDetails (gameId)
{
	var oForm = $("editDetailsForm");

	if (isdate())
	{
		var companyId 	= oForm.companyId.value;
		var exitDate	= oForm.birthDate.value;
		var ganers		= creatNewGaner();

		if (ganers == "")
		{
			alert ("יש לבחור לפחות ז'אנר אחד");
			return;
		}

		var numPlayers	= "";

		var options 	= document.getElementsByName("numPlayers");

		for (var i=0; i < options.length; i++)
		{
			if(options[i].checked == true)
			{
				if(numPlayers != "")
					numPlayers += ",";

				numPlayers += options[i].value;
			}	
		}

		if (numPlayers!="")
		{
			numPlayers = "," + numPlayers + ",";
		}
	}

	xml = "<data>" +
			"<command>private.updateGameDetails</command>" 		+
			"<gameId>"		+ gameId		+ "</gameId>" 		+
			"<companyId>" 	+ companyId 	+ "</companyId>"	+
			"<exitDate>"  	+ exitDate 		+ "</exitDate>"		+
			"<ganers>"		+ ganers		+ "</ganers>"		+
			"<numPlayers>"	+ numPlayers	+ "</numPlayers>"	+
	 "</data>";

	xmlRequest.init (xml);
	xmlRequest.sendAsyncRequest ("server.php", xmlRequest.obj, "afterUpdateGameData");
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* openSelectBoxDismantlingYear																									*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function openSelectBoxDismantlingYear()
{
	document.getElementById("SelectBoxDismantlingYear").style.display="block";
	document.getElementById("contentActive").style.width="116px";
	document.getElementById("contentEnactive").style.width="116px";
}
/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* closeSelectBoxDismantliformIdOpenngYear																									*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function closeSelectBoxDismantlingYear()
{
	document.getElementById("SelectBoxDismantlingYear").style.display="none";
	document.getElementById("contentActive").style.width="184px";
	document.getElementById("contentEnactive").style.width="184px";
}
var formIdOpen = null;
var toShowIdOpen = null;
/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* openContent																									*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/

function openContent(formId, toShowId)
{
	
	if (formIdOpen != null && toShowIdOpen != null )
	{
		document.getElementById(formIdOpen).style.display="none";
		document.getElementById(toShowIdOpen).innerHTML = "לצפייה בתוכן לחץ<span class='openContentConfirm' onclick=\"openContent('"+formIdOpen+"','"+toShowIdOpen+"')\"> כאן</span>";
	}
	formIdOpen = formId;
	toShowIdOpen = toShowId;

	document.getElementById(formIdOpen).style.display="block";
	document.getElementById(toShowIdOpen).innerHTML = "<div><span class='closeContentConfirm' onclick=\"closeContent('"+formId+"','"+toShowId+"')\">סגור</span></div>";
}
/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* openContent																									                */
/* ----------------------------------------------------------------------------------------------------------------------------	*/

function closeContent(formId,toShowId)
{
	document.getElementById(formIdOpen).style.display="none";
	document.getElementById(toShowId).innerHTML = "לצפייה בתוכן לחץ<span class='openContentConfirm' onclick=\"openContent('"+formId+"','"+toShowId+"')\"> כאן</span> ";
}
/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* addEssays																									                */
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function addEssays(formId,pageId,formType)
{
	tinyMCE.triggerSave();
	var title, subtitle, txt, grade, gradeXml,filesNames, dirName,newsPicDesc;

	grade 		= "";
	filesNames	= ""; 
   	dirName		= "";
	newsPicDesc = "";
	extraData3  = "";

	switch (formType)
	{
		case "news":
			title 	 	= document.getElementById("addNewsTitle").value;
			subtitle 	= document.getElementById("addNewsSubtitle").value;
			txt 		= document.getElementById("addNewsTxt").value;
			extraData3 	= document.getElementById("extraData3").value;

			document.getElementById("newsFileName").value = document.getElementById("newsFileName_spn").innerHTML;

			filesNames 	= document.getElementById("newsFileName").value;
			dirName 	= document.getElementById("newsFileDir").value;
			newsPicDesc = document.getElementById("newsPicDesc").value;

			if (document.getElementById("addEssayWithPageId") != undefined && document.getElementById("addEssayWithPageId").value == "0")
				pageId = "";

			break;

		case "cheats":
			title 		= document.getElementById("addCheatTitle").value;
			subtitle 	= document.getElementById("addCheatSubtitle").value;
			txt 		= document.getElementById("addCheatTxt").value;
			break;

		case "review":
			title 		= document.getElementById("addReviewTitle").value;
			subtitle 	= document.getElementById("addReviewSubtitle").value;
			txt 		= document.getElementById("addReviewTxt").value;
			grade 		= document.getElementById("addReviewGrade").value;
			break;
	}

	if (title == "")
	{
		alert("יש להזין כותרת ראשית");
		return;
	}
	if (subtitle == "")
	{
		alert("יש להזין כותרת משנה");
		return;
	}
	if (txt == "")
	{
		alert("יש להזין את התוכן");
		return;
	}
	if (formType == "review" && grade=="grade")
	{
		alert("יש לבחור ציון למשחק");
		return;
	}

	if (essayFileDoUpload)
	{
		alert ("יש להמתין לסיום טעינת התמונה");
		return;
	}

	xml = "<data>" +
			"<command>private.addEssays</command>" +
			"<title><![CDATA["+title+"]]></title>" +
			"<subtitle><![CDATA["+subtitle+"]]></subtitle>" +
			"<txt><![CDATA["+txt+"]]></txt>" +
			"<grade>"+grade+"</grade>" +
			"<pageId>"+pageId+"</pageId>" +
			"<formType>"+formType+"</formType>" +
			"<filesNames>"+filesNames+"</filesNames>" +
			"<dirName>"+dirName+"</dirName>" +
			"<newsPicDesc>"+newsPicDesc+"</newsPicDesc>" +
			"<extraData3><![CDATA["+extraData3+"]]></extraData3>" +
		 "</data>";
	xmlRequest.init (xml);
	xmlRequest.sendAsyncRequest ("server.php", xmlRequest.obj, "afterAddEssays");	
}
/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* afterAddEssays				     																			                */
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function afterAddEssays (i)
{
	xmlRequest.init(commonDecode(asyncHttpObjs[i].responseText));
	
	try
	{
		var returnValue = xmlRequest.getValue("success");
		if (returnValue == "ok")
		{		
			window.location = "/index2.php?id=6&lang=HEB";
		}
	}
	catch (e)
	{
	}
}
/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* sendPM																										                */
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function sendPM()
{
	var title, txt, memberToId;

	title = document.getElementById("addPMTitle").value;
	txt = document.getElementById("addPMTxt").value;
	memberToId = document.getElementById("memberToId").value;
	if (title == "")
	{
		alert("יש להזין כותרת");
		return;
	}
	xml = "<data>" +
			"<command>private.addPM</command>" +
			"<title>"+title+"</title>" +
			"<txt><![CDATA["+txt+"]]></txt>" +
			"<memberToId>"+memberToId+"</memberToId>" +
		 "</data>";
	xmlRequest.init (xml);
	xmlRequest.sendAsyncRequest ("server.php", xmlRequest.obj, "afterSendPM");	
}
/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* afterAddPM					     																			                */
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function afterSendPM (i)
{
	xmlRequest.init(commonDecode(asyncHttpObjs[i].responseText));
	
	try
	{
		var returnValue = xmlRequest.getValue("success");
		if (returnValue == "ok")
		{		
			document.getElementById(popupOpenBorderId).style.display="none";
			document.getElementById(popupOpenFormId).style.display="none"; 
			openPopup('popupAfterSend','popupText',popupOpenHeight,popupOpenHeight1);
		}
	}
	catch (e)
	{
		alert ("AJAX Error");
	}
}
/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* insertGrade				     																			                */
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function insertGrade (grade)
{
	if (grade != "")
	{
		document.getElementById(grade).selected="selected";
	}	
}
/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* delStatusGame				     																			                */
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function delStatusGame (gameId, typeField)
{
	var del=confirm("האם אתה בטוח");

	if (del==true)
	{
  		xml = "<data>" +
				"<command>private.delStatusGame</command>" +
				"<gameId>"+gameId+"</gameId>" +
				"<typeField>"+typeField+"</typeField>" +
			 "</data>";
		xmlRequest.init (xml);
		xmlRequest.sendAsyncRequest ("server.php", xmlRequest.obj, "afterDelStatusGame");
	}
	else
  	{
  		return;
  	}
	
}
/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* afterDelStatusGame				     																			                */
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function afterDelStatusGame (i)
{
	xmlRequest.init(commonDecode(asyncHttpObjs[i].responseText));
	
	try
	{
		var returnValue = xmlRequest.getValue("success");
		if (returnValue == "ok")
		{		
			window.location.reload();
		}
	}
	catch (e)
	{
		alert ("AJAX Error");
	}
}
/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* updateConfirm				     																			                */
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function updateConfirm (action)
{
	try {tinyMCE.triggerSave();} catch(e) {}

	document.getElementById("action").value = action;
	document.getElementById("confirmForm").submit();
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* uploadBoxShot																										*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function uploadBoxShot (tableName,rowId,nameField)
{
	var filesNames, dirName;
	document.getElementById("filesNames").value = document.getElementById("essayFileName_spn").innerHTML;
	filesNames = document.getElementById("filesNames").value;
	dirName = document.getElementById("filesDir").value;
	
	if (filesNames == "")
	{
		alert ("יש לבחור תמונה למשחק");
	} else {
		xml = "<data>" +
				"<command>private.uploadBoxShot</command>" +
				"<filesNames>"+filesNames+"</filesNames>" +
				"<tableName>"+tableName+"</tableName>" +
				"<rowId>"+rowId+"</rowId>" +
				"<nameField>"+nameField+"</nameField>" +
				"<dirName>"+dirName+"</dirName>" +
			 "</data>";
		xmlRequest.init (xml);
		xmlRequest.sendAsyncRequest ("server.php", xmlRequest.obj, "afterUploadBoxShot");
	}
}
/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* afterUploadGameData																										*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function afterUploadBoxShot (i)
{
	xmlRequest.init(commonDecode(asyncHttpObjs[i].responseText));
	
	try
	{
		var returnValue = xmlRequest.getValue("success");
		if (returnValue == "ok")
		{		
			document.getElementById(popupOpenBorderId).style.display="none";
			document.getElementById(popupOpenFormId).style.display="none"; 
			openPopup('popupAfterSend','popupText',popupOpenHeight,popupOpenHeight1);
		}
	}
	catch (e)
	{
		alert ("AJAX Error");
	}
}
/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* sendMail																										*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function sendPass ()
{
	var username;
	userName = document.getElementById("sendUsername").value;
	if (userName == "")
	{
		alert("יש להזין שם משתמש");
		document.getElementById("sendUsername").focus();
		return;
	}
	else
	{	
		document.getElementById("passForm").submit();
	}
}
/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* 	getResults																									*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
var advGaner, advPlat, advNumPlayers, advConpany, advYear, isFreeSearch, freeSearchValue;
advGaner = "";
advPlat = "";
advNumPlayers = "";
advConpany = "";
advYear = "";
isFreeSearch = false;
freeSearchValue = "";
function getResults (value, cat)
{
		
	switch (cat)
	{
		case "ganer":
			advGaner = value;
		break;
		case "platform":
			advPlat = value;
		break;
		case "company":
			advConpany = value;
		break;
		case "year":
			advYear = value;
		break;
		case "numPlayers":
			advNumPlayers = value;
		break;
		case "freeSearch":
			isFreeSearch = true;
			freeSearchValue = value;
		break;
	}

	xml = "<data>" +
			"<command>private.getResults</command>" +
			"<ganer>"+advGaner+"</ganer>" +
			"<platform>"+advPlat+"</platform>" +
			"<numPlayers>"+advNumPlayers+"</numPlayers>" +
			"<year>"+advYear+"</year>" +
			"<company>"+advConpany+"</company>" +
			"<advFreeSearch>"+freeSearchValue+"</advFreeSearch>" +
		 "</data>";
	xmlRequest.init (xml);
	xmlRequest.sendAsyncRequest ("server.php", xmlRequest.obj, "afterGetResults");

}
/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* 	afterGetResults																									*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function afterGetResults (i)
{
	xmlRequest.init(commonDecode(asyncHttpObjs[i].responseText));
	
	try
	{

		var path = xmlRequest.getValue("path");
		var result = xmlRequest.getValue("result");
		document.getElementById("advSearch").innerHTML = result;
		document.getElementById("choosePath").innerHTML = path;	
	}
	catch (e)
	{
		//alert ("AJAX Error at afterGetResults: " + e.message );
	}
}
/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* 	cleanPath																									*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function cleanPath (cat)
{
	switch (cat)
	{
		case "ganer":
			advGaner = "";
			getResults (advGaner,cat);
		break;
		case "platform":
			advPlat = "";
			getResults (advPlat,cat);
		break;
		case "company":
			advConpany = "";
			getResults (advConpany,cat);
		break;
		case "year":
			advYear = "";
			getResults (advYear,cat);
		break;
		case "numPlayers":
			advNumPlayers = "";
			getResults (advNumPlayers,cat);
		break;	
		case "free":
			isFreeSearch = false;
			freeSearchValue = "";
			document.getElementById("freeSearch").value = "הקלד מילת חיפוש";
			getResults (freeSearchValue,cat);
		break;
	}	
}
/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* 	cleanInput																									*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function cleanInput()
{
	if (document.getElementById("freeSearch").value == "הקלד מילת חיפוש")
	{
		document.getElementById("freeSearch").value = "";	
	}
	
}
/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* 	advFreeSearch																									*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function advFreeSearch ()
{
	var freeSearchStr = document.getElementById("freeSearch").value;

	if ((freeSearchStr == "הקלד מילת חיפוש") || (freeSearchStr == ""))
	{
		alert ("אנא הכנס ערך לחיפוש");
		cleanInput();
		document.getElementById("freeSearch").focus();
	}
	else
	{
		xml = "<data>" +
				"<command>private.advfreeSearch</command>" +
				"<freeSearchVal>"+freeSearchStr+"</freeSearchVal>" +
			 "</data>";
		xmlRequest.init (xml);
		xmlRequest.sendAsyncRequest ("server.php", xmlRequest.obj, "afterFreeSearch");
	}

}
/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* 	afterFreeSearch																							            		*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function afterFreeSearch (i)
{
	xmlRequest.init(commonDecode(asyncHttpObjs[i].responseText));
	
	try
	{
		var result = xmlRequest.getValue("result");
		var path = xmlRequest.getValue("path");
		document.getElementById("advSearch").innerHTML = result;
		document.getElementById("choosePath").innerHTML = path;
		isFreeSearch = true;
	}
	catch (e)
	{
		alert ("AJAX Error");
	}
}
/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* 	submitGameSaleForm																							            		*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function submitGameSaleForm()
{
	var city = document.getElementById("city").value;
	var price = document.getElementById("price").value;
	var partNumber = document.getElementById("partNumber").value;
	var mediaType = document.getElementById("mediaType").value;
	var flag;

	flag = getFlag("diskStatus");
	if (flag == false)
	{
		alert("יש לסמן את מצב הדיסק");
		return;
	}
	if (mediaType == "0")
	{
		alert("יש לבחור את סוג המדיה של המשחק");
		document.getElementById("price").focus();
		return;
	}
	if (partNumber == "0")
	{
		alert("יש לבחור את מספר החלקים שיש למשחק");
		document.getElementById("price").focus();
		return;
	}
	flag = getFlag("originalBox");
	if (flag == false)
	{
		alert("יש לסמן האם יש קופסה מקורית למשחק");
		return;
	}
	flag = getFlag("opBooklet");
	if (flag == false)
	{
		alert("יש לסמן האם קיימת חוברת הוראות למשחק");
		return;
	}
	if (city == "")
	{
		alert("יש להזין את שם העיר בא נמצא המשחק");
		document.getElementById("city").focus();
		return;
	}
	if (price == "")
	{
		alert("יש להזין את המחיר של המשחק");
		document.getElementById("price").focus();
		return;
	}

	if (isNumber("price"))
		document.getElementById("formGameSale").submit();

	
}
/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* 	getFlag																							            		*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function getFlag(radioName)
{
	var radioField = document.getElementsByName(radioName);
	var flag = false;

	for (var i = 0; i < radioField.length && flag == false ; i++)
	{
		if (radioField[i].checked == true)
		{
			flag = true;
		}
	}
	return 	flag;
}
/* -----------------------------------------------------`-----------------------------------------------------------------------	*/
/* 	addCommunity																							            		*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function openCommunity (pageId)
{
	var formValidator = new Validator('addCommunity');
	formValidator.addValidation('addCommunitySubject', 'required', 'יש להזין את נושא');
	formValidator.addValidation('addCommunityContent', 'required', 'יש להזין תוכן');
	if (formValidator.validate ())
	{
		var subject = document.getElementById("addCommunitySubject").value;
		var content = document.getElementById("addCommunityContent").value;
		var forumId = document.getElementById("forumId").value;
		xml = "<data>" +
				"<command>private.openCommunity</command>" +
				"<pageId>"+pageId+"</pageId>" +
				"<content>"+content+"</content>" +
				"<subject>"+subject+"</subject>" +
				"<forumId>"+forumId+"</forumId>" +
			 "</data>";
		xmlRequest.init (xml);
		xmlRequest.sendAsyncRequest ("server.php", xmlRequest.obj, "afterOpenCommunity");
	}
	

}
/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* 	afterOpenForum																							            		*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function afterOpenCommunity (i)
{
	xmlRequest.init(commonDecode(asyncHttpObjs[i].responseText));
	
	try
	{
		var success = xmlRequest.getValue("success");
		document.getElementById(popupOpenBorderId).style.display="none";
		document.getElementById(popupOpenFormId).style.display="none"; 
		openPopup('popupAfterSend','popupText',popupOpenHeight,popupOpenHeight1);
	}
	catch (e)
	{
		alert ("AJAX Error");
	}
}
/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* 	clearCode																							            		*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function clearCode()
{
	var code = document.getElementById("code").value;
	if (code == "הכנס קוד")
		 document.getElementById("code").value = "";
}
/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* 	switchMoreGames																							            		*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function switchMoreGames()
{
	var div1 = document.getElementById("moreGames1");
	var div2 = document.getElementById("moreGames2");
	if (div1.style.display == 'none')
	{
			div2.style.display = 'none';
			div1.style.display = '';
	} else {
			div1.style.display = 'none';
			div2.style.display = '';
	}
}

function addLoadEvent(func)
{   
	var oldonload = window.onload;   
	if (typeof window.onload != 'function') {   
		window.onload = func;   
	} else {   
		window.onload = function() {   
			if (oldonload) {   
				oldonload();   
			}   
			func();   
		}   
	}   
} 
				

function changeEssayPageTabs (on, off)
{
	document.getElementById(off).style.display 		= "none";
	document.getElementById(on).style.display  		= "";

	document.getElementById(off+"Tab").className   	= "tab_bg";
	document.getElementById(on+"Tab").className    	= "selectedTab_bg";
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* games_selectMainEssays																										*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function games_selectMainEssays (tab, plat)
{
  	xml = "<data>" +
				"<command>private.getMainEssays</command>" +
				"<tab>"	 + tab	+ "</tab>"	+
				"<plat>" + plat	+ "</plat>"	+
		 "</data>";

	xmlRequest.init (xml);
	xmlRequest.sendAsyncRequest ("server.php", xmlRequest.obj, "loadMainEssays");
}

function loadMainEssays (i)
{
	xmlRequest.init(commonDecode(asyncHttpObjs[i].responseText));
	
	try
	{
		var essaysTopHtml 	 = xmlRequest.getValue("essaysTopHtml");
		var essaysBottomHtml = xmlRequest.getValue("essaysBottomHtml");
		var tab 	 		 = xmlRequest.getValue("tab");

		for (var i = 1; i <= 4; i++)
		{
			if (tab == i)
				document.getElementById("essaysTab" + i).className = "mainEssaysTab_selected";
			else
				document.getElementById("essaysTab" + i).className = "mainEssaysTab";
		}

		document.getElementById("mainEssaysTopContent").innerHTML 	 = essaysTopHtml;
		document.getElementById("mainEssaysBottomContent").innerHTML = essaysBottomHtml;
	}
	catch (e)
	{
	}
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* games_selectMainGames																										*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function games_selectMainGames (tab, plat)
{
	if (document.getElementById("gamesTab" + tab).className != "mainGamesTab_selected")
	{
		if (tab == 1)
			otherTab = 2;
		else
			otherTab = 1;

		document.getElementById("gamesTab" + tab).className 		= "mainGamesTab_selected";
		document.getElementById("gamesTab" + otherTab).className 	= "mainGamesTab";

		var saveHtml = document.getElementById("mainGamesContent").innerHTML;
		document.getElementById("mainGamesContent").innerHTML = document.getElementById("mainGamesOtherContent").innerHTML
		document.getElementById("mainGamesOtherContent").innerHTML = saveHtml;
	}

}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* games_topMenuOver																											*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function games_topMenuOver (pos)
{
	document.getElementById("topMenu_link" + pos).className = "topMenu_link_selected";

	if (pos == 0)
	{
		document.getElementById("topMenuFirst").className = "topMenuFirst_selected";
	}
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* games_topMenuOut																												*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function games_topMenuOut (pos)
{
	document.getElementById("topMenu_link" + pos).className = "topMenu_link";

	if (pos == 0)
	{
		document.getElementById("topMenuFirst").className = "topMenuFirst";
	}
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* games_showHideLoginForm																										*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function games_showHideLoginForm ()
{
	var oTopMember = document.getElementById("topMember");

	if (oTopMember.className.indexOf("_open") == -1)
	{
		oTopMember.className += "_open";
		document.getElementById("loginPopup").style.display = "";
	}
	else
	{
		oTopMember.className = oTopMember.className.substr(0, oTopMember.className.length-5);
		document.getElementById("loginPopup").style.display = "none";
	}
}

var currNews = 1;
var autoChange = true;

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* games_changeNews																												*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function games_changeNews ()
{
	if (!autoChange) return;

	var count = document.getElementById("newsCount").innerHTML * 1;

	if (currNews == count)
		currNews = 1;
	else
		currNews++;
	
	$("#topOneNews_title").fadeOut ("slow", function() { games_completeShowAfterFadeOut();});
}

function games_completeShowAfterFadeOut ()
{
	var theId 	 = document.getElementById("newsId" + currNews).innerHTML;
	var theTitle = document.getElementById("newsTitle" + currNews).innerHTML;

	document.getElementById("topOneNews_title").innerHTML = "<a href='news" + theId + ".html'>" + theTitle + "</a>";

	$("#topOneNews_title").fadeIn (1000);
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* games_nextNews																												*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function games_nextNews ()
{
	clearInterval (newsInterval)

	autoChange = false;

	var count = document.getElementById("newsCount").innerHTML * 1;

	if (currNews == count)
		currNews = 1;
	else
		currNews++;

	$("#topOneNews_title").fadeOut ("slow", function() { games_completeShowAfterFadeOut();});
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* games_prevNews																												*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function games_prevNews ()
{
	clearInterval (newsInterval)
	autoChange = false;

	var count = document.getElementById("newsCount").innerHTML * 1;

	if (currNews == 1)
		currNews = count;
	else
		currNews--;

	$("#topOneNews_title").fadeOut ("slow", function() { games_completeShowAfterFadeOut();});
}

var downloadsFilterSep		= "#";

var downloadsFilter_plat	= "";
var downloadsFilter_ganer	= "";
var downloadsFilter_price	= "";
var downloadsFilter_shop	= "";

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* games_showDownloadsFilter																									*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function games_showDownloadsFilter ()
{
	$("filterClose").style.display 		= "none";
	$("filterOpen").style.display  		= "";
	$("filterCloseBtn").style.display  	= "";
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* games_hideDownloadsFilter																									*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function games_hideDownloadsFilter ()
{
	$("filterOpen").style.display  		= "none";
	$("filterCloseBtn").style.display  	= "none";
	$("filterClose").style.display 		= "";
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* games_chooseDownloadOption																									*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function games_chooseDownloadOption (which, count)
{
	var oOption = $(which + count);

	var toRedraw = false;

	if (oOption.className == "v")
	{
		oOption.className 	= "x";
		toRedraw			= true;
	}
	else if (oOption.className == "x")
	{
		oOption.className 	= "v";
		toRedraw			= true;
	}
	else if (oOption.className == "v0")
	{
		oOption.className 	= "x0";
		toRedraw			= true;
	}

	if (toRedraw)
		games_redrawDownloadFilter ($("currTab").innerHTML);
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* games_redrawDownloadFilter																									*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function games_redrawDownloadFilter (tab)
{
	var plat 	= downloadsFilterSep + games_getDownloadOptionsOf("plat");
	var ganer 	= downloadsFilterSep + games_getDownloadOptionsOf("ganer");
	var price	= downloadsFilterSep + games_getDownloadOptionsOf("price");
	var shop	= downloadsFilterSep + games_getDownloadOptionsOf("shop");

  	xml = "<data>" +
				"<command>privateDownloads.getDownloadsFilter</command>" 	+
				"<tab>"		+ 	tab		+	"</tab>"		+
				"<plat>"	+	plat	+	"</plat>"		+
				"<ganer>"	+	ganer	+	"</ganer>"		+
				"<price>"	+	price	+	"</price>"		+
				"<shop>"	+	shop	+	"</shop>"		+
		 "</data>";
	xmlRequest.init (xml);
	xmlRequest.sendAsyncRequest ("server.php", xmlRequest.obj, "games_doRedrawDownloadFilter");

}

function games_doRedrawDownloadFilter (i)
{
	xmlRequest.init(commonDecode(asyncHttpObjs[i].responseText));
	
	try
	{
		var filterTitleHtml = xmlRequest.getValue("filterTitle");
		var filterHtml 		= xmlRequest.getValue("filter");

//		$("filterTitle").innerHTML = filterTitleHtml;
		$("filterOpen").innerHTML  = filterHtml;
	}
	catch (e)
	{
	}
}

function games_getDownloadOptionsOf (which)
{
	var options = "";
	var count 	= 1;
	var oOption = $(which + count);

	while (oOption != undefined)
	{
		if (oOption.className == "v" || oOption.className == "v0")
		{
			options += $(which + "Id" + count).innerHTML + downloadsFilterSep;
		}

		count++;
		oOption = $(which + count);
	}
	
	return options;
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* games_showDownloadsMoreOptions																								*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function games_showDownloadsMoreOptions (which)
{
	$(which + "MoreOptionsLink").style.display 	= "none";
	$(which + "MoreOptions").style.display 		= "";
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* games_resetDownloadsFilter																									*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function games_resetDownloadsFilter ()
{
  	xml = "<data>" +
				"<command>privateDownloads.getDownloadsFilter</command>" 	+
				"<tab>"				+ 	$("currTab").innerHTML				+	"</tab>"		+
				"<plat></plat>"		+
				"<ganer></ganer>"	+
				"<price></price>"	+
				"<shop></shop>"		+
		 "</data>";
	xmlRequest.init (xml);
	xmlRequest.sendAsyncRequest ("server.php", xmlRequest.obj, "games_doRedrawDownloadFilter");
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* games_updateDownloadsFilter																									*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function games_updateDownloadsFilter ()
{
	games_hideDownloadsFilter ();

	downloadsFilter_plat 	= downloadsFilterSep + games_getDownloadOptionsOf("plat");
	downloadsFilter_ganer 	= downloadsFilterSep + games_getDownloadOptionsOf("ganer");
	downloadsFilter_price	= downloadsFilterSep + games_getDownloadOptionsOf("price");
	downloadsFilter_shop	= downloadsFilterSep + games_getDownloadOptionsOf("shop");

	games_selectDownloads ($("currTab").innerHTML);
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* games_cancelDownloadsFilter																									*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function games_cancelDownloadsFilter ()
{
	downloadsFilter_plat	= "";
	downloadsFilter_ganer	= "";
	downloadsFilter_price	= "";
	downloadsFilter_shop	= "";
	
  	xml = "<data>" +
				"<command>privateDownloads.getDownloads</command>" 	+
				"<pageNumber>1</pageNumber>"			+
				"<tab>"				+ 	$("currTab").innerHTML	+	"</tab>"		+
				"<plat></plat>"		+
				"<ganer></ganer>"	+
				"<price></price>"	+
				"<shop></shop>"		+
		 "</data>";
	xmlRequest.init (xml);
	xmlRequest.sendAsyncRequest ("server.php", xmlRequest.obj, "games_loadDownloads");
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* games_downloadsGoPage																										*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function games_downloadsGoPage (gotoPage)
{
  	xml = "<data>" +
				"<command>privateDownloads.getDownloads</command>" 	+
				"<pageNumber>"	+	gotoPage				+ 	"</pageNumber>"	+
				"<tab>"			+ 	$("currTab").innerHTML	+	"</tab>"		+
				"<plat>"		+	downloadsFilter_plat	+	"</plat>"		+
				"<ganer>"		+	downloadsFilter_ganer	+	"</ganer>"		+
				"<price>"		+	downloadsFilter_price	+	"</price>"		+
				"<shop>"		+	downloadsFilter_shop	+	"</shop>"		+
		 "</data>";
	xmlRequest.init (xml);
	xmlRequest.sendAsyncRequest ("server.php", xmlRequest.obj, "games_loadDownloads");
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* games_selectDownloads																										*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function games_selectDownloads (tab)
{
  	xml = "<data>" +
				"<command>privateDownloads.getDownloads</command>" 	+
				"<pageNumber>1</pageNumber>"			+
				"<tab>"		+ 	tab						+	"</tab>"		+
				"<plat>"	+	downloadsFilter_plat	+	"</plat>"		+
				"<ganer>"	+	downloadsFilter_ganer	+	"</ganer>"		+
				"<price>"	+	downloadsFilter_price	+	"</price>"		+
				"<shop>"	+	downloadsFilter_shop	+	"</shop>"		+
		 "</data>";
	xmlRequest.init (xml);
	xmlRequest.sendAsyncRequest ("server.php", xmlRequest.obj, "games_loadDownloads");
}

function games_loadDownloads (i)
{
	xmlRequest.init(commonDecode(asyncHttpObjs[i].responseText));
	
	try
	{
		var filterTitleHtml = xmlRequest.getValue("filterTitle");
		var filterHtml 		= xmlRequest.getValue("filter");
		var pageNumber 		= xmlRequest.getValue("pageNumber");
		var prevPage 		= xmlRequest.getValue("prevPage");

		$("filterTitle").innerHTML = filterTitleHtml;
		$("filterOpen").innerHTML  = filterHtml;

		var games1Html 	= xmlRequest.getValue("games1");
		var games2Html 	= xmlRequest.getValue("games2");
		var tab 	 	= xmlRequest.getValue("tab");

		for (var i = 1; i <= 5; i++)
		{
			if (tab == i)
				$("downloadsTab" + i).className = "downloadTab_selected";
			else
				$("downloadsTab" + i).className = "downloadTab";
		}

		if (pageNumber == 1)
		{
			$("tabContent1").innerHTML = games1Html;
			$("tabContent2").innerHTML = games2Html;
		}
		else
		{
			$("downloadsGoNextPage" + prevPage).style.display = "none";
			$("tabContent2").innerHTML += games1Html + games2Html;
		}

		$("currTab").innerHTML	   = tab;
	}
	catch (e)
	{
	}
}

var saveEvent;

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* games_openDownloadsNoticeRegister																							*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function games_openDownloadsNoticeRegister (gameId, gameName, e)
{
	saveEvent = e;

	var oForm = document.getElementById("noticeRegisterForm");

	oForm.gameId.value = gameId;

	document.getElementById("downloadPopupGameName1").innerHTML = gameName;
	document.getElementById("downloadPopupGameName2").innerHTML = gameName;

	point_it("downloadsNoticeRegister_popupBorder","downloadsNoticeRegister_popup","alertRegisterForm", saveEvent);
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* games_submitDownloadsNoticeRegister																							*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function games_submitDownloadsNoticeRegister ()
{
	var oForm = document.getElementById("noticeRegisterForm");

	var theEmail = "";
	if (oForm.email != undefined)
	{
		theEmail = oForm.email.value;

		if (theEmail == "")
		{
			alert ("יש להזין דואר אלקטרוני");
			return false;
		}

		if (!validateEmailv2 (theEmail))
		{
			alert ("יש להזין דואר אלקטרוני חוקי");
			return false;
		}
	}

	games_downloadsNoticeAdd (saveEvent, oForm.gameId.value, "", oForm.email.value);

}

function games_downloadsNoticeAdd (e, gameId, gameName, theEmail)
{
	if (theEmail == undefined)
	{
		document.getElementById("downloadPopupGameName1").innerHTML = gameName;
		document.getElementById("downloadPopupGameName2").innerHTML = gameName;

		theEmail = "";
	}

	saveEvent = e;

  	xml = "<data>" +
				"<command>privateDownloads.addDownloadNotice</command>" 		+
				"<email>"		+	theEmail	+	"</email>"		+
				"<gameId>"		+	gameId		+	"</gameId>"		+
		 "</data>";
	xmlRequest.init (xml);
	xmlRequest.sendAsyncRequest ("server.php", xmlRequest.obj, "games_afterAddDownloadNotice");

	return false;
}

function games_afterAddDownloadNotice (i)
{
	xmlRequest.init(commonDecode(asyncHttpObjs[i].responseText));
	
	try
	{
		var returnCode 	= xmlRequest.getValue("returnCode");
		var memberId 	= xmlRequest.getValue("memberId");
		var gameId	 	= xmlRequest.getValue("gameId");

		if (returnCode == "OK")
		{
			if (memberId == 0)
			{
				closePopup ("downloadsNoticeRegister_popupBorder", "downloadsNoticeRegister_popup");
			}
			else
			{
				document.getElementById("downloadsNoticeAdd_game"    + gameId).style.display = "none";
				document.getElementById("downloadsNoticeCancel_game" + gameId).style.display = "";
			}

			point_it   ("downloadsNoticeOk_popupBorder", "downloadsNoticeOk_popup", "", saveEvent)
		}
		else if (returnCode == "MISSING_EMAIL")
		{
			alert ("יש להזין דואר אלקטרוני");
		}
	}
	catch (e)
	{
	}
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* games_submitDownloadsNoticeCancel																							*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function games_submitDownloadsNoticeCancel ()
{
	var oForm = document.getElementById("noticeRegisterForm");

	var theEmail = "";
	if (oForm.email != undefined)
	{
		theEmail = oForm.email.value;

		if (theEmail == "")
		{
			alert ("יש להזין דואר אלקטרוני");
			return false;
		}

		if (!validateEmailv2 (theEmail))
		{
			alert ("יש להזין דואר אלקטרוני חוקי");
			return false;
		}
	}

	games_downloadsNoticeCancel (saveEvent, oForm.gameId.value, oForm.email.value);
}

function games_downloadsNoticeCancel (e, gameId, theEmail)
{
	if (theEmail == undefined)
		theEmail = "";

	saveEvent = e;

  	xml = "<data>" +
				"<command>privateDownloads.cancelDownloadNotice</command>"	+
				"<email>"		+	theEmail	+	"</email>"		+
				"<gameId>"		+	gameId		+	"</gameId>"		+
		 "</data>";
	xmlRequest.init (xml);
	xmlRequest.sendAsyncRequest ("server.php", xmlRequest.obj, "games_afterCancelDownloadNotice");

	return false;
}

function games_afterCancelDownloadNotice (i)
{
	xmlRequest.init(commonDecode(asyncHttpObjs[i].responseText));
	
	try
	{
		var returnCode 	= xmlRequest.getValue("returnCode");
		var memberId 	= xmlRequest.getValue("memberId");
		var gameId	 	= xmlRequest.getValue("gameId");

		if (returnCode == "OK")
		{
			if (memberId == 0)
			{
				closePopup ("downloadsNoticeRegister_popupBorder", "downloadsNoticeRegister_popup");
			}
			else
			{
				document.getElementById("downloadsNoticeAdd_game"    + gameId).style.display = "";
				document.getElementById("downloadsNoticeCancel_game" + gameId).style.display = "none";
			}

			point_it   ("downloadsNoticeDelete_popupBorder", "downloadsNoticeDelete_popup", "", saveEvent)
		}
	}
	catch (e)
	{
	}
}

var firstSelectGameTab = true;

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* games_selectGamePageTab																										*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function games_selectGamePageTab (tab, gameId)
{
	if (firstSelectGameTab)
	{
		// save tab 1 content
		firstSelectGameTab = false;

		$("gamePageTabContent1").innerHTML = $("gamePageTabContent_in").innerHTML;
	}

	if ($("gamePageTabContent" + tab).innerHTML == "")
	{
	  	xml = "<data>" +
					"<command>privateGamePage.getGameTab</command>" 	+
					"<tab>"		+ 	tab						+	"</tab>"		+
					"<gameId>"	+ 	gameId					+	"</gameId>"		+
			 "</data>";
		xmlRequest.init (xml);
		xmlRequest.sendAsyncRequest ("server.php", xmlRequest.obj, "games_loadGamePageTab");
	}
	else
	{
		games_changeGamePageTab (tab);
	}
}

function games_loadGamePageTab (i)
{
	xmlRequest.init(commonDecode(asyncHttpObjs[i].responseText));
	
	try
	{
		var tab		= xmlRequest.getValue("tab");
		var gameTab	= xmlRequest.getValue("gameTab");

		$("gamePageTabContent" + tab).innerHTML = gameTab;

		games_changeGamePageTab (tab);
	}
	catch (e)
	{
	}
}

function games_changeGamePageTab (tab)
{
	for (var i = 1; i <= 5; i++)
	{
		if (tab == i)
			$("gamePageTab" + i).className = "gamePageTab_selected";
		else
			$("gamePageTab" + i).className = "gamePageTab";
	}

	$("gamePageTabContent_in").innerHTML = $("gamePageTabContent" + tab).innerHTML;
}


/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* addMivzak																									                */
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function addMivzak ()
{
	tinyMCE.triggerSave();

	var oForm 		= document.getElementById("addMivzakForm");

	var title 		= oForm.title.value;
	var txt 		= oForm.mivzakTxt.value;
	var keywords 	= oForm.keywords.value;
	var extraData1 	= oForm.extraData1.value;
	var extraData3 	= oForm.extraData3.value;

	if (title == "")
	{
		alert("יש להזין כותרת למבזק");
		return;
	}

	if (txt == "")
	{
		alert("יש להזין את תוכן המבזק");
		return;
	}

	xml = "<data>" +
			"<command>private.addEssays</command>" +
			"<formType>mivzak</formType>" +
			"<title><![CDATA["+title+"]]></title>" +
			"<keywords><![CDATA["+keywords+"]]></keywords>" +
			"<extraData1><![CDATA["+extraData1+"]]></extraData1>" +
			"<extraData3><![CDATA["+extraData3+"]]></extraData3>" +
			"<txt><![CDATA["+txt+"]]></txt>" +
		 "</data>";

	xmlRequest.init (xml);
	xmlRequest.sendAsyncRequest ("server.php", xmlRequest.obj, "afterAddMivzak");	
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* afterAddMivzak				     																			                */
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function afterAddMivzak (i)
{
	xmlRequest.init(commonDecode(asyncHttpObjs[i].responseText));
	
	try
	{
		var returnValue = xmlRequest.getValue("success");
		if (returnValue == "ok")
		{		
			window.location = "/index2.php?id=13";
		}
	}
	catch (e)
	{
	}
}

