
MouseX = 0;
MouseY = 0;

$().mousemove( function(e)
				{
					MouseX = e.pageX;
					MouseY = e.pageY;
				}
			);

function RateThread( params )
{
	$.post( '/threadrate.php', params );
	$('#threadrating_input')[0].innerHTML = "Rated!";
	$('#threadrating_input').fadeOut( 5000 );
	return false;
}

function RateThreadInline( boss, params )
{
	$.post( '/threadrate.php', params );
	$(boss)[0].innerHTML = "Thanks!";
	$('#threadrating_input').fadeOut( 1000 );
	return false;
}

function AdminThreadReply( data )
{
	$('#threadadmin')[0].innerHTML += data.response + "<br />";
}

function AdminThread( typename, threadid, verify, value )
{
	if (!value) value = $( '#ThreadAdmin' )[0].value;
	
	$.post( "fp_qadmin.php", { type: 'thread', action: typename, threadid: threadid, value: value, verify: verify }, AdminThreadReply, "json" );	  
	$('#threadadmin')[0].innerHTML += "<font color=green>>>" + typename + "..</font><br />";
	return false;
}

function AdminPostReply( data, postid )
{
	$( '#postadmin_'+postid )[0].innerHTML += data.response + "<br />";
}

function AdminUser( typename, userid, postid, verify )
{
	var value = $( '#PAR_'+postid )[0].value;

	$.post( "fp_qadmin.php", { type: 'user', action: typename, userid: userid, postid: postid, value: value, verify: verify }, function( d ) { AdminPostReply( d, postid ); }, "json" );	  
	$( '#postadmin_'+postid )[0].innerHTML += "<font color=green>>>" + typename + "..</font><br />";
	return false;
}

function OpenPostAdmin( threadid, postid, userid, verify )
{
	if ( $( '#postadmin_'+postid )[0] )
	{
		$( '#postadmin_'+postid ).toggle( 'fast' );
		return false;
	}
	
	var div = document.createElement( 'div' );
	div.id = 'postadmin_'+postid;
	div.className = 'postadmin';
	div.style.left = MouseX-180 + 'px';
	div.style.top = MouseY + 'px';
	div.style.display = 'none';
	
	div.innerHTML += 'Ban:';
	div.innerHTML += '<hr/>';
	div.innerHTML += '<a href="#" onclick="return AdminUser( \'unban\', '+userid+', '+postid+', \''+verify+'\' );">UNBAN</a> | ';
	div.innerHTML += '<a href="#" onclick="return AdminUser( \'ban1h\', '+userid+', '+postid+', \''+verify+'\' );">1H</a> ';
	div.innerHTML += '<a href="#" onclick="return AdminUser( \'ban1d\', '+userid+', '+postid+', \''+verify+'\' );">1D</a> ';
	div.innerHTML += '<a href="#" onclick="return AdminUser( \'ban1w\', '+userid+', '+postid+', \''+verify+'\' );">1W</a> ';
	div.innerHTML += '<a href="#" onclick="return AdminUser( \'banp\', '+userid+', '+postid+', \''+verify+'\' );">PERM</a>';
	div.innerHTML += '<input id="PAR_'+postid+'">';
	
	
	div.innerHTML += '<br/>Post Actions: <hr/>';
	
	div.innerHTML += '<a href="#" onclick="return AdminUser( \'delpost\', '+userid+', '+postid+', \''+verify+'\' );">Delete</a> | ';
	div.innerHTML += '<a href="#" onclick="return AdminUser( \'undelpost\', '+userid+', '+postid+', \''+verify+'\' );">UnDelete</a>';
	
	document.body.appendChild( div );
	$( div ).show( 'fast' );
	
	$( '#PAR_'+postid ).focus();
	
	return false;
}

function CreateFloatingDiv( x, y, id )
{
	var Exists = $( '#'+id );
	if ( Exists[0] )
	{	
		Exists[0].style.left = x + 'px';
		Exists[0].style.top = y + 'px';
		Exists[0].style.display = 'none';
		Exists.show( 'fast' );
		return;
	}
	
	var div = document.createElement( 'div' );
	div.style.left = x + 'px';
	div.style.top = y + 'px';
	div.style.position = "absolute";
	div.style.background = "#ffd";
	div.style.border = "1px solid #777";
	div.style.padding = '5px';
	div.style.color = '#555';
	div.style.fontSize = '11px';
	div.style.display = 'none';
	div.className = "top";
	div.id = id;
	
	document.body.appendChild( div );
	
	$( div ).show( 'fast' );
	
	return div;
}

function OpenEvent( $data, $id )
{
	var div = CreateFloatingDiv( MouseX, MouseY, 'Event_'+$id );
	if (!div) return false;
	
	div.innerHTML += 'Fetching..';
	$(div).click( function(){ $(div).hide(); } );
	
	$( div ).show( 'fast' );
	
	$.get( '/fp_events.php', 'aj=1&' + $data, function( d ) { div.innerHTML = d; }, "html" );  
	return false;
}

function ReportPost( $postid )
{
	var div = CreateFloatingDiv( MouseX, MouseY, 'Report_'+$postid );
	if (!div) return;
	div.innerHTML = 'Wait..';
	
	$.get( '/fp_report.php', '&postid=' + $postid, function( d ) { div.innerHTML = d; }, "html" );
}

function SendReportPost( $PostID, $id )
{
	$.post( '/fp_report.php', '&action=report&postid=' + $PostID + '&reasonid=' + $id, function( d ) { if (d) (alert(d)); }, "html" );
}

function CloseThis( pChild, reason )
{
	if ( $( pChild ).hasClass("top") )
	{
		if ( reason )
		{
			pChild.innerHTML = reason;
			$(pChild).fadeOut( 3000 );
		}
		else
		{
			$( pChild ).hide();
		}
		
		return false;
	}
	
	return CloseThis( pChild.parentNode, reason );
}

function OpenURLInBox( $name, $url )
{
	var div = CreateFloatingDiv( MouseX, MouseY, $name );
	if (!div) return false;
	
	div.innerHTML += 'Fetching..';
	$(div).click( function(){ $(div).hide(); } );
	
	$( div ).show( 'fast' );
	
	$.get( $url, '', function( d ) { div.innerHTML = d; }, "html" );  
	return false;
}

function RatePost( id, params )
{
	$.post( '/fp_ratings.php', params );
	$(id)[0].innerHTML = "Rated!";
	return false;
}

function OnHoverPost( pid )
{
	$( '#postrating_' + pid ).show();
}

function OnUnHoverPost( pid )
{
	$( '#postrating_' + pid ).hide();
}