/******
*	hasClass()
*
*	This is needed to work around a bug in IE related to element attributes
******/

function hasClass(obj) {
	var result = false;
	if (obj.getAttributeNode("class") != null) {
		result = obj.getAttributeNode("class").value;
	}
	return result;
}	



/******
*	stripe()
*
*	This walks through a table and alternates the colors of the rows.
*	Two optional arguments can be provided which provide the colors.
*	If no colors are provided then default are used.
*	If the table of "id" is not found the function exits.
*
*	The function also will not process any TR's or TD's that have a
*	either a class or a backgroundColor assigned.
******/

function stripe(id) {
	var even = false;
	var evenColor = arguments[1] ? arguments[1] : "#fff";
	var oddColor = arguments[2] ? arguments[2] : "#d3e2fc";

	var table = document.getElementById(id);
	if (! table) { return; }
	
	var tbodies = table.getElementsByTagName("tbody");
	for (var h = 0; h < tbodies.length; h++) {
		var trs = tbodies[h].getElementsByTagName("tr");
		for (var i = 0; i < trs.length; i++) {
		if (!hasClass(trs[i]) && !trs[i].style.backgroundColor) {
				var tds = trs[i].getElementsByTagName("td");
				for (var j = 0; j < tds.length; j++) {
					var mytd = tds[j];
					if (!hasClass(mytd) && !mytd.style.backgroundColor) {
						mytd.style.backgroundColor = even ? evenColor : oddColor;
					}
				}
			}
			even = !even;
		}
	}
}



/******
*	OpenNewWindow()
*
*	This opens a new window. Used for opening larger views of images, etc.
*
*	Typical features list:
*	location=no,scrollbars=no,resizable=no,width=600,height=400,top=50,left=50
*
******/

function OpenNewWindow(theURL, winName, features) {
	window.open(theURL, winName, features);
	return false;
}



/******
*	DoRedirect()
*
*	This redirects the browser to a new page based on the option
*	selected from a popup menu.
*
******/

function DoRedirect(formname)
{
	var redir_value;

	if (formname.length > 0) {
		redir_value = document.forms[formname].redir.options[document.forms[formname].redir.selectedIndex].value;
    	if (redir_value != "") {
    		window.location = redir_value;
		}
		else {
			alert("Invalid Menu Selection.");
		}
	}
	else {
		alert("Error processing selection!");
    }
	return false;
}



/******
*	OnChangeRedirect()
*
*	This redirects the browser to a new page based on the option
*	selected from a popup menu.
*
*	Pass in the form name containing the popup and the name of
*	the popup.
*
******/

function OnChangeRedirect(frm, elm)
{
	var redir_value;

	if (frm.length > 0) {
		redir_value = document.forms[frm].elements[elm].value;
    	if (redir_value != "") {
    		window.location = redir_value;
		}
		else {
			alert("Invalid Menu Selection.");
		}
	}
	else {
		alert("Error processing selection!");
    }
	return false;
}



/******
*	DoFormFocus()
*
*	This sets keyboard focus to element "i" in the form "f".
******/

function DoFormFocus(f, i)
{
	document.forms[f].elements[i].focus();
	document.forms[f].elements[i].select();
}



/******
*	hiliteCurrentLink()
*
*	This highlights the current link in the navigation menu.
*
******/

function hiliteCurrentLink()
{
	var l, a, b, p, i;
	l = document.links;
	for (i = 0; i < l.length; i++) {
		a = l[i].href;
		p = a.lastIndexOf("?");
		if (p > 0) a = a.substring(0, p);
		p = a.lastIndexOf("/") + 1;
		a = a.substring(0, p);
		b = top.location.href;
		p = b.lastIndexOf("?");
		if (p > 0) b = b.substring(0, p);
		p = b.lastIndexOf("/") + 1;
		b = b.substring(0, p);
		a = a.replace("file:///", "file:/");
		b = b.replace("file:///", "file:/");
		if (a.toLowerCase() == b.toLowerCase()) {
			l[i].className = "current";
			break;
		}
	}
}



/******
*	sfHoverFix()
*
*	This is used to make a CSS hover behavior work with IE.
******/

function sfHoverFix(id)
{
	var list = document.getElementById(id);
	if (!list) { return; }
	var sfEls = document.getElementById(id).getElementsByTagName("li");
	for (var i = 0; i < sfEls.length; i++) {
		sfEls[i].onmouseover = function() {
			sel = document.getElementsByTagName("object");
			for (var i = 0; i < sel.length; i++) {
				sel[i].style.visibility = 'hidden'; 
			}
			sel = document.getElementsByTagName("select");
			for (var i = 0; i < sel.length; i++) {
				sel[i].style.visibility = 'hidden'; 
			}
			if (window.attachEvent) this.className+=" sfhover";
		}
		sfEls[i].onmouseout = function() {
			sel = document.getElementsByTagName("object");
			for (var i = 0; i < sel.length; i++) {
				sel[i].style.visibility = 'visible'; 
			}
			sel = document.getElementsByTagName("select");
			for (var i = 0; i < sel.length; i++) {
				sel[i].style.visibility = 'visible'; 
			}
			if (window.attachEvent) this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}



/******
*	sfFocusFix()
*
*	This is used to make a CSS focus behavior work with IE.
******/

function sfFocusFix(tag)
{
	var sfEls, i;

	if (window.attachEvent) {
		sfEls = document.getElementsByTagName(tag);
		for (i = 0; i < sfEls.length; i++) {
			sfEls[i].onfocus = function() {
				this.className+=" sffocus";
			}
			sfEls[i].onblur = function() {
				this.className=this.className.replace(new RegExp(" sffocus\\b"), "");
			}
		}
	}
}



/******
*	SetAllCheckBoxes()
*
*	This is used to check/uncheck all checkboxes on a page.
******/

function SetAllCheckBoxes(FormName, FieldName, CheckValue)
{
	if(!document.forms[FormName])
		return;
	var objCheckBoxes = document.forms[FormName].elements[FieldName];
	if(!objCheckBoxes)
		return;
	var countCheckBoxes = objCheckBoxes.length;
	if(!countCheckBoxes)
		objCheckBoxes.checked = CheckValue;
	else
		// set the check value for all check boxes
		for(var i = 0; i < countCheckBoxes; i++)
			objCheckBoxes[i].checked = CheckValue;
}



function SetNewChecked(formName)
{
	dml=document.forms[formName];
	len = dml.elements.length;
	var i=0;
	for( i=0 ; i<len ; i++) {
		if (dml.elements[i].type == 'checkbox' && dml.elements[i].id != 'control') {
			if (dml.elements[i].checked) {
				dml.elements[i].checked = false;
			} else {
				dml.elements[i].checked = true;
			}
		}
	}
}



function MyEditFocus(field, dText)
{
	var oInput = document.getElementById(field);

	if (oInput.value == dText) {
		oInput.value = '';
	}
	oInput.style.color = '#000';
}



function MyEditBlur(field, dText)
{
	var oInput = document.getElementById(field);

	if (oInput.value == '') {
		oInput.value = dText;
		oInput.style.color = '#999';
	}
	else {
		oInput.style.color = '#000';
	}
}
