function chkR( str, from, to ) {
	if ( str < from ) return false;
	if ( str > to ) return false;
	return true;
    }
    function isAlphaNum(s) {
        return chkR(s,"a","z") || chkR(s,"A","Z") || chkR(s,"0","9");
    }
    function isWord(s) {
        var i;
	if ( s.length == 0 ) {
	    return false;
	}
	for ( i=0; i<s.length; i++) {
	    var c = s.charAt(i);
	    if ( ! isAlphaNum(c) ) {
	        if ( i == 0 ) return false;
		if ( i == s.length - 1 ) return false;
	        if ( c != "-" ) 
	            return false;
	    }
	}
  return true;
}

function isWordOrDot(s) {
  var i;
	if ( s.length == 0 ) {
	    return false;
	}
	for ( i=0; i<s.length; i++) {
	    var c = s.charAt(i);
	    if ( ! isAlphaNum(c) ) {
	        if ( i == 0 ) return false;
		if ( i == s.length - 1 ) return false;
	        if ( (c != "-") && (c != ".") ) 
	            return false;
	    }
	}
  return true;
}



function check_mail(mail) {
  var idx = mail.indexOf( "@" );
  if ( idx == -1 || idx == 0 || idx == mail.length - 1) {
      return 0;
  } else {
      var user = mail.substring(0, idx);
      var host = mail.substring(idx + 1, mail.length);
      //
      // test mail
      //if ( ! isWordOrDot( user ) ) return false;
      //
      // test host
      var tok = host.split(".");
      for ( idx = 0; idx < tok.length; idx++ ) {
          if ( ! isWord( tok[ idx ] ) ) return false;
      }
      return true;
  }
}

function checkForm () {
  var ok = true;
  var msg = "Bitte füllen Sie noch folgende Felder aus:\n";
  if (document.kontaktform.name.value == "" || document.kontaktform.name.value == "Name*") 
  {
	    msg = msg + "- Name\n";
	    var ok = false;
	} 
  if (document.kontaktform.email.value == "" || document.kontaktform.email.value == "E-Mail*") 
  {
	    msg = msg + "- E-Mail\n";
	    var ok = false;
	} 
  if (document.kontaktform.nachricht.value == "" || document.kontaktform.nachricht.value == "Ihre Nachricht*") 
  {
	    msg = msg + "- Ihre Nachricht\n";
	    var ok = false;
	} 
  if ( document.kontaktform.email.value == "user@provider.suffix"	|| ! check_mail( new String(document.kontaktform.email.value) ) )
  {
	    msg = msg + "\nIhre E-Mail ist falsch eingegeben\n";
	    var ok = false;
	} 
  if ( ok == false ){
    alert(msg);
    return false;
  } 
  else{
  	return true;
  }
}
function checkNewsletterForm () {
  var ok = true;
  var msg = "Bitte füllen Sie noch folgende Felder aus:\n";
  if (document.newsletterform.email.value == "" || document.newsletterform.email.value == "E-Mail*") 
  {
	    msg = msg + "- E-Mail\n";
	    var ok = false;
	} 
  if ( document.newsletterform.email.value == "user@provider.suffix"	|| ! check_mail( new String(document.newsletterform.email.value) ) )
  {
	    msg = msg + "\nIhre E-Mail ist falsch eingegeben\n";
	    var ok = false;
	} 
  if ( ok == false ){
    alert(msg);
    return false;
  } 
  else{
  	return true;
  }
}

function checkGBForm () {
  var ok = true;
  var msg = "Bitte füllen Sie noch folgende Felder aus:\n";
  if (document.gbform.name.value == "") 
  {
	    msg = msg + "- Name\n";
	    var ok = false;
	} 
  if (document.gbform.email.value == "") 
  {
	    msg = msg + "- E-Mail\n";
	    var ok = false;
	} 
  if (document.gbform.nachricht.value == "") 
  {
	    msg = msg + "- Eintrag\n";
	    var ok = false;
	} 
  if ( document.gbform.email.value == "user@provider.suffix"	|| ! check_mail( new String(document.gbform.email.value) ) )
  {
	    msg = msg + "\nIhre E-Mail ist falsch eingegeben\n";
	    var ok = false;
	} 
  if ( ok == false ){
    alert(msg);
    return false;
  } 
  else{
  	return true;
  }
}

