function Pager(totalpages) {
    this.currentPage = 1;
    this.pages = totalpages;
    this.pno = 1;

//    var iFra = document.getElementById('contentframe');
//    var urlstr = ifr.src;
//    var strMatch = "?PageNo=";
//    urlstr = urlstr.substring(urlstr.indexOf(strMatch) + strMatch.length);
//    alert(urlstr);
    
    var urlstr = window.location.href;
    if (urlstr.indexOf('/cur/') > -1) {
        urlstr = urlstr.substring(0, urlstr.lastIndexOf('/cur/'))
        urlstr = urlstr.substring(urlstr.lastIndexOf('/') + 1)
    }
    else {
        urlstr = urlstr.substring(window.location.href.lastIndexOf('/') + 1)
    }
    
    if (isNaN(parseInt(urlstr)) == false) {
        this.pno = urlstr;
    }
//    var qsvar=urlstr.split("&");
//    var qsval;
//    for (var i=0;i<qsvar.length;i++)
//    {
//        qsval=qsvar[i].split("=");
//        if (qsval[0]=="Pno")
//        {
//            this.pno=qsval[1];
//            break;
//        }
    //    }
    
    this.currentPage = parseInt(this.pno);

    this.inited = false;
    var itemsPerPage=3;
    this.showRecords = function(from, to) {        
    }

    this.showPage = function(pageNumber) {
        if (!this.inited) {
            alert("not inited");
            return;
        }
        var ifr = document.getElementById('contentframe');
        if (pageNumber > 0) {
            var str = window.parent.location.href;
            if (str.indexOf('/page/') > -1) {
                if (str.indexOf('/cur/') > -1) {
                    ifr.src = "../../../../../../Products/MultiProductPage.aspx?PageNo=" + pageNumber;
                }
                else {
                    ifr.src = "../../../../Products/MultiProductPage.aspx?PageNo=" + pageNumber;
                }
            }
            else if (str.indexOf('/cur/') > -1) {
                    ifr.src = "../../../../Products/MultiProductPage.aspx?PageNo=" + pageNumber;
            }
            else {
                ifr.src = "../../Products/MultiProductPage.aspx?PageNo=" + pageNumber;
            }
        }
        var oldPageAnchor = document.getElementById('pg' + this.currentPage);
        oldPageAnchor.className = 'pg-normal';

        this.currentPage = pageNumber;
        var newPageAnchor = document.getElementById('pg' + this.currentPage);
        newPageAnchor.className = 'pg-selected';


        if (this.currentPage < 10) {
            for (var pageno = 11; pageno <= this.pages; pageno++) {
                var tmpanchor = document.getElementById('pg' + pageno);
                if (tmpanchor != null)
                    tmpanchor.style.display = 'none';
            }
        }
        else {
            this.RangeChk = function(rangemin, rangemax, valu) {
                if ((valu >= rangemin) && (valu <= rangemax))
                    return true;
                else
                    return false;
            }

            if ((this.currentPage % 10) == 0 && this.currentPage < this.pages) {
                for (var pageno = 1; pageno <= this.pages; pageno++) {
                    var tmpanchor = document.getElementById('pg' + pageno);
                    if (tmpanchor != null) {
                        if (this.RangeChk(this.currentPage - 10, this.currentPage, pageno)) {
                            tmpanchor.style.display = '';
                        }
                        else {
                            if (this.RangeChk(this.currentPage, this.currentPage + 10, pageno)) {
                                tmpanchor.style.display = '';
                            }
                            else {
                                tmpanchor.style.display = 'none';
                            }
                        }
                    }
                }
            }
        }

        var from = (pageNumber - 1) * itemsPerPage + 1;
        var to = from + itemsPerPage - 1;
        this.showRecords(from, to);
    }   
    
    this.prev = function() {
        if (this.currentPage > 1)
            this.showPage(this.currentPage - 1);
    }
    
    this.next = function() {
        if (this.currentPage < this.pages) {
            this.showPage(this.currentPage + 1);
        }
    }                        
    
    this.init = function() {
//        var rows = document.getElementById(tableName).rows;
//        var records = (rows.length - 1); 
//        this.pages = Math.ceil(records / itemsPerPage);
        this.inited = true;
    }

    this.showPageNav = function(pagerName, positionId) {
    	if (! this.inited) {
    		alert("not inited");
    		return;
    	}
    	var element = document.getElementById(positionId);
    	if (element != null)
    	{
	        var pagerHtml = '<span onclick="' + pagerName + '.prev();" class="pg-normal"> &#171 Prev </span>';
            for (var page = 1; page <= this.pages; page++) 
                pagerHtml += '<span id="pg' + page + '" style="white-space:nowrap;" class="' + (this.pno!=page?"pg-normal":"pg-selected") + '" onclick="' + pagerName + '.showPage(' + page + ');" >&nbsp;' + page + '&nbsp;</span>';
            pagerHtml += '<span onclick="'+pagerName+'.next();" class="pg-normal"> Next &#187;</span>';            
            
            element.innerHTML = pagerHtml;
        }
    }
}

