
/* -------------------------------------------------------------------------------------------------------------------- */
/* memberEmail_openSendMsg																								*/
/* -------------------------------------------------------------------------------------------------------------------- */
function memberEmail_openSendMsg (id, name, from, msgId)
{
	if (msgId == undefined) msgId = "";
	if (from  == undefined) from  = "";

	oSendForm = document.getElementById("sendEmailForm");

	oSendForm.to.value   		= id;
	oSendForm.origMsg.value   	= msgId;
	oSendForm.from.value   		= from;

	var msgSubject = "";

	if (msgId != "")
	{
		msgSubject 	= "Re: " + document.getElementById("msgSubject" + msgId).innerHTML.replace(/Re: /g,"");

		document.getElementById("origMsgContent").innerHTML = name + ":<br/>" + document.getElementById("msgContent" + msgId).innerHTML;
		document.getElementById("origMsgContent").style.display = "";

		oSendForm.newMsgContent.className = "textareaField_replyMsg";
	}
	else
	{
		document.getElementById("origMsgContent").style.display = "none";
		oSendForm.newMsgContent.className = "textareaField";
	}

	oSendForm.subject.value 		= msgSubject;
	oSendForm.newMsgContent.value 	= "";

	document.getElementById("sendEmail_popupTitle").innerHTML 	= "שלח הודעה ל" + name;

	abiliko_openPopup ("sendEmail");

	oSendForm.subject.focus ();
}

/* ------------------------------------------------------------------------------------------------------------ */
/* memberEmail_addNewMsg																						*/
/* ------------------------------------------------------------------------------------------------------------ */
function memberEmail_addNewMsg ()
{
	oForm = document.getElementById("sendEmailForm");

	if (oForm.subject.value == "")
	{
		alert ("יש להזין נושא להודעה");
		lastErrorField = document.getElementById("subject");
		return false;
	}

	reply = "0";
	if (oForm.from.value == "reply")
		reply = "1";

	var xml = "<data>" +	
					"<command>privateEmail.addNewMsg</command>"   				+
					"<to>"					+ oForm.to.value 					+ "</to>" 			+
					"<subject>"				+ oForm.subject.value 				+ "</subject>" 		+
					"<content><![CDATA["	+ oForm.newMsgContent.value 		+ "]]></content>"	+
					"<reply>"				+ reply								+ "</reply>" 		+
					"<origMsgId>"			+ oForm.origMsg.value				+ "</origMsgId>" 	+
			  "</data>";

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

	return true;
}

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

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

		if (returnCode == "OK")
		{
			abiliko_closePopup ("sendEmail");
			document.getElementById("sendEmailForm").reset();
			alert ("הודעתך נשלחה");
		}
		else if (returnCode == "NOT_LOGIN")
		{
			alert("עליך להתחבר לאתר תחילה כדי להגיב");
		}
	}
	catch (e)
	{
	}
}

/* ------------------------------------------------------------------------------------------------------------ */
/* memberEmail_updateMsgStatus																					*/
/* ------------------------------------------------------------------------------------------------------------ */
function memberEmail_updateMsgStatus (msgId)
{
	var xml = "<data>" +
					"<command>privateEmail.updateMsgStatus</command>"  		+
					"<msgId>"		+ msgId 		+ "</msgId>" 			+
			  "</data>";

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

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

	try
	{
		var returnCode 		= xmlRequest.getValue("returnCode");
		var newStatus  		= xmlRequest.getValue("newStatus");
		var msgId 	   		= xmlRequest.getValue("msgId");
		var countInboxNew   = xmlRequest.getValue("countInboxNew");
		var countFaqNew   	= xmlRequest.getValue("countFaqNew");

		if (returnCode == "OK")
		{
			if (msgId != "")
			{
				document.getElementById("msgStatus" + msgId).src = "designFiles/msgStatus_" + newStatus + ".png";

				if (newStatus == "new")
				{
					document.getElementById("msgStatus" + msgId).title = "הודעה חדשה";
					document.getElementById("msgStatus" + msgId).alt   = "הודעה חדשה";
				}
				else
				{
					document.getElementById("msgStatus" + msgId).title = "הודעה נקראה";
					document.getElementById("msgStatus" + msgId).alt   = "הודעה נקראה";
				}

				if (newStatus == "read")
					document.getElementById("msgRow" + msgId).className = "msgRow";
				else
					document.getElementById("msgRow" + msgId).className = "msgRow_new";

				if (countInboxNew == 0)
					document.getElementById("noNewInboxMsgs").innerHTML = "";
				else if (countInboxNew != -1)
					document.getElementById("noNewInboxMsgs").innerHTML = countInboxNew;

				if (countFaqNew == 0)
					document.getElementById("noNewFaqMsgs").innerHTML = "";
				else if (countFaqNew != -1)
					document.getElementById("noNewFaqMsgs").innerHTML = countFaqNew;
			}
		}
		else if (returnCode == "NOT_LOGIN")
		{
			alert("עליך להתחבר לאתר תחילה כדי להגיב");
		}
	}
	catch (e)
	{
	}
}

/* ------------------------------------------------------------------------------------------------------------ */
/* memberEmail_hideMsgContent																					*/
/* ------------------------------------------------------------------------------------------------------------ */
function memberEmail_hideMsgContent (msgId)
{
	var contentRow = document.getElementById("msgRowContent" + msgId);

	contentRow.style.display = "none";
}

/* ------------------------------------------------------------------------------------------------------------ */
/* memberEmail_showHideMsgContent																				*/
/* ------------------------------------------------------------------------------------------------------------ */
function memberEmail_showHideMsgContent (msgId)
{
	var oRow = document.getElementById("msgRow" + msgId);

	if (oRow.className == "msgRow_new")
	{
		oRow.className = "msgRow";
		document.getElementById("msgStatus" + msgId).src   = "designFiles/msgStatus_read.png";
		document.getElementById("msgStatus" + msgId).title = "הודעה נקראה";
		document.getElementById("msgStatus" + msgId).alt   = "הודעה נקראה";
		memberEmail_updateMsgAsRead (msgId);
	}

	var contentRow = document.getElementById("msgRowContent" + msgId);

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

/* ------------------------------------------------------------------------------------------------------------ */
/* memberEmail_updateMsgAsRead																					*/
/* ------------------------------------------------------------------------------------------------------------ */
function memberEmail_updateMsgAsRead (msgId)
{
	var xml = "<data>" +
					"<command>privateEmail.updateMsgAsRead</command>"  		+
					"<msgId>"		+ msgId 		+ "</msgId>" 			+
			  "</data>";

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

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

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

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

function memberEmail_sendMsgToTrash (msgId)
{
	abiloko_showPopupMsg ("אישור מחיקה", 
						  "האם אתה בטוח שברצונך למחוק הודעה זו?<br/>" + 
						  "<div onclick='memberEmail_doSendMsgToTrash(" + msgId + ")'" 	+
						  "		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 memberEmail_doSendMsgToTrash (msgId)
{
	var xml = "<data>" +
					"<command>privateEmail.sendToTrash</command>"  			+
					"<msgId>"		+ msgId 		+ "</msgId>" 			+
			  "</data>";

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

/* --------------------------------------------------------------------------------------------------------------------	*/
/* memberEmail_sendMsgToTrash_response																					*/
/* --------------------------------------------------------------------------------------------------------------------	*/
function memberEmail_sendMsgToTrash_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)
	{
	}
}


function memberEmail_deleteAll (folder)
{
	abiloko_showPopupMsg ("אישור מחיקה", 
						  "האם אתה בטוח שברצונך למחוק את כל ההודעות בתיבת דואר זו?<br/>" + 
						  "<div onclick='memberEmail_doDeleteAll(\"" + folder + "\")'" 	+
						  "		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 memberEmail_doDeleteAll (folder)
{
	var xml = "<data>" +
					"<command>privateEmail.deleteAll</command>"  			+
					"<folder>"		+ folder 		+ "</folder>" 			+
			  "</data>";

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



