// $Id: functions.js,v 1.4 2007-10-06 07:47:48 lina Exp $

function bool2YN (b) {

	return b ? "yes" : "no";

}

function openWindow (url, name, width, height, resizable, scrollbars) {

	var o = "";
	if (width) o += ",width=" + width;
	if (height) o += ",height=" + height;
	if (!width || !height) resizable = true;

	var w = window.open(url, name || "popup", "resizable=" + bool2YN(resizable) + ",scrollbars=" + bool2YN(scrollbars) + ",status=no" + o);
	w.focus();

	// just in case we want a reference to it later
	return w;

}

function correctPNG()
{
	for(var i=0; i<document.images.length; i++)
	{
		var img = document.images[i]
		var imgName = img.src.toUpperCase()
		if (imgName.substring(imgName.length-3, imgName.length) == "PNG" && img.width && img.height && img.className.indexOf("correctPNG") > -1)
		{
			var imgID = (img.id) ? "id='" + img.id + "' " : ""
			var imgClass = (img.className) ? "class='" + img.className + "' " : ""
			var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
			var imgStyle = "display:inline-block;" + img.style.cssText
			if (img.align == "left") imgStyle = "float:left;" + imgStyle
			if (img.align == "right") imgStyle = "float:right;" + imgStyle
			if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
			var strNewHTML = "<span " + imgID + imgClass + imgTitle
			+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
			+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
			+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
			img.outerHTML = strNewHTML
			i = i-1
		}
	}
	var inputs = document.getElementsByTagName("input")
	var re = new RegExp("(.*\/)[^\/]+$")
	for(i=0; i<inputs.length; i++)
	{
		img = inputs[i]
		imgName = img.type == "image" ? img.src.toUpperCase() : "dummy.jpg"
		if (imgName.substring(imgName.length-3, imgName.length) == "PNG" && img.width && img.height && img.className.indexOf("correctPNG") > -1)
		{
			imgStyle = img.style.cssText
			imgStyle = "width:" + img.width + "px; height:" + img.height + "px;"
			+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
			+ "(src=\'" + img.src + "\', sizingMethod='scale');" + imgStyle
			img.style.cssText = imgStyle
			var m = re.exec(img.src)
			img.src = m[1] + "spacer.gif"
		}
	}
}

if (window.attachEvent) {

	window.attachEvent("onload", correctPNG);

}
