// Make an object visible
function setShow(obj)
{
	if (NN4)
		obj.visibility = "show"
	else
		obj.style.visibility = "visible"
}
// Make an object invisible
function setHide(obj)
{
	if (NN4)
		obj.visibility = "hide";
	else
		obj.style.visibility = "hidden";
}

// Gets the object representation of the element specified by id.
function getObj(id, win)
{
	var obj;
	if (!win)
		win = self;
	
	if (IE && MAC)
		obj = win.document.all[id];
	else
		obj = win.document.getElementById(id);

	return obj;
}

// Deprecated version: Gets the object representation of the element specified by id.
function getObj_deprecated(id, win)
{
	var obj;
	if (IE) {
		for (var i = 0; i < parent.main.document.all.length; i++) {

			if (parent.main.document.all[i].id == id) {
				
				obj = parent.main.document.all[i];
				break;
			}
		}
	}
	
	else {
		obj = parent.main.document.bodyDiv.document.layers[id];
	}
	return obj;
}


function getIndex (obj) {

	var itemIndex = null;
	var re = new RegExp("[0123456789]");
	
	//itemIndex = obj.id.substring("note".length, 100);
	itemIndex = re.exec(obj.id);
	return itemIndex;
}

function getIndexFromString (str) {

	var itemIndex = null;
	var re = new RegExp("[0123456789]");
	
	itemIndex = re.exec(str);
	return itemIndex;
}


function getLeft(obj)
{
	var left = 0
	if (NN4)
		left = obj.left
	else
		left = obj.offsetLeft

	return left
}

function getWindowWidth () {

	if (NN4)
		return window.innerWidth;
	else
		return document.body.clientWidth;
}

function getTop(obj)
{
	var top = 0
	if (NN4)
		top = obj.top;
	else
		top = obj.offsetTop
		// top = obj.style.top;
		
	return top
}


function getWidth(obj)
{
	var width = 0
	if (NN4)
		width = obj.clip.width;
	else if (NN)
		width = obj.offsetWidth;
	else
		width = obj.clientWidth;
	return width
}

function getHeight(obj)
{
	var height = 0
	if (NN4)
		height = obj.clip.height;
	else if (NN)
		height = obj.offsetHeight;
	else
		height = obj.clientHeight;
	return height
}

function setPos(obj, x, y)
{
//	if (obj.id != "srcHilite" && obj.id != "trgHilite" && (x < 0 || y < 0))
//		return
	if (obj.id != "srcHilite" && obj.id != "trgHilite")
	{
		x = (x < 0) ? 0 : x;
		y = (y < 0) ? 0 : y;
	}
	
	if (NN4)
	{
		obj.moveTo(x, y)
	}
	else
	{
		obj.style.left = x;
		obj.style.top = y;
	}
}

// Set zIndex property
function setZIndex(obj, zOrder) {
	if (NN4) {
		obj.zIndex = zOrder
	} else {
		obj.style.zIndex = zOrder
	}
}

// Position an object at a specific pixel coordinate
function shiftTo(obj, x, y) {
	if (NN4) {
		obj.moveTo(x,y);
	} else {
		obj.style.left = x;
		obj.style.top = y;
	}
}

// Gets the closest parent of src of the specified tag type.
function getParentTag(src, tag)
{
	while ("HTML" != src.tagName)
	{
		if (tag == src.tagName)
			return src;
		src = src.parentElement;
	}
	return null;
}

function placeScreenObject(obj, x, y) {
	
	if (NN) {
		shiftTo(obj, x + pageXOffset, y + pageYOffset);
	}

	else if (IE) {
		shiftTo(obj, x + document.body.scrollLeft, y + document.body.scrollTop);
	}
}


// called on keypress events
function keyPress()
{
	if (IE)
	{
		switch (window.event.keyCode)
		{
			// backspace key
			case 8:
				// If the cursor is not in a textarea or textbox, intercept the keypress event and throw it away.
				// This stops IE from navigating to the previous page when the backspace key is pressed.
				// The backspace key event is not passed through on Windows/IE so this code doesn't work with that platform/browser.
				if (!theCursorLoc.isInTextarea() && !theCursorLoc.isInTextbox())
					return false;
				break;

			// return/enter key
			case 13:
				// If the cursor is not in a textarea, intercept the keypress event and throw it away.
				// This stops IE from submitting the page when the return/enter key is pressed.
				if (!theCursorLoc.isInTextarea())
					return false;
				break;
		}
	}
}

// This function removes whitespace from a string.
function removeWhitespace(theText)
{
	theText = theText.split(" ").join("");
	
	// Both Mac and Win string contain a \r for a line break, but Win additionally contains \n.
	theText = theText.split("\r").join("");
	theText = theText.split("\n").join("");
	
	return theText;
}

// This function escapes double quotes within a string.
function escapeQuotes(theText)
{
	theText = theText.split('"').join("\\\"");
	
	return theText;
}

// This function replaces escaped quotes within a string with the quote alias.
// In text boxes,  an escaped quote won't work because of surrounding quotes.
function replaceQuotes(theText)
{
	var newText = theText.split('"').join("&quot;");
	return newText;
}

// Class to track the cursor location.
// It keeps track of whether the cursor is in a text area, a text box, or neither.
function CursorLoc()
{
	this.inTextarea = false;
	this.inTextbox = false;
}

// called when cursor enters a text area
CursorLoc.prototype.enterTextarea = function()
{
	this.inTextarea = true;
}

// called when cursor exits a text area
CursorLoc.prototype.exitTextarea = function()
{
	this.inTextarea = false;
}

// called when cursor enters a text box
CursorLoc.prototype.enterTextbox = function()
{
	this.inTextbox = true;
}

// called when cursor exits a text box
CursorLoc.prototype.exitTextbox = function()
{
	this.inTextbox = false;
}

// returns true if cursor is in a text area
CursorLoc.prototype.isInTextarea = function()
{
	return this.inTextarea;
}

// returns true if cursor is in a textbox
CursorLoc.prototype.isInTextbox = function()
{
	return this.inTextbox;
}

var theCursorLoc = new CursorLoc();

