function NewWindow(mypage,myname,w,h,scroll){
	var win = null;
	LeftPosition = 0;
	TopPosition = 0;
	settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
	win = window.open(mypage,myname,settings)
}

function ZmienKolor(tedek,sciezka,akcja,wybranadata,obrazek,IdApartamentu){
	ImagePorownaj = 'url('+sciezka+'/checked.gif)';
	FirstImage = "FirstImage"+IdApartamentu;
	SecondImage = "SecondImage"+IdApartamentu;
	if (akcja == 1){
		if (tedek.style.backgroundImage == ImagePorownaj){
			if (obrazek == 0){
				tedek.style.backgroundImage = "";
			}else{
				tedek.style.backgroundImage = 'url('+sciezka+'/'+obrazek+')';
			}
			tedek.style.border = 'solid 1px #999999';
		}else{
			tedek.style.backgroundImage = 'url('+sciezka+'/checked.gif)';
			tedek.style.border = 'solid 1px #4cad23';
		}
			if (document.getElementById(FirstImage).value == ""){
				document.getElementById(FirstImage).value = 'url('+sciezka+'/'+obrazek+')';
			}else{
				document.getElementById(SecondImage).value = 'url('+sciezka+'/'+obrazek+')';
			}
		Rezerwuj(wybranadata,IdApartamentu);
	}else if(akcja == 2){
		if (obrazek == 0){
			tedek.bgColor = '#b3ffB3';
		}else{
			if (tedek.style.backgroundImage != ImagePorownaj){
				tedek.style.backgroundImage = 'url('+sciezka+'/najedz.gif)';
			}
		}
		tedek.style.border = 'solid 1px #4cad23';
		tedek.style.cursor = 'pointer';
	}else{
		if (obrazek == 0){
			tedek.bgColor = '#ffffff';
		}else{
			if (tedek.style.backgroundImage != ImagePorownaj){
			tedek.style.backgroundImage = 'url('+sciezka+'/'+obrazek+')';
			}
		}
		if (tedek.style.backgroundImage != ImagePorownaj){
			tedek.style.border = 'solid 1px #999999';
		}
		tedek.style.cursor = 'normal';
	}
}

function Rezerwuj(data,IdApartamentu){
	DataPrzyjazdu = "DataPrzyjazdu"+IdApartamentu;
	DataWyjazdu = "DataWyjazdu"+IdApartamentu;
	FirstImage = "FirstImage"+IdApartamentu;
	SecondImage = "SecondImage"+IdApartamentu;
	przyjazd = document.getElementById(DataPrzyjazdu);
	wyjazd = document.getElementById(DataWyjazdu);
	if(przyjazd.value == data){
		przyjazd.value = "";
	}else if(wyjazd.value == data){
		wyjazd.value = "";
	}else if(przyjazd.value == ""){
		przyjazd.value = data;
	}else if(wyjazd.value == ""){
		wyjazd.value = data;
	}else{
		if (data < przyjazd.value){
			KtoraKomorka = przyjazd.value;
			przyjazd.value = data;
		}else{
			KtoraKomorka = wyjazd.value;
			wyjazd.value = data;
		}
		if (document.getElementById(FirstImage).value == ""){
		document.getElementById(KtoraKomorka).style.backgroundImage = "";
		}else{
		document.getElementById(KtoraKomorka).style.backgroundImage = document.getElementById(FirstImage).value;
		}
		document.getElementById(KtoraKomorka).style.border = 'solid 1px #999999';

	}
	if (przyjazd.value != "" && wyjazd.value != ""){
		if (wyjazd.value < przyjazd.value){
			bufor = wyjazd.value;
			wyjazd.value = przyjazd.value;
			przyjazd.value = bufor;
			buforobrazek = document.getElementById(SecondImage).value;
			document.getElementById(SecondImage).value = document.getElementById(FirstImage).value;
			document.getElementById(FirstImage).value = buforobrazek;
		}
		potwierdzenie(IdApartamentu);
	}
}

function potwierdzenie(IdApartamentu) {
	DataPrzyjazdu = "DataPrzyjazdu"+IdApartamentu;
	DataWyjazdu = "DataWyjazdu"+IdApartamentu;
	IdRezerwacji = "rezerwacja"+IdApartamentu;
	FirstImage = "FirstImage"+IdApartamentu;
	SecondImage = "SecondImage"+IdApartamentu;
	var sprawdz = window.confirm("Czy chesz przejść do rezerwacji?");
	if (sprawdz == true) {
		document.getElementById(IdRezerwacji).submit();
		return true;
	}else{
		przyjazd = document.getElementById(DataPrzyjazdu);
		wyjazd = document.getElementById(DataWyjazdu);
		if (document.getElementById(FirstImage).value == ""){
			document.getElementById(przyjazd.value).style.backgroundImage = "";
		}else{
			document.getElementById(przyjazd.value).style.backgroundImage = document.getElementById(FirstImage).value;
		}
		document.getElementById(przyjazd.value).style.border = 'solid 1px #999999';
		przyjazd.value="";
		if (document.getElementById(SecondImage).value == ""){
		document.getElementById(wyjazd.value).style.backgroundImage = "";
		}else{
			document.getElementById(wyjazd.value).style.backgroundImage = document.getElementById(SecondImage).value;
		}
		document.getElementById(wyjazd.value).style.border = 'solid 1px #999999';
		wyjazd.value="";
		document.getElementById(FirstImage).value = "";
		document.getElementById(SecondImage).value = "";
	}
}

function ObliczCene(){
	document.rezerwuje.target='orderPrice';
	document.rezerwuje.action='/oblicz_kwote.php';
	document.rezerwuje.submit();
}

function FakturaSprawdz(){
	faktura = document.getElementById("FakturaAgree");
	firma = document.getElementById("FakturaFirma");
	ulica = document.getElementById("FakturaUlica");
	nrdomu = document.getElementById("FakturaNrDomu");
	nrmieszkania = document.getElementById("FakturaNrMieszkania");
	miejscowosc = document.getElementById("FakturaMiejscowosc");
	kod = document.getElementById("FakturaKodPocztowy");
	nip = document.getElementById("FakturaNIP");
	if (faktura.checked == true){
		firma.className = 'input';
		ulica.className = 'input';
		nrdomu.className = 'input';
		nrmieszkania.className = 'input';
		miejscowosc.className = 'input';
		kod.className = 'input';
		nip.className = 'input';
		firma.disabled = '';
		ulica.disabled = '';
		nrdomu.disabled = '';
		nrmieszkania.disabled = '';
		miejscowosc.disabled = '';
		kod.disabled = '';
		nip.disabled = '';
	}else{
		firma.className = 'input disabled';
		ulica.className = 'input disabled';
		nrdomu.className = 'input disabled';
		nrmieszkania.className = 'input disabled';
		miejscowosc.className = 'input disabled';
		kod.className = 'input disabled';
		nip.className = 'input disabled';
		firma.disabled = 'disabled';
		ulica.disabled = 'disabled';
		nrdomu.disabled = 'disabled';
		nrmieszkania.disabled = 'disabled';
		miejscowosc.disabled = 'disabled';
		kod.disabled = 'disabled';
		nip.disabled = 'disabled';
	}

}

function sprawdzForm(pagin,apartament){
	imie = document.getElementById("Imie");
	nazwisko = document.getElementById("Nazwisko");
	miejscowosc = document.getElementById("Miejscowosc");
	kraj = document.getElementById("Kraj");
	komorka = document.getElementById("NrKomorki");
	email = document.getElementById("EmailKonto");
	email_spr = document.getElementById("EmailSpr");
	regulamin = document.getElementById("Regulamin");
	if (imie.value == "" || nazwisko.value == "" || miejscowosc.value == "" || kraj.value == "" || komorka.value == "" || email.value == "" || email_spr.value == "" || regulamin.checked == false){
		alert("Proszę wypełnić wszystkie wymagane pola!");
	}else{
		document.rezerwuje.target='';
		document.rezerwuje.action='/apartamenty/'+pagin+'/'+apartament+'/rezerwuj';
		document.rezerwuje.submit();
	}
}

function ZapiszProfil(){
	imie = document.getElementById("Imie");
	nazwisko = document.getElementById("Nazwisko");
	miejscowosc = document.getElementById("Miejscowosc");
	kraj = document.getElementById("Kraj");
	komorka = document.getElementById("NrKomorki");
	email = document.getElementById("Email");
	if (imie.value == "" || nazwisko.value == "" || miejscowosc.value == "" || kraj.value == "" || komorka.value == "" || email.value == ""){
		alert("Proszę wypełnić wszystkie wymagane pola")
	}else{
		document.profil.submit();
	}
}
function sprawdzForm2(pagin,apartament){
	regulamin = document.getElementById("Regulamin");
	if (regulamin.checked == false){
		alert("Proszę zaznaczyć pole akceptacji regulaminu")
	}else{
		document.rezerwuje.target='';
		document.rezerwuje.action='/apartamenty/'+pagin+'/'+apartament+'/rezerwuj/krok1.html';
		document.rezerwuje.submit();
	}
}
function showLocal(robId) {
			var vlocal = window.open('/s/viewLocal.php5?ROB_ID='+robId, 'photoL', 'width=600,height=500,resizable=no,scrollbars=yes,toolbar=no,location=no,status=no,menubar=no');
			vlocal.focus();
			return false;
		}

function flash(id, kolor, czas, kolor2, czas2)
{
	document.getElementById(id).style.color = kolor;
	setTimeout('flash("' + id + '","' + kolor2 + '",' + czas2 + ',"' + kolor + '",' + czas + ')', czas);
}

function SubmitForm(pagin,apartament){
	document.rezerwuje.target='';
	document.rezerwuje.action='/apartamenty/'+pagin+'/'+apartament+'/rezerwuj/krok1.html';
	document.rezerwuje.submit();
}

function ZamowDowoz(){
	if(document.getElementById("Przywoz").checked == true){
		document.getElementById("IloscOsobPrzyjazd").disabled = "";
		document.getElementById("IloscOsobPrzyjazd").className = "inputSelect";
		document.getElementById("NrLotu").disabled = "";
		document.getElementById("NrLotu").className = "input";
		document.getElementById("GodzinaPrzylot").disabled = "";
		document.getElementById("GodzinaPrzylot").className = "inputSelect";
		document.getElementById("MinutyPrzylot").disabled = "";
		document.getElementById("MinutyPrzylot").className = "inputSelect";
	}else{
		document.getElementById("IloscOsobPrzyjazd").disabled = "disabled";
		document.getElementById("IloscOsobPrzyjazd").className = "inputSelect disabledSelect";
		document.getElementById("NrLotu").disabled = "disabled";
		document.getElementById("NrLotu").className = "input disabled";
		document.getElementById("GodzinaPrzylot").disabled = "disabled";
		document.getElementById("GodzinaPrzylot").className = "inputSelect disabledSelect";
		document.getElementById("MinutyPrzylot").disabled = "disabled";
		document.getElementById("MinutyPrzylot").className = "inputSelect disabledSelect";
	}
}

function ZamowOdwoz(){
	if(document.getElementById("Odwoz").checked == true){
		document.getElementById("IloscOsobWyjazd").disabled = "";
		document.getElementById("IloscOsobWyjazd").className = "inputSelect";
		document.getElementById("CzasNaLotnisko1").disabled = "";
		document.getElementById("CzasNaLotnisko2").disabled = "";
		PrzyjazdKierowcy()
	}else{
		document.getElementById("IloscOsobWyjazd").disabled = "disabled";
		document.getElementById("IloscOsobWyjazd").className = "inputSelect disabledSelect";
		document.getElementById("CzasNaLotnisko1").disabled = "disabled";
		document.getElementById("CzasNaLotnisko2").disabled = "disabled";
		document.getElementById("GodzinaWylot").disabled = "disabled";
		document.getElementById("GodzinaWylot").className = "inputSelect disabledSelect";
		document.getElementById("MinutyWylot").disabled = "disabled";
		document.getElementById("MinutyWylot").className = "inputSelect disabledSelect";
	}
}

function PrzyjazdKierowcy(){
		if(document.getElementById("CzasNaLotnisko2").checked == true){
			document.getElementById("GodzinaWylot").disabled = "";
			document.getElementById("GodzinaWylot").className = "inputSelect";
			document.getElementById("MinutyWylot").disabled = "";
			document.getElementById("MinutyWylot").className = "inputSelect";
		}else{
			document.getElementById("GodzinaWylot").disabled = "disabled";
			document.getElementById("GodzinaWylot").className = "inputSelect disabledSelect";
			document.getElementById("MinutyWylot").disabled = "disabled";
			document.getElementById("MinutyWylot").className = "inputSelect disabledSelect";
		}
}

function DodajKosztUslugi(idek,kwota,przelicznik,pole_przelicznika){
	PoleDozaplaty = document.getElementById("razem")
	Dozaplaty = parseInt(PoleDozaplaty.value);
	if(przelicznik == "no"){
		kwotaWstaw = kwota;
	}else if (przelicznik == "doba"){
		kwotaWstaw = Math.ceil(kwota*pole_przelicznika);
	}else if (przelicznik == "odwoz"){
		iloscOsob = document.getElementById(pole_przelicznika).value;
		if(iloscOsob > 0 && iloscOsob < 5){
			kwotaWstaw = 70;
		}else if(iloscOsob < 7){
			kwotaWstaw = 100;
		}else if(iloscOsob < 9){
			kwotaWstaw = 140;
		}else if(iloscOsob < 14){
			kwotaWstaw = 200;
		}else{
			kwotaWstaw = 280;
		}
	}
	if(document.getElementById(idek).checked == true){
		wyswietl = Dozaplaty+kwotaWstaw;
		PoleDozaplaty.value = wyswietl;
	}else{
		PoleDozaplaty.value = Dozaplaty-kwotaWstaw;
	}
}



function SprawdzTazeIlosc(elemelek, ylosc)
{
   var i = 0;

   for(j = 0; j < ylosc; j++)
   {
      nazwa_temp_p = 'radio_p_' + j;
      nazwa_temp_n = 'radio_n_' + j;

      radio_p = document.getElementById(nazwa_temp_p);
      radio_n = document.getElementById(nazwa_temp_n);

      if(radio_p.checked == true || radio_n.checked == true)
      {
         i++;
      }

      if(i > 12)
      {
         elemelek.checked = false;
         alert('Można zaznaczyć do 12 opcji.');
         break;
      }
   }
}



function ZerujTazeIlosc(ylosc)
{
   var i = 0;

   for(j = 0; j < ylosc; j++)
   {
      nazwa_temp_p = 'radio_p_' + j;
      nazwa_temp_n = 'radio_n_' + j;

      radio_p = document.getElementById(nazwa_temp_p);
      radio_n = document.getElementById(nazwa_temp_n);

      radio_p.checked = false;
      radio_n.checked = false;
   }
}

function Rozwin(){
    document.getElementById("ramka2").style.display = "none";
    document.getElementById("ramka3").style.display = "block";
}

function Zwin(){
    document.getElementById("ramka3").style.display = "none";
    document.getElementById("ramka2").style.display = "block";
}
