//Thin Ajax - Seems to work on all browsers 

var cur_page = 0;
var last_page = 0;
var last_button = 0;

// Composite function for selecting a top level window.

function SelectPage( page )
{

	cur_page=page;
	SelectButton(page);
	GetPage(page_tabl[page], 'ajaxcontentarea');

}

// Size functions

function SizeThem()
{  
	// Get the size of the window 
	var de = document.documentElement;
	var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;

	set_table( h - 125 );
}

function  ResizeThem()
{
	SizeThem();
	GetPage(page_tabl[cur_page], 'ajaxcontentarea'); // get the first page - could do some persistance with cookies

}

// Set up image labels from the button array
// into the items labeled menu.

function SetButtonLabels()
{
var i;	
var tab;

	for (i = 0; i < page_tabl_cnt; i++ )
	{
		tab = "button" + i;
		document.getElementById(tab).src = but_tab1[i];
	}
}

function SelectButton( num )
{
var ob;
var tab;

	// do a number range check here.  If outside range then
	// reset to page zero
	
		// Do a range check on the number of pages.
	// this could be moved to the Get page number routine ??

	if (num < 0)
		num = 0;
		
	if (num >= page_tabl_cnt )
		num = 0;

	// Change the menu tabs for the current page
	
	tab = "button" + last_button;
	document.getElementById(tab).src = but_tab1[last_button];

	tab = "button" + num;
	document.getElementById(tab).src = but_tab1[num + page_tabl_cnt];

	last_button = num;
}

// Set up image labels from the table array
// into the items labeled menu.

function SetMenuLabels()
{
var i;	
var tab;

	for (i = 0; i < page_tabl_cnt; i++ )
	{
		tab = "menu" + i;
		document.getElementById(tab).src = tab_tab1[i];
	}
}

function GetPageNo( num, area )
{
var ob;
var tab;

	// do a number range check here.  If outside range then
	// reset to page zero
	
		// Do a range check on the number of pages.
	// this could be moved to the Get page number routine ??

	if (num < 0)
		num = 0;
		
	if (num >= page_tabl_cnt )
		num = 0;

	// Change the menu tabs for the current page
	
	tab = "menu" + last_page;
	document.getElementById(tab).src = tab_tab1[last_page];

	tab = "menu" + num;
	document.getElementById(tab).src = tab_tab1[num + page_tabl_cnt];

	cur_page = num;
	last_page = num;
	
	// Manage next and previous buttons.
	
	if ( cur_page == 0 )
	{	
		ob = document.getElementById('prev');
		if (ob )
			ob.style.display = 'none';
	}
	else
	{
		ob = document.getElementById('prev');
		if (ob )
			ob.style.display = 'block';
	}
	
	if ( cur_page == (page_tabl_cnt - 1))
	{
		ob = document.getElementById('next');
		if ( ob )
			ob.style.display = 'none';
	}
	else
	{
		ob = document.getElementById('next');
		if ( ob )
			ob.style.display = 'block';
	}
	
	GetPage( page_tabl[num], area );
}

function GetPageNext( area )
{
	if( (cur_page + 1) < page_tabl_cnt )
		cur_page++;
		
	GetPageNo( cur_page, area );
}

function GetPagePrev( area )
{
	if( (cur_page - 1) > -1 )
		cur_page--;
		
	GetPageNo( cur_page, area );
}

function GetPage( url, area )
{
var xmlhttp;
	
	if (window.XMLHttpRequest)
 	{
 		 // code for IE7+, Firefox, Chrome, Opera, Safari
 		 xmlhttp=new XMLHttpRequest();
 	}
	else if (window.ActiveXObject)
  	{
 		// code for IE6, IE5
 		 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
 	}
	else
  	{
  		alert("Your browser does not support XMLHTTP!");
  	}

	// Set up a call back function  
	// Other states could be used for managing errors
	// and putting up busy windows.

	xmlhttp.onreadystatechange=function()
	{
		if( xmlhttp.readyState == 4 )
	  	{
			// ajaxcontentarea.innerHTML = xmlhttp.responseText; - does not work with Firefox
			document.getElementById( area ).innerHTML = xmlhttp.responseText;
			document.body.style.cursor = "default";
	 	}
	}
	
	// Make the call
	
	document.body.style.cursor = "wait";
	xmlhttp.open( "GET", url, true );
	
	xmlhttp.send( null );
}


