var errors='';

function isFilledOut( field, label ) {
   var entry = field.value.replace( /\s/g, '' );
   if( !entry ) {
      errors += "-> "+ label + " fehlt.\n";
      return false;
   } 
   else
      return true; 
}

function isEmail( str )  {

  var atPos = str.indexOf('@' );
    
  if( (atPos > 0) && (atPos < str.length-1) && (atPos == str.lastIndexOf('@')) ) {
     // contains exact one @ which is neither the first nor the last character.   
     atPos = str.indexOf('.' );
     if( (atPos >0 ) && (atPos < str.length -1) ) {
	 return true;
     }
  }
  return false;
}


function validateAnmeldung(form) {

   errors = '';  // Set back error variable  

   var test = true;
  
   isFilledOut(form.Name,  "Name");
   
   if( form.emailAdresse.value ) {
      if(!isEmail(form.emailAdresse.value) ) 
          errors += "-> Die eMail Adresse ist fehlerhaft.\n";
   }
   else 
   {
       errors += "-> Die eMail Adresse muss angegeben werden.\n";
   }

   
   

  if (errors) alert('Das Formular ist unvollstaendig:\n'+
                    errors + 
     '\nBitte korrigieren Sie das und schicken es dann erneut ab.!');

  return !errors;
}
