
var RICOLARowTwistieIDsUsed=new Array();
var RICOLARowTwistieCurrentStatus=new Array();
var RICOLARowTwistieClassesToBeWhite=new Array("HeaderRow","HeaderRowSub","HeaderRowSubTwo","subgroup");
var RICOLARowTwistie_useCustomJavaScript_flag = false;

function RICOLARowTwistie_expandAll() {
	for (var i=0; i < RICOLARowTwistieIDsUsed.length; i++) {
		if (RICOLARowTwistieCurrentStatus[i] == "0") {
			RICOLAExecuteRowTwistie(RICOLARowTwistieIDsUsed[i],1);
		}
	}
}

function RICOLARowTwistie_collapseAll() {
	for (var i=0; i < RICOLARowTwistieIDsUsed.length; i++) {
		if (RICOLARowTwistieCurrentStatus[i] == "1") {
			RICOLAExecuteRowTwistie(RICOLARowTwistieIDsUsed[i],0);
		}
	}
}





function RICOLAExecuteRowTwistie(inIDNum, inAction) {
	var ie4 = (document.all) ? true : false;
	var ns4 = (document.layers) ? true : false;
	var ns6 = (document.getElementById && !document.all) ? true : false;
	var currID="RICOLATwistieRowInclude_" + inIDNum;

	var IDsUsedInExecute = new Array();

	if (arguments.length != 2) {
		alert("Row Twistie Error #6653:\tNot enough parameters were passed to RICOLAExecuteRowTwistie.  There needs to be two (2) parameters passed, you passed " + arguments.length + ".  For more information, please visit the documentation at http://home.www.uprr.com/emp/it/hf/ricola/twistie/row/");
		return false;
	} else if ((inAction != 0) && (inAction != 1)) {
		alert("Row Twistie Error #6654:\tThe second parameter needs to be a '1' (expand) or a '0' (collapse).  You passed in '" + inAction + "'.  For more information, please visit the documentation at http://home.www.uprr.com/emp/it/hf/ricola/twistie/row/");
		return false;
	} else if (!ie4 && !ns6) {
		return true;
	}
	var MainOpen="RICOLATwistieRow" + inIDNum + "_open";
	var MainClosed="RICOLATwistieRow" + inIDNum + "_closed";
	if (inAction == 0) {	//if you want to collapse it...
		var currAction=new String("none");
		if (ie4) {
			document.all[MainOpen].style.display="none";
			document.all[MainClosed].style.display="inline";
		} else if (ns6) {
			document.getElementById([MainOpen]).style.display="none";
			document.getElementById([MainClosed]).style.display="";
		}
	} else {				//if you want to expand it
		if (ie4) {
			var currAction=new String("inline");			//set var to switch the TR children
			document.all[MainOpen].style.display="inline";	//
			document.all[MainClosed].style.display="none";	//switch between the "expanded" menu (span) and the "collapsed" menu (span)
		} else if (ns6) {
			var currAction=new String("");
			document.getElementById([MainOpen]).style.display="";
			document.getElementById([MainClosed]).style.display="none";
		}
	}
		//alert(document.getElementById("myTable").innerHTML);
	if (ie4) {
		var inItem=document.all[currID];
	} else if (ns6) {
		var inItem=document.getElementsByName([currID]);
	}
	if (inItem.length) {		//if that menu has TRs underneath it, then iterate thru them, collapsing or expanding them all
		var i=0;
		var subTwistieID = new String();
		for (i=0; i< inItem.length; i++) {
			if (ie4) {
				if (inAction == 0) {		//if you want to collapse it...
					var innerHTMLHold = new String(inItem[i].innerHTML);
					var cRTStartLoc = innerHTMLHold.search(/RowTwistie\(\d/);
					if (cRTStartLoc != -1) {		//if there are twisties inside of twisties...?
						var cRTEndLoc = innerHTMLHold.search(/<\/scrip/i);
						subTwistieID = innerHTMLHold.substring(cRTStartLoc, cRTEndLoc);
						subTwistieID = subTwistieID.replace(/[\n\t\r]*/g, "");
						subTwistieID = subTwistieID.replace(/^.*RowTwistie\(\d\,\s*\"([^\"]+)\".+$/g, "$1");
						RICOLAExecuteRowTwistie(subTwistieID, inAction);
					}
				}
				inItem[i].style.display=currAction;
			} else if (ns6) {
				inItem[i].style.display=currAction;
			}
		}
	} else {
		if (ie4) {
			if (inAction == 0) {
				var innerHTMLHold = new String(inItem.innerHTML);
				var cRTStartLoc = innerHTMLHold.search(/RowTwistie\(\d/);
				if (cRTStartLoc != -1) {
					var cRTEndLoc = innerHTMLHold.search(/<\/scrip/i);
					subTwistieID = innerHTMLHold.substring(cRTStartLoc, cRTEndLoc);
					subTwistieID = subTwistieID.replace(/[\n\t\r]*/g, "");
					subTwistieID = subTwistieID.replace(/^.*RowTwistie\(\d\,\s*\"([^\"]+)\".+$/g, "$1");
					RICOLAExecuteRowTwistie(subTwistieID, inAction);
				}
			}
			inItem.style.display=currAction;
		} else if (ns6) {
			inItem.style.display=currAction;
		}
	}
	for (var i=0; i < RICOLARowTwistieIDsUsed.length; i++) {
		if (RICOLARowTwistieIDsUsed[i] == inIDNum) {
			RICOLARowTwistieCurrentStatus[i] = inAction;
			i = RICOLARowTwistieIDsUsed.length;
		}
	}
	if (RICOLARowTwistie_useCustomJavaScript_flag) {
		RICOLARowTwistie_HasFired(inIDNum, inAction);
	}
}



function RowTwistie(inStatus, inIDNum, inText) {
	if (arguments.length < 3) {
		alert("Row Twistie Error #6649:\tIncorrect Number of Parameters were sent to the RowTwistie Function.  Atleast three (3) parameters should be specified, there were only " + arguments.length + " sent.  Please visit the documentation at http://home.www.uprr.com/emp/it/hf/ricola/twistie/row/");
		return false;
	} else if ((parseInt(inStatus,10) != 0) && (parseInt(inStatus,10) != 1)) {
		alert("Row Twistie Error #6650:\tThe first parameter (Status of open or closed), needs to \"0\" (Closed) or \"1\" (Open).  Please visit the documentation at http://home.www.uprr.com/emp/it/hf/ricola/twistie/row/");
		return false;
	}
	var i=0;
	var IDAlreadyUsed=false;
	var TwistieGraphicColor=new String("");
	for (i=0; i < RICOLARowTwistieIDsUsed.length; i++) {
		if (inIDNum == RICOLARowTwistieIDsUsed[i]) {
			IDAlreadyUsed=true;
		}
	}
	if (IDAlreadyUsed) {
		alert("Row Twistie Error #6656:\tThe ID '" + inIDNum + "' has already been used to define a Twistie Row.  Please select a unique ID to start another twistie.  Please visit the documentation at http://home.www.uprr.com/emp/it/hf/ricola/twistie/row/ for more information.");
		return false;
	}
	RICOLARowTwistieIDsUsed[RICOLARowTwistieIDsUsed.length]=inIDNum;
	if (parseInt(inStatus,10) == 1) {
		var OpenStyle=new String("");
		var ClosedStyle=new String(" STYLE=\"display: none;\" ");
		RICOLARowTwistieCurrentStatus[RICOLARowTwistieCurrentStatus.length]=1;
	} else {
		var OpenStyle=new String(" STYLE=\"display: none;\" ");
		var ClosedStyle=new String("");
		RICOLARowTwistieCurrentStatus[RICOLARowTwistieCurrentStatus.length]=0;
	}
	var x=0;
	var currClass=new String(" CLASS=\"TwistieLabel\" ");
	for (x=3; x < arguments.length; x++) {
		if (arguments[x].search(/^\s*class\:.*$/i) != -1) {
			for (i=0; i < RICOLARowTwistieClassesToBeWhite.length; i++) {
				currClass=arguments[x].replace(/\s*$/, "").replace(/^\s*class\:\s*(.*)$/i,"$1");
				if (RICOLARowTwistieClassesToBeWhite[i] == currClass) {
					TwistieGraphicColor="_white";
					currClass=" CLASS=\"" + currClass + "\" ";
					if (currClass.indexOf("subgroup") != -1) {
						currClass += " STYLE=\"color: #FFFFFF !important;\" ";
					}
					i=RICOLARowTwistieClassesToBeWhite.length;
				} else {
					currClass=" CLASS=\"TwistieLabel\" ";
				}
			}
		}
	}
	//write the span tags for the collapsed header and the expanded header, then when the users clicks, turn one on and the other off
	document.write("<span ID=\"RICOLATwistieRow" + inIDNum + "_open\" " + OpenStyle + "><A HREF=\"javascript: void RICOLAExecuteRowTwistie('" + inIDNum + "',0);\" TITLE=\"Click To Collapse\" " + currClass + " STYLE=\"text-decoration: none;\">");
	document.write("<IMG SRC=\"/graphics/apps/twistie/twistie_open" + TwistieGraphicColor + ".gif\" WIDTH=\"11\" HEIGHT=\"11\" BORDER=\"0\">");
	document.write("&nbsp;" + inText + "</A></span>");

	document.write("<span ID=\"RICOLATwistieRow" + inIDNum + "_closed\" " + ClosedStyle + "><A HREF=\"javascript: void RICOLAExecuteRowTwistie('" + inIDNum + "',1);\" TITLE=\"Click To Expand\" " + currClass + " STYLE=\"text-decoration: none;\">");
	document.write("<IMG SRC=\"/graphics/apps/twistie/twistie_closed" + TwistieGraphicColor + ".gif\" WIDTH=\"11\" HEIGHT=\"11\" BORDER=\"0\">");
	document.write("&nbsp;" + inText + "</A></span>");

}


function RowTwistieInclude(inIDNum) {
	var ie4 = (document.all) ? true : false;
	var ns4 = (document.layers) ? true : false;
	var ns6 = (document.getElementById && !document.all) ? true : false;
	var CustExtras=new String("");
	var CurrStyle=new String("");
	var i=0;
	var IDUsed=false;
	var IDint=0;
	for (i=0; i< RICOLARowTwistieIDsUsed.length; i++) {
		if (RICOLARowTwistieIDsUsed[i] == inIDNum) {
			IDUsed=true;
			IDint=i;
			i=RICOLARowTwistieIDsUsed.length;
		}
	}
	if (arguments.length < 1) {
		alert("Row Twistie Error #6651:\tIncorrect Number of Parameters were sent to the RowTwistieInclude Function.  There needs to be atleast one (1) parameter specified (the ID).  Please visit the documentation at http://home.www.uprr.com/emp/it/hf/ricola/twistie/row/");
		return false;
	} else if (!IDUsed) {
		alert("Row Twistie Error #6652:\tID not used.  You have chosend an ID that hasn't been defined in the RowTwistie Function yet.  Please put this function, RowTwistieInclude(), after the RowTwistie() function or choose a ID that has already been defined.  For more information, please visit the documentation at http://home.www.uprr.com/emp/it/hf/ricola/twistie/row/");
		return false;
	}
	if (RICOLARowTwistieCurrentStatus[IDint] == 0) {
		if (ie4 || ns6) {
			CurrStyle=" STYLE=\"display: none;\"";
		} else {
			CurrStyle=" STYLE=\"visibility: hidden;\"";
		}
	} else if (RICOLARowTwistieCurrentStatus[IDint] == 1) {
		CurrStyle=" STYLE=\"display: ;\"";
	}
	for (i=1; i < arguments.length; i++ ) {
		if ((arguments[i].search(/^(id|name|style)\:/i) == -1) && (arguments[i].search(/\:/g) != -1) && (arguments[i].indexOf(":") == arguments[i].lastIndexOf(":"))) {
			CustExtras+=arguments[i].replace(/^\s*/, "").replace(/\s*$/, "").replace(/^(\w*)\:\s*(.*)$/, " $1\=\"$2\"");
		}
	}
	document.writeln("<TR NAME=\"RICOLATwistieRowInclude_" + inIDNum + "\" ID=\"RICOLATwistieRowInclude_" + inIDNum + "\" " + CurrStyle + " " + CustExtras + ">");
}

	function RICOLARowTwistie_UseCustomJavaScript() {
		RICOLARowTwistie_useCustomJavaScript_flag = true;
	}
