

// Place focus on the first input capable field on the first form
// Original:  Tom Khoury (twaks@yahoo.com) -->
function placeFocus() {
	if (document.forms.length > 0) {
		var field = document.forms[0];
		for (i = 0; i < field.length; i++) {
			if ((field.elements[i].type == "text") 
			   || (field.elements[i].type == "textarea") 
			   || (field.elements[i].type.toString().charAt(0) == "s")) {
				document.forms[0].elements[i].focus();
				break;
		         }
		}
	}
}




// ===================================================================
// Author: Matt Kruse <mkruse@netexpress.net>
// WWW: http://www.mattkruse.com/
//
// NOTICE: You may use this code for any purpose, commercial or
// private, without any further permission from the author. You may
// remove this notice from your final code if you wish, however it is
// appreciated by the author if at least my web site address is kept.
//
// You may *NOT* re-distribute this code in any way except through its
// use. That means, you can include it in your product, or your web
// site, or any other form where the code is actually being used. You
// may not put the plain javascript up on your site for download or
// include it in your javascript libraries for download. Instead,
// please just point to my URL to ensure the most up-to-date versions
// of the files. Thanks.
// ===================================================================
// gprior:  changed name to be more specific.  was getElementIndex

//-------------------------------------------------------------------
// getFormElementIndex(input_object)
//   Pass an input object, returns index in form.elements[] for the object
//   Returns -1 if error
//-------------------------------------------------------------------
function getFormElementIndex(obj) {
	var theform = obj.form;
	for (var i=0; i<theform.elements.length; i++) {
		if (obj.name == theform.elements[i].name) {
			return i;
			}
		}
	return -1;
	}

// -------------------------------------------------------------------
// tabNext(input_object)
//   Pass an form input object. Will focus() the next field in the form
//   after the passed element.
//   a) Will not focus to hidden or disabled fields
//   b) If end of form is reached, it will loop to beginning
//   c) If it loops through and reaches the original field again without
//      finding a valid field to focus, it stops
// -------------------------------------------------------------------
function tabNext(obj) {
	if (navigator.platform.toUpperCase().indexOf("SUNOS") != -1) {
		obj.blur(); return; // Sun's onFocus() is messed up
		}
	var theform = obj.form;
	var i = getFormElementIndex(obj);
	var j=i+1;
	if (j >= theform.elements.length) { j=0; }
	if (i == -1) { return; }
	while (j != i) {
		if ((theform.elements[j].type!="hidden") && 
		    (theform.elements[j].name != theform.elements[i].name) && 
			(!theform.elements[j].disabled)) {
			theform.elements[j].focus();
			break;
			}
		j++;
		if (j >= theform.elements.length) { j=0; }
		}
	}

// -----------------------------------------------------------------------
// get information about the user's browser and set in form variables.
function getICSBrowserStats(sForm)
{
  sForm.sockyEna.value = navigator.cookieEnabled;
  sForm.soplatform.value = navigator.platform;
  sForm.sosysLng.value = navigator.systemLanguage;
  sForm.sousrAgt.value = navigator.userAgent;
  sForm.sojvaEna.value = navigator.javaEnabled();
  sForm.soscnHi.value  = screen.height;
  sForm.soscnWid.value = screen.width;
  sForm.soclrDep.value = screen.colorDepth;
  sForm.sochrSet.value = document.defaultCharset;
}


// -----------------------------------------------------------------------
// change or clear the browser status message.
function showMsg(msg) {window.status = msg; return true;}
function clrMsg(msg) {window.status = ''; return true;}


// -----------------------------------------------------------------------
// submit form and disable button.
function submitAndDisable(b) {
	b.form.submit();
	b.disabled = true;
}
function submitButton(b) {
	b.form.submit();
	b.disabled = true;
}
function validateAndSubmit(b) {
	if (validate(b.form))
	{
		b.form.submit();
		b.disabled = true;
	}
	return b.disabled
}

// http://www.chrispederick.com/work/javascript/source/browser/browser.js
// Adds a function to the onload event
function addLoadFunction(newFunction)
{
    // If window.onload is a function
	if(typeof window.onload == "function")
	{
    	var previousOnload = window.onload;

	    // New window.onload
		window.onload = function()
		{
			previousOnload();
			newFunction();
		}
	}
	else
	{
		window.onload = newFunction;
	}
}

// Utility function to add an event listener
function addEvent(o,e,f){
	if (o.addEventListener){ o.addEventListener(e,f,true); return true; }
	else if (o.attachEvent){ return o.attachEvent("on"+e,f); }
	else { return false; }
}

function cssClassSwap(obj, cls1, cls2)
{
	obj.className=!cssClassCheck(obj,cls1) ? obj.className.replace(cls2,cls1) : obj.className.replace(cls1,cls2);
}
function cssClassAdd(obj, cls1)
{
	if(!cssClassCheck(obj,cls1))
	{
		obj.className+=obj.className?' '+cls1:cls1;
	}
}
function cssClassRemove(obj, cls1)
{
	if (cssClassCheck(obj, cls1))
	{
		var rep=obj.className.match(' '+cls1)?' '+cls1:cls1;
		obj.className=obj.className.replace(rep,'');
	}
}
function cssClassCheck(obj, cls1)
{
	return new RegExp('\\b'+cls1+'\\b').test(obj.className)
}
function expandCollapseList(rowId)
{
	expandCollapse( document.getElementById(rowId))
}
function expandCollapse(row)
{
	cssClassSwap( row, 'expanded', 'collapsed')
}

function hiliteTables()
{
	var tables = document.getElementsByTagName('table');
	for (var i=0; i < tables.length; i++)
	{
		var table = tables[i]
		if (cssClassCheck(table, 'hilite'))
		{
			var rows = table.getElementsByTagName('TBODY')[0].getElementsByTagName('TR')
			var oe = 0
			for (var j=0; j < rows.length; j++)
			{
				if (rows[j].getElementsByTagName('th').length == 0)
				{
					oe = oe + 1
					cssClassAdd(rows[j], (oe%2==0 ? 'even' : 'odd'))
				}
			}
		}
	}
}
function expandomatic()
{
	var tables = document.getElementsByTagName('table');
	var anchor = document.createElement("a");
	var tnode = document.createTextNode('test');
	anchor.appendChild(tnode);
	for (var i=0; i < tables.length; i++)
	{
		var table = tables[i]
		if (cssClassCheck(table, 'expandomatic'))
		{
			var rows = tables[i].getElementsByTagName('tbody')[0].getElementsByTagName('tr')
			for (var j=0; j < rows.length; j++)
			{
				var row = rows[j]
				if ( !cssClassCheck(row,'DoNotExpand') )
				{
					cssClassRemove(row,'expanded')
					cssClassAdd(row, 'collapsed')
					row.onclick=function() {expandCollapse(this);}
					var td = row.getElementsByTagName('td')[0]
					if (td && (td.getElementsByTagName('a').length == 0))
					{
							td.innerHTML = '<span class="expando">&nbsp;</span>' + td.innerHTML;
					}
				}
			}
		}
	}
}
