/**
 * 小秘书提示
 * @package	fmw-admin
 * @copyright Copyright (c) 2010, fmworlds.com
 * @author	 zx
 */
 
var clerk =
{
	frame:'clerkTipsFrame',
	body:'clerkTipsBody',
	page:'clerkTipsPage',
	ts:false,
	limit:0,
	index:0,
	list:[],
	prev:0,
	next:0,
	total:0,
	cache:0,
	id:[],
	tipTime:false,
	tips: function(txt)
	{
		var txt = txt || false;
		
		if(!clerk.ts)
		{
			clerk.ts = document.title;
		}
		
		clerk.result(txt);
	},
	result: function(txt)
	{
		var txt = txt || '';
		
		if(txt)
		{
			eval('var data=' + txt);
			
			if(data.data)
			{
				var list = data.data.split(';;');
				var len = list.length - 1;
				
				if(this.index >= clerk.total)
				{
					for(var i = 0; i < len; i++)
					{
						var ls = list[i].split(':=:');
						clerk.id.push(ls[0]);
						clerk.list.push(ls[1]);
					}
				}
				
				clerk.total = clerk.list.length;
			}
			
			clerk.next = clerk.total > clerk.index + 1 ? clerk.index + 1 : -1;
			clerk.prev = clerk.index > 0 ? clerk.index - 1 : -1;
			clerk.showContent( );
			document.getElementById(clerk.page).innerHTML = (clerk.prev >= 0 ? '<a href="javascript:clerk.prevShow( );">上一条</a>' : '<span>上一条</span>') + ' ' + (clerk.index + 1) + '/' + (clerk.total > 0 ? clerk.total : 1) + ' ' + (clerk.next >= 0 ? '<a href="javascript:clerk.nextShow( );">下一条</a>' : '<span>下一条</span>');
		}
		else
		{
			clerk.frameHide( );
		}
	},
	nextShow: function( )
	{
		if(this.total > this.next)
		{ 
			this.prev = this.index;
			this.index = this.next;
			this.next = this.index + 1;
		}
		else
		{
			this.next = -1;
		}
		
		this.showContent( );
	},
	prevShow: function( )
	{
		if(this.prev >= 0)
		{
			this.next = this.index;
			this.index = this.prev;
			this.prev = this.index - 1;
		}
		else
		{
			this.prev = -1;
		}
		
		this.showContent( );
	},
	frameHide: function( )
	{
		var frame = document.getElementById(this.frame);
		
		if(frame)
		{
			frame.style.display = 'none';
			return(true);
		}
		
		return(false);
	},
	frameShow: function( )
	{
		var frame = document.getElementById(this.frame);
		
		if(frame)
		{
			frame.style.display = 'block';
			return(true);
		}
		
		return(false);
	},
	showContent: function( )
	{
		if(this.list[this.index])
		{
			if(this.index <= this.cache)
			{
				document.getElementById(this.body).innerHTML = this.list[this.index];
				document.getElementById(this.page).innerHTML = (this.prev >= 0 ? '<a href="javascript:clerk.prevShow( );">上一条</a>' : '<span>上一条</span>') + ' ' + (this.index + 1) + '/' + (this.total > 0 ? this.total : 1) + ' ' + (this.next >= 0 ? '<a href="javascript:clerk.nextShow( );">下一条</a>' : '<span>下一条</span>');
				this.frameShow( );
				clerk.tipTime = window.setTimeout('clerk.tipUser( )', 500);
			}
			else
			{
				this.cache++;
				document.getElementById(this.body).innerHTML = this.list[this.index];
				fajax('/vclerk/clerk.php?a=ajax&s=' + this.id[this.index], '', this.result, true);
				document.getElementById(this.page).innerHTML = '传输中...请等待...';
				this.frameShow( );
			}
		}
		else
		{
			this.frameHide( );
		}
	},
	tipUser: function( )
	{
		if(!document.hasFocus( ))
		{
			if(this.limit > 0)
			{
				document.title = clerk.ts;
				this.limit = 0;
			}
			else
			{
				document.title = '【秘书提醒，您有新消息！】';
				this.limit++;
			}
			
			clerk.tipTime = window.setTimeout('clerk.tipUser( )', 500);
		}
	},
	noTip: function( )
	{
		if(clerk.ts)
		{
			window.clearTimeout(clerk.tipTime);
			document.title = clerk.ts;
		}
	},
	close: function( )
	{
		this.frameHide( );
		clerk.total = 0;
		clerk.list = new Array( );
	}
};
