function dodajPole(){


    var x = document.getElementById("iloscPol");
    
    var wiecej = Number(x.value) + 1;
    
    var id = x.value
    
    x.value = wiecej.toString();
    
    document.getElementById("iloscPol").value = x.value;
    
    var nowyElement = document.createElement('li');
    
    nowyElement.setAttribute('id', 'pole' + id)
    
    nowyElement.innerHTML = '<input type="text" name="pole' + id + '" /><a onclick="usunPole(\'pole' + id + '\')">Usun pole</a>'
    
    document.getElementById('lista').appendChild(nowyElement);
    
}

function usunPole(id){


    var x = document.getElementById("iloscPol");
    
    var pierwotnie = x.value;
    
    var mniej = Number(x.value) - 1;
    
    x.value = mniej.toString();
    
    document.rem
    
    document.getElementById("iloscPol").value = x.value;
    
    doKasacji = document.getElementById(id)
    
    document.getElementById('lista').removeChild(doKasacji)
    
}


function wyslijFormularz(){



    var x = document.forms;
    
    var licznosc = x.length;
    
    var nrKomorki = licznosc - 1;
    
    document.forms[nrKomorki].submit();
}

function formularzKontaktowy(){

    var x = document.forms;
    
    var licznosc = x.length;
    
    var nrKomorki = licznosc - 2;
    
    
    
    if (!document.forms[nrKomorki].elements['osoba'].value.length) {
        document.forms[nrKomorki].elements['osoba'].focus();
        alert('Podanie danych osobowych jest obowiÄzkowe.');
        return false;
    }
    
    if (!document.forms[nrKomorki].elements['telefon'].value.length) {
    
        document.forms[nrKomorki].elements['telefon'].focus();
        alert('Podanie numeru telefonu jest obowiÄzkowe.');
        return false;
    }
    
    if (!document.forms[nrKomorki].elements['email'].value.length) {
    
        document.forms[nrKomorki].elements['email'].focus();
        alert('Podanie adresu e-mail jest obowiÄzkowe.');
        return false;
    }
}

function isValidEmail(email, required){
    if (required == undefined) { // if not specified, assume it's required
        required = true;
    }
    if (email == null) {
        if (required) {
            return false;
        }
        return true;
    }
    if (email.length == 0) {
        if (required) {
            return false;
        }
        return true;
    }
    if (!allValidChars(email)) { // check to make sure all characters are valid
        return false;
    }
    if (email.indexOf("@") < 1) { //  must contain @, and it must not be the first character
        return false;
    }
    else 
        if (email.lastIndexOf(".") <= email.indexOf("@")) { // last dot must be after the @
            return false;
        }
        else 
            if (email.indexOf("@") == email.length) { // @ must not be the last character
                return false;
            }
            else 
                if (email.indexOf("..") >= 0) { // two periods in a row is not valid
                    return false;
                }
                else 
                    if (email.indexOf(".") == email.length) { // . must not be the last character
                        return false;
                    }
    return true;
}

function allValidChars(email){
    var parsed = true;
    var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
    for (var i = 0; i < email.length; i++) {
        var letter = email.charAt(i).toLowerCase();
        if (validchars.indexOf(letter) != -1) 
            continue;
        parsed = false;
        break;
    }
    return parsed;
}

function sprawdzEmail(email){

    if (isValidEmail(email)) {
    
        document.getElementById('formularzNewsletter').submit();
    }
    else {
    
        alert('Nie wpisano adresu e-mail lub jest w nim błąd');
        
    }
}

function pokazStrone(strona, iloscStron){



    for (var i = 0; i < iloscStron; i++) {
    
    
        if (strona == i) {
        
            document.getElementById("strona" + i).style.display = "block";
            document.getElementById("odnosnikDoStrony" + i).style.fontWeight = "bold";
            
            if ((i - 1) > 0) {
            
                document.getElementById("nawigatorWstecz").href = "javascript: pokazStrone(" + (i - 1) + ", " + iloscStron + ")";
            }
            else {
            
                document.getElementById("nawigatorWstecz").href = "javascript: pokazStrone(0, " + iloscStron + ")";
            }
            if ((i + 1) < iloscStron) {
            
                document.getElementById("nawigatorNaprzod").href = "javascript: pokazStrone(" + (i + 1) + ", " + iloscStron + ")";
            }
            
        }
        else {
        
            document.getElementById("strona" + i).style.display = "none";
            document.getElementById("odnosnikDoStrony" + i).style.fontWeight = "normal";
        }
        
    }
    
    
    
    
};


function getElementsByName_iefix(tag, name) {
     
     var elem = document.getElementsByTagName(tag);
     var arr = new Array();
     for(i = 0,iarr = 0; i < elem.length; i++) {
          att = elem[i].getAttribute("name");
          if(att == name) {
               arr[iarr] = elem[i];
               iarr++;
          }
     }
     return arr;
}


function podswietl(indeks){
    
    var tablicaElementow = getElementsByName_iefix("div", "menu"+indeks);
    temp = getElementsByName_iefix("a", "menu"+indeks);
    tablicaElementow[2] = temp[0];
    
    for(var i=0; i<3; i++){
        

        if(i == 0){
            
            tablicaElementow[i].style.backgroundImage = "url('img/menuPrzyciskAktywnyLewa.gif')";
            
        }
        if(i == 1){
            
            tablicaElementow[i].style.backgroundImage = "url('img/menuPrzyciskAktywnyPrawa.gif')";
            
        }
        if(i == 2){
            
            tablicaElementow[i].style.backgroundImage = "url('img/menuPrzyciskAktywnySrodek.gif')";
            
        }
        
        

    }
    
}

function wygas(indeks){
    
    var tablicaElementow = getElementsByName_iefix("div", "menu"+indeks);
    temp = getElementsByName_iefix("a", "menu"+indeks);
    tablicaElementow[2] = temp[0];
    
    for(var i=0; i<tablicaElementow.length; i++){
        
        if(i == 0){
            
            tablicaElementow[i].style.backgroundImage = "url('img/menuPrzyciskNieaktywnyLewa.gif')";
            
        }
        if(i == 2){
            
            tablicaElementow[i].style.backgroundImage = "url('img/menuPrzyciskNieaktywnySrodek.gif')";
            
        }
        if(i == 1){
            
            tablicaElementow[i].style.backgroundImage = "url('img/menuPrzyciskNieaktywnyPrawa.gif')";
            
        }
    }
    
}

function przelaczObrazek(id){

      var ajaxRequest; // The variable that makes Ajax possible!
    try {
        // Opera 8.0+, Firefox, Safari
        ajaxRequest = new XMLHttpRequest();
    } 
    catch (e) {
        // Internet Explorer Browsers
        try {
            ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
        } 
        catch (e) {
            try {
                ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
            } 
            catch (e) {
                // Something went wrong
                alert("Błąd przy wymianie danych!");
                return false;
            }
        }
    }
    // Create a function that will receive data sent from the server
    
    
    
    var url = "ajax/przelaczObrazek.php";
    var params = "id=" + id;
    
    
    ajaxRequest.open("POST", url, true);
    
    //Send the proper header information along with the request
    ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    ajaxRequest.setRequestHeader("Content-length", params.length);
    ajaxRequest.setRequestHeader("Connection", "close");
    
    /*
     ajaxRequest.onreadystatechange = function() {//Call a function when the state changes.
     if(http.readyState == 4 && http.status == 200) {
     alert(ajaxRequest.responseText);
     }
     }
     */
    ajaxRequest.onreadystatechange = function(){
    
        if (ajaxRequest.readyState != 4) {
        
            document.getElementById("obramowanieObrazka").innerHTML = "<div class='ladowanie'><img  src='img/ajax-loadingSzary.gif' width='31' height='31' /><br /> Wykonywanie operacji w toku...</div>";
        }
        
        if (ajaxRequest.readyState == 4) {
        
        
        
            document.getElementById("obramowanieObrazka").innerHTML = ajaxRequest.responseText;
            
            
        }
    }
    
    
    
    ajaxRequest.send(params);  
    
};

