﻿/* **************************************************************
	Wiz Javascript - AJAX Utility Library Pager Control
	Version : 1.0
	Developer : wiz (wizys@yahoo.co.kr / http://wiz.pe.kr/)
	Last Updated : 2007.04.10 - First Version By wiz
	* 소스의 무단 사용을 금지 합니다.
************************************************************** */

WizPager = function (tg, pgs, itemcnt, pgcnt, fnName, arg0)
{
	this.Parent = tg;
	this.PGI = 1;
	this.PCNT = pgcnt;
	this.MaxPage = Math.ceil(itemcnt/pgs);
	this.FNN = fnName;
	this.ARG0 = arg0;
	this.ReDrawPager();
}
WizPager.prototype=
{
	ReDrawPager: function()
	{
		if(this.PGI<=0) { this.PGI = 0; }

		this.Spgi = (Math.floor(this.PGI/this.PCNT)*this.PCNT)+1;
		if(this.Spgi<1) { this.Spgi=1; }

		this.Ppgi = (this.Spgi-this.PCNT);
		this.Npgi = (this.Spgi+this.PCNT);

		var PBO = document.createElement('div');
			PBO.setAttribute('id', 'Pager');
			PBO.className = ('Pager');

		var PBP = document.createElement('img');
			PBP.src = 'http://enportsimg.joins.com/blogplus/blogplus2/btn_prev1.gif';

		if(this.Spgi>=this.PCNT)
		{
			PBP.setAttribute('onmouseover', 'this.src=\'http://enportsimg.joins.com/blogplus/blogplus2/btn_prev1_on.gif\';');
			PBP.setAttribute('onmouseout', 'this.src=\'http://enportsimg.joins.com/blogplus/blogplus2/btn_prev1.gif\';');

			var PBPA = document.createElement('a');
			var fns = (this.FNN + '(' + this.Ppgi);
			if(this.ARG0) { fns = (fns + ',\'' + this.ARG0 + '\''); }
			fns = (fns + ')');
			PBPA.href = ('javasc' + 'ript:' + fns);
			PBPA.innerHTML = GetOuterHTML(PBP);
			PBO.appendChild(PBPA);
		}
		else { PBO.appendChild(PBP); }

		var PBN = null;
		for(tmpi=this.Spgi;tmpi<(this.Spgi+this.PCNT);tmpi++)
		{
			PBN = null;
			if(tmpi>this.MaxPage) { break; }
			if(tmpi!=this.Spgi)
			{
				var PBS = document.createElement('span');
					PBS.className='SP';
					PBS.innerHTML = '|';
					PBO.appendChild(PBS);
			}
			PBN = document.createElement('a');
			if(tmpi==this.PGI) { PBN.className='SEL'; }
			else { PBN.className='NOR'; }
			PBN.setAttribute('id', this.Parent.id + 'Paging_' + tmpi);
			var fns = (this.FNN + '(' + tmpi);
			if(this.ARG0) { fns = (fns + ',\'' + this.ARG0 + '\''); }
			fns = (fns + ')');

			PBN.href = ('javasc' + 'ript:' + fns);
			PBN.innerHTML = (''+tmpi+'');
			PBO.appendChild(PBN);
		}

		var PBN = document.createElement('img');
			PBN.src = 'http://enportsimg.joins.com/blogplus/blogplus2/btn_next1.gif';

		if((this.MaxPage-this.PCNT)>this.PGI)
		{
			PBN.setAttribute('onmouseover', 'this.src=\'http://enportsimg.joins.com/blogplus/blogplus2/btn_next1_on.gif\';');
			PBN.setAttribute('onmouseout', 'this.src=\'http://enportsimg.joins.com/blogplus/blogplus2/btn_next1.gif\';');

			var PBNA = document.createElement('a');
			var fns = (this.FNN + '(' + this.Npgi);
			if(this.ARG0) { fns = (fns + ',\'' + this.ARG0 + '\''); }
			fns = (fns + ')');
			PBNA.href = ('javasc' + 'ript:' + fns);
			PBNA.innerHTML = GetOuterHTML(PBN);
			PBO.appendChild(PBNA);
		}
		else { PBO.appendChild(PBN); }

		this.Parent.innerHTML='';
		this.Parent.appendChild(PBO);
	},
	PageChange: function(pgi)
	{
		var op = $get(this.Parent.id + 'Paging_' + this.PGI);
		if(op) { op.className = 'NOR'; }
		this.PGI = pgi;
		var op = $get(this.Parent.id + 'Paging_' + this.PGI);
		if(op) { op.className = 'SEL'; }
		if(this.PGI<this.Spgi || this.PGI>=(this.Spgi+this.PCNT)) { this.ReDrawPager(); }
	}
}

