// 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('-- Miejsce przyjazdu --','');	
		
		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.disabled = false;	
	}
	
	function rezerwacja()
	{
		var from = document.getElementById('start_from');
		var to = document.getElementById('end_to');
		
		if(from.value && to.value)
		{
			if(!document.all)
			{
				document.getElementById('rezerwacja_kursu').submit();
			}
			else
			{
				document.rezerwacja_kursu.submit();
			}
		}
		else
		{	
			if(!document.all)
			{
				from.style.border = from.value ? '2px solid #C1D1F5' : '2px solid red;';
				to.style.border = to.value ? '2px solid #C1D1F5' : '2px solid red;'
				alert('Wypełnij pola oznaczone na czerwono');
			}
			else
			{				
				alert('Prosze wskazać przystańek początkowy i końcowy');
			}
		}
	}
	
	function rezerwacjaD()
	{
		var from = document.getElementById('start_d');
		
		if(from.value)
		{
			document.getElementById('szukaj_d').submit();
		}
		else
		{
			if(!document.all)
			{
				from.style.border = from.value ? '2px solid #C1D1F5' : '2px solid red;';			
				alert('Wybierz kierunek podróży');
			}
			else
			{
				alert('Wybierz kierunek podróży');
			}
		}
	}
	
	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('Wybierz interesujący cię termin wyjazdu');
			}
		}
		else
		{
			if(document.trasa.to_hour.value  && document.trasa.from_hour.value)
			{
				document.trasa.submit();
			}
			else
			{
				alert('Wybierz interesujący cię termin wyjazdu');
			}
		}
	}
	
	
	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 = document.getElementById(forma);
		var id_ary = id_inp.toString().split(",");
		var all_ok = true;
		
		for(i = 0; i < id_ary.length; i++)
		{
			var divv = document.getElementById(id_ary[i]);
			if(divv.value == '')
			{
				all_ok = false;
				if(!document.all)
				{
					divv.style.border = divv.value ? '2px solid #C1D1F5' : '2px solid red;';						
				}			
			}
		}
		
		if(all_ok) 
		{
			formularz.submit(); 
		}
		else
		{
			if(!document.all)
			{
				alert('Wypełnij pola oznaczone na czerwono');
			}
			else
			{
				alert('Musisz wypełnić wszystkie pola');
			}
		}
	}
	
	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('Wypełnij pola oznaczone na czerwono');
			}
			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');
	}

