// ------------------------------------------------------------------------------------------------------------
// movePage -	Used to Page between sets of objects: needs to be used in conjunction wit a <form> that has
//				all the correct hidden fields defined
// ------------------------------------------------------------------------------------------------------------
// obj:				Object defining Current thing being paged
// objMax:			Max thing being paged
// objIncrement:	Increment thing being paged by
// pageCurr:		Object defining Current page
// pageMax:			Max page
// pageIncr:		Increment page by
// objPerPageCurr:	No of objects (being paged) per page
// action:			The action to perform (all, pages, back go, fwd)
// ------------------------------------------------------------------------------------------------------------

function movePage(objCurr, objMax, objIncrement, pageCurr, pageMax, pageIncr, displayWhat, objPerPageCurr, objPerPageDefault, goToURL, action)
	{
//	alert("Start: " +
//			objCurr + " " + objMax + " " + objIncrement + " " +
//			pageCurr + " " + pageMax + " " +
//			pageIncr + " " + objPerPageCurr + " " +
//			action + "");
	// Note: Math.round() used to force type to integer
	if (action == 'all')
		{
		objCurr = 1;
		pageCurr = 1;
		objPerPageCurr = objMax;
		displayWhat = "Pages";
		}
	if (action == 'pages')
		{
		objCurr = 1;
		pageCurr = 1;
		objPerPageCurr = objPerPageDefault;
		displayWhat = "All";
		}
	if (action == 'back')
		pageCurr = pageCurr - pageIncr;
	if (action == 'go')
		pageCurr = pageIncr;
	if (action == 'fwd')
		pageCurr = pageCurr + pageIncr;
	if (pageCurr < 0)
		pageCurr = 1;
	if (pageCurr > pageMax)
		pageCurr = pageMax;
//	alert("Mid: " + 
//			objCurr + " " + objMax + " " + objIncrement + " " +
//			pageCurr + " " + pageMax + " " +
//			pageIncr + " " + objPerPageCurr + " " +
//			action + "");
	objCurr = ((( pageCurr - 1) * objPerPageCurr) + 1);
	// document.getElementById('fpaging').submit();
	updateSession(	"" +
					"objPerPageDefault~" + objPerPageDefault + "|" +
					"objPerPageCurr~" + objPerPageCurr + "|" +
					"objCurr~" + objCurr + "|" +
					"pageCurr~" + pageCurr + "|" +
					"displayWhat~" + displayWhat
					);
//	alert(goToURL + "&pageNo=" + pageCurr +
//		"  (" +
//		"objPerPageDefault~" + objPerPageDefault + "|" +
//		"objPerPageCurr~" + objPerPageCurr + "|" +
//		"objCurr~" + objCurr + "|" +
//		"pageCurr~" + pageCurr + "|" +
//		"displayWhat~" + displayWhat +
//		")");
	window.location = goToURL +"&pageNo=" + pageCurr;
//	alert("End: " +
//			objCurr + " " + objMax + " " + objIncrement + " " +
//			pageCurr + " " + pageMax + " " +
//			pageIncr + " " + objPerPageCurr + " " +
//			action + "");
/* ------------------
------------------ */
	} // movePage
	
// ------------------------------------------------------------------------------------------------
// updateSession - Tests What Key has been pressed and acts acordingly
// ------------------------------------------------------------------------------------------------
// whatToSet:	String contaning one or more pairs of var/val in the format :-
//					var=val|var=val|var=val......
// ------------------------------------------------------------------------------------------------
 
function updateSession(whatToSet) 
	{
	objAjax.open("POST", "routines/setSessionVars.php");
	objAjax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	
	ajaxTxt = "whatToSet=" + whatToSet;
	//	alert(ajaxTxt);
	//	Call Function to process the results once Ajax process has completed
	objAjax.onreadystatechange = ajaxResponse; 
	//	Send the data. Use something other than null when sending using the POST method
	// alert('ajaxSend: (' + ajaxTxt + ')');
	objAjax.send(ajaxTxt);
	} // updateSession

// ------------------------------------------------------------------------------------------------
// KeyWhat - Tests What Key has been pressed and acts acordingly
// ------------------------------------------------------------------------------------------------
// evnt:	The Event object that were working with
// ------------------------------------------------------------------------------------------------
 
function createRequestObject(){
// The following function creates an XMLHttpRequest object... 
var request_o; //declare the variable to hold the object.
var browser = navigator.appName; //find the browser name
	if	(browser == "Microsoft Internet Explorer")
		{
		// Create the object using MSIE's method 
		request_o = new ActiveXObject("Microsoft.XMLHTTP");
		}
	else {
		// Create the object using other browser's method 
		request_o = new XMLHttpRequest();
		}
	return request_o; //return the object
	} // createRequestObject

var objAjax = createRequestObject(); 

// ------------------------------------------------------------------------------------------------
// ajaxResponse - Handles the Ajax responses 
// ------------------------------------------------------------------------------------------------
 
function ajaxResponse()
	{
	if	(objAjax.readyState == 4)
		{	//	Finished loading the response
		//	alert('disp JshOrdDisp');
		var response = objAjax.responseText;
		// alert('ajaxResponse: (' + response + ')');
		}
	} // typJshOrdDispDisplay

// ------------------------------------------------------------------------------------------------------------
// movePageOld -	Used to Page between sets of objects: needs to be used in conjunction wit a <form> that has
//					all the correct hidden fields defined
// ------------------------------------------------------------------------------------------------------------
// obj:				Object defining Current thing being paged
// objMax:			Max thing being paged
// objIncrement:	Increment thing being paged by
// pageCurr:		Object defining Current page
// pageMax:			Max page
// pageIncr:		Increment page by
// objPerPageCurr:	No of objects (being paged) per page
// action:			The action to perform (all, pages, back go, fwd)
// ------------------------------------------------------------------------------------------------------------

function movePageOld(objThis, objMax, objIncrement, pageCurr, pageMax, pageIncr, displayWhat, objPerPageCurr, objPerPageDefault, action)
	{
//	alert("Start: " +
//		Math.round(objThis.value) + " " + objMax + " " + objIncrement + " " +
//		Math.round(pageCurr.value) + " " + pageMax + " " +
//		pageIncr + " " + Math.round(objPerPageCurr.value) + " " +
//		action + "");
	// Note: Math.round() used to force type to integer
	if (action == 'all')
		{
		objThis.value = 1;
		pageCurr.value = 1;
		objPerPageCurr.value = objMax;
		displayWhat.value = "Pages";
		}
	if (action == 'pages')
		{
		objThis.value = 1;
		pageCurr.value = 1;
		objPerPageCurr.value = objPerPageDefault.value;
		displayWhat.value = "All";
		}
	if (action == 'back')
		pageCurr.value = Math.round(pageCurr.value) - pageIncr;
	if (action == 'go')
		pageCurr.value = pageIncr;
	if (action == 'fwd')
		pageCurr.value = Math.round(pageCurr.value) + pageIncr;
	if (Math.round(pageCurr.value) < 0)
		pageCurr.value = 1;
	if (Math.round(pageCurr.value) > Math.round(pageMax))
		pageCurr.value = pageMax;
//alert("Mid: " + 
//		Math.round(objThis.value) + " " + objMax + " " + objIncrement + " " +
//		Math.round(pageCurr.value) + " " + pageMax + " " +
//		pageIncr + " " + Math.round(objPerPageCurr.value) + " " +
//		action + "");
	objThis.value = ((( Math.round(pageCurr.value) - 1) * Math.round(objPerPageCurr.value)) + 1);
	document.getElementById('fpaging').submit();
//alert("End: " +
//		Math.round(objThis.value) + " " + objMax + " " + objIncrement + " " +
//		Math.round(pageCurr.value) + " " + pageMax + " " +
//		pageIncr + " " + Math.round(objPerPageCurr.value) + " " +
//		action + "");
	} // movePageOld

// ------------------------------------------------------------------------------------------------------------
// openWindow -	Used open a popup window
// ------------------------------------------------------------------------------------------------------------
// mylink:		The url of the page to open
// windowname:	Name of the window to open
// ------------------------------------------------------------------------------------------------------------

function openWindow(mylink, windowname, features)
	{
var href;
	if (! window.focus)
		return true;
	if (typeof(mylink) == 'string')
		href = mylink;
	else href = mylink.href;
	if (features == '')
		features = 'top=200px, left=200px; width=550px, height=310px, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no';
//	alert(href);
//	alert(windowname);
//	alert(features);
	window.open(href, windowname, features);
	return false;
	} // openWindow

// ------------------------------------------------------------------------------------------------
// OpenNewWin - Opens a new window checking for popup blockers.
//			    If the new window does not open a warning to turn off popup blockers is issued.
// ------------------------------------------------------------------------------------------------
// Typ        : Description of the type of function being performed: used in warning if required
// Desc       : Description to be used in warning if required
// URLName    : Full name of the URL to be opened, Any args should have been appended to the URLName
// LinkType   : Controls the type of window ("_self" = Same window), ("" = Seperate NEW window)
// Features   : Defines the "Features" of the window (if new), position, size, bars etc
// ------------------------------------------------------------------------------------------------

function OpenNewWin(Typ, Desc, URL, LinkType, Features)
	{
var oWin;
	oWin = window.open(URL, LinkType, Features);
	if (oWin==null || typeof(oWin)=="undefined") 
		{
		// Replace any <br />'s in Desc as its displaying in an Alert box
		myRe = /<br \/>/g;
		Msg = Desc.replace(myRe, "\n\r");
		alert(Typ + ": The system is trying to open a new window " +
			"to perform the function shown above but it failed to open.\n\r\n\r" + 
			Msg +
			"\n\r\n\rFor the system to work properly, as intended, you must have popups enabled for this web site.\n\r\n\r" +
			"If you are running a Popup blocker, please set it to allow popups for this site.\n\r\n\r" +
			"Depending on the browser you are using, PopUp settings can usually be found in Options or Preferences.");
		}
	} // OpenNewWin

// ------------------------------------------------------------------------------------------------------------
// mousePos -	Used to get the mouse x/y cordinates
// ------------------------------------------------------------------------------------------------------------

function mousePos(event)
	{
	mouseX = event.clientX;
	mouseY = event.clientY;
	return [mouseX,mouseY];
	} // mousePos
	
// ------------------------------------------------------------------------------------------------
// FindPos -	Finds the position of an object (Obj) relative to the window. It does it in a way 
//				that should work in all browsers by chaining back through its parents until it
//				reaches the root. It returns an array containing the (x,y) cordinates.
//				Left[0] top[1]
// ------------------------------------------------------------------------------------------------
// Obj: The object to find the position of
// ------------------------------------------------------------------------------------------------

function FindPos(objThis)
	{
	var curleft = curtop = 0;
	if (objThis.offsetParent) 
		{
		curleft = objThis.offsetLeft
		curtop = objThis.offsetTop
		while (objThis = objThis.offsetParent) 
			{
			curleft += objThis.offsetLeft
			curtop += objThis.offsetTop
			}
		}
	return [curleft,curtop];
	} //FindPos

// ------------------------------------------------------------------------------------------------------------
// winWidth -	Returns the width of the current window
// ------------------------------------------------------------------------------------------------------------

function winWidth() 
	{
var width = 0;
	if	(!window.innerWidth)
		{
		// ----- Interner Explorer -----
		if	(!(document.documentElement.clientWidth == 0))
			{
			// Strict mode
			width = document.documentElement.clientWidth;
			}
		else {
			// ----- Quirks mode -----
			width = document.body.clientWidth;
			}
		}
	else {
		// ----- W3C -----
		width = window.innerWidth;
		}
	return(width);
	} // winHeight

// ------------------------------------------------------------------------------------------------------------
// winHeight -	Returns the height of the current window
// ------------------------------------------------------------------------------------------------------------

function winHeight() 
	{
var height = 0;
	if	(!window.innerHeight)
		{
		// ----- Interner Explorer -----
		if	(!(document.documentElement.clientWidth == 0))
			{
			// Strict mode
			height = document.documentElement.clientHeight;
			}
		else {
			// ----- Quirks mode -----
			height = document.body.clientHeight;
			}
		}
	else {
		// ----- W3C -----
		height = window.innerHeight;
		}
	return(height);
	} 

// ------------------------------------------------------------------------------------------------------------
// ToggleObject -	Toggles the display style of a DOM Object
// ------------------------------------------------------------------------------------------------------------

function ToggleObject(ObjName, SetTo) 
	{
	ToggleWhat = document.getElementById(ObjName);
	if (SetTo == "")
		{
		if (ToggleWhat.style.display == "inline")
			ToggleWhat.style.display='none';
		else ToggleWhat.style.display='inline';
		}
	else ToggleWhat.style.display=SetTo;
	} // ToggleObject	
	
// ------------------------------------------------------------------------------------------------------------
// SortMap -	Sorts the height of the td containing maps to be the same height as the map image so the 
//				bottom bar (bottom.html) appears in the correct place
//				Does it 5 times with delay to make sure all the page has been drawn.
// ------------------------------------------------------------------------------------------------------------

function SortMap() 
	{
	divMap1 = document.getElementById('divMap1');
	imgMap = document.getElementById('imgMap');
	for (Cnt=0; Cnt<=5; Cnt++)
		{
		var timer1=setTimeout("divMap1.style.height = imgMap.height + 'px';", (2500*Cnt));
		//alert('Map : ' + Cnt);
		} // SortMap
	}
