// JavaScript Code for Nykris-designed Websites
// (c) 2003 Nykris Digital Design Ltd.
// Engineer: Graham Bartram

// Global Settings

var gUseQuickTime = true; // If this is true the code will replace Flash elements with .movs if Flash isn't available and QuickTime is.



// Browser ID Utilities

var gAgent = window.navigator.userAgent;
var gAgentVers = parseInt(gAgent.charAt(gAgent.indexOf("/")+1),10);

function is_explorer()
{
	return gAgent.indexOf("MSIE") > 0;
}
	
function is_macexplorer()
{
	if (gAgent.indexOf("Mac") <= 0)
		return false;
	else
		return gAgent.indexOf("MSIE") > 0;
}
	
function is_macnetscape()
{
	if (gAgent.indexOf("Mac") <= 0)
		return false;
	else
		return !(gAgent.indexOf("MSIE") > 0);
}
	
function is_macie4()
{
	if ((gAgent.indexOf("Mac") > 0) && (gAgent.indexOf("MSIE") > 0) && (gAgentVers < 5))
		return true;
	else
		return false;
}

function is_pcnetscape()
{
	if (gAgent.indexOf("Mac") > 0)
		return false;
	else
		return !(gAgent.indexOf("MSIE") > 0);
}
	
function is_aol()
{
	return gAgent.indexOf("AOL") > 0;
}


function choose_stylesheet(name)
{
	if (is_macexplorer())
		name = name + "_macie";
	else if (is_macnetscape())
		name = name + "_macnet";
	else if (is_explorer())
		name = name + "_ie";
	else
		name = name + "_net";
		
	document.write('<link rel="stylesheet" href="' + name + '.css" type="text/css">');
}



// Rollover Utilities


var gRollovers = new Object();
var gStaticMenu = new Object();
var gRolloversPath = "*";

	
	
// Recursively look for an element, including searching the layers in Netscape. Doesn't support frames.

function find_element(name,layer)
{
  var element=null,i;
  if (!layer)
    {
    layer=document;
    }
  if (!(element=layer[name]) && layer.all)
    {
    element=layer.all[name];
    }
  for (i=0; !element && i<layer.forms.length; i++)
    {
    element=layer.forms[i][name];
    } 
  for (i=0; !element && layer.layers && i<layer.layers.length; i++)
    {
    element=find_element(name,layer.layers[i].document);
    }
  if (!element && document.getElementById)
    {
    element=document.getElementById(name);
    }
  if (!element && document.layers)
  	{
  	//alert("trying layers for "+name+":"+document.layers[name]);
  	element=document.layers[name];
  	}
  //if (!element) alert("Could not find " + name);
  return element;
}



// This function locates a graphic element whose name parameter is set to "rollover_marker" and sets the
// path for rollovers to the path of that graphic element.

function set_rollovers_path()
{
	gRolloversPath = '';
	if (document.images)
	{
		var img = (!is_explorer()) ? find_element('rollover_marker',0) : document['rollover_marker'];
		if (img)
		{
			var src = img.src
			var lastOffset = src.lastIndexOf('/');
			if (lastOffset != -1)
			{
				gRolloversPath = src.substr(0,lastOffset+1);
			}
		}
	}
}


// Loads the normal and overlay versions of the button, but will not try to do so for the
// "rollover_marker" image or any image whose name begins with an underscore.

function load_rollover(button)
{
	//alert("Loading rollover images for " + gRolloversPath + button);
	if (document.images && button.charAt(0) != '_' && button.substr(0,15) != 'rollover_marker')
	{
		gRollovers[button] = new Object();
		gRollovers[button][0] = new Image();
		gRollovers[button][0].src = gRolloversPath + button + '_norm.gif';
		gRollovers[button][1] = new Image();
		gRollovers[button][1].src = gRolloversPath + button + '_over.gif';
	}
}


// Loops through all the named images in the page and attempts to load the rollover images for them

function load_all_rollovers()
{
	set_rollovers_path();
	if (document.images && gRolloversPath != '*')
		{
		var numImages = document.images.length;
		if (numImages > 0)
		{
			for (var i=0;i<numImages;i++)
			{
				if (document.images[i])
				{
					if (document.images[i].name) load_rollover(document.images[i].name);
				}
			}
		}
		
 		gStaticMenu['quizradio_off'] = new Image();
 		gStaticMenu['quizradio_off'].src = gRolloversPath + 'quizradio_off.gif';
 		gStaticMenu['quizradio_on'] = new Image();
 		gStaticMenu['quizradio_on'].src = gRolloversPath + 'quizradio_on.gif';
/* 		gStaticMenu['uparrow_on'] = new Image(); */
/* 		gStaticMenu['uparrow_on'].src = gRolloversPath + 'uparrow_on.gif'; */
/* 		gStaticMenu['transparent'] = new Image(); */
/* 		gStaticMenu['transparent'].src = gRolloversPath + 'transparent.gif'; */
/* 		gStaticMenu['anchor'] = new Image(); */
/* 		gStaticMenu['anchor'].src = gRolloversPath + 'anchor.gif'; */
/* 		gStaticMenu['anchor_on'] = new Image(); */
/* 		gStaticMenu['anchor_on'].src = gRolloversPath + 'anchor_on.gif'; */
		}
}



function rollover(button,state)
{
	if (document.images && gRolloversPath != '*')
	{
		if (gRollovers[button])
		{
			var img = (!is_explorer()) ? find_element(button,0) : document[button];
			if (img) img.src = gRollovers[button][state].src;
			return true;
		}
	}
	return false;
}



function rollover_image(button,imageName)
{
	//alert("1 " + button + "," + imageName);
	if (document.images && gRolloversPath != '*')
	{
		//alert("2 " + button + "," + imageName);
		var img = (!is_explorer()) ? find_element(button,0) : document[button];
		if (img)
		{
			if (gStaticMenu[imageName])
			{
				img.src = gStaticMenu[imageName].src;
			}
			else
			{
				//alert("3 " + button + "," + img + "," + gRolloversPath + imageName + '.gif');
				img.src = gRolloversPath + imageName + '.gif';
			}
			return true;
		}
	}
	return false;
}



// Miscellaneous Javascript Utilities

var gPopup = "none";




// Open a window in either the topleft or topright screen corner

function openWin(url,name,w,h,loc)
{
	var secs = new Date();

	closeWin();

	if (loc == 'topright')
	{
		gPopup=window.open(url,'popup'+secs.getTime(),'left='+(screen.width.valueOf()-(w+100))+',top=100,width='+w+',height='+h+',toolbar=no,location=no,status=no,scrollbars=yes,resizable=yes')
	}
	else if (loc == 'topleft')
	{
		gPopup=window.open(url,'popup'+secs.getTime(),'left=100,top=100,width='+w+',height='+h+',toolbar=no,location=no,status=no,scrollbars=yes,resizable=yes')
	}
}



// Open a window in either the topleft or topright screen corner

function openFixedWin(url,name,w,h,loc)
{
	var secs = new Date();

	closeWin();

	if (loc == 'topright')
	{
		gPopup=window.open(url,'popup'+secs.getTime(),'left='+(screen.width.valueOf()-(w+100))+',top=100,width='+w+',height='+h+',toolbar=no,location=no,status=no,scrollbars=no,resizable=no')
	}
	else if (loc == 'topleft')
	{
		gPopup=window.open(url,'popup'+secs.getTime(),'left=100,top=100,width='+w+',height='+h+',toolbar=no,location=no,status=no,scrollbars=no,resizable=no')
	}
}

// jump menu script


function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

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_jumpMenuGo(selName,targ,restore){ //v3.0
  var selObj = MM_findObj(selName); if (selObj) MM_jumpMenu(targ,selObj,restore);
}

// Text only

function execLink () {
   var cURL = "http://www.oxfam.org.uk/cgi-bin/parser.pl/" + location.host + location.pathname;
   window.location = cURL;
   return;
}


// Open a popup window

choose_stylesheet("/stylesheets/css_whatwedo")

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


// Close the popup window if it is open

function closeWin()
{	
	if (gPopup)
	{
		if (!is_macie4())
			{
				if (typeof(gPopup) == "object")
				{
					if (gPopup.closed == false)
					{
						gPopup.close();
					}
					gPopup="none";
				}
			}
		else
			{
				if (typeof(gPopup) == "object")
				{
					gPopup="none";
				}
			}
	}
}
