function skift(elm, c) {
	elm.style.backgroundColor = c;
}

// Funktion til at vise billeder i et tilpasset vindue
function vis_billede(pic) { 
	picWin = window.open('', 'picWin', 'width=50,height=50,scrollbars=no,resizable=yes,status=no,titlebar=no');
	picWin.document.open();
	picWin.document.write("<html>\n<head>\n<title>Vis billede [" + pic + "]</title>\n");
	picWin.document.write("<scr" + "ipt language=\"javasc" + "ript\" type=\"text/javascr" + "ipt\">\nself.focus();\n\nfunction tilpas_win()\n{\n    $billW = document.getElementById('billede').width + 40;\n    $billH = document.getElementById('billede').height + 50;\n    if ($billW > screen.availWidth) {\n        $billW = screen.availWidth;\n    }\n    if ($billH > screen.availHeight) {\n        $billH = screen.availHeight;\n    }\n    window.resizeTo($billW, $billH);\n    return true;\n}\n</scr" + "ipt>\n");
	picWin.document.write("</head>\n<body bgcolor=\"#ffffff\" text=\"#000000\" style=\"margin: 0\" onload=\"tilpas_win();\">\n");
	picWin.document.write("<table style=\"width: 100%; height: 100%; text-align: center; cursor: pointer;\" border=\"0\" onclick=\"window.close();\">\n<tr>\n    <td><img src=\"http://www.jensgram.dk/" + pic + "\" id=\"billede\" style=\"border: 1px solid #000000;\" \></td>\n</tr>\n</table>\n</body>\n</html>"); 
	picWin.document.close();
}

function JgMenuCoreShow(index, items) {
	for (i = 0; i < items.length; i++) {
		document.getElementById(items[i]).style.display = 'none';
	}
	document.getElementById(items[index]).style.display = 'block';
}

/**
 * Alias for document.getElementById.
 */
function r(id) {
	return document.getElementById(id);
}

/**
 * Toggles the style.display property of elm.
 * Returns true if the element is now displayed, false otherwise.
 */
function toggleDisp(elm, dVal) {
	var d;
	if (elm) {
		dVal = (dVal == null ? 'block' : dVal);
		d = (elm.style.display != 'none');
		elm.style.display = (d ? 'none' : dVal);
		return !d;
	}
	return false;
}

/**
 * Switches the text (s1 and s2) of elm.
 */
function swapText(elm, s1, s2) {
	elm.firstChild.nodeValue = (elm.firstChild.nodeValue == s1 ? s2 : s1);
}


// Add ins/del data
var isVersionButtonInserted = false;
var isDelDataVisible = false;

function bindInsDelData() {
	var aDel = document.getElementById('siteContent').getElementsByTagName('del');
	var aIns = document.getElementById('siteContent').getElementsByTagName('ins');
	if (aDel.length > 0 && aIns.length > 0) { // Continue only if there are both ins and del elements
		for (var i = 0; i < aIns.length; i++) {
			var eIns = aIns[i];
			eIns.onmouseover = function() {
				if (!isVersionButtonInserted) {
					var eShow = document.createElement('img');
					eShow.setAttribute('src', '/gfx/showversions.png');
					eShow.setAttribute('title', 'Denne side indeholder opdaterede oplysninger. Klik her for at vise gamle (slettede) oplysninger.');
					eShow.style.paddingLeft = '4px'
					eShow.onclick = function() { showDelData(aIns, aDel); };
					eIns.appendChild(eShow);
				}
				isVersionButtonInserted = true;
			};
		}
	}
}

function showDelData(aIns, aDel) {
	if (!isDelDataVisible) {
		for (var i = 0; i < aIns.length; i++) {
			aIns[i].style.backgroundColor = '#cf5';
		}
		for (var i = 0; i < aDel.length; i++) {
			aDel[i].style.display = 'inline';
			if (aDel[i].getAttribute('datetime')) {
				sDate = aDel[i].getAttribute('datetime');
				sDate = sDate.substring(0, 10) + ' kl. ' + sDate.substring(11, 19);
				aDel[i].appendChild(document.createTextNode(' (Slettet ' + sDate + ')'));
			}
		}
	}
	isDelDataVisible = true;
}

window.onload = bindInsDelData;