function MM_reloadPage(init) {  //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_showHideLayers() { //v3.0
var i,p,v,obj,args=MM_showHideLayers.arguments;
for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
obj.visibility=v; }
}

function MM_callJS(jsStr) { //v2.0
return eval(jsStr)
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function StatusMsg(msgStr) { 
  status=msgStr;
  document.MM_returnValue = true;
}

function popupMsg(msg) { 
  alert(msg);
}


function Restore() {
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function Find(n, d) {
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=Find(n,d.layers[i].document); return x;
}

function Swap() {
  var i,j=0,x,a=Swap.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=Find(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function passSwap() {
	MM_swapImage('download','','/images/down2.jpg',1);
}


function openMyPictureWindow(image_name,img_w,img_h,img_alt)	//Ben's function for enlarging images in a customised window
	{

	/*****
	Function to create a pop-up window for displaying a graphic...
	TO USE:
	
	call the function using the following arguments in order;
	image name (e.g. mypic.gif), image width in pixels, image height in pixels, image alt text...e.g...

	openMyPictureWindow('mypic.gif',322,404,'a_diagram')

	alt text MUST be strung together with NO white space

	Note: size is sometimes ignored in Netscape!
	*****/

	

	var scrnWidth = screen.availWidth-10;
	var scrnHeight = screen.availHeight-30;

	var copy_w = img_w;
	var copy_h = img_h;

	var style_path = "/bgs.css";
	if((navigator.appVersion.indexOf("Mac")!= -1))
		{
		style_path = "/bgs.css";
		}
			

	img_w = img_w * 1.1;		//increase dimensions by a factor to accommodate the text
	img_h = (img_h * 1.1) + 45;
	
	var sw_track = 0;


	/***
	set case for different instances of image size
	***/
	if(img_w >= scrnWidth && img_h >= scrnHeight)
		sw_track = 1;

	else if(img_w >= scrnWidth && img_h < scrnHeight)
		sw_track = 2;

	else if(img_h >= scrnHeight && img_w < scrnWidth)
		sw_track = 3;

	else
		sw_track = 4;




	/***
	detect case which describes requirements of unique image
	e.g. small image can have a window where both dimensions are set
	but larger image window is restricted to available screen size and given scrollbars
	***/
	switch(sw_track)
		{

		case 1:
			image_window = window.open("",null,"width="+scrnWidth+",height="+scrnHeight+",scrollbars=yes,status=no,location=no,directories=no,resizable=yes,toolbar=no,menubar=no");
			break;

		case 2:
			image_window = window.open("",null,"width="+scrnWidth+",height="+img_h+",scrollbars=yes,status=no,location=no,directories=no,resizable=yes,toolbar=no,menubar=no");
			break;

		case 3:
			image_window = window.open("",null,"width="+img_w+",height="+scrnHeight+",scrollbars=yes,status=no,location=no,directories=no,resizable=yes,toolbar=no,menubar=no");
			break;

		case 4:
			image_window = window.open("",null,"width="+img_w+",height="+img_h+",scrollbars=no,status=no,location=no,directories=no,resizable=yes,toolbar=no,menubar=no");
			break;

		}

	image_window.moveTo(0, 0);

	image_window.document.close();
	image_window.document.open();
	image_window.document.write("<html><head><link rel='stylesheet' href='" + style_path + "' type='text/css'><title>" + image_name + "</title>"
	+ "</head><body bgcolor='ffffff' onBlur='window.close()'><div align='center'>"
	+ "<img src='" + image_name + "' border='0' alt=" + img_alt + " width='"+copy_w+"' height='"+copy_h+"'>"
	+ "<p>Please <a href='' onClick='window.close()' class='bodyLink'>close</a> this window to return to <i>" + document.title +"</i></p></div>"
	+ "</body></html>");
	img_w = 0;
	img_h = 0;
	img_alt = null;

	

	
	}	//close openMyPictureWindow()






/*****
Function to open up a customised window for loading a URL or specific text by Ben.

TO USE:

You can call the function using various arguments

1) Load URL;

e.g.  infoWindow('foo.html','foowindow',400,200,'','','','topleft','')

will load foo.html into a 400*200 pixel window that is positioned at the top left of the screen

2) Load specific html content

e.g. infoWindow('','foowindow',450,300,'/images/bgimg.gif','My Window','<p>Any html</p>','','/styles/mystyle.css')

will open a 450*300 pixel window in the centre of the screen (default behaviour) containing the specified html content
with the specified background image and window title with the specified style-sheet applied.

*****/

var i;


function infoWindow(url,name,w,h,bg_img,title,content,position,style)
	{

	var scrnWidth = screen.availWidth-10;
	var scrnHeight = screen.availHeight-30;

	if(h == "")
		{
		var length = content.length;
		var win_h = length/2.3 + 90;
		}
	else
		{
		win_h = h;
		}

	var info_window = new Array(10);	


	if(url == "")
		{

		if(win_h >= scrnHeight)
			{
			win_h = scrnHeight - 30;
			}
		if(w >= scrnWidth - 150)
			{
			w = scrnWidth - 150;
			}
		

		info_window[i] = window.open(url,name,"width=" + w + ",height=" + win_h + ",scrollbars=yes,status=no,location=no,directories=no,resizable=yes,toolbar=no,menubar=yes");
	
		
		if(position == "topleft")
			{
			info_window[i].moveTo(0,0);
			}
		else if(position == "topright")
			{
			info_window[i].moveTo(scrnWidth - w,0);
			}
		else if(position == "bottomleft")
			{
			info_window[i].moveTo(0,scrnHeight - win_h);
			}
		else if(position == "bottomright")
			{
			info_window[i].moveTo(scrnWidth - w,scrnHeight - win_h);
			}
		else //default to centre
			{
			info_window[i].moveTo((scrnWidth/2)-(w/2), (scrnHeight/2)-(win_h/2));
			}

		info_window[i].document.close();
		info_window[i].document.open();
		info_window[i].document.write("<html><head><link rel='stylesheet' href='" + style + "' type='text/css'><title>" + title + "</title></head><body background='" + bg_img + "'>" + content	
					+ "<p align='center'>Please <a href='' onClick='window.close()' class='bodyLink'>close</a> this window to return to <i>" + document.title +"</i></p>");
		}
	else
		{
		if(h >= scrnHeight)
			{
			h = scrnHeight;
			}
		info_window[i] = window.open(url,name,"width=" + w + ",height=" + h + ",scrollbars=yes,status=no,location=no,directories=no,resizable=yes,toolbar=no,menubar=yes");

		
		if(position == "topleft")
			{
			info_window[i].moveTo(0,0);
			}
		else if(position == "topright")
			{
			info_window[i].moveTo(scrnWidth - w,0);
			}
		else if(position == "bottomleft")
			{
			info_window[i].moveTo(0,scrnHeight - h);
			}
		else if(position == "bottomright")
			{
			info_window[i].moveTo(scrnWidth - w,scrnHeight - h);
			}
		else //default to centre
			{
			info_window[i].moveTo((scrnWidth/2)-(w/2), (scrnHeight/2)-(h/2));
			}
		}
	i++;
	
	} //end infoWindow

//PDBE functions to hide and show layers on DFID KaR Flowchart

var isNav4 = false;
var isNav5up = false;
var isNav = false;
var isIE = false;
if (navigator.appName == "Netscape") {
	isNav =true;
	if (navigator.appVersion.search("5.0") == -1)
   		isNav4 = true;
	else isNav5up = true;

	}
else 
	isIE = true;

// get the layer object called "name"
function getLayer(name) {
	  if (isNav4)
	    return(document.layers[name]);
		  else if (isIE) {
		    layer = eval('document.all.' + name + '.style');
		    return(layer);
		  } else if (isNav) {
		//	var theElements = document.getElementsByTagName("DIV");


//			var theObj;
//			var j = -1;
//			for (i=0;i<theElements.length;i++) {
//				if (theElements[i].id==name) theObj = theElements[i].style;
//			}
//
//			return theObj

			//funny goings on - above commented out and included below for Netscape4
			return(document.layers[name]);

		  }
		  else
		    return(null);
	}

function isVisible(name) {
	  var layer = getLayer(name);
	  if (isNav && layer.visibility == "show")
	    return(true);
	  if (isIE && layer.visibility == "visible")
	    return(true);
	  return(false);
}

// toggle layer to invisible
function hideLayer(name) {		
  	var layer = getLayer(name);		
  	if (isNav4)
    	layer.visibility = "hide";
	else
   		 layer.visibility = "hidden";
}

// toggle layer to visible
function showLayer(name) {		
  	var layer = getLayer(name);		
  	if (isNav4)
    	layer.visibility = "show";
	else
   	 layer.visibility = "visible";
}

function setupLeftMenu(){
	if(document.getElementById && document.getElementsByTagName)
		{
		var theTable=document.getElementById('leftMenuTable');
		if(theTable)
			{
			var theText='';
			var theLinks = theTable.getElementsByTagName("a");
			var pageURL=document.location.href;
			// find first slash after http:slashslash i.e. after posn 7
			// assumes user is using http
			var pagePath1=pageURL.indexOf('/',7);
			var pagePath2=pageURL.lastIndexOf('/');
			var pagePathTxt=pageURL.slice(pagePath1,pagePath2);
			pagePathTxt=pagePathTxt.toUpperCase();
			// alert(pagePathTxt);
			pageURL=pageURL.toUpperCase();
			// alert(pageURL);
			for(var i=0;i<theLinks.length;i++)
				{
				var theLinkURL=theLinks[i].href;
				theLinkURL=theLinkURL.toUpperCase();
				// alert(theLinkURL);
				if(theLinkURL == pageURL){ 
					// link url = page url
					// exact match
					theText=theLinks[i].innerHTML;
					theText=theText.bold();
					theLinks[i].innerHTML=theText;
					}
				else if(pageURL.indexOf(theLinkURL,0) == 0){
					// menu link is a substring at start of page link
					// i.e. it is a page higher up the tree = parent
					theLinks[i].style.color='black';
					//theText=theLinks[i].innerHTML;
					//theText=theText.italics();
					//theLinks[i].innerHTML=theText;
					}
				else if(theLinkURL.indexOf(pagePathTxt,0) != -1){
					// url of link matches path of page at start of page link
					// both in same directory = some relation
					// theText=theLinks[i].innerHTML;
					theLinks[i].style.color='black';
					// theText=theText.bold();
					// theLinks[i].innerHTML=theText;
					}
				else
					{
					// unrelated link - colour black
					theLinks[i].style.color='black';
					}
				}
			}
		else{return;}
		}
	else{return;}
	}

