if (window.NOF_RSN_ARRAY == null) {
    window.NOF_RSN_ARRAY = new Array();
}
  
var nof_null_rsn = new RSNavigator("",0,0,0);

function GetRSN(name) {
    if (window.NOF_RSN_ARRAY[name] != null) {
        return window.NOF_RSN_ARRAY[name];
    } else {
        return nof_null_rsn;
    }
}

function RSNavigator(queryName, currentStartRow, resultsPerPage, recordCount) {
    this.queryName        = queryName;
    this.currentStartRow  = currentStartRow;
    this.resultsPerPage   = resultsPerPage;
    this.recordCount      = recordCount;
    this.pagesNo          = Math.ceil(recordCount/resultsPerPage);
    this.lastPageStartRow = ((resultsPerPage * this.pagesNo + 1) <= recordCount) ? 
                            resultsPerPage * this.pagesNo + 1 : resultsPerPage * (this.pagesNo -1) + 1;

    RSNavigator.prototype.First = function NOF_RSNavigator_First() {
        if (this.currentStartRow > 1) {
            this.reload(1);
        }
    };

    RSNavigator.prototype.Previous = function NOF_RSNavigator_Previous(){
        if (this.currentStartRow - this.resultsPerPage >= 1) {
            this.reload(this.currentStartRow - this.resultsPerPage);                    
        }
    };

    RSNavigator.prototype.Next = function NOF_RSNavigator_Next(){
        if (this.currentStartRow + this.resultsPerPage <= this.recordCount) {
            this.reload(this.currentStartRow + this.resultsPerPage);
        }
    };

    RSNavigator.prototype.Last = function NOF_RSNavigator_Last() {
        if ( this.lastPageStartRow >  this.currentStartRow) {
            this.reload(this.lastPageStartRow);
        }
    };

    RSNavigator.prototype.reload = function NOF_RSNavigator_reload(rowNumber) {
        var startRowParam = "NOF_StartRow_"+ this.queryName;
        var newRowArg = startRowParam + "=" + rowNumber;
        if (location.search != "") {
            var paramIndex = location.search.indexOf( startRowParam );
            if (paramIndex != -1) {
                eval("re = /" + startRowParam + "=\\d+/")
                location.href = location.href.replace(re, newRowArg);
            } else {
                location.href = location.href + "&" + newRowArg;
            }
        } else {
            location.href = window.location.href +  "?" + newRowArg;
        }
    };
}
