var Contact = Class.create();

Contact.prototype = {
   initialize: function() {
      this.email_match = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/
      this.is_error = 0
   },
   
   /* -------------------------------------------------------------------------- */
   check: function() {
   // #ff9999
      if (! form_fields) {
         alert("sorry no form fields initialized, we are going to quit")
         return false
      } else {
         this.is_error = 0
      }

      for ( var i=0; i<form_fields.length; i++ ) {
         if ( !$(form_fields[i][0]) ) {
            alert("Veld: " + form_fields[i][0] + " bestaat niet!")
            return false
         }
         if (  ( $(form_fields[i][1]) == 1 ) && ( $F(form_fields[i][0]) == '' ) ) {
            this.blink_field(form_fields[i][0]);
            this.is_error = 1;
         } else {
            $(form_fields[i][0]).style.backgroundColor = 'white';
         }
      }

      if ( this.is_error == 1 ) {
         this.init_error_message()
         return false;
      } else {
         return true;
      }
   },
   /* -------------------------------------------------------------------------- */


   /* -------------------------------------------------------------------------- */
   blink_field: function(field) {
      if ( !$(field) ) {
         alert(field + " does not exist, please update your code.")
         return
      }
      $(field).style.backgroundColor = '#7E0000';
      $(field).onclick = function() { this.style.backgroundColor = '' };
      new Effect.Appear(field);
   },
   /* -------------------------------------------------------------------------- */

   /* -------------------------------------------------------------------------- */
   init_error_message: function() {
      var message = 'Onderstaande formulier bevat fouten, controleer het formulier en probeer het opnieuw!';
      $('contact_error_msg').innerHTML = message;
      new Effect.Appear('contact_error_container');
      emergo.scrollTo('contact_error_container');
   }
   /* -------------------------------------------------------------------------- */
   
}
function initContact() { contact = new Contact(); }