// navigate to a the first page 
//
// hlima@brq.com 2008-07-22
//
function page_goto_first(){
	$j("#page").val( 1 );
	search();	
}

// navigate to a the last page 
//
// hlima@brq.com 2008-07-15
//
function page_goto_last(){
	$j('#page').val( $j('#pageTotal').val() );
	search();	
}

// navigate to a page based on the current page 
//
// hlima@brq.com 2008-07-15
//
function page_goto(relative_to_current_page ){
	$j('#page').val( parseInt($j('#page').val()) + relative_to_current_page );

	if( $j('#page').val() < 1 ) {
		 $j('#page').val(1);
	}
	search();
}

// sets the last page of the pager 
//
// hlima@brq.com,tsilveira@brq.com 2008-07-22
// hlima@brq.com 2008-08-01 - changed to use div instad of ul
//
function createPager( pageTotal ){

	$j('#pageTotal').val( pageTotal );
	var html = '';

	// Shows the pagination when appropriate
	//if (parseInt($j('#pageTotal').val()) > 1){
		//html += '<span class="pagination">Page: </span>'; 	
	//}
	
	// check if shows the first page link
	if( parseInt($j('#page').val()) > 1 ){
		html += '<a class="pagination" href="javascript:page_goto_first();"><strong>First&nbsp;</strong></a>'; 
		html += '<a class="pagination" href="javascript:page_goto_first();"><img src="images/first.gif" alt="First Page" width="8" height="14" border="0" align="absmiddle"/></a>&nbsp;&nbsp;'; 
		html += '<a class="pagination" href="javascript:page_goto(-1);"><img src="images/iconBack.gif" alt="Previous" width="8" height="14" border="0" align="absmiddle"/></a>&nbsp;'; 
	} else if (parseInt($j('#pageTotal').val()) > 1) {
		html += '<span class="pagination">First&nbsp;</span>'; 
		html += '<span class="pagination"><img src="images/first_disabled.gif" alt="First Page" width="8" height="14" border="0" align="absmiddle"/></span>&nbsp;&nbsp;'; 
		html += '<span class="pagination"><img src="images/iconBack_disabled.gif" alt="Previous" width="8" height="14" border="0" align="absmiddle"/></span>&nbsp;'; 		
	}

	// show the current page
	if (parseInt($j('#pageTotal').val()) > 1){
		html += '<span class="pagination" id="current_page"><strong>' + 
			$j("#page").val() + '</strong> of ' + $j('#pageTotal').val() + '</span>'
			'</span>'; 		
	}

	// check if shows the last page link
	if( parseInt($j('#page').val()) < parseInt($j('#pageTotal').val()) ){
		//html += '<span class="pagination" style=" font-weight:bold;">' + $j('#pageTotal').val() + '</span>'; 
		html += '&nbsp;<a class="pagination" href="javascript:page_goto(+1);"><img src="images/iconFoward.gif" alt="Next" width="8" height="14" border="0" align="absmiddle" /></a>&nbsp;&nbsp;'; 			
		html += '<a class="pagination" href="javascript:page_goto_last();"><img src="images/last.gif" alt="Last" width="8" height="14" border="0" align="absmiddle" /></a>'; 
		html += '<a class="pagination" href="javascript:page_goto_last();" style=" font-weight:bold;">&nbsp;Last</a>'; 		
	} else if (parseInt($j('#pageTotal').val()) > 1) {
		html += '&nbsp;<span class="pagination"><img src="images/iconFoward_disabled.gif" alt="Next" width="8" height="14" border="0" align="absmiddle" /></span>&nbsp;&nbsp;'; 			
		html += '<span class="pagination"><img src="images/last_disabled.gif" alt="Last" width="8" height="14" border="0" align="absmiddle" /></span>'; 
		html += '<span class="pagination">&nbsp;Last</span>'; 				
	}

	return html;
}

