var KS, windowHeight;
var strs = {
	  '0': {"s": "site-houder", "p": "site-houders", "S": "Site-houder", "P": "Site-houders"}
	, '1': {"s": "site", "p": "sites", "S": "Site", "P": "Sites"}
	, '2': {"s": "sectie / pagina", "p": "secties / paginas", "S": "Sectie / pagina", "P": "Secties / Paginas"}
	, '3': {"s": "alinea", "p": "alineas", "S": "Alinea", "P": "Alineas"}
}
var fouten = {
	  'bb': 'Om geavanceerdere faciliteiten te kunnen gebruiken, is een nieuwere browser nodig. Wij raden Firefox aan (minimaal versie 2), of anders Opera (minimaal versie 9), of Internet Explorer (minimaal versie 7).'
	
	, 'mod-1': 'Minstens 3 tekens!'
	, 'mod-2': 'Voer een getal tussen -1000 en 1000 in!'

	, 'add-3': 'Kan hier geen items plaatsen!'
	, 'add-4': 'Minstens 3 tekens!'
}

function fout(code) {
	var str = fouten[code];
	if (str == undefined) str = 'Er is een onbekende fout opgetreden. Meld dit alstublieft bij de administratie.\n\nFoutcode: ' + code;
	alert(str);
	return false;
}

function getEntry(eid) {
	if (window.entries[eid] == undefined) window.entries[eid] = {
		  'extra_data': {}, 'id': eid, 'eid': eid
	}
	return window.entries[eid];
}
function refresh() {
	var href = window.location.href;
	window.location.href = '';
	window.location.href = href;
}

function calcWindowHeight() {
	windowHeight = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
}

function appInit() {
	KS = new Interface('ks', function() {
		var me;
		if (KS.res.uid != undefined && KS.res.users != undefined) me = KS.res.users[KS.res.uid];
		if (KS.res.uid == 0 || me != undefined) KS.me = me;
		response();
	}, './');
	return true;
}

function stdEntry(title, value, classC, id, styleTitle, styleValue, styleC) {
	id = id == undefined ? "" : id; if (id != "") id = " id=\"" + id + "\"";
	styleTitle = styleTitle == undefined ? "" : styleTitle; if (styleTitle != "") styleTitle = " style=\"" + styleTitle + "\"";
	styleValue = styleValue == undefined ? "" : styleValue; if (styleValue != "") styleValue = " style=\"" + styleValue + "\"";
	styleC = styleC == undefined ? "" : styleC; if (styleC != "") styleC = " style=\"" + styleC + "\"";
	title = (title == undefined || title == "") ? "" : "<p" + styleTitle + " class=\"title\">" + title + "</p>";
	value = (value == undefined || value == "") ? "" : "<div" + styleValue + " class=\"value\">" + value + "</div>";
	return "<div"+ styleC + " class=\"" + classC + "\">" + title + value + "</div>";
}

function mkNN(obj) {
	var ts = trim(obj.value);
	return parseInt(ts) == ts ? (ts < 0 ? 0 : ts) : 0;
}

function checkNiv(niv) {
	if (KS.me == undefined) {sluit("Log a.u.b. in."); return false;}
	if (KS.me.level < niv) {sluit("U bent niet gemachtigd."); return false;}
	return true;
}

function $(id) {
	return document.getElementById(id);
}

function preLoadImages() {
	var MWJ_img_cache = new Object();
	for( var i = 0; i < 2; i++ ) {
		var ar = i ? ( document.getElementsByTagName ? document.getElementsByTagName('input') : ( document.all ? document.all.tags('INPUT') : [] ) ) : document.images;
		for( var x = 0; ar[x]; x++ ) {
			var im = ar[x];
			if( im.getAttribute ) { im.hoversrc = im.getAttribute('hoversrc'); im.activesrc = im.getAttribute('activesrc'); }
			if( im.hoversrc || im.activesrc ) {
				if( !MWJ_img_cache[im.src] ) { MWJ_img_cache[im.src] = new Image(); MWJ_img_cache[im.src].src = im.src; }
				im.rootsrc = im.src;
				im.onmouseout = function () { this.src = this.rootsrc; };
			}
			if( im.hoversrc ) {
				if( !MWJ_img_cache[im.hoversrc] ) { MWJ_img_cache[im.hoversrc] = new Image(); MWJ_img_cache[im.hoversrc].src = im.hoversrc; }
				im.onmouseover = function () { this.src = this.hoversrc; };
			}
			if( im.activesrc ) {
				if( !MWJ_img_cache[im.activesrc] ) { MWJ_img_cache[im.activesrc] = new Image(); MWJ_img_cache[im.activesrc].src = im.activesrc; }
				im.onmousedown = function (e) {
					e = e ? e : window.event;
					if( e.button > 1 || e.which > 1 ) { return; }
					this.src = this.activesrc;
				};
				im.onmouseup = function (e) {
					e = e ? e : window.event;
					if( e.button > 1 || e.which > 1 ) { return; }
					this.src = this.hoversrc ? this.hoversrc : this.rootsrc;
				};
			}
		}
	}
}