<!--

function get(id) {
        if (document.getElementById(id)) {
            return document.getElementById(id);
        }
    return false;
}

function checkMail(id) {
    email = get(id).value;
	var filter  = /([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (filter.test(email)) {
        return true;
    }
    return false;
}

function checkInput(id, min) {
    input = get(id).value;
    if (input.length >= min) {
        return true;
    }
    return false;
}

function przelicz() {
    var ilosc = get('ilosc').value;
    
    var id_procesor = get('iprocesor').value;
    var id_ram = get('iram').value;
    var id_hdd = get('ihdd').value;
    var id_gwarancja = get('igwarancja').value;
    var id_monitor = get('imonitor').value;
    
    var cena_zestawu = 0;
    for(var i=0; i<ceny.length; i++) {
        if (ilosc >= ceny[i][0] && ilosc <= ceny[i][1]) {
            cena_zestawu = cena_zestawu + parseFloat(ceny[i][2]);
	    break;
        }
    }
    
    if (cechy[id_procesor][2] > 0) { cena_zestawu += parseFloat(cechy[id_procesor][2]); }
    if (cechy[id_ram][2] > 0) { cena_zestawu += parseFloat(cechy[id_ram][2]); }
    if (cechy[id_hdd][2] > 0) { cena_zestawu += parseFloat(cechy[id_hdd][2]); }
    if (cechy[id_gwarancja][2] > 0) { cena_zestawu += parseFloat(cechy[id_gwarancja][2]); }
    if (cechy[id_monitor][2] > 0) { cena_zestawu += parseFloat(cechy[id_monitor][2]); }
    
    var i = 1;
    while(get('akc'+i)) {
        var id_akcesoria = get('akc'+i).value;
        if (get('akc'+i).checked) {
            for(var j=0; j<akcesoria.length; j++) {
                if (id_akcesoria == akcesoria[j][0]) {
                    if (akcesoria[j][3] == 't') {
                        cena_zestawu = cena_zestawu+parseFloat(akcesoria[j][2]); 
                    }
                }
            }
        }
        i++;
    }

    get('cj').value = cena_zestawu;
    get('cena_sztuki').innerHTML = number_format(cena_zestawu, 2, ',', '');
    
    cena_zestawu = number_format(cena_zestawu, 2, '.', '')*ilosc;
    
    var przelicznik = getPrzelicznik(cena_zestawu);
    get('cena_leasing').innerHTML = number_format(cena_zestawu/przelicznik/ilosc/30, 2, ',', '');
    
    var i = 1;
    while(get('akc'+i)) {
        var id_akcesoria = get('akc'+i).value;
        if (get('akc'+i).checked) {
            for(var j=0; j<akcesoria.length; j++) {
                if (id_akcesoria == akcesoria[j][0]) {
                    if (akcesoria[j][3] == 'f') {
                        cena_zestawu = cena_zestawu+parseFloat(akcesoria[j][2]); 
                    }
                }
            }
        }
        i++;
    }
    get('cz').value = cena_zestawu;
    get('cena_zestawu').innerHTML = number_format(cena_zestawu, 2, ',', '');
    get('mar').value = 0;
}

function getPrzelicznik(cena) {
    var przelicznik = '24';
    for(var i=0; i<leasing.length; i++) {
        if (leasing[i][0] <= cena && leasing[i][1] >= cena) {
            przelicznik = leasing[i][2];
        }
    }
    return przelicznik;
}

function przeliczLaptopy() {
    var cena_zestawu = 0;
    var ilosc = get('ilosc').value;
    var i = 0;
    while(get('laptop'+i+'r')) {
        if (get('laptop'+i+'r').checked) {
            var id = get('laptop'+i+'r').value;
            var cenal = ceny[id];
            for(var j=0; j<cenal.length; j++) {
                if (cenal[j][0] <= ilosc && cenal[j][1] >= ilosc) {
                    cena_zestawu = cena_zestawu+parseFloat(cenal[j][2]);
		    break;
                }
            }
        }
        i++;
    }
    
    var i = 1;
    while(get('akc'+i)) {
        var id_akcesoria = get('akc'+i).value;
        if (get('akc'+i).checked) {
            for(var j=0; j<akcesoria.length; j++) {
                if (id_akcesoria == akcesoria[j][0]) {
                    if (akcesoria[j][3] == 't') {
                        cena_zestawu = cena_zestawu+parseFloat(akcesoria[j][2]);
                    }
                }
            }
        }
        i++;
    }

    get('cj').value = cena_zestawu;
    get('cena_sztuki').innerHTML = number_format(cena_zestawu, 2, ',', '');
    cena_zestawu = cena_zestawu*ilosc;
    
    var przelicznik = getPrzelicznik(cena_zestawu);
    
    get('cena_leasing').innerHTML = number_format(cena_zestawu/przelicznik/ilosc/30, 2, ',', '');
    
    var i = 1;
    while(get('akc'+i)) {
        var id_akcesoria = get('akc'+i).value;
        if (get('akc'+i).checked) {
            for(var j=0; j<akcesoria.length; j++) {
                if (id_akcesoria == akcesoria[j][0]) {
                    if (akcesoria[j][3] == 'f') {
                        cena_zestawu = cena_zestawu+parseFloat(akcesoria[j][2]); 
                    }
                }
            }
        }
        i++;
    }
    
    get('cz').value = cena_zestawu;
    get('cena_zestawu').innerHTML = number_format(cena_zestawu, 2, ',', '');
    get('mar').value = 0;
}

function number_format(a, b, c, d) {
    a = Math.round(a * Math.pow(10, b)) / Math.pow(10, b);
    e = a + '';
    f = e.split('.');
    if (!f[0]) { f[0] = '0'; }
    if (!f[1]) { f[1] = ''; }
    if (f[1].length < b) { g = f[1]; for (i=f[1].length + 1; i <= b; i++) { g += '0'; } f[1] = g; }
    if(d != '' && f[0].length > 3) { h = f[0]; f[0] = ''; for(j = 3; j < h.length; j+=3) { i = h.slice(h.length - j, h.length - j + 3); f[0] = d + i +  f[0] + ''; } j = h.substr(0, (h.length % 3 == 0) ? 3 : (h.length % 3)); f[0] = j + f[0]; }
    c = (b <= 0) ? '' : c;
    return f[0] + c + f[1];
}

function sprawdzZamowienie() {
    var wynik = true;
    var pokaz = true;
    
    var info = new Array();
    var i = 0;
    
    if (get('p1').selectedIndex == 0 && get('p2').selectedIndex == 0 && get('p3').selectedIndex == 0) { wynik = false;  info[i++] = '- wybierz zestawy'; }
    if (!checkInput('nazwa', 1)) { wynik = false; info[i++] = '- nazwa jednostki'; }
    if (!checkInput('adres', 1)) { wynik = false; info[i++] = '- adres'; }
    if (!checkInput('kod', 1)) { wynik = false; info[i++] = '- kod'; }
    if (!checkInput('miasto', 1)) { wynik = false; info[i++] = '- miasto'; }
    if (!checkInput('nip', 1)) { wynik = false; info[i++] = '- NIP'; }
    if (!checkInput('telefon', 1)) { wynik = false; info[i++] = '- telefon'; }
    if (!checkInput('email', 1)) { wynik = false; info[i++] = '- e-mail'; }
    
    if (wynik == false && info.length > 0 && pokaz == true) {
        var napis = "Proszę poprawnie uzupełnić następujące pola: \n"+info.join("\n");
        alert(napis);
    }
    return wynik;
}

function zoom(id, typ) {
    window_handle = window.open('zoom.html?id='+id+'&typ='+typ,'Device','scrollbars=yes,status=no,width=500,height=500,left=50,top=50');
}
function zoom2(typ) {
    window_handle = window.open('grenke.html','Device','scrollbars=yes,status=no,width=500,height=500,left=50,top=50');
}

function zmienLaptop() {
    var i=0;
    while(get('laptop'+i+'i')) { get('laptop'+i+'i').style.display = 'none'; i++; }
    i=0;
    while(get('zdjecie'+i)) { get('zdjecie'+i).style.display = 'none'; i++; }
    i=0;
    while(get('laptop'+i+'c')) { get('laptop'+i+'c').className = 'tyt1'; i++; }
    i=0;
    while(get('specyfikacja'+i)) { get('specyfikacja'+i).style.display = 'none'; i++; }
    i=0;
    while(get('laptop'+i+'r')) {
        if (get('laptop'+i+'r').checked) { 
            get('laptop'+i+'i').style.display = 'block';
            get('laptop'+i+'c').className = 'tyt';
            if (get('zdjecie').value == 1) {
                get('zdjecie'+i).style.display = 'block'; 
            }
            else {
                get('specyfikacja'+i).style.display = 'block';
            }
        }
        i++;
    }
}

function zmienZdjecie() {
    var i=0;
    get('zdjecie').value = 1;
    while(get('zdjecie'+i)) { get('zdjecie'+i).style.display = 'none'; i++; }
    i=0;
    while(get('specyfikacja'+i)) { get('specyfikacja'+i).style.display = 'none'; i++; }
    i=0;
    while(get('laptop'+i+'r')) {
        if (get('laptop'+i+'r').checked) { 
            get('zdjecie'+i).style.display = 'block'; 
        }
        i++;
    }
}

function zmienAtuty() {
    var i=0;
    get('zdjecie').value = 0;
    while(get('zdjecie'+i)) { get('zdjecie'+i).style.display = 'none'; i++; }
    i=0;
    while(get('specyfikacja'+i)) { get('specyfikacja'+i).style.display = 'none'; i++; }
    i=0;
    while(get('laptop'+i+'r')) {
        if (get('laptop'+i+'r').checked) { 
            get('specyfikacja'+i).style.display = 'block'; 
        }
        i++;
    }
}

//-->