/*
 * $Header: /usr/local/cvsroot/vorkdk/_inc/main.js,v 1.6 2006/05/10 14:26:40 krut Exp $
 *
 * Javascript Lib
 *
 */

// Detect Browser
var ns4 = (document.layers) ? true:false;
var ns6 = (document.getElementById) ? true:false;
var ie4 = (document.all) ? true:false;
var ie5 = false;
if(ie4)
{
	if ((navigator.userAgent.indexOf('MSIE 5') > 0) || (navigator.userAgent.indexOf('MSIE 6') > 0))
	{
		ie5 = true;
	}
	if(ns6)
	{
		ns6 = false;
	}
}

function popup(popupUrl, windowName, theWidth, theHeight)
{
	var wHandle;
	
	wHandle = window.open(popupUrl , windowName, "toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=1, resizable=1, width="+theWidth+", height="+theHeight+", left=100, top=50,screenX=100, screenY=50'");
	wHandle.focus();
}

function confirmSubmit(formHandle, msg)
{
	if (confirm(msg))
	{
		formHandle.submit ()
	}
}

function confirmButtonClick(msg, url)
{
	if (confirm(msg))
	{
		window.location = url;
	}
}

function loadInParentWindow(url, closeSelf)
{
	self.opener.location = url;
	self.opener.focus();
	if(closeSelf)
	{
		self.close();
	}
}

function crossFade(fromId,toId)
{
	document.getElementById(fromId).style.zindex = 1;
	document.getElementById(toId).style.zindex = 2;

	opacityFade(fromId,0,100);
	opacityFade(toId,100,100);
}

function opacityFade(id,opacityEnd,millisec)
{
	var speed = Math.round(millisec / 100);
	var timer = 0;
	var opacityStart = 100;
	
	if (document.getElementById(id).style.opacity < 100)
	{
		opacityStart = document.getElementById(id).style.opacity * 100;
	}

	if (opacityStart > opacityEnd)
	{
		for(i = opacityStart; i >= opacityEnd; i--)
		{
			setTimeout("setOpacity('" + id + "'," + i + ")",(timer * speed));
			timer++;
		}
		setTimeout("document.getElementById('" + id + "').style.display = 'none'",(timer * speed));
	} else if (opacityStart < opacityEnd)
	{
		document.getElementById(id).style.display = 'block';
		for(i = opacityStart; i <= opacityEnd; i++)
		{
			setTimeout("setOpacity('" + id + "'," + i + ")",(timer * speed));
			timer++;
		}
	}
}

function setOpacity(id, opacity)
{
	var object = document.getElementById(id).style;

    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}	

function fixPng () 
{
	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")
		{
			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
		}
	}
}

if (ie4 || ie5)
{
	window.attachEvent("onload", fixPng);
}

