var rules = {
	"#cbfa": function(el) {
		el.onkeyup = function( e ) {
			//if ( this.value.length == 5 && !isNaN( this.value ) ) {
			if ( !isNaN( this.value ) ) {
				Effect.Fade( "badcbfa" );
				allowSubmit(this);
			}
			else {
				Effect.Appear( "badcbfa" );
				noSubmit(this);
			}
			
		}
	},
	
	"#email_niet": function(el) {
		el.onkeyup = function( e ) {
			var email = this.value;
			if ( email.indexOf( "@" ) > 0 && email.lastIndexOf( "." ) > email.indexOf( "@" ) ) {
				Effect.Fade( "bademail" );
				allowSubmit(this);
			}
			else {
				Effect.Appear( "bademail" );
				noSubmit(this);
			}
			
		}
	},

	"#submitter": function(el) {
		el.onclick = function( e ) {
			if ( !checkForm( this.form ) ) {
				Effect.Appear( "badform" );
				return false;
			}
		}
	}
};

Behaviour.register( rules );

function checkForm(form) {
	if ( form.naam.value.length == 0 ) return false;
	if ( form.voornaam.value.length == 0 ) return false;
	if ( form.kantoor.value.length == 0 ) return false;
	if ( form.straat.value.length == 0 ) return false;
	if ( form.nummer.value.length == 0 ) return false;
	if ( form.postcode.value.length == 0 ) return false;
	if ( form.gemeente.value.length == 0 ) return false;
	if ( form.tel.value.length == 0 ) return false;
	//if ( form.fax.value.length == 0 ) return false;
	if ( form.email.value.length == 0 ) return false;
	//if ( form.cbfa.value.length == 0 ) return false;
	
	return true;
}

function allowSubmit(at) {
	at.form.onsubmit = null;
}

function noSubmit(at) {
	at.form.onsubmit = function() { return false; }
}
