
 jQuery.noConflict();
jQuery(document).ready(function(){
//function ready2(){
	
	
	
	
	jQuery("#data_wylotu").datepicker(jQuery.extend({}, 
	jQuery.datepicker.regional["pl"],{
		showAnim: "",  
		duration:"",
    	minDate: "1d", 
    	numberOfMonths: 1, 
    	showOn: "both", 
    	buttonImage: "sky4fly/qbeif1/img/icon-kalendarz3.gif", 
    	buttonImageOnly: true 
	}));	
		jQuery("#data_powrotu").datepicker(jQuery.extend({}, 
	jQuery.datepicker.regional["pl"],{
		showAnim: "",  
		duration:"",
	 	minDate: "1d",
		numberOfMonths: 1, 
    	showOn: "both", 
    	buttonImage: "sky4fly/qbeif1/img/icon-kalendarz3.gif", 
    	buttonImageOnly: true 
	}));
	

	

	
	
		
}
);

function lupa(co)
{
	window.document.p=co.toUpperCase();
	window.document.f='panel';

	if (co=='zamknij')
	{
		if (document.getElementById('pop-up-loty-z').klik) lupa('z');
		if (document.getElementById('pop-up-loty-d').klik) lupa('d');
		
	}
	else
	{
		if (!document.getElementById('pop-up-loty-'+co).klik)
		{
			document.getElementById('pop-up-loty-'+co).klik=1;
			//jQuery('#pop-up-loty-'+co).fadeIn();
			jQuery('#pop-up-loty-'+co).show();
			if (co=='z') zpliku('sky4fly/qbeif1/atlas/atlas.html', 'lotniska_'+co);
			if (co=='d') zpliku('sky4fly/qbeif1/atlas/atlas_d.html', 'lotniska_'+co);
		}
		else
		{
			document.getElementById('pop-up-loty-'+co).klik=0;
			//jQuery('#pop-up-loty-'+co).fadeOut();
			jQuery('#pop-up-loty-'+co).hide();
		}
	}
	
	
	return true
};

function zamknij_iframe()
{
	if (document.getElementById('pop-up-loty-z').klik) lupa('z');
	if (document.getElementById('pop-up-loty-d').klik) lupa('d');
	//alert (doc.id);
	/*
	if (!parent.document.getElementById('pop-up-loty-z').klik)
	{
		parent.document.getElementById('pop-up-loty-z').klik=1;
		jQuery(".lupa").next(".pop-up-loty").fadeIn();
		zpliku('../atlas/atlas.html', 'if_wylot');
	}
	else
	{
		
		parent.document.getElementById('pop-up-loty-z').klik=0;
		//jQuery("parent.document.lupa").next(".pop-up-loty").fadeOut();
		//jQuery('parent.document#pop-up-loty-z').fadeOut();
		zamknij();
			
	}
	/**/
	return true
};

function zpliku(plik, element) {
 
  xml = null;
  document.getElementById(element).innerHTML="";
  try {
    xml = new ActiveXObject("Microsoft.XMLHTTP"); // IE
  } catch(e) {
    try {
      xml = new XMLHttpRequest(); // Mozilla/FireFox/Opera
    } catch(e) {
      xml = null;
    }
  }
  if (xml != null) {
    xml.onreadystatechange = function() {
      if (xml.readyState==4) {
	  var tresc;
	  tresc=xml.responseText;
	 // tresc=tresc.replace(/form/,"");
	  document.getElementById(element).innerHTML=tresc;
        
      }
    }
    xml.open("GET", plik, true);
    xml.send(null);
  }
}

function start()
{
	//ready2();
	//setTimeout("ready2()", 5000);

	//wstaw_date_pocz();
	//ustaw_helper();
}
function wstaw_date_pocz()
{
	
	var data = new Date();
	var godzina = data.getHours();
	var min = data.getMinutes();
	var dzien = data.getDate();
	var miesiac = data.getMonth()+1;
	var rok = data.getFullYear();
	var teraz = ""+((godzina<10)?"0":"")+godzina+((min<10)?":0":":")+min;
	
	
	dzien+=1;
	if (!czy_jest_data(dzien, miesiac, rok))
	{
		miesiac+=1;
		dzien=1;
	}
	if (dzien<10) dzienTxt="0"+dzien; 
	else dzienTxt=dzien;
	if (miesiac<10) miesiacTxt="0"+miesiac;	
	else miesiacTxt=miesiac;
	var wylot = rok+"-"+miesiacTxt+"-"+dzienTxt;	
	document.getElementById("data_wylotu").value=wylot;

	miesiac+=1;
	if (!czy_jest_data(dzien, miesiac, rok))
	{
		miesiac+=1;
		dzien=1;
	}
	if (dzien<10) dzienTxt="0"+dzien; 
	else dzienTxt=dzien;
	if (miesiac<10) miesiacTxt="0"+miesiac;	
	else miesiacTxt=miesiac;
	var powrot = rok+"-"+miesiacTxt+"-"+dzienTxt;
	document.getElementById("data_powrotu").value=wylot;
	
	//alert( jQuery('#data_wylotu').value);//value="x"
	

} 

function czy_jest_data(dzien, miesiac, rok) {
  miesiac = miesiac-1;
  d = new Date(rok,miesiac,dzien);
  if (dzien==d.getDate() && miesiac==d.getMonth() && rok==d.getFullYear())
    return true;
  else
    return false
}

function ustaw_helper()
{
	//document.getElementById('helperToolTip').style.top=32;
	//document.getElementById('helperToolTip').style.left=0;
	//--document.getElementById('helperList').style.top=32;
	//--document.getElementById('helperList').style.left=0;
	
	//document.getElementById('helperList').style.top=document.getElementById('miasto_z').style.top;
	//document.getElementById('helperList').style.left=document.getElementById('miasto_z').style.left;
	
	//miasto_d
	//helperToolTip2
	//helperList2
}

function wyslij_zap()
{
	//alert(Math.round(data_w_d));
	errorTxt="";
	error=0;

	
	//--- czy miasta ok
	if (!document.getElementById('miasto_z').value || document.getElementById('miasto_z').value=='')
	{
		error=1;
		errorTxt+="Nieokreślone miejsce wylotu.\n";
	}
	
	if (!document.getElementById('miasto_d').value || document.getElementById('miasto_d').value=='' || document.getElementById('miasto_d').value.search(/wybierz/)>0  || document.getElementById('miasto_d').value.search(/wpisz/)>0)
	{
		error=1;
		errorTxt+="Nieokreślone miejsce przylotu.\n";
	}

	//--- czy data ok
	data_w=document.getElementById('data_wylotu').value;
	data_w=data_w.split('-');
	data_w_r=Math.round(data_w[0]);
	data_w_m=Math.round(data_w[1]);
	data_w_d=Math.round(data_w[2]);
	if (data_w_r<=9) data_w_r="0"+String(data_w_r);
	if (data_w_m<=9) data_w_m="0"+String(data_w_m);
	if (data_w_d<=9) data_w_d="0"+String(data_w_d);	
	data_w_str=String(data_w_r)+String(data_w_m)+String(data_w_d);

	data_p=document.getElementById('data_powrotu').value;
	data_p=data_p.split('-');
	data_p_r=Math.round(data_p[0]);
	data_p_m=Math.round(data_p[1]);
	data_p_d=Math.round(data_p[2]);
	if (data_p_r<=9) data_p_r="0"+String(data_p_r);
	if (data_p_m<=9) data_p_m="0"+String(data_p_m);
	if (data_p_d<=9) data_p_d="0"+String(data_p_d);
	data_p_str=String(data_p_r)+String(data_p_m)+String(data_p_d)

	var data_d = new Date();
	var data_d_d = data_d.getDate();
	var data_d_m = data_d.getMonth()+1;
	var data_d_r = data_d.getFullYear();
	if (data_d_r<=9) data_d_r="0"+String(data_d_r);
	if (data_d_m<=9) data_d_m="0"+String(data_d_m);
	if (data_d_d<=9) data_d_d="0"+String(data_d_d);
	data_d_str=String(data_d_r)+String(data_d_m)+String(data_d_d)
	
	if (!czy_jest_data(data_w_d, data_w_m, data_w_r)) 
	{
		error=1;
		errorTxt+="Data wylotu jest niepoprawna.\n";
	}
	if (!czy_jest_data(data_p_d, data_p_m, data_p_r) && document.getElementById('daty_powrot').style.visibility!='hidden') 
	{
		error=1;
		errorTxt+="Data powrotu jest niepoprawna.\n";
	}
	if (data_w_str>=data_p_str && document.getElementById('daty_powrot').style.visibility!='hidden') 
	{
		error=1;
		errorTxt+="Data powrotu musi być późniejsza niż data wylotu.\n";
	}
	if (data_w_str<=data_d_str) 
	{
		error=1;
		errorTxt+="Data wylotu musi być poźniejsza.\n";
	}

	//--- czy w 1 strone
	if (document.getElementById('szukaj-polaczenia-box').elements['w_jedna'].checked)
	{
		document.getElementById('szukaj-polaczenia-box').elements['ow'].checked=true;
	}
	else document.getElementById('szukaj-polaczenia-box').elements['ow'].checked=false;
	

	
	





	if (error)
	{
		errorTxt+="\nProszę zmienić parametry szukania.";
		alert(errorTxt);
	}
	else 
	{
		document.getElementById('w_d').value=data_w_d;
		document.getElementById('w_m').value=data_w_m;
		document.getElementById('w_r').value=data_w_r;
		document.getElementById('p_d').value=data_p_d;
		document.getElementById('p_m').value=data_p_m;
		document.getElementById('p_r').value=data_p_r;

		
		document.getElementById('szukaj-polaczenia-box').submit();
	}
}

function engine_oneway(way)
{
	if (way) document.getElementById('daty_powrot').style.visibility='hidden';	
	else document.getElementById('daty_powrot').style.visibility='visible';
}

var ok = 0;
	function wyslij() {
	  if (ok==1) return true;
	  return false;
	}
	

function wlacz_select(isVisible)
{
	if (navigator.appName=="Microsoft Internet Explorer")
	{		
		if (isVisible) document.getElementById('poj-select').style.visibility='hidden';
		else document.getElementById('poj-select').style.visibility='visible';
	}
		
}

//function odslon_engine2()
//{
	//alert('zz');
	//getElementById('engine_index').style.visibility='visible';
//}

function odslon_engine()
{
	//start();
	
	try 
	{   
		if(document.getElementById('engine_index')) document.getElementById('engine_index').style.visibility='visible';
		if (document.getElementById('loading')) document.getElementById('loading').style.display='none'; 
		

	} catch(e) {};
}
function wylacz_cityhelper()
{
	helper1.showList(false);
	helper2.showList(false);
	//wylacz_kalendarz('on');
	
}

