function doLogin(text) {
	var textElements = text.split('§');
	switch (textElements[0]) {
		case "ERROR":
			document.getElementById('message').innerHTML = textElements[1]; break;
		case "OK":
			document.getElementById('content').innerHTML = textElements[1];
			if (textElements[2]) {
				document.getElementById(textElements[2]).innerHTML = textElements[3]; 
			}
			break;
		default:
			document.getElementById('content').innerHTML = text;
	}
}

function fillInContent(text) {
	var textElements = text.split('§menu§');
	document.getElementById('content').innerHTML = textElements[0];
	if (textElements[1]) {
		document.getElementById('menu').innerHTML = textElements[1];
	}
}

function fillInKommune(text) {
	var selectNode = document.getElementById('kommune');
	
	while(selectNode.length){
		selectNode.remove(0);
	}
	
	if (text) {
		var antal = text.getElementsByTagName('kommune').length;
	} else {
		var antal = 0;
	}
	
	var optionNode = document.createElement('option');
	if (antal == 0) {
		optionNode.appendChild(document.createTextNode('Vælg først region'));
	} else {
		optionNode.appendChild(document.createTextNode('Alle'));
	}
	selectNode.appendChild(optionNode);	

	for (var i = 0; i < antal; i++) {
		var optionNode = document.createElement('option');
		optionNode.value = text.getElementsByTagName('kode')[i].childNodes[0].nodeValue;
		optionNode.appendChild(document.createTextNode(text.getElementsByTagName('navn')[i].childNodes[0].nodeValue));
		selectNode.appendChild(optionNode);
	}
}

function fillInResult(text) {
	document.getElementById('result').innerHTML = text;
}

function grayOutButton(button) {
	switch (button) {
		case "hvadVis":
			if (document.getElementById('region').value == "") { document.getElementById('hvadVis').disabled = true; }
			else { document.getElementById('hvadVis').disabled = false; }
			break;
	}
}

function newpage(item) {
	var elements = item.split(',');
	doAjax(elements[0],elements[1],elements[2],elements[3],elements[4],elements[5]);
}

function setError(element) {
	$(document.getElementById(element)).addClass("redborder");
	document.getElementById(element).focus();
}

function removeError(element) {
	$(document.getElementById(element)).removeClass("redborder");
}
