var inboxDiv = "inbox";
var outboxDiv = "outbox";
var familyDiv = "family";

var oldClickedOn = "tdInbox";
var inboxRequested = false;
var outboxRequested = false;
var lastMessageId=0;
var lastMessageType=1;
var toUserId=0;

function mouseOver(div){
	div.style.backgroundColor='#ECEFF5';
	//div.style.color='#3B5998';
	//div.style.fontWeight='bold';
}

function mouseOut(div){
	div.style.backgroundColor='#ffffff';
	//div.style.color='#0077BB';
	//div.style.fontWeight='normal';
}

function mouseClick(div1, div2){
	document.getElementById(oldClickedOn).style.fontWeight="normal";
	document.getElementById(oldClickedOn).style.color="#0077BB";
	document.getElementById(div1).style.fontWeight="bold";
	document.getElementById(div1).style.color="darkBlue";
	oldClickedOn = div1;
	document.getElementById("inbox").style.display="none";
	document.getElementById("outbox").style.display="none";
	document.getElementById(div2).style.display="";
	if(div2 == 'inbox' && inboxRequested == false){
		getInbox();
		inboxRequested = true;
	}
	if(div2 == 'outbox' && outboxRequested == false){
		getOutbox();
		outboxRequested = true;
	}
	
	
}

function getInbox(){
	sendRequest("inbox", "/blog/message/getMessages");
}

function getOutbox(){
	sendRequest("outbox", "/blog/message/getSentMessages");
}

function viewMessage(type1, id1, read){
	lastMessageId = id1;
	lastMessageType = type1;
	document.getElementById("reply").value="";
	document.getElementById("replyWindow").style.display="none";
	centerElement("generalContainer", 500, 400);
	if(read == 1){
		sendRequestCallFunctionAfter("generalContainerInnerWindow", "/blog/message/getMessage?type=" + type1 + "&id=" + id1, 1, "getUpdates()");
	}
	else
		sendRequest("generalContainerInnerWindow", "/blog/message/getMessage?type=" + type1 + "&id=" + id1);
}

function deleteMessage(type1, id1, read1){
	lastMessageId = id1;
	lastMessageType = type1;
	document.getElementById("reply").value="";
	document.getElementById("replyWindow").style.display="none";
	centerElement("generalContainer", 500, 400);
	if(type1 == 1)
		sendRequestCallFunctionAfter("generalContainerInnerWindow", "/blog/message/deleteMessage?type=" + type1 + "&id=" + id1 + "&is_read=" + read1, 1, "getInbox()");
	else
		sendRequestCallFunctionAfter("generalContainerInnerWindow", "/blog/message/deleteMessage?type=" + type1 + "&id=" + id1 + "&is_read=" + read1, 1, "getOutbox()");
}

function reply(to, id){
	lastMessageId = id;
	toUserId = to;
	document.getElementById("replyWindow").style.display="";
}

function sendReply(){
	theReply = document.getElementById("reply").value;
	if(theReply == ''){
		alert("Reply is empty ...");
		return;
	}
	document.getElementById("replyWindow").style.display="none";
	sendPostRequest('generalContainerInnerWindow', "/blog/message/submitMessage", "id= " + toUserId +  "&message="+theReply, 1);
	
	sendRequest("generalContainerInnerWindow", "/blog/message/getMessage?type=" + type1 + "&id=" + id1);
}

function share(){
	document.getElementById('shareInnerWindow').innerHTML = document.getElementById('shareInnerWindowBackup').innerHTML;
	centerElement("shareDiv",500, 400);
}

function sendShare(theId){
	theEmail = document.getElementById('shareEmailText').value;
	if(theEmail == '')
		return;
		
	sendPostRequest('shareInnerWindow', "/blog/friend/shareFriends", "email=" + theEmail + "&id=" + theId, 1);
}

