// Checks if a string is empty
function emptystr(string) {
	var x = 0;
	var chr;
	var empty = true;
	if (string.length) {
		do {
			chr = string.substring(x, x + 1);
			x++;
			empty = (chr == ' ' || chr == '\t' || chr == '\n' || chr == '\r');
		} while (empty && x < string.length);
	}
	return empty;
}

function checkGetal(item, name){
  if (isNaN(document.subform.elements[item].value)){
	  alert(name + ' moet een nummer zijn!');
    document.subform.elements[item].focus();
    return false;
  }
  else{
    return true;
  }
}

function showAlert(item, name){
  if (emptystr(document.subform.elements[item].value)){
    alert('U heeft ' + name + ' vergeten in te voeren!');
    document.subform.elements[item].focus();
    return false;
  }
  else{
    return true;
  }
}

function checkEmail(item){
  var pattern=/(^[\-_\.a-zA-Z0-9]+)@((([0-9]{1,3}\.){3}([0-9]{1,3})((:[0-9])*))|(([a-zA-Z0-9\-]+)(\.[a-zA-Z]{2,})+(\.[a-zA-Z]{2})?((:[0-9])*)))/;
  
  if (document.subform.elements[item].value.search(pattern) == -1){
    alert('Het e-mailadres is onjuist!');
    document.subform.elements[item].focus();
    return false;
  }
  else{
    return true;
  }
}

function addSubject() {
    return (showAlert('subject', 'het onderwerp') && showAlert('user', 'de naam') && checkEmail('email') && showAlert('content', 'het bericht')); 
}

function addPost() {
    return (showAlert('user', 'de naam') && checkEmail('email') && showAlert('content', 'het bericht')); 
}

function addNewsletterMember() {
    return (showAlert('lastname', 'de achternaam') && showAlert('firstname', 'de voornaam') && checkEmail('email'));
}

function removeNewsletterMember() {
    return checkEmail('email');
}

function searchRelation() {
    return (showAlert('search_string', 'de zoekopdracht'));
}

function windowOpen(name,url,Hoogte,Breedte) {
  LeftPosition = (screen.width) ? (screen.width-Breedte)/2 : 0;
  TopPosition = (screen.height) ? (screen.height-Hoogte)/2 : 0;
  settings ='height='+Hoogte+',width='+Breedte+',top='+TopPosition+',left='+LeftPosition+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no'
  window_open = window.open(url,name, settings);
  window_open.focus();
}

function selectListboxItem ( theListbox, theItem ) {
	theOptions = theListbox.options;
	for(i=0; i<theOptions.length; i++) {
		theOptions[i].selected = theOptions[i].value == theItem;
	}
}

function printFrame(frame_name){ 
  if(typeof window.print == "undefined"){ 
    alert("Uw browser ondersteund dit niet!"); 
  }else{ 
    parent.frames[frame_name].focus(); 
    parent.frames[frame_name].window.print();  
  } 
} 

function form_setfocus( aForm ) {
	if( aForm.elements[0]!=null) {
		var i;
		var max = aForm.length;
		for( i = 0; i < max; i++ ) {
			if( aForm.elements[ i ].type != "hidden" &&
				!aForm.elements[ i ].disabled &&
				!aForm.elements[ i ].readOnly ) {
				aForm.elements[ i ].focus();
				break;
			}
		}
	}
}

imgFadeObjects = new Object();
imgFadeTimers = new Object();

function imgFade(object, naarDoorzichtigheid, snelheid, aantalStappen) {


	if (!document.all) {
		return;
	}

	if (object != "[object]") {
		setTimeout("imgFade("+object+","+naarDoorzichtigheid+","+snelheid+","+aantalStappen+")",0);
		return;
	}

	clearTimeout(imgFadeTimers[object.sourceIndex]);

	diff = naarDoorzichtigheid-object.filters.alpha.opacity;
	direction = 1;
	if (object.filters.alpha.opacity > naarDoorzichtigheid) {
		direction = -1;
	}

	aantalStappen = Math.min(direction*diff,aantalStappen);
	object.filters.alpha.opacity+=direction*aantalStappen;

	if (object.filters.alpha.opacity != naarDoorzichtigheid) {
		imgFadeObjects[object.sourceIndex] = object;
		imgFadeTimers[object.sourceIndex] = setTimeout("imgFade(imgFadeObjects["+object.sourceIndex+"],"+naarDoorzichtigheid+","+snelheid+","+aantalStappen+")",snelheid);
	}
}

// this is a dummy function. Every module can override this function for initialisation
function init() {
	null;
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function hide(val) {

                var ele = document.getElementById('popin');

                ele.style.display = val ? 'none' : 'block';

            }
