//------------------------------------------------------------------------------
//--- Add additional onload events to a page
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}

//------------------------------------------------------------------------------
//--- Open Centered Window

function openPopup(URL, ident, width, height, scrolling){

	if(height > screen.availHeight){
		scrolling = "yes";
		width += 17;
	}

	var startX = ((screen.availWidth - width)/2);
	var startY = ((screen.availHeight - height)/2);
	var options = "height=" + height + ",width=" + width + ",left=" + startX + ",top=" + startY + ",screenX=" + startX + ",screenY=" + startY + ",directories=no,location=no,menubar=no,resizable=no,noresize,scrollbars="+scrolling+",status=no,titlebar=no,toolbar=no";
	var objWindow = window.open(URL, ident, options);
	objWindow.focus();
}

//------------------------------------------------------------------------------
//--- Get element by its class name

function get_by_class(parent,tagname,classname){
	var children;
	if(typeof(parent) == "object"){
		children = parent.getElementsByTagName(tagname);
	}else{
		children = document.getElementById(parent).getElementsByTagName(tagname);
	}
	var element;
	for(i=0;i<children.length;i++){
		var arr_list = (children[i].className).split(" ");
		for(j=0;j<arr_list.length;j++){
			if(arr_list[j] == classname) element = children[i];
		}
		//if(children[i].className == classname) element = children[i];
	}
	return element;
}

/* The IE Behavior to deal with pings has some serious issues, so instead we're going to handle pngs with this chunk.
 * Assuming that the global variable "DYNAMIC_PNGS is set to true, then this
 * code will fire, replacing all png background images inside of divs with the
 * class "dynamic-png".  This has the benefit of only doing the replacement once
 * (on pageload).
 *
 */

transformDynamicPngs = function(){
	if ($.browser.msie && $.browser.version == "6.0") {
		$(".dynamic-png").each(function() {
								   if ((this.style.backgroundImage != 'none')) {
									   var pngSrc = (this.style.backgroundImage.substring(4,this.style.backgroundImage.length - 1));
									   this.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+pngSrc+"')";
									   this.style.backgroundImage = 'none';
								   }
							   });
	}
};

if ((typeof DYNAMIC_PNGS != 'undefined') && DYNAMIC_PNGS) {
	$(document).ready(transformDynamicPngs);
}