function getNodeValue(obj,tag) { /* XML uitlezen */
    return obj.getElementsByTagName(tag)[0].firstChild.nodeValue;
}

function getSingleData(response,tag) { /* XML uitlezen */
	return response.getElementsByTagName(tag)[0].firstChild.data;
}

function setLoading(state) { /* Overlay laten zien of weghalen */
	if(state == 'inactive') {
		document.getElementById('overlay').style.display = 'none';
		document.getElementById('loading').style.display = 'none';
	} else {
		if(document.getElementById('overlay')) {
			document.getElementById('overlay').style.display = 'block';
		} else {
			var newdiv = document.createElement('div');
			newdiv.setAttribute('id', 'overlay');
			document.body.appendChild(newdiv);
		}
		document.getElementById('loading').style.display = 'block';
	}
}

function submitPoll() {
	var inputs = $$('#pollformulier input');
	var value = 0;
	var poll = '';
	
	for(i=0;i<inputs.length;i++) {
		if(inputs[i].checked == true) {
			value = inputs[i].value;
			poll = inputs[i].name;
		}
	}
	
	if(value == 0) {
		alert('Je kan niet op de poll stemmen zonder een optie te selecteren.');	
	}
	else {
		var url = linkprefix + 'XML/poll.php';
		var pars = 'poll=' + poll + '&value=' + value;
		
		var myAjax = new Ajax.Request(
		url, 
		{
			method: 'post', 
			parameters: pars, 
			onComplete: showResponse = function(request) {
				var response = request.responseXML;
				var status = getSingleData(response,'status');
				var message = getSingleData(response,'message');
				
				if(status != 0) alert(message);
				else {
					// De stem is opgeslagen, haal de resultaten op
					var url = linkprefix + 'XML/poll_stand.php';
					var myAjax = new Ajax.Request(
					url, 
					{
						method: 'post', 
						parameters: pars, 
						onComplete: showResponse = function(request) {
							var response = request.responseText;
							$('pollformulier').innerHTML = response;
						}
					});
				}
			}
		});
	}
}

function setVoorkeur(id) {
	if($(id).checked == true) {
		$(id + '_wrapper').className = 'actief';	
	}
	else {
		$(id + '_wrapper').className = '';
	}
}

/* Formulieren */
function activateField(id) { /* Veld/button actief maken */
	document.getElementById(id).disabled = false;
}

function focusField(id) { /* Zet cursor in veld */
	$(id).focus();
}

/* Toetsaanslagen */
function checkKeyCode(evt) {
	var charCode = (evt.which) ? evt.which : event.keyCode;
	return charCode;
}

function checkCapsLock( e ) {
	var key, shift;
	
	var caps = document.getElementById('error');
	
	if (typeof e == 'undefined') {
		e = window.event;
		
		if (typeof e == 'undefined') {
			return;
		}
	}  
		
	if (e.which) { // netscape, firefox
		key = e.which;
	} else if (e.keyCode) { // IE
		key = e.keyCode;
	} else {
		return;
	}
		
	if (typeof e.shiftKey != 'undefined') { // IE, firefox
		shift = e.shiftKey;
	} else if (e.modifiers) { // netscape
		shift = (e.modifiers & 4); // 3e bit is shift
	} else {
		return;
	}
		
	if ((key > 64) && (key < 91)) {
		if (shift == false) {
			caps.innerHTML = 'Let op! Uw Caps Lock staat aan. E-mailadres en wachtwoord zijn hoofdletter gevoelig!';
		} else {
			caps.innerHTML = '';
		}
	} else if ((key > 96) && (key < 123)) {
		if (shift == true) {
			caps.innerHTML = 'Let op! Uw Caps Lock staat aan. E-mailadres en wachtwoord zijn hoofdletter gevoelig!';
		} else {
			caps.innerHTML = '';
		} 
	}
}

function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else if (document.documentElement && document.documentElement.scrollHeight > document.documentElement.offsetHeight){ // Explorer 6 strict mode
		xScroll = document.documentElement.scrollWidth;
		yScroll = document.documentElement.scrollHeight;
	} else { // Explorer Mac...would also work in Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) { // all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}
	
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	
	
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}
