/************************************************
 * Script: Event Library                        *
 * Version: 1.0                                 *
 * Required Libraries: Array                    *
 ***********************************************/

var Event = new Object();

Event.cache = new Array();

Event.add = function(elem, type, func, capture)
{
	// set up an event handler of the correct type (per browser)
	var handler = null;
	if (elem.addEventListener != null)
		elem.addEventListener(type, func, capture);
	else if (elem.attachEvent != null)
		elem.attachEvent("on" + type, func);
	else if (typeof(elem["on" + type]) == "function")
	{
		// if a handler is already present for the event
		handler = elem["on" + type];
		elem["on" + type] = function(evt)
		{
			handler(evt);
			func(evt);
		};
	}
	else
		elem["on" + type] = func;
		
	// handle the cache of application events accordingly
	Event.cache.push([elem, type, func, capture, handler]);
	if (Event.cache.length == 1) Event.add(window, "unload", Event.flush, true);
};

Event.remove = function(elem, type, func, capture)
{
	// get the previous event handler (if there is one)
	var handler = null;
	for (var i=0; i<Event.cache.length; i++)
	{
		if (Event.cache[i][0] == elem && Event.cache[i][1] == type && Event.cache[i][2] == func && Event.cache[i][3] == capture)
		{
			handler = Event.cache[i][4];
			Event.cache.splice(i, 1);
			break;
		}
	}
				
	// remove the given event handler
	if (elem.removeEventListener)
		elem.removeEventListener(type, func, capture);
	else if (elem.detachEvent)
		elem.detachEvent("on" + type, func);
	else
	{
		// make sure to put the old handler back in for old browsers
		if (handler != null)
		{
			elem["on" + type] = function(evt)
			{
				handler(evt);
			};
		}
		else
			elem["on" + type] = null;
	}
};

Event.stop = function(evt)
{
	// prevent an event from bubbling up or causing a default action
	if (document.addEventListener != null)
	{
		evt.stopPropagation();
		evt.preventDefault();
	}
	else if (document.attachEvent != null)
	{
		evt.cancelBubble = true;
		evt.returnValue = false;
	}
};

Event.flush = function()
{
	// uninitialize all the event handlers set for the application
	var info = null;
	while (Event.cache.length > 0)
	{
		info = Event.cache.pop();
		Event.remove(info[0], info[1], info[2], info[3]);
	}
};

function cancelRightClick(e)
{
  var message = "Copyright © 2006 Leggett & Platt, Incorporated. All Rights Reserved.";
  if (document.all != null && window.opera == null)
  {
    if (event.button == 2)
    {
      alert(message);
      return false;
    }
  }
  else
  {
    if (e.which == 3)
    {
      alert(message);
      return false;
    }
  }
} 

function popWindow(getpage,getname,w,h,features) {
  if(screen.width){
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  }else{winl = 0;wint =0;}
  if (winl < 0) winl = 0;
  if (wint < 0) wint = 0;
  var settings = 'height=' + h + ',';
  settings += 'width=' + w + ',';
  settings += 'top=' + wint + ',';
  settings += 'left=' + winl + ',';
  settings += features;
  win = window.open(getpage,getname,settings);
  win.window.focus();
}
