// overwrite alert function
window.alert = function(str) 
{
 	abiloko_showPopupMsg ("הודעת מערכת", str);
}
 
/* ------------------------------------------------------------------------------------------------------------	*/
/* abiloko_showPopupMsg																							*/
/* ------------------------------------------------------------------------------------------------------------	*/
function abiloko_showPopupMsg (title, msg)
{
	if (document.getElementById("popupMsg_popupTitle"))
		document.getElementById("popupMsg_popupTitle").innerHTML = title;
	if (document.getElementById("popupMsg_popupText"))
		document.getElementById("popupMsg_popupText").innerHTML = msg;

	abiliko_openPopup ("popupMsg");
}

var doAfterClose = "";

/* ------------------------------------------------------------------------------------------------------------	*/
/* abiliko_showMsgBeforeAction																					*/
/* ------------------------------------------------------------------------------------------------------------	*/
function abiliko_showMsgBeforeAction (title, msg, onClose)
{
	doAfterClose = onClose;

	abiloko_showPopupMsg (title, msg);
	
}

var xmlRequest = new xmlObj(false);

var lastErrorField = null;

/* ------------------------------------------------------------------------------------------------------------	*/
/* abiloko_submitUserRegistrationForm																			*/
/* ------------------------------------------------------------------------------------------------------------	*/
function abiloko_submitUserRegistrationForm ()
{
		var f = document.getElementById('userRegistrationForm');
		var formValidator = new Validator('userRegistrationForm');

		formValidator.clearAllValidations ();
	
		formValidator.addValidation('firstname',		'required',		'יש להזין שם פרטי');
		formValidator.addValidation('lastname',			'required',		'יש להזין שם משפחה');
		formValidator.addValidation('nickname',			'required',		'יש להזין כינוי');
		formValidator.addValidation('email',			'required',		'יש להזין דואר אלקטרוני');
		formValidator.addValidation('email',			'email',		'יש להזין דואר אלקטרוני חוקי');
		if (f.updating.value != "1" || f.password.value != "")
		{
			formValidator.addValidation('password',			'required',		'יש להזין סיסמא');
			formValidator.addValidation('password',			'minlen=4',		'יש להזין סיסמא בת 4 תווים לפחות');
			formValidator.addValidation('cNewPassword',		'required',		'יש להזין את אימות הסיסמא');
		}
		formValidator.addValidation('userRegistrationForm_verification','required', 'יש להזין את האותיות שבתמונה');
		if (f.memberType_web2.value == "2" || f.memberType_web2.value == "3")
		{
			formValidator.addValidation('about',			'required',		'יש להזין תיאור');
		//	formValidator.addValidation('about',			'minlen=120',	'יש להזין תיאור של לפחות 120 תווים');
		}

		if (formValidator.validate ())
		{
			lastErrorField = null;

				// few more tests
				var checkCount = 0;
				for (var i = 0; i < f.elements.length; i++)
				{
					if (f.elements[i].type == "checkbox" && f.elements[i].name != "agree" && f.elements[i].name != "mailingList8" && f.elements[i].checked)
					{
						checkCount++;
					}
				}
				/* Not necessary anymore since Businesses can register as Organizations
				if (checkCount == 0 && f.memberType_web2.value != 4)
				{
						alert('יש לבחור לפחות תחום התמחות/התעניינות אחד');
						lastErrorField = document.getElementById("expertise1");
						return;
				}
				*/
				if (f.password.value != f.cNewPassword.value)
				{
						alert('אימות הסיסמא אינו זהה לסיסמא');
						lastErrorField = document.getElementById("cNewPassword");
						return;
				}
				if (f.updating.value != "1" && !f.agree.checked)
				{
						alert('חובה לאשר את הסכמתך לתקנון');
						lastErrorField = document.getElementById("agree");
						return;
				}
				abiliko_gotoCheckRegistrationFormOnServer("abiloko_answerUserRegistrationForm");
		}
		else
		{
			lastErrorField = formValidator.getLastErrorField ();
		}

		return false;
}

/* ------------------------------------------------------------------------------------------------------------	*/
/* abiliko_gotoCheckRegistrationFormOnServer																	*/
/* ------------------------------------------------------------------------------------------------------------	*/
function abiliko_gotoCheckRegistrationFormOnServer(funcName)
{
		var f = document.getElementById('userRegistrationForm');
		// server-side tests
		xml = "<data>"	+
				"<command>privateValidate.checkRegisterFormFields</command>"	+
				"<memberId>"+ f.memberId.value	+ "</memberId>"	+
				"<email>"	+ f.email.value		+ "</email>"	+
				"<nickname>"+ f.nickname.value	+ "</nickname>"	+
			  "</data>";
		xmlRequest.init (xml);
		xmlRequest.sendAsyncRequest ("server.php", xmlRequest.obj, funcName);
}

/* ------------------------------------------------------------------------------------------------------------	*/
/* abiliko_answerRegistrationFormOnServer																		*/
/* ------------------------------------------------------------------------------------------------------------	*/
function abiliko_answerRegistrationFormOnServer(i)
{
	xmlRequest.init(commonDecode(asyncHttpObjs[i].responseText));
	retCode = xmlRequest.getValue("returnCode");

	var f = document.getElementById('userRegistrationForm');
	document.getElementById('checkUsername').innerHTML = '';
	document.getElementById('checkNickname').innerHTML = '';
	document.getElementById('checkEmail').innerHTML = '';
	if (retCode == "email_dns_not_valid")
	{
		document.getElementById('checkEmail').innerHTML = 'כתובת האימייל לא נכונה';
		lastErrorField = document.getElementById("email");
		return false;
	}
	if (retCode == "nickname_not_unique")
	{
		document.getElementById('checkNickname').innerHTML = 'הכינוי תפוס';
		lastErrorField = document.getElementById("nickname");
		return false;
	}
	if (retCode == "email_not_unique")
	{
		document.getElementById('checkEmail').innerHTML = 'כתובת האימייל תפוסה';
		lastErrorField = document.getElementById("email");
		return false;
	}
	return true;
}

/* ------------------------------------------------------------------------------------------------------------	*/
/* abiloko_answerUserRegistrationForm																			*/
/* ------------------------------------------------------------------------------------------------------------	*/
function abiloko_answerUserRegistrationForm(i)
{
	if (abiliko_answerRegistrationFormOnServer(i) == true)
		verification_check("userRegistrationForm","HEB"); // if ok this function submits the form
}

/* ------------------------------------------------------------------------------------------------------------	*/
/* abiliko_submitSendQuestionForm																				*/
/* ------------------------------------------------------------------------------------------------------------	*/
function abiliko_submitSendQuestionForm ()
{
		var f = document.getElementById('sendQuestionForm');
		var formValidator = new Validator('sendQuestionForm');

		formValidator.clearAllValidations ();
	
		formValidator.addValidation('question',		'required',		'יש להזין כותרת לשאלה');
		formValidator.addValidation('question',		'maxlen=140',	'אורך הכותרת צריך להיות עד 140 תווים');

		if (formValidator.validate ())
		{
			lastErrorField = null;

				var checkCount = 0;

				for (var i = 0; i < f.elements.length; i++)
				{
					if (f.elements[i].type == "checkbox" && f.elements[i].checked)
					{
						checkCount++;
					}
				}

				if (checkCount == 0)
				{
						alert('יש לבחור לפחות קהילה אחת');
						lastErrorField = document.getElementById("expertise1");
						return;
				}

				abiliko_showMsgBeforeAction ("השאלה נקלטה בהצלחה",
				"תודה שפנית למומחים של abiliko . מערכת abiliko פועלת על מנת לתת לך את המענה הטוב ביותר לשאלתך. הודעה תישלח לתיבת הדואר הפנימית שלך באתר.",
				"document.getElementById('sendQuestionForm').submit()");
		}
		else
		{
			lastErrorField = formValidator.getLastErrorField ();
		}
		return false;
}

/* ------------------------------------------------------------------------------------------------------------	*/
/* abiliko_showLogin																							*/
/* ------------------------------------------------------------------------------------------------------------	*/
function abiliko_showLogin()
{
	abiliko_closePopup ("sendPassForm");
	abiliko_openPopup  ("loginForm");
/*		document.getElementById('topRegisterBtn').style.display = "none";
		document.getElementById('topRegisteredLink').style.display = "none";
		document.getElementById('topRegistrationForm').style.display = "";
		document.getElementById('topRemindForm').style.display = "none";*/
}

/* ------------------------------------------------------------------------------------------------------------	*/
/* abiliko_submitLoginForm																						*/
/* ------------------------------------------------------------------------------------------------------------	*/
function abiliko_submitLoginForm ()
{
	var formValidator = new Validator("loginFrm");

	formValidator.clearAllValidations ();
	
	formValidator.addValidation("username",			"required",		"יש להזין כתובת מייל");
	formValidator.addValidation("username",			"email",		"יש להזין כתובת מייל חוקית");
	formValidator.addValidation("password",			"required",		"יש להזין סיסמא");

	if (formValidator.validate ())
	{
		lastErrorField = null;

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

		var xml	= "<data>" +
						"<command>private.validateBeforeLogin</command>" 			+
						"<username>" + oForm.username.value 		+ "</username>" +
						"<password>" + oForm.password.value 		+ "</password>" +
				  "</data>";

		xmlRequest.init (xml);
		xmlRequest.sendAsyncRequest ("server.php", xmlRequest.obj, "abiliko_validateBeforeLogin_response");
	}
	else
	{
		lastErrorField = formValidator.getLastErrorField ();
	}

	return false;
}

function abiliko_validateBeforeLogin_response (i)
{
	xmlRequest.init(commonDecode(asyncHttpObjs[i].responseText));

	try
	{
		var returnCode = xmlRequest.getValue("returnCode");
		var goToPage   = xmlRequest.getValue("goToPage");

		if (returnCode == "OK")
		{
			var oForm		 = document.getElementById("loginFrm");

			abiliko_closePopup ("loginForm")

			// [7/6/2010] Amir Natan finally decieded not to change the page after login		
			//oForm.afterLoginPageId.value = goToPage;

			oForm.submit ();
		}
		else if (returnCode == "WRONG_LOGIN")
		{
			alert ("כתובת המייל או הסיסמא שגויים");
		}
	}
	catch (e)
	{
	}

	return false;
}


//
//document.getElementById(\"loginFrm\").submit()

/* ------------------------------------------------------------------------------------------------------------	*/
/* abiliko_showRemind																							*/
/* ------------------------------------------------------------------------------------------------------------	*/
function abiliko_showRemind()
{
	abiliko_closePopup ("loginForm");
	abiliko_openPopup ("sendPassForm");

/*		document.getElementById('topRegisterBtn').style.display = "none";
		document.getElementById('topRegisteredLink').style.display = "none";
		document.getElementById('topRegistrationForm').style.display = "none";
		document.getElementById('topRemindForm').style.display = "";*/
}

/* ------------------------------------------------------------------------------------------------------------	*/
/* abiloko_addAmutaToUserRequest																				*/
/* ------------------------------------------------------------------------------------------------------------	*/
function abiloko_addAmutaToUserRequest ()
{
		var f = document.getElementById('userRegistrationForm');

		if (f.email.value == '')
		{
				alert("עליך למלא תחילה את כתובת המייל");
				return;
		}
		if (f.firstname.value == '')
		{
				alert("עליך למלא תחילה את השם הפרטי");
				return;
		}
		if (f.lastname.value == '')
		{
				alert("עליך למלא תחילה את שם המשפחה");
				return;
		}
		if (f.chooseAmuta.options[f.chooseAmuta.selectedIndex].id == '')
		{
				alert("עליך לבחור את אחד הארגונים מהרשימה");
				return;
		}
		alert("בקשתך נשלחה למשתמש הראשי של הארגון");

		xml = "<data>"	+
				"<command>private.addAmutaToUserRequest</command>"	+
				"<email>"+ f.email.value	+ "</email>"	+
				"<firstname>"+ f.firstname.value	+ "</firstname>"	+
				"<lastname>"+ f.lastname.value	+ "</lastname>"	+
				"<amutaId>"+ f.chooseAmuta.options[f.chooseAmuta.selectedIndex].id	+ "</amutaId>"	+
				"<amutaName>"+ f.chooseAmuta.options[f.chooseAmuta.selectedIndex].value	+ "</amutaName>"	+
			  "</data>";
		xmlRequest.init (xml);
		xmlRequest.sendAsyncRequest ("server.php", xmlRequest.obj, '');
}

/* ------------------------------------------------------------------------------------------------------------	*/
/* abiloko_checkAlphanumericUsername																			*/
/* ------------------------------------------------------------------------------------------------------------	*/
function abiloko_checkAlphanumericUsername (fld)
{
		var spn=document.getElementById("checkUsername");
		if (fld.value.search(/^[a-zA-Z0-9]*$/) == -1)
			spn.innerHTML = "תו לא חוקי";
		else
			spn.innerHTML = " ";
}

/* ------------------------------------------------------------------------------------------------------------	*/
/* abiliko_showAmutaBranches																					*/
/* ------------------------------------------------------------------------------------------------------------	*/
function abiliko_refreshAmutaBranches()
{
		var f = document.getElementById('userRegistrationForm');
		var allBranchesArea = document.getElementById("allBranchesArea");
		if (allBranchesArea == undefined)
				return;
		var allBranches = f.amutaBranches.value.replace(/^@@|@@$/g,"").split("@@");
		var allDivs = '';

		if (allBranches != "")
			for (var i in allBranches)
		   	{
				var city = allBranches[i].split("|");
				allDivs += "<div><a href='' onclick='abiliko_updateAmutaBranch("+ city[0] + ");return false'>הסר/עדכן</a> &nbsp; " +
						   f.cityId.options[city[0]].innerHTML + "</div>";
			}
		
		allBranchesArea.innerHTML = allDivs;
}

/* ------------------------------------------------------------------------------------------------------------	*/
/* abiliko_addAmutaBranch																						*/
/* ------------------------------------------------------------------------------------------------------------	*/
function abiliko_addAmutaBranch()
{
		var f = document.getElementById('userRegistrationForm');
		var cityId = f.cityId.options[f.cityId.selectedIndex].value;
		var cityName = f.cityId.options[f.cityId.selectedIndex].innerHTML;

		if (cityName == '')
		{
				alert("עליך לבחור יישוב מהרשימה");
				lastErrorField = document.getElementById("cityId");
				return;
		}
		
		var newCity = cityId + "|" + f.managerName.value + "|" + f.branchPhone.value + "|" + f.street.value+ "|" + f.no.value + "@@";
		if (f.amutaBranches.value == '')
			f.amutaBranches.value = "@@" + newCity;
		else
		{
				var startPos = 0;
				var currentId = -1;
				while (currentId < cityId)
				{
					startPos = f.amutaBranches.value.indexOf("@@", startPos) + 2;
					endPos = f.amutaBranches.value.indexOf("|", startPos);
					if (endPos == -1)
							break;
					currentId = f.amutaBranches.value.substring(startPos, endPos) * 1;
				}
				f.amutaBranches.value = f.amutaBranches.value.substring(0,startPos) + newCity + f.amutaBranches.value.substring(startPos);
		}

		f.cityId.selectedIndex = 0;
		f.managerName.value = '';
		f.branchPhone.value = '';
		f.street.value = '';
		f.no.value = '';

		abiliko_refreshAmutaBranches();
}

/* ------------------------------------------------------------------------------------------------------------	*/
/* abiliko_removeAmutaBranch																					*/
/* ------------------------------------------------------------------------------------------------------------	*/
function abiliko_removeAmutaBranch(cityId)
{
		var f = document.getElementById('userRegistrationForm');

		var startPos = f.amutaBranches.value.indexOf("@@" + cityId);
		if (startPos == -1)
				return;
		var endPos = f.amutaBranches.value.indexOf("@@", startPos + 1);

		f.amutaBranches.value = f.amutaBranches.value.substring(0,startPos) + f.amutaBranches.value.substring(endPos);

		abiliko_refreshAmutaBranches();
}

/* ------------------------------------------------------------------------------------------------------------	*/
/* abiliko_updateAmutaBranch																					*/
/* ------------------------------------------------------------------------------------------------------------	*/
function abiliko_updateAmutaBranch(cityId)
{
		var f = document.getElementById('userRegistrationForm');

		var startPos = f.amutaBranches.value.indexOf("@@" + cityId);
		if (startPos == -1)
				return;
		var endPos = f.amutaBranches.value.indexOf("@@", startPos + 1);

		var branch = f.amutaBranches.value.substring(startPos+2, endPos).split("|");

		f.cityId.selectedIndex = branch[0];
		f.managerName.value = branch[1];
		f.branchPhone.value = branch[2];
		f.street.value = branch[3];
		f.no.value = branch[4];

		abiliko_removeAmutaBranch(cityId);
}

/* ------------------------------------------------------------------------------------------------------------	*/
/* abiliko_indexFilter																							*/
/* ------------------------------------------------------------------------------------------------------------	*/
function abiliko_indexFilter(kind)
{
		commonSetCookie('indexFilterKind', kind);
		window.location.reload();
}

/* ------------------------------------------------------------------------------------------------------------	*/
/* abiliko_indexSelectLetter																					*/
/* ------------------------------------------------------------------------------------------------------------	*/
function abiliko_indexSelectLetter (letter)
{
		commonSetCookie("indexFilterLetter", letter);
		window.location.href = "index2.php?id=26";
}

/* ------------------------------------------------------------------------------------------------------------	*/
/* abiliko_submitIndexFilterForm																				*/
/* ------------------------------------------------------------------------------------------------------------	*/
function abiliko_submitIndexFilterForm ()
{
	var oForm = document.getElementById("indexFilterForm");

	commonSetCookie("catId", 	  oForm.catId.value);
	commonSetCookie("indexCatId", oForm.indexCatId.value);

	window.location.href = "index2.php?id=26";
}


/* -------------------------------------------------------------------------------------------------------------------- */
/* abiliko_selectProfileTab																								*/
/* -------------------------------------------------------------------------------------------------------------------- */
function abiliko_selectProfileTab (tab)
{
	if (currProfileTab != tab &&
		document.getElementById("profileTab" + tab).className.indexOf("disabled") == -1)
	{
		document.getElementById("profileTab" + currProfileTab).className = "tabTd";
		document.getElementById("contentOfProfileTab" + currProfileTab).style.display = "none";

		currProfileTab = tab;

		document.getElementById("profileTab" + currProfileTab).className = "tabTd_selected";
		document.getElementById("contentOfProfileTab" + currProfileTab).style.display = "";
	}
}

var currOpenPopup = null;
var currFader	  = 0;

/* -------------------------------------------------------------------------------------------------------------------- */
/* abiliko_openPopup																									*/
/* -------------------------------------------------------------------------------------------------------------------- */
function abiliko_openPopup (popupId)
{
	if (document.getElementById(popupId) != undefined)
	{
		oPopup = document.getElementById(popupId);

		if (oPopup.style.display != "block")	// not already opened
		{
			currFader++;

			oFader = document.getElementById("fader" + currFader);

			if (oFader != undefined)
			{
				oFader.style.height = document.documentElement.scrollHeight + "px";
				oFader.style.width = "100%";
				oFader.style.display = "";
			}

			delta		= 170;
			posY		= ((window.pageYOffset) ? window.pageYOffset + delta : document.documentElement.scrollTop + document.body.scrollTop + delta);

			popupWidth = 450;

			oPopup.style.top 		= posY + "px";
			oPopup.style.right 		= (screen.availWidth-popupWidth)/2 + "px"; 
			oPopup.style.zIndex		= currFader*20;

			oPopup.style.display	= "block";	

			var iFrameTag 				= document.getElementById("blocker");

			if (iFrameTag != undefined) // && iFrameTag.style.visibility == "hidden")
			{
				iFrameTag.style.right    	= oPopup.style.right;
				iFrameTag.style.top     	= oPopup.style.top;
				iFrameTag.style.width   	= popupWidth+"px";
				iFrameTag.style.height  	= oPopup.offsetHeight + "px";
				iFrameTag.style.zIndex		= currFader*20 - 1
				iFrameTag.style.visibility  = "visible";
			}
		}
	}
}

/* -------------------------------------------------------------------------------------------------------------------- */
/* abiliko_closePopup																									*/
/* -------------------------------------------------------------------------------------------------------------------- */
function abiliko_closePopup (popupId, toReload)
{
	if (popupId == undefined) popupId = currOpenPopup;

	oFader = document.getElementById("fader" + currFader);

	if (oFader != undefined)
		oFader.style.display = "none";

	if (currFader > 0)
		currFader--;

	document.getElementById(popupId).style.display = "none";

	if (document.getElementById("blocker") != undefined && document.getElementById("fader1").style.display == "none")
		document.getElementById("blocker").style.visibility  = "hidden";

	if (toReload)
		window.location.reload();

	if (doAfterClose != "")
	{
		setTimeout (doAfterClose, 0);
		doAfterClose = "";
	}

	if (lastErrorField != null)
	{
		lastErrorField.focus ();
		lastErrorField = null;
	}

}

/* --------------------------------------------------------------------------------------------------------------------	*/
/* abiliko_startListenToMember																							*/
/* --------------------------------------------------------------------------------------------------------------------	*/
function abiliko_startListenToMember(withMember)
{
	var xml = "<data>" +	
					"<command>private.startListen</command>"		+
					"<withMember>"		+ withMember				+ "</withMember>" 		+
			  "</data>";

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

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

	try
	{
		var returnCode = xmlRequest.getValue("returnCode");
		var nickname = xmlRequest.getValue("nickname");

		if (returnCode == "OK")
		{
			abiliko_showMsgBeforeAction ("הוספת חבר", nickname + " הוסף לרשימת האנשים להם אתה מקשיב", "window.location.href += \"&profileTab=6\"");
		}
		else if (returnCode == "NOT_LOGIN")
		{
			alert("עליך להתחבר לאתר תחילה כדי להקשיב");
		}
		else if (returnCode == "ALREADY_LISTENING")
		{
				alert("הינך כבר מקשיב לחבר זה");
		}
		else if (returnCode == "NOT_SUCH_MEMBER")
		{
				alert("חבר זה לא קיים");
		}
	}
	catch (e)
	{
	}
}

/* --------------------------------------------------------------------------------------------------------------------	*/
/* abiliko_stopListenToMember																							*/
/* --------------------------------------------------------------------------------------------------------------------	*/
function abiliko_stopListenToMember(withMember)
{
	var xml = "<data>" +	
					"<command>private.stopListen</command>"		+
					"<withMember>"		+ withMember			+ "</withMember>" 		+
			  "</data>";

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

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

	try
	{
		var returnCode = xmlRequest.getValue("returnCode");

		if (returnCode == "OK")
		{
			abiliko_showMsgBeforeAction ("הורדת חבר", "החבר הורד מרשימת האנשים להם אתה מקשיב", "window.location.href += \"&profileTab=6\"");
		}
		else if (returnCode == "NOT_LOGIN")
		{
			alert("עליך להתחבר לאתר תחילה כדי להפסיק להקשיב");
		}
	}
	catch (e)
	{
	}
}

/* --------------------------------------------------------------------------------------------------------------------	*/
/* abiliko_reportDuplicateQuestion																						*/
/* --------------------------------------------------------------------------------------------------------------------	*/
function abiliko_reportDuplicateQuestion(qid)
{
	var xml = "<data>" +	
					"<command>private.reportDuplicateQuestion</command>"		+
					"<questionId>"		+ qid			+ "</questionId>" 		+
			  "</data>";

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

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

	try
	{
		var returnCode = xmlRequest.getValue("returnCode");

		if (returnCode == "OK")
		{
			alert("תודה על הדיווח");
		}
		else if (returnCode == "NOT_LOGIN")
		{
			alert("עליך להתחבר לאתר תחילה כדי לדווח על השאלה");
		}
	}
	catch (e)
	{
	}
}

/* --------------------------------------------------------------------------------------------------------------------	*/
/* abiliko_joinCommunity																								*/
/* --------------------------------------------------------------------------------------------------------------------	*/
function abiliko_joinCommunity(communityCatId)
{
	var xml = "<data>" +	
					"<command>private.joinCommunity</command>"		+
					"<communityCatId>"		+ communityCatId				+ "</communityCatId>" 		+
			  "</data>";

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

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

	try
	{
		var returnCode = xmlRequest.getValue("returnCode");

		if (returnCode == "OK")
		{
			abiliko_showMsgBeforeAction ("הצטרפות לקהילה", "תודה שהצטרפת לקהילה", "window.location.reload()");
		}
		else if (returnCode == "NOT_LOGIN")
		{
			alert("עליך להתחבר לאתר תחילה כדי להצטרף לקהילה");
		}
		else if (returnCode == "ALREADY_JOINED")
		{
				alert("הינך כבר חבר בקהילה זו");
		}
		else if (returnCode == "NOT_SUCH_COMMUNITY")
		{
				alert("הקהילה לא קיימת");
		}
	}
	catch (e)
	{
	}
}

/* --------------------------------------------------------------------------------------------------------------------	*/
/* abiliko_showLongDescription																							*/
/* --------------------------------------------------------------------------------------------------------------------	*/
function abiliko_showLongDescription()
{
		document.getElementById('memberDescription').style.overflow='visible';
		document.getElementById('memberDescription').style.height='auto';
		document.getElementById('memberContinue').style.display='none';
}

/* ------------------------------------------------------------------------------------------------------------	*/
/* abiliko_showSendAssaultReport																				*/
/* ------------------------------------------------------------------------------------------------------------	*/
function abiliko_showSendAssaultReport(itemId, itemType)
{
	var oForm = document.getElementById("assaultReportForm");

	oForm.itemId.value 	 = itemId;
	oForm.itemType.value = itemType;

	abiliko_openPopup ("assaultReport");
}

/* ------------------------------------------------------------------------------------------------------------	*/
/* abiliko_sendAssaultReport																					*/
/* ------------------------------------------------------------------------------------------------------------	*/
function abiliko_sendAssaultReport ()
{
	var oForm = document.getElementById("assaultReportForm");

	if (oForm.reportMsg.value == "")
	{
		alert ("יש להזין את סיבת הדיווח");
		oForm.reportMsg.focus();
		return false;
	}

	var xml = "<data>" +	
					"<command>private.sendAssaultReport</command>"		+
					"<itemId>"		+ oForm.itemId.value				+ "</itemId>" 		+
					"<itemType>"	+ oForm.itemType.value				+ "</itemType>" 	+
					"<reportMsg>"	+ oForm.reportMsg.value				+ "</reportMsg>" 	+
			  "</data>";

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

/* ------------------------------------------------------------------------------------------------------------	*/
/* abiliko_afterSendAssaultReport																				*/
/* ------------------------------------------------------------------------------------------------------------	*/
function abiliko_afterSendAssaultReport (i)
{
	var oForm = document.getElementById("assaultReportForm");
	
	xmlRequest.init(commonDecode(asyncHttpObjs[i].responseText));

	try
	{
		var returnCode = xmlRequest.getValue("returnCode");

		if (returnCode == "OK")
		{
			abiliko_closePopup ("assaultReport")

			alert("תודה על הדיווח");

			oForm.reset ();
		}
		else if (returnCode == "NOT_LOGIN")
		{
			alert("עליך להתחבר לאתר תחילה כדי לדווח על תוכן פוגעני");
		}
	}
	catch (e)
	{
	}
}

/* ------------------------------------------------------------------------------------------------------------	*/
/* abiliko_moreWall																								*/
/* ------------------------------------------------------------------------------------------------------------	*/
function abiliko_moreWall(catId, startAt)
{
	var oDiv = document.getElementById("more"+startAt);
	oDiv.innerHTML = "<br />טוען...";

	var xml = "<data>" +	
					"<command>private.moreWall</command>"	+
					"<catId>"	+ catId						+ "</catId>" 	+
					"<startAt>"	+ startAt					+ "</startAt>" 	+
			  "</data>";

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

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

	try
	{
		var returnCode = xmlRequest.getValue("returnCode");

		if (returnCode == "OK")
		{
			var oMore = document.getElementById("more"+xmlRequest.getValue("startAt"));
			oMore.style.display = 'none';
			var oDiv = document.getElementById("communityWall");
			oDiv.innerHTML += xmlRequest.getValue("moreWallConent");
		}
	}
	catch (e)
	{
	}
}

function abiliko_replaceShopPic(str)
{
		document.getElementById("shopMagnifying").href = str;
		document.getElementById("shopEnlargedPic").src = str.replace("size0", "size2", "g");
}

/* ------------------------------------------------------------------------------------------------------------ */
/* abiliko_emptyCart																							*/
/* ------------------------------------------------------------------------------------------------------------ */
function abiliko_emptyCart ()
{
	if (confirm("האם ברצונך לרוקן את סל הקניות?"))
	{
		shop_emptyCart(true);
		window.location.reload();
	}
}

/* ------------------------------------------------------------------------------------------------------------ */
/* abiliko_openWhatsNewsPopup																					*/
/* ------------------------------------------------------------------------------------------------------------ */
function abiliko_openWhatsNewsPopup ()
{
	var oForm = document.getElementById("addWhatsNewsForm");

	oForm.whatsNewsText.value = "";

	document.getElementById("addWhatsNewsPopup").style.display = "";

	oForm.whatsNewsText.focus ();
}

/* ------------------------------------------------------------------------------------------------------------ */
/* abiliko_closeWhatsNewsPopup																					*/
/* ------------------------------------------------------------------------------------------------------------ */
function abiliko_closeWhatsNewsPopup ()
{
	document.getElementById("addWhatsNewsPopup").style.display = "none";
}

/* ------------------------------------------------------------------------------------------------------------ */
/* abiliko_submitAddWhatsNewsForm																				*/
/* ------------------------------------------------------------------------------------------------------------ */
function abiliko_submitAddWhatsNewsForm (toReload)
{
	var oForm = document.getElementById("addWhatsNewsForm");

	if (oForm.whatsNewsText.value == "")
	{
		alert ("יש להזין תוכן");
		return false;
	}

	var xml	= "<data>" +
					"<command>private.addWhatsNews</command>"	+
					"<text>" + oForm.whatsNewsText.value 		+ "</text>" 	+
					"<toReload>" + toReload						+ "</toReload>" +
			  "</data>";

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

	abiliko_closeWhatsNewsPopup ();

	return false;
}

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

	try
	{
		var returnCode = xmlRequest.getValue("returnCode");

		if (returnCode == "OK")
		{
			var toReload = xmlRequest.getValue("toReload");

			if (toReload == "1")
				window.location.reload ();
		}
		else if (returnCode == "NOT_LOGIN")
		{
			alert("עליך להתחבר לאתר תחילה");
		}
	}
	catch (e)
	{
	}

	return false;
}

/* ------------------------------------------------------------------------------------------------------------	*/
/* abiliko_deleteWhatsNews																						*/
/* ------------------------------------------------------------------------------------------------------------	*/
function abiliko_deleteWhatsNews (whatsNewsId)
{
	abiloko_showPopupMsg ("אישור מחיקה", 
						  "האם אתה בטוח שברצונך למחוק שורת סטטוס זו?<br/>" + 
						  "<div onclick='abiliko_doDeleteWhatsNews(" + whatsNewsId + ")'" 	+
						  "		onmouseout =\"this.childNodes[0].style.color='white'\" " +
						  "		onmouseover=\"this.childNodes[0].style.color='#eaff74'\" class='yesNoBtn' id='yesBtn'>" + 
						  	"<div style='color:white;'>כן</div></div>" + 
						  "<div onclick='abiliko_closePopup(\"popupMsg\")'" 	+
						  "		onmouseout =\"this.childNodes[0].style.color='white'\" " +
						  "		onmouseover=\"this.childNodes[0].style.color='#eaff74'\" class='yesNoBtn' id='noBtn'>" + 
						  	"<div style='color:white;'>לא</div></div>" + 
						  "<div style='clear:both'></div>");
}

function abiliko_doDeleteWhatsNews (whatsNewsId)
{
	commentDeleted = true;

	var xml = "<data>" +	
					"<command>private.deleteWhatsNews</command>"	+
					"<id>"		+ whatsNewsId	+ "</id>" 				+
			  "</data>";

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

function abiliko_doDeleteWhatsNews_response (i)
{
	xmlRequest.init(commonDecode(asyncHttpObjs[i].responseText));

	try
	{
		var returnCode = xmlRequest.getValue("returnCode");
		var htmlCode   = xmlRequest.getValue("htmlCode");

		if (returnCode == "OK")
		{
			document.getElementById("profileWhatsNewsContainer").innerHTML 	= htmlCode;

			abiliko_closePopup("popupMsg");
		}
		else
		{
		}
	}
	catch (e)
	{
	}
}

/* ------------------------------------------------------------------------------------------------------------	*/
/* abiliko_toggle																								*/
/* ------------------------------------------------------------------------------------------------------------	*/
function abiliko_toggle (elementName)
{
	oName = document.getElementById(elementName);

	if (oName.style.display == "")
		oName.style.display = "none";
	else
		oName.style.display = "";
}

/* ------------------------------------------------------------------------------------------------------------	*/
/* abiliko_addWhatsNewsFeedback																					*/
/* ------------------------------------------------------------------------------------------------------------	*/
function abiliko_addWhatsNewsFeedback (postId)
{
	var oForm 		  = document.getElementById("whatsNewsFeedbackForm" + postId);

	if (oForm.feedback.value == "")
	{
		alert ("יש להזין תגובה");
		oForm.feedback.focus ();
		return false;
	}

	var xml = "<data>" +	
					"<command>private.addWhatsNewsFeedback</command>"	+
					"<postId>"				+ postId		 			+ "</postId>" 			+
					"<title></title>" 		+
					"<content><![CDATA["	+ oForm.feedback.value		+ "]]></content>" 		+
			  "</data>";

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

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

	try
	{
		var returnCode = xmlRequest.getValue("returnCode");

		if (returnCode == "OK")
		{
			window.location.reload ();
		}
		else if (returnCode == "NOT_LOGIN")
		{
			alert("עליך להתחבר לאתר תחילה כדי להגיב");
		}
	}
	catch (e)
	{
	}
}

/* --------------------------------------------------------------------------------------------------------------------	*/
/* abiliko_submitJofOffer																								*/
/* --------------------------------------------------------------------------------------------------------------------	*/
function abiliko_submitJofOffer()
{
	if (document.getElementById("addjob_title").value == "")
	{
		alert("יש למלא כותרת למשרה");
		return false;
	}

	if (document.getElementById("addjob_email").value == "")
	{
		alert("יש למלא כתובת אימייל לקבלת פניות ממועמדים");
		return false;
	}

	document.getElementById("addjobForm").submit();
	return true;
}

function abiliko_updateAppStatus(appId)
{
	status = document.getElementById('appStatus' + appId).value;

	var xml = "<data>" +	
					"<command>private.updateAppStatus</command>"	+
					"<appId>"		+ appId			+ "</appId>" 			+
					"<status><![CDATA["	+ status		+ "]]></status>" 		+
		  "</data>";

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

function abiliko_afterAppStatus (i)
{
	xmlRequest.init(commonDecode(asyncHttpObjs[i].responseText));

	try
	{
		var returnCode = xmlRequest.getValue("returnCode");

		if (returnCode == "OK")
		{
			alert ("סטטוס המועמד עודכן בהצלחה");
		}
		else
		{
			alert("שגיאה בעדכון הסטטוס");
		}
	}
	catch (e)
	{
	}
}

/* ------------------------------------------------------------------------------------------------------------	*/
/* abiliko_submitNewsletterRegistrationForm																		*/
/* ------------------------------------------------------------------------------------------------------------	*/
function abiliko_submitNewsletterRegistrationForm ()
{
	var formValidator = new Validator('newsletterRegistrationFrm');

	formValidator.clearAllValidations ();
	
	formValidator.addValidation('firstname',	'required',		'יש להזין שם');
	formValidator.addValidation('email',		'required',		'יש להזין דואר אלקטרוני');
	formValidator.addValidation('email',		'email',		'יש להזין דואר אלקטרוני חוקי');

	if (formValidator.validate ())
	{
		verification_check("newsletterRegistrationFrm","HEB"); 
	}
	return false;
}


