// JavaScript Document
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 testsubmit () {
    //alert(document.kontaktformular.usertext.value.length);
if (document.kontaktformular.name.value == "") 
         {
	    alert( "Bitte geben Sie Ihren Namen ein!" );
	    return false;
	} 

if (document.kontaktformular.mail.value == "") 
         {
	    alert( "Bitte geben Sie Ihre eMail-Adresse ein!" );
	    return false;
	} 
        if ( document.kontaktformular.mail.value == "user@provider.suffix"
	|| ! check_mail( new String(document.kontaktformular.mail.value) ) )
 {
	    alert("Die eMail-Adresse ist falsch eingegeben!" );
	    return false;
	} 
if (document.kontaktformular.text.value == "") 
         {
	    alert( "Das Nachrichtenfeld darf nicht leer bleiben!" );
	    return false;
	} 


	return true;

    }
