﻿
window.onload=performLoad;

function performLoad()
{
	showMenu();
	checkParams();
}

function setStyleProperty(o, sProperty, value)
{
	if (o)
	{
		if (typeof o.style != "undefined")
		{
			if (typeof o.style[sProperty] != "undefined")
			{
				return (o.style[sProperty] = value) == value;
			}
		}
		// for NN4, positioned elements only
		else if (typeof o[sProperty] != "undefined")
		{
			return (o[sProperty] = value) == value;
		}
	}
	
	return false;
}

function show(o)
{
	return setStyleProperty(o, "display", "block");
}

function hide(o)
{
	return setStyleProperty(o, "display", "none");
}

function getElementsByClassName(oElm, strTagName, oClassNames){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	var arrRegExpClassNames = new Array();
	if(typeof oClassNames == "object"){
		for(var i=0; i<oClassNames.length; i++){
			arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames[i].replace(/\-/g, "\\-") + "(\\s|$)"));
		}
	}
	else{
		arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames.replace(/\-/g, "\\-") + "(\\s|$)"));
	}
	var oElement;
	var bMatchesAll;
	for(var j=0; j<arrElements.length; j++){
		oElement = arrElements[j];
		bMatchesAll = true;
		for(var k=0; k<arrRegExpClassNames.length; k++){
			if(!arrRegExpClassNames[k].test(oElement.className)){
				bMatchesAll = false;
				break;
			}
		}
		if(bMatchesAll){
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements)
}

function hideAllSystems()
{
	var techsections = getElementsByClassName(document.getElementById("tech_body"), "div", "tech_section");
	
	for ( var sect in techsections )
	{
		hide(techsections[sect]);
	}
	
	return true;
}

function showSystemsByClass(className)
{
	var techsections = getElementsByClassName(document.getElementById("tech_body"), "div", className);
	
	for ( var sect in techsections )
	{
		show(techsections[sect]);
	}
	
	return true;
}

function processSelection()
{
	var index = document.systemsForm.TypeSelector.selectedIndex;
	var selval = document.systemsForm.TypeSelector.options[index].value;

	hideAllSystems();
	
	showSystemsByClass(selval);	
	
	return true;
}

function getParams() {
	var idx = document.URL.indexOf('?');
	var params = new Array();
			if (idx != -1) {
				var pairs = document.URL.substring(idx+1, document.URL.length).split('&');
				for (var i=0; i<pairs.length; i++) {
				nameVal = pairs[i].split('=');
				params[nameVal[0]] = nameVal[1];
	   }
	}
	return params;
}

function checkParams()
{
	var systemSelect = getParams();
	
	var diagmode = unescape(systemSelect["diag"]);
	if(diagmode == "true")
	{
		outputTechSections();
	}
	
	if(systemSelect)
	{
		var systype = unescape(systemSelect["type"]);
	
		if(systype)
		{
			eval('selectObject = document.systemsForm.TypeSelector;');
			for (index = 0; index < selectObject.options.length; index++)
			{
				if(selectObject.options[index].value == systype)
				{
					selectObject.selectedIndex = index;
					processSelection();
					break;
				}
			}
		}
	}
}

function outputTechSections()
{
	var techsections = getElementsByClassName(document.getElementById("tech_body"), "div", "tech_section");
	var outputElement = document.getElementById("tech_header");
	var outputText = "output=";
	
	if(document.createTextNode)
	{		
		for (sect in techsections)
		{
			outputText += "Id = " + techsections[sect].id + ":" + "Classes = " + techsections[sect].className +",";
		}
		
		newElement = document.createTextNode(outputText);
		outputElement.appendChild(newElement);
	}
	
	return true;
}