// JavaScript Document

	function goToStartWeb(timer)
	{
		timer--;
		if(timer == -1)
		{		
			var href = window.location.host;
			var path = window.location.pathname;
			
			var end = path.toString().indexOf("/",1);
			
			//alert(path + " end " + end);
			
			if(end != 0)
			{
				var adress = "http://" + href + path.substr(0,end) + "/";
			}
			else
			{
				var adress = "http://" + href;
			}
			
			//alert(adress);
			
			//document.location = "http://www.psew.pl/en/";
			document.location = adress;
		}
		else
		{
			//alert(document.getElementById('timer'));
			document.getElementById('timer').innerHTML = timer;
			setTimeout("goToStartWeb(" + timer + ")", 1000);
		}
	}

	function countProdukt(obj)
	{
		if(obj)
		{
			var text = obj.value;
			
			var value = parseInt(text);
			if(!value)
			{
				obj.value = 0;
			}
			else
			{
				obj.value = value;
			}
		}
	}
	
	function oneWay(obj)
	{
		if(obj.checked) 
		{ 
			document.getElementById('return_data').disabled = true; 
		} 
		else
		{ 
			document.getElementById('return_data').disabled = false; 
		}
	}	
	
	function setWay(obj,pos)
	{
		for (var i=0; i<obj.options.length; i++)
		{
			if(obj.options[i].value == pos)
			{
				obj.options[i].selected = 'selected';
			}		 
		}
	}
	
	function checkWay(obj)
	{	
		var selectCity = '';
		
		for(var i = 0; i < przystanki.length; i++)
		{
			if(przystanki[i][0] == obj.value)
			{
				selectCity = przystanki[i][2];
				break;
			}
		}
		
		var select = document.getElementById('end_to');
		
		
		for(;;)
		{
			for (var i=0;i<select.options.length;i++)
			{
				select.options[i]=null;		 
			}
			if(select.options.length == 0) break;
		}
		select.options[0] = new Option('-- Ankunft --','');	
		
		var r = 1;	
		for(var i = 0; i < przystanki.length; i++)
		{	
			if(przystanki[i][2] != selectCity)
			{
				select.options[r] = new Option(przystanki[i][1] + ' - ' + przystanki[i][2],przystanki[i][0]);
				r++;
			}											
		}
		
        select.options[1].selected = "1";
		select.disabled = false;	
	}
	
	function rezerwacja()
	{
		if($('#start_from').val() && $('#end_to').val()){
			$('#rezerwacja_kursu').submit();
		} else {	
			if ($('#start_from').val()) { 
				$('#start_from').css('border','2px solid #C1D1F5');
			} else {
				$('#start_from').css('border','2px solid #FF0000');
			}
			
			if ($('#end_to').val()) {
				$('#end_from').css('border','2px solid #C1D1F5');
			} else {
				$('#end_from').css('border','2px solid #FF0000');
			}
			
			alert('Bitte rot markierte Felder ausfüllen');
		}
	}
	
	function rezerwacjaD()
	{			
		if($('#start_d').val()) {
			$('#szukaj_d').submit();
		} else {
			if ($('#start_d').val()) {
				$('#start_d').css('border','2px solid #C1D1F5');
			} else {
				$('#start_d').css('border','2px solid #FF0000');
			}
			
			alert('Bitte rot markierte Felder ausfüllen');
		}
	}
	
	function setFromPoint(obj)
	{
		var div = document.getElementById('rez_wyjazd');
		var diva = div.getElementsByTagName('div');
	
		for(var i = 0; i < diva.length; i++)
		{				
			if(diva[i].align == 'center')
			{
				if(diva[i].id == obj.id)
				{
					diva[i].className = 'rez_wyj_e';
					document.trasa.to_hour.value = obj.id;
				}
				else
				{
					diva[i].className = 'rez_wyj_d';
				}		
			}
		}	
	}
	
	function setToPoint(obj)
	{
		var div = document.getElementById('rez_powrot');
		var diva = div.getElementsByTagName('div');
	
		for(var i = 0; i < diva.length; i++)
		{				
			if(diva[i].align == 'center')
			{
				if(diva[i].id == obj.id)
				{
					diva[i].className = 'rez_pow_e';
					document.trasa.from_hour.value = obj.id;
				}
				else
				{
					diva[i].className = 'rez_pow_d';
				}		
			}
		}	
	}
	
	function checkRez()
	{
		if(document.trasa.no_return.value)
		{
			if(document.trasa.to_hour.value)
			{
				document.trasa.submit();
			}
			else
			{
				alert('Bitte Datum auswählen');
			}
		}
		else
		{
			if(document.trasa.to_hour.value  && document.trasa.from_hour.value)
			{
				document.trasa.submit();
			}
			else
			{
				alert('Bitte Datum auswählen');
			}
		}
	}
	
	
	function b(obj)
	{
		if(obj.lang == 'a')
		{
			obj.src = 'panel/' + obj.name + '_n.png';
			obj.lang = 'n';
		}
		else
		{
			obj.src = 'panel/' + obj.name + '.png';
			obj.lang = 'a';
		}
	}
	
	function s(id,nid)
	{
		document.getElementById(id).style.display = 'block';
		document.getElementById(nid).style.display = 'none';
	}
	
	function p(pid,spid)
	{
		if(document.getElementById('div_' + pid).style.display != 'block' )
		{		
			s('div_' + pid,'div_' + spid);
			b(document.getElementById(pid));
			b(document.getElementById(spid));
		}
	}
	
	function checkForm(forma,id_inp){
		
		var formularz = $('#'+forma);
		var id_ary = id_inp.toString().split(",");
		var all_ok = true;
		
		for(i = 0; i < id_ary.length; i++)
		{
			var sdiv = $('#'+id_ary[i]);
			if(sdiv.val()){
				sdiv.css('border','2px solid #C1D1F5');
			} else 	{
				all_ok = false;
				sdiv.css('border','2px solid #FF0000');
			}
		}
		
		if(all_ok) 
		{
			formularz.submit(); 
		}
		else
		{
			alert('Bitte rot markierte Felder ausfüllen');			
		}
	}
	
	function checkPerson()
	{
		var id_ary = new Array('req_imie','req_nazwisko','req_telefon','req_street','req_house','req_city','req_email');
		var id_aary = new Array('reu_imie_a[]','reu_nazwisko_a[]','reu_imie_b[]','reu_nazwisko_b[]','reu_imie_c[]','reu_nazwisko_c[]');	
		
		var all_ok = true;
		
		for(i = 0; i < id_ary.length; i++)
		{	
			var divv = document.getElementById(id_ary[i]);		
			if(!document.all)
			{
				if(divv.value == '')
				{
					divv.style.border = '2px solid red;';
					all_ok = false;							
				}
				else
				{
					divv.style.border = '2px solid #C1D1F5';
				}	
			}							
		}
		
		for(j = 0; j < id_aary.length; j++)
		{				
			var inp = document.getElementsByName(id_aary[j]);
			for(n = 0; n < inp.length; n++)
			{			
				if(!document.all)
				{
					if(inp[n].value == '')
					{
						inp[n].style.border = '2px solid red;';
						all_ok = false;
					}
					else
					{
						inp[n].style.border = '2px solid #C1D1F5';						
					}				
				}						
			}					
		}
		
		if(all_ok)
		{
			document.getElementById('next').submit();
		}
		else
		{
			if(!document.all)
			{
				alert('Bitte rot markierte Felder ausfüllen');
			}
			else
			{
				alert('Musisz wype³niæ wszystkie pola');
			}
		}
		
	}
	
	
	function nOkno(url) 
	{
		var Win = window.open("text.php5?id=" + url,"displayWindow",'width=500,height=300,resizable=1,scrollbars=yes,menubar=no');
	}

	var xmlHttp;

	function showHint(str)
	{
		if (str.length < 3)
		{ 						
		  	return;
		}
		
		xmlHttp=GetXmlHttpObject();
		 
		var url="up.php";
		url=url+"?q="+str;
		var ie = (document.all ? '1' : '0');
		url=url+"&ie="+ie;
		url=url+"&sid="+Math.random();
		xmlHttp.onreadystatechange=stateChanged;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	} 
		
	function stateChanged() 
	{ 
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{ 			
			var street = xmlHttp.responseXML.getElementsByTagName('street');						
			var html = '';
			
			if(street.length > 0)
			{
				count = street.length;
				if(count > 16) count = 16;
				for(i = 0; i < count; i++)
				{
					var name = street[i].getElementsByTagName('name')[0].firstChild.data;
					var id = street[i].getElementsByTagName('id')[0].firstChild.data;
					
					html += '- <a href="javascript:us(\'' + name + '\',\'' + id + '\');">' + name + '</a><br/>';										
				}
				if(street.length > 16)
				{
					html += '<br/>i jeszcze ' + (street.length - 16) + ' innych ulic, sprecyzuj nazwe ulicy';
				} 
			}	
			
			document.getElementById('street_list').innerHTML = html;					
		} 
	}
		
	function GetXmlHttpObject()
	{
		var xmlHttp=null;
		
		try
		{
			 // Firefox, Opera 8.0+, Safari
		 	xmlHttp=new XMLHttpRequest();
		}
		catch (e)
		{
			 // Internet Explorer
		 	try
		  	{
		  		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		  	}
		 	catch (e)
		  	{
		  		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		  	}
		}
		
		return xmlHttp;
	}
	
	function us(name, id)
	{
		document.getElementById('street').style.display = 'none';
	
		document.getElementById('wyj_street').value = name;
		document.getElementById('wyj_street_id').value = id;
		
		document.getElementById('w_street').value = name;
	}
	
	function ug()
	{
		if(document.getElementById('wyj_city').value == 1)
		{
			document.getElementById('street').style.display = 'block';
		}		
	}
	
	function uf(object)
	{
		if(document.getElementById('wyj_city').value == 1)
		{
			document.getElementById('wyj_street').readOnly = true;
		}
		else
		{
			document.getElementById('wyj_street').readOnly = false;
		}
		
		document.getElementById('street_list').innerHTML = '';
		document.getElementById('w_street').value = '';
		document.getElementById('wyj_street').value = '';
		document.getElementById('wyj_street_id').value = 0;
	}
