/*
 * $Header: /usr/local/cvsroot/understrom/_inc/common.js,v 1.2 2008/10/01 11:27:27 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 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);
}

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();
}


//
// AJAX Stuff
//
function createHttpRequestHandle()
{
	httpRequest = false;
	
	if (window.ActiveXObject)
	{
		httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
		
		if (!httpRequest)
		{
			httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
		}
	} else if (window.XMLHttpRequest)
	{
		httpRequest = new XMLHttpRequest();
	}
	
	return httpRequest;
}
	
function makeRequest(url, responseHandle)
{
	httpRequest = createHttpRequestHandle();
	
	var safari=navigator.userAgent.indexOf("Safari")>=0;
	
	if (!httpRequest || safari && !responseHandle)
	{
		(new Image()).src=url;
	} else
	{
		httpRequest.open('GET', url, true);
		if (responseHandle)
		{
			httpRequest.onreadystatechange = function()
			{
				if(httpRequest.readyState == 4)
				{
					responseHandle(httpRequest.responseXML);
				}
			}
		}
		
		httpRequest.send(null);
	}
}

function closeDiv(divId)
{
	document.getElementById(divId).style.display = "none";
}

/*
 * DEBUG FUNCTIONS
 * ---------------
 *
 */
function dump(theObj, replaceTag)
{
	var output = "<table>";
	var props = new Array();
	for (var i in theObj)
	{
		props.push(i);
	}

	props.sort();

	for (var i=0; i<props.length; i++)
	{
		output += "<tr><td>"+props[i]+"<\/td><td>"+theObj[props[i]]+"<\/td><\/tr>";
	}

	output += "<\/table>"

	document.getElementById(replaceTag).innerHTML = output;
}
