// JavaScript Document

var background  = null;

formService.check = function(f) {


    if (background != null)
    for (var n = 0; n < f.elements.length; n++) {
        var input = f[n];
        if (input.className != 'button') input.style.background = background;
    }

    var ok = true;
    var komunikat = '';
    var eNumber = 0;
    var eElement = null;

    if (formService.isEmpty(f.imie.value)) {
        eNumber++;
        komunikat += eNumber + '. Wprowadź imię.\n';
        background  = f.imie.style.background;
        f.imie.style.background = "#FFDDDD";
        if (!eElement) eElement = f.imie;
        ok = false;
//        return ok = false;
    }

    if (formService.isEmpty(f.nazwisko.value)) {
        eNumber++;
        komunikat += eNumber + '. Wprowadź nazwisko.\n';
        background  = f.nazwisko.style.background;
        f.nazwisko.style.background = "#FFDDDD";
        if (!eElement) eElement = f.nazwisko;
        ok = false;
//        return ok = false;
    }

    if (formService.isEmpty(f.email.value)) {
        eNumber++;
        komunikat += eNumber + '. Koniecznie ustaw adres e-mail.\n';
        background  = f.email.style.background;
        f.email.style.background = "#FFDDDD";
        if (!eElement) eElement = f.email;
        ok = false;
//        return ok = false;
    } else

    if (!formService.check_email(f.email.value)) {
        eNumber++;
        komunikat += eNumber + '. Proszę wprowadzić  poprawny adres e-mail.\n';
        background  = f.email.style.background;
        f.email.style.background = "#FFDDDD";
        if (!eElement) eElement = f.email;
        ok = false;
//        return ok = false;
    }


    if (formService.isEmpty(f.telefon.value)) {
        eNumber++;
        komunikat += eNumber + '. Prosimy o wprowadzenie numeru telefonu.\n';
        background  = f.telefon.style.background;
        f.telefon.style.background = "#FFDDDD";
        if (!eElement) eElement = f.telefon;
        ok = false;
//        return ok = false;
    }


    if (!ok) {
//        eElement.style.background = "#FFDDDD";
        eElement.focus();
        eElement.select();

        komunikat = 'Czerwonym kolorem zaznaczono niepoprawne wpisy:\n' +
            komunikat ;

        alert(komunikat);
    }

    return ok;
}


