var MouseX = 0;
var MouseY = 0
var ClickX = 0;
var ClickY = 0;
var admin_AJAX = null;


if (document.layers)
{

    document.captureEvents(Event.MOUSEMOVE);

}

document.onmousemove = captureMousePosition;



function captureMousePosition( e )
{

	// IE doesn't pass e.

	if (!e) e = window.event;
	if (!e) return;

	// Firefox makes it simple

	if ( e.pageX )
	{

		MouseX = e.pageX;

		MouseY = e.pageY;

		return;

	}

	// IE's mouse position is relative to the page scroll.. so we have to add it on.

	MouseX =  e.clientX + (document.documentElement.scrollLeft ?

						document.documentElement.scrollLeft :

						document.body.scrollLeft);

	MouseY =  e.clientY + (document.documentElement.scrollTop ?

						document.documentElement.scrollTop :

						document.body.scrollTop);

}

function Admin_Open( id, userid )
{

	panel = document.getElementById( id );

	if (!panel) return false;

	if (panel.style.display == 'none')
	{

		panel.style.display = 'block';

		panel.style.left = MouseX - 275 + 'px'; 

		panel.style.top = MouseY + 2 + 'px';

	}
	else
	{

		panel.style.display = 'none';

	}

	return false;

}

function Admin_Ban_Callback()
{

	if (!admin_AJAX)
	{
		location.reload();
		return;
	}

	if (admin_AJAX.handler.readyState == 4)
	{
		AdminDiv.innerHTML = OldAdmin;
		delete admin_AJAX;
		admin_AJAX = false;
		location.reload();
	}

}



function Admin_Ban( postid, userid, days )
{

	Admin_Feedback = document.getElementById( "adminidreason_" + postid );

	if (admin_AJAX)
	{
		alert( 'One at a time!' );
		return false;
	}

	if (!Admin_Feedback || Admin_Feedback.value == '')
	{
		alert( 'You didn\'t enter a reason!' );
		return false;
	}

	admin_AJAX = new vB_AJAX_Handler(true);
	admin_AJAX.onreadystatechange( Admin_Ban_Callback );
	admin_AJAX.send( 'ajax.php?do=quickadminban', 'userid=' + escape( userid ) + '&reason=' + escape( Admin_Feedback.value ) + '&postid=' + escape( postid ) + '&days=' + escape( days ) );
	Admin_Load( postid );

	return false;

}

function Admin_Load( postid )
{

	AdminDiv = document.getElementById( "adminid_" + postid );
	OldAdmin = AdminDiv.innerHTML;
	AdminDiv.innerHTML = "Loading...";

}

function Admin_DDT( gt, postid, gtitle, forumid )
{

	Admin_Feedback = document.getElementById( "adminidreason_" + postid );

	if (admin_AJAX)
	{
		alert( 'One at a time!' );
		return false;
	}

	admin_AJAX = new vB_AJAX_Handler(true);
	admin_AJAX.onreadystatechange( Admin_Ban_Callback );
	admin_AJAX.send( 'postings.php?do=domovethread&t=' + gt, 's&t=' + gt + '&do=domovethread&title=' + escape(gtitle) + '&destforumid=' + forumid +'&redirect=none' );
	Admin_Load( postid );

	return false;

}

function Admin_LockUnlock( gt, postid, gtitle )
{

	Admin_Feedback = document.getElementById( "adminidreason_" + postid );

	if (admin_AJAX)
	{
		alert( 'One at a time!' );
		return false;
	}

	admin_AJAX = new vB_AJAX_Handler(true);
	admin_AJAX.onreadystatechange( Admin_Ban_Callback );
	admin_AJAX.send( 'postings.php?do=openclosethread&t=' + gt, 's&t=' + gt + '&do=openclosethread&title=' + escape(gtitle) );
	Admin_Load( postid );

	return false;

}

function Admin_Delete( gt, postid, gtitle )
{

	Admin_Feedback = document.getElementById( "adminidreason_" + postid );

	if (admin_AJAX)
	{
		alert( 'One at a time!' );
		return false;
	}

	admin_AJAX = new vB_AJAX_Handler(true);
	admin_AJAX.onreadystatechange( Admin_Ban_Callback );
	admin_AJAX.send( 'postings.php?do=dodeletethread&t=' + gt, 's&t=' + gt + '&do=dodeletethread&deletetype=1&keepattachments=1&title=' + escape(gtitle) );
	Admin_Load( postid );

	return false;

}

function Admin_Undelete( gt, postid, gtitle )
{

	Admin_Feedback = document.getElementById( "adminidreason_" + postid );

	if (admin_AJAX)
	{
		alert( 'One at a time!' );
		return false;
	}

	admin_AJAX = new vB_AJAX_Handler(true);
	admin_AJAX.onreadystatechange( Admin_Ban_Callback );
	admin_AJAX.send( 'postings.php?do=updatethread&t=' + gt, 's&t=' + gt + '&do=updatethread&threadstatus=1&keepattachments=1&title=' + escape(gtitle) );
	Admin_Load( postid );

	return false;

}
