﻿// KEYSOURCE JAVASCRIPT FUNCTIONS
function getElementsByClassName(node, classname)
{
    var a = [];
    var re = new RegExp('\\b' + classname + '\\b');
    var els = node.getElementsByTagName("*");
    for(var i=0,j=els.length; i<j; i++)
        if(re.test(els[i].className))a.push(els[i]);
    return a;
}
function displayUnits(group)
{
    //close any other open classes
    var currentClass = document.getElementById(group).className;
     var elems = getElementsByClassName(document, 'UnitReduce');
     for(var i = 0; i < elems.length; i++)
     {
        elems[i].className = 'UnitExpand';
     }
    //open our unit by changing class
    if (currentClass == 'UnitReduce')
    {
		document.getElementById(group).className = 'UnitExpand';
    }
    else
    {
		document.getElementById(group).className = 'UnitReduce';
    }   
}



window.onload=DoUnitFromHash;
function DoUnitFromHash(){
          if (location.hash.replace("#","")!="")
          {
			displayUnits(location.hash.replace("#",""));
          }
}

function CreateCustomUnitNode()
{
	var cMan  = document.getElementById("Custom_manufacturer").value;
	var cCat  = document.getElementById("Custom_category").value;
	var cVA   = document.getElementById("Custom_VARating").value;
	document.getElementById("Custom_node").value="<Unit><Manufacturer>"+cMan+String.fromCharCode(60,47)+"Manufacturer><Category>"+cCat+String.fromCharCode(60,47)+"Category><VARating>"+cVA+String.fromCharCode(60,47)+"VARating>"+String.fromCharCode(60,47)+"Unit>";
}

function AddMaxUpTime(oForm)
   {
   var nUp = oForm.cUptime.options[oForm.cUptime.selectedIndex].value;
   var nMax = 0;
   switch (nUp) {
			case "10": nMax = 30; break;
			case "30": nMax = 60; break;
			case "60": nMax = 120; break;
			case "120": nMax = 240; break;
			case "240": nMax = 420; break;
			case "420": nMax = 1000; break;	
			default: nMax =	1000; break;	
		}
		oForm.cMaxTime.value=nMax;
   }
   
function ChangeVA(oSelect)
{
	var redundancy = oSelect.options[oSelect.selectedIndex].value*1;
	var basicVA = document.notesForm.cBasicVA.value*1;
	if (redundancy!=0)
	{
		var newVA = 0;
		newVA = basicVA + ((basicVA/100)*redundancy);
		document.notesForm.cRequiredVA.value = newVA;
	}
	else
	{
		getBasicVA();
	}
}
function getBasicVA()
{
	document.notesForm.cRequiredVA.value = document.notesForm.cBasicVA.value*1;
}