// JavaScript Document

// This file is maintained by Pooyan Balouchian <pooyan1982@yahoo.com>

//Defining Global Variables
var countNewMessages = 0;
var countOldMessages = 0;
var counterMessages = 0;



//Change Background Color of Header Left Links
function changeBgColor(id)
	{
	document.getElementById(id).style.cursor = "pointer";
	document.getElementById(id).style.backgroundColor = '#7582AF';	
	}

//Bring Back the Background Color of Header Left Links to Normal Color
function backBgColor(id)
	{
	document.getElementById(id).style.backgroundColor = '#3B5999';	
	}

//Change the Background of MEMORYTHM Logo to HUMAN BRAIN
function bringHumanBrain(id)
	{
	document.getElementById(id).style.cursor = "pointer";
	document.getElementById(id).style.backgroundImage = "url(photos/humanBrain.jpg)";
	}

//Change the Background of HUMAN BRAIN to MEMORYTHM Logo
function backToLogo(id)
	{
	document.getElementById(id).style.backgroundImage = "url(photos/memorythmLogo.jpg)";	
	}

//Submit the Form
function submitForm(event,id)
	{
	document.forms[id].submit();
	/*
	var value = document.forms[id].friendname.value;
	var str = "friendname="+escape(value);
	document.getElementById('mainframe').loadPage('showFriendSearchResult',str);
	event.returnValue=false;
	*/
	}

//Change the Appearance of Cursor to HAND
function makeCurserHand(id)
	{
	document.getElementById(id).style.cursor = "pointer";
	}

//Clear Any Text Box
function clearBox(obj) 
	{
	obj.value="";
	}

//Change Background Color of Search Friend Result Table
function changeBgColorOfSearchFriendResult(id,divid)
	{
	document.getElementById(id).style.cursor = "pointer";
	document.getElementById(id).style.backgroundColor = '#3B5999';
	document.getElementById(divid).style.color = '#ffffff';
	}

//Bring Back the Background Color of Search Friend Result Table
function backBgColorOfSearchFriendResult(id,divid)
	{
	document.getElementById(id).style.backgroundColor = '#ffffff';
	document.getElementById(divid).style.color = '#3B5999';
	}

//Make Link Visible
function makeLinkVisible(idMarkAsUnread,idMarkAsRead,idDelete,checkboxid,messageStatus)
	{
	if(document.allmessages[checkboxid].checked == true)//If the checkbox is clicked
		{
		if(messageStatus == 0)//If the message is new
			{
			countNewMessages++;
			//alert("I am checked. There are currently "+countNewMessages+" New Messages Selected and "+countOldMessages+" Old Messagses Selected.");
			if(countNewMessages != 0)//If there is no new message selected yet
				{
				document.getElementById(idMarkAsRead).style.cursor = 'pointer';
				document.getElementById(idMarkAsRead).href = 'javascript:markMessageAsRead();';
				document.getElementById(idMarkAsRead).onclick='';
				document.getElementById(idMarkAsRead).style.color = '#7582AF';
				document.getElementById(idMarkAsRead).style.fontWeight = 'bold';
				}
			}
		else if(messageStatus == 1)//If the message is old
			{
			countOldMessages++;
			//alert("I am UNchecked. There are currently "+countOldMessages+" Old Messages Selected and "+countNewMessages+" New Messagses Selected.");			if(countOldMessages != 0)//If there is at least one old message selected
				{
				document.getElementById(idMarkAsUnread).style.cursor = 'pointer';
				document.getElementById(idMarkAsUnread).href = 'javascript:markMessageAsUnread();';
				document.getElementById(idMarkAsUnread).style.color = '#7582AF';
				document.getElementById(idMarkAsUnread).onclick = '';
				document.getElementById(idMarkAsUnread).style.fontWeight = 'bold';
				}
			}
		document.getElementById(idDelete).style.cursor = 'pointer';
		document.getElementById(idDelete).href = 'javascript:deleteMessage();';
		document.getElementById(idDelete).onclick='';
		document.getElementById(idDelete).style.color = '#7582AF';
		document.getElementById(idDelete).style.fontWeight = 'bold';
		}
	else//If a checkbox is de-selected
		{
		if(messageStatus == 0)//If the message is new
			{
			countNewMessages--;
			//alert("I am checked. There are currently "+countNewMessages+" New Messages Selected and "+countOldMessages+" Old Messagses Selected.");			
			if(countNewMessages == 0)//If there is no new message selected yet
				{
				document.getElementById(idMarkAsRead).href = '#';
				document.getElementById(idMarkAsRead).onclick = function () { return false; };
				document.getElementById(idMarkAsRead).style.color = '#A0A0A0';
				document.getElementById(idMarkAsRead).style.fontWeight = 'normal';
				document.getElementById(idMarkAsRead).style.cursor = 'default';
				}
			}
		else if(messageStatus == 1)//If the message is old
			{
			countOldMessages--;
			//alert("I am UNchecked. There are currently "+countOldMessages+" Old Messages Selected and "+countNewMessages+" New Messagses Selected.");			
			if(countOldMessages == 0)//If there is at least one old message selected
				{
				document.getElementById(idMarkAsUnread).href = '#';
				document.getElementById(idMarkAsUnread).onclick = function () { return false; };
				document.getElementById(idMarkAsUnread).style.color = '#A0A0A0';
				document.getElementById(idMarkAsUnread).style.fontWeight = 'normal';
				document.getElementById(idMarkAsUnread).style.cursor = 'default';
				}
			}
		if(countNewMessages == 0 && countOldMessages == 0)//If there is absolutly no new message or old message selected
			{
			document.getElementById(idDelete).href = '#';
			document.getElementById(idDelete).onclick = function () { return false; };
			document.getElementById(idDelete).style.color = '#A0A0A0';	
			document.getElementById(idDelete).style.fontWeight = 'normal';
			document.getElementById(idDelete).style.cursor = 'default';
			}

		}
	}

//Make Link Visible for Sent Messages
function makeLinkVisibleSentMessages(idDelete1,checkboxid)
	{
	if(document.sentmessages[checkboxid].checked == true)//If the checkbox is clicked
		{
		counterMessages++;
		document.getElementById(idDelete1).style.cursor = 'pointer';
		document.getElementById(idDelete1).href = 'javascript:deleteMessageSentMessages();';
		document.getElementById(idDelete1).onclick='';
		document.getElementById(idDelete1).style.color = '#7582AF';
		document.getElementById(idDelete1).style.fontWeight = 'bold';
		}
	else//If a checkbox is de-selected
		{
		counterMessages--;
		if(counterMessages == 0)//If there is no message selected
			{
			document.getElementById(idDelete1).href = '#';
			document.getElementById(idDelete1).onclick = function () { return false; };
			document.getElementById(idDelete1).style.color = '#A0A0A0';
			document.getElementById(idDelete1).style.fontWeight = 'normal';
			document.getElementById(idDelete1).style.cursor = 'default';
			}
		}

	if(counterMessages==0)//If there is absolutly no message selected
		{
		document.getElementById(idDelete1).href = '#';
		document.getElementById(idDelete1).onclick = function () { return false; };
		document.getElementById(idDelete1).style.color = '#A0A0A0';	
		document.getElementById(idDelete1).style.fontWeight = 'normal';
		document.getElementById(idDelete1).style.cursor = 'default';
		}
	}

//Show Underline
function showUnderline(obj)
	{
	obj.style.textDecoration = 'underline';
	}

//Hide Underline
function hideUnderline(obj)
	{
	obj.style.textDecoration = 'none';
	}

var DMRes=null;

//Delete Message
function deleteMessage()
	{
	countNewMessages = 0;
	countOldMessages = 0;
	
	var str="";
	var counter;
	var messageList = Array();
	for(counter=0;counter<document.forms['allmessages'].length;counter++)//It get the messageIds of all selected messages
		{
		if (document.allmessages[counter].checked) 
			{
			messageList[messageList.length] = document.allmessages[counter].value;
			str += "id[]=" + document.allmessages[counter].value + "&" ;
			}
		}
	for(counter=0;counter<messageList.length;counter++)//It traverses all threads <tr>s to delete those selected
		{
		trId = "messageRow"+messageList[counter];
		c =   document.getElementById(trId);
		p = c.parentNode;
		p.removeChild(c);
		//ajaxEnable('halambehamkhord');
		//document.getElementById('halambehamkhord').loadPage("deleteMessage",str);
		//alert(str);
		//sendMsg("deleteMessage",str);
		
		
		callFunction("deleteMessage",str,"DMRes");
	
		if(DMRes == "ok")//If the threads have been successfully deleted in the database
			{
		
			document.getElementById('delete').href = '#';
			document.getElementById('delete').onclick = function () { return false; };
			document.getElementById('delete').style.color = '#A0A0A0';	
			document.getElementById('delete').style.fontWeight = 'normal';
			document.getElementById('delete').style.cursor = 'default';
	
			document.getElementById('markasunread').href = '#';
			document.getElementById('markasunread').onclick = function () { return false; };
			document.getElementById('markasunread').style.color = '#A0A0A0';	
			document.getElementById('markasunread').style.fontWeight = 'normal';
			document.getElementById('markasunread').style.cursor = 'default';
	
			document.getElementById('markasread').href = '#';
			document.getElementById('markasread').onclick = function () { return false; };
			document.getElementById('markasread').style.color = '#A0A0A0';	
			document.getElementById('markasread').style.fontWeight = 'normal';
			document.getElementById('markasread').style.cursor = 'default';
			
			}
		
		else//If there has been a problem causing the updates not affecting the database. Most probably database connection problem.
			{
			alert("problem");	
			}

		}
	}



var DMSMRes = null;
//Delete Message for Sent Messages
function deleteMessageSentMessages()
	{
	counterMessages = 0;
	
	var str="";
	var counter;
	var messageList = Array();
	for(counter=0;counter<document.forms['sentmessages'].length;counter++)//It get the messageIds of all selected messages
		{
		if (document.sentmessages[counter].checked) 
			{
			messageList[messageList.length] = document.sentmessages[counter].value;
			str += "id[]=" + document.sentmessages[counter].value + "&" ;
			}
		}
	for(counter=0;counter<messageList.length;counter++)//It traverses all threads <tr>s to delete those selected
		{
		trId = "messageRow"+messageList[counter];
		c =   document.getElementById(trId);
		p = c.parentNode;
		p.removeChild(c);
		//ajaxEnable('halambehamkhord');
		//document.getElementById('halambehamkhord').loadPage("deleteMessage",str);
		//alert(str);
		//sendMsg("deleteMessage",str);
		
		
		callFunction("deleteMessage",str,"DMSMRes");
	
		if(DMSMRes == "ok")//If the threads have been successfully deleted in the database
			{
		
			document.getElementById('deleteSentMessages').href = '#';
			document.getElementById('deleteSentMessages').onclick = function () { return false; };
			document.getElementById('deleteSentMessages').style.color = '#A0A0A0';	
			document.getElementById('deleteSentMessages').style.fontWeight = 'normal';
			document.getElementById('deleteSentMessages').style.cursor = 'default';
			}
		
		else//If there has been a problem causing the updates not affecting the database. Most probably database connection problem.
			{
			alert("problem");	
			}

		}
	}



var MAURes=null;

//Mark Thread as Unread
function markMessageAsUnread()
	{
	countNewMessages = 0;
	countOldMessages = 0;

	var str="";
	var counter;
	var messageList = Array();
	for(counter=0;counter<document.forms['allmessages'].length;counter++)//It get the threadIds of all selected messages
		{
		if (document.allmessages[counter].checked) 
			{
			messageList[messageList.length] = document.allmessages[counter].value;
			str += "id[]=" + document.allmessages[counter].value + "&" ;
			}
		}

	//ajaxEnable('halambehamkhord');
	//document.getElementById('halambehamkhord').loadPage("markMessageAsUnread",str);
	//alert(str);

	callFunction("markMessageAsUnread",str,"MAURes");
	
	
	
	if(MAURes == "ok")//If the updates have really affected the database
		{
			
		for(counter=0;counter<messageList.length;counter++)//It traverses all threads <tr>s to delete those selected
			{
			trId = "messageRow"+messageList[counter];
			checkBoxId = "messagecheckbox"+messageList[counter];
			imgId = "newMessage"+messageList[counter];
			document.getElementById(trId).style.backgroundColor = '#F4F8FC';
			document.allmessages[checkBoxId].checked = false;
			document.allmessages[checkBoxId].onclick = new Function ("","makeLinkVisible('markasunread','markasread','delete','"+checkBoxId+"',0);");
			
			document.getElementById(imgId).style.display = 'block';
			}
			
		document.getElementById('delete').href = '#';
		document.getElementById('delete').onclick = function () { return false; };
		document.getElementById('delete').style.color = '#A0A0A0';	
		document.getElementById('delete').style.fontWeight = 'normal';
		document.getElementById('delete').style.cursor = 'default';

		document.getElementById('markasunread').href = '#';
		document.getElementById('markasunread').onclick = function () { return false; };
		document.getElementById('markasunread').style.color = '#A0A0A0';	
		document.getElementById('markasunread').style.fontWeight = 'normal';
		document.getElementById('markasunread').style.cursor = 'default';

		document.getElementById('markasread').href = '#';
		document.getElementById('markasread').onclick = function () { return false; };
		document.getElementById('markasread').style.color = '#A0A0A0';	
		document.getElementById('markasread').style.fontWeight = 'normal';
		document.getElementById('markasread').style.cursor = 'default';
		


	}
	else//If there has been a problem causing the updates not affecting the database. Most probably database connection problem.
		{
			
		alert("problem");
			
		}
	}

var MARes=null;

//Mark Thread as Read
function markMessageAsRead()
	{
	countNewMessages = 0;
	countOldMessages = 0;

	var str="";
	var counter;
	var messageList = Array();
	for(counter=0;counter<document.forms['allmessages'].length;counter++)//It get the threadIds of all selected messages
		{
		if (document.allmessages[counter].checked) 
			{
			messageList[messageList.length] = document.allmessages[counter].value;
			str += "id[]=" + document.allmessages[counter].value + "&" ;
			}
		}

	//ajaxEnable('halambehamkhord');
	//document.getElementById('halambehamkhord').loadPage("markMessageAsUnread",str);
	//alert(str);

	callFunction("markMessageAsRead",str,"MARes");
	
	
	
	if(MARes == "ok")//If the updates have really affected the database
		{
			
		for(counter=0;counter<messageList.length;counter++)//It traverses all threads <tr>s to delete those selected
			{
			trId = "messageRow"+messageList[counter];
			checkBoxId = "messagecheckbox"+messageList[counter];
			imgId = "newMessage"+messageList[counter];
			document.getElementById(trId).style.backgroundColor = '#FFFFFF';
			document.allmessages[checkBoxId].checked = false;
			document.allmessages[checkBoxId].onclick = new Function ("","makeLinkVisible('markasunread','markasread','delete','"+checkBoxId+"',1);");
			document.getElementById(imgId).style.display = 'none';
			}
			
		document.getElementById('delete').href = '#';
		document.getElementById('delete').onclick = function () { return false; };
		document.getElementById('delete').style.color = '#A0A0A0';	
		document.getElementById('delete').style.fontWeight = 'normal';
		document.getElementById('delete').style.cursor = 'default';

		document.getElementById('markasunread').href = '#';
		document.getElementById('markasunread').onclick = function () { return false; };
		document.getElementById('markasunread').style.color = '#A0A0A0';	
		document.getElementById('markasunread').style.fontWeight = 'normal';
		document.getElementById('markasunread').style.cursor = 'default';

		document.getElementById('markasread').href = '#';
		document.getElementById('markasread').onclick = function () { return false; };
		document.getElementById('markasread').style.color = '#A0A0A0';	
		document.getElementById('markasread').style.fontWeight = 'normal';
		document.getElementById('markasread').style.cursor = 'default';
		


	}
	else//If there has been a problem causing the updates not affecting the database. Most probably database connection problem.
		{
			
		alert("problem");
			
		}
	}


var SMRes = null;

//Send Message --> Start a totally new thread
function sendMessage(oEv)
	{
	var receiver = document.composemessage['receiver'].value;
	var messageBody = document.composemessage['messageBody'].value;
	var str = "receiver="+receiver+"&messageBody="+messageBody;

	/*
	ajaxEnable('boogh');
	document.getElementById('boogh').loadPage("sendMessage",str);
	alert(str);
	event.returnValue = false;
	*/
	
	callFunction("sendMessage",str,"SMRes");

	if(SMRes != "false")
		{
		location.href='showMessage.php?threadId='+SMRes;
		}
	
		if(typeof(event)=="object")
			{
			event.returnValue = false;	
			}
		else
			{
			oEv.preventDefault();	
			}
	}


var RMRes = null;

//Reply Message --> When a thread of message is shown
function replyMessage(obj,oEv,threadId)
	{
	var msgBody = obj.msgBody.value;
	var str = "msgBody="+msgBody+"&threadId="+threadId;
	/* send with ajax to serveer */
	
	callFunction("replyMessage",str,"RMRes");
	/* add to list if return ok from server */
//	alert(RMRes);
	RMRes = RMRes.split('&&');
	if(RMRes[0] == "ok")
		{
		var systemdate = RMRes[1];
		var firstname = RMRes[2];
		var lastname = RMRes[3];
		var uid = RMRes[4];
		var msgBody = RMRes[5];
		var photo = RMRes[6];
		var tbody = 1;
		if ( checkBrowser() == "MSIE" )
			{	
			tbody = 0;
			}
		var t = document.getElementById("messageTable").childNodes[tbody];
		var rtr = document.getElementById("ReplyFormTr");
		var tr = document.createElement("TR");
		var td = document.createElement("TD");
		t.insertBefore(tr,rtr);
		tr.appendChild(td);
		td.innerHTML = ""+
		"<table width='100%' style='font-size:10px;' border='0px' cellpadding='0px' cellspacing='0px'>"+
			"<tr>"+
				"<td colspan='6'>&nbsp;</td>"+
			"</tr>"+
			"<tr>"+
				"<td width='15px'>&nbsp;</td>"+
				"<td width='70px'>"+photo+
				"</td>"+
				"<td width='120px' style='padding:10px'>"+
				"<span style='font-size:10px; color:#7582AF; font-weight:bold;'>"+firstname+" "+lastname+
				"</span><br />"+
				"<span style='color:#999999; font-size:8px'>"+systemdate+
				"</span>"+
				"</td>"+
				"<td width='15px'>&nbsp;</td>"+
				"<td align='left' width='300px' style='padding:5px; border-bottom:1px solid #CCCCCC'>"+
				"<span style='font-size:10px; color:#000000;'>"+msgBody+
				"</span>"+
				"</td>"+
				"<td width='15px'>"+
				"</td>"+
			"</tr>"+
		"</table>";
		}
	else
		{
		alert("problem");	
		}
		
		if ( typeof(event) == "object" ) 
			{
			event.returnValue =  false;
			}
		else
			{
			oEv.preventDefault();
			}
	}
	
/***************************************** Check Browswer **********************************************/

function checkBrowser() {
	var msie = RegExp("MSIE","i");
	var firefox = RegExp("firefox","i");
	var safari = RegExp("safari","i");
	if ( msie.test(window.navigator.userAgent) )
		return "MSIE";
	if ( firefox.test(window.navigator.userAgent))
		return "FIREFOX";
	if ( safari.test(window.navigator.userAgent)) 
		return "SAFARI";
}

/***************************************** Bulletin**********************************************/
var leftMargin = 0;
var topMargin = 0;

function showBulletin(header,mainbody,footer)
	{
		if ( !document.getElementById('bulletinDIV') ){
			document.body.innerHTML  = '<div id="bulletinDIV" style="position:absolute; visibility:hidden; z-index:1000;"></div>'+document.body.innerHTML;
			window.onresize = function () {
			setLeftMargin();
	 		setTopMargin();
	 }	
		}
		
	document.getElementById('bulletinDIV').innerHTML ="<table style='width:520px;' cellpadding='0px' cellspacing='0px'>"+
	"<tr style='font-size:8px;'>"+
		"<td width='10px' style='background:url(photos/popuprcornerleft.png);'>&nbsp;</td>"+
		"<td width='500px' style='background:url(photos/popuptop.png);'>&nbsp;</td>"+
		"<td width='10px' style='background:url(photos/popuprcornerright.png);'>&nbsp;</td>"+
	"</tr>"+

	"<tr>"+
		"<td width='10px' style='background:url(photos/popupleft.png); background-repeat:repeat;'>&nbsp;</td>"+
		
		"<td align='center' width='500px'>"+

			"<table width='500px' id='bulletinTable' style='background-color:#F7F7F7; border:1px solid #8496BA;' cellpadding='0px' cellspacing='0px'>"+

				"<tr style='background-color:#6D84B4; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; color:#FFFFFF; font-weight:bold; padding-left:5px; padding-right:5px;'>"+
					"<td id='header' height='30px' style='padding-left:5px; padding-right:px;' id='bulletinHeader' align='left'>"+
						header+
					"</td>"+
			"	</tr>"+
				
				"<tr>"+

					"<td id='bulletinBody' style='background-color:#FFFFFF; padding-left:5px; padding-right:5px; padding-top:5px; padding-bottom:5px;'>"+mainbody+"</td>"+

				"</tr>"+
	
				"<tr>"+
	
					"<td id='bulletinFooter' style='border-top:1px solid #999999; background-color:#F2F2F2; padding-left:5px; padding-right:5px; padding-top:5px; padding-bottom:5px;'>"+footer+"</td>"+
	
				"</tr>"+

			"</table>"+

		"</td>"+
		
		"<td width='10px' style='background:url(photos/popupright.png); background-repeat:repeat;'>&nbsp;</td>"+
	"</tr>"+

	"<tr style='font-size:8px;'>"+
		"<td width='10px' style='background:url(photos/popuprcornerbottomleft.png);'>&nbsp;</td>"+
		"<td width='500px' style='background:url(photos/popupbottom.png);'>&nbsp;</td>"+
		"<td width='10px' style='background:url(photos/popuprcornerbottomright.png);'>&nbsp;</td>"+
	"</tr>"+

"</table>";
	setLeftMargin();
	setTopMargin();
	document.getElementById('bulletinDIV').style.visibility = 'visible';
	}

/***************************************** Set Left Margin **********************************************/

function setLeftMargin()
{
	
        var x = 0;
        if (self.innerHeight)
        {
                x = self.innerWidth;
        }
        else if (document.documentElement && document.documentElement.clientHeight)
        {
                x = document.documentElement.clientWidth;
        }
        else if (document.body)
        {
                x = document.body.clientWidth;
        }
        leftMargin = ((x-520)/2);
	
		document.getElementById('bulletinDIV').style.left = leftMargin+"px";
		
}

/***************************************** Set Top Margin **********************************************/
 
function setTopMargin()
{
        var height = 0;
		var y = 0;
        if (self.innerHeight)
        {
                y = self.innerHeight;
        }
        else if (document.documentElement && document.documentElement.clientHeight)
        {
                y = document.documentElement.clientHeight;
        }
        else if (document.body)
        {
                y = document.body.clientHeight;
        }
        height = document.getElementById('bulletinDIV').clientHeight;
		
		topMargin = ((y-height)/2);
		if ( checkBrowser() == "MSIE" ) 
			topMargin += document.documentElement.scrollTop;
		else
			topMargin += window.pageYOffset;

		document.getElementById('bulletinDIV').style.top = topMargin+"px";

}

/******************************************** Add Friend **********************************************/

var AFRes = null;

function showAddFriend(fId)
	{

	var str = "friendId="+fId;

callFunction("showAddFriend",str,"AFRes");

AFRes = AFRes.split('&&');
	if(AFRes[0] == "ok")
		{
		vheader = AFRes[1];
		vbody = AFRes[2];
		vfooter = AFRes[3];
		showBulletin(vheader,vbody,vfooter);
		}
	else
		{
		alert("problem");	
		}
	}
	
/******************************************** Send Friend Request **********************************************/

var SFRes = null;

function sendFriendRequest(fId)
	{
	var message = document.getElementById('messageBody').value;
	var str = "friendId="+fId+"&message="+message;
	
	//ajaxEnable('boogh');
	//document.getElementById('boogh').loadPage("addFriend",str);
	//alert(str);
	//event.returnValue = false;

callFunction("sendFriendRequest",str,"SFRes");

	if(SFRes == "ok")
		{
		destroyBulletin();
		document.getElementById('firsttd'+fId).style.color = '#666666';
		document.getElementById('firsttd'+fId).style.backgroundColor = '#FFFFFF';
		document.getElementById('firstlink'+fId).href = '#';
		document.getElementById('firsttd'+fId).style.cursor = 'default';
		document.getElementById('firsttd'+fId).style.disabled = 'disabled';
		document.getElementById('firsttd'+fId).style.borderBottom = 'solid 1px #CCCCCC';


		
		document.getElementById('firstdiv'+fId).onmouseover = function(){ };
		
		document.getElementById('firstdiv'+fId).onmouseout = function(){ };
		document.getElementById('firsttd'+fId).innerHTML = " Friend Requested";

		}
	else
		{
		alert("problem");	
		}
	}

/******************************************** Destroy Bulletin **********************************************/

function destroyBulletin()
	{
	document.getElementById('bulletinDIV').style.visibility = 'hidden';		
	}

/******************************************** Show Message Form **********************************************/

function showMessageForm()
	{
	document.getElementById('addFriendMessage').style.display = 'block';	
	document.getElementById('cpmessage').style.display = 'block';
	document.getElementById('pmessage').style.href = '#';
	document.getElementById('pmessage').style.color = '#000000';
	document.getElementById('pmessage').style.fontWeight = 'normal';
	document.getElementById('pmessage').style.textDecoration = 'none';
	document.getElementById('pmessage').style.cursor = 'default';
	document.getElementById('pmessage').onmouseover = function() {};
	document.getElementById('pmessage').onclick = function () { return false; };
	}

/******************************************** Hide Message Form **********************************************/

function hideMessageForm()
	{
	document.getElementById('messageBody').value = '';
	document.getElementById('addFriendMessage').style.display = 'none';
	document.getElementById('cpmessage').style.display = 'none';
	document.getElementById('pmessage').style.color = '#6D84B4';
	document.getElementById('pmessage').style.fontWeight = 'bold';
	document.getElementById('pmessage').onmouseover = function() {
		document.getElementById('pmessage').style.cursor = 'pointer'; 
		document.getElementById('pmessage').style.textDecoration = 'underline';
	};
	document.getElementById('pmessage').onclick = function() {
		showMessageForm();
	};
	}

/******************************************** Hide Message Form **********************************************/

var SSMRes = null;

function showSendMessage(fId)
	{
		
	var str = "friendId="+fId;
	
	//ajaxEnable('boogh');
	//document.getElementById('boogh').loadPage("showSendMessage",str);
	//alert(str);
	//event.returnValue = false;

	callFunction("showSendMessage",str,"SSMRes");
	SSMRes = SSMRes.split("&");

	if(SSMRes[0] == "ok")
		{
		vheader = SSMRes[1];
		vbody = SSMRes[2];
		vfooter = SSMRes[3];
		showBulletin(vheader,vbody,vfooter);
		}
	
	else
		{
		alert("problem");	
		}
	
		
	}

/******************************************** Send Private Message **********************************************/

var SPMRes = null;

function sendPrivateMessage(fId)
	{
	var msgBody = document.getElementById('messageBody').value;
	var str = "friendId="+fId+"&messageBody="+msgBody;

	//ajaxEnable('boogh');
	//document.getElementById('boogh').loadPage("sendPrivateMessage",str);
	//alert(str);
	//event.returnValue = false;

	callFunction("sendPrivateMessage",str,"SPMRes");

	if(SPMRes == "ok")
		{
		destroyBulletin();
		}
	
	else
		{
		alert("problem");	
		}
	
	}

/******************************************** Create Recepient Label **********************************************/

function createRecepientLabel(name,linkUrl)
	{
	var str="<table style='float:left;' cellpadding='0px' cellspacing='0px'>"+
						"<tr>"+
							"<td background='photos/toReceiverLeft.jpg' width='5px' height='18px'>"+
							
							"</td>"+
							"<td style='background-image:url(photos/toReceiverCenter.jpg); background-repeat:repeat;' id='receiverName'>"+
							name
							"</td>"+
							"<td onClick='"+linkUrl+"' background='photos/toReceiverRightSendMessage.jpg' width='5px' height='18px' style='cursor=pointer;'>"+
							"</td>"+
						"</tr>"+
					"</table>";
	return str;
	}

/******************************************** Show Delete Friend Confirmation **********************************************/

function showDeleteFriendConfirmation(id,name,lastname)
	{
	vheader = "Remove Friend?";
	vbody = "<span style='float:left; font-size: 11px;'>Are you sure you want to remove <strong>"+name+" "+lastname+"</strong> from your friend list?</span>";
	vfooter = "<span style='float:right'><input type='button' value='Remove' onClick='deleteFriend("+id+");' style='border: 1px solid #E0E0E0; height:20px; width:70px; background:#3B5999; color:#FFFFFF; font-weight:bold; border-bottom-style:outset; font-size:11px;'> <input style='border: 1px solid #E0E0E0; height:20px; width:70px; background:#F0F0F0; color:#000000; font-weight:bold; border-bottom-style:outset; font-size:11px;' type='button' value='Cancel' onClick='destroyBulletin();'></span>";
	showBulletin(vheader,vbody,vfooter);
	}


/******************************************** Delete Friend **********************************************/

var DFRes = null;

function deleteFriend(fId)
	{
	var str = "friendId="+fId;
	trId = fId;
	c =   document.getElementById(trId);
	p = c.parentNode;
	p.removeChild(c);

	callFunction("deleteFriend",str,"DFRes");
	DFRes = DFRes.split("&");
	if(DFRes[0] == "ok")
		{
		destroyBulletin();
		document.getElementById('noOfFriendsDiv').innerHTML = "You have <strong>"+DFRes[1]+"</strong> friends.";
		}
	
	else
		{
		alert("problem");	
		}
	}

/******************************************** Show Mutual Friend **********************************************/

var SMFRes = null;

function showMutualFriends(fId)
	{
	var str = "friendId="+fId;
	var tdId = 'mFriend'+fId;
	
	callFunction("showMutualFriend",str,"SMFRes");
	SMFRes = SMFRes.split("&&");
	if(SMFRes[0] == "ok")
		{
		document.getElementById(tdId).style.display = 'block';
		document.getElementById(tdId).innerHTML = SMFRes[1];
		}
	
	else
		{
		alert("problem");	
		}

	
	//ajaxEnable(tdId);
	//document.getElementById(tdId).loadPage("showMutualFriend",str);
	//setTimeout("alert(document.getElementById('"+tdId+"').innerHTML)",1000);
	}

/******************************************** Send Invitation **********************************************/

var SINRes = null;

function sendInvitation()
	{
	var emails = document.getElementById('toEmails').value;
	var msg = document.getElementById('inviteMsg').value;

	var str = "emails="+emails+"&messageBody="+msg;

	
	callFunction("sendInvitation",str,"SINRes");



	SINRes = SINRes.split("&&");

	if(SINRes[0] == "ok")
		{
		vheader = SINRes[1];
		vbody = SINRes[2];
		vfooter = SINRes[3];
		showBulletin(vheader,vbody,vfooter);
		}
	else
		{
		alert("problem");	
		}

	}

/******************************************** Show Your Friends in This Memory **********************************************/

var SYFITMRes = null;

function showYourFriendsInThisMemory(caseId)
	{
	var str = "caseId="+caseId;
	var tdId = 'yFriend'+caseId;

	ajaxEnable(tdId);
	
	document.getElementById(tdId).loadPage("showYourFriendsInThisMemory",str);
	document.getElementById(tdId).style.display = 'block';
	}

/******************************************** Show Your Friends in This Memory **********************************************/

var SFBRes = null;

function sendFeedBack(uid)
	{
	var msgBody = document.getElementById('feedBackMessage').value;
	var str = "from="+uid+"&feedBackMessage="+msgBody;

	callFunction("sendFeedBack",str,"SFBRes");

	SFBRes = SFBRes.split("&");

	if(SFBRes[0] == "ok")
		{
		vheader = SFBRes[1];
		vbody = SFBRes[2];
		vfooter = SFBRes[3];
		showBulletin(vheader,vbody,vfooter);
		}
	else
		{
		alert("problem");	
		}
	}


/******************************************** Show Single Photo Layer **********************************************/

var SSPRes = null;

function showSinglePhoto(caseId,imageId,index)
	{
	document.getElementById('tabbingTable').style.display = 'none';
	document.getElementById('photoAlbum').style.display = 'none';
	document.getElementById('singlePhoto').style.display = 'block';

	var str = "caseId="+caseId+"&imageId="+imageId+"&index="+index;

	callFunction("showSinglePhoto",str,"SSPRes");

	SSPRes = SSPRes.split("&&");

	if(SSPRes[0] == "ok")
		{
		var singlePhoto = SSPRes[1];
		document.getElementById('singlePhoto').innerHTML = singlePhoto;
		}
	else
		{
		alert("problem");	
		}
	}


/********************************************Get Previous Photo**********************************************/

var GPPRes = null;

function getPreviousPhoto( )
	{
	callFunction("getPreviousPhoto","","GPPRes");
	GPPRes = GPPRes.split("&&");
	if(GPPRes[0] == "ok")
		{
		var mainPhoto = GPPRes[1];
		var comments = GPPRes[2];
		var photoInformation = GPPRes[3];
		document.getElementById('mainPhoto').innerHTML = mainPhoto;
		document.getElementById('commentTableTd').innerHTML = comments;
		document.getElementById('photoInformation').innerHTML = photoInformation;
		}
	else
		{
		alert("problem");	
		}
	}


/********************************************Get Next Photo**********************************************/

var GNPRes = null;

function getNextPhoto( )
	{
	callFunction("getNextPhoto","","GNPRes");
	GNPRes = GNPRes.split("&&");
	if(GNPRes[0] == "ok")
		{
		var mainPhoto = GNPRes[1];
		var comments = GNPRes[2];
		var photoInformation = GNPRes[3];
		document.getElementById('mainPhoto').innerHTML = mainPhoto;
		document.getElementById('commentTableTd').innerHTML = comments;
		document.getElementById('photoInformation').innerHTML = photoInformation;
		}
	else
		{
		alert("problem");	
		}
	}

/********************************************Add comment to a photo**********************************************/

var AICRes = null;

function addImageComment(obj,oEv,imageId,caseId,photoCounter)
	{
	var commentBody = obj.iComment.value;
	var str = "commentBody="+commentBody+"&imageId="+imageId+"&caseId="+caseId+"&photoCounter="+photoCounter;
	/* send with ajax to serveer */
	callFunction("addImageComment",str,"AICRes");
	/* add to list if return ok from server */

	AICRes = AICRes.split('&&');
	if(AICRes[0] == "ok")
		{
		var comment = AICRes[1];
		var senderName = AICRes[2];
		var date = AICRes[3];
		var senderImage = AICRes[4];
		
		var tbody = 1;
		if ( checkBrowser() == "MSIE" )
			{	
			tbody = 0;
			}
			
		var t = document.getElementById("commentTableInner").childNodes[tbody];
		var rtr = document.getElementById("formTr");
		var tr = document.createElement("TR");
		var td = document.createElement("TD");
		t.insertBefore(tr,rtr);
		tr.appendChild(td);
		td.innerHTML ="<tr>"+
				"<td style='padding-bottom:10px;'>"+
					"<table cellpadding='0px' cellspacing='0px' border='0px'>"+
						"<tr>"+
							"<td valign='top' width='70px' align='center'>"+senderImage+
							"</td>"+
							"<td valign='top' width='400px'>"+
								"<table cellpadding='0px' cellspacing='0px'>"+
									"<tr>"+
										"<td style='border-top:1px solid #3B5998; border-bottom:1px solid #999999; background-color:#F7F7F7; font-size:10px; padding-top:5px; padding-bottom:5px; padding-left:5px; padding-right:5px;' valign='top'  width='400px'>"+
										"<span style='color:#3B5998; font-weight:bold;' >"+senderName+
										"</span> commented on this photo<br>on <span style='color: #999999; font-size: 10px;'>"+date+
										"</span>"+
										"</td>"+
									"</tr>"+
									
									"<tr>"+
										"<td style='padding:5px; font-size:11px;'>"+comment+

									"</td>"+
									"</tr>"+
								
								"</table>"+
						"</td>"+
					"</tr>"+
					"</table>"+
				"</td>"+
			"</tr>";
		}
	else
		{
		alert("problem");	
		}

		if ( typeof(event) == "object" ) 
			event.returnValue =  false;
		else
			oEv.preventDefault();
	}

/********************************************Destroy Single Photo**********************************************/

function destroySinglePhoto()
	{
	document.getElementById('singlePhoto').style.display = 'none';
	document.getElementById('tabbingTable').style.display = 'block';
	document.getElementById('photoAlbum').style.display = 'block';
	}
	
/********************************************Play Video**********************************************/

function playVideo(url) {
	document.getElementById("VIDEO").url = url;
	document.getElementById("VIDEO").Controls.play();
}

/********************************************Play Sound**********************************************/

function playSound(url) {
	
	document.getElementById("SOUND").url = url;
	document.getElementById("SOUND").Controls.play();
}

/********************************************Sign Up**********************************************/

var SURes = null;

function signup(inviterId) 
	{
	var firstname = document.forms['signupform'].firstname.value;	
	var lastname = document.forms['signupform'].lastname.value;	
	var country = document.forms['signupform'].country.value;	
	var email = document.forms['signupform'].email.value;	
	var password = document.forms['signupform'].password.value;	
	var gender = document.forms['signupform'].gender.value;	
	var day = document.forms['signupform'].day.value;	
	var month = document.forms['signupform'].month.value;	
	var year = document.forms['signupform'].year.value;
	
	var str = "firstname="+firstname+"&lastname="+lastname+"&country="+country+"&email="+email+"&password="+password+"&gender="+gender+"&day="+day+"&month="+month+"&year="+year+"&inviterId="+inviterId;
		
	callFunction("signup",str,"SURes");
	SURes = SURes.split('&');	
	
	/* add to list if return ok from server */
	if(SURes[0] == "ok")
		{
		vheader = SURes[1];
		vbody = SURes[2];
		vfooter = SURes[3];
		showBulletin(vheader,vbody,vfooter);
		}
	else
		{
		alert("Problem");	
		}
	}


/********************************************Go To Sign In Page**********************************************/

function goToSignInPage() 
	{
	destroyBulletin();
	location.href = 'http://www.memorythm.com';
	}
