
    var VISIBLE = 5;

    var __pageNo = 0;
    var __resultsPerPage = 0;
    var __totalResults = 0;
    var __limit = 0;
    
    function setPagerParameters( pageNo, resultsPerPage, totalResults, limit ) {
	__pageNo = pageNo;
	__resultsPerPage = resultsPerPage;
	__totalResults = totalResults;
	__limit = limit;
    }
    
    function getTotalPages() {
    	var limitedTotalResults = __totalResults;
    	if ( __limit > 0 ) {
    		limitedTotalResults = __totalResults < __limit ? __totalResults : __limit;
    	}
    	return parseInt((parseInt(limitedTotalResults) + parseInt(__resultsPerPage) - 1) / parseInt(__resultsPerPage));
    }
    
    function getFirstVisibleRecord() {
    	if ( __totalResults > 0 ) {
	        return parseInt(__pageNo) * parseInt(__resultsPerPage) + 1;
	    } else {
	    	return 0;
	    }
    }
    
    function getLastVisibleRecord() {
        var tmp = (parseInt(__pageNo) + 1) * parseInt(__resultsPerPage);
        if (tmp < __totalResults) {
            return tmp;
        } else {
            return __totalResults;
        }
    }
    
    function getFirstVisiblePage() {
        if (__pageNo - VISIBLE > 0) {
            return __pageNo - VISIBLE;
        } else {
            return 0;
        }
    }
    
    function getLastVisiblePage() {
        if (getFirstVisiblePage() + (2 * VISIBLE) < getTotalPages() - 1) {
            return getFirstVisiblePage() + (2 * VISIBLE);
        } else {
            return getTotalPages() - 1;
        }
    }    
    
