/*
window.onload = function(){
            util = new PageUtil();
            util.totalCnt   = 1000; 
            util.pageRows   = 8;     
            util.curPage    = 1;  
            util.disPagepCnt= 10;     
            util.setTotalPage();
           
            var pg  = parent.document.getElementById('page');  // div ÅÂ±×¸¦ ÀÌ¿ëÇÏ¿© ÆäÀÌÂ¡À» Ã³¸® 
            pg.innerHTML    = util.Drow();
 
}
var goPage=function(val){  
            util.curPage    = val;  
            util.setTotalPage();
			var pg  = parent.document.getElementById('page');  // div ÅÂ±×¸¦ ÀÌ¿ëÇÏ¿© ÆäÀÌÂ¡À» Ã³¸® 
            pg.innerHTML    = util.Drow();
}
*/


var PageUtil = function() // ÆäÀÌÁö Ã³¸® ÇÔ¼ö
{
    var totalCnt; // ÃÑ °Ç¼ö
    var pageRows; // ÇÑ ÆäÀÌÁö¿¡ Ãâ·ÂµÉ Ç×¸ñ °¹¼ö
    var curPage; // ÇöÀç ÆäÀÌÁö
    var disPagepCnt;// È­¸éÃâ·Â ÆäÀÌÁö¼ö
    var totalPage;

    this.setTotalPage = function()
    {
        this.totalPage = parseInt((this.totalCnt/this.pageRows)) + (this.totalCnt%this.pageRows>0 ? 1:0);
    }

    this.getPrev = function()
    {
        var prev    = 0;

        if(this.curPage > 1)
            prev    = this.curPage - 1;
        else
            prev    = 1;

        return prev;
    }

    this.getNext = function()
    {
        var next    = 0;

        if(this.curPage < this.totalPage)
            next = this.curPage + 1;
        else
            next = this.totalPage;

        return next;
    }

    this.getPrevPage = function()
    {
        var prevPage    = 0;
        var curPos      = (parseInt((this.curPage/this.disPagepCnt))+(this.curPage%this.disPagepCnt>0 ? 1:0));

        if(curPos>1)
        {
            prevPage    = parseInt((curPos-1))*this.disPagepCnt;
        }

        return prevPage;
    }

    this.getNextPage = function()
    {
        var nextPage    = 0;
        var curPos  = parseInt((parseInt((this.curPage/this.disPagepCnt))+(this.curPage%this.disPagepCnt >0 ? 1:0)));

        if((curPos*this.disPagepCnt+1) <= this.totalPage)
        {
            nextPage    = curPos*this.disPagepCnt+1;
        }

        if( this.totalPage >= nextPage )
            return nextPage;
        else
            return this.totalPage;
    }

    this.Drow = function()
    {
        var sb = '<div class="itemPaging">';
		var tmp=0;

        var start   = ((parseInt((this.curPage/this.disPagepCnt))+(this.curPage%this.disPagepCnt>0 ? 1:0)) * this.disPagepCnt - (this.disPagepCnt-1));
        var end     = ((parseInt((this.curPage/this.disPagepCnt))+(this.curPage%this.disPagepCnt>0 ? 1:0)) * this.disPagepCnt);
        if(end > this.totalPage)
            end = this.totalPage;

        if(this.curPage > this.disPagepCnt)
        {
            sb += "&nbsp;&nbsp;<a href='javascript:goPage("+(this.curPage-(this.disPagepCnt))+");'><img src='/images/community/btnReplyPrev2.gif'></a>&nbsp;";
        }

        if(this.getPrev() < this.curPage)
        {
            sb += "&nbsp;&nbsp;<a href='javascript:goPage("+(this.curPage-1)+");'><img src='/images/community/btnReplyPrev.gif'></a>&nbsp;&nbsp;";
        }

        for(var i=start; i<=end; i++)
        {
            if(i==this.curPage)
            {
                sb += "<strong>"+i+"</strong>&nbsp;";
            }
            else
            {
                sb += "<a href='javascript:goPage("+i+");'>"+i+"</a>&nbsp";
            }
        }

        if(this.curPage < this.getNext())
        {
           // sb += "&nbsp;&nbsp;<a href='javascript:Next();'>¢º</a>&nbsp;&nbsp;";
		   sb += "<a href='javascript:goPage("+(parseInt(this.curPage)+1)+");'><img src='/images/community/btnReplyNext.gif'></a>&nbsp;&nbsp;";
		   
        }

        if(this.totalPage > this.getNextPage() && this.getNextPage() != 0 )
        {
			if (this.curPage%10==0)
				tmp = parseInt(this.curPage/10)*this.disPagepCnt+1;
			else
				tmp = (parseInt(this.curPage/10)+1)*this.disPagepCnt+1;
		 
 
            sb += "&nbsp;&nbsp;<a href='javascript:goPage("+tmp+");'><img src='/images/community/btnReplyNext2.gif'></a>&nbsp;";
        }
		sb += "</div>"
        return sb;
    }
}


 
