// define a few variables that are required
var pohmenu_usepopups = false;
var ignorequotechars = 0;

// #############################################################################
// lets define the browser we have instead of multiple calls throughout the file
var userAgent = navigator.userAgent.toLowerCase();
var is_opera  = (userAgent.indexOf('opera') != -1);
var is_saf    = ((userAgent.indexOf('applewebkit') != -1) || (navigator.vendor == "Apple Computer, Inc."));
var is_webtv  = (userAgent.indexOf('webtv') != -1);
var is_ie     = ((userAgent.indexOf('msie') != -1) && (!is_opera) && (!is_saf) && (!is_webtv));
var is_ie4    = ((is_ie) && (userAgent.indexOf("msie 4.") != -1));
var is_moz    = ((navigator.product == 'Gecko') && (!is_saf));
var is_kon    = (userAgent.indexOf('konqueror') != -1);
var is_ns     = ((userAgent.indexOf('compatible') == -1) && (userAgent.indexOf('mozilla') != -1) && (!is_opera) && (!is_webtv) && (!is_saf));
var is_ns4    = ((is_ns) && (parseInt(navigator.appVersion) == 4));

// catch possible bugs with WebTV and other older browsers
var is_regexp = (window.RegExp) ? true : false;

// #############################################################################
// let's find out what DOM functions we can use
var pohDOMtype = '';
if (document.getElementById)
{
	pohDOMtype = "std";
}
else if (document.all)
{
	pohDOMtype = "ie4";
}
else if (document.layers)
{
	pohDOMtype = "ns4";
}

// make an array to store cached locations of objects called by fetch_object
var pohobjects = new Array();

// #############################################################################
// function to emulate document.getElementById
function fetch_object(idname, forcefetch)
{
	if (forcefetch || typeof(pohobjects[idname]) == "undefined")
	{
		switch (pohDOMtype)
		{
			case "std":
			{
				pohobjects[idname] = document.getElementById(idname);
			}
			break;

			case "ie4":
			{
				pohobjects[idname] = document.all[idname];
			}
			break;

			case "ns4":
			{
				pohobjects[idname] = document.layers[idname];
			}
			break;
		}
	}
	return pohobjects[idname];
}

// #############################################################################
// function to handle the different event models of different browsers
// and prevent event bubbling
function do_an_e(eventobj)
{
	if (!eventobj || is_ie)
	{
		window.event.returnValue = false;
		window.event.cancelBubble = true;
		return window.event;
	}
	else
	{
		eventobj.stopPropagation();
		eventobj.preventDefault();
		return eventobj;
	}
}

// #############################################################################
// function to open a generic window
function openWindow(url, width, height)
{
	var dimensions = "";
	if (width)
	{
		dimensions += ",width=" + width;
	}
	if (height)
	{
		dimensions += ",height=" + height;
	}
	window.open(url, "pohPopup", "statusbar=no,menubar=no,toolbar=no,scrollbars=yes,resizable=yes" + dimensions);
	return false;
}

// #############################################################################
// function to register a menu for later initialization
function pohmenu_register(controlid, nowrite, datefield)
{
	if (pohmenu_usepopups)
	{		
		pohmenu_doregister(controlid, nowrite, datefield);		
		
	}
}
// #############################################################################
// ############## Main poh Javascript Initialization #####################
// #############################################################################

function poh_init()
{
	if (is_webtv)
	{
		return true;
	}
	var imgs = null;
	switch (pohDOMtype)
	{
		case "std": imgs = document.getElementsByTagName("img"); break;
		case "ie4": imgs = document.all.tags("img");             break;
		default:    imgs = false;                                break;
	}
	if (imgs)
	{
		// set 'title' tags for image elements
		for (var i = 0; i < imgs.length; i++)
		{
			if (!imgs[i].title && imgs[i].alt != "")
			{
				imgs[i].title = imgs[i].alt;
			}
		}
	}

	// init registered menus
	if (pohmenu_usepopups && pohmenu_registered.length > 0)
	{
		for (i in pohmenu_registered)
		{
			pohmenu_init(pohmenu_registered[i]);
		}

		// close all menus on mouse click
		document.onclick = pohmenu_close;
	}
	
	return true;
}