/* $Id: menutool.js,v 1.6 2005/06/01 01:49:16 brad Exp $ */
/** begin menutool functions **/

function Rollover( base_name )
{
	this.name = base_name;
	this.image_dir = "/images";
	this.img = null;

	this.Load = doRollLoad;
	this.Over = doRollNull;
	this.Out = doRollNull;

}

function doRollNull() { ; }

function doRollLoad()
{
	this.img = new Array();
	this.img[0] = new Image();
	this.img[0].src = this.image_dir + "/" + this.name + ".gif";
	this.img[1] = new Image();
	this.img[1].src = this.image_dir + "/" + this.name + "_o.gif";
	this.Over = doRollOver;
	this.Out = doRollOut;
}

function doRollOver()
{
	if( document.images )
	{
		image = document.images[ this.name ];
		image.src = this.img[1].src;
	}
}

function doRollOut()
{
	if( document.images )
	{
		image = document.images[ this.name ];
		image.src = this.img[0].src;
	}
}

function doRollDown()
{
	if( document.images && (this.src3 != '') )
	{
		image = document.images[ this.name ];
		image.src = this.img[2].src;
	}
}

MenuRollovers = Array();
function MenuRollover( base_name, src1, src2, src3 )
{
	this.name = base_name;
	this.img = null;
	this.src1 = src1;
	this.src2 = src2;
	this.src3 = src3;

	if( this.src3 + "" == "undefined" )
	{
		this.src3 = "";
	}

	this.Load = doMenuRollLoad;
	this.Over = doRollNull;
	this.Out = doRollNull;
	this.Down = doRollNull;

	MenuRollovers[ MenuRollovers.length ] = this;
	this.loaded = false;

}

function doMenuRollLoad()
{
	this.img = new Array();
	this.img[0] = new Image();
	this.img[0].src = this.src1;
	this.img[1] = new Image();
	this.img[1].src = this.src2;
	if( this.src3 != "" )
	{
		this.img[2] = new Image();
		this.img[2].src = this.src3;
	}
	this.Over = doRollOver;
	this.Out = doRollOut;
	if( navigator.userAgent.indexOf('Mac') == -1 )
	{
		this.Down = doRollDown;
	}
}

function MenuRollover_OnLoad()
{
	for( i=0; i<MenuRollovers.length; i++ )
	{
		MenuRollovers[i].Load();
	}
	for( i=0; i<FormRollovers.length; i++ )
	{
		FormRollovers[i].Load();
	}
}

FormRollovers = Array();
function FormButton( src1, src2, src3 )
{
	this.img = null;
	this.src1 = src1;
	this.src2 = src2;
	this.src3 = src3;

	this.Load = doMenuRollLoad;
	this.Over = doRollNull;
	this.Out = doRollNull;
	this.Down = doRollNull;

	FormRollovers[ FormRollovers.length ] = this;
}

/* addEvent( element [object], type [string], function_to_call [function], capture_event [bool] ) */
function addEvent(elem, evType, func, useCapture) {
	if(typeof elem.addEventListener != 'undefined') {
		elem.addEventListener(evType, func, useCapture);
		return true;
	} else if( typeof elem.attachEvent != 'undefined' ) { 
		var r = elem.attachEvent("on" + evType, func);
		return r; 
	} else { 
		var onEvt = "on" + evType;
		var elOldEvFuncs = elem[onEvt];
		if( typeof elem[onEvt] != 'function' ) {
			elem[onEvt] = func; 
		} else {
			elem[onEvt] = function() { elOldEvFuncs(); func(); }
		}
	}
}

function addLoadEvent(x) {
	var y = window;
	if(typeof document.addEventListener != 'undefined' && window.addEventListener == 'undefined') {
		y = document;
	}
	addEvent(y,"load",x,false);
}

function addUnLoadEvent(x) {
	var y = window;
	if(typeof document.addEventListener != 'undefined' && window.addEventListener == 'undefined') {
		y = document;
	}
	addEvent(y,"unload",x,false);
}

addLoadEvent(MenuRollover_OnLoad);

/** end menutool functions **/
/** $Id: htmltools.js,v 1.17 2006/10/04 00:38:53 tt Exp $ **/
/** htmltools javascript functions **/

/* stop pressing 'Return' submits forms */
var htmltools_form_focus = -1;
var htmltools_buttons = new Array();
var htmltools_forms = new Array();
function htmltools_onkeypress(e)
{
	var code = (window.Event) ? e.which : event.keyCode;
	j = htmltools_form_focus;
	if(code == "13" && j!=-1 )
	{
		l = htmltools_forms[j].length;
		if( l == 0 )
		{
			return true;
		}
		if( l == 1 )
		{
//			return true; /* enable this to get 'normal' behaviour for forms with 1 button */
		}
		if( typeof g_htmltools_active_combobox == 'object' )
		{
			htmltools_combobox_toggle( g_htmltools_active_combobox );
			return false;
		}
		el = document.getElementById( htmltools_forms[j][l-1] );
		if( el != null && el.nodeName=='INPUT') el.focus();
		return false;
	}
	return true;
}

function htmltools_init_forms()
{
	var frms = document.getElementsByTagName("FORM");

	for( var j=0; j<frms.length; j++ )
	{
		htmltools_forms[j] = new Array();
		for( var i=0; i<htmltools_buttons.length; i++ )
		{
			el = document.getElementById( htmltools_buttons[i] );
			if( el.form == frms[j] )
			{
				k = htmltools_forms[j].length;
				htmltools_forms[j][k] = htmltools_buttons[i];
			}
		}
	}
	
	for (var i=0; i<frms.length; i++)
	{
		for( var j=0; j<frms[i].elements.length; j++ )
		{
			switch( frms[i].elements[j].type )
			{
			case "hidden" :
			case "textarea" :
				break;
			default:
				eval( "addOnFocusEvent(frms[" + i + "].elements[" + j + "], function() { htmltools_form_focus=" + i + ";})" );
				frms[i].elements[j].onblur = function() {
					htmltools_form_focus = -1;
				}
			}
		}
	}
	document.onkeypress = htmltools_onkeypress;
		
		el = document.getElementById( "text_1" );
		if( el )
		{
			el.focus();
		}
	
}

function htmltools_register_button( id )
{
	htmltools_buttons[htmltools_buttons.length] = id;
}

function htmltools_checkbox_controller( id1, id2, label, show_class, hide_class )
{
	id1 = document.getElementById( id1 );
	id2 = document.getElementById( id2 );
	label = document.getElementById( label );

	id1.controls = id2;
	id1.labels = label;
	id1.show_class = show_class;
	id1.hide_class = hide_class;
	id1.onclick = function() {
		htmltools_checkbox_controller_onclick( this, this.controls, this.labels, id1.show_class, id1.hide_class );
	}
	id2.checked_last_val = id2.checked;
	id2.checked = (!id1.checked) && id2.checked || (id1.checked && id2.checked);
	id2.disabled = !id1.checked;
	label.className = id1.checked ? show_class:hide_class;
}
	
function htmltools_checkbox_controller_onclick( id1, id2, label, show_class, hide_class )
{
	id2.disabled=!id1.checked;
	if( id1.checked )
	{
		id2.checked=id2.checked_last_val;
	}
	else
	{
		id2.checked_last_val=id2.checked;
		id2.checked=false;
	}
	label.className = (id1.checked ? show_class:hide_class);
}

function addOnFocusEvent(el,func)
{
	var oldonfocus = el.onfocus;
	if( typeof el.onfocus != 'function') {
		el.onfocus = func;
	} else {
		el.onfocus = function() {
			oldonfocus();
			func();
		}
	}
}

addLoadEvent(htmltools_init_forms);

/** end htmltools javascript functions **/

g_te_id = 0;
var g_te_hide_delay = 0; /* milliseconds to wait before hiding menu after mouseout */
var g_te_count = 0;

function template_engine_hover( MenuName )
{
	var m_els = document.getElementById(MenuName).getElementsByTagName("LI");
	var m_forms = document.getElementsByTagName("SELECT");

	for (var i=0; i<m_els.length; i++)
	{
		m_els[i].te_state = 0;
		m_els[i].onmouseover=function() {
			if( document.all && (g_te_count == 0) )
			{
				/* hide some form elements for IE */
				for (var j=0; j<m_forms.length; j++)
				{
					m_forms[j]+=(m_forms[j].length>0? " ": "") + "m_hideme"
				}
			}
			g_te_count++;
			if( this.te_state != 0 ) return;
			this.className+=(this.className.length>0? " ": "") + "m_hover";
			this.te_state = 1;
			prev_id = g_te_id;
			g_te_id = this.id;
			if( prev_id != 0 )
			{
				template_engine_close_menu( prev_id );
			}
		}
		m_els[i].onmouseout=function() {
			g_te_count--;
			setTimeout("template_engine_close_menu('" + this.id + "')",g_te_hide_delay);
		}
	}
}

function template_engine_close_menu( id )
{
	if( g_te_count==0 )
	{
		g_te_id = "";
		var m_forms = document.getElementsByTagName("SELECT");
		for (var j=0; j<m_forms.length; j++)
		{
			m_forms[j].className = m_forms[j].className.replace(new RegExp("( ?|^)m_hideme\\b"), "");
		}
	}
	/* if g_te_id is a child of id, do nothing */
	if( g_te_id.substr(0, id.length + 1) == id + "_" )
	{
		return;
	}

	/* close this menu item */
	el = document.getElementById(id);
	el.className = el.className.replace(new RegExp(" m_hover\\b"), "");
	el.te_state = 0;
	
	/* close the parent menu item */
	parent_id = template_engine_get_parent(id);
	if( "" != parent_id )
	{
		template_engine_close_menu( parent_id );
	}
	return;
}

function template_engine_get_parent( id )
{
	id = id.replace( new RegExp( "_\\d+\$" ), "" );
	if( id.search("_") == -1 ) return "";
	return id;
}

