function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

/*
 * Ext JS Library 2.2
 * Copyright(c) 2006-2008, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://extjs.com/license
 */

/**
 * @class Ext.PagingToolbar
 * @extends Ext.Toolbar
 * A specialized toolbar that is bound to a {@link Ext.data.Store} and provides automatic paging controls.
 * @constructor
 * Create a new PagingToolbar
 * @param {Object} config The config object
 */
Ext.PagingToolbar = Ext.extend(Ext.Toolbar, {
    /**
     * @cfg {Ext.data.Store} store The {@link Ext.data.Store} the paging toolbar should use as its data source (required).
     */
    /**
     * @cfg {Boolean} displayInfo
     * True to display the displayMsg (defaults to false)
     */
    /**
     * @cfg {Number} pageSize
     * The number of records to display per page (defaults to 20)
     */
    pageSize: 20,
    /**
     * @cfg {String} displayMsg
     * The paging status message to display (defaults to "Displaying {0} - {1} of {2}").  Note that this string is
     * formatted using the braced numbers 0-2 as tokens that are replaced by the values for start, end and total
     * respectively. These tokens should be preserved when overriding this string if showing those values is desired.
     */
    displayMsg : 'Displaying {0} - {1} of {2}',
    /**
     * @cfg {String} emptyMsg
     * The message to display when no records are found (defaults to "No data to display")
     */
    emptyMsg : 'No data to display',
    /**
     * Customizable piece of the default paging text (defaults to "Page")
     * @type String
     */
    beforePageText : "Page: ",
    /**
     * Customizable piece of the default paging text (defaults to "of {0}"). Note that this string is
     * formatted using {0} as a token that is replaced by the number of total pages. This token should be 
     * preserved when overriding this string if showing the total page count is desired.
     * @type String
     */
    afterPageText : "of {0}",
    /**
     * Customizable piece of the default paging text (defaults to "First Page")
     * @type String
     */
    firstText : "First",
    /**
     * Customizable piece of the default paging text (defaults to "Previous Page")
     * @type String
     */
    prevText : "Prev",
    /**
     * Customizable piece of the default paging text (defaults to "Next Page")
     * @type String
     */
    nextText : "Next",
    /**
     * Customizable piece of the default paging text (defaults to "Last Page")
     * @type String
     */
    lastText : "Last",
    /**
     * Customizable piece of the default paging text (defaults to "Refresh")
     * @type String
     */
    refreshText : "Refresh",

    /**
     * Object mapping of parameter names for load calls (defaults to {start: 'start', limit: 'limit'})
     */
    paramNames : {start: 'start', limit: 'limit'},

    initComponent : function(){
        this.addEvents('change', 'beforechange');
        Ext.PagingToolbar.superclass.initComponent.call(this);
        this.cursor = 0;
        this.bind(this.store);
    },

    // private
    onRender : function(ct, position){
        Ext.PagingToolbar.superclass.onRender.call(this, ct, position);
        //this.add(this.beforePageText);
        this.first = this.addButton({
            //text: this.firstText,
            iconCls: "x-tbar-page-first",
            disabled: true,
            handler: this.onClick.createDelegate(this, ["first"])
        });
        this.prev = this.addButton({
            text: this.prevText,
            iconCls: "x-tbar-page-prev",
            disabled: true,
            handler: this.onClick.createDelegate(this, ["prev"])
        });
        //this.addSeparator();
        /*this.field = Ext.get(this.addDom({
           tag: "input",
           type: "text",
           size: "3",
           value: "1",
           cls: "x-tbar-page-number"
        }).el);
        this.field.on("keydown", this.onPagingKeydown, this);
        this.field.on("focus", function(){this.dom.select();});
        this.afterTextEl = this.addText(String.format(this.afterPageText, 1));
        this.field.setHeight(18);*/
        this.page1 = this.addText('1');
        this.page2 = this.addText('2');
        this.page3 = this.addText('3');
        this.page4 = this.addText('4');
        this.page5 = this.addText('5');
        //this.addSeparator();
        this.next = this.addButton({
            text: this.nextText,
            iconCls: "x-tbar-page-next",
            disabled: true,
            handler: this.onClick.createDelegate(this, ["next"])
        });
        this.last = this.addButton({
            //text: this.lastText,
            iconCls: "x-tbar-page-last",
            disabled: true,
            handler: this.onClick.createDelegate(this, ["last"])
        });
        //this.addSeparator();
        this.loading = this.addButton({
            tooltip: this.refreshText,
            iconCls: "x-tbar-loading",
            handler: this.onClick.createDelegate(this, ["refresh"]),
            id: 'loading_button'
        });

        if(this.displayInfo){
            this.displayEl = Ext.fly(this.el.dom).createChild({cls:'x-paging-info'});
        }
        if(this.dsLoaded){
            this.onLoad.apply(this, this.dsLoaded);
        }
    },

    // private
    updateInfo : function(){
        if(this.displayEl){
            var count = this.store.getCount();
            var msg = count == 0 ?
                this.emptyMsg :
                String.format(
                    this.displayMsg,
                    this.cursor+1, this.cursor+count, this.store.getTotalCount()
                );
            this.displayEl.update(msg);
        }
    },

    // private
    onLoad : function(store, r, o){
        if(!this.rendered){
            this.dsLoaded = [store, r, o];
            return;
        }
       this.cursor = o.params ? o.params[this.paramNames.start] : 0;
       var d = this.getPageData(), ap = d.activePage, ps = d.pages;
        //this.afterTextEl.el.innerHTML = String.format(this.afterPageText, d.pages);
        //this.field.dom.value = ap;
        
        //set value of 5 page options
        this.page1.el.innerHTML = (ap<=3 ? 1 : (ap>ps-2 ? (ps>5 ? ps-4 : 1) : ap-2));
        this.page2.el.innerHTML = (ap<=3 ? 2 : (ap>ps-2 ? (ps>5 ? ps-3 : 2) : ap-1));
        this.page3.el.innerHTML = (ap<=3 ? 3 : (ap>ps-2 ? (ps>5 ? ps-2 : 3) : ap));
        this.page4.el.innerHTML = (ap<=3 ? 4 : (ap>ps-2 ? (ps>5 ? ps-1 : 4) : ap+1));
        this.page5.el.innerHTML = (ap<=3 ? 5 : (ap>ps-2 ? ps : ap+2));
        //set onclick function
        this.page1.el.onclick = this.onClick.createDelegate(this, [this.page1.el.innerHTML-1]);
        this.page2.el.onclick = this.onClick.createDelegate(this, [this.page2.el.innerHTML-1]);
        this.page3.el.onclick = this.onClick.createDelegate(this, [this.page3.el.innerHTML-1]);
        this.page4.el.onclick = this.onClick.createDelegate(this, [this.page4.el.innerHTML-1]);
        this.page5.el.onclick = this.onClick.createDelegate(this, [this.page5.el.innerHTML-1]);
        //set css cursor to be pointer
        this.page1.el.style.cursor = 'pointer';
        this.page2.el.style.cursor = 'pointer';
        this.page3.el.style.cursor = 'pointer';
        this.page4.el.style.cursor = 'pointer';
        this.page5.el.style.cursor = 'pointer';
        //set css text decoration to be underline onmouseover (hover)
        this.page1.el.onmouseover = function(){this.style.textDecoration = 'underline'};
        this.page2.el.onmouseover = function(){this.style.textDecoration = 'underline'};
        this.page3.el.onmouseover = function(){this.style.textDecoration = 'underline'};
        this.page4.el.onmouseover = function(){this.style.textDecoration = 'underline'};
        this.page5.el.onmouseover = function(){this.style.textDecoration = 'underline'};
        //set css text decoration to be normal onmouseout (come off of hover)
        this.page1.el.onmouseout = function(){this.style.textDecoration = 'none'};
        this.page2.el.onmouseout = function(){this.style.textDecoration = 'none'};
        this.page3.el.onmouseout = function(){this.style.textDecoration = 'none'};
        this.page4.el.onmouseout = function(){this.style.textDecoration = 'none'};
        this.page5.el.onmouseout = function(){this.style.textDecoration = 'none'};
        //hide if less than 5 pages
        if (ps < 2) this.page2.el.style.display = 'none'; else this.page2.el.style.display = '';
        if (ps < 3) this.page3.el.style.display = 'none'; else this.page3.el.style.display = '';
        if (ps < 4) this.page4.el.style.display = 'none'; else this.page4.el.style.display = '';
        if (ps < 5) this.page5.el.style.display = 'none'; else this.page5.el.style.display = '';
        //make the current page bold, make all others normal
        if (this.page1.el.innerHTML==ap) this.page1.el.className = 'ytb-text page_num_text_selected';
        else this.page1.el.className = 'ytb-text page_num_text';
        if (this.page2.el.innerHTML==ap) this.page2.el.className = 'ytb-text page_num_text_selected';
        else this.page2.el.className = 'ytb-text page_num_text';
        if (this.page3.el.innerHTML==ap) this.page3.el.className = 'ytb-text page_num_text_selected';
        else this.page3.el.className = 'ytb-text page_num_text';
        if (this.page4.el.innerHTML==ap) this.page4.el.className = 'ytb-text page_num_text_selected';
        else this.page4.el.className = 'ytb-text page_num_text';
        if (this.page5.el.innerHTML==ap) this.page5.el.className = 'ytb-text page_num_text_selected';
        else this.page5.el.className = 'ytb-text page_num_text';

        this.first.setDisabled(ap == 1);
        this.prev.setDisabled(ap == 1);
        this.next.setDisabled(ap == ps);
        this.last.setDisabled(ap == ps);
        
        //set margins/position of paging info based on size of paging bar
        /*var paging_table = document.getElementById('paging_bar').getElementsByTagName('table');
        var paging_info = getElementsByClass('x-paging-info');
        paging_info[0].style.marginRight = paging_table[0].scrollWidth;*/
        
	    //paging_bar_class = getElementsByClass('paging_bar');
		if (document.getElementById("paging_top") && document.getElementById("all_photos_dataview")){
		   	paging_table = document.getElementById("paging_top").getElementsByTagName('table');
		   	paging_info = getElementsByClass('x-paging-info');
		   	paging_info[0].style.marginRight = paging_table[0].scrollWidth + "px";
		   	//paging_info[1].style.marginRight = paging_table[0].scrollWidth + "px";
		}
		if (document.getElementById("paging_top") && document.getElementById("main_dataview"))
		{
		   	paging_table = document.getElementById("paging_top").getElementsByTagName('table');
		   	paging_info = getElementsByClass('x-paging-info');
		   	paging_info[0].style.marginRight = paging_table[0].scrollWidth + "px";
		   	paging_info[1].style.marginRight = paging_table[0].scrollWidth + "px";
		   	num_events = getElementsByClass('event_div');
		   	num_dates = getElementsByClass('date_div');
		   	num_dates_stuck = getElementsByClass('date_div_stuck');
		   	num_members = getElementsByClass('member_div');
		   	num_emails = getElementsByClass('email');
		   	one_email = getElementsByClass('one_email');
		   	if (num_emails.length || one_email.length || document.getElementById("main_dataview").innerHTML=="No email to display")
		   	{
	//		   	height = parseInt(parseInt(num_events.length * 88) + parseInt(num_dates.length * 30) + parseInt(num_dates_stuck.length * 30));
	//		   	document.getElementById("search_left_middle").style.height = document.getElementById("main_dataview").style.height = height+"px";
				document.getElementById("main_dataview").style.height = "auto";
				if (parseInt(document.getElementById("main_dataview").scrollHeight)<=365)//248
				{
				   	document.getElementById("search_left_middle").style.height = "365px";//234
				   	document.getElementById("main_dataview").style.height = "365px";//248
				}
				else
				{
				   	document.getElementById("search_left_middle").style.height = parseInt(parseInt(document.getElementById("main_dataview").scrollHeight)-24) + "px";
				}
				/*event_pictures = getElementsByClass("event_picture");
			   	for (i=0;i<event_pictures.length;i++)
			   	{
			   		pictures = event_pictures[i].getElementsByTagName('img');
				   	if (pictures[0].scrollWidth>event_pictures[i].scrollHeight)
				   	{
				   		pictures[0].style.width = "106px";
				   	}
				   	else
				   	{
				   		pictures[0].style.height = "75px";
				   	}
			   	}*/
		   	}
		   	if (num_events.length || document.getElementById("main_dataview").innerHTML=="No events to display")
		   	{
	//		   	height = parseInt(parseInt(num_events.length * 88) + parseInt(num_dates.length * 30) + parseInt(num_dates_stuck.length * 30));
	//		   	document.getElementById("search_left_middle").style.height = document.getElementById("main_dataview").style.height = height+"px";
				document.getElementById("main_dataview").style.height = "auto";
				if (parseInt(document.getElementById("main_dataview").scrollHeight)<=365)//248
				{
				   	document.getElementById("search_left_middle").style.height = "365px";//234
				   	document.getElementById("main_dataview").style.height = "365px";//248
				}
				else
				{
				   	document.getElementById("search_left_middle").style.height = parseInt(document.getElementById("main_dataview").scrollHeight) + "px";
				}
				/*event_pictures = getElementsByClass("event_picture");
			   	for (i=0;i<event_pictures.length;i++)
			   	{
			   		pictures = event_pictures[i].getElementsByTagName('img');
				   	if (pictures[0].scrollWidth>event_pictures[i].scrollHeight)
				   	{
				   		pictures[0].style.width = "106px";
				   	}
				   	else
				   	{
				   		pictures[0].style.height = "75px";
				   	}
			   	}*/
		   	}
		   	if (num_members.length || document.getElementById("main_dataview").innerHTML=="No members to display")
		   	{
		   		/*height = 0;
			   	member_pictures = getElementsByClass("member_picture");
			   	member_div = getElementsByClass("member_div");
			   	for (i=0;i<member_pictures.length;i++)
			   	{
			   		pictures = member_pictures[i].getElementsByTagName('img');
			   		if (pictures[0].scrollHeight > 80)
			   		{
			   			member_div[i].style.height = parseInt(pictures[0].scrollHeight) + 13;
			   			height += parseInt(pictures[0].scrollHeight) + 13;
			   		}
			   		else
			   			height += 94;*/
	//			   	if (pictures[0].scrollWidth>member_pictures[i].scrollHeight)
	//			   	{
	//			   		pictures[0].style.width = "105px";
	//			   	}
	//			   	else
	//			   	{
	//			   		pictures[0].style.height = "80px";
	//			   	}
			   	//}
			   	//height = parseInt(parseInt(num_members.length * 94));
				document.getElementById("main_dataview").style.height = "auto";
				if (parseInt(document.getElementById("main_dataview").scrollHeight)<=365)//236
				{
				   	document.getElementById("search_left_middle").style.height = "365px";//222
				   	document.getElementById("main_dataview").style.height = "365px";//236
				}
				else
				{
				   	document.getElementById("search_left_middle").style.height = parseInt(document.getElementById("main_dataview").scrollHeight) + "px";
				}
			   	//document.getElementById("search_left_middle").style.height = document.getElementById("main_dataview").style.height = height+"px";
			   	document.getElementById("main_body").style.height = (parseInt(document.getElementById("main_left_center").scrollHeight)>830 ? parseInt(parseInt(document.getElementById("main_left_center").scrollHeight)+20)+"px" : "830px");
		   	}
		}
   		this.loading.enable();
        this.updateInfo();
        this.fireEvent('change', this, d);
    },

    // private
    getPageData : function(){
        var total = this.store.getTotalCount();
        return {
            total : total,
            activePage : Math.ceil((this.cursor+this.pageSize)/this.pageSize),
            pages :  total < this.pageSize ? 1 : Math.ceil(total/this.pageSize)
        };
    },

    // private
    onLoadError : function(){
        if(!this.rendered){
            return;
        }
        this.loading.enable();
    },

    /*readPage : function(d){
        var v = this.field.dom.value, pageNum;
        if (!v || isNaN(pageNum = parseInt(v, 10))) {
            this.field.dom.value = d.activePage;
            return false;
        }
        return pageNum;
    },*/

    // private
    /*onPagingKeydown : function(e){
        var k = e.getKey(), d = this.getPageData(), pageNum;
        if (k == e.RETURN) {
            e.stopEvent();
            pageNum = this.readPage(d);
            if(pageNum !== false){
                pageNum = Math.min(Math.max(1, pageNum), d.pages) - 1;
                this.doLoad(pageNum * this.pageSize);
            }
        }else if (k == e.HOME || k == e.END){
            e.stopEvent();
            pageNum = k == e.HOME ? 1 : d.pages;
            this.field.dom.value = pageNum;
        }else if (k == e.UP || k == e.PAGEUP || k == e.DOWN || k == e.PAGEDOWN){
            e.stopEvent();
            if(pageNum = this.readPage(d)){
                var increment = e.shiftKey ? 10 : 1;
                if(k == e.DOWN || k == e.PAGEDOWN){
                    increment *= -1;
                }
                pageNum += increment;
                if(pageNum >= 1 & pageNum <= d.pages){
                    this.field.dom.value = pageNum;
                }
            }
        }
    },*/

    // private
    beforeLoad : function(){
        if(this.rendered && this.loading){
            this.loading.disable();
        }
    },

    doLoad : function(start){
        var o = {}, pn = this.paramNames;
        if (this.store.lastOptions.params)
        	o = this.store.lastOptions.params;
        o[pn.start] = start;
        o[pn.limit] = this.pageSize;
        if(this.fireEvent('beforechange', this, o) !== false){
            this.store.load({params:o});
        }
    },

    /**
     * Change the active page
     * @param {Integer} page The page to display 
     */
    changePage: function(page){
        this.doLoad(((page-1) * this.pageSize).constrain(0, this.store.getTotalCount()));  
    },

    // private
    onClick : function(which){
        var store = this.store;
        switch(which){
            case "first":
                this.doLoad(0);
            break;
            case "prev":
                this.doLoad(Math.max(0, this.cursor-this.pageSize));
            break;
            case "next":
                this.doLoad(this.cursor+this.pageSize);
            break;
            case "last":
                var total = store.getTotalCount();
                var extra = total % this.pageSize;
                var lastStart = extra ? (total - extra) : total-this.pageSize;
                this.doLoad(lastStart);
            break;
            case "refresh":
                this.doLoad(this.cursor);
            break;
            //added for glocals page list
            default:
            	this.doLoad(which * this.pageSize)
        }
    },

    /**
     * Unbinds the paging toolbar from the specified {@link Ext.data.Store}
     * @param {Ext.data.Store} store The data store to unbind
     */
    unbind : function(store){
        store = Ext.StoreMgr.lookup(store);
        store.un("beforeload", this.beforeLoad, this);
        store.un("load", this.onLoad, this);
        store.un("loadexception", this.onLoadError, this);
        this.store = undefined;
    },

    /**
     * Binds the paging toolbar to the specified {@link Ext.data.Store}
     * @param {Ext.data.Store} store The data store to bind
     */
    bind : function(store){
        store = Ext.StoreMgr.lookup(store);
        store.on("beforeload", this.beforeLoad, this);
        store.on("load", this.onLoad, this);
        store.on("loadexception", this.onLoadError, this);
        this.store = store;
    }
});
Ext.reg('paging', Ext.PagingToolbar);