function szukaj_szyb(){
	if(document.f1.kategorie.value!=""){
document.f1.action="index.php?ak=szukaj_szyb";
document.f1.submit()}
}
function wstecz(){
document.limit.action="index.php?ak=szukaj_szyb&wstecz=1";
document.limit.submit()
}
function wstecz_s(){
document.limit.action="index.php?ak=szczegol&wstecz=1";
document.limit.submit()
}
function szukaj_szczegol(){
if(document.f_s.kategorie_s.value!=""){
	document.f_s.action="index.php?ak=szczegol";
	document.f_s.submit()
	}
}

function addbookmark(){
var bookmarkurl="http://www.certafides.com"
var bookmarktitle="Certafdes"



window.external.AddFavorite(bookmarkurl,bookmarktitle)
}

function okno_foto(adres){

config='toolbar=no,location=no,directories=no,status=no,menubar=no,width=640,height=480'
config += 'scrollbars=no,resizable=no'
pop = window.open ("","pop",config)

pop.document.write('<html><head></head><body bgcolor=#FFFFFF  onclick="window.close()" style="margin-left:0px;margin-top:0px;">');
pop.document.write('<img src="'+adres+'">');
pop.document.write('</body></html>');
}
function powieksz(rozx,rozy,nazwa)
{
if (otwarte==1) 	{ if (noweokno.closed) {otwarte=0 } else { noweokno.close(); otwarte=0}
					};
nazwab=nazwa
noweokno=window.open("big.htm", "noweokno", "width="+rozx+", height="+rozy+", titlebar=yes, scrollbars=no");

otwarte=1;
}



function blokuj(){

document.f1.cena.options.length=0
document.f1.osob.options.length=0
cena=new Array()
cena[0]=new Option("","cena");
osob=new Array()
osob[0]=new Option("","");
for (i=0;i<cena.length;i++){
		document.f1.cena.options[i]=new Option(cena[i].text,cena[i].value)
	}
for (i=0;i<osob.length;i++){
		document.f1.osob.options[i]=new Option(osob[i].text,osob[i].value)
	}

if(document.f1.kategorie.value=="imprezy"){
	document.f1.data_od.disabled=0
	document.f1.cena.value=""
	document.f1.osob.value=""
	document.f1.cena.disabled="true"
	document.f1.osob.disabled="true"
}
if(document.f1.kategorie.value=="atrakcje"){
	document.f1.cena.value=""
	document.f1.osob.value=""
	document.f1.data_od.value=""
	document.f1.data_od.disabled="true"
	document.f1.cena.disabled="true"
	document.f1.osob.disabled="true"
}
if(document.f1.kategorie.value=="ex"){

	document.f1.data_od.disabled=0
	document.f1.cena.disabled=0
	
	
	
	
	cena=new Array()
	cena[0]=new Option("","cena");
	cena[1]=new Option(" < 30 ","0");
	cena[2]=new Option(" 30-50 ","30-50");
	cena[3]=new Option(" 50-70 ","50-70");
	cena[4]=new Option(" 70-100 ","70-100");
	cena[5]=new Option(" 100-150 ","100-150");
	cena[6]=new Option(" 150-200 ","150-200");
	cena[7]=new Option(" 200 > ","200");
		
	for (i=0;i<cena.length;i++){
		document.f1.cena.options[i]=new Option(cena[i].text,cena[i].value)
	}
	
	osob=new Array()
	osob[0]=new Option("","");
	osob[1]=new Option(" - 1 - ","1");
	osob[2]=new Option(" - 2 - ","2");
	osob[3]=new Option(" - 3 - ","3");
	osob[4]=new Option(" - 4 - ","4");
	osob[5]=new Option(" - 5 - ","5");
	osob[6]=new Option(" - 6 - ","6");
	osob[7]=new Option(" - 7 - ","7");
	osob[8]=new Option(" - 8 - ","8");
	osob[9]=new Option(" - 9 - ","9");
	osob[10]=new Option(" - 10 - ","10");
	osob[11]=new Option(" - 11 - ","11");
	osob[12]=new Option(" - 12 - ","12");
	osob[13]=new Option(" - 13 - ","13");
	osob[14]=new Option(" - 14 - ","14");
	osob[15]=new Option(" 15 >","15");

	for (i=0;i<osob.length;i++){
		document.f1.osob.options[i]=new Option(osob[i].text,osob[i].value)
	}
}

if(document.f1.kategorie.value=="kwatera"){

	document.f1.data_od.disabled=0
	document.f1.cena.disabled=0
	document.f1.osob.disabled=0
	
	
	cena=new Array()
	cena[0]=new Option("","cena");
	cena[1]=new Option(" < 70 ","0");
	cena[2]=new Option(" 70-100 ","70-100");
	cena[3]=new Option(" 100-150 ","100-150");
	cena[4]=new Option(" 150-220 ","150-220");
	cena[5]=new Option(" 220-300 ","220-300");
	cena[6]=new Option(" 300-400 ","300-400");
	cena[7]=new Option(" 400-600 ","400-600");
	cena[8]=new Option(" 600-900 ","600-900");
	cena[9]=new Option(" 900 > ","900");

	for (i=0;i<cena.length;i++){
		document.f1.cena.options[i]=new Option(cena[i].text,cena[i].value)
	}

	
    
	osob=new Array()
	osob[0]=new Option("","");
	osob[1]=new Option(" - 1 - ","1");
	osob[2]=new Option(" 2-3 ","2-3");
	osob[3]=new Option(" 4-5 ","4-5");
	osob[4]=new Option(" 5-8 ","5-8");
	osob[5]=new Option(" 8-12 ","8-12");
	osob[6]=new Option(" 12-18 ","12-18");
	osob[7]=new Option(" 18 > ","18");
	

	for (i=0;i<osob.length;i++){
		document.f1.osob.options[i]=new Option(osob[i].text,osob[i].value)
	}
              	
}
 
if(document.f1.kategorie.value=="mieszk"){

	

	document.f1.data_od.disabled=0
	document.f1.cena.disabled=0
	document.f1.osob.disabled=0
	
	cena=new Array()
	cena[0]=new Option("","cena");
	cena[1]=new Option(" < 20 ","0");
	cena[2]=new Option(" 20-30 ","20-30");
	cena[3]=new Option(" 30-45 ","30-45");
	cena[4]=new Option(" 45-60 ","45-60");
	cena[5]=new Option(" 60-80 ","80-100");
	cena[6]=new Option(" 100-150 ","100-150");
	cena[7]=new Option(" 150 > ","150");
	
	for (i=0;i<cena.length;i++){
		document.f1.cena.options[i]=new Option(cena[i].text,cena[i].value)
	}

	
    
	osob=new Array()
	osob[0]=new Option("","");
	osob[1]=new Option(" - 1 - ","1");
	osob[2]=new Option(" 2-3 ","2-3");
	osob[3]=new Option(" 4-5 ","4-5");
	osob[4]=new Option(" 5-8 ","5-8");
	osob[5]=new Option(" 8 > ","8");
	     
	for (i=0;i<osob.length;i++){
		document.f1.osob.options[i]=new Option(osob[i].text,osob[i].value)
	}
	
	
}
if(document.f1.kategorie.value=="pokoj"){

	

	document.f1.data_od.disabled=0
	document.f1.cena.disabled=0
	document.f1.osob.disabled=0
	
	cena=new Array()
	cena[0]=new Option("","cena");
	cena[1]=new Option(" < 20 ","0");
	cena[2]=new Option(" 20-30 ","20-30");
	cena[3]=new Option(" 30-45 ","30-45");
	cena[4]=new Option(" 45-60 ","45-60");
	cena[5]=new Option(" 60-80 ","80-100");
	cena[6]=new Option(" 100-150 ","100-150");
	cena[7]=new Option(" 150 > ","150");
	
	for (i=0;i<cena.length;i++){
		document.f1.cena.options[i]=new Option(cena[i].text,cena[i].value)
	}

	
    
	osob=new Array()
	osob[0]=new Option("","");
	osob[1]=new Option(" - 1 - ","1");
	osob[2]=new Option(" 2-3 ","2-3");
	osob[3]=new Option(" 4-5 ","4-5");
	osob[4]=new Option(" 5-8 ","5-8");
	osob[5]=new Option(" 8 > ","8");
	     
	for (i=0;i<osob.length;i++){
		document.f1.osob.options[i]=new Option(osob[i].text,osob[i].value)
	}


	}
}
function logoj(){
	//alert(document.logowanie.kl_haslo.value);
	
document.logowanie.kl_haslo.value=MD5(document.logowanie.kl_haslo.value);
document.logowanie.submit();
	
}


function wyzywienie(){

	if(document.f_s.wyz_cal.checked==1){
	
		document.f_s.wyz_ok.checked=0;
		document.f_s.wyz_ok.disabled=1;
		document.f_s.wyz_sni.checked=0;
		document.f_s.wyz_obi.checked=0;
		document.f_s.wyz_kol.checked=0;
		document.f_s.wyz_sni.disabled=1;
		document.f_s.wyz_obi.disabled=1;
		document.f_s.wyz_kol.disabled=1;
	}
	if(document.f_s.wyz_ok.checked==1){
	
		document.f_s.wyz_cal.checked=0;
		document.f_s.wyz_cal.disabled=1;
		document.f_s.wyz_sni.checked=0;
		document.f_s.wyz_obi.checked=0;
		document.f_s.wyz_kol.checked=0;
		document.f_s.wyz_sni.disabled=1;
		document.f_s.wyz_obi.disabled=1;
		document.f_s.wyz_kol.disabled=1;
	}
	
	if(document.f_s.wyz_sni.checked==1 && document.f_s.wyz_obi.checked==1 && document.f_s.wyz_kol.checked==1){
	
		document.f_s.wyz_sni.checked=0;
		document.f_s.wyz_obi.checked=0;
		document.f_s.wyz_kol.checked=0;
		document.f_s.wyz_sni.disabled=1;
		document.f_s.wyz_obi.disabled=1;
		document.f_s.wyz_kol.disabled=1;
		document.f_s.wyz_cal.checked=1;
		document.f_s.wyz_ok.checked=0;
		document.f_s.wyz_cal.disabled=0;
		document.f_s.wyz_ok.disabled=1;
	}
	if(document.f_s.wyz_sni.checked==1 || document.f_s.wyz_obi.checked==1 || document.f_s.wyz_kol.checked==1){
		
		document.f_s.wyz_cal.disabled=1;
		document.f_s.wyz_ok.disabled=1;
		
	}
	if(document.f_s.wyz_cal.checked==0 && document.f_s.wyz_ok.checked==0)
	{
		document.f_s.wyz_sni.disabled=0;
		document.f_s.wyz_obi.disabled=0;
		document.f_s.wyz_kol.disabled=0;
		document.f_s.wyz_cal.disabled=0;
		document.f_s.wyz_ok.disabled=0;
	}
	
	if(document.f_s.wyz_sni.value=="")
	{
		document.f_s.wyz_sni.disabled=1;
	}
	if(document.f_s.wyz_ok.value=="")
	{
		document.f_s.wyz_ok.disabled=1;
	}
	if(document.f_s.wyz_obi.value=="")
	{
		document.f_s.wyz_obi.disabled=1;
	}
	if(document.f_s.wyz_kol.value=="")
	{
		document.f_s.wyz_kol.disabled=1;
	}
	if(document.f_s.wyz_cal.value=="")
	{
		document.f_s.wyz_cal.disabled=1;
	}


}

function wycena(){

var cena_doby,ile_wyz,jakie_wyz,data_od,data_do;


//wyjatki cenowe zliczenie ilości dni



if(document.f_s.zwierze){

cena_doby=document.f_s.cena.value*1;
osob=document.f_s.osob.value*1;
dzieci_znizka=document.f_s.dzieci_znizka.value*0.01;
zwierze_cena=document.f_s.zwierze_cena.value*1;
max_os=document.f_s.max_os.value*1;
zwierze_cena=document.f_s.zwierze_cena.value*1;
dzieci=document.f_s.dzieci.value*1;
zwierze=document.f_s.zwierze.value*1;




var cena_posilku=0;

	for(x=0;x<document.f_s.length;x++){
	if(document.f_s.elements[x].type=="checkbox" && document.f_s.elements[x].checked==1){
		a=document.f_s.elements[x].value*1;
		
		cena_posilku=cena_posilku + a;
		}
	}
var suma=(zwierze*zwierze_cena)+((max_os-dzieci*dzieci_znizka)*cena_doby);
var jedzenie=(osob+dzieci*dzieci_znizka)*cena_posilku;
//alert(jedzenie);
var text=suma+jedzenie;
//document.getElementById("wycena").innerHTML=text+ " €";
return Math.round(text);
}
else{
//wycena dla sportu
if(document.f_s.osob){
	
	cena_doby=document.f_s.cena.value;
	osob=document.f_s.osob.value;
	data_od=document.f_s.data_od_s.value;
	data_do=document.f_s.data_do_s.value;

	//alert(date_roznica()*((cena_posilku*ile_pos)+(1*cena_doby)));
	var text=cena_doby*osob;
	//document.getElementById("wycena").innerText=text+ " €";
	return Math.round(text);
}

//wycena dla kwatery i mieszkania
if(document.f_s.wyz_osob){

	cena_doby=document.f_s.cena.value;
	ile_wyz=document.f_s.wyz_osob.value;
	data_od=document.f_s.data_od_s.value;
	data_do=document.f_s.data_do_s.value;
	ile_pos=document.f_s.wyz_osob.value;
	var cena_posilku=0;

for(x=0;x<document.f_s.length;x++){
	if(document.f_s.elements[x].type=="checkbox" && document.f_s.elements[x].checked==1){
		a=document.f_s.elements[x].value*1;
		
		cena_posilku=cena_posilku + a;
	}

}
	
  var text=Math.round((cena_posilku*ile_pos)+(1*cena_doby));
	//alert(text)
	//document.getElementById("wycena").innerText=text+ " €";
	return text;
	}

	}
}



function date_roznica(){
date1 = new Date();
date2 = new Date();
diff  = new Date();
data1_rozdzielona= new Array();
data2_rozdzielona= new Array();

if (document.f_s.data_od_s.value!="") {

data1_rozdzielona=document.f_s.data_od_s.value.split("-")

date1temp = new Date(data1_rozdzielona[0],data1_rozdzielona[1]-1,data1_rozdzielona[2]-1,0,0,0,0);
date1.setTime(date1temp.getTime());
}
//else return false; // otherwise exits

if (document.f_s.data_do_s.value!="") {
data2_rozdzielona=document.f_s.data_do_s.value.split("-")
date2temp = new Date(data2_rozdzielona[0],data2_rozdzielona[1]-1,data2_rozdzielona[2]-1,0,0,0,0);

date2.setTime(date2temp.getTime());
}
//else return false; // otherwise exits


diff.setTime(Math.abs(date1.getTime() - date2.getTime()));
timediff = diff.getTime();
days = Math.floor(timediff / (1000 * 60 * 60 * 24)); 


//document.f_s.roznica.value =days + " days, ";
//alert(days);
return days; // form should never submit, returns false
}


//data do wpisania



function date_roznica_2(data_od,data_do){
date1 = new Date();
date2 = new Date();
diff  = new Date();
data1_rozdzielona= new Array();
data2_rozdzielona= new Array();

if (data_od!="") {

data1_rozdzielona=data_od.split("-")

date1temp = new Date(data1_rozdzielona[0],data1_rozdzielona[1]-1,data1_rozdzielona[2]-1,0,0,0,0);
date1.setTime(date1temp.getTime());
}
//else return false; // otherwise exits

if (data_do!="") {
data2_rozdzielona=data_do.split("-")
date2temp = new Date(data2_rozdzielona[0],data2_rozdzielona[1]-1,data2_rozdzielona[2]-1,0,0,0,0);

date2.setTime(date2temp.getTime());
}
//else return false; // otherwise exits


diff.setTime(date1.getTime() - date2.getTime());
timediff = diff.getTime();
days = Math.floor(timediff / (1000 * 60 * 60 * 24)); 


//document.f_s.roznica.value =days + " days, ";
//alert(days);
return days; // form should never submit, returns false
}



//wyjatki cenowe





function tablica(){
	
date1 = new Date();
date2 = new Date();
diff  = new Date();	
wyj = new Array();
procent= new Array();
dni= new Array();
dni_wyjatku=new Array();
var d=0;
var z;
var porc_dany;
var ilosc_dni;
var cena_1=0;
var cena_2=-0
var cena;
rez = new Array();
//tablice wyjatków

for(z=0;z<document.f_s.a.value;z++)
{

	rok_od=eval("document.f_s.od_rok_"+z);
	mi_od=eval("document.f_s.od_mi_"+z);
	dz_od=eval("document.f_s.od_dz_"+z);

	rok_do=eval("document.f_s.do_rok_"+z);
	mi_do=eval("document.f_s.do_mi_"+z);
	dz_do=eval("document.f_s.do_dz_"+z);
	porc_dany=eval("document.f_s.procent_"+z);
	//alert(rok_od)
	dni[z]=0;
	wyj[z] = new Array();
	procent[z]=porc_dany.value;
	
	
	date1temp = new Date(1*(rok_od.value),1*mi_od.value-1,1*dz_od.value);
	date2temp = new Date(1*rok_do.value,1*mi_do.value-1,1*dz_do.value);

	date1.setTime(date1temp.getTime());
	date2.setTime(date2temp.getTime());
	diff.setTime(Math.abs(date1.getTime() - date2.getTime()));
	timediff = diff.getTime();
	dni_wyjatku[z] = Math.floor(timediff / (1000 * 60 * 60 * 24));

	//alert(dni_wyjatku);
	
	//uwaga data w js: miesiąc jest od 0-11
	
	var x;
	for(x=0;x<=(dni_wyjatku[z]+1);x++){
	//date1temp = new Date(1*rok_od.value,(1*mi_od.value),1*dz_od.value+x);
	//wyj[z][x-1]=date1temp.getFullYear()+"-"+(date1temp.getMonth()+1)+"-"+date1temp.getUTCDate();
	wyj[z][x]=new Date(1*rok_od.value,(1*mi_od.value)-1,1*dz_od.value+x);
	//alert(date1temp)
	}
	//alert(mi_od.value);
	//alert((1*mi_od.value)-1);
//wyj=document.f_s.wyj.value;
//alert(1*document.f_s.od_rok.value+" , "+1*document.f_s.od_mi.value-1+" , "+1*document.f_s.od_dz.value-1)


	}
	
	

	
	//tablica z dni rezerwowanych
if(document.f_s.sport_ex){
ilosc_dni=date_roznica()+1
}
else{
ilosc_dni=date_roznica()
}
//alert(dni_wyjatku[0]+" "+dni_wyjatku[1]);	


data1_rozdzielona=document.f_s.data_od_s.value.split("-")


var y;
	for(y=0;y<ilosc_dni;y++){
	var d=0;
	
	rez[y]=new Date(data1_rozdzielona[0],((1*data1_rozdzielona[1])-1),(1*data1_rozdzielona[2])+y);
	for(z=0;z<document.f_s.a.value;z++)
		{
		//dni[z]=10;
		//alert(dni[z]);
		for(x=0;x<=dni_wyjatku[z];x++){
				//alert(wyj[z][x].getTime()+" == "+rez[y].getTime());
				if(wyj[z][x].getTime()==rez[y].getTime()){
					d++;
					//alert(dni[z]+" z=>"+z+" x=>"+x)
					break;
				}
				/*if(x==0 && z==1){
					alert(wyj[z][x].getTime()+" == "+rez[y].getTime());
					}
				}
				if(dni[z-1]){
					//dni[z]=d-dni[z-1];
				}*/
				
			
		}
		dni[z]+=d;
		//dni[z]+=1;
	}	


}
ilosc_dni=parseFloat(ilosc_dni);

text=wycena();
//console.log('text'+text);
//alert (text);
for(z=z-1;z>=0;z--){
if(z>0){
dni[z]=parseFloat(dni[z])-parseFloat(dni[z-1]);
 /* to chyba niepotrzebne - ilosc dni nie powinna sie zmieniac ilosc_dni=ilosc_dni-dni[z]; */
	}
	if(procent[z]>0){
	//alert(dni[z]+" ->  "+procent[z]);
	cena_1=cena_1+text*dni[z]*procent[z]*0.01;
	
	}
	else{
		cena_2=cena_2+text*dni[z]*procent[z]*0.01;
		
    ;}
//console.log('cena_2'+cena_2);
}


//alert (cena_1);
//console.log('cena_1'+cena_1);
//console.log('cena_2'+cena_2);
//console.log('ilosc_dni'+ilosc_dni);
//console.log('text'+text);
//alert (ilosc_dni);
cena=(ilosc_dni*text)+cena_2+cena_1;
//alert(cena);
if(document.f_s.ka_rodzaj.value=="s" && cena>0){
	cena=cena+document.f_s.ka_koszt.value*1;
}



if(document.f_s.ka_rodzaj.value=="p" && cena>0){
	cena=cena+(cena*document.f_s.ka_koszt.value)*0.01;
}
if(cena>0){
	cena=cena+document.f_s.koszt_rez.value*1
}
if(cena>=document.f_s.ubez_od.value){
	cena=cena+document.f_s.ubez_cena.value*1
}

document.getElementById("wycena").innerHTML=Math.round(cena)+ " €";
/*
alert (text);
alert(parseFloat(text));
alert (ilosc_dni);
alert(dni[0]+" - "+procent[0]);

alert(dni[1]+" - "+procent[1]);*/


document.f_s.wycena.value=cena;
}

////////////////////////

//Wycena turnusu

///////////////////////

function wycena_t(){
var x;
var a=0;
var cena=0;



cena_os=document.turnus.cena_tur.value;

		
		osob=eval("document.turnus.osob");
		pok_os=eval("document.turnus.pok_miejsc");
		dzieci=eval("document.turnus.dzieci");
	
		//alert(cena_os);
		
		if(document.turnus.dziecko && dzieci.value!=''){
			//alert(dzieci.value);
			cena+=(0.01*document.turnus.puste.value*cena_os*(pok_os.value-osob.value))+(cena_os*osob.value)-(cena_os*dzieci.value*document.turnus.dziecko.value*0.01);
		}
		else{
			cena+=(0.01*document.turnus.puste.value*cena_os*(pok_os.value-osob.value))+(cena_os*osob.value);
			}

if(document.turnus.ka_rodzaj.value=="s" && cena>0){
	cena=cena+document.turnus.ka_koszt.value*1;
}

if(document.turnus.ka_rodzaj.value=="p" && cena>0){
	cena=cena+(cena*document.turnus.ka_koszt.value)*0.01;
}
if(cena>0){
	cena=cena+document.turnus.koszt_rez.value*1
}
if(cena>=document.turnus.ubez_od.value){
	cena=cena+document.turnus.ubez_cena.value*1
}		
	
	
document.getElementById("wycena").innerHTML=Math.round(cena)+ " €";
document.turnus.wycena.value=Math.round(cena);
}
function wycena_tex()
{

	cena=document.turex.osob.value*document.turex.cena.value;

if(document.turex.ka_rodzaj.value=="s" && cena>0){
	cena=cena+document.turex.ka_koszt.value*1;
}

if(document.turex.ka_rodzaj.value=="p" && cena>0){
	cena=cena+(cena*document.turex.ka_koszt.value)*0.01;
}
if(cena>0){
	cena=cena+document.turex.koszt_rez.value*1
}
if(cena>=document.turex.ubez_od.value){
	cena=cena+document.turex.ubez_cena.value*1
}


document.getElementById("wycena").innerHTML=Math.round(cena)+ " €";
document.turex.wycena.value=Math.round(cena);

}
function typ()
{
	document.rez_szcz.submit();
}
