Index: /branches/2.2.0.1/expressoMail1_2/js/search.js
===================================================================
--- /branches/2.2.0.1/expressoMail1_2/js/search.js	(revision 4686)
+++ /branches/2.2.0.1/expressoMail1_2/js/search.js	(revision 4701)
@@ -4,8 +4,11 @@
 	function searchE()
 	{
+		this.totalPages = 1;
+		this.numPages = 5;
+		this.lastPage = 0;
 		this.searchW   		= [];
 		this.condition		= "";
 		this.sort_type		= "";
-		this.page 			= 0;
+		//this.page 			= 0;
 		this.name_box_search = "";
 		this.all_boxes		= [];
@@ -247,5 +250,5 @@
 	{
 		var span_pg = Element("span_paging"+currentTab);
-		
+
 		if( span_pg == null )
 		{
@@ -255,34 +258,96 @@
 		else
 			span_pg.innerHTML = "";
-		
-		if ( size > preferences.max_email_per_page )
-		{
-			for ( var i = (this.page > 2 ? this.page-2 : 0) ; i <= parseInt( this.page )+4 ; i+= 1 )
-			{
-				if( ( i * preferences.max_email_per_page ) > size)
-				{
-					break;
-				}
-
-				if( this.page == i )
-				{
-					var _link = document.createElement('span');
-						_link.setAttribute("style", "font-weight:bold; color:red")
-						_link.innerHTML = ( this.page + 1 ) + "&nbsp;&nbsp;";
-				}
-				else
-				{
-					var _page = i;
-					var _link = document.createElement('A');					
-						_link.innerHTML = ( _page + 1 ) + "&nbsp;&nbsp;";
-						_link.href  = 'javascript:EsearchE.page='+i+';';
-						_link.href += 'cExecute("$this.imap_functions.search_msg",openpage,"condition='+this.condition+'&sort_type='+this.sort_type+'&page='+_page+'&current_tab='+currentTab+'");';
-				}
-						
-				span_pg.appendChild( _link );
-			}
-
-			Element("div_menu_c3").appendChild(span_pg);
-		}
+
+		if(size > parseInt(preferences.max_email_per_page)) {
+		    this.totalPages = parseInt(size/preferences.max_email_per_page);
+		    if((size/preferences.max_email_per_page) > this.totalPages)
+			this.totalPages++;
+		}
+
+		if(this.page != 0) {
+		    _link = document.createElement("A");
+		    _link.href  = 'javascript:EsearchE.page=0;';
+		    _link.href += 'cExecute("$this.imap_functions.search_msg",openpage,"condition='+this.condition+'&sort_type='+this.sort_type+'&page=0&current_tab='+currentTab+'");';
+		}
+		else {
+		    _link = document.createElement("SPAN");
+		}
+		span_pg.appendChild(_link);
+
+		_link.innerHTML = "&lt;&lt;";
+		_link.title = get_lang("First");
+		span_pg.innerHTML += "&nbsp;";
+
+		if(this.page == this.lastPage + (this.numPages))
+		{
+		    this.lastPage = this.page - 1;
+		}
+		else if((this.lastPage != 0 && this.lastPage == this.page) || this.page == (this.totalPages-1))
+		{
+		    this.lastPage = this.page - (this.numPages - 1);
+		}
+		else if(this.page == 0)
+		{
+		    this.lastPage = 0;
+		}
+
+		if(this.lastPage < 0)
+		    this.lastPage = 0;
+		else if(this.lastPage > 0 && (this.lastPage > (this.totalPages -(this.numPages - 1))))
+		    this.lastPage = this.totalPages -(this.numPages);
+
+		var hasMarked = false;
+		for(i = this.lastPage; i <= this.totalPages; i++)
+		{
+			if( ( i * preferences.max_email_per_page ) > size)
+			{
+				break;
+			}
+
+			if( this.page == i || (i == this.totalPages && !hasMarked) )
+			{
+				var _link = document.createElement('span');
+					_link.setAttribute("style", "font-weight:bold; color:red")
+					_link.innerHTML = ( this.page + 1 ) + "&nbsp;&nbsp;";
+			}
+			else
+			{
+				var _page = i;
+				var _link = document.createElement('A');
+					_link.innerHTML = ( _page + 1 ) + "&nbsp;&nbsp;";
+					_link.href  = 'javascript:EsearchE.page='+i+';';
+					_link.href += 'cExecute("$this.imap_functions.search_msg",openpage,"condition='+this.condition+'&sort_type='+this.sort_type+'&page='+_page+'&current_tab='+currentTab+'");';
+			}
+			_link.innerHTML = "&nbsp;...&nbsp;";
+			if(i == (this.lastPage + this.numPages))
+			{
+			    span_pg.appendChild( _link );
+			    break;
+			}
+			else if(this.lastPage == 0 || i != this.lastPage)
+			{
+			    _link.innerHTML = "&nbsp;"+( i + 1 )+"&nbsp;";
+			}
+			//span_pg.innerHTML += "&nbsp;";
+
+			span_pg.appendChild( _link );
+		}
+
+		if(this.page != (this.totalPages - 1)) {
+		    _link = document.createElement("A");
+		    _link.href  = 'javascript:EsearchE.page='+(this.totalPages-1)+';';
+		    _link.href += 'cExecute("$this.imap_functions.search_msg",openpage,"condition='+this.condition+'&sort_type='+this.sort_type+'&page='+(this.totalPages-1)+'&current_tab='+currentTab+'");';
+		}
+		else {
+		    _link = document.createElement("SPAN");
+		}
+
+		span_pg.innerHTML += "&nbsp;";
+		span_pg.appendChild(_link);
+
+		_link.title = get_lang("Last");
+		_link.innerHTML += "&gt;&gt;";
+
+		Element("div_menu_c3").appendChild(span_pg);
 	}
 
