// ********************************************
function checkalphaspace(which, alerttext)
//funkcja zwraca false jesli which nie jest ciagnie liter i/lub spacji
{
    var testresult=true;
    var x=which.value
    var i;

    if (x.length==0) testresult=false;
    for (i = 0; i < x.length; i++)
    {
        // Check that current character is number or letter.
        var c = x.charAt(i);

        if (! (isLetter(c) || isSpace(c)))
            testresult=false;
    }

    if (!testresult) //jesli cos nie tak wyswietlamy stosowny komunikat
    {
        if (alerttext.length!=0) alert(alerttext)
            which.focus();
    }
    return (testresult)
}

// ********************************************
function checkulica(which, alerttext)
//funkcja zwraca false jesli which nie jest ciagnie liter i/lub spacji
{
    var testresult=true;
    var x=which.value
    var i;

    //if (x.length==0) testresult=false;

    for (i = 0; i < x.length; i++)
    {
        // Check that current character is number or letter.
        var c = x.charAt(i);

        if (! (isLetter(c) || isSpace(c) || isPlLetter(c) || isDigit(c) || (c == ".") || (c == ",") || (c == "\"") || (c == "\'") || (c == "/") || (c == "-") || (c == ":") || (c == "&")))
            testresult=false;
    }

    if (!testresult) //jesli cos nie tak wyswietlamy stosowny komunikat
    {
        if (alerttext.length!=0) alert(alerttext)
            which.focus();
            //which.value="";
    }
    return (testresult)
}

// ********************************************
function checkimienazwisko(which, alerttext)
//funkcja zwraca false jesli which nie jest ciagnie liter i/lub spacji
{
    var testresult=true;
    var x=which.value
    var i;

    //if (x.length==0) testresult=false;

    for (i = 0; i < x.length; i++)
    {
        // Check that current character is number or letter.
        var c = x.charAt(i);

        if (! (isLetter(c) || isSpace(c) || isPlLetter(c) || (c == "-")))
            testresult=false;
    }


    if (!testresult) //jesli cos nie tak wyswietlamy stosowny komunikat
    {
        if (alerttext.length!=0) alert(alerttext)
            which.focus();
            //which.value="";
    }
    return (testresult)
}

// ********************************************
function checkwww(which, alerttext)
//funkcja zwraca false jesli which nie jest ciagnie liter i/lub spacji
{
    var testresult=true;
    var x=which.value
    var filter=/^((?:\w+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;

    if(x.length==0) return true;

    if (filter.test(x)) //sprawdzanie czy podano poprawny email
        testresult=true
    else
        testresult=false

    if (!testresult) //jesli cos nie tak wyswietlamy stosowny komunikat
    {
        if (alerttext.length!=0) alert(alerttext)
        which.focus();
        //which.value="";
    }
    return (testresult)
}

// ********************************************
function checkemail(which, alerttext)
//funkcja zwraca false jesli which nie jest ciagnie liter i/lub spacji
{
    var testresult=true;
    var x=which.value
    var filter=/^(\w+(?:\.\w+)*)@((?:\w+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;

    if(x.length==0) return true;

    if (filter.test(x)) //sprawdzanie czy podano poprawny email
        testresult=true
    else
        testresult=false

    if (!testresult) //jesli cos nie tak wyswietlamy stosowny komunikat
    {
        if (alerttext.length!=0) alert(alerttext)
        which.focus();
        //which.value="";
    }
    return (testresult)
}

// ********************************************
function checknum(which, alerttext)
//funkcja zwraca false jesli which nie jest zestawem samych cyfr
{
    var testresult=true;
    var x=which.value
    var anum=/(^\d+$)/

    if(x.length==0)     return true;

    if (anum.test(x)) //sprawdzanie czy podano same cyfry
        testresult=true
    else
        testresult=false

    if (!testresult) //jesli cos nie tak wyswietlamy stosowny komunikat
    {
        if (alerttext.length!=0) alert(alerttext)
        which.focus();
        //which.value="";
    }
    return (testresult)
}

function checklogin(which, alerttext)
//funkcja zwraca false jesli which nie jest ciagiem  liter lub cyfr
{
    var testresult=true;
    var x=which.value
    var i;

    if (x.length < 4) testresult=false;

    for (i = 0; i < x.length; i++)
    {
        // Check that current character is number or letter.
        var c = x.charAt(i);

        if (! (isLetter(c) || isDigit(c)))
           testresult=false;
    }

    if (!testresult) //jesli cos nie tak wyswietlamy stosowny komunikat
    {
        if (alerttext.length!=0) alert(alerttext)
            which.focus();
            //which.value="";
    }
    return (testresult)
}

function checkhaslo(which, alerttext)
//funkcja zwraca false jesli which nie jest ciagiem  liter lub cyfr, nie krotsze niz 6 znakow
{
    var testresult=true;
    var x=which.value
    var i;

    if (x.length < 6) testresult=false;

    for (i = 0; i < x.length; i++)
    {
        // Check that current character is number or letter.
        var c = x.charAt(i);

        if (! (isLetter(c) || isDigit(c)))
           testresult=false;
    }

    if (!testresult) //jesli cos nie tak wyswietlamy stosowny komunikat
    {
        if (alerttext.length!=0) alert(alerttext)
            which.focus();
            //which.value="";
    }
    return (testresult)
}

// ********************************************
function checkpelnanazwa(which, alerttext)
//funkcja zwraca false jesli which nie jest ciagnie liter i/lub spacji
{
    var testresult=true;
    var x=which.value
    var i;

    //if (x.length==0) testresult=false;

    for (i = 0; i < x.length; i++)
    {
        // Check that current character is number or letter.
        var c = x.charAt(i);

        if (! (isLetter(c) || isSpace(c) || isPlLetter(c) || isDigit(c) || (c == ".") || (c == ",") || (c == "\"") || (c == "\\") || (c == "\'") || (c == "-") || (c == "&") || (c == ":")))
           testresult=false;
    }

    if (!testresult) //jesli cos nie tak wyswietlamy stosowny komunikat
    {
        if (alerttext.length!=0) alert(alerttext)
            which.focus();
            //which.value="";
    }
    return (testresult)
}

// ********************************************
function checkalphaspace_pliterki(which, alerttext)
//funkcja zwraca false jesli which nie jest ciagnie liter (z polskimi znakami) i/lub spacji
{
    var testresult=true;
    var x=which.value
    var i;

    if (x.length==0) testresult=false;

    for (i = 0; i < x.length; i++)
    {
        // Check that current character is number or letter.
        var c = x.charAt(i);

        if (! (isLetter(c) || isSpace(c) || isPlLetter(c)))
            testresult=false;
    }

    if (!testresult) //jesli cos nie tak wyswietlamy stosowny komunikat
    {
        if (alerttext.length!=0) alert(alerttext)
            which.focus();
    }
    return (testresult)
}

// ********************************************
function check_miejsc(which, alerttext)
//funkcja zwraca false jesli which nie jest ciagiem liter (z polskimi znakami) i/lub spacji .
{
    var testresult=true;
    var x=which.value
    var i;

    if (x.length==0) testresult=false;

    for (i = 0; i < x.length; i++)
    {
        // Check that current character is number or letter.
        var c = x.charAt(i);

        if (! (isLetter(c) || isSpace(c) || isPlLetter(c) || isDigit(c) || (c == ".") || (c == ",") || (c == "\"") || (c == "\'") || (c == "/") || (c == "-") || (c == ":") || (c == "&")))
            testresult=false;
    }

    if (!testresult) //jesli cos nie tak wyswietlamy stosowny komunikat
    {
        if (alerttext.length!=0) alert(alerttext)
            which.focus();
    }
    return (testresult)
}

// ********************************************
function checkalphanumspace(which, alerttext)
//funkcja zwraca false jesli which nie jest ciagnie znakow alfanumerycznych i/lub spacji
{
    var testresult=true;
    var x=which.value
    var i;

    if (x.length==0) testresult=false;

    for (i = 0; i < x.length; i++)
    {
        // Check that current character is number or letter.
        var c = x.charAt(i);

        if (! (isLetter(c) || isDigit(c) || isSpace(c)))
            testresult=false;
    }

    if (!testresult) //jesli cos nie tak wyswietlamy stosowny komunikat
    {
        if (alerttext.length!=0) alert(alerttext)
            which.focus();
    }
    return (testresult)
}

// ********************************************
function checktelefon(which, alerttext)
//funkcja zwraca false jesli which nie jest ciagnie znakow numerycznych i/lub spacji
{
    var testresult=true;
    var x=which.value

    if (x.length==0) return true;

    var filter1=/(^((\+\d{2,4}\.\d{2}\.)?|(\d{2}\.))\d{6,7}(\.\d+)?$)/;          //+48.42.6543211.56 - [+kraj.][kierunek.]wlasciwy[.wewnetrzny]
    var filter2=/(^(\+\d{2,4}\.)?\d{9}$)/                                       //+48.987654321 - [+kraj.]wlasciwykomorkowy

    if (! (filter1.test(x) || filter2.test(x)) )
            testresult=false;


    if (!testresult) //jesli cos nie tak wyswietlamy stosowny komunikat
    {
        if (alerttext.length!=0) alert(alerttext)
            which.focus();
            //which.value="";
    }
    return (testresult)
}

// ********************************************
function checktelkom(which, alerttext)
//funkcja zwraca false jesli which nie jest ciagnie znakow numerycznych i/lub spacji
{
    var testresult=true;
    var x=which.value

    if (x.length==0) return true;

    var filter=/(^\d{9}$)/;                                       //987654321

    if (! filter.test(x) )
            testresult=false;

    if (!testresult) //jesli cos nie tak wyswietlamy stosowny komunikat
    {
        if (alerttext.length!=0) alert(alerttext)
            which.focus();
            //which.value="";
    }
    return (testresult)
}

// ********************************************
function checkdate(which, alerttext)
//funkcja zwraca false jesli which nie jest porawna data rrrr-mm-dd
{
    var testresult=true;
    var x=which.value
    var anum=/(^\d\d\d\d-\d\d-\d\d$)/

    if(x.length == 0)   return testresult;

    var year=which.value.substring(0,4);
    var month=which.value.substring(5,7);
    var day=which.value.substring(8,10);

    if (anum.test(x)) //sprawdzanie czy podano date w formacie rrrr-mm-dd
        testresult=true
    else
        testresult=false

    if ((year<1900) | (month<1 | month>12) | (day<1 | day>31)) //sprawdzamy logiczna poprawnosc danych
    {
//        alert(''+ year +'-' + month + '-'+day);
        testresult=false
    }

    if (!testresult) //jesli cos nie tak wyswietlamy stosowny komunikat
    {
        if (alerttext.length!=0) alert(alerttext)
        which.focus();
        //which.value="";
    }
    return (testresult)
}



// ********************************************

function checkdatetime(which, alerttext)
//funkcja zwraca false jesli which nie jest porawna data rrrr-mm-dd
{
    var testresult=true;
    var x=which.value
    var anum=/(^\d\d\d\d-\d\d-\d\d,\d\d:\d\d$)/

    var year=which.value.substring(0,4);
    var month=which.value.substring(5,7);
    var day=which.value.substring(8,10);
    var hour=which.value.substring(11,13);
    var min=which.value.substring(14,16);

    if (anum.test(x)) //sprawdzanie czy podano date w formacie rrrr-mm-dd
        testresult=true
    else
        testresult=false

    if ((year<1900) | (month<1 | month>12) | (day<1 | day>31) | (hour<0 | hour>24) | (min<0 | min>59)) //sprawdzamy logiczna poprawnosc danych
    {
//        alert(''+ year +'-' + month + '-'+day);
        testresult=false
    }

    if (!testresult) //jesli cos nie tak wyswietlamy stosowny komunikat
    {
        if (alerttext.length!=0) alert(alerttext)
        which.focus();
        //which.value="";
    }
    return (testresult)
}

// ********************************************

function checknumberint(which, alerttext)

{
    var testresult=true;
    var x=which.value
    var anum=/(^\d+$)/
    if (anum.test(x))
        testresult=true
    else
    {
        if (alerttext.length!=0) alert(alerttext)
        which.focus();

        testresult=false
    }
    return (testresult)
}

// ********************************************
function checknumberprocent(which, alerttext)
{
    var testresult=true;
    var x=which.value
    var anum=/(^\d+$)/
    if (anum.test(x) && x <= 100)
        testresult=true
    else
    {
        if (alerttext.length!=0) alert(alerttext)
        which.focus();

        testresult=false
    }
    return (testresult)
}

// ********************************************

function checknumbernatural(which, alerttext)
{
// troche nazwa przeklaman, bo tak narpawde sprawdza aby byla calkowita i nieujemna
    var testresult=true;
    var x=which.value
    var anum=/(^\d+$)/

    if (anum.test(x) && x >= 0)
        testresult=true
    else
    {
        if (alerttext.length!=0) alert(alerttext)
        which.focus();

        testresult=false
    }
    return (testresult)
}

// ********************************************
function checknumbernaturalorempty(which, alerttext)
{
    var testresult=true;
    var x=which.value
    var anum=/(^\d+$)/
    if ((anum.test(x) && x > 0) || (x.length == 0))
        testresult=true
    else
    {
        if (alerttext.length!=0) alert(alerttext)
        which.focus();

        testresult=false
    }
    return (testresult)
}

// ********************************************
function checknumberreal(which, alerttext)
{
    var testresult=true;
    var x=which.value

    var anum=/(^\d+$)|(^\d+\.\d+$)|(^\d+,\d+$)/
    if (anum.test(x))
        testresult=true
    else
    {
        if (alerttext.length!=0) alert(alerttext)
        which.focus();

        testresult=false
    }
    return (testresult)
}

// ********************************************
function checkpostcode(which, alerttext)
//funkcja zwraca false jesli which nie kodem pocztowym w postaci 00-000
{
    var testresult=true;
    var x=which.value
    var anum=/(^\d\d-\d\d\d$)/

    if (anum.test(x)) //sprawdzanie czy podano kod pocztowy xx-xxx
        testresult=true
    else
        testresult=false

    if (!testresult) //jesli cos nie tak wyswietlamy stosowny komunikat
    {
        if (alerttext.length!=0) alert(alerttext)
        which.focus();
        //which.value="";
    }
    return (testresult)
}

// ********************************************
function checknip(which, alerttext)
//funkcja zwraca false jesli which nie kodem pocztowym w postaci 00-000
{
    var testresult=true;
    var x=which.value
    var anum1=/(^\d\d\d-\d\d\d-\d\d-\d\d$)/
    var anum2=/(^\d\d\d-\d\d-\d\d-\d\d\d$)/

    if (anum1.test(x) || anum2.test(x)) //sprawdzanie czy podano nip xxx-xxx-xx-xx lub xxx-xx-xx-xxx
        testresult=true
    else if(x.length!=0)
        testresult=false

    if (!testresult) //jesli cos nie tak wyswietlamy stosowny komunikat
    {
        if (alerttext.length!=0) alert(alerttext)
        which.focus();
        //which.value="";
    }
    return (testresult)
}



// ********************************************

function checkregon(which, alerttext)
//funkcja zwraca false jesli which nie kodem pocztowym w postaci 00-000
{
    var testresult=true;
    var x=which.value
    var anum=/(^\d+$)/

    if (anum.test(x)) //sprawdzanie czy podano kod pocztowy xx-xxx
        testresult=true
    else if(x.length!=0)
        testresult=false

    if (!testresult) //jesli cos nie tak wyswietlamy stosowny komunikat
    {
        if (alerttext.length!=0) alert(alerttext)
        which.focus();
        //which.value="";
    }
    return (testresult)
}



// #########################################################################
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//                              ***********
//
// +++++++++++              SUBMIT FORMULARZY               ++++++++++++++++
//
//                              ***********
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function checkGrupa(form)
{
    var testresult=true;

//nazwa - puste pole
if ((testresult) && document.forms[form].nazwa.value.length==0)
    {
        alert('Podaj nazwę grupy.');
        document.forms['grupa'].nazwa.focus();
        testresult=false;
    }

//pozycja - puste pole

if ((testresult) && document.forms[form].pozycja.value.length==0)
    {
        alert('Podaj pozycję na jakiej ma się pojawić ta grupa.');
        document.forms['grupa'].pozycja.focus();
        testresult=false;
    }

if ((testresult) && !checknumbernatural(document.forms[form].pozycja,""))
    {
        alert('Pozycja powinna być podana jako liczba naturalna');
        testresult=false;
    }

    return testresult;

}

function checkPodGrupa(form)
{
    var testresult=true;

//nazwa - puste pole
if ((testresult) && document.forms[form].nazwa.value.length==0)
    {
        alert('Podaj nazwę grupy.');
        document.forms[form].nazwa.focus();
        testresult=false;
    }

//pozycja - puste pole

if ((testresult) && document.forms[form].pozycja.value.length==0)
    {
        alert('Podaj pozycję na jakiej ma się pojawić ta grupa.');
        document.forms[form].pozycja.focus();
        testresult=false;
    }

if ((testresult) && !checknumbernatural(document.forms[form].pozycja,""))
    {
        alert('Pozycja powinna być podana jako liczba naturalna');
        testresult=false;
    }

    return testresult;

}

function checkProdukt(form)
{
    var testresult=true;

//nazwa - puste pole
if ((testresult) && document.forms[form].nazwa.value.length==0)
    {
        alert('Podaj nazwę produktu.');
        document.forms[form].nazwa.focus();
        testresult=false;
    }

//symbol - puste pole
if ((testresult) && document.forms[form].symbol.value.length==0)
    {
        alert('Podaj Symbol produktu.');
        document.forms[form].symbol.focus();
        testresult=false;
    }

//kod EAN - puste pole
if ((testresult) && document.forms[form].symbol.value.length==0)
    {
        alert('Podaj kod EAN.');
        document.forms[form].ean.focus();
        testresult=false;
    }

//cena 1 - puste pole
if ((testresult) && document.forms[form].cena1.value.length==0)
    {
        alert('Podaj cenę I produktu.');
        document.forms[form].cena1.focus();
        testresult=false;
    }
if ((testresult) && !checknumberreal(document.forms[form].cena1,""))
    {
        alert('Cena powinna być podana w postaci liczby: np. 13.50');
        document.forms[form].cena1.focus();
        testresult=false;
    }

//cena 2 - puste pole
if ((testresult) && document.forms[form].cena2.value.length==0)
    {
        alert('Podaj cenę II produktu.');
        document.forms[form].cena2.focus();
        testresult=false;
    }
if ((testresult) && !checknumberreal(document.forms[form].cena2,""))
    {
        alert('Cena powinna być podana w postaci liczby: np. 13.50');
        document.forms[form].cena2.focus();
        testresult=false;
    }

//cena 3 - puste pole
if ((testresult) && document.forms[form].cena3.value.length==0)
    {
        alert('Podaj cenę III produktu.');
        document.forms[form].cena3.focus();
        testresult=false;
    }
if ((testresult) && !checknumberreal(document.forms[form].cena3,""))
    {
        alert('Cena powinna być podana w postaci liczby: np. 13.50');
        document.forms[form].cena3.focus();
        testresult=false;
    }

//cena EUR
if ((testresult) && !checknumberreal(document.forms[form].eur,""))
    {
        alert('Cena powinna być podana w postaci liczby: np. 13.50');
        document.forms[form].eur.focus();
        testresult=false;
    }

//ilosc jednostek - puste pole
if ((testresult) && document.forms[form].iloscjedn.value.length==0)
    {
        alert('Podaj ilość jednostek w paczce.');
        document.forms[form].iloscjedn.focus();
        testresult=false;
    }
if ((testresult) && !checknumberint(document.forms[form].iloscjedn,""))
    {
        alert('Ilość jednostek powinna być podana w postaci liczby naturalnej: np. 10');
        testresult=false;
    }
    return testresult;

}


function checkKlient(form)
{
    var testresult=true;

//kod klienta - puste pole
if ((testresult) && document.forms[form].kodklienta.value.length==0)
    {
        alert('Podaj Kod klienta.');
        document.forms[form].kodklienta.focus();
        testresult=false;
    }

//nazwa firmy - puste pole
if ((testresult) && document.forms[form].firma.value.length==0)
    {
        alert('Podaj Nazwę firmy.');
        document.forms[form].firma.focus();
        testresult=false;
    }

//NIP - puste pole
if ((testresult) && document.forms[form].nip.value.length==0)
    {
        alert('Podaj NIP klienta.');
        document.forms[form].nip.focus();
        testresult=false;
    }
if ((testresult) && !checknip(document.forms[form].nip,""))
    {
        alert('Postać wprowadzonego numeru NIP jest niepoprawna');
        document.forms[form].nip.focus();
        testresult=false;
    }

//imie i nazwisko
if ((testresult) && !checkimienazwisko(document.forms[form].osdokont,""))
    {
        alert('Postać wprowadzonej Osoby kontaktowej jest niepoprawna');
        document.forms[form].osdokont.focus();
        testresult=false;
    }

//Miejscowosc - puste pole
if ((testresult) && document.forms[form].miejsc.value.length==0)
    {
        alert('Podaj Miejscowość klienta.');
        document.forms[form].miejsc.focus();
        testresult=false;
    }
if ((testresult) && !check_miejsc(document.forms[form].miejsc,""))
    {
        alert('Postać wprowadzonej miejscowości jest niepoprawna');
        document.forms[form].miejsc.focus();
        testresult=false;
    }

//Kod pocztowy - puste pole
if ((testresult) && document.forms[form].kod.value.length==0)
    {
        alert('Podaj Kod pocztowy klienta.');
        document.forms[form].kod.focus();
        testresult=false;
    }
if ((testresult) && !checkpostcode(document.forms[form].kod,""))
    {
        alert('Postać wprowadzonego Kodu pocztowego jest niepoprawna');
        document.forms[form].kod.focus();
        testresult=false;
    }

//Ulica - puste pole
if ((testresult) && document.forms[form].ulica.value.length==0)
    {
        alert('Podaj Ulicę.');
        document.forms[form].ulica.focus();
        testresult=false;
    }
if ((testresult) && !checkulica(document.forms[form].kod,""))
    {
        alert('Postać wprowadzonej Ulicy jest niepoprawna');
        document.forms[form].ulica.focus();
        testresult=false;
    }

//Obszar - puste pole
if ((testresult) && document.forms[form].idobszar.value==0)
    {
        alert('Nie wybrałeś żadnego Obszaru dla klienta.');
        document.forms[form].idobszar.focus();
        testresult=false;
    }

//email
if ((testresult) && !checkemail(document.forms[form].email,""))
    {
        alert('Wprowadzony Email posiada niepoprawną postać');
        document.forms[form].email.focus();
        testresult=false;
    }

//www
if ((testresult) && !checkwww(document.forms[form].www,""))
    {
        alert('Wprowadzony adres WWW posiada niepoprawną postać');
        document.forms[form].www.focus();
        testresult=false;
    }

//login
if ((testresult) && !checklogin(document.forms[form].login,""))
    {
        alert('Login powinien składać się przynajmniej z 4 liter lub cyfr (bez spacji)');
        testresult=false;
    }

//haslo
if ((testresult) && !checkhaslo(document.forms[form].haslo,""))
    {
        alert('Hasło powinno składać się przynajmniej z 6 liter lub cyfr (bez spacji)');
        testresult=false;
    }

    return testresult;
}


function checkPracownik(form)
{
    var testresult=true;

//imie - puste pole
if ((testresult) && document.forms[form].imie.value.length==0)
    {
        alert('Podaj Imię pracownika.');
        document.forms[form].imie.focus();
        testresult=false;
    }

//nazwisko - puste pole
if ((testresult) && document.forms[form].nazwisko.value.length==0)
    {
        alert('Podaj Nazwisko pracownika.');
        document.forms[form].nazwisko.focus();
        testresult=false;
    }

//login - puste pole
if ((testresult) && document.forms[form].login.value.length==0)
    {
        alert('Podaj Login pracownika.');
        document.forms[form].login.focus();
        testresult=false;
    }
if ((testresult) && !checklogin(document.forms[form].login,""))
    {
        alert('Login powinien składać się przynajmniej z 4 liter lub cyfr (bez spacji)');
        testresult=false;
    }

//haslo - puste pole
if ((testresult) && document.forms[form].haslo.value.length==0)
    {
        alert('Podaj Hasło pracownika.');
        document.forms[form].haslo.focus();
        testresult=false;
    }
if ((testresult) && !checkhaslo(document.forms[form].haslo,""))
    {
        alert('Hasło powinno składać się przynajmniej z 6 liter lub cyfr (bez spacji)');
        testresult=false;
    }

    return testresult;

}


function checkImpreza(form)
{
    var testresult=true;

//nazwa - puste pole
if ((testresult) && document.forms[form].nazwa.value.length==0)
    {
        alert('Podaj nazwę imprezy.');
        document.forms[form].nazwa.focus();
        testresult=false;
    }

//data rozpoczecia - puste pole
if ((testresult) && document.forms[form].datarozp.value.length==0)
    {
        alert('Podaj datę rozpoczęcia imprezy.');
        document.forms[form].datarozp.focus();
        testresult=false;
    }
if ((testresult) && !checkdate(document.forms[form].datarozp,""))
    {
        alert('Data powinna być podana w formacie RRRR-MM-DD');
        document.forms[form].datarozp.focus();
        testresult=false;
    }

//data zakonczenia - puste pole
if ((testresult) && document.forms[form].datazakoncz.value.length==0)
    {
        alert('Podaj datę zakończenia imprezy.');
        document.forms[form].datazakoncz.focus();
        testresult=false;
    }
if ((testresult) && !checkdate(document.forms[form].datazakoncz,""))
    {
        alert('Data powinna być podana w formacie RRRR-MM-DD');
        document.forms[form].datazakoncz.focus();
        testresult=false;
    }

//Miejsce - puste pole
if ((testresult) && document.forms[form].miejsce.value.length==0)
    {
        alert('Podaj miejsce imprezy.');
        document.forms[form].miejsce.focus();
        testresult=false;
    }

    return testresult;
}

// #########################################################################



// ********************************************

function isLetter (c)

{   return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )

}

// ********************************************

function isPlLetter (c)

{

//    alert('Kod znaku '+c+' to:'+c.charCodeAt())

   return ((c.charCodeAt() == 261) || //ą

           (c.charCodeAt() == 260) || //Ą

           (c.charCodeAt() == 263) || //ć

           (c.charCodeAt() == 262) || //ć

           (c.charCodeAt() == 281) || //ę

           (c.charCodeAt() == 280) || //Ę

           (c.charCodeAt() == 322) || //ł

           (c.charCodeAt() == 321) || //Ł

           (c.charCodeAt() == 324) || //ń

           (c.charCodeAt() == 323) || //Ń

           (c.charCodeAt() == 243) || //ó

           (c.charCodeAt() == 211) || //Ó

           (c.charCodeAt() == 347) || //ś

           (c.charCodeAt() == 346) || //Ś

           (c.charCodeAt() == 378) || //Ą

           (c.charCodeAt() == 377) || //Ź

           (c.charCodeAt() == 379) || //ż

           (c.charCodeAt() == 380)) //Ż

}

// ********************************************

function isDigit (c)

{   return ((c >= "0") && (c <= "9"))

}

// ********************************************

function isSpace (c)

{   return (c == " ")

}

// ********************************************
// ********************************************
//      FUNKCJE POMOCNICZE SPRAWDZAJACE
// ********************************************
// ********************************************

function Potwierdz(pytanie)
{
// funkcja wysiwetla okno z prosba o potwierdzenie dokonania akcji

    var tekst = "Jesteś pewien że chcesz to zrobić?\nAby potwierdzić wciśnij <OK>\nAby zrezygnować wciśnij <Anuluj>";
    ok = confirm(pytanie+tekst);
    return ok;

}

function IsINT(toTest)

{
    var testresult=true;
    var x=toTest
    var anum=/(^\d+$)/
    if (anum.test(x))
        testresult=true
    else
    {
          testresult=false
    }
    return (testresult)
}

function cenaWylicz(formularz,idp,i1,c1,i2,c2,i3,c3,waluta)
{
    var testresult=true;
    var poleCena = 'produkt' + idp + 'cena';
    var poleSztuk = 'produkt' + idp + 'ilosc';
    var poleWartosc = 'produkt' + idp + 'wartosc';

    var cena;
    var sztuk = document.forms[formularz][poleSztuk].value;

    if(sztuk == "") {
      document.forms[formularz][poleCena].value = '';
      document.forms[formularz][poleWartosc].value = '';
      return true;
    }
    if(!IsINT(sztuk)) {
      document.forms[formularz][poleSztuk].value = '';
      return true;
    }
    if(sztuk < i1) {
      document.forms[formularz][poleCena].value = '';
      document.forms[formularz][poleWartosc].value = '';
      return true;
    }

    if(sztuk >= i1 && sztuk < i2)  cena = c2 + (i2-sztuk)*(c1-c2)/(i2-i1);
    else if(sztuk >= i2 && sztuk < i3)  cena = c3 + (i3-sztuk)*(c2-c3)/(i3-i2);
    else if(sztuk >= i3)  cena = c3;

    var cena, cena1, wartosc;

    cena = cena * 100;
    cena1 = Math.round(cena);
    wartosc  = cena1*sztuk;
    cena2  = cena1 * 0.01;
    wartosc  = wartosc * 0.01;

    cenastr = new String(cena2);
    poz = cenastr.indexOf(".");
    cenapokaz = new String(cena2);
    wartoscpokaz = new String(wartosc);

    if(poz == -1) {
    	cenapokaz1 = cenapokaz.concat(".00");
    	wartoscpokaz1 = wartoscpokaz.concat(".00");
    }
    else{
      pozwartosc = wartoscpokaz.indexOf(".");
      pozcena = cenapokaz.indexOf(".");
      cenapokaz1 = new String(cenapokaz.substr(0,pozcena + 3));
      if(pozwartosc!=-1)  wartoscpokaz1 = new String(wartoscpokaz.substr(0,pozwartosc + 3));
      else                wartoscpokaz1 = wartoscpokaz.concat(".00");
    }

    if(cenapokaz1.length-3 < cenapokaz1.indexOf(".")) cenapokaz1 = cenapokaz1.concat("0");
    if(wartoscpokaz1.length-3 < wartoscpokaz1.indexOf(".")) wartoscpokaz1 = wartoscpokaz1.concat("0");


    //document.forms[formularz][poleCena].value = cena2;
    document.forms[formularz][poleCena].value = cenapokaz1 + ' ' + waluta;
    //document.forms[formularz][poleWartosc].value = wartosc;
    document.forms[formularz][poleWartosc].value = wartoscpokaz1 + ' ' + waluta;

    return true;
}

function cenaWyliczProsto(formularz,idp,cena,waluta)
{
    var testresult=true;
    var poleCena = 'produkt' + idp + 'cena';
    var poleSztuk = 'produkt' + idp + 'ilosc';
    var poleWartosc = 'produkt' + idp + 'wartosc';

    var cena2;
    var sztuk = document.forms[formularz][poleSztuk].value;

    if(sztuk == "") {
      document.forms[formularz][poleCena].value = '';
      document.forms[formularz][poleWartosc].value = '';
      return true;
    }
    if(!IsINT(sztuk)) {
      document.forms[formularz][poleSztuk].value = '';
      return true;
    }
    if(sztuk < 1) {
      document.forms[formularz][poleCena].value = '';
      document.forms[formularz][poleWartosc].value = '';
      return true;
    }

    cena2 = cena;
    wartosc = cena * sztuk;

    cenastr = new String(cena2);
    poz = cenastr.indexOf(".");
    cenapokaz = new String(cena2);
    wartoscpokaz = new String(wartosc);

    if(poz == -1) {
    	cenapokaz1 = cenapokaz.concat(".00");
    	wartoscpokaz1 = wartoscpokaz.concat(".00");
    }
    else{
      pozwartosc = wartoscpokaz.indexOf(".");
      pozcena = cenapokaz.indexOf(".");
      cenapokaz1 = new String(cenapokaz.substr(0,pozcena + 3));
      if(pozwartosc!=-1)  wartoscpokaz1 = new String(wartoscpokaz.substr(0,pozwartosc + 3));
      else                wartoscpokaz1 = wartoscpokaz.concat(".00");
    }

    if(cenapokaz1.length-3 < cenapokaz1.indexOf(".")) cenapokaz1 = cenapokaz1.concat("0");
    if(wartoscpokaz1.length-3 < wartoscpokaz1.indexOf(".")) wartoscpokaz1 = wartoscpokaz1.concat("0");


    //document.zamawiam[poleCena].value = cena2;
    document.forms[formularz][poleCena].value = cenapokaz1 + ' ' + waluta;
    //document.zamawiam[poleWartosc].value = wartosc;
    document.forms[formularz][poleWartosc].value = wartoscpokaz1 + ' ' + waluta;

    return true;
}

function SprawdzZamowienie(idp,i1,c1,i2,c2,i3,c3)
{
    var testresult=true;
    var poleCena = 'produkt' + idp + 'cena';
    var poleSztuk = 'produkt' + idp + 'ilosc';
    var poleWartosc = 'produkt' + idp + 'wartosc';

    var cena;
    var sztuk = document.zamawiam[poleSztuk].value;

    if(sztuk < i1) {
      document.zamawiam[poleSztuk].value = '';
      document.zamawiam[poleCena].value = '';
      document.zamawiam[poleWartosc].value = '';
      alert('Minimalna ilość sztuk tego produktu jaką możesz zamówić to: ' + i1);
      return true;
    }

    return true;
}
