{"size": 3867, "ext": "js", "max_stars_repo_path": "website/src/util/common.js", "max_stars_repo_name": "neuweiler/GEVCU", "max_stars_repo_stars_event_min_datetime": "2015-10-15T12:40:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-19T03:56:30.000Z", "max_issues_repo_path": "website/src/util/common.js", "max_issues_repo_name": "neuweiler/GEVCU", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "website/src/util/common.js", "max_forks_repo_name": "neuweiler/GEVCU", "max_forks_repo_forks_event_min_datetime": "2017-06-12T13:07:01.000Z", "max_forks_repo_forks_event_max_datetime": "2017-06-12T13:07:01.000Z"}
{"max_stars_count": 8, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 27.6214285714, "max_line_length": 106, "alphanum_fraction": 0.6503749677}
var nodecache = new Array();

function showTab(pageId) {
	// show the correct div and hide the others
	var tabs = document.getElementById('tabs');
	for (var i = 0; i < tabs.childNodes.length; i++) {
		var node = tabs.childNodes[i];
		if (node.nodeType == 1) { /* Element */
			node.style.display = (node.id == pageId) ? 'block' : 'none';
		}
	}

	if (pageId == 'dashboard') {
		dashboard.activate();
	} else {
		// change the class of the selected tab
		var tabHeader = document.getElementById('tabHeader');
		var linkToActivate = document.getElementById(pageId + 'link');
		for (var i = 0; i < tabHeader.childNodes.length; i++) {
			var node = tabHeader.childNodes[i];
			if (node.nodeType == 1) { /* Element */
				node.className = (node == linkToActivate) ? 'on' : '';
			}
		}
		if (pageId == 'controls') {
			resizeThrottleCanvas();
		}
	}
	loadData(pageId);
}

//lazy load of page, replaces content of div with id==<pageId> with
//content of remote file <pageId>.htm
function loadPage(pageId) {
	ajaxCall(pageId + ".htm", function (response) {
		document.getElementById(pageId).innerHTML = response;
		if (pageId == 'motor') {
			generateRangeControls();
			resizeThrottleCanvas();
		}
		if (pageId == 'dashboard') {
			// load config for dashboard gauges, then generate them
			ajaxCall("config/dashboard.js", function (response) {
				var data = JSON.parse(response);
				generateGauges(data);
				dashboard.setCruiseData(data);
			});
			loadPage("annunciator");
			loadPage("batteries");
			dashboard.hideStateDivs();
		}
	});
}

function getCache(name) {
	var target = nodecache[name];
	if (!target) {
		target = document.getElementById(name);
		if (!target) { // id not found, try to find by name
			var namedElements = document.getElementsByName(name);
			if (namedElements && namedElements.length) {
				target = namedElements[0];
			}
		}
		nodecache[name]=target;
	}
	return target;
}

function setNodeValue(name, value) {
	// a normal div/span/input to update
	target = getCache(name);
	if (target) { // found an element, update according to its type
		if (target.nodeName.toUpperCase() == 'DIV' || target.nodeName.toUpperCase() == 'SPAN') {
			target.innerHTML = value;
		} else if (target.nodeName.toUpperCase() == 'INPUT') {
			if (target.type && (target.type.toUpperCase() == 'CHECKBOX' || target.type.toUpperCase() == 'RADIO')) {
				target.checked = value;
			} else {
				target.value = value;
				// find corresponding slider element
				var slider = document.getElementById(name + "Level");
				if (slider) {
					slider.value = value;
				}
			}
		} else if (target.nodeName.toUpperCase() == 'SELECT') {
			selectItemByValue(target, value);
		}
	}
}

// load data from dynamic json and replace values in input fields, div's, gauges
function loadData(pageId) {
	ajaxCall('config/' + pageId + '.js', function(response) {
		var data = JSON.parse(response);

//		hideDeviceTr();
		for (name in data) {
			var value = data[name];
			if (name.indexOf('device_x') == 0 && value == '1') {
				// it's a device config, update device specific visibility
				setTrVisibility(name, true);
			} else {
				setNodeValue(name, value);
			}
		}

		if (pageId == 'controls') {
			refreshThrottleVisualization();
		}
	});
}

// scan through the options of a select input field and activate the one with
// the given value
function selectItemByValue(node, value) {
	for (var i = 0; i < node.options.length; i++) {
		if (node.options[i].value == value) {
			node.selectedIndex = i;
			break;
		}
	}
}

function ajaxCall(url, callback) {
	try {
		var xmlhttp = new XMLHttpRequest();
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				callback(xmlhttp.responseText);
			}
		};
		xmlhttp.open("GET", url, true);
		xmlhttp.send();
	} catch (err) {
		alert("unable to retrieve data for page " + pageId);
	}
}
