function okno(url, width, height)
{
    window.open(url, "okno", 'width=' + width + ', height=' + height + ', resizable=0, scrollbars=yes, menubar=no');
}

function okno2(url, width, height)
{
    window.open(url, "okno", 'width=' + width + ', height=' + height + ', resizable=0, scrollbars=no, menubar=no');
}

function sprawdz_dokosza()
{
    with (document.forms[0])
    {
        if (jaki_material() == 'Samoprzylepna' || jaki_material() == 'Winylowa')
		{
			if (szerokosc.value == '' || wysokosc.value == '')
			{
				alert('Prosze wybrać rozmiar naklejki.');
            	return false;
			}
			else return true;
		}
		
		if (typeof(rozmiar.length) == "undefined")
		{
			if (rozmiar.checked) s = true; else s = false;			
		}
		else
		{
			s = false;
			len = rozmiar.length;
			
			for (i = 0; i < len; i++)
			{
				if (rozmiar[i].checked)
				{
					s = true;
				}
			}
		}
		
		if (s == false)
		{
			alert('Prosze wybrać rozmiar naklejki.');
            return false;
		}
        else if (kolor.value == '')
        {
            alert('Prosze podać wybrany kolor naklejki.');
            return false;
        }
    }
}

function liczba(a)
{
    with (document.forms[0])
    {
        if ( !/^(\d+|)\d+$/i.test(a.value))
        {
            alert('Przepraszamy, ale w tym polu można wpisać tylko liczbę naturalną.');
            a.value = '1';
            a.focus();
            a.select();
            return false;
        }
        
        if(a.value < 1)
        {
           a.value = '1';
           return false;
        }
        else
        {
            return true;
        }
    }
}

function sprawdz_email(x)
{
    with (document.forms[0])
    {
        if ( !/^[\w\.-]+@([\w-]+\.)*[a-z]{2,4}$/i.test(x.value))
        {
            alert('Adres e-mail jest nieprawidłowy!');
            x.focus();
            x.select();
            return false;
        }
        else
        {
            return true;
        }
    }
}

function sprawdz_zamowienie(a)
{

    if (a == '0')
    {
        if (document.zamowienie.zamawiajacy.value == '0')
        {
            alert('Aby dokonać zakupu, proszę się zalogować lub zarejestrować.');
            return false;
        }
    }
    if (document.zamowienie.przesylka.value == '0')
    {
        alert('Proszę wybrać formę przesyłki.');
        document.zamowienie.przesylka.focus();
        return false;
    }
    else if (document.zamowienie.zamawiajacy.value == '0')
    {
        if (document.zamowienie.imie.value == '')
        {
            alert('Proszę podać swoje imię.');
            document.zamowienie.imie.focus();
            return false;
        }
        else if (document.zamowienie.nazwisko.value == '')
        {
            alert('Proszę podać swoje nazwisko.');
            document.zamowienie.nazwisko.focus();
            return false;
        }
        else if (document.zamowienie.email.value == '')
        {
            alert('Proszę podać swój e-mail.');
            document.zamowienie.email.focus();
            return false;
        }
        else if (document.zamowienie.telefon.value == '')
        {
            alert('Proszę podać swój telefon.');
            document.zamowienie.telefon.focus();
            return false;
        }
        else if (document.zamowienie.ulica.value == '')
        {
            alert('Proszę podać ulicę.');
            document.zamowienie.ulica.focus();
            return false;
        }
        else if (document.zamowienie.nr_domu.value == '')
        {
            alert('Proszę podać numer domu.');
            document.zamowienie.nr_domu.focus();
            return false;
        }
        else if (document.zamowienie.miejscowosc.value == '')
        {
            alert('Proszę podać miejscowość.');
            document.zamowienie.miejscowosc.focus();
            return false;
        }
        else if (document.zamowienie.kod_pocztowy.value == '')
        {
            alert('Proszę podać kod pocztowy.');
            document.zamowienie.kod_pocztowy.focus();
            return false;
        }
        else if (document.zamowienie.wojewodztwo.value == '')
        {
            alert('Proszę podać województwo.');
            document.zamowienie.wojewodztwo.focus();
            return false;
        }
        if (document.zamowienie.email.value != '')
        {
            if ( !/^[\w\.-]+@([\w-]+\.)*[a-z]{2,4}$/i.test(document.zamowienie.email.value))
            {
                alert('Adres e-mail jest nieprawidłowy!');
                document.zamowienie.email.focus();
                document.zamowienie.email.select();
                return false;
            }
        }
    }
    else
    {
          return true;
    }
}

function foto(a, b)
{
	document.getElementById("akt_foto").src = "galerie/img/"+a;
   
    document.getElementById(a).style.display = "none";
	document.getElementById(b).style.display = "block";
}

function sprawdz_newsletter(a)
{
    var x;

    if (document.newsletter.email.value == '')
    {
        if (a == 'dodaj')
        {
            alert('Proszę podać e-mail który ma zostać dopisany do newslettera.');
        }
        else if (a == 'usun')
        {
            alert('Proszę podać e-mail który ma zostać usunięty z newslettera.');
        }
        document.newsletter.email.focus();
        return false;
    }
    if (document.newsletter.email.value != '')
    {
        if ( !/^[\w\.-]+@([\w-]+\.)*[a-z]{2,4}$/i.test(document.newsletter.email.value))
        {
            alert('Adres e-mail jest nieprawidłowy!');
            document.newsletter.email.focus();
            document.newsletter.email.select();
            return false;
        }
    }
    if (document.newsletter.email.value != '')
    {
        if (window.ActiveXObject)
        {
            x = new ActiveXObject('Microsoft.XMLHTTP');
        }
        else if (window.XMLHttpRequest)
        {
            x = new XMLHttpRequest();
        }
        if (x)
        {
            x.open('GET','files/ajax/ajax.php?d=newsletter&v='+a+'&v2='+document.newsletter.email.value,true);
            x.onreadystatechange = function()
            {
                if (x.readyState == 4)
                {
                    if (x.responseText == "1")
                    {
                        if (a == 'dodaj')
                        {
                            alert('Dziękujemy! Twój e-mail dostał dopisany do newslettera.');
                            document.newsletter.email.value = '';
                        }
                        else if (a == 'usun')
                        {
                            alert('Dziękujemy! Twój e-mail dostał usunięty z newslettera.');
                            document.newsletter.email.value = '';
                        }
                    }
                    else if (x.responseText == "2")
                    {
                        if (a == 'dodaj')
                        {
                            alert('Przepraszamy, ale podany adres e-mail instnieje już w naszej bazie danych.');
                            document.newsletter.email.value = '';
                        }
                        else if (a == 'usun')
                        {
                            alert('Przepraszamy, ale podany adres e-mail nie instnieje w naszej bazie danych.');
                            document.newsletter.email.value = '';
                        }
                    }
                }
            }
            x.send(null);
        }
    }
}

function pokaz_ukryj(a)
{
	for (var i=0; i<=200; i++)
	{
		if (document.getElementById('roz_'+i)) document.getElementById('roz_'+i).style.display = 'none';
	}
	document.getElementById('roz_'+a).style.display = 'block';
}

function pokaz(a, b)
{
	if (a == 'foto') 
	{
		document.getElementById('mat_pow').style.display = 'none';
		document.getElementById('mat_foto').style.display = 'block';
		document.produkt.szerokosc.value = '';
		document.produkt.wysokosc.value = '';
		
		if (b == 's')
		{
			document.produkt.kolor.value = 'Fototapeta samoprzylepna';
			document.getElementById('kolor_js').innerHTML = 'Fototapeta samoprzylepna';
		}	
		else if (b == 'w')
		{
			document.produkt.kolor.value = 'Fototapeta winylowa';
			document.getElementById('kolor_js').innerHTML = 'Fototapeta winylowa';
		}
		
		document.getElementById('cena_js').innerHTML = '<b>-</b>';	
		document.getElementById('rozmiar_js').innerHTML = '<b>-</b>';	
		return;
	}
	
	with (document.forms[0])
    {
		s = false;
		len = rozmiar.length;
			
		for (i = 0; i < len; i++)
		{
			if (rozmiar[i].checked && a != 10) rozmiar[i].checked = false;
		}
	}	
	
	if (a != 10) 
	{
		document.getElementById('cena_js').innerHTML = '<b>-</b>';
		document.getElementById('rozmiar_js').innerHTML = '<b>-</b>';
	}
	
	if (document.getElementById('mat_pow')) document.getElementById('mat_pow').style.display = 'none';
	if (document.getElementById('mat_0')) document.getElementById('mat_0').style.display = 'none';
	if (document.getElementById('mat_10')) document.getElementById('mat_10').style.display = 'none';
	if (document.getElementById('mat_15')) document.getElementById('mat_15').style.display = 'none';
	if (document.getElementById('mat_25')) document.getElementById('mat_25').style.display = 'none';
	if (document.getElementById('mat_40')) document.getElementById('mat_40').style.display = 'none';
	if (document.getElementById('mat_60')) document.getElementById('mat_60').style.display = 'none';
	if (document.getElementById('mat_350')) document.getElementById('mat_350').style.display = 'none';
	if (document.getElementById('mat_pol')) document.getElementById('mat_pol').style.display = 'none';
	if (document.getElementById('mat_foto')) document.getElementById('mat_foto').style.display = 'none';
	document.getElementById('mat_'+a).style.display = 'block';
	
	switch(a)
	{
		case 0:
		  document.getElementById('sel_col_1').style.display = 'block';
		  document.getElementById('sel_col_2').style.display = 'none';
		  document.getElementById('sel_col_3').style.display = 'none';
		  document.getElementById('sel_col_4').style.display = 'none';
		  if (b == 'm')
		  {
		  	  document.produkt.kolor.value = '';
			  document.getElementById('kolor_js').innerHTML = 'Folia matowa';
		  }	  
		  else if  (b == 'p')
		  {
	     	 document.produkt.kolor.value = '';
			 document.getElementById('kolor_js').innerHTML = 'Plakat';
		  }
		  else if  (b == 'o')
		  {
	     	 document.produkt.kolor.value = '';
			 document.getElementById('kolor_js').innerHTML = 'Obraz';
		  }
		  else
		  {
	     	 document.produkt.kolor.value = '';
			 document.getElementById('kolor_js').innerHTML = 'Folia błyszcząca';
		  }
		  break;
		case 15:
		  document.getElementById('sel_col_1').style.display = 'none';
		  document.getElementById('sel_col_2').style.display = 'none';
		  document.getElementById('sel_col_3').style.display = 'none';
		  document.getElementById('sel_col_4').style.display = 'none';
		  document.produkt.kolor.value = 'Folia szablonowa';
		  document.getElementById('kolor_js').innerHTML = 'Folia szablonowa';
		  break;
		case 25:
		  document.getElementById('sel_col_1').style.display = 'none';
		  document.getElementById('sel_col_2').style.display = 'none';
		  document.getElementById('sel_col_3').style.display = 'none';	
		  document.getElementById('sel_col_4').style.display = 'none';
		  if (b == 'w')
		  {
			  document.getElementById('kolor_js').innerHTML = 'Folia witrażowa';
			  document.getElementById('sel_col_4').style.display = 'block';
		  }	
		  else
		  {
			  document.produkt.kolor.value = 'Folia mrożona';
		  	  document.getElementById('kolor_js').innerHTML = 'Folia mrożona';
		  }		  	  
		  break;
		case 40:
		  document.getElementById('sel_col_1').style.display = 'none';
		  document.getElementById('sel_col_2').style.display = 'none';
		  document.getElementById('sel_col_3').style.display = 'block';
		  document.getElementById('sel_col_4').style.display = 'none';
		  document.produkt.kolor.value = '';
		  document.getElementById('kolor_js').innerHTML = 'Folia odblaskowa';
		  break;  
		case 60:
		  document.getElementById('sel_col_1').style.display = 'none';
		  document.getElementById('sel_col_2').style.display = 'block';
		  document.getElementById('sel_col_3').style.display = 'none';
		  document.getElementById('sel_col_4').style.display = 'none';
		  document.produkt.kolor.value = '';
		  document.getElementById('kolor_js').innerHTML = 'Folia fluorescencyjna';
		  break;
		case 350:
		  document.getElementById('sel_col_1').style.display = 'none';
		  document.getElementById('sel_col_2').style.display = 'none';
		  document.getElementById('sel_col_3').style.display = 'none';
		  document.getElementById('sel_col_4').style.display = 'none';
		  document.produkt.kolor.value = 'Folia fotoluminescencyjna';
		  document.getElementById('kolor_js').innerHTML = 'Folia fotoluminescencyjna';
		  break;   
	}
}

function jaki_material()
{
	with (document.forms[0])
    {
		s = false;
		len = material.length;
			
		for (i = 0; i < len; i++)
		{
			if (material[i].checked) return material[i].value;
		}
	}
}

function kolor_res()
{
	document.getElementById('kolor_sel_1').selectedIndex = 0;
	document.getElementById('kolor_sel_2').selectedIndex = 0;
	document.getElementById('kolor_sel_3').selectedIndex = 0;
	document.getElementById('kolor_sel_4').selectedIndex = 0;
}

function oblicz_cene(samoprzylepna, winylowa)
{	
	if (jaki_material() == 'Samoprzylepna')
	{
		cena = Math.round((document.produkt.szerokosc.value * document.produkt.wysokosc.value / 10000) * samoprzylepna);
		document.produkt.rozmiar.value = document.produkt.szerokosc.value+'x'+document.produkt.wysokosc.value+'-'+cena;
		document.getElementById('rozmiar_js').innerHTML = '<b>'+document.produkt.szerokosc.value+'x'+document.produkt.wysokosc.value+' cm</b>';
		document.getElementById('cena_js').innerHTML = '<b>'+cena+' zł</b>';
	}
	else if (jaki_material() == 'Winylowa')
	{
		cena = Math.round((document.produkt.szerokosc.value * document.produkt.wysokosc.value / 10000) * winylowa);
		document.produkt.rozmiar.value = document.produkt.szerokosc.value+'x'+document.produkt.wysokosc.value+'-'+cena;
		document.getElementById('rozmiar_js').innerHTML = '<b>'+document.produkt.szerokosc.value+'x'+document.produkt.wysokosc.value+' cm</b>';
		document.getElementById('cena_js').innerHTML = '<b>'+cena+' zł</b>';
	}
}


