// Common functions.

// Function
// getDom()
// Find out which of the 3 possible DOM versions the current browser supports.
// Takes 2 arguments:
// elementID = this is the id of the element you are looking at.
// returnWhat = this must be "style" or "object" and will return the appropriate method for accessing the element.
function getDom(elementID, returnWhat) {	
	if (document.layers) {
		// Browser supports rubbish buggy Netscape 4 document object model.
		currentDomSupport = "netscape4DOM";
		// Check that element exists!
		if (document.layers[elementID]) {
			currentDomObject = document.layers[elementID];
			currentDomStyle = document.layers[elementID];
		} else {
			return false;
		}		
	}
	if (document.all) {
		// Browser supports Internet Explorer 4 document object model.
		currentDomSupport = "internetexplorer4DOM";
		// Check that element exists!
		if (document.all[elementID]) {
			currentDomObject = document.all[elementID];
			currentDomStyle = document.all[elementID].style;
		} else {
			return false;
		}
	}
	if (document.getElementById) {
		// Browser supports proper WC3 complient document object model.
		currentDomSupport = "wc3DOM";
		// Check that element exists!
		if (document.getElementById(elementID)) {
			currentDomObject = document.getElementById(elementID);
			currentDomStyle = document.getElementById(elementID).style;
		} else {
			return false;
		}
	}
	if (returnWhat == "object") {
		return currentDomObject;
	}
	if (returnWhat == "style") {
		return currentDomStyle;
	}
}

// Function
// getWindowDimensions()
// Find the inner dimensions of the current window or frame.
// Takes 1 arguments:
// returnWhat = this must be "width" or "height" and will return the appropriate value.
function getWindowDimensions(returnWhat) {
	// All except Explorer.
	if (self.innerHeight) {
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	// Explorer 6 Strict Mode.
	} else if (document.documentElement && document.documentElement.clientHeight) {
		windowWidth = document.documentElement.clientWidth;
		windowHeight= document.documentElement.clientHeight;
	// other Explorers
	} else if (document.body) {
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	if (returnWhat == "width") {
		return windowWidth;
	}
	if (returnWhat == "height") {
		return windowHeight;
	}
}

// Function
// getScrollPostion()
// Find the scroll position of the current window or frame.
// Takes 1 arguments:
// returnWhat = this must be "width" or "height" and will return the appropriate value.
function getScrollPostion(returnWhat) {
	// All except Explorer.
	if (self.pageYOffset) {
		windowWidth = self.pageXOffset;
		windowHeight = self.pageYOffset;
	// Explorer 6 Strict Mode.
	} else if (document.documentElement && document.documentElement.clientHeight) {
		windowWidth = document.documentElement.scrollLeft;
		windowHeight= document.documentElement.scrollTop;
	// other Explorers
	} else if (document.body) {
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.scrollTop;
	}
	if (returnWhat == "width") {
		return windowWidth;
	}
	if (returnWhat == "height") {
		return windowHeight;
	}
}

// Function
// writeDIV()
// Write the content of a DIV.
// NOTE - For Netscape 4 (and only for Netscape 4) you have to give the div element an absolute position when defining on the page.
// Takes 2 arguments:
// text = this is the content that you wish to write to the DIV.
// elementID = this is the id of the DIV element you are writing to.
function writeDIV(text,elementID) {
	// WC3 complient browsers.
	if (document.getElementById) {
		x = document.getElementById(elementID);
		x.innerHTML = '';
		x.innerHTML = text;
	// Internet Explorer 4.
	} else if (document.all) {
		x = document.all[elementID];
		x.innerHTML = text;
	// Bloody Netscape 4.
	} else if (document.layers) {
		x = document.layers[elementID];
		x.document.open();
		x.document.write(text);
		x.document.close();
	}
}

// Function
// getPostion()
// Find the absolute X or Y pixel position of the element specified
// Takes 2 arguments:
// elementID = this is the id of the element you are looking at.
// returnWhat = this must be "x" or "y" and will return the appropriate value.
function getPostion(elementID, returnWhat) {
	// WC3 complient browsers.
	if (elementID.offsetLeft) {
		elementX = elementID.offsetLeft;
		elementY = elementID.offsetTop;
	// Bloody Netscape 4.
	} else if (elementID.x) {
		elementX = elementID.x;
		elementY = elementID.y;
	}
  if (returnWhat == "x") {
		return elementX;
	}
	if (returnWhat == "y") {
		return elementY;
	}
}
