function $(obj_id) {
	return (document.getElementById(obj_id))? document.getElementById(obj_id): null;
}

function Utils() {}

Utils.trim = function(string) {
	string = string.toString();
	// this will get rid of leading spaces 
	while (string.substring(0, 1) == ' ') 
			string = string.substring(1, string.length);
	// this will get rid of trailing spaces 
	while (string.substring(string.length - 1 ,string.length) == ' ')
			string = string.substring(0, string.length - 1);
 return string;
}

Utils.isEmptyString = function(string) {
	return (Utils.trim(string) == "")
}

Utils.reloadCurrentPageBare = function() { //reload current page without query string or post
	window.location = Site.rwpap; //rpap = root web path and page
}

Utils.getUrlDomain = function() {
	var url_domain = document.domain;
	
	return url_domain;
}

Utils.getObjById = function(obj_id) {
	return (document.getElementById(obj_id))? document.getElementById(obj_id): null;
}

Utils.setFocus = function(obj_id) {
	if (document.getElementById(obj_id)) document.getElementById(obj_id).focus();
}

Utils.getValue = function(obj_id) {
	return (document.getElementById(obj_id))? document.getElementById(obj_id).value: "";
}

Utils.setValue = function(obj_id, value) {
	if (document.getElementById(obj_id)) document.getElementById(obj_id).value = value;
}

Utils.getSrc = function(obj_id) {
	return (document.getElementById(obj_id))? document.getElementById(obj_id).src: "";
}

Utils.setSrc = function(obj_id, value) {
	if (document.getElementById(obj_id)) document.getElementById(obj_id).src = value;
}

Utils.getHref = function(obj_id) {
	return (document.getElementById(obj_id))? document.getElementById(obj_id).href: "";
}

Utils.setHref = function(obj_id, value) {
	if (document.getElementById(obj_id)) document.getElementById(obj_id).href = value;
}

Utils.getTitle = function(obj_id) {
	return (document.getElementById(obj_id))? document.getElementById(obj_id).title: "";
}

Utils.setTitle = function(obj_id, value) {
	if (document.getElementById(obj_id)) document.getElementById(obj_id).title = value;
}

Utils.getInnerHtml = function(obj_id) {
	return (document.getElementById(obj_id))? document.getElementById(obj_id).innerHTML: "";
}

Utils.setInnerHtml = function(obj_id, value) {
	if (document.getElementById(obj_id)) document.getElementById(obj_id).innerHTML = value; //formatForWeb(value);
}

Utils.appendInnerHtml = function(obj_id, value) {
	if (document.getElementById(obj_id)) document.getElementById(obj_id).innerHTML += value; //formatForWeb(value);
}

/*
Utils.getInnerHTML = function(obj_id) {
	return (document.getElementById(obj_id))? document.getElementById(obj_id).innerHTML: "";
}

Utils.setInnerHTML = function(obj_id, value) {
	if (document.getElementById(obj_id)) document.getElementById(obj_id).innerHTML = value; //formatForWeb(value);
}
*/

Utils.getDisplay = function(obj_id) {
	return (document.getElementById(obj_id))? document.getElementById(obj_id).style.display: "";
}

Utils.setDisplay = function(obj_id, value) {
	if (document.getElementById(obj_id)) document.getElementById(obj_id).style.display = value;
}

Utils.getVisibility = function(obj_id) {
	return (document.getElementById(obj_id))? document.getElementById(obj_id).style.visibility: "";
}

Utils.setVisibility = function(obj_id, value) {
	if (document.getElementById(obj_id)) document.getElementById(obj_id).style.visibility = value;
}

Utils.getZIndex = function(obj_id) {
	return (document.getElementById(obj_id))? document.getElementById(obj_id).style.zIndex: "";
}

Utils.setZIndex = function(obj_id, value) {
	if (document.getElementById(obj_id)) document.getElementById(obj_id).style.zIndex = value;
}

Utils.getClassName = function(obj_id) {
	return (document.getElementById(obj_id))? document.getElementById(obj_id).className: "";
}

Utils.setClassName = function(obj_id, class_name) {
	if (document.getElementById(obj_id)) document.getElementById(obj_id).className = class_name;
}

Utils.setBackgroundImg = function(obj_id, value) {
	if (document.getElementById(obj_id)) document.getElementById(obj_id).style.backgroundImage = "url('"+value+"')";
}

Utils.getStyleOpacity = function(obj_id) {
	return (document.getElementById(obj_id))? document.getElementById(obj_id).style.opacity: 0;
}

Utils.setStyleOpacity = function(obj_id, value) {
	if (document.getElementById(obj_id)) document.getElementById(obj_id).style.opacity = value;
}

Utils.getMaxWidth = function(obj_id) {
	return (document.getElementById(obj_id))? parseInt(document.getElementById(obj_id).style.maxWidth.replace(/px/g, "")): 0;
}

Utils.setMaxWidth = function(obj_id, value) {
	if (document.getElementById(obj_id)) document.getElementById(obj_id).style.maxWidth = value+"px";
}

Utils.getStyleWidth = function(obj_id) {
	return (document.getElementById(obj_id))? parseInt(document.getElementById(obj_id).style.width.replace(/px/g, "")): 0;
}

Utils.setStyleWidth = function(obj_id, value) {
	if (document.getElementById(obj_id)) document.getElementById(obj_id).style.width = value+"px";
}

Utils.setStyleWidthToInherit = function(obj_id) {
	if (document.getElementById(obj_id)) document.getElementById(obj_id).style.width = "inherit";
}

Utils.getStyleHeight = function(obj_id) {
	return (document.getElementById(obj_id))? parseInt(document.getElementById(obj_id).style.height.replace(/px/g, "")): 0;
}

Utils.setStyleHeight = function(obj_id, value) {
	if (document.getElementById(obj_id)) document.getElementById(obj_id).style.height = value+"px";
}

Utils.setStyleHeightToInherit = function(obj_id) {
	if (document.getElementById(obj_id)) document.getElementById(obj_id).style.height = "inherit";
}

Utils.getStyleLeft = function(obj_id) {
	return (document.getElementById(obj_id))? parseInt(document.getElementById(obj_id).style.left.replace(/px/g, "")): 0;
}

Utils.setStyleLeft = function(obj_id, value) {
	if (document.getElementById(obj_id)) document.getElementById(obj_id).style.left = value+"px";
}

Utils.getStyleRight = function(obj_id) {
	return (document.getElementById(obj_id))? parseInt(document.getElementById(obj_id).style.right.replace(/px/g, "")): 0;
}

Utils.setStyleRight = function(obj_id, value) {
	if (document.getElementById(obj_id)) document.getElementById(obj_id).style.right = value+"px";
}

Utils.getStyleTop = function(obj_id) {
	return (document.getElementById(obj_id))? parseInt(document.getElementById(obj_id).style.top.replace(/px/g, "")): 0;
}

Utils.setStyleTop = function(obj_id, value) {
	if (document.getElementById(obj_id)) document.getElementById(obj_id).style.top = value+"px";
}

Utils.getStyleBottom = function(obj_id) {
	return (document.getElementById(obj_id))? parseInt(document.getElementById(obj_id).style.bottom.replace(/px/g, "")): 0;
}

Utils.setStyleBottom = function(obj_id, value) {
	if (document.getElementById(obj_id)) document.getElementById(obj_id).style.bottom = value+"px";
}

Utils.getStylePosition = function(obj_id) {
	return (document.getElementById(obj_id))? document.getElementById(obj_id).style.position: "";
}

Utils.setStylePosition = function(obj_id, value) {
	if (document.getElementById(obj_id)) document.getElementById(obj_id).style.position = value;
}

Utils.getPullDownMenuValue = function(obj_id) {
	if (document.getElementById(obj_id)) {
		var obj = document.getElementById(obj_id);
		return obj.options[obj.selectedIndex].value;
	} else {
		return "";
	}
}

Utils.getPullDownMenuLabel = function(obj_id) {
	if (document.getElementById(obj_id)) {
		var obj = document.getElementById(obj_id);
		return obj.options[obj.selectedIndex].text;
	} else {
		return "";
	}
}

Utils.getObjWidth = function(obj_id) {
	return (document.getElementById(obj_id))? parseInt(document.getElementById(obj_id).offsetWidth): 0; //obj.clientWidth
}

Utils.getObjHeight = function(obj_id) {
	return (document.getElementById(obj_id))? parseInt(document.getElementById(obj_id).offsetHeight): 0; //obj.clientHeight
}

Utils.setOpacity = function(obj_id, opacity) {
	if (document.getElementById(obj_id)) {
		var object = document.getElementById(obj_id);
		object.style.opacity = opacity;
		object.style.MozOpacity = opacity;
		object.style.KhtmlOpacity = opacity;
		object.style.filter = "alpha(opacity="+(opacity * 100)+")";
		//object.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity="+(opacity * 100)+")";
	}
} 

Utils.getObjectStylePos = function(obj_id) {
	if (document.getElementById(obj_id)) {
		the_left = Utils.getStyleLeft(obj_id);
		the_top = Utils.getStyleTop(obj_id);
		return {left: the_left, top: the_top};
	} else {
		return {left: 0, top: 0};
	}
}

Utils.getObjectDimensions = function(obj_id) {
	if (document.getElementById(obj_id)) {
		var the_width = Utils.getObjWidth(obj_id);
		var the_height = Utils.getObjHeight(obj_id);
		return {width: the_width, height: the_height};
	} else {
		return {width: 0, height: 0};
	}
	
}

Utils.getObjOffsetT = function(obj_id){ //offset top
	if (document.getElementById(obj_id)) {
		var obj = document.getElementById(obj_id);
		var totaloffset = obj.offsetTop;
		var parentEl = obj.offsetParent;
		while (parentEl != null){
			totaloffset = totaloffset + parentEl.offsetTop;
			parentEl = parentEl.offsetParent;
		}
		return totaloffset;
	} else {
		return 0;
	}
}

Utils.getObjOffsetL = function(obj_id){ //offset left
	if (document.getElementById(obj_id)) {
		var obj = document.getElementById(obj_id);
		var total_offset = obj.offsetLeft;
		var parentEl = obj.offsetParent;
		while (parentEl != null){
			total_offset = total_offset + parentEl.offsetLeft;
			parentEl = parentEl.offsetParent;
		}
		return total_offset;
	} else {
		return 0;
	}
}

Utils.getObjOffset = function(obj_id) {
	if (document.getElementById(obj_id)) {
		var obj = document.getElementById(obj_id);
		var total_offset = {left: obj.offsetLeft, top: obj.offsetTop};
		var parent = obj.offsetParent;
		while (parent != null){
			total_offset.left += parent.offsetLeft;
			total_offset.top += parent.offsetTop;
			parent = parent.offsetParent;
		}
		return total_offset;
	} else {
		return {left: 0, top: 0};
	}
}

Utils.getObjOffsetFromObj = function(obj_id_1, obj_id_2) {
	if (document.getElementById(obj_id_1) && document.getElementById(obj_id_2)) {
		var obj = document.getElementById(obj_id_1);
		var total_offset = {left: obj.offsetLeft, top: obj.offsetTop};
		var parent = obj.offsetParent;
		while (parent != null){
			total_offset.left += parent.offsetLeft;
			total_offset.top += parent.offsetTop;
			parent = parent.offsetParent;
			if (parent && parent.id == obj_id_2) parent = null;
		}
		return total_offset;
	} else {
		return {left: 0, top: 0};
	}
}

Utils.getObjOffsetFromParent = function(obj_id) {
	if (document.getElementById(obj_id)) {
		var obj = document.getElementById(obj_id);
		var total_offset = {left: obj.offsetLeft, top: obj.offsetTop};
		return total_offset;
	} else {
		return {left: 0, top: 0};
	}
}

Utils.getObjLTWH = function(obj_id) {
	var obj_pos = Utils.getObjOffset(obj_id);
	var obj_dims = Utils.getObjectDimensions(obj_id);
	return {left: obj_pos.left, top: obj_pos.top, width: obj_dims.width, height: obj_dims.height};
}

Utils.getRandomInt = function(min, max) {
	return Math.floor(Math.random() * (max - min + 1)) + min;
}

Utils.functionExists = function(function_name) {
	return (typeof function_name == "function");
}

Utils.getPageDims = function() {
	var page_width = 0;
	var page_height = 0;
	
	if (self.innerHeight) // all except Explorer
	{
		page_width = self.innerWidth;
		page_height = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
	{
		page_width = document.documentElement.clientWidth;
		page_height = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		page_width = document.body.clientWidth;
		page_height = document.body.clientHeight;
	}
	
	return {width: page_width, height: page_heigh};
}

Utils.getWindowSize = function() {
	var the_width;
	var the_height;
	
	if (window.innerWidth) {
		the_width = window.innerWidth; //compensate for vertical scrollbar in FF
	} else if (document.documentElement && document.documentElement.clientWidth) {
		the_width = document.documentElement.clientWidth;
	} else if (document.body) {
		the_width = document.body.clientWidth;
	}
	if (window.innerHeight) {
		the_height = window.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		the_height = document.documentElement.clientHeight;
	} else if (document.body) {
		the_height = document.body.clientHeight;
	}
	
	return {width: the_width, height: the_height};
}

Utils.getWindowScroll = function(){
	var scroll_x = 0;
	var scroll_y = 0;
	
	if (typeof(window.pageYOffset) == "number") {
		//Netscape compliant
		scroll_x = window.pageXOffset;
		scroll_y = window.pageYOffset;
	} else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
		//DOM compliant
		scroll_x = document.body.scrollLeft;
		scroll_y = document.body.scrollTop;
	} else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
		//IE6 standards compliant mode
		scroll_x = document.documentElement.scrollLeft;
		scroll_y = document.documentElement.scrollTop;
	}

	return {x: scroll_x, y: scroll_y};
}

Utils.formatForID = function(text) {
	text = text.toLowerCase();
	text = text.replace(/\s/g, "_");
	text = text.replace(/\'/g, "");
	text = text.replace(/\"/g, "");
	return text;
}

Utils.fixIePngAlpha = function() {
	for (var i in document.images) {
		if (document.images[i].src) {
			var img_src = document.images[i].src;
			if (img_src.substr(img_src.length - 4).toLowerCase() === ".png") {
				var img_classname = document.images[i].className;
				if (img_classname.substr(0, 8) === "iePngFix") {
					document.images[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true', sizingMethod='crop', src='"+img_src+"')";
				}
			}
		}
	}
}

Utils.formatNumber = function(number) {
	number += '';
	x = number.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

Utils.sortArrayNumericAsc = function(a, b) {
	return (a - b); //causes an array to be sorted numerically and ascending
}

Utils.sortArrayNumericDesc = function(a, b) {
	return (b - a); //causes an array to be sorted numerically and descending
}

Utils.iStringComp = function(string_1, string_2) { //case insensitive string comparison
	return (string_1.toLowerCase() == string_2.toLowerCase());
}

Utils.ucFirtLetter = function(string) {
    return string.charAt(0).toUpperCase() + string.slice(1);
}

Utils.isEven = function(number) {
	return (number % 2 == 0);
}

Utils.isOdd = function(number) {
	return (number % 2 != 0);
}


/*
Utils.setFrameworkSizePos = function() {
	var win_dims = Utils.getWindowSize();
	
	if (Site.mode == "web") { //web
		var header_panel_height = Utils.getObjHeight("header_panel");
		var footer_panel_height = Utils.getObjHeight("footer_panel");
		var content_panel_height = win_dims.height - header_panel_height - footer_panel_height;
	} else { //kiosk
		var content_panel_height = win_dims.height;
	}	
	Utils.setStyleHeight("content_panel", content_panel_height);
}
*/

