var timeStamp = Date();
var xmlLoaderImage = 'http://cdn.myanimelist.net/images/xmlhttp-loader.gif';

function quoteEm(msgId)
{
	if (document.getElementById("quickReply").style.display == 'none')
		{
		showHideQuickReply();
		}
	
	var username = document.getElementById("messageuser"+msgId).innerText || document.getElementById("messageuser"+msgId).textContent
	var getMsgText = document.getElementById("message"+msgId).innerText || document.getElementById("message"+msgId).textContent;
	
	 $.get("../includes/quotetext.php?msgid="+msgId+"&timestamp="+timeStamp, function(data)
		{
   		document.quickReplyForm.msg_text.value = document.quickReplyForm.msg_text.value + "[quote="+username+"]"+data+"[/quote]";
	 	}
		);

	document.getElementById("quickReply").focus();
	document.quickReplyForm.msg_text.focus();
}

function ignoreBoard(boardid,inVal)
{
	document.getElementById("iBoardId").innerHTML = '<img src="'+xmlLoaderImage+'">';
	$.get("../includes/ajax.inc.php?t=16&val="+inVal+"&ibid="+boardid+"&timestamp="+timeStamp, function (data) 
			{
			if (inVal == 2)
				document.getElementById("iBoardId").innerHTML = "<a href='javascript:void(0);' onclick='ignoreBoard("+boardid+",1);'>Ignore Board</a>";
			else 
				document.getElementById("iBoardId").innerHTML = "<a href='javascript:void(0);' onclick='ignoreBoard("+boardid+",2);'>Un-ignore Board</a>";
			}
		); 
}

function ignoreTopic(topicid,idName,cVal)
{
	$.get("../includes/ajax.inc.php?t=1&val="+cVal+"&id="+topicid+"&timestamp="+timeStamp, function (data) 
			{
			$('#'+idName).toggle(); 
			}
		); 
}

function ignoreTopicinThread(topicid,cVal)
{
	document.getElementById("ignoreThreadText").innerHTML = '<img src="'+xmlLoaderImage+'">';
	$.get("../includes/ajax.inc.php?t=1&val="+cVal+"&id="+topicid+"&timestamp="+timeStamp, function (data) 
			{
			if (cVal == 2)
				document.getElementById("ignoreThreadText").innerHTML = "<a href='javascript:void(0);' onclick='ignoreTopicinThread("+topicid+",1);'>Ignore Topic</a>";
			else 
				document.getElementById("ignoreThreadText").innerHTML = "<a href='javascript:void(0);' onclick='ignoreTopicinThread("+topicid+",2);'>Un-ignore Topic</a>";
			}
		); 
}

function showHideQuickReply($type)
{
	if ($type)
		{
		document.getElementById("quickReply").style.display = $type;
		return true;
		}
	
	if (document.getElementById("quickReply").style.display == 'none')
		{
		document.getElementById("quickReply").style.display = 'block';
		document.quickReplyForm.msg_text.focus();
		}
	else
		{
		document.getElementById("quickReply").style.display = 'none';
		}
}

// JavaScript Document

function watchTopic(topicid)
{
	document.getElementById("watchText").innerHTML = '<img src="'+xmlLoaderImage+'">';
	$.get("../includes/ajax.inc.php?t=69&topic_id="+topicid+"&timestamp="+timeStamp, function(data)
			{
			document.getElementById("watchText").innerHTML = data;
	 		}
		);
}

function  topicview_watchTopic(topicid)
{
	var topicObj = document.getElementById("wt"+topicid);
	$.get("../includes/ajax.inc.php?t=69&topic_id="+topicid+"&timestamp="+timeStamp, function(data)
			{
			var myRegExp = /Watching/;
			var matchPos = data.search(myRegExp);
			
			if (matchPos != -1) // found it
				{
				topicObj.innerHTML = '<img src="http://cdn.myanimelist.net/images/watch_y.gif" title="You are watching this topicd">';
				}
			else
				{
				topicObj.innerHTML = '<img src="http://cdn.myanimelist.net/images/watch_n.gif" title="You are not watching this topic">';
				}
	 		}
		);
}
