var adres=1;
var www=1;
var mail=1;
var logo=1;
var zdjecie=1;

function dodaj_adres()
{
 adres++;

 document.getElementById("adres").innerHTML+="<table class=\"dane\">\
                <tr>\
                    <td class=\"dane_opis\">\
                        * Województwo\
                    </td>\
                    <td class=\"dane_wartosc\">\
                        <select name=\"wojewodztwo"+adres+"\">\
                            <option value=\"wybierz\">wybierz</option>\
                            <option value=\"dolnoslaskie\">dolnośląskie\</option>\
                            <option value=\"kujawsko-pomorskie\">kujawsko-pomorskie</option>\
                            <option value=\"lubelskie\">lubelskie</option>\
                            <option value=\"lubuskie\">lubuskie</option>\
                            <option value=\"lodzkie\">łódzkie</option>\
                            <option value=\"malopolskie\">małopolskie</option>\
                            <option value=\"mazowieckie\">mazowieckie</option>\
                            <option value=\"opolskie\">opolskie</option>\
                            <option value=\"podkarpackie\">podkarpackie</option>\
                            <option value=\"podlaskie\">podlaskie</option>\
                            <option value=\"pomorskie\">pomorskie</option>\
                            <option value=\"slaskie\">śląskie</option>\
                            <option value=\"swietokrzyskie\">świętokrzyskie</option>\
                            <option value=\"warminsko-mazurskie\">warmińsko-mazurskie</option>\
                            <option value=\"wielkopolskie\">wielkopolskie</option>\
                            <option value=\"zachodniopomorskie\">zachodniopomorskie</option>\
                        </select>\
                    </td>\
                </tr>\
                <tr>\
                    <td class=\"dane_opis\">\
                        Powiat\
                    </td>\
                    <td class=\"dane_wartosc\">\
                        <input type=\"text\" name=\"powiat"+adres+"\">\
                    </td>\
                </tr>\
                <tr>\
                    <td class=\"dane_opis\">\
                        Miejscowość\
                    </td>\
                    <td class=\"dane_wartosc\">\
                        <input type=\"text\" name=\"miejscowosc"+adres+"\">\
                    </td>\
                </tr>\
                <tr>\
                    <td class=\"dane_opis\">\
                        Gmina\
                    </td>\
                    <td class=\"dane_wartosc\">\
                        <input type=\"text\" name=\"gmina"+adres+"\">\
                    </td>\
                </tr>\
                <tr>\
                    <td class=\"dane_opis\">\
                        Ulica\
                    </td>\
                    <td class=\"dane_wartosc\">\
                        <input type=\"text\" name=\"ulica"+adres+"\">\
                    </td>\
                </tr>\
                <tr>\
                    <td class=\"dane_opis\">\
                        Nr domu\
                    </td>\
                    <td class=\"dane_wartosc\">\
                        <input type=\"text\" name=\"nr_domu"+adres+"\">\
                    </td>\
                </tr>\
                <tr>\
                    <td class=\"dane_opis\">\
                        Nr lokalu\
                    </td>\
                    <td class=\"dane_wartosc\">\
                        <input type=\"text\" name=\"nr_lokalu"+adres+"\">\
                    </td>\
                </tr>\
                <tr>\
                    <td class=\"dane_opis\">\
                        Telefon\
                    </td>\
                    <td class=\"dane_wartosc\">\
                        <input type=\"text\" name=\"telefon"+adres+"\">\
                    </td>\
                </tr>\
                <tr>\
                    <td class=\"dane_opis\">\
                        Fax\
                    </td>\
                    <td class=\"dane_wartosc\">\
                        <input type=\"text\" name=\"fax"+adres+"\">\
                    </td>\
                </tr>\
                <tr>\
                    <td class=\"dane_opis\">\
                        Tel. kom.\
                    </td>\
                    <td class=\"dane_wartosc\">\
                        <input type=\"text\" name=\"kom"+adres+"\">\
                    </td>\
                </tr>\
            </table>";
}

function dodaj_www()
{
 www++;

 document.getElementById("www").innerHTML+="<table class=\"dane\">\
                <tr>\
                    <td class=\"dane_opis\">\
                        Adres www\
                    </td>\
                    <td class=\"dane_wartosc\">\
                        <input type=\"text\" name=\"www"+www+"\">\
                    </td>\
                </tr>\
            </table>";
}

function dodaj_mail()
{
 mail++;

 document.getElementById("mail").innerHTML+="<table class=\"dane\">\
                <tr>\
                    <td class=\"dane_opis\">\
                        E-mail\
                    </td>\
                    <td class=\"dane_wartosc\">\
                        <input type=\"text\" name=\"mail"+mail+"\">\
                    </td>\
                </tr>\
            </table>";
}

function dodaj_logo()
{
 if ( document.getElementById("wizytowka").checked )
   {
    logo++;

    logo_dodane=document.createElement("div");
    logo_dodane.setAttribute("class","wpis_dzial");
    logo_dodane.innerHTML="Logo (max 50KB) <input type=\"file\" name=\"logo"+logo+"\" id=\"logo"+logo+"\">";

    document.getElementById("logo").appendChild(logo_dodane);
   }
 else alert("Dodatkowe logo jest dostępne po wybraniu wpisu z wizytówką.");
}

function dodaj_zdjecie()
{
 if ( document.getElementById("wizytowka").checked )
   {
    zdjecie++;

    zdjecie_dodane=document.createElement("div");
    zdjecie_dodane.setAttribute("class","zdjecie_dodaj");
    zdjecie_dodane.innerHTML="Zdjęcie do wizytówki (max 70KB) <input type=\"file\" name=\"zdjecie"+zdjecie+"\" id=\"zdjecie"+zdjecie+"\">";

    document.getElementById("zdjecie").appendChild(zdjecie_dodane);
   }
 else alert("Dodatkowe zdjęcie jest dostępne po wybraniu wpisu z wizytówką.");
}

function sprawdz_formularz_platny()
{
 poprawne=1;

 if ( document.getElementById("nazwa_firmy").value==null || document.getElementById("nazwa_firmy").value=="" ) poprawne=0;
 if ( document.getElementById("wojewodztwo1").selectedIndex==0 ) poprawne=0;
 if ( document.getElementById("slowa_kluczowe").value==null || document.getElementById("slowa_kluczowe").value=="" ) poprawne=0;
 if ( document.getElementById("opis").value==null || document.getElementById("opis").value=="" ) poprawne=0;
 if ( document.getElementById("faktura_nazwa_firmy").value==null || document.getElementById("faktura_nazwa_firmy").value=="" ) poprawne=0;
 if ( document.getElementById("faktura_adres").value==null || document.getElementById("faktura_adres").value=="" ) poprawne=0;
 if ( document.getElementById("faktura_nip").value==null || document.getElementById("faktura_nip").value=="" ) poprawne=0;
 if ( document.getElementById("osoba").value==null || document.getElementById("osoba").value=="" ) poprawne=0;
 if ( document.getElementById("osoba_telefon").value==null || document.getElementById("osoba_telefon").value=="" ) poprawne=0;
 if ( document.getElementById("osoba_mail").value==null || document.getElementById("osoba_mail").value=="" ) poprawne=0;

 if ( document.getElementById("opis").value.length>1000 )
   {
    alert("Pole \"Treść reklamy\" moża zawierać najwyżej 1000 znaków.");
    return false;
   }

 if ( poprawne==0 )
   {
    alert("Proszę wypełnić wymagane pola.");
    return false;
   }
 else return true;
}

function sprawdz_formularz_darmowy()
{
 poprawne=1;

 if ( document.getElementById("nazwa_firmy").value==null || document.getElementById("nazwa_firmy").value=="" ) poprawne=0;
 if ( document.getElementById("wojewodztwo").selectedIndex==0 ) poprawne=0;
 if ( document.getElementById("slowa_kluczowe").value==null || document.getElementById("slowa_kluczowe").value=="" ) poprawne=0;
 if ( document.getElementById("opis").value==null || document.getElementById("opis").value=="" ) poprawne=0;
 if ( document.getElementById("osoba").value==null || document.getElementById("osoba").value=="" ) poprawne=0;
 if ( document.getElementById("osoba_telefon").value==null || document.getElementById("osoba_telefon").value=="" ) poprawne=0;
 if ( document.getElementById("osoba_mail").value==null || document.getElementById("osoba_mail").value=="" ) poprawne=0;
 if ( document.getElementById("link").value==null || document.getElementById("link").value=="" ) poprawne=0;

 if ( document.getElementById("slowa_kluczowe").value.length>300 )
   {
    alert("Pole \"Słowa kluczowe\" moża zawierać najwyżej 300 znaków.");
    return false;
   }

 if ( document.getElementById("opis").value.length>300 )
   {
    alert("Pole \"Treść reklamy\" moża zawierać najwyżej 300 znaków.");
    return false;
   }

 if ( poprawne==0 )
   {
    alert("Proszę wypełnić wymagane pola.");
    return false;
   }
 else return true;
}

function wlacz_logo_zdjecie()
{
 if ( document.getElementById("wizytowka").checked )
   {
    for ( a=2 ; a<=logo ; a++ )
      {
       document.getElementById("logo"+a).disabled=false;
      }

    for ( a=1 ; a<=zdjecie ; a++ )
      {
       document.getElementById("zdjecie"+a).disabled=false;
      }
   }
 else
   {
    for ( a=2 ; a<=logo ; a++ )
      {
       document.getElementById("logo"+a).disabled=true;
      }

    for ( a=1 ; a<=zdjecie ; a++ )
      {
       document.getElementById("zdjecie"+a).disabled=true;
      }
   }
}

function iloscPole(id, idIle, max)
{
 ilePole=document.getElementById(id).value.length;

 if ( ilePole<=max ) kolor="#00FF00";
 else kolor="#FF0000";

 document.getElementById(idIle).innerHTML="<span style=\"color: "+kolor+"\">"+ilePole+"</span>";
}
