function refreshPage() { window.location.href = window.location.href; }

function getElementHandle(sID, sName, sTag, iIndex, iX, iY) {
	
	if ((iX || iY) && document.elementFromPoint) {
		return document.elementFromPoint(iX, iY)
	}
	if (sID) {
		if (document.getElementById) {
			return document.getElementById(sID);
		} else {
			eval("var o = " + sID);
			if (typeof(o == "object")) return o;
		}
	}
	if (!iIndex) iIndex = 0;
	if (sName) {
		eval("var o = " + sName);
		if (typeof(o == "object")) return o;
		var aElems = getElementArray(sName);
		return aElems[iIndex];
	}
	if (sTag) {
		var aElems = getElementArray('', sTag);
		return aElems[iIndex];
	}
}

function getElementArray(sName, sTag, oParent) {
	if (sName && document.getElementsByName) return document.getElementsByName(sName);	// IE5
	if (sTag && oParent && oParent.getElementsByTagName) return oParent.getElementsByTagName(sTag);	// IE5
	if (sTag && document.getElementsByTagName) return document.getElementsByTagName(sTag);	// IE5
}

function getTextNode(oObject) {
	if (oObject.firstChild && oObject.firstChild.nodeName == "#text") return oObject.firstChild;
	else {
		if (!(oNode = newNode("text", ""))) return null;
		if (oObject.appendChild) oObject.appendChild(oNode);
		else return null;
		return oNode;
	}
}

function getTextContent(oObject, bIgnoreKids) {
	
	if (bIgnoreKids && (oNode = getTextNode(oObject)))
		return oNode.data;
	
	if (oObject.nodeName && oObject.nodeName == "#text")
		return oObject.data;
	
	if (oObject.innerText) return oObject.innerText;

}

// The first call (the "open" call) to this function completely overwrites existing content.
// To append or insert content retreive it before the first call to this function.
// Subsequent calls will append content if the "opened" by a prior call and not
// "closed" by a prior call.

function setTextContent(oObject, sContent, bCRLF, bOpen, bClose, bIgnoreKids) {
	
	if (bIgnoreKids && (oNode = getTextNode(oObject))) {
		if (bOpen) oNode.data = sContent;
		else oNode.data += sContent;
		return;
	}
	
	if (oObject.nodeName && oObject.nodeName == "#text") {
		if (bOpen) oObject.data = sContent;
		else oObject.data += sContent;
		return;
	}
	
	var innerTextReadOnly = false;
	if (oObject.tagName && (oObject.tagName == "HTML" || oObject.tagName == "TABLE" || oObject.tagName == "TBODY" || oObject.tagName == "TFOOT" || oObject.tagName == "THEAD" || oObject.tagName == "TR"))
		innerTextReadOnly = true;
	
	if (oObject.innerText && !innerTextReadOnly) {
		if (bOpen) oObject.innerText = sContent;
		else oObject.innerText += sContent;
	} else if (oObject.text) {
		if (bOpen) oObject.text = sContent;
		else oObject.text += sContent;
	} else if (oObject.writeln && oObject.write) {
		if (bOpen) oObject.open();
		if (bCRLF) oObject.writeln(sContent);
		else oObject.write(sContent);
		if (bClose) oObject.close();
	} else if (oObject.document) {
		if (bOpen) oObject.document.open();
		if (bCRLF) oObject.document.writeln(sContent);
		else oObject.document.write(sContent);
		if (bClose) oObject.document.close();
	}
}

// Note; the preferred method for manipulaing HTML is through nodes.
// Try these function only if that fails.

function getHTMLContent(oObject) {
	
	// TO-DO: return inner for all inline and outer for block
	
	if ((oObject.tagName == "IMG") && oObject.outerHTML) return oObject.outerHTML;
	if (oObject.innerHTML) return oObject.innerHTML;
	return "";
}

// The first call (the "open" call) to this function completely overwrites existing content.
// To append or insert content retreive it before the first call to this function.
// Subsequent calls will append content if the "opened" by a prior call and not
// "closed" by a prior call.

function setHTMLContent(oObject, sContent, bCRLF, bOpen, bClose) {
	
	// TO-DO: set inner for all inline and outer for block
	
	
	var innerHTMLReadOnly = false;
	if (oObject.tagName && (oObject.tagName == "HTML" || oObject.tagName == "TABLE" || oObject.tagName == "TBODY" || oObject.tagName == "TFOOT" || oObject.tagName == "THEAD" || oObject.tagName == "TR"))
		innerHTMLReadOnly = true;

	if (oObject.innerHTML && !innerHTMLReadOnly) {
		if (bOpen) var s = sContent;
		else var s = getHTMLContent(oObject) + sContent;
		oObject.innerHTML = s;
	} else if ((oObject.tagName == "IMG") && oObject.outerHTML) {
		if (bOpen) var s = sContent;
		else var s = getHTMLContent(oObject) + sContent;
		oObject.outerHTML = s;
	} else if (oObject.htmlText && oObject.pasteHTML) {
		if (bOpen) var s = sContent;
		else var s = oObject.htmlText + sContent;
		oObject.pasteHTML(s);
	} else if (oObject.writeln && oObject.write) {
		if (bOpen) oObject.open();
		if (bCRLF) oObject.writeln(sContent);
		else oObject.write(sContent);
		if (bClose) oObject.close();
	} else if (oObject.document) {
		if (bOpen) oObject.document.open();
		if (bCRLF) oObject.document.writeln(sContent);
		else oObject.document.write(sContent);
		if (bClose) oObject.document.close();
	}
}

function clearContent(o) {
	if (o.tagName && o.tagName == "TD") var s = "&nbsp;";
	else var s = "";
	setHTMLContent(o, s, false, true, true);
}
