var contentRegionUpperHeight = -1;
var previousHeight = 0;

function getWindowHeight() {
	if (typeof(window.innerHeight) == 'number') {
		getWindowHeight = function() { return window.innerHeight; };
	} else {
		if (document.documentElement && document.documentElement.clientHeight) {
			getWindowHeight = function() { return document.documentElement.clientHeight; };
		} else if (document.body && document.body.clientHeight) {
			getWindowHeight = function() { return document.body.clientHeight; };
		} else {
			getWindowHeight = function() { return null; };
		}
	}
	return getWindowHeight();
}

function setHeight() {
	var contentRegionUpper = document.getElementById('ContentRegionUpper');
	var contentRegionLower = document.getElementById('ContentRegionLower');

	if (contentRegionUpperHeight == -1) contentRegionUpperHeight = contentRegionUpper.clientHeight;

	var contentRegionLowerHeight = contentRegionLower.clientHeight;
	var currentWindowHeight = getWindowHeight();
	var newHeight = currentWindowHeight - contentRegionLowerHeight;

	if (newHeight < contentRegionUpperHeight) newHeight = contentRegionUpperHeight;
	
	if (newHeight != previousHeight) contentRegionUpper.style.height = newHeight + 'px';
	previousHeight = newHeight;
}

function getObjectById(id) { // getElementById
	if (document.getElementById) getObjectById = function(id) { return (typeof(id) != 'string') ? id : document.getElementById(id); };
		else if (document.all) getObjectById = function(id) { return (typeof(id) != 'string') ? id : document.all[id]; };
		else if (document.layers) getObjectById = function(id) { return (typeof(id) != 'string') ? id : document.layers[id]; };
		else getObjectById = function(id) { throw new Error('Browser does not support \"getObjectById()\" function.') };
	return getObjectById(id);
}

function getElementsByClass(oElement, strTagName, oClassNames) {
	var arrElements = (strTagName == '*' && oElement.all) ? oElement.all : oElement.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	var arrRegExpClassNames = new Array();
	var bMatchesAll;

	if(typeof(oClassNames) == "object") {
		for(var i = 0; i < oClassNames.length; i++) { arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames[i].replace(/\-/g, "\\-") + "(\\s|$)")); }
	} else{
		arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames.replace(/\-/g, "\\-") + "(\\s|$)"));
	}

	for(var j = 0; j < arrElements.length; j++){
		oElement = arrElements[j];
		bMatchesAll = true;
		for(var k = 0; k < arrRegExpClassNames.length; k++ ){
			if(!arrRegExpClassNames[k].test(oElement.className)) {
				bMatchesAll = false;
				break;
			}
		}
		if(bMatchesAll) { arrReturnElements.push(oElement); }
	}

	return arrReturnElements;
}

function removeChildrenFromNode(oElement) {
	oElement = getObjectById(oElement);
	while (oElement.hasChildNodes()) oElement.removeChild(oElement.firstChild);
}

function getVisibility(oElement) { 
	oElement = getObjectById(oElement);
	return (oElement.style.display != 'none') ? true : false;
}

function setVisibility(oElement, visibility) { 
	oElement = getObjectById(oElement);
	if (oElement == null) return false;
	oElement.style.display = (visibility) ? 'block' : 'none';
}

function toggleVisibility(id) {
	setVisibility(id, !getVisibility(id));
	return false;
}

function getInnerText(oElement) {
	oElement = getObjectById(oElement);
	return (oElement.innerText) ? oElement.innerText : oElement.textContent;
}

function setInnerText(oElement, text) {
	oElement = getObjectById(oElement);
	return (oElement.innerText) ? oElement.innerText = text : oElement.textContent = text;
}

Date.prototype.getMonthName = function() {
	var m = ['January','February','March','April','May','June','July','August','September','October','November','December'];
	return m[this.getMonth()];
}