function setPager(callback, msgHolderId)
{
	msgHolderId = msgHolderId || '#middle_right';
	
	if(parseInt(_PHP_.pager.total) > parseInt(_PHP_.pager.limit))
	{
		$('#pager').pagination(_PHP_.pager.total, 
			{
				current_page: _PHP_.pager.page||0,
				items_per_page: _PHP_.pager.limit,
				num_edge_entries: 2,
				num_display_entries: 10,
				next_text: '&nbsp',
				prev_text: '&nbsp',
				ellipse_text: '|',
				
				callback: function(page, pager)
					{
						$(msgHolderId).block(modal.wait());
						$('#bt_texto').hide().remove();
						
						$("#rows").animate({opacity: '-=1'}, 'normal', function()
							{
								if(typeof callback.before == 'function') callback.before();
								
								loadPage(page, _PHP_.pager.url, function(responseText, textStatus, XMLHttpRequest)
									{
										$(msgHolderId).unblock();
										$('#rows').animate({opacity: '+=1'}, 'fast', function()
											{
												IERacks.fixAllFonts(this);
											});
										
										if(textStatus != 'success')
										{
											$(modal.erro()).appendTo(msgHolderId).displayBox();
										}
										else
										{
											if(typeof callback.after == 'function') callback.after();	
										}
									});
							});
						return false;
					}
			}).callback(function()
				{
					var total = 0;
					$('#pager > *').each(function()
						{
							total += $(this).width() + 21;
						});
					
					$('#pager').css('width', total+'px');
				});
	}
}

function loadStartPage(page, url, hasText, callback, msgHolderId)
{
	msgHolderId = msgHolderId || '#middle_right';
	
	$(msgHolderId).block(modal.wait());
	
	loadPage(page, url, function(responseText, textStatus, XMLHttpRequest)
		{
			$(msgHolderId).unblock();
			
			if(textStatus != 'success')
			{
				$(modal.erro()).appendTo(msgHolderId).displayBox();
				if(hasText) $('#bt_texto').hide();
				$('#pager').hide();
			}
			else
			{
				$("#rows").fadeIn("slow");
			
				if(hasText)
				{
					collapses.collapsable
						({
							bt_id: '#bt_texto',
							content_id: '#collapsable',
							images: ['arrow_up', 'arrow_down'],
							speed: 'normal'
						});
				}
				
				if(typeof callback == 'function') callback();
			}
		});
}

var backup = {};
function loadRow(options)
{
	msgHolderId = options.msgHolderId || '#middle_right';
	backup.rows = $("#rows").clone();
	
	$(msgHolderId).block(modal.wait());
	$("#rows").animate({opacity: '-=1'}, 'normal', function()
		{
			if(typeof options.onload.before == 'function') options.onload.before();
			
			$("#rows").load
				(
					options.url,
					options.data,
					function(responseText, textStatus, XMLHttpRequest)
						{
							$(msgHolderId).unblock();
							
							if(textStatus != 'success')
							{
								undoLoadRow();
								$(modal.erro()).appendTo(msgHolderId).displayBox();
							}
							else
							{
								//GOOGLE ANALYTICS
								if(typeof window.pageTracker != 'undefined')
								{
									pageTracker._trackPageview(options.url);	
								}
								
								if(typeof options.onload.after == 'function') options.onload.after();
								
								$("#rows").animate({opacity: '+=1'}, 'normal', function()
									{
										IERacks.fixAllFonts(this);
										//this.scrollTop = 0;
									});
								
								if($('#voltar').html() == null)
								{
									$('#ctrl').append('<input id="voltar" class="button" type="button" value="voltar"/>').callback(function()
										{
											$('#voltar').click(function()
												{
													undoLoadRow(options.onundo);
												});
										});
								}
								
								$('#ctrl').show('slow');
							}
						}
				);
		});
	$('#ctrl').hide('fast');
}

function undoLoadRow(onundo)
{
	$("#rows").animate({opacity: "-=1"}, 'normal', function()
		{
			if(typeof onundo.before == 'function') onundo.before();
			
			$("#rows").replaceWith($(backup.rows)).animate({opacity: "+=1"}, 'normal', function()
				{
					IERacks.fixAllFonts(this);
					//this.scrollTop = 0;
					if(typeof onundo.after == 'function') onundo.after();
				});
			$('#ctrl').show();
		});
	$('#ctrl').hide('fast');
}