/*======================================================================*\
|| #################################################################### ||
|| #  				  Imperial Bulletin Board v1.x                    # ||
|| # ---------------------------------------------------------------- # ||
|| #  For license, version and changelog questions or concerns,       # ||
|| #  navigate to the docs/ folder or visit the forums at the		  # ||
|| #  website, http://www.imperialbb.com/forums. with your questions. # ||
|| # ---------------------------------------------------------------- # ||
|| # Name: js_mark_read.js                                            # ||
|| # ---------------------------------------------------------------- # ||
|| #                "Copyright(c) 2007 The iBB Group"                 # ||
|| # ---------------------------------------------------------------- # ||
|| #################################################################### ||
\*======================================================================*/

function ibb_mark_read ( ) 
{
	this.ajax 	 = null;
	this.oldlang = marker_nonew;
	var read  	 = this;

	this.marker_init = function ( fid )
	{
		var icon = $ ( 'forumid_'+fid );
		if ( icon )
		{
			if ( icon.src.match ( '_old.gif' ) || icon.src.match ( '_locked.gif' ) || icon.src.match ( '_redirect.gif' ) || (icon.title && icon.title == this.oldlang)) 
			{
				return false;
			}
			icon.style.cursor = IBB.cursor;
			icon.name 		  = fid;
			icon.onclick = function ( )
			{
				read.mark_forum_read ( parseInt ( this.name ) ); 
			};
		}
	};

	this.mark_forum_read = function ( fid ) 
	{
		this.ajax 	= new ibb_ajax ( );
		var enabled = this.ajax.ajax_enabled ( );
		if ( enabled == 1 )
		{
			var txtreturn = 0;
			this.ajax.onload = function ( data )
			{
				if ( !data )
				{
					return;
				}
				img = $ ( 'forumid_'+fid );
				imgregex 		 = new RegExp ( "forum_new\\.gif$" );
				img.src 		 = img.src.replace ( imgregex, 'forum_old.gif' );
				img.title 		 = this.oldlang;
				img.style.cursor = 'default';
				img.onclick 	 = '';
				txtreturn = data;
			}
			this.ajax.set_arg ( AJAX_GET, 'func', 'mark_read' );
			this.ajax.set_arg ( AJAX_GET, 'fid', fid );
			this.ajax.send ( root_path+'misc.php', AJAX_MODE_TXT );
			if ( txtreturn == 1 )
			{
				return false;
			}
		}
		else
		{
			read.mark_read ( fid );
			return false;	
		}
	};

	this.mark_read = function ( fid )
	{
		var rand = Math.floor ( Math.random ( ) * 1000000 );
		var url = 'misc.php?func=mark_read&fid='+fid+'&nocache='+rand;
		IBB.general.location_jump ( url, 'true', 'win' );
		return false;
	};
};
IBB.namespace ( 'mark' );
IBB.mark = new ibb_mark_read ( );

/*======================================================================*\
|| #################################################################### ||
|| #                "Copyright(c) 2007 The iBB Group"                 # ||
|| #################################################################### ||
\*======================================================================*/