<!--

var katalog_start = '/';
var status_bar1 = '50px';
var status_bar2 = '100px';

function get(id) {
        if (document.getElementById(id)) {
            return document.getElementById(id);
        }
    return false;
}

function checkInput(id, min) {
    input = get(id).value;
    if (input.length >= min) {
        return true;
    }
    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 checkLength(id, idc) {
    var max = 300;
    if (get(id).value.length > max) {
        get(id).value = get(id).value.substring(0, max);
    }
    get(idc).innerHTML = max-get(id).value.length;
}

function sprawdzPolec() {
    var wynik=true;
    if (!checkMail('polec_od')) { get("polec_od").className="error"; wynik=false; } else { get("polec_od").className="pole"; }
    if (!checkMail('polec_do')) { get("polec_do").className="error"; wynik=false; } else { get("polec_do").className="pole"; }
    if (!checkInput('polec_podpis', 1)) { get('polec_podpis').className = 'error'; wynik=false; } else { get('polec_podpis').className = 'pole'; }
	if (wynik==false){ alert(kt['pp']); }
    return wynik;
}

function sprawdzKomentarz() {
    var wynik=true;
    if (!checkInput('identyfikator_pole', 1)) { get("identyfikator_pole").className="error"; wynik=false; } else { get("identyfikator_pole").className="pole"; }
    if (!checkInput('komentarz_pole', 1)) { get("komentarz_pole").className="error"; wynik=false; } else { get("komentarz_pole").className="pole"; }
	if (wynik==false){ alert(kt['pp']); }
    return wynik;
}

function pokazPolecTytul() {
    get('polec_tytul').value = get('polec_podpis').value+' '+get('tytul2').value+' '+get('tytul1').value;
}

function numbersonly(element, e, dec) {
    var key;
    var keychar;
    if (window.event) key = window.event.keyCode;
    else if (e) key = e.which;
    else return true;
    
    keychar = String.fromCharCode(key);

    if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) ) { return true; }
    if (dec == true) { if ((("0123456789\.").indexOf(keychar) > -1) && (keychar != '.' || element.value.indexOf('.') <= -1)) { return true; } }
    else if ((("0123456789").indexOf(keychar) > -1)) { return true; }
    return false;
}

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 kat_t(kat) {
    var kategoria = kategorie[kat];
    get('nowosci2').innerHTML = kategoria[1];
    get('promocje2').innerHTML = kategoria[2];
    get('wszystkie2').innerHTML = kategoria[3];
    if (kat == 'suma') {
        get('cena2').innerHTML = '';
        get('cenaod2').innerHTML = '';
    }
    else {
        get('cena2').innerHTML = kategoria[0];
        get('cenaod2').innerHTML = ceny_od;
    }
}



function pokazOpisyWszystkie(lista, typ) {
    lista_array = lista.split(";");
    for (var i=0; i < lista_array.length; i++) {
        if (typ == 'specyfikacja' || (typ == 'opisy' && get('opis'+lista_array[i]).innerHTML)) {
            pokazOpisy(lista_array[i], typ);
        }
    }
    parent.wydruk.location.href = 'ustawienia.php?'+typ+'=1';
}

function zmienPolaJakWyzej1() {
    if (get('jakwyzej1').checked) {
        get('firma_adres_wysylka').readOnly = true;
        get('firma_kod_wysylka').readOnly = true;
        get('firma_miasto_wysylka').readOnly = true;
        get('firma_adres_wysylka_text').className='txt-disabled';
        get('firma_kod_wysylka_text').className='txt-disabled';
        get('firma_miasto_wysylka_text').className='txt-disabled';
        get('firma_adres_wysylka').value = '';
        get('firma_kod_wysylka').value = '';
        get('firma_miasto_wysylka').value = '';
        zgasWysylke();
    }
    else {
        get('firma_adres_wysylka').readOnly = false;
        get('firma_kod_wysylka').readOnly = false;
        get('firma_miasto_wysylka').readOnly = false;
        get('firma_adres_wysylka_text').className='txt';
        get('firma_kod_wysylka_text').className='txt';
        get('firma_miasto_wysylka_text').className='txt';
        zapalWysylke();
    }
}

function zmienPolaJakWyzej2(numer) {
    if (numer == 2) {
        get('jakwyzej3').checked = false;
    }
    else if (numer == 3) {
        get('jakwyzej2').checked = false;
    }
    

    if ((get('jakwyzej2').checked) || (get('jakwyzej3').checked)) {
        get('firma_adres').readOnly = true;
        get('firma_kod').readOnly = true;
        get('firma_miasto').readOnly = true;
        
        get('firma_adres_text').className='txt-disabled';
        get('firma_kod_text').className='txt-disabled';
        get('firma_miasto_text').className='txt-disabled';

        get('firma_adres').value = '';
        get('firma_kod').value = '';
        get('firma_miasto').value = '';
        
        if (get('jakwyzej2').checked) {
            get('zgodny_z_rejestracja').className='txt';
            get('zgodny_z_faktura').className='txt-disabled';
       }
       else { 
            get('zgodny_z_rejestracja').className='txt-disabled';
            get('zgodny_z_faktura').className='txt';
       }
       zgasFirma();
    }
    else {
        get('firma_adres').readOnly = false;
        get('firma_kod').readOnly = false;
        get('firma_miasto').readOnly = false;
        
        get('firma_adres_text').className='txt';
        get('firma_kod_text').className='txt';
        get('firma_miasto_text').className='txt';
        
        get('zgodny_z_rejestracja').className='txt-disabled';
        get('zgodny_z_faktura').className='txt-disabled';
        zapalFirma();
    }
}

function zgasFirma() {
     get('firma_adres').className = 'pole-disabled';
     get('firma_kod').className = 'pole-disabled';
     get('firma_miasto').className = 'pole-disabled';
}

function zapalFirma() {
     get('firma_adres').className = 'pole';
     get('firma_kod').className = 'pole';
     get('firma_miasto').className = 'pole';
}

function zgasWysylke() {
     get('jakwyzej1_txt').className='txt';
     get('firma_adres_wysylka').className = 'pole-disabled';
     get('firma_kod_wysylka').className = 'pole-disabled';
     get('firma_miasto_wysylka').className = 'pole-disabled';
}

function zapalWysylke() {
    get('jakwyzej1_txt').className='txt-disabled';
     get('firma_adres_wysylka').className = 'pole';
     get('firma_kod_wysylka').className = 'pole';
     get('firma_miasto_wysylka').className = 'pole';
}
function menu(id, kategoria, ok) {
    if (ok === true) { get(id).src = katalog_start+'img_'+parent.ln+'/menu_'+kategoria+'_ok.gif'; }
    else { get(id).src = katalog_start+'img_'+parent.ln+'/menu_'+kategoria+'.gif'; }
}

function show(id, typ, u) {
    var w = 'sale';
    if (typ == 'sale' || typ == 'spec') {
        if (get('p'+id).value == 'video') { get('z'+id).innerHTML = get('b'+id).innerHTML; get('b'+id).innerHTML = ''; }
        if (typ == 'sale' && get('z'+id+'a').innerHTML != '') { get('z'+id+'b').style.display = 'none'; get('z'+id+'a').style.display = 'block'; w = 'sale';  }
        else { get('z'+id+'a').style.display = 'none'; get('z'+id+'b').style.display = 'block'; w = 'spec'; }
    }
    if (typ == 'video' && get('v'+id) != false) {
        if (get('p'+id).value == 'sale' || get('p'+id).value == 'spec') { get('b'+id).innerHTML = get('z'+id).innerHTML; }
        var video = str_replace("/watch?v=", "/v/", get('v'+id).value)+'&hl=pl&fs=1&rel=0&border=1';
        get('z'+id).innerHTML = '<object data="'+video+'" type="application/x-shockwave-flash" width="340" height="285"><param name="movie" value="'+video+'"><param name="quality" value="high"><param name="menu" value="false"><param name="wmode" value="opaque"></object>';
        // get('z'+id).innerHTML = '<embed src="'+video+'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="340" height="285"></embed>';
        // get('z'+id).innerHTML = '<object width="340" height="285"><param name="movie" value="http://www.youtube.com/v/FnGsxp2tKoE&hl=pl&fs=1&rel=0&border=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/FnGsxp2tKoE&hl=pl&fs=1&rel=0&border=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="340" height="285"></embed></object>';
        w = 'video';
    }
    get('p'+id).value = w;
    if (u == true) { ustawienia.location.href = katalog_start+'ustawienia.php?id='+id+'&w='+w; }
}

function show_all(lista, typ) {
    lista_array = lista.split(";");
    for (var i=0; i < lista_array.length; i++) {
        show(lista_array[i], typ, false);
        
        if (get('p'+lista_array[i]).value == 'video') { get('r'+lista_array[i]+'c').checked = 'true'; }
        if (get('p'+lista_array[i]).value == 'spec') { get('r'+lista_array[i]+'b').checked = 'true'; }
        if (get('p'+lista_array[i]).value == 'sale') { get('r'+lista_array[i]+'a').checked = 'true'; }

    }
    ustawienia.location.href = katalog_start+'ustawienia.php?w='+typ;
}

function str_replace(search, replace, subject) {
    var s = subject;
    var ra = r instanceof Array, sa = s instanceof Array;
    var f = [].concat(search);
    var r = [].concat(replace);
    var i = (s = [].concat(s)).length;
    var j = 0;
    
    while (j = 0, i--) {
        if (s[i]) {
            while (s[i] = (s[i]+'').split(f[j]).join(ra ? r[j] || "" : r[0]), ++j in f){};
        }
    }
 
    return sa ? s : s[0];
}

function r(link) {
    document.location.href = link;
}
function u(link) {
    ustawienia.location.href = link;
}
function k(id, o) {
    if (o == 'change') { ustawienia.location.href = katalog_start+'ustawienia.php?id='+id+'&o='+o+'&liczba='+parent.statusbar1.get('ilosc'+id).value; }
    else { ustawienia.location.href = katalog_start+'ustawienia.php?id='+id+'&o='+o; }
}
function kp(id, o) {
    if (o == 'change') { ustawienia.location.href = katalog_start+'ustawienia.php?k=1&id='+id+'&o='+o+'&liczba='+parent.get('ilosc'+id).options[get('ilosc'+id).selectedIndex].value; }
    else { ustawienia.location.href = katalog_start+'ustawienia.php?id='+id+'&o='+o; }
}
function pz(id) {
    ustawienia.location.href = katalog_start+'ustawienia.php?id='+id+'&z=1';
    //parent.ustawienia.focus();
    //parent.ustawienia.print();
}

function ki(id, suffix) {
    parent.get('i'+id).src = katalog_start+'img_'+parent.ln+'/kupuje'+suffix+'.gif';
}
function p(id, o) {
    ustawienia.location.href = katalog_start+'ustawienia.php?id='+id+'&p='+o;
}
function s(o) {
    ustawienia.location.href = katalog_start+'ustawienia.php?s='+o;
}
function show_bar1() {
    parent.get('statusbar1').style.height=status_bar1;
    get('sb2').style.display = 'none';get('sb1').style.display = 'block';
    get('p2').style.display = 'none';
    get('k2').style.display = 'none';
    parent.s(0);
}
function show_bar2() {
    parent.get('statusbar1').style.height=status_bar2;
    get('sb1').style.display = 'none';get('sb2').style.display = 'block';
    get('p2').style.display = 'block';
    get('k2').style.display = 'block';
    parent.s(1);
}

function zmien_transport() {
    var id_transportu = get('transport').options[get('transport').selectedIndex].value;
    var cena_zakupu_brutto = get('produkty_kwota').value;
    for(i=0;i<transporty.length;i++) {
        var transport = transporty[i];
        if (id_transportu == transport[0]) {
            get('transport_kwota').innerHTML = number_format(transport[2], 2, ',', ' ');
            get('zamowienie_kwota').innerHTML = number_format(parseFloat(cena_zakupu_brutto)+parseFloat(transport[2]), 2, ',', ' ');
        }
    }
    zmien_raty();
}

function removeAllOptions(selectbox) {
    var i;
    for(i=selectbox.options.length-1;i>=0;i--) {
        selectbox.remove(i);
    }
}

function addOption(selectbox, value, text ) {
    var optn = document.createElement("OPTION");
    optn.text = text;
    optn.value = value;
    selectbox.options.add(optn);
}


function zmien_platnosc() {
    var platnosc = get('platnosc_select').options[get('platnosc_select').selectedIndex].value;
    removeAllOptions(get('transport'));
    if (platnosc == 'w kasie Sims Lifecycle Services') {
        addOption(get('transport'), "0", transporty[0][1]);
        zmien_transport();
    }
    else {
        for(i=1;i<transporty.length;i++) {
            addOption(get('transport'), transporty[i][0], transporty[i][1]);
        }
        if (platnosc != 'za pobraniem') {
            addOption(get('transport'), "0", transporty[0][1]);
        }
    }
    zmien_transport();
    zmien_raty();
}

function zmien_raty() {
    if (ln == 'pl') {
        var platnosc = get('platnosc_select').options[get('platnosc_select').selectedIndex].value;
        if (platnosc == 'raty') {
            iraty.location.href = katalog_start+'_blank.php';
            var id_transportu = get('transport').options[get('transport').selectedIndex].value;
            iraty.location.href = katalog_start+'raty.php?id_transportu='+id_transportu;
            if (ln == 'pl') { get('draty').style.display = 'block'; }
        }
        else {
            get('draty').style.display = 'none';
        }
    }
}

function pp() {
    parent.window.open('/porownanie.php', 'Sims_Lifecycle_Services', 'status=yes,scrollbars=yes,width=1005,height=500,left=0,top=0');
}
function zoom(link) {
    parent.window.open('/zoom/'+link, 'Sims_Lifecycle_Services', 'status=yes,scrollbars=yes,width=420,height=400,left=50,top=50');
}
function rz(id) {
    if (get('cena_produktu')) {
        var cena = parseFloat(get('cena_produktu').innerHTML.replace(' ', ''));
        parent.window.open('/raty.php?id='+id+'&cena='+cena, 'Sims_Lifecycle_Services', 'status=yes,scrollbars=yes,width=420,height=450,left=50,top=50');
    }
    else {
        parent.window.open('/raty.php?id='+id, 'Sims_Lifecycle_Services', 'status=yes,scrollbars=yes,width=420,height=450,left=50,top=50');
    }
}

function replaceAll(ciag,we,wy){
    if ((we!=wy) && (we.length>0)){
        while (ciag.indexOf(we)!=-1) {
            ciag=ciag.replace(we,wy);
        }
    }
    return ciag;
}


function checkPhone(form, submit, pokaz) {
    wynik = true;
    var info = new Array();
    var i = 0;
    
    var telefon = replaceAll(get('telefon1').value, ' ', '');
    if (telefon.length <9) { wynik = false; if (pokaz == true) { info[i++] = '- telefon'; } }

    if (wynik == false && info.length > 0 && pokaz == true) {
        var napis = "Proszę wprowadzić poprawny numer telefonu.";
        alert(napis);
    }
    return wynik;
}

function pl(id) {
    show_bar2();
    get('pl1').style.display = 'none';
    get('pl2').style.display = 'none';
    get('pl3').style.display = 'none';
    get('pl'+id).style.display = 'block';
}

function sprawdzAkceptacja() {
    wynik = false;
    if (get('akceptacja').checked) { wynik = true; }
    else { alert(kt['pa']); }
    return wynik;
}

function sprawdzPlatnosc(){
    wynik = false;
    var platnosc = get('platnosc_select').options[get('platnosc_select').selectedIndex].value;
    if (platnosc) { wynik = true; }
    else { alert(kt['wp']); }
    return wynik;
}

function sprawdzRejestracja() {
    var wynik = true;
    if (!checkInput('imie', 1)) { get('imie').className = 'error'; wynik=false; } else { get('imie').className ="pole"; }
    if (!checkInput('nazwisko', 1)) { get('nazwisko').className = 'error'; wynik=false; } else { get('nazwisko').className ="pole"; }
    if (!checkMail('email')) { get("email").className="error"; wynik=false; } else { get("email").className="pole"; }
    if (!checkInput('telefon', 1)) { get('telefon').className = 'error'; wynik=false; } else { get('telefon').className ="pole"; }
    if (get('jakwyzej1').checked == false) {
        if (!checkInput('firma_adres_wysylka', 1)) { get('firma_adres_wysylka').className = 'error'; wynik=false; } else { get('firma_adres_wysylka').className = 'pole'; }
        if (!checkInput('firma_miasto_wysylka', 1)) { get('firma_miasto_wysylka').className = 'error'; wynik=false; } else { get('firma_miasto_wysylka').className = 'pole'; }
        if (!checkInput('firma_kod_wysylka', 1)) { get('firma_kod_wysylka').className = 'error'; wynik=false; } else { get('firma_kod_wysylka').className = 'pole'; }
    }
    if (get('jakwyzej2').checked == false && get('jakwyzej3').checked == false) {
        // if (!checkInput('firma_nazwa', 1)) { get('firma_nazwa').className = 'error'; wynik=false; } else { get('firma_nazwa').className = 'pole'; }
        if (!checkInput('firma_adres', 1)) { get('firma_adres').className = 'error'; wynik=false; } else { get('firma_adres').className = 'pole'; }
        if (!checkInput('firma_miasto', 1)) { get('firma_miasto').className = 'error'; wynik=false; } else { get('firma_miasto').className = 'pole'; }
        if (!checkInput('firma_kod', 1)) { get('firma_kod').className = 'error'; wynik=false; } else { get('firma_kod').className = 'pole'; }
    }
    if (wynik==false){ alert(kt['pp']); }
    return wynik;
}

function pg(id)  {
    var i = 1;
    while (get('g'+i)) {
        if (i == id) { get('g'+i).style.display = 'block'; }
        else { get('g'+i).style.display = 'none'; }
        i++;
    }
}

function zpg(lp, id) {
    var pole = 'gw'+lp;
    var ilosc = parseFloat(get(pole).innerHTML);
    if (get('a'+id).checked) {
        ilosc = ilosc + 1;
    }
    else {
        ilosc = ilosc - 1;
    }
    get(pole).innerHTML = number_format(ilosc, 0, ',', ' ');
}

function checkKeyCode(e) {
	var keycode;
	if (window.event) 
		keycode = window.event.keyCode;
	else if (e) 
		keycode = e.which;
	if (keycode==13) {
        return true;
    }
    return false;
}

function przeliczCena() {
    var cena_produktu = parseFloat(get('cena_wyjsciowa').value);
    var lp = 0;
    while (get('ia'+lp)) {
        var wybrany = get('ia'+lp).options[get('ia'+lp).selectedIndex].text;
        pos = wybrany.indexOf('|');
        if (wybrany.substring(pos+2) == 'w cenie' || wybrany.substring(pos+2) == 'included') { cena = 0; }
        else { cena = parseFloat(wybrany.substring(pos+2).replace(',', '.')); }
        cena_produktu = cena_produktu+cena;
        lp++;
    }
    get('cena_produktu').innerHTML = number_format(cena_produktu, 2, ',', ' ');
    if (ln == 'pl') { get('cena_raty').innerHTML = number_format(cena_produktu*0.11, 0, ',', ' '); }
    if (www == 'librus') { get('cena_produktu2').innerHTML = number_format(cena_produktu*1.23, 2, ',', ' '); }
}

function akcesoriaSesja(lp, id_produktu, cecha) {
    var id = get('ia'+lp).options[get('ia'+lp).selectedIndex].value;
    parent.ustawienia.location.href = katalog_start+'ustawienia.php?i=1&id='+id+'&id_produktu='+id_produktu+'&cecha='+cecha;
}

// -->

