// Script f&uuml;r die Clientseitige Formularpr&uuml;fung
/* Pflichtfelder anmelden (JavaScript) :

    arrChk = new Array("feldname1,pr&uuml;ftyp,Bezeichnung,minlength",
                       "feldname2,pr&uuml;ftyp,Bezeichnung,minlength",
                       "feldname3,pr&uuml;ftyp,Bezeichnung,minlength")

    Aufruf der Formvalidierung geschieht clientseitig
    im Form-Tag : <form ... onSubmit="return checkForm(this)">
    oder in einer "send()" Funktion: checkForm(document.formularname)

    die Funktion "checkForm" hat die R&uuml;ckgabewerte true/false

  pr&uuml;ftypen :
   Pflichtfelder( Eingabe + Format zwingend )
    1  - text
    2  - number
    3  - email
    50 - datum
    51 - zeit
    52 - preis
    53 - Kommazahl
    54 - Punktzahl
    55 - keine sonderzeichen


   Kein Pflichtfeld( Format zwingend )
    4 - number
    5 - email
    6 - datum
    7 - zeit
    8 - preis
    9 - Kommazahl
    10 - Punktzahl
    11 - keine sonderzeichen

*/




function checkForm( objForm ){
  arrMSG = new Array(" muß ausgefüllt werden!",                           // Pflichtfeld
                     " muß ein numerischen Wert enthalten!",             // Nummer
                     " hat ein ungültiges Format! Gültiges Format: test@hotmail.de", // Mail-syntax
                     " hat ein falsches Format ! Richtig: 12.03.2001 ",  // Datums-Syntax
                     " hat ein falsches Format ! Richtig: 16:55 ",       // Zeit-syntax
                     " hat ein falsches Format ! Richtig: 12,99 ",       // Preis mit max 2 stellen (komma)
                     " hat ein falsches Format ! Richtig: 12345,9973 ",  // Kommazahl
                     " hat ein falsches Format ! Richtig: 12345.9973 ",  // Punktzahl
                     " darf keine Sonderzeichen enthalten!" ) // Sonderzeichen

  // ist ein checkarray vorhanden?
  if (arrChk){
    for (f=0;f<arrChk.length;f++){
      tmp = arrChk[f].split(",");
      Ename = tmp[0];
      Etype = tmp[1];
      Edesc = tmp[2];
      Elength = tmp[3];
      objE = eval("objForm."+Ename);
      // auf leer pr&uuml;fen
      if( Etype == "1" || Etype == "2" || Etype == "3" || Etype == "51" || Etype == "50" || Etype == "52" || Etype == "53" || Etype == "54" || Etype == "55"){
        if (objE.value == ''){
          objE.select();
          objE.focus();
          alert("Ungültige Eingabe, "+Edesc + arrMSG[0])
//          aBox("Ung&uuml;ltiges Eingabe",Edesc + arrMSG[0]);
          return false;
        }
        if(Elength > 0 && objE.value.length < Elength){
          objE.select();
          objE.focus();
          aBox("Ung&uuml;ltiges Eingabe",Edesc + " muss mindestens "+Elength+" Zeichen lang sein!");
          return false;
        }
      }
      // auf numeric pr&uuml;fen ( 12 oder 13.456 )
      if( Etype == "2" || Etype == "4"){
        if (isNaN(objE.value) && objE.value != ""){
          objE.select();
          objE.focus();
          alert("Ungültige Eingabe, "+Edesc + arrMSG[1])

//          aBox("Ung&uuml;ltiges Eingabe",Edesc + arrMSG[1]);
          return false;
        }
      }
      // auf mailsyntax pr&uuml;fen ( name.sonstwas@domain.de )
      if( Etype == "3" || Etype == "5" ){
        if (objE.value.replace(/[\w\._-]+@[\w\.-]+[\w\.-]+\.[\w]+[\w]+/, '') != '' && objE.value != ""){
          objE.select();
          objE.focus();
          alert("Ungültige Eingabe, "+Edesc + arrMSG[2])
//          aBox("Ung&uuml;ltiges Eingabe",Edesc + arrMSG[2]);
          return false;
        }
      }
      // Auf g&uuml;ltiges Datumsformat pr&uuml;fen ( 12.03.2001 )
      if( Etype == "6" || Etype == "50"){
        if (objE.value.replace(/[0-3][0-9][.][0-1][0-9][.][1-2][0-9][0-9][0-9]/, '') != ''){
          objE.select();
          objE.focus();
          alert("Ungültige Eingabe, "+Edesc + arrMSG[3])
//          aBox("Ung&uuml;ltiges Eingabe",Edesc + arrMSG[3]);
          return false;
        }
      }

      // auf g&uuml;ltige Zeitangabe pr&uuml;fen ( 16:55  )
      if( Etype == "7" || Etype == "51"){
        if (objE.value.replace(/(([01][0-9])|([2][0-3])|([01][0-9])|([0-9]))([:][0-5][0-9])/, '') != ''){
          objE.select();
          objE.focus();
          alert("Ung&uuml;ltiges Eingabe",Edesc + arrMSG[4])
//          aBox("Ung&uuml;ltiges Eingabe",Edesc + arrMSG[4]);
          return false;
        }
      }

      // auf g&uuml;ltige Preisangabe pr&uuml;fen ( 12,99 )
      if( Etype == "8" || Etype == "52"){
        if (objE.value.replace(/([0-9]*[,][0-9][0-9])|([0-9]*)/, '') != ''){
          objE.select();
          objE.focus();
          alert("Ungültige Eingabe, "+Edesc + arrMSG[5])
//          aBox("Ung&uuml;ltiges Eingabe",Edesc + arrMSG[5]);
          return false;
        }
      }

      // auf eine g&uuml;ltige n-stellige Kommazahl pr&uuml;fen ( 1234,56789 )
      if( Etype == "9" || Etype == "53"){
        if (objE.value.replace(/([0-9]*[,][0-9]*)|([0-9]*)/, '') != ''){
          objE.select();
          objE.focus();
          alert("Ungültige Eingabe, "+Edesc + arrMSG[6])
//          aBox("Ung&uuml;ltiges Eingabe",Edesc + arrMSG[6]);
          return false;
        }
      }

      // auf eine g&uuml;ltige n-stellige Kommazahl pr&uuml;fen ( 1234,56789 )
      if( Etype == "10" || Etype == "54"){
        if (objE.value.replace(/([\-]|[0-9])([0-9]*[\.][0-9]*)|(([\-]|[0-9])([0-9]*))/, '') != ''){
          objE.select();
          objE.focus();
          alert("Ungültige Eingabe, "+Edesc + arrMSG[7])
//          aBox("Ung&uuml;ltiges Eingabe",Edesc + arrMSG[7],objE);
          return false;
        }
      }

      // auf sonderzeiche pr&uuml;fen
      if( Etype == "11" || Etype == "55"){
        if (objE.value.replace(/([a-zA-Z]*)/, '') != ''){
          objE.select();
          objE.focus();
          alert("Ungültige Eingabe, "+Edesc + arrMSG[8])
//          aBox("Ung&uuml;ltiges Eingabe",Edesc + arrMSG[8]);
          return false;
        }
      }

    }
  }
  return true;
}




