
/*
Written by Peter Tyrrell, Andornot Consulting 2003
Inmagic report next & previous buttons
*/


	
function nextprev_block(record_count)
{
	var params = window.dbtw_params;
	var next_write = "";
	var next_link = "";
	var prev_write = "";
	var prev_link = "";
	var nextprev_link = "";
	var rc = parseInt(record_count);

	// find the record number
	var rns = params.match(/RN=(\d+)/);
	var rn = parseInt(rns[1]);

	// MR is records at a time
	var mrs = params.match(/MR=(\d+)/);
	var mr = parseInt(mrs[1]);
	
	//comparison number for next block
	var next_total = (rc - mr - rn);
	
	//comparison number for prev block
	var prev_total = (rn - mr);
	
	// determine if a "Previous x Records" link should be made
	if (prev_total >= 0)
	{
		prev_write = "Previous " + mr + " Records";	

		//prev_link = "<form>";
		prev_link += "<a class='NavBar_Links' href='javascript:dbtw_prev(\"";
		//prev_link += "<input type='button' value='" + prev_write + "' onClick='dbtw_prev(\"";
		prev_link +=  "/dbtw-wpd/exec/dbtwpub.dll?AC=PREV_BLOCK" + params;
		prev_link += "\")' >";
		prev_link += prev_write + "</a>&nbsp;";
		//prev_link += "</form>";
	}
	
	// determine if a "Next x Records" link should be made
	if (next_total < mr && next_total > 0)
	{
		next_write = "Next " + next_total + " Records";
	}
	else if (next_total >= mr)
	{
		next_write = "Next " + mr + " Records";
	}

	if (next_write != "")
	{
		//next_link = "<form>";
		next_link += "<a class='NavBar_Links' href='javascript:dbtw_next(\"";
		//next_link += "<input type='button' value='" + next_write + "' onClick='dbtw_next(\"";
		next_link +=  "/dbtw-wpd/exec/dbtwpub.dll?AC=NEXT_BLOCK" + params;
		next_link += "\")' >";
		next_link += next_write + "</a>";
		//next_link += "</form>";
	}

	// build the final string to write into HTML
	if (next_link == "" && prev_link == "")
	{
		nextprev_link = "";	
	}
	else if (next_link != "" && prev_link == "")
	{
		nextprev_link += next_link;
	}
	else if (next_link == "" && prev_link != "")
	{
		nextprev_link += prev_link;	
	}
	else
	{ 
		nextprev_link += prev_link + "|&nbsp;" + next_link;		
	}

		
	return nextprev_link;

} //end fxn

function nextprev_record(record_count)
{
	var params = window.dbtw_params;
	var next_write = "";
	var next_link = "";
	var prev_write = "";
	var prev_link = "";
	var nextprev_link = "";
	var rc = parseInt(record_count);

	// find the record number
	var rns = params.match(/RN=(\d+)/);
	var rn = parseInt(rns[1]);

	
	// determine if a "Previous Record" link should be made
	if (rn > 0)
	{
		prev_write = "Previous Record";

		//prev_link = "<form>";
		prev_link += "<a class='NavBar_Links' href='javascript:dbtw_prev(\"";
		//prev_link += "<input type='button' value='" + prev_write + "' onClick='dbtw_prev(\"";
		prev_link +=  "/dbtw-wpd/exec/dbtwpub.dll?AC=PREV_RECORD" + params;
		prev_link += "\")' >";
		prev_link += prev_write + "</a>&nbsp;";
		//prev_link += "</form>";
	}
	
	// determine if a "Next Record" link should be made
	if (rn+1 < rc)
	{
		next_write = "Next Record";

		//next_link = "<form>";
		next_link += "<a class='NavBar_Links' href='javascript:dbtw_next(\"";
		//next_link += "<input type='button' value='" + next_write + "' onClick='dbtw_next(\"";
		next_link +=  "/dbtw-wpd/exec/dbtwpub.dll?AC=NEXT_RECORD" + params;
		next_link += "\")' >";
		next_link += next_write + "</a>";
		//next_link += "</form>";
	}

	// build the final string to write into HTML
	if (next_link == "" && prev_link == "")
	{
		nextprev_link = "";	
	}
	else if (next_link != "" && prev_link == "")
	{
		nextprev_link += next_link;
	}
	else if (next_link == "" && prev_link != "")
	{
		nextprev_link += prev_link;	
	}
	else
	{ 
		nextprev_link += prev_link + "|&nbsp;" + next_link;		
	}

		
	return nextprev_link;

} //end fxn


/*
 This back_to_block method written by Terry McBride tttmcbride@yahoo.com
 This method takes you from a display of an expanded record back to  the list from the position that the current expanded record would be in.
*/

function back_to_block() 
{
	var params = window.dbtw_params;

	// find the record number
	var rns = params.match(/RN=(\d+)/);
	var rn = parseInt(rns[1]);

	// MR is records at a time
	var mrs = params.match(/MR=(\d+)/);
	var mr = parseInt(mrs[1]);

	// find the lower multiple of mr and add another mr to it to fool PREV_BLOCK
	var remainder = (rn % mr);
	var start = (rn - remainder + mr); 

	var i = params.indexOf("RN=") + 3;
	var j = params.indexOf("&", i);

	var url = "/dbtw-wpd/exec/dbtwpub.dll?AC=PREV_BLOCK" + params.substring (0, i) + start + params.substring(j, params.length);

	window.location.href = url; 

}
	
function back_to_block_cookie(Textbase) 
{
	var params = window.dbtw_params;

	// find the record number
	var rns = params.match(/RN=(\d+)/);
	var rn = parseInt(rns[1]);

	// MR is records at a time
	var mrs = params.match(/MR=(\d+)/);
	var mr = parseInt(mrs[1]);

	// find the lower multiple of mr and add another mr to it to fool PREV_BLOCK
	var remainder = (rn % mr);
	var start = (rn - remainder + mr); 

	var i = params.indexOf("RN=") + 3;
	var j = params.indexOf("&", i);

	var url = "/dbtw-wpd/exec/dbtwpub.dll?AC=PREV_BLOCK" + params.substring (0, i) + start + params.substring(j, params.length);
	
	document.cookie = Textbase + "_DbtwLastResult=" + url + "; path=/";
	
}


function back_to_record_cookie(Textbase, RecordNumber)
{
	var params = window.dbtw_params;
	var rn = parseInt(RecordNumber) - 1;
	var i = params.indexOf("RN=") + 3;
	var j = params.indexOf("&", i);
	
	// reconstruct the link with only the RN value replaced
	var url = "/dbtw-wpd/exec/dbtwpub.dll?AC=GET_RECORD" + params.substring (0, i) + rn + params.substring(j, params.length);
	document.cookie = Textbase+ "_DbtwFullRecord=" + url + "; path=/";
}

function record_count_cookie(Textbase, RecordCount)
{
	document.cookie = Textbase + "_RecordCount=" + RecordCount + "; path=/";
}
