// font size aanpassen
var defaultFontSize =100;
function revertStyles() {
	prefs.fontSize = defaultFontSize;
	changeFontSize(0);
}
function changeFontSize(sizeDifference){
	prefs.fontSize = Math.max(Math.min(Number(prefs.fontSize ? prefs.fontSize : defaultFontSize) + sizeDifference * 10,140),60);
	setFontSize(prefs.fontSize);
}
function setFontSize(fontSize){
	document.body.style.fontSize = fontSize + '%';
}
// prefs saven/loaden
var prefs = { rssstate: {} };
function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*3600000));
    var expires = "; expires="+date.toGMTString();
  } else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}
function setUserOptions() {
	if( prefs.fontSize != null ) return;
	var str = readCookie("prefs");
	if ( !str ) return;
	prefs = JSON.parse( str );
	setFontSize( prefs.fontSize ? prefs.fontSize : defaultFontSize);
}
function saveSettings() {
  createCookie("prefs", JSON.stringify( prefs ), 365);
}
//rss
function toggle( sel, speed ) {
	if ( $(sel).length==0 ) return;
	if ( speed==null ) speed = 500;
	var cl = $(sel+'_button').attr('class').split('_');
	cl.pop();
	if ( $( sel+':visible' ).length ) {
		$(sel).hide(ie6 ? 0 : speed);
		cl.push( 'closed' );
		delete( prefs.rssstate[sel] );
	} else {
		$(sel).show(ie6 ? 0 : speed);
		cl.push( 'open' );
		prefs.rssstate[sel] = 1;
	}
	$(sel+'_button').attr('class', cl.join('_') );
	if ( ie6 ) fixRssBack();
}
// xAjax Stuff
function switchlang( lang, page ) {
	xajax.call('custom_xajax#switchlang', new Array(lang,page), 1);
}
function setIndemedia( ) {
	xajax.call('custom_xajax#setIndemedia', arguments, 1);
}
function submitForm(e, additional_cf) {
	
	if (e && e.tagName == 'FORM') {
		
		if(!ValidateForm(e)) return false;
		
		var formElements = e.elements;
		var target_cf = formElements['target_cf'] ? formElements['target_cf'].value : additional_cf;
		var wait_button = formElements['wait_button'].value;
		
		if(target_cf) {
			
			var chksum = location.hostname;
			formElements['checksum'].setAttribute("value",chksum);
			
			if (xajax.$(wait_button)) {
				xajax.$(wait_button).disabled=true;
				xajax.$(wait_button).value="Even geduld aub...";
			}
			xajax.call(target_cf, new Array(xajax.getFormValues(e)), 1);
			
		} else {
			alert('submitForm: No valid arguments');
		}
	} else {
		alert('submitForm: No valid FORM object');
	}
	return false;
}


function ValidateForm(e) {
	var msg = '';
	var chk = '';
	var focusfld = '';
	var i,ii,x;
	var rclist = [];
	var val = '';
	for(i=0;i<e.length;i++) {
		if (chk = e[i].getAttribute('inpchk')) {
			e[i].className = e[i].className.replace('mandatory','');
			if ((chk == 'notempty')) {
				if (e[i].type == 'checkbox') {
					val = (e[i].checked) ? '1' : '';
				} else {
					val = e[i].value;
				}
				if (val == '') {
					if (focusfld == '') focusfld = e[i].name;
					msg += e[i].getAttribute('chkmsg')+"\n";
					e[i].className += ' mandatory';
				}
			}
			if ((chk == 'minmaxlen')) {
				var min = e[i].getAttribute('minlen');
				var max = e[i].getAttribute('maxlen');
				if (e[i].value.length < min) {
					msg += e[i].getAttribute('chkmsg')+"\n";
					if (focusfld == '') focusfld = e[i].name;
					e[i].className += ' mandatory';
				}
				if (e[i].value.length > max) {
					msg += e[i].getAttribute('maxmsg')+"\n";
					if (focusfld == '') focusfld = e[i].name;
					e[i].className += ' mandatory';
				}
			}
			if ((chk == 'radiovalue')) {
				if (rclist[e[i].name] == 1) continue;
				rclist[e[i].name] = 1;
				x = e[e[i].name];
				if (!!x[0]) {
					for(ii=0;ii<x.length;ii++) {
						x[ii].className = x[ii].className.replace('mandatory','');
					}
					val = false;
					for(ii=0;ii<x.length;ii++) {
						if (x[ii].checked) val = true;
					}
					if (!val) {
						for(ii=0;ii<x.length;ii++) {
							x[ii].className += ' mandatory';
						}
						if (focusfld == '') focusfld = i;
						msg += e[i].getAttribute('chkmsg')+"\n";
					}
				}
			}
		}
	}
	if (msg) {
		alert(msg);
		e[focusfld].scrollIntoView(false);
		e[focusfld].focus();
		return false;
	}
	return true;
}


