// Check Input of a form
function check_input(formname, fields, formats, aliases, errormessage) {

  reg_email =  /^([_a-zA-Z0-9-]+)(\.[_a-zA-Z0-9-]+)*@([a-zA-Z0-9-]+\.)+([a-zA-Z]{2,4})$/;
  not_matched = "";
  not_matched_first = "";
	
  for (i=0; i<fields.length; i++) {
  
  
    value  = document.forms[formname].elements[fields[i]].value;
    format = formats[i];
	  field  = fields[i];
	  alias  = aliases[i];
    match  = true;
  
    if (format == "datum") {
	
	  match = match && (!isNaN(value.charAt(0)) && !isNaN(value.charAt(1)) && !isNaN(value.charAt(3)) && !isNaN(value.charAt(4)) && !isNaN(value.charAt(6)) && !isNaN(value.charAt(7)) && !isNaN(value.charAt(8)) && !isNaN(value.charAt(9)) && (value.charAt(2)==".") && (value.charAt(5)==".") && (value.length == 10));
	}
	
	if (format == "text") {
	
	  match = match && (value.length > 0);
	}
	
	if (format == "zahl") {
	
	  match = match && (!isNaN(value) && (value.length > 0));
	}
    
    if (format == "email") {
    
      atpos  = value.indexOf("@");
      dotpos = value.lastIndexOf(".");
      match  = match && (atpos > 0) && (dotpos > 0) && (dotpos > atpos) && (dotpos < (value.length-2)) && ((atpos+3) < dotpos);
			match  = match && reg_email.test(value);
    }
	
	if (!match) {
	
	  not_matched = not_matched + "- " + alias + "\n";
		
		if (not_matched_first == "") {
		
		  not_matched_first = field;
		}
	}
  } 
  
  if (not_matched.length > 0) {
     
	   alert(errormessage + not_matched);
		 document.forms[formname].elements[not_matched_first].focus();
     return false;
  } else { 
  
    return true;
  }
}
