

var det=navigator.userAgent.toUpperCase();

var IE4PC=(det.indexOf("WIN",0) != -1) && (det.indexOf("MSIE 4",0) != -1);
var IE5PC=(det.indexOf("WIN",0) != -1) && (det.indexOf("MSIE 5",0) != -1);
var IE6PC=(det.indexOf("WIN",0) != -1) && (det.indexOf("MSIE 6",0) != -1);
var Netscape4PC=(det.indexOf("WIN",0) != -1) && (det.indexOf("MOZILLA/4",0) != -1) && (navigator.appName == "Netscape");
var Netscape6PC=(det.indexOf("WIN",0) != -1) && (det.indexOf("NETSCAPE6",0) != -1) && (navigator.appName == "Netscape");
if (!Netscape6PC) {
	var MozillaPC=(det.indexOf("WIN",0) != -1) && (det.indexOf("GECKO",0) != -1);
} else {
	var MozillaPC=false;
}
var OperaPC=(det.indexOf("WIN",0) != -1) && (det.indexOf("OPERA",0) != -1);
var IE4MAC=(det.indexOf("MAC",0) != -1) && (det.indexOf("MSIE 4",0) != -1);
var IE5MAC=(det.indexOf("MAC",0) != -1) && (det.indexOf("MSIE 5",0) != -1);
var IE6MAC=(det.indexOf("MAC",0) != -1) && (det.indexOf("MSIE 6",0) != -1);
var Netscape4MAC=(det.indexOf("MAC",0) != -1) && (det.indexOf("MOZILLA/4",0) != -1) && (navigator.appName == "Netscape");
var Netscape6MAC=(det.indexOf("MAC",0) != -1) && (det.indexOf("NETSCAPE6",0) != -1) && (navigator.appName == "Netscape");
var OperaMAC=(det.indexOf("MAC",0) != -1) && (det.indexOf("OPERA",0) != -1);
var MozillaMAC=(det.indexOf("MAC",0) != -1) && (det.indexOf("GECKO",0) != -1);

var GroupBoxStatusAry=new Array();
var bgColorChoice=0;
var bgColorsAry=new Array("#6A9192","#669999","#99CCCC","#993333","#CC6666","#999966","#CCCC99","#666666","#6699CC","#CC9933");
var numOfGroupBox=0;
var closingOutGB=-1;
var useCollapseAry=new Array();


function RICOLAGroupbox_clickCheck(inStr) {
	var containsClickable = true;
	containsClickable = (inStr.search(/(\sHREF\=|\sonClick\=)/i) != -1) ? true : false;
	return containsClickable;
}

function StartGroupBox()
{
	var inTitle="&nbsp;";
	if (arguments[0]) { inTitle=arguments[0]; }
	var gbholdstr=new String("");
	var gbholdstrTD=new String("");
	var gbholdstr2=new String("");
	var inSmall = new String("");
	var inStyle=0;
	var inCollapse  = 0;
	var useCollapse = false;
	var cellpaduse  = false;
	var usetcenter  = false;
	var useIndexPageStyle = false;
	var useTarget = false;
	var useHeight = false;
	for (iargs=1; iargs<arguments.length; iargs++) {
		if (arguments[iargs].toString().indexOf(":") == -1) {
			alert("GroupBox Error #7212: Argument #" + (iargs + 1) + " (" + arguments[iargs] + ") is not a valid parameter.\n\nPlease check the documentation at http://home.www.uprr.com/emp/it/hf/ricola/groupbox/ for valid parameters and format.");
		} else if (arguments[iargs].toString().search(/^\s*small\s*title\s*:\s*(1|true)\s*$/i) != -1) {
			inSmall = "SM";
		} else if (arguments[iargs].toString().toLowerCase().indexOf("index:") != -1) {
			useIndexPageStyle=true;
		} else if (arguments[iargs].toString().toLowerCase().indexOf("height:") != -1) {
			useHeight = true;
			var heightValue=arguments[iargs].replace(/(\w+)\s*:\s*(\S+)/,"$2");
			if (!isNaN(heightValue)) { heightValue -= 15; }
			gbholdstr+=" " + arguments[iargs].replace(/(\w+)\s*:\s*(\S+)/,"$1") + "=\"" + heightValue + "\" ";
		} else if (arguments[iargs].toString().toLowerCase().indexOf("valign:") != -1) {
			gbholdstrTD+=" " + arguments[iargs].replace(/(\w+)\s*:\s*(\w+)/,"$1") + "=\"" +  arguments[iargs].replace(/(\w+)\s*:\s*(\w+)/,"$2") + "\" ";
			gbholdstr+=" " + arguments[iargs].replace(/(\w+)\s*:\s*(\w+)/,"$1") + "=\"" + arguments[iargs].replace(/(\w+)\s*:\s*(\w+)/,"$2") + "\" ";
		} else if (arguments[iargs].toString().toLowerCase().indexOf("style:") != -1) {
			 inStyle=arguments[iargs].replace(/(\w+)\s*:\s*(\w+)/,"$2");
			 bgColorChoice=inStyle;
		} else if (arguments[iargs].toString().toLowerCase().indexOf("target:") != -1) {
			useTarget=true;
		} else if (arguments[iargs].toString().toLowerCase().indexOf("collapsable:") != -1) {
			useCollapse=true;
			inCollapse=arguments[iargs].replace(/(\w+)\s*:\s*(\w+)/,"$2");
		} else if ((arguments[iargs].toString().toLowerCase().indexOf("title: center") != -1) || (arguments[iargs].toString().toLowerCase().indexOf("title:center") != -1)) {
			usetcenter=true;
		} else {
			gbholdstr+=" " + arguments[iargs].replace(/(\w+)\s*:\s*(\S+)/,"$1") + "=\"" + arguments[iargs].replace(/(\w+)\s*:\s*(\S+)/,"$2") + "\" ";
			if (arguments[iargs].toString().toLowerCase().indexOf("cellpadding:") != -1) {
				cellpaduse=true;
			}
		}
	}

	if (useHeight && useCollapse) {	// If it is a collapsable box, it can't have a set height.  Default to the height
		useCollapse = false;
	}
	if (useTarget && !useCollapse) {
			alert("GroupBox Error #7217: To use the \"Target:\" parameter, you must also use the \"Collapsable:\" parameter.\n\nPlease check the documentation at http://home.www.uprr.com/emp/it/hf/ricola/groupbox/ for valid parameters and format.");

	}
	if (!cellpaduse) { gbholdstr2=" cellpadding=\"4\" "; }

	if (inStyle != 0) {
		gbholdstr+=" bordercolor=\"" + bgColorsAry[inStyle] + "\" ";
		gbholdstr += (useIndexPageStyle)? " border=\"0\" " : " border=\"1\" ";
		document.writeln("<table " + gbholdstr + gbholdstr2 + " cellspacing=\"0\">");
	} else {
		document.writeln("<table class='RicolaV1_Groupbox' " + gbholdstr + gbholdstr2 + " cellspacing=\"0\">");
	}

	if (useIndexPageStyle) {
		document.writeln("<tr>");
		document.write("<td nowrap height=\"15\">");
		if (!Netscape4PC && useCollapse) {
			(inCollapse == 1) ? gbholdstr="none" : gbholdstr="";
			GroupBoxStatusAry[numOfGroupBox]=inCollapse;
			document.write("<div style='position: relative; display: " + gbholdstr + ";' id='GroupBox" + numOfGroupBox + "Header0'><a href='javascript: void groupShowHide(" + numOfGroupBox + ",1," + useTarget + ")' style='background-color: White; color: Black; text-decoration: none;' title='Click to Expand'>");

			document.write("<img src=\"/graphics/apps/twistie/twistie_closed_ind.gif\" width=\"9\" height=\"12\" border=\"0\" alt=\"Click to Expand\">");
			document.write(" <span class=\"IndHeader\">" + inTitle + "</span>");
			document.write("</a>");
			if (useTarget) {
				document.write("<a NAME=\"GBTarget" + numOfGroupBox + "\"></a>");
			}
			document.write("</div>");

			(inCollapse == 1) ? gbholdstr="inline" : gbholdstr="none";
			document.write("<div style='position: relative; display: " + gbholdstr + ";' id='GroupBox" + numOfGroupBox + "Header1'><a HREF='javascript: void groupShowHide(" + numOfGroupBox + ",0," + useTarget + ")' style='background-color: White; color: Black; text-decoration: none;' TITLE='Click to Collapse'>");

			document.write("<img src=\"/graphics/apps/twistie/twistie_open_ind.gif\" width=\"9\" height=\"12\" border=\"0\" alt=\"Click to Expand\">");
			document.write(" <span class=\"IndHeader\">" + inTitle + "</span>");
			document.write("</a>");
			if (useTarget) {
				document.write("<a NAME=\"GBTarget" + numOfGroupBox + "\"></a>");
			}
			document.write("</div>");
		} else {
			if (usetcenter) { document.write("<div align=\"center\">"); }
			GroupBoxStatusAry[numOfGroupBox]=-1;
			document.write("<span class=\"IndHeader\">" + inTitle + "</span>");
			if (usetcenter) { document.write("</div>"); }
		}
		document.writeln("</td></tr>");
	} else {  // Normal Groupbox
		if (!Netscape4PC && useCollapse) {  // If Collapsable
			var ContainsClickableItem = RICOLAGroupbox_clickCheck(inTitle);
			if (ContainsClickableItem) {
				document.writeln("<tr class=\"GroupBox" + inStyle + "Title\">");
				document.write("<td class=\"GroupBox" + inStyle + "Title" + inSmall + " RicolaGBHeader\" nowrap=\"nowrap\" height=\"15\">");
				(inCollapse == 1) ? gbholdstr="none" : gbholdstr="";
				GroupBoxStatusAry[numOfGroupBox]=inCollapse;
				document.write("<div style='position: relative; display: " + gbholdstr + ";' id='GroupBox" + numOfGroupBox + "Header0'><a HREF='javascript: void groupShowHide(" + numOfGroupBox + ",1," + useTarget + ")' style='background-color: White; color: Black; text-decoration: none;' TITLE='Click to Expand'>");

				document.write("<img src=\"/graphics/apps/ricola1yellow/groupbox-dark-plus.gif\" width=\"11\" height=\"11\" border=\"0\" alt=\"Click to Expand\">");
				if (useTarget) {
					document.write("</a>&nbsp; <a NAME=\"GBTarget" + numOfGroupBox + "\">" + inTitle + "</a>");
				} else {
					document.write("</a>&nbsp; ");
					document.write(inTitle);
				}
				document.write("</div>");

				(inCollapse == 1) ? gbholdstr="" : gbholdstr="none";
				document.write("<div style='position: relative; display: " + gbholdstr + ";' id='GroupBox" + numOfGroupBox + "Header1'><a HREF='javascript: void groupShowHide(" + numOfGroupBox + ",0," + useTarget + ")' style='background-color: White; color: Black; text-decoration: none;' TITLE='Click to Collapse'>");

				document.write("<img src=\"/graphics/apps/ricola1yellow/groupbox-dark-minus.gif\" width=\"11\" height=\"11\" border=\"0\" alt=\"Click to Collapse\">");
				if (useTarget) {
					document.write("</a>&nbsp; <a NAME=\"GBTarget" + numOfGroupBox + "\">" + inTitle + "</a>");
				} else {
					document.write("</a>&nbsp; ");
					document.write(inTitle);
				}
				document.write("</div>");
				document.writeln("</td></tr>");
			} else { // Create the entire row to be clickable
				(inCollapse == 1) ? gbholdstr="none" : gbholdstr="";
				GroupBoxStatusAry[numOfGroupBox]=inCollapse;
				document.writeln("<tr style='display: " + gbholdstr + ";' id='GroupBox" + numOfGroupBox + "Header0' onClick='groupShowHide(" + numOfGroupBox + ",1," + useTarget + ")' class=\"GroupBox" + inStyle + "Title\">");
				document.write("<td class=\"GroupBox" + inStyle + "Title" + inSmall + " RicolaGBHeader\" nowrap=\"nowrap\" height=\"15\" TITLE='Click to Expand'>");

				document.write("<img src=\"/graphics/apps/ricola1yellow/groupbox-dark-plus.gif\" width=\"11\" height=\"11\" border=\"0\" alt=\"Click to Expand\">");
				if (useTarget) {
					document.write("&nbsp; <a NAME=\"GBTarget" + numOfGroupBox + "\">" + inTitle + "</a>");
				} else {
					document.write("&nbsp; " + inTitle);
				}
				document.write("</td>");
				document.write("</tr>");

				(inCollapse == 1) ? gbholdstr="" : gbholdstr="none";
				document.writeln("<TR style='display: " + gbholdstr + ";' id='GroupBox" + numOfGroupBox + "Header1' onClick='groupShowHide(" + numOfGroupBox + ",0," + useTarget + ")' class=\"GroupBox" + inStyle + "Title\">");
				document.write("<td class=\"GroupBox" + inStyle + "Title" + inSmall + "  RicolaGBHeader\" nowrap=\"nowrap\" height=\"15\" TITLE='Click to Collapse'>");
				document.write("<img src=\"/graphics/apps/ricola1yellow/groupbox-dark-minus.gif\" width=\"11\" height=\"11\" border=\"0\" alt=\"Click to Collapse\">");
				if (useTarget) {
					document.write("&nbsp; <a NAME=\"GBTarget" + numOfGroupBox + "\">" + inTitle + "</a>");
				} else {
					document.write("&nbsp; " + inTitle);
				}
				document.writeln("</td></tr>");
			}
		} else {
			document.write("<tr class=\"GroupBox" + inStyle + "Title\">");
			document.write("<td class=\"GroupBox" + inStyle + "Title" + inSmall + "  RicolaGBHeader\" nowrap=\"nowrap\" height=\"15\">");
			if (usetcenter) { document.write("<div align=\"center\">"); }
			GroupBoxStatusAry[numOfGroupBox]=-1;
			document.write(inTitle);
			if (usetcenter) { document.write("</div>"); }
			document.writeln("</td></tr>");
		}
	}
	document.write("<tr>");
	document.write("<td class=\"GroupBox" + inStyle + "Body" + inSmall + "" + ((useIndexPageStyle) ? "" : " RicolaGBBody") + "\" " + gbholdstrTD + ">");
	if (!Netscape4PC && useCollapse) {
		if (inCollapse == 1) {
			if (Netscape6PC) {
				gbholdstr=" ";
			} else {
				gbholdstr=" style='display: inline;' ";
			}
		} else {
			gbholdstr=" style='display: none;' ";
		}

		document.write("<div id='GroupBox" + numOfGroupBox + "Body' " + gbholdstr + ">");
		useCollapseAry[useCollapseAry.length] == 1;
	} else {
		useCollapseAry[useCollapseAry.length] == 0;
	}
	numOfGroupBox++;
	closingOutGB++;
}

function EndGroupBox()
{
	if (closingOutGB == -1) { alert("Error: #7215  \n There are mismatching number of StartGroupBox() and EndGroupBox() function calls.  Please have equal amounts of each and redisplay this page."); }
	var isCollapsable=useCollapseAry[closingOutGB];
        closingOutGB--;
	if (!Netscape4PC && (isCollapsable == 1)) {
		document.write("</div>");
	}
	document.writeln("</td></tr></TABLE>");
}


function groupShowHide(inGB, inAction, inUseTarget) {
	var tmpstr=new String("");
	(inAction == 1) ? tmpstr="0" : tmpstr="1";
	var gbhfrom="GroupBox" + inGB + "Header" + tmpstr;
	var gbhto="GroupBox" + inGB + "Header" + inAction;
	var gbb="GroupBox" + inGB + "Body";
	var ie4 = (document.all) ? true : false;
	var ns4 = (document.layers) ? true : false;
	var ns6 = (document.getElementById && !document.all) ? true : false;

	GroupBoxStatusAry[inGB] = inAction;

	if (ie4) {
		document.all[gbhfrom].style.display = "none";
		document.all[gbhto].style.display = "inline";
		if (inAction == 1) {
			document.all[gbb].style.display = "inline";
		} else {
			document.all[gbb].style.display = "none";
		}
	}
	if (ns6) {
		document.getElementById([gbhfrom]).style.display = "none";
		document.getElementById([gbhto]).style.display = "";
		if (inAction == 1) {
			document.getElementById([gbb]).style.display = "";
		} else {
			document.getElementById([gbb]).style.display = "none";
		}
	}
	if (inUseTarget) {
		if (inAction == 1) {
			window.location="#GBTarget"+ inGB;
		} else {
			window.location="#";
		}
	}
}

function RICOLAGroupBox_collapseAll() {
	for (var i=0; i < GroupBoxStatusAry.length; i++) {
		if (GroupBoxStatusAry[i] == 1) {
			groupShowHide(i, 0, false);
		}
	}
}

function RICOLAGroupBox_expandAll() {
	for (var i=0; i < GroupBoxStatusAry.length; i++) {
		if (GroupBoxStatusAry[i] == 0) {
			groupShowHide(i, 1, false);
		}
	}
}
