function updateTransportCost( id )
{
    var poleSpan = document.getElementById( 'kosztTransportu' );
    var opcjaTransportu = id;
    var sumaKoszyka = document.getElementById( 'sumaKoszyka' );
    var sumaZawartosci = document.getElementById( 'sumaFormularza' ).value;
    var sposobTransportu = document.getElementById( 'sposobTransportu' );

    if( opcjaTransportu == '0' )
    {
        poleSpan.style.display = 'none';
        sumaKoszyka.innerHTML = sumaZawartosci;
        sposobTransportu.value = 0;
    }
    else
    {
        sposobTransportu.value = opcjaTransportu;
        poleSpan.style.display = 'inline';
        poleSpan.innerHTML = 'Cena: ' + kosztTransportu[opcjaTransportu] + ' pln';
        Koszt = Number(sumaZawartosci) + Number(kosztTransportu[opcjaTransportu]);
        KosztTotal = new Number( Koszt );
        sumaKoszyka.innerHTML = KosztTotal.toFixed( 2 );
    }
}

function checkPaymentType( wartosc, koszt )
{
    var poleSelect = document.getElementById( 'pay_type' );
    var poleZagla = document.getElementById( 'infoZagiel' );
    var suma = document.getElementById( 'sumaFormularza' ).value;
    var total = document.getElementById( 'sumaKoszyka' );
    var kosztPrzesylki = document.getElementById( 'koszt_platnosci' );

    if( koszt > 0 )
    {
        kosztPrzesylki.innerHTML = "Opłata: " + koszt.toFixed( 2 ) + " PLN<br /><br />";
    }
    else
    {
        kosztPrzesylki.innerHTML = "";
    }

    var Koszt = new Number( Number(suma) + Number(koszt) );
    total.innerHTML = Koszt.toFixed( 2 );

    if( wartosc == "pla" )
    {
        poleSelect.disabled = "";
    }
    else
    {
        poleSelect.disabled = "disabled";
    }
}

function okno(img)
{
pozX = Math.floor(((screen.width)/2)-25);
pozY = Math.floor(((screen.height)/2)-25);
fotowindow = window.open('/thumb/bigFoto.php?name=' + img, 'shop', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,fullscreen=no,channelmode=no,width=100,height=100, left=' + pozX + ', top=' + pozY);
fotowindow.focus();
}

function dodajOpinie()
{
    var pbutton = document.getElementById( 'dodajOpinieButton' );
    var formdiv = document.getElementById( 'formAddComment' );

    pbutton.style.display = 'none';
    formdiv.style.display = 'block';
}

function showAlert( text, error )
{
    var spanKomunikat = document.getElementById( 'trescKomunikatu' );
    var divKomunikat = document.getElementById( 'komunikat' );
    var Wleft = Math.floor( ( ( screen.width ) / 2 ) - 250 );
    var Wtop = Math.floor( ( ( screen.height ) / 2 ) - 150 );

    if (document.documentElement && document.documentElement.scrollTop)
        theTop = document.documentElement.scrollTop;
    else if (document.body)
        theTop = document.body.scrollTop

    Wtop = Wtop + theTop;
    divKomunikat.style.left = Wleft + "px";
    divKomunikat.style.top = Wtop + "px";
    divKomunikat.style.display = "block";
    if( error == 1 ) spanKomunikat.style.color = "red";
    spanKomunikat.innerHTML = text;
}

function hideAlert()
{
    var divKomunikat = document.getElementById( 'komunikat' );
    divKomunikat.style.display = "none";
}

function changeLargerPhoto( foto )
{
    var komorka = document.getElementById( 'largerPhoto' );
    var html = '';

    html += '<a href="javascript:void(0)" onclick="okno( \'' + foto + '\' )">';
    html += '<img src="/thumb/miniatura.php?rx=460&amp;name=' + foto + '" alt="" />';
    html += '</a>';

    komorka.innerHTML = html;
}

function fillAddressForm()
{
    var adresID = document.getElementById( 'istniejacyAdres' ).value;
    var imieF 	= document.getElementById( 'imie' );
    var nazwiskoF 	= document.getElementById( 'nazwisko' );
    var ulicaF 	= document.getElementById( 'ulica' );
    var kodF 	= document.getElementById( 'kod' );
    var miastoF 	= document.getElementById( 'miasto' );
	
	var firmaF 	= document.getElementById( 'firma' );
	var nipF 	= document.getElementById( 'nip' );
	var telefonF 	= document.getElementById( 'telefon' );
	var mailF 	= document.getElementById( 'mail' );
	
    if( adresID > 0 )
    {
        imieF.value  = imie[adresID];
        nazwiskoF.value = nazwisko[adresID];
        ulicaF.value = ulica[adresID];
        kodF.value	 = kod[adresID];
        miastoF.value= miasto[adresID];
		
		firmaF.value= firma[adresID];
		nipF.value= nip[adresID];
		telefonF.value= telefon[adresID];
		mailF.value= mail[adresID];
    }
    else
    {
        ulicaF.value = '';
        imieF.value = '';
        nazwiskoF.value = '';
        kodF.value	 = '';
        miastoF.value= '';
		firmaF.value= '';
		nipF.value= '';
		telefonF.value= '';
		mailF.value= '';
    }
}

function showSendAddressForm()
{
    var formularz 	= document.getElementById( 'adresWysylkiForm' );
    var etykieta = document.getElementById( 'addressFormLabel' );

    if( formularz.style.display == 'none' )
    {
        formularz.style.display = 'table-cell';
        etykieta.innerHTML = 'nie zmieniaj adresu wysyłki';
    }
    else
    {
        formularz.style.display = 'none';
        etykieta.innerHTML = 'wprowadź adres wysyłki, jeżeli jest inny niż adres powyżej';
    }
}

function clearLogin( pole )
{
    if( pole.value == 'login' ) pole.value = '';
}

function restoreLogin( pole )
{
    if( pole.value == '' ) pole.value = 'login';
}

function clearPass( pole )
{
    if( pole.value == 'hasło' )
    {
        pole.value = '';
        pole.type = 'password';
    }
}

function restorePass( pole )
{
    if( pole.value == '' )
    {
        pole.value = 'hasło';
        pole.type = 'text';
    }
}