// CrossBrowserAPI.js custom API for cross-platform DHTML
// Adapted by Guy Penfold (http://www.pds.com.au)
// from "JavaScript Bible" 4th Edition by Danny Goodman (http://www.dannyg.com)

// Browser detection
var IsNetscape = (navigator.appName.indexOf("Netscape") >= 0) ? 1 : 0
var IsIE4 = (navigator.appVersion.indexOf("MSIE 4.") >= 0) ? 1 : 0
var IsIE5 = (navigator.appVersion.indexOf("MSIE 5.") >= 0) ? 1 : 0
var IsIE6 = (navigator.appVersion.indexOf("MSIE 6.") >= 0) ? 1 : 0

// Convert object name string or object reference
// into a valid object reference
function GetObject(Object) {
	if (document.layers) {
		return document.layers[Object]
	}
	if (document.getElementById) {
		return document.getElementById(Object)
	}
	if (document.all) {
		return document.all(Object)
	}
	return null
}
function GetObjectFromWindow(Win, Object) {
	if (Win.document.layers) {
		return Win.document.layers[Object]
	}
	if (Win.document.getElementById) {
		return Win.document.getElementById(Object)
	}
	if (Win.document.all) {
		return Win.document.all(Object)
	}
	return null
}

// Convert object name string or object reference
// into a valid object reference ready for style change
function GetObjectStyle(Object) {
	if (document.layers) {
		if (typeof Object == "string") {
			return document.layers[Object]
		} else {
			return Object
		}
	}
	if (document.getElementById) {
		if (typeof Object == "string") {
			if (document.getElementById(Object))
				return document.getElementById(Object).style
		} else {
			return Object.style
		}
	}
	if (document.all) {
		if (typeof Object == "string") {
			if (document.all(Object))
				return document.all(Object).style
		} else {
			return Object.style
		}
	}
	return null
}

// set the background colour of an object
function SetBackgroundColour(Object, Colour) {
	var ObjectReference = GetObjectStyle(Object)
	if (ObjectReference.bgColor) {
		ObjectReference.bgColor = Colour
	} else if (typeof ObjectReference.backgroundColor != "undefined") {
		ObjectReference.backgroundColor = Colour
	}
}

// set the foreground colour of an object
function SetForegroundColour(Object, Colour) {
	var ObjectReference = GetObjectStyle(Object)
	if (typeof ObjectReference.color != "undefined")
		ObjectReference.color = Colour
}

// set the visibility of an object to visible
function Show(Object) {
	var ObjectReference = GetObjectStyle(Object)
	ObjectReference.visibility = "visible"
}

// set the visibility of an object to hidden
function Hide(Object) {
	var ObjectReference = GetObjectStyle(Object)
	ObjectReference.visibility = "hidden"
}

// Add new element and content to the element with the specified id
function ReplaceContent(ContainerID, Content) {
	var ContainerElement = GetObject(ContainerID)
	ContainerElement.innerHTML = Content
}

// Add new element and content to the element with the specified id
function ReplaceValueFromWindow(Win, ContainerID, Content) {
	var ContainerElement = GetObjectFromWindow(Win, ContainerID)
	ContainerElement.value = Content;
}

// Add new element and content to the element with the specified id
function ReplaceContentFromWindow(Win, ContainerID, Content) {
	var ContainerElement = GetObjectFromWindow(Win, ContainerID)
	ContainerElement.innerHTML = Content;
}

// Get the x coordinate of the mouse pointer
function GetMouseX(evt) {
	if (evt.pageX) {
		return evt.pageX	
	} else {
		return window.event.clientX + document.body.scrollLeft
	}
}

// Get the y coordinate of the mouse pointer
function GetMouseY(evt) {
	if (evt.pageY) {
		return evt.pageY	
	} else {
		return window.event.clientY + document.body.scrollTop
	}
}
