// 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 selectListboxItem ( theListbox, theItem ) {
	theOptions = theListbox.options;
	for(i=0; i<theOptions.length; i++) {
		theOptions[i].selected = theOptions[i].value == theItem;
	}
}

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;
			}
		}
	}
}
// this is a dummy function. Every module can override this function for initialisation
function init() {
	null;
}

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 + ',resizable=no,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes';
	window_open = window.open(url,name,settings);
	window_open.focus();
}