function inputControl( form ){
	inputtags = form.all.tags( 'input' );
	selecttags = form.all.tags( 'select' );
	textareatags = form.all.tags( 'textarea' );

	//----------INPUT CONTROLE-------------------------------------------------------------------------
	for( i=0; i<inputtags.length; i++ ){	
		if( inputtags(i).require == 'true'){
			if( inputtags(i).value == '' ){
				alert('Niet alle verplicht velden zijn ingevuld!');
				inputtags(i).focus();
				return false;
			} else {
				if( !controleerVeld( inputtags(i) ) ) return false;
			}
		} else {
			if( inputtags(i).value != '' && inputtags(i).type == 'text') {
				if( !controleerVeld( inputtags(i) ) ) return false;
			}
		}
	}

	//----------SELECT CONTROLE------------------------------------------------------------------------
	for( i=0; i<selecttags.length; i++ ){
		if( selecttags(i).require == 'true'){
			if( selecttags(i).value == '' ){
				alert('Niet alle verplicht velden zijn ingevuld!');
				selecttags(i).focus();
				return false;
			} 
		} 
	}

	//----------TEXTAREA CONTROLE----------------------------------------------------------------------
	for( i=0; i<textareatags.length; i++ ){
		if( textareatags(i).require == 'true'){
			if( textareatags(i).value == '' ){
				alert('Niet alle verplicht velden zijn ingevuld!');
				textareatags(i).focus();
				return false;
			} 
		} 
	}
	
	return true;
}

function controleerVeld( veld ){
	switch (veld.controltype){
		case 'text':
			return true;
			break;
		case 'numeriek':
			if( isNaN( veld.value ) == true ){
				veld.focus();
				veld.select();
				alert('De invoer is niet numeriek!');
				return false;
			} else {
				return true;
			}
			break;
		case 'decimaal1':
			if( isNaN( veld.value ) == true ){
				veld.focus();
				veld.select();
				alert('De invoer is geen getal!');
				return false;
			} else {
				veld.value = round( veld.value, 1 );
				return true;
			}
			break;
		case 'decimaal2':
			if( isNaN( veld.value ) == true ){
				veld.focus();
				veld.select();
				alert('De invoer is geen getal!');
				return false;
			} else {
				veld.value = round( veld.value, 2 );
				return true;
			}
			break;
		case 'telefoon':
			if( isTelefoon(veld.value) == false ){
				veld.focus();
				veld.select();
				alert('De invoer is geen geldig telefoonnummer / faxnummer!');
				return false;
			} else {
				return true;
			}
			break;
		case 'email':
			if(isEmail(veld.value) == false){
				veld.focus();
				veld.select();
				alert('De invoer is geen geldig emailadres!');
				return false;
			} else {
				return true;
			}
			break;
		case 'postcode':
			if(isPostcode(veld.value) == false){
				veld.focus();
				veld.select();
				alert('De invoer is geen geldige postcode');
				return false;
			} else {
				return true;
			}
			break;
		case 'hoofdletters':
			veld.value = veld.value.toUpperCase();
			return true;
			break;
		case 'kleineletters':
			veld.value = veld.value.toLowerCase();
			return true;
			break;
	}
}

function isEmail( email ) {
	var at="@"
	var dot="."
	var lat=email.indexOf(at)
	var lemail=email.length
	var ldot=email.indexOf(dot)

	if( email.indexOf( at ) == -1 )	{
	    return false;
	}

	if( email.indexOf( at ) == -1 || email.indexOf( at ) == 0 || email.indexOf( at ) == lemail ) {
		return false;
	}

	if( email.indexOf( dot ) == -1 || email.indexOf( dot ) == 0 || email.indexOf( dot ) == lemail )	{
		return false;
	}

	if( email.indexOf( at, ( lat + 1 ) ) != -1 ) {
		return false;
	}

 	if( email.substring( lat - 1, lat ) == dot || email.substring( lat + 1, lat + 2 ) == dot ) {
	    return false;
	}

	if( email.indexOf( dot, ( lat + 2 ) ) == -1 ) {
	   	return false;
	}

 	if( email.indexOf( " " ) != -1 ) {
 	  	return false;
 	}

 	return true;
}

function isPostcode( postcode ) {
	postcode = postcode.replace(" ", "");
	
	if( postcode != '' && postcode.length == 6 ) {
		valid = "01234567890";
		if( valid.indexOf( postcode.charAt( 0 ) ) == -1 ||  valid.indexOf( postcode.charAt( 1 ) ) == -1 || valid.indexOf( postcode.charAt( 2 ) ) == -1 || valid.indexOf( postcode.charAt( 3 ) ) == -1 ) {
			return false;
		}

		valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
		if( valid.indexOf( postcode.charAt( 4 ) ) == -1 ||  valid.indexOf( postcode.charAt( 5 ) ) == -1 ) {
			return false;
		}
	
		return true;
	}
	
	return false;
}

function isTelefoon( telefoon ){
	if( telefoon.length == 10 || telefoon.length == 12 ){
		var plus = telefoon.charAt(0);
		var cijfers = telefoon.substring(1, telefoon.length);

		if(isNaN(plus) == false) {
			// Gewoon telefoonnummer....
			if( isNaN(cijfers) == true || telefoon.length != 10 ) {
				return false;
			} else {
				return true;
			}
		} else {
			// Buitenlands nummer
			if( plus != "+" || isNaN(cijfers) == true || telefoon.length != 12 ){
				return false;
			} else {
				return true;
			}
		}
	}
	
	return false;
}

function round( value, decimal ) {
	var f = Math.pow(10, decimal);
	value = Math.round(value * f) / f;
	value += Math.pow(10, - (decimal + 1));
	value += '';
	return decimal == 0 ? value.substring(0, value.indexOf('.')) :
	value.substring(0, value.indexOf('.') + decimal + 1);
}