//
// Common JavaScript Routines including browser detection.
//

//
// Browser Detection
//
isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;
NS4 = (document.layers) ? true : false;
IEmac = ((document.all)&&(isMac)) ? true : false;
IE4plus = (document.all) ? true : false;
IE4 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 4.")!=-1)) ? true : false;
IE5 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 5.")!=-1)) ? true : false;
ver4 = (NS4 || IE4plus) ? true : false;
NS6 = (!document.layers) && (navigator.userAgent.indexOf('Netscape')!=-1)?true:false;

//
// Body onload utility (supports multiple onload functions)
//
var gSafeOnload = new Array();
function SafeAddOnload(f)
{
	if (IEmac && IE4)  // IE 4.5 blows out on testing window.onload
	{
		window.onload = SafeOnload;
		gSafeOnload[gSafeOnload.length] = f;
	}
	else if  (window.onload)
	{
		if (window.onload != SafeOnload)
		{
			gSafeOnload[0] = window.onload;
			window.onload = SafeOnload;
		}		
		gSafeOnload[gSafeOnload.length] = f;
	}
	else
		window.onload = f;
}
function SafeOnload()
{
	for (var i=0;i<gSafeOnload.length;i++)
		gSafeOnload[i]();
}

//
// x-browser form var get
//
function GetFormObj(name)
{
	var returnObj = null;
	
	if (IE4plus && ! document.getElementsByName(name) )
	{
		returnObj =  eval("document[\""+name+"\"]");
		//alert("here1");
	}
	else if (NS4)
	{
		returnObj =  document.forms[name];
		//alert("here2");
	}
	else if (NS6 || document.getElementsByName(name) )
	{	
		returnObj =  document.getElementsByName(name)[0];
		//alert("here3");
	}
	//alert("GetFormObj("+name+") = ("+returnObj+")");
	return returnObj;
}

//
// DHTML x-browser get
//
function GetEl(el_str) {
	var el = null;
	if (document.getElementById) {
		// IE 5 and NN 6
		el = document.getElementById(el_str);
	} else if (document.layers) {
		// NN4
		el = document.layers[el_str];
	} else {
		// IE 4
		el = document.all[el_str];
	}
	//alert("el_str = ("+el_str+"), el = ("+el+")");
	return (el)
}

//
// list elements...
//
function dumpit(obj) {
	var dumpstr = 'abc:';
	for (var i=0; i < obj.length; i++) {
		if ( obj[i].type == "text" || obj[i].type != "object" ) {
			dumpstr += "\n["+i+"] : ("+obj[i].value+")";
		} else {
			dumpstr += "\n["+i+"] :: "+dumpit(obj[i]);
		}
	}

	return (dumpstr);
}
