//--------------------------------------------------------------------
// lineyka.js v.011123.2 makes "pages: 1,2,3..., next, previous dialog"
// author: Nikolay I.Nikolskiy : http://nik.tepkom.ru
//--------------------------------------------------------------------
// uses js: nfrom, ncount, npage, fullheadlines (must be defined BEFORE)
//--------------------------------------------------------------------
// special params: (can be redefined AFTER)
var nmaxpagenumbers = 10;
var sprevbutton = "[previous]";
var snextbutton = "[next]";
var spagehref = 'javascript:changePage(%%PAGE%%)';
var lineyka_userecords = 0;
//--------------------------------------------------------------------
var lineyka_isInitialised;
var ncurrpagemax;
var fIsNextButton;
var fIsPreviousButton;
var nPages;
var nPagePortions;
var fUsePagePortions; 
var fIsPreviousPagePortions;
var nCurrentPagePortion;
var fIsNextPagePortions;
var nCurrentPortionBegin;
//---------------------------------------------------------------------
function lineyka_makeHref (ipage)
{
	var re = "%%PAGE%%";
	return (spagehref.replace (re, ipage));
}
//---------------------------------------------------------------------
function CLineykaEl (stowr, shref, i)
{
	this.stowr = stowr;
	this.shref = shref;
	this.i = i;
}

var arLineyka = new Array;
var oLineykaPrev,oLineykaNext = null;

//---------------------------------------------------------------------
function lineyka_Init()
{
	if (lineyka_isInitialised) return ;
	if (!window.ncount) ncount = 10;
	if (!window.npage) npage = 1;
	ncurrpagemax = Math.min(nfrom+ncount, fullheadlines);
	fIsNextButton = fullheadlines > ncurrpagemax ? 1 : 0 ;
	fIsPreviousButton = npage > 1 ? 1 : 0 ;
	nPages = Math.ceil(fullheadlines / ncount);
	nPagePortions = Math.ceil( nPages / nmaxpagenumbers) ;
	fUsePagePortions = nPagePortions > 1 ? 1 : 0 ; 
	fIsPreviousPagePortions = fUsePagePortions && (npage > nmaxpagenumbers) ? 1 : 0 ;
	nCurrentPagePortion = Math.ceil(npage / nmaxpagenumbers);
	fIsNextPagePortions = fUsePagePortions && ( nCurrentPagePortion < nPagePortions ) ? 1 : 0 ;
	nCurrentPortionBegin = (nCurrentPagePortion-1)*nmaxpagenumbers + 1;
	lineyka_makeArray();
	lineyka_isInitialised = 1;
}
//---------------------------------------------------------------------
function lineyka_makeArray()
{
	if (nPages <= 1) return ;
	var mult = (lineyka_userecords?ncount:1);
	var curtowr;
	if (fIsPreviousButton)
	{
		oLineykaPrev = new CLineykaEl (sprevbutton, lineyka_makeHref ((npage-1)), npage-1);
	}
	if (fIsPreviousPagePortions)
	{
		arLineyka[arLineyka.length] = new CLineykaEl ("...", lineyka_makeHref (nCurrentPortionBegin-nmaxpagenumbers), nCurrentPortionBegin-nmaxpagenumbers);
	}
	for (var i=nCurrentPortionBegin; i<=Math.min(nCurrentPortionBegin+nmaxpagenumbers, nPages); i++)
	{
		curtowr = lineyka_userecords? (i-1)*mult : i;
		if (!curtowr) curtowr = 1;
		if (i==npage)
		{
			arLineyka[arLineyka.length] = new CLineykaEl (curtowr, null, i);
		}
		else
		{
			arLineyka[arLineyka.length] = new CLineykaEl (curtowr, lineyka_makeHref(i), i);
		}
	}
	if (fIsNextPagePortions)
	{
		arLineyka[arLineyka.length] = new CLineykaEl ("...", lineyka_makeHref (nCurrentPortionBegin+nmaxpagenumbers), nCurrentPortionBegin+nmaxpagenumbers);
	}
	if (fIsNextButton)
	{
		oLineykaNext = new CLineykaEl (snextbutton, lineyka_makeHref (npage+1), npage+1);
	}
}

//---------------------------------------------------------------------
function lineyka_getSimple()
{
	lineyka_Init();
	if ( !arLineyka || arLineyka.length == 0 ) return ("");
	var fmustcomma = 0;
	var rs = "pages:&nbsp";
	if (fIsPreviousButton)
	{
		rs += "<a href='" + oLineykaPrev.shref + "' class=lineykaNS title='previpous page'>" + oLineykaPrev.stowr + "</a>&nbsp;&nbsp;";
	}
	for (var i=0; i < arLineyka.length; i++)
	{
		curr = arLineyka[i];
		if (fmustcomma)
		{
			rs += ",&nbsp;";
		}
		if (!curr.shref)
		{
			rs += "<span class=lineykaS><b>" + curr.stowr + "</b></span>";
		}
		else
		{
			rs += "<a href='" + curr.shref + "' class=lineykaNS>" + curr.stowr + "</a>";
		}
		fmustcomma = 1;
	}
	if (fIsNextButton)
	{
		rs += "&nbsp;&nbsp;<a href='" + oLineykaNext.shref + "' class=lineykaNS title='next page'>" + oLineykaNext.stowr + "</a>";
	}
	return (rs);
}

//-------------------------------------------------------------------------------------
//TODO must be modified later. must use styles for tables (or parameters)
function lineyka_getTable()
{
	lineyka_Init();
	if ( !arLineyka || arLineyka.length == 0 ) return ("");
	var rs = '<table border=0 cellpadding=0 class=lineyka><tr>';
	if (oLineykaPrev)
	{
		rs += '<td><table border=0 cellspacing=0 width="100%" cellpadding=1 bgcolor="#668DB0"><tr><td width="100%" class=lineyka valign="middle"><font size="1">&nbsp;<a class=lineyka href="' + oLineykaPrev.shref + '">' + oLineykaPrev.stowr + '</a>&nbsp;</font></td></tr></table></td><td><table border=0 cellspacing=0 width="100%" cellpadding=1 bgcolor="#FFFFFF"><tr><td width="100%">&nbsp;</td></tr></table></td>';
	}
	var curr;
	for (var i=0; i < arLineyka.length; i++)
	{
		curr = arLineyka[i];
		if (!curr.shref)
		{
			rs += '<td><table border=0 cellspacing=0 width="100%" cellpadding=1 bgcolor="#D1DAE3"><tr><td width="100%" class=lineykathis><font color=white size="1" >&nbsp;'+curr.stowr+'&nbsp;</font></td></tr></table></td>';
		}
		else
		{
			rs += '<td><table border=0 cellspacing=0 width="100%" cellpadding=1 bgcolor="#668DB0"><tr><td width="100%" class=lineyka><a class=lineyka href="' + curr.shref + '"><font size="1">&nbsp;' + curr.stowr + '&nbsp;</font></a></td></tr></table></td>';
		}
	}
	if (oLineykaNext)
	{
		rs += '<td><table border=0 cellspacing=0 width="100%" cellpadding=1 bgcolor="#FFFFFF"><tr><td width="100%">&nbsp;</td></tr></table></td><td><table border=0 cellspacing=0 width="100%" cellpadding=1 bgcolor="#668DB0"><tr><td width="100%" class=lineyka valign="middle"><font size="1">&nbsp;<a class=lineyka href="' + oLineykaNext.shref + '">' + oLineykaNext.stowr + '</a>&nbsp;</font></td></tr></table></td>';
	}
	rs += "</tr></table>";
	return (rs);
}










































