          // Code To add pagination to your page----Hemant Kumar Singh
function Pagernew(itemsPerPage,func) {
    this.itemsPerPage = itemsPerPage;
 	this.funname=func;
    this.currentPage = 1;
    this.pages =0;
    this.inited = false;
	
     this.init = function() {
        		
		var rows = document.getElementById('totalresult').value;		
		
		this.pages = Math.ceil(rows / itemsPerPage);
			
        this.inited = true;
    }
	
    this.showRecords = function(from) {        
   
		document.getElementById('from').value=from;
	
	 	eval(this.funname+"()");	
    }
    
    this.showPage = function(pageNumber) {
    	if (! this.inited) {
    		//alert("not inited");
    		return;
    	}
		var currentPage=document.getElementById('currentpage').value;
		
        var oldPageAnchor = document.getElementById('pagination'+currentPage);

		if(oldPageAnchor.className!='hide')
		{
        	oldPageAnchor.className = 'pagination-normal';
		}
		
       document.getElementById('currentpage').value = pageNumber;
	   
        var newPageAnchor = document.getElementById('pagination'+pageNumber);
        newPageAnchor.className = 'pagination-selected';
        
        var from = (pageNumber - 1) * itemsPerPage;
    //    var to = from + itemsPerPage - 1;
        this.showRecords(from);
    }   
    
    this.prev = function(pagevalue) {
		if(document.getElementById('limitfrom').value>1)
		{
			var fromlimit=parseInt(document.getElementById('limitfrom').value);
			var tolimit=fromlimit-1;
			var fromlimit=tolimit-4;
			for (var page = 1; page <= pagevalue; page++)
			 if (page < fromlimit || page > tolimit)
			 {
			   document.getElementById('pagination' + page).className="hide";
			   document.getElementById('pagespacediv' + page).className="hide";
			 }
			 else
			 {
				  document.getElementById('pagination'+page).className="pagination-normal";
				   document.getElementById('pagespacediv' + page).className="pagespacediv";
			 }
			 document.getElementById('limitfrom').value=fromlimit;
			 document.getElementById('limitto').value=tolimit;
			 var fromprev = (fromlimit - 1) * this.itemsPerPage;
	         var toprev = fromprev + this.itemsPerPage - 1;
			 //this.showRecords(fromprev, toprev);
			 this.showPage(fromlimit);
		}
    }
    
    this.next = function(pagevalue) {

		if(document.getElementById('limitto').value<pagevalue)
		{
			var tolimit=parseInt(document.getElementById('limitto').value);
			var fromlimit=tolimit+1;
			tolimit=fromlimit+4;
			for (var page = 1; page <= pagevalue; page++)
			 if (page < fromlimit || page > tolimit)
			 {
			   document.getElementById('pagination' + page).className="hide";
			    document.getElementById('pagespacediv' + page).className="hide";
			 }
			 else
			 {
				  document.getElementById('pagination'+page).className="pagination-normal";
				  document.getElementById('pagespacediv' + page).className="pagespacediv";
			 }
			 document.getElementById('limitfrom').value=fromlimit;
			 document.getElementById('limitto').value=tolimit;
			 this.showPage(fromlimit);
		}
    }                        
    
  
    this.showPageNav = function(pagerName, positionId) {
    	if (! this.inited) {
    	//	alert("not inited");
    		return;
    	}
    	var element = document.getElementById(positionId);
    	var fromlimit=document.getElementById('limitfrom').value;
		var tolimit=document.getElementById('limitto').value;
		var pagerHtml='';
		if(this.pages>0)
		{
    	pagerHtml = '<div class="admininp"><div onclick="' + pagerName + '.prev('+this.pages+');" class="pagination-normal"> &#171 Prev  </div>';
        for (var page = 1; page <= this.pages; page++) 
        pagerHtml += '<div id="pagespacediv' + page + '" class="pagespacediv">&nbsp;</div><div id="pagination' + page + '" class="pagination-normal" onclick="' + pagerName + '.showPage(' + page + ');">' + page + '</div>';	  
        pagerHtml += '<div class="pagespacediv">&nbsp;</div><div onclick="'+pagerName+'.next('+this.pages+');" class="pagination-normal">  Next &#187;</div></div>';            
		}
        element.innerHTML = pagerHtml;
		
		for (var page = 1; page <= this.pages; page++) 
		 if (page < fromlimit || page > tolimit)
		 {
           document.getElementById('pagination' + page).className="hide";
	       document.getElementById('pagespacediv' + page).className="hide"; 
		 }
		 else
		 {
			  document.getElementById('pagination'+page).className="pagination-normal";
			  document.getElementById('pagespacediv' + page).className="pagespacediv";
		 }
    }
}