
// JavaScript Document
/*
* Netscape Navigator 4.x (ns4): The most important test - NS4 does almost everything differently to the other browsers.
* Opera 5 (op5): Opera 5 lacks some of the functions that other browsers have. These include not being able to change an elements background colour and style class. Opera 5 also chokes when sizes and co-ordinates are set using the "px" suffix.
* Opera 6 (op6): Opera 6 only lacks the ability to change an elements style class.
* MSIE on the Mac (mac_ie): The problem with MSIE on the Mac is when you try to get the top co-ordinate of a table cell element. It incorrectly returns the top co-ordinate of the table element, not the table cell. To get round this, you have to base positioning on table row elements instead. Konqueror on Linux seems to have the opposite problem which adds to the fun.
*/
var ns4 = document.layers;
var op5 = (navigator.userAgent.indexOf("Opera 5")!=-1) || (navigator.userAgent.indexOf("Opera/5")!=-1);
var op6 = (navigator.userAgent.indexOf("Opera 6")!=-1) || (navigator.userAgent.indexOf("Opera/6")!=-1);
var agt=navigator.userAgent.toLowerCase();
var mac = (agt.indexOf("mac")!=-1);
var ie = (agt.indexOf("msie") != -1); 
var mac_ie = mac && ie;

//This function is lifted pretty much straight from Apple developer site (the copyright message allows it's use in other sites). This version will handle nested layers however.
function getStyleObject(objectId) {
	if(document.getElementById && document.getElementById(objectId)) {
		return document.getElementById(objectId).style;
	} else if (document.all && document.all(objectId)) {
		return document.all(objectId).style;
	} else if (document.layers && document.layers[objectId]) {
		return getObjNN4(document,objectId);
	} else {
		return false;
	}
} 

//The function getObjNN4(obj,name) returns the object for "name". It starts the search in "obj"
//This function is needed to find nested elements in a page.
function getObjNN4(obj,name)
{
	var x = obj.layers;
	var foundLayer;
	for (var i=0;i<x.length;i++)
	{
		if (x[i].id == name)
		 	foundLayer = x[i];
		else if (x[i].layers.length)
			var tmp = getObjNN4(x[i],name);
		if (tmp) foundLayer = tmp;
	}
	return foundLayer;
}


//The function hides or shows a page element.
function changeObjectVisibility(objectId, newVisibility) {
    var styleObject = getStyleObject(objectId, document);
    if(styleObject) {
	styleObject.visibility = newVisibility;
	return true;
    } else {
	return false;
    }
} 

//The function getImage returns the object for "name".
function findImage(name, doc) {
	var i, img;
	for (i = 0; i < doc.images.length; i++) {
    	if (doc.images[i].name == name) {
			return doc.images[i];
		}
	}
	for (i = 0; i < doc.layers.length; i++) {
    	if ((img = findImage(name, doc.layers[i].document)) != null) {
			img.container = doc.layers[i];
			return img;
    	}
	}
	return null;
}

function getImage(name) {
	if (document.layers) {
    	return findImage(name, document);
	}
	return null;
}

//The functions return the width or height of an object.
function getElementHeight(Elem) {
	if (ns4) {
		var elem = getObjNN4(document, Elem);
		return elem.clip.height;
	} else {
		if(document.getElementById) {
			var elem = document.getElementById(Elem);
		} else if (document.all){
			var elem = document.all[Elem];
		}
		if (op5) { 
			xPos = elem.style.pixelHeight;
		} else {
			xPos = elem.offsetHeight;
		}
		return xPos;
	} 
}

function getElementWidth(Elem) {
	if (ns4) {
		var elem = getObjNN4(document, Elem);
		return elem.clip.width;
	} else {
		if(document.getElementById) {
			var elem = document.getElementById(Elem);
		} else if (document.all){
			var elem = document.all[Elem];
		}
		if (op5) {
			xPos = elem.style.pixelWidth;
		} else {
			xPos = elem.offsetWidth;
		}
		return xPos;
	}
}

//The functions return the x or y co-ordinate of an element.
function getElementLeft(Elem) {
	if (ns4) {
		var elem = getObjNN4(document, Elem);
		return elem.pageX;
	} else {
		var elem;
		if(document.getElementById) {
			var elem = document.getElementById(Elem);
		} else if (document.all){
			var elem = document.all[Elem];
		}
		xPos = elem.offsetLeft;
		tempEl = elem.offsetParent;
  		while (tempEl != null) {
  			xPos += tempEl.offsetLeft;
	  		tempEl = tempEl.offsetParent;
  		}
		return xPos;
	}
}


function getElementTop(Elem) {
	if (ns4) {
		var elem = getObjNN4(document, Elem);
		return elem.pageY;
	} else {
		if(document.getElementById) {	
			var elem = document.getElementById(Elem);
		} else if (document.all) {
			var elem = document.all[Elem];
		}
		yPos = elem.offsetTop;
		tempEl = elem.offsetParent;
		while (tempEl != null) {
  			yPos += tempEl.offsetTop;
	  		tempEl = tempEl.offsetParent;
  		}
		return yPos;
	}
}

// For NS4.x
//NOTE: All the browsers except Netscape 4.x just call getElementWidth(myImage) or getElementHeight(myImage) to get the width or height.

//The functions return the width or height of an image.
function getImageWidth(myImage) {
	var x, obj;
	if (document.layers) {
		var img = getImage(myImage);
		return img.width;
	} else {
		return getElementWidth(myImage);
	}
	return -1;
}

function getImageHeight(myImage) {
	var y, obj;
	if (document.layers) {
		var img = getImage(myImage);
		return img.height;
	} else {
		return getElementHeight(myImage);
	}
	return -1;
}

//The functions return the x or y co-ordinate of an image.
function getImageTop(myImage) {
	var y, obj;
	if (document.layers) {
		var img = getImage(myImage);
		if (img.container != null)
			return img.container.pageY + img.y;
		else
			return img.y;
	} else {
		return getElementTop(myImage);
	}
	return -1;
}


function getImageLeft(myImage) {
	var x, obj;
	if (document.layers) {
		var img = getImage(myImage);
    	if (img.container != null)
			return img.container.pageX + img.x;
		else
			return img.x;
  	} else {
		return getElementLeft(myImage);
	}
	return -1;
}

//Move the element "myObject" to screen co-ordinates x, y.
//NOTE: All browsers except Opera 5 use the "px" suffix. Otherwise, when the doctype of your document is specified as HTML4.0 in the DOM browsers, the function will not work.

function moveXY(myObject, x, y) {
	obj = getStyleObject(myObject);
	if (ns4) {
		obj.top = y;
 		obj.left = x;
	} else {
		if (op5) {
			obj.pixelTop = y;
 			obj.pixelLeft = x;
		} else {
			obj.top = y + 'px';
 			obj.left = x + 'px';
		}	
	}
}


//Move the element "myObject" to screen co-ordinates x, y.
//NOTE: All browsers except Opera 5 use the "px" suffix. Otherwise, when the doctype of your document is specified as HTML4.0 in the DOM browsers, the function will not work.

function moveY(myObject,  y) {
	obj = getStyleObject(myObject);
	if (ns4) {
		obj.top = y;
	} else {
		if (op5) {
			obj.pixelTop = y;
		} else {
			obj.top = y + 'px';
		}	
	}
}

//Move the element "myObject" to screen co-ordinates x, y.
//NOTE: All browsers except Opera 5 use the "px" suffix. Otherwise, when the doctype of your document is specified as HTML4.0 in the DOM browsers, the function will not work.

function moveX(myObject, x) {
	obj = getStyleObject(myObject);
	if (ns4) {
 		obj.left = x;
	} else {
		if (op5) {
 			obj.pixelLeft = x;
		} else {
 			obj.left = x + 'px';
		}	
	}
}


//Changes the Style Class of "Elem" to "myClass".
//NOTE: This function will not work in Opera 5 or 6, or Netscape 4.x.
//There is a NS4 workaround at WebReference.com.

function changeClass(Elem, myClass) {
	var elem;
	if(document.getElementById) {
		var elem = document.getElementById(Elem);
	} else if (document.all){
		var elem = document.all[Elem];
	}
	elem.className = myClass;
}

//Changes the source the source of "target" to "source".
function changeImage(target, source) {
	var imageObj;
	
	if (ns4) {
		imageObj = getImage(target);
		if (imageObj) imageObj.src = eval(source).src; 
	} else {
		imageObj = eval('document.images.' + target);
		if (imageObj) imageObj.src = eval(source).src; 
	}
}

//Changes the background colour of element "myObject" to colour.
function changeBGColour(myObject, colour) {
	if (ns4) {
		var obj = getObjNN4(document, myObject);
		obj.bgColor=colour;
	} else {
		var obj = getStyleObject(myObject);
		if (op5) {
			obj.background = colour;	
		} else {
			obj.backgroundColor = colour;
		}	
	}
}


function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }

  return [ scrOfX, scrOfY ];
}

function getWindowSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }


  return [ myWidth, myHeight ];
}

//The functions sets the width or height of an object.
function setElementSize(objectId, newWidth, newHeight) {
	var styObj = getStyleObject(objectId);

	if( styObj.style ) { styObj = styObj.style; }

	if( styObj.resizeTo ) {
	  styObj.resizeTo( newWidth, newHeight );
	}
	var noPx = document.childNodes ? 'px' : 0;
	styObj.width = newWidth + noPx;
	styObj.pixelWidth = newWidth;
	styObj.height = newHeight + noPx;
	styObj.pixelHeight = newHeight;	

}

function showObject(objectId)
{
	var styObj = getStyleObject(objectId);
	
	if( styObj.style ) { styObj = styObj.style; }
	
	styObj.display='block';
}

function hideObject(objectId)
{
	var styObj = getStyleObject(objectId);
	
	if( styObj.style ) { styObj = styObj.style; }
	
	styObj.display='none';
	
}

function getFlashMovieObject(movieName)
{
  if (window.document[movieName]) 
  {
      return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
    return document.getElementById(movieName);
  }
}
 
