﻿function Pagination() {
    this.Ajax = new ajax();
    this.strpage = new String('');
    this.pageprev = new Number();
    this.pagenext = new Number();
    this.pagereminder = new Number(4);
    this.CurrentPage = new Number();
    this.TotalPage = new Number();
    this.Links = new String();
    this.Method = new Number();
    this.parameters = new String();
    this.Obj = new String();
    this.Class = new String('');
    this.ClassObj = new Object();
    
}

Pagination.prototype.Show = function() {




    if (parseInt(this.TotalPage) > 1) {


        this.strpage = '<span title="انتقل إلى الصفحة ..." class="pagelink"><a href="javascript:' + this.Class + '.Page.Enter();">عدد الصفحات : ' + this.TotalPage + '</a></span>&nbsp;'
        if (parseInt(this.CurrentPage) > 1) {
            this.pageprev = parseInt(this.CurrentPage) - 1;

            this.strpage += '&nbsp;<span title="الصفحة الأول" class=pagelinklast><a  href="javascript:' + this.Class + '.DoPageing(\'' + this.Links + '&pageno=1\', ' + this.Method + ', \'' + this.parameters + '\');">«</a></span>';
            this.strpage += '&nbsp;<span title="الصفحة السابقة" class=pagelink><a  href="javascript:' + this.Class + '.DoPageing(\'' + this.Links + '&pageno=' + this.pageprev + '\', ' + this.Method + ', \'' + this.parameters + '\');">&lt;</a></span>';


            for (var i = parseInt(this.pagereminder); i > 0; i--) {

                this.sum = parseInt(this.CurrentPage) - parseInt(i);

                if (parseInt(this.sum) > 0) {

                    this.strpage += '&nbsp;<span class=pagelink><a  href="javascript:' + this.Class + '.DoPageing(\'' + this.Links + '&pageno=' + this.sum + '\', ' + this.Method + ', \'' + this.parameters + '\');">' + this.sum + '</a></span>&nbsp;';

                }

            }

        }



        this.strpage += '&nbsp;<span class=pagecurrent>' + this.CurrentPage + '</span>&nbsp;';


        if (parseInt(this.CurrentPage) < parseInt(this.TotalPage)) {

            this.pagenext = parseInt(this.CurrentPage) + 1;


            for (var i = 0; i < parseInt(this.pagereminder); i++) {

                this.sum = parseInt(this.CurrentPage) + parseInt(i) + 1;

                if (parseInt(this.sum) > 0 && parseInt(this.sum) <= this.TotalPage) {

                    this.strpage += '&nbsp;<span class=pagelink><a  href="javascript:' + this.Class + '.DoPageing(\'' + this.Links + '&pageno=' + this.sum + '\', ' + this.Method + ', \'' + this.parameters + '\');">' + this.sum + '</a></span>&nbsp;';

                }

            }


            this.strpage += '&nbsp;&nbsp;<span title="الصّفحة التّالية" class=pagelink><a  href="javascript:' + this.Class + '.DoPageing(\'' + this.Links + '&pageno=' + this.pagenext + '\', ' + this.Method + ', \'' + this.parameters + '\');">&gt;</a></span>';
            this.strpage += '&nbsp;<span title="الصفحة الأخيرة" class=pagelinklast><a  href="javascript:' + this.Class + '.DoPageing(\'' + this.Links + '&pageno=' + this.TotalPage + '\', ' + this.Method + ', \'' + this.parameters + '\');">»</a></span>';



        }
    }
    else {
        this.strpage = '';
    }
    $(this.Obj).innerHTML = this.strpage;




}
Pagination.prototype.Enter = function() {

    this.pageno = prompt("أدخل رقم الصفحة التي تود الإنتقال إليها:", "");


    if (this.pageno) {
        if (parseInt(this.pageno) >= 1 && parseInt(this.pageno) <= parseInt(this.TotalPage)) {



            
            this.ClassObj.DoPageing(this.Links + '&pageno=' + this.pageno, this.Method, this.parameters);
        }


        else {

            alert('القيمة المدخلة يجب أن تترواح ما بين 1 إلى ' + this.TotalPage);
        }
    }

}



