/* -----------------------------------------------------------------
   -- Script-Magic (C) phpTrix SoftLabs / Dipl.Inf.(FH) S. Einsle --
   ----------------------------------------------------------------- */

   var checks = [
        'vorname',  /(...+)/g, 'Please state your first name!',
        'nachname', /(...+)/g, 'Please state your last name!',
        'telefon', /(0|\+)+[\d\s\-\(\)]{5,}/g, 'Please correct your phone number!',
        'email' , /(\w\w+@\w\w\w+\.\w\w+)/g, 'Please state your E-Mail adress!',
        'betreff', /(.....+)/g, 'Please state a message subject!',
        'anfrage', /(.....+)/g, 'Please state your request!',
   ];

   function checkfield( f, name, reg ) {
        var e = f.elements[name];
        if ( !e ) return;
        if ( e.value.length>2 && e.value.match(reg) ) {
           e.style.backgroundColor="";
           return(true);
        }
        e.style.backgroundColor="#ffdddd";
        return(false);
   }

   function checkform( f ) {

        var err = [];

        for( var i=0; i+3<=checks.length; i+=3 )
           if ( !checkfield(f,checks[i],checks[i+1]) )
              err[err.length] = checks[i+2];

        if ( err.length ) {
            var f = document.getElementById("fehler");
            f.className="error";
            f.innerHTML = "<h1>Please correct the following errors:</h1>"+
                          "<ul><li>"+err.join("\n<li>")+"</ul><br>\n";
            window.scrollTo(0,150);
            return(false);
        }

        f.action = "/co/mail_send.php";
        return(true);
   }


