﻿/******************************* * Start of Listener Functions * *******************************/
/* create an event queue ***/
Listener = function(src) {
    this.src = src;
    this.callStack = [];
};
/*The Listener class uses encapsulation to associate a callStack with the object. 
The object's event handler is assigned to an anonymous function returned from Listener.fire*/
Listener.instances = {};
Listener.getInstance = function(src, sEvent, oScope) {
    var bucket = Listener.instances[sEvent]
         || (Listener.instances[sEvent] = []);

    for (var i = bucket.length - 1; i >= 0; i--)
        if (bucket[i].src == src)
        return bucket[i];

    // not found.
    var listener = new Listener(src);
    if (src[sEvent]) {
        listener.callStack[listener.callStack.length] = src[sEvent];
    }
    src[sEvent] = Listener.fire(listener, oScope || src);
    return bucket[bucket.length] = listener;
};
/*Creates and returns a function reference. 
Using a closure to assign each function in the Listener's callStack to the object*/
/*the function returned by Listener.fire is executed 
in the context of the Listener's src property (object itself), or if Scope is specified, 
in the context of the Scope parameter object*/
Listener.fire = function(listener, src) {
    return function(e) {
        for (var i = listener.callStack.length - 1; i >= 0; i--) {
            src.__scopeFix = listener.callStack[i];
            src.__scopeFix(e);
        }
        src.__scopeFix = null;
    };
};
Listener.add = function(src, sEvent, fp, oScope) {
    var callStack = Listener.getInstance(src, sEvent, oScope).callStack;
    callStack[callStack.length] = fp;
};

Listener.remove = function(src, sEvent, fp, oScope) {
    var idx = this.findForEvent(src[sEvent], fp, oScope);
    if (idx != -1) {
        var iLast = src[sEvent]._listeners.length - 1;
        src[sEvent]._listeners[idx] = src[sEvent]._listeners[iLast];
        src[sEvent]._listeners.length--;
    }
};

Listener.cleanUp = function() {
    for (var type in Listener.instances) {
        var bucket = Listener.instances[type];
        var i = bucket.length - 1;
        while (i >= 0)
            bucket[i--][type] = null;
    }
    if (window.CollectGarbage && i > 15)
        window.CollectGarbage();
};
Listener.add(window, "unload", Listener.cleanUp);

/******************************* * End of Listener Functions * *******************************/


/******************************* * Start of Carousel Class Definitions * *******************************/

var CarouselClass = function(carouselobj, visibleNum, speedScroll, easingFunction, scrollType, autoScrollTimer, randomStartForAuto, carouselHeight, carouselWidth, carouselItemLeftPad, carouselItemRightPad) {
    this.carousel = carouselobj;
    this.numVisible = visibleNum;
    this.scrollSpeed = speedScroll;
    this.easing = easingFunction;
    this.scrollType = scrollType;
    this.trackWidth = 0;
    this.timer = 0;
    this.timeout = autoScrollTimer; //3500;
    this.currentElement = 0;
    this.elementLeftPad = 0;
    this.elementRightPad = 0;
    this.randomStartForAuto = randomStartForAuto;
    this.init = function() {
        var carouselClipClass = "carousel-clip-region";
        var carouselListClass = "carousel-list";
        var prevElementClass = "carousel-prev";
        var nextElementClass = "carousel-next";

        //Carousel Clip Div
        this.carouselClip = this.getElementsByClassName(carouselClipClass, "div", this.carousel)[0];
        //UL
        this.carouselList = this.getElementsByClassName(carouselListClass, "ul", this.carousel)[0];
        //Right Arrow and Left Arrow
        this.prevButtonElement = this.getElementsByClassName(prevElementClass, "div", this.carousel)[0];
        this.nextButtonElement = this.getElementsByClassName(nextElementClass, "div", this.carousel)[0];
        this.size = this.carouselList.getElementsByTagName("li").length;

        //Set Carousel Height
        this.carousel.style.height = (this.isInteger(carouselHeight)) ? carouselHeight + "px" : "400px";

        //Set Carousel Width
        this.carousel.style.width = (this.isInteger(carouselWidth)) ? carouselWidth + "px" : "454px";

        //Set Item Left and Right Paddings
        if (this.isInteger(carouselItemLeftPad) && this.isInteger(carouselItemRightPad)) {
            for (var i = 0; i < this.size; i++) {
                this.carouselList.getElementsByTagName("li")[i].style.paddingLeft = carouselItemLeftPad + "px";
                this.carouselList.getElementsByTagName("li")[i].style.paddingRight = carouselItemRightPad + "px";
            }
        }

        //Element paddings
        this.elementLeftPad = parseFloat(this.carouselList.getElementsByTagName("li")[0].currentStyle["paddingLeft"]);
        this.elementRightPad = parseFloat(this.carouselList.getElementsByTagName("li")[0].currentStyle["paddingRight"]);

        this.getLiElementSize();

        //total Size of visible portion
        //this.visiblePortion=(this.numVisible)*(this.elementSize); ////BEFORE
        this.visiblePortion = parseFloat(this.carousel.currentStyle["width"]);
        this.scrollAmount = parseFloat(this.carousel.currentStyle["width"]);
        this.totalSize = (this.size) * (this.elementSize) + (this.size * this.elementLeftPad) + (this.size * this.elementRightPad);
        this.initialDisplay();
        this.determineEasingFunction();
        var oThis = this;
        Listener.add(this.carousel, "onmouseover", oThis.stopRollup, oThis);
        Listener.add(this.carousel, "onmouseout", oThis.resumeRollup, oThis);
        Listener.add(this.nextButtonElement, "onclick", oThis.showNext, oThis);
        Listener.add(this.prevButtonElement, "onclick", oThis.showPrev, oThis);
    };


    //For Auto scrolling, picks up a random start frame
    this.randomAutoStart = function() {
        var rnd = 0;
        var totalFrames = 0;
        if (this.scrollType == 1 && this.randomStartForAuto == 1)//Auto
        {
            totalFrames = Math.ceil(this.totalSize / this.scrollAmount);
            rnd = Math.ceil(Math.random() * totalFrames);
            for (var i = 1; i <= rnd; i++) {
                this.Next();
            }
        }
    }

    //this.InitialDisplay=function()
    this.initialDisplay = function() {
        this.carouselList.className = "carousel-list";
        this.carouselClip.style.width = this.visiblePortion;
        this.carouselClip.style.display = "block";
        this.carousel.style.display = "block";

        //set the width of each li
        for (var i = 0; i < this.size; i++) {
            this.carouselList.getElementsByTagName("li")[i].style.width = this.elementSize + "px";
        }

        //Toggle navigation elements for linear scrolling type
        if (this.scrollType == 2)
            this.prevButtonElement.style.visibility = "hidden";
    };

    //this.getElementsByClassName=function(className, tag, elm)
    this.getElementsByClassName = function(className, tag, elm) {
        var testClass = new RegExp("(^|\\s)" + className + "(\\s|$)");
        var tag = tag || "*";
        var elm = elm || document;
        var elements = (tag == "*" && elm.all) ? elm.all : elm.getElementsByTagName(tag);
        var returnElements = [];
        var current;
        var length = elements.length;
        for (var i = 0; i < length; i++) {
            current = elements[i];
            if (testClass.test(current.className)) {
                returnElements.push(current);
            }
        }
        return returnElements;
    };

    this.showNext = function() {
        if (this.timer) {
            clearTimeout(this.timer);
        }
        this.Next();
    };
    this.Next = function() {
        if (((this.trackWidth * -1) + this.scrollAmount) < this.totalSize) {
            this.currentElement += this.currentElement;
            this.trackWidth = this.trackWidth * -1;
            var t1 = new CarouselAnimation(this.carouselList.style, 'left', this.easingFunction, -(this.trackWidth), -(this.trackWidth + this.scrollAmount), this.scrollSpeed, 'px');
            this.trackWidth = this.trackWidth + this.scrollAmount;
            this.trackWidth = this.trackWidth * -1;

            /** BEGIN: CustomEaseIn validation 
            /** For CustomEaseIn, this calls t1.customEaseInStart() function.
            /** for all other easing types, it calls the t1.start() function.**/
            if (this.easing == 7)
                t1.customEaseInStart();
            else
                t1.start();
            /** END: CustomEaseIn validation  **/

            //Toggle navigation elements for linear scrolling type
            if (this.scrollType == 2) {
                this.prevButtonElement.style.visibility = "visible";
                if ((this.trackWidth * -1) + (this.scrollAmount) >= this.totalSize)
                    this.nextButtonElement.style.visibility = "hidden";
            }
        }
        else {
            if (this.scrollType == 1 || this.scrollType == 3) {
                this.trackWidth = -this.visiblePortion;
                t1 = new CarouselAnimation(this.carouselList.style, 'left', this.easingFunction, -(this.trackWidth), -(this.trackWidth + this.visiblePortion), this.scrollSpeed, 'px');
                this.trackWidth = this.trackWidth + this.visiblePortion;
                this.trackWidth = this.trackWidth * -1;
                /** BEGIN: CustomEaseIn validation 
                /** For CustomEaseIn, this calls t1.customEaseInStart() function.
                /** for all other easing types, it calls the t1.start() function.**/
                if (this.easing == 7)
                    t1.customEaseInStart();
                else
                    t1.start();
                /** END: CustomEaseIn validation  **/
            }
        }
    };

    this.showPrev = function() {
        if (this.trackWidth < 0) {
            var t1 = new CarouselAnimation(this.carouselList.style, 'left', this.easingFunction, (this.trackWidth), (this.trackWidth + this.scrollAmount), this.scrollSpeed, 'px');
            this.trackWidth = this.trackWidth + this.scrollAmount;
            /** BEGIN: CustomEaseIn validation 
            /** For CustomEaseIn, this calls t1.customEaseInStart() function.
            /** for all other easing types, it calls the t1.start() function.**/
            if (this.easing == 7)
                t1.customEaseInStart();
            else
                t1.start();
            /** END: CustomEaseIn validation  **/

            //Toggle navigation elements for linear scrolling type
            if (this.scrollType == 2) {
                this.nextButtonElement.style.visibility = "visible";
                if (this.trackWidth == 0)
                    this.prevButtonElement.style.visibility = "hidden";
            }
        }
        else {
            if (this.scrollType == 1 || this.scrollType == 3) {
                this.trackWidth = -(this.totalSize);
                var t1 = new CarouselAnimation(this.carouselList.style, 'left', this.easingFunction, (this.trackWidth), (this.trackWidth + this.scrollAmount), this.scrollSpeed, 'px');
                this.trackWidth = this.trackWidth + this.scrollAmount;
                /** BEGIN: CustomEaseIn validation 
                /** For CustomEaseIn, this calls t1.customEaseInStart() function.
                /** for all other easing types, it calls the t1.start() function.**/
                if (this.easing == 7)
                    t1.customEaseInStart();
                else
                    t1.start();
                /** END: CustomEaseIn validation  **/
            }
        }
    };

    //Size of each Li
    this.getLiElementSize = function() {
        var li = this.carouselList.getElementsByTagName("li")[0];
        var carouselWidth = parseFloat(this.carousel.currentStyle["width"]);
        var calcElementSize = parseFloat((carouselWidth - ((this.numVisible * this.elementLeftPad) + (this.numVisible * this.elementRightPad))) / this.numVisible);

        //Resize the carousel width if required.
        this.resizeWidth(calcElementSize, carouselWidth);
        this.elementSize = parseInt(calcElementSize);
        this.carouselList.style.position = "relative";
    }
    this.isInteger = function(s) {
        return (s.toString().search(/^[0-9]+$/) == 0);
    }
    /** This function takes the calculated element size and the actual width of the carousel obj as params.
    /** checks if the calculated element size is not an integer then it sets the carousel width to a whole number
    /** which is divisible by number of visible elements **/
    this.resizeWidth = function(elementSize, actualWidth) {
        var pos;
        var fraction;
        var delta;
        if (!this.isInteger(elementSize)) {
            pos = elementSize.toString().indexOf('.', 0);
            if (pos != -1) {
                fraction = elementSize.toString().substring(pos, pos + 3);
                delta = Math.round(fraction * this.numVisible);
                this.carousel.style.width = actualWidth - delta + "px";
            }
        }
    }

    this.determineEasingFunction = function() {
        if (this.easing == 1)
            this.easingFunction = CarouselAnimation.regularEaseIn;
        else if (this.easing == 2)
            this.easingFunction = CarouselAnimation.regularEaseOut;
        else if (this.easing == 3)
            this.easingFunction = CarouselAnimation.regularEaseInOut
        else if (this.easing == 4)
            this.easingFunction = CarouselAnimation.strongEaseIn
        else if (this.easing == 5)
            this.easingFunction = CarouselAnimation.strongEaseOut
        else if (this.easing == 6)
            this.easingFunction = CarouselAnimation.strongEaseInOut
        else if (this.easing == 7)
            this.easingFunction = CarouselAnimation.customEaseIn; //CustomEaseIn
        else
            this.easingFunction = CarouselAnimation.strongEaseOut;
    };
    this.startAuto = function() {
        var xThis = this;
        if (xThis.scrollType == 1) {
            xThis.Next();
            xThis.timer = setTimeout(function() { xThis.startAuto(); }, xThis.timeout, xThis);
        }
    }

    this.stopRollup = function() {
        if (this.timer) {
            clearTimeout(this.timer);
        }
    };

    this.resumeRollup = function() {
        var aThis = this;
        aThis.timer = setTimeout(function() { aThis.startAuto(); }, aThis.timeout, aThis);
    };

    this.init();
    this.randomAutoStart();
    this.startAuto();
};

function Dlgt() { }
Dlgt.create = function(o, f) {
    var arr = new Array();
    var len = arguments.length;
    for (var i = 2; i < len; i++) arr[i - 2] = arguments[i];
    return function() {
        var aP = [].concat(arguments, arr);
        f.apply(o, aP);
    }
}

CarouselAnimation = function(obj, prop, func, begin, finish, duration, suffixe) {
    this.init(obj, prop, func, begin, finish, duration, suffixe)
}
var t = CarouselAnimation.prototype;

t.obj = new Object();
t.prop = '';
t.func = function(t, b, c, d) { return c * t / d + b; };
t.begin = 0;
t.change = 0;
t.prevTime = 0;
t.prevPos = 0;
t.looping = false;
t._duration = 0;
t._time = 0;
t._pos = 0;
t._position = 0;
t._startTime = 0;
t._finish = 0;
t.name = '';
t.suffixe = '';
t._listeners = new Array();
t.setTime = function(t) {
    this.prevTime = this._time;
    if (t > this.getDuration()) {
        if (this.looping) {
            this.rewind(t - this._duration);
            this.update();
            this.broadcastMessage('onMotionLooped', { target: this, type: 'onMotionLooped' });
        } else {
            this._time = this._duration;
            this.update();
            this.stop();
            this.broadcastMessage('onMotionFinished', { target: this, type: 'onMotionFinished' });
        }
    } else if (t < 0) {
        this.rewind();
        this.update();
    } else {
        this._time = t;
        this.update();
    }
}
t.getTime = function() {
    return this._time;
}
t.setDuration = function(d) {
    this._duration = (d == null || d <= 0) ? 100000 : d;
}
t.getDuration = function() {
    return this._duration;
}
t.setPosition = function(p) {
    this.prevPos = this._pos;
    var a = this.suffixe != '' ? this.suffixe : '';
    this.obj[this.prop] = Math.round(p) + a;
    this._pos = p;
    this.broadcastMessage('onMotionChanged', { target: this, type: 'onMotionChanged' });
}
t.getPosition = function(t) {
    if (t == undefined) t = this._time;
    return this.func(t, this.begin, this.change, this._duration);
};
t.setFinish = function(f) {
    this.change = f - this.begin;
};
t.geFinish = function() {
    return this.begin + this.change;
};
t.init = function(obj, prop, func, begin, finish, duration, suffixe) {
    if (!arguments.length) return;
    this._listeners = new Array();
    this.addListener(this);
    if (suffixe) this.suffixe = suffixe;
    this.obj = obj;
    this.prop = prop;
    this.begin = begin;
    this._pos = begin;
    this.setDuration(duration);
    if (func != null && func != '') {
        this.func = func;
    }
    this.setFinish(finish);
}
t.start = function() {
    this.rewind();
    this.startEnterFrame();
    this.broadcastMessage('onMotionStarted', { target: this, type: 'onMotionStarted' });
}
t.rewind = function(t) {
    this.stop();
    this._time = (t == undefined) ? 0 : t;
    this.fixTime();
    this.update();
}
t.fforward = function() {
    this._time = this._duration;
    this.fixTime();
    this.up
    date();
}
t.update = function() {
    this.setPosition(this.getPosition(this._time));
}
t.startEnterFrame = function() {
    this.stopEnterFrame();
    this.isPlaying = true;
    this.onEnterFrame();
}
t.onEnterFrame = function() {
    if (this.isPlaying) {
        this.nextFrame();
        setTimeout(Dlgt.create(this, this.onEnterFrame), 0);
    }
}
t.nextFrame = function() {
    this.setTime((this.getTimer() - this._startTime) / 1000);
}
t.stop = function() {
    this.stopEnterFrame();
    this.broadcastMessage('onMotionStopped', { target: this, type: 'onMotionStopped' });
}
t.stopEnterFrame = function() {
    this.isPlaying = false;
}

t.continueTo = function(finish, duration) {
    this.begin = this._pos;
    this.setFinish(finish);
    if (this._duration != undefined)
        this.setDuration(duration);
    this.start();
}
t.resume = function() {
    this.fixTime();
    this.startEnterFrame();
    this.broadcastMessage('onMotionResumed', { target: this, type: 'onMotionResumed' });
}
t.yoyo = function() {
    this.continueTo(this.begin, this._time);
}

t.addListener = function(o) {
    this.removeListener(o);
    return this._listeners.push(o);
}
t.removeListener = function(o) {
    var a = this._listeners;
    var i = a.length;
    while (i--) {
        if (a[i] == o) {
            a.splice(i, 1);
            return true;
        }
    }
    return false;
}
t.broadcastMessage = function() {
    var arr = new Array();
    for (var i = 0; i < arguments.length; i++) {
        arr.push(arguments[i])
    }
    var e = arr.shift();
    var a = this._listeners;
    var l = a.length;
    for (var i = 0; i < l; i++) {
        if (a[i][e])
            a[i][e].apply(a[i], arr);
    }
}
t.fixTime = function() {
    this._startTime = this.getTimer() - this._time * 1000;
}
t.getTimer = function() {
    return new Date().getTime() - this._time;
}

/*** customEaseInStart function gets called only for CustomEaseIn style***/
t.customEaseInStart = function() {
    this.startEnterFrame();
    this.broadcastMessage('onMotionStarted', { target: this, type: 'onMotionStarted' });
}
CarouselAnimation.strongEaseInOut = function(t, b, c, d) {
    return c * (t /= d) * t * t * t * t + b;
}
CarouselAnimation.regularEaseIn = function(t, b, c, d) {
    return c * (t /= d) * t + b;
}
CarouselAnimation.regularEaseOut = function(t, b, c, d) {
    return -c * (t /= d) * (t - 2) + b;
}
CarouselAnimation.regularEaseInOut = function(t, b, c, d) {
    if ((t /= d / 2) < 1) return c / 2 * t * t + b;
    return -c / 2 * ((--t) * (t - 2) - 1) + b;
}
CarouselAnimation.strongEaseIn = function(t, b, c, d) {
    return c * (t /= d) * t * t * t * t + b;
}
CarouselAnimation.strongEaseOut = function(t, b, c, d) {
    return c * ((t = t / d - 1) * t * t * t * t + 1) + b;
}
CarouselAnimation.strongEaseInOut = function(t, b, c, d) {
    if ((t /= d / 2) < 1) return c / 2 * t * t * t * t * t + b;
    return c / 2 * ((t -= 2) * t * t * t * t + 2) + b;
}
CarouselAnimation.customEaseIn = function(t, b, c, d) {
    return c * (t /= d) * t * t * t * t + b;
}

/******************************* * End of Carousel Class Definitions * *******************************/


/******************************* * Start of CBQO Class Definitions * *******************************/
//CBQO Globals
var CBQOWP = [];
var otherQueryParams = new Array();

/******************************* * Start of CBQO Global Functions * *******************************/

function cbqFilter() { }
cbqFilter.prototype.Type;
cbqFilter.prototype.Column;
cbqFilter.prototype.Value;
cbqFilter.prototype.Operation;
cbqFilter.prototype.ColumnType;


function getQueryStringParams() {
    var cbq = new Array();
    otherQueryParams = new Array();
    var href = window.location.href.replace(/#/, "");
    var qstring = href.split(/\?/)[1];
    if (qstring == null) return cbq;

    qstring = qstring.split(/\&/);
    for (var i = 0; i < qstring.length; i++) {
        var param = qstring[i].substring(0, 2);
        var index = (param == "sf" || param == "so") ? 0 : qstring[i].substring(2, 3);
        var value = qstring[i].split(/=/)[1];

        if (cbq[index] == null) cbq[index] = new cbqFilter();

        switch (param.toLowerCase()) {
            // Sort Params     
            case "ff":
                cbq[index].Type = "filter";
                cbq[index].Column = value;
                break;
            case "fv":
                cbq[index].Value = value;
                break;
            case "fo":
                cbq[index].Operation = value;
                break;
            case "ft":
                cbq[index].ColumnType = value;
                break;
            // Sort Params     
            case "sf":
                cbq[index].Type = "sort";
                cbq[index].Column = value;
                break;
            case "so":
                cbq[index].Value = value;
                break;
            default:
                otherQueryParams[otherQueryParams.length] = qstring[i].split(/=/)[0] + "=" + value;
        }
    }
    return cbq;
}

function buildNewQueryString(params) {
    var pstring = "";
    var filterIndex = 1;
    for (var i = 0; i < params.length; i++) {
        if (params[i] == null) continue;
        if (pstring.length == 0) pstring += "?";
        else pstring += "&";

        if (params[i].Type == "filter") {
            pstring += "ff" + filterIndex + "=" + params[i].Column;
            pstring += "&fv" + filterIndex + "=" + params[i].Value;
            pstring += "&fo" + filterIndex + "=" + params[i].Operation;
            pstring += "&ft" + filterIndex + "=" + params[i].ColumnType;
            filterIndex++;
        }
        else if (params[i].Type == "sort") {
            pstring += "sf1=" + params[i].Column;
            pstring += "&so1=" + params[i].Value;
        }
    }
    return pstring;
}

function getBaseLocation() {
    var href = window.location.href.replace(/#/, "");
    return href.split(/\?/)[0];
}
/******************************* * End of CBQO Global Functions * *******************************/


/******************************* * Start of CBQO Toolpart Functions * *******************************/

function EnablePaging(chkPagingObj, editorpartObj) {
    var chkPgingObj = document.getElementById(editorpartObj + "_" + chkPagingObj)
    var editorPropObj = document.getElementById(editorpartObj)
    var propElems = editorPropObj.getElementsByTagName("input");

    if (chkPgingObj.checked == true) {

        for (var e = 0; e < propElems.length; e++) {
            if (propElems[e].id.indexOf("pageSize") >= 0) {
                //alert(propElems[e].name);
                //alert(chkPgingObj.checked);
                propElems[e].disabled = false;
            }
        }
    }
    else {
        for (var e = 0; e < propElems.length; e++) {
            if (propElems[e].id.indexOf("pageSize") >= 0) {
                propElems[e].disabled = true;
            }
        }

    }
}

/******************************* * End of CBQO Toolpart Functions * ****************************** */

/******************************* * Start of Pagination Functions * *******************************/

var CBQPagingClass = function(CBQOPageObj, CBQQualifier, AllRecords, ItemsPerPage, CurrPageNo) {

    this.CBQPageObj = CBQOPageObj;
    this.totalRecords = AllRecords;
    this.recordsPerPage = ItemsPerPage;
    this.currentPageNo = CurrPageNo;
    this.CBQQualifier = CBQQualifier;
    this.init = function() {

        this.firstRecordButton = document.getElementById(this.CBQPageObj.id + "_FirstPg");
        this.prevRecordButton = document.getElementById(this.CBQPageObj.id + "_PrevPg");
        this.nextRecordButton = document.getElementById(this.CBQPageObj.id + "_NextPg");
        this.lastRecordButton = document.getElementById(this.CBQPageObj.id + "_LastPg");
        this.messageText = document.getElementById(this.CBQPageObj.id + "_msgRecordStatus")

        this.RefreshScrolling();
    };

    this.RefreshScrolling = function() {

        var params = getQueryStringParams();

        var totalPages = Math.ceil(this.totalRecords / this.recordsPerPage);

        if (totalPages == 1) {
            this.disableStatus(this.firstRecordButton);
            this.disableStatus(this.prevRecordButton);
            this.disableStatus(this.nextRecordButton);
            this.disableStatus(this.lastRecordButton);

            this.messageText.innerHTML = "Showing 1 to " + this.totalRecords + " of " + this.totalRecords;
        }
        else if (this.currentPageNo == 1) {
            //Disable preivous styles
            this.disableStatus(this.firstRecordButton);
            this.disableStatus(this.prevRecordButton);

            Listener.add(this.nextRecordButton, "onclick", this.ShowNextPage, this);
            Listener.add(this.lastRecordButton, "onclick", this.ShowLastPage, this);

            this.messageText.innerHTML = "Showing 1 to " + (this.currentPageNo * this.recordsPerPage) + " of " + this.totalRecords;
        }
        else if (this.currentPageNo >= totalPages) {
            //Disable next+last styles
            this.disableStatus(this.nextRecordButton);
            this.disableStatus(this.lastRecordButton);

            Listener.add(this.firstRecordButton, "onclick", this.ShowFirstPage, this);
            Listener.add(this.prevRecordButton, "onclick", this.ShowPrevPage, this);

            this.messageText.innerHTML = "Showing " + ((this.currentPageNo - 1) * this.recordsPerPage + 1) + " to " + this.totalRecords + " of " + this.totalRecords;
        }
        else {
            //Enable all
            Listener.add(this.firstRecordButton, "onclick", this.ShowFirstPage, this);
            Listener.add(this.prevRecordButton, "onclick", this.ShowPrevPage, this);
            Listener.add(this.nextRecordButton, "onclick", this.ShowNextPage, this);
            Listener.add(this.lastRecordButton, "onclick", this.ShowLastPage, this);

            this.messageText.innerHTML = "Showing " + ((this.currentPageNo - 1) * this.recordsPerPage + 1) + " to " + (this.currentPageNo * this.recordsPerPage) + " of " + this.totalRecords;
        }

    };

    this.disableStatus = function(elm) {
        elm.className = elm.className + "Off";
        elm.onclick = "javascript.event.returnValue = false";
    };

    this.ShowFirstPage = function() {

        this.currentPageNo = 1;
        this.ScrollPage();
    };

    this.ShowPrevPage = function() {

        this.currentPageNo--;
        if (this.currentPageNo <= 0) this.currentPageNo = 1;
        this.ScrollPage();
    };

    this.ShowNextPage = function() {

        if ((this.currentPageNo * this.recordsPerPage) <= this.totalRecords) {
            this.currentPageNo++;
            this.ScrollPage();
        }

    };

    this.ShowLastPage = function() {

        this.currentPageNo = Math.ceil(this.totalRecords / this.recordsPerPage);
        this.ScrollPage();
    };

    this.ScrollPage = function() {
        var href = getBaseLocation();
        var params = getQueryStringParams();
        var finalQryString = buildNewQueryString(params);
        var pagevar = this.CBQQualifier + "pg=" + this.currentPageNo;

        if (finalQryString == "")
            finalQryString += "?" + pagevar;
        else if (finalQryString == "?")
            finalQryString += pagevar;
        else
            finalQryString += "&" + pagevar;


        for (var i = 0; i < otherQueryParams.length; i++)
            if (otherQueryParams[i].indexOf(this.CBQQualifier + "pg=") == -1)
            finalQryString += "&" + otherQueryParams[i];

        window.location = href + finalQryString;
    };

    this.init();
}

/******************************* * End of Pagination Functions * *******************************/


/******************************* * End of CBQO Class Definitions * *******************************/