function open_window(src,h,w)
{
	Nowe=null;
	if (Nowe!=null)
	{
		Nowe.close();
		Nowe=null;
	}

	Nowe=window.open("zdjecie.php?src="+src, "Zdjecie", "toolbar=no,menubar=no,location=no,personalbar=no,scrollbars=no,status=no,directories=no,resizable=no,height="+h+",width="+w);
}

function formularz_open(id, id_term, dest, val, subcode)
{
	var sciezka = 'rezerwacja.php?id=' + id + '&id_term=' + id_term + '&dest=' + dest + '&val=' + val + '&subcode=' + subcode;  
	
	Okno_rezerwacja=window.open(sciezka,'Formularz','toolbar=yes, menubar=no, location=no, personalbar=no, scrollbars=yes, directories=no, status=yes, resizable=no, width=600, height=600');
	Okno_rezerwacja.document.close();
	Okno_rezerwacja.focus();
	
	return false;				
}

function formularz_open_2(id)
{
	var sciezka_2 = 'rozklad_jazdy.php?id=' + id;  
	
	Okno_rezerwacja=window.open(sciezka_2,'Rozklad_jazdy','toolbar=yes, menubar=no, location=no, personalbar=no, scrollbars=yes, directories=no, status=yes, resizable=no, width=600, height=600');
	Okno_rezerwacja.document.close();
	Okno_rezerwacja.focus();
	
	return false;				
}

function check_email(email) 
{
	/*
	 * Niedozwolone znaki
	 */
	invalid = " /:,;";
    for(j=0; j < invalid.length; j++) 
    {
		bad = invalid.charAt(j);
		if (email.indexOf (bad, 0) != -1) { return false; }
	}
		    
	/*
	 * At dwa razy
	 */
	if (email.lastIndexOf("@")!=email.indexOf("@"))
	return false;

	/*
	 * At na pierwszym miejscu lub brak
	 */
	at = email.indexOf("@", 0);
	if( (at == -1) || (at == 0) )
	return false;
		    
    at_str = email.substring((at+1),email.length);
		    
	/* 
	 * Jezeli brak at
	 */
	if (at_str=="")
	return false;
		    
	/*
	 * Dot na pierwszy miejscu lub brak 
	 */
	dot = at_str.indexOf(".", 0);
	if( (dot == -1) || (dot == 0) )
	return false;
	     
	if ((at_str.lastIndexOf(".")+1)==at_str.length)
	return false;
	    		   
	return true;
}

function sprawdzForm(element)
{ 
	for (i=0;i<document.forms[0].elements.length;i++)
	{
		//if (document.forms[0].elements[i].name.toString()=="ip_miejsce_odjazdu")
		//if (document.forms[0].elements[i].value == 0)
		//{
		//	alert('Wybierz miejsce odjazdu!');
		//	return false;
		//}	
	
		if (document.forms[0].elements[i].name.toString()=="zamawia_imie")
		if (document.forms[0].elements[i].value == "")
		{
			alert('Uzupełnij pole: Imię (osoby zamawiającej)');
			return false;
		}
		
		if (document.forms[0].elements[i].name.toString()=="zamawia_nazwisko")
		if (document.forms[0].elements[i].value == "")
		{
			alert('Uzupełnij pole: Nazwisko (osoby zamawiającej)');
			return false;
		}
		
		if (document.forms[0].elements[i].name.toString()=="zamawia_miejscowosc")
		if (document.forms[0].elements[i].value == "")
		{
			alert('Uzupełnij pole: Miejscowość (osoby zamawiającej)');
			return false;
		}
		
		if (document.forms[0].elements[i].name.toString()=="zamawia_kod")
		if (document.forms[0].elements[i].value == "")
		{
			alert('Uzupełnij pole: Kod pocztowy (osoby zamawiającej)');
			return false;
		}	
		
		if (document.forms[0].elements[i].name.toString()=="zamawia_ulica")
		if (document.forms[0].elements[i].value == "")
		{
			alert('Uzupełnij pole: Ulica (osoby zamawiającej)');
			return false;
		}
		
		if (document.forms[0].elements[i].name.toString()=="zamawia_nr_domu")
		if (document.forms[0].elements[i].value == "")
		{
			alert('Uzupełnij pole: Nr domu (osoby zamawiającej)');
			return false;
		}
		
		if (document.forms[0].elements[i].name.toString()=="zamawia_email")
		{
			if (document.forms[0].elements[i].value == "")
			{
				alert('Uzupełnij pole: E-mail (osoby zamawiającej)');
				return false;
			} else
			{
				if (check_email(document.forms[0].elements[i].value)==false)
				{
					alert('Podaj poprawny e-mail (osoby zamawiającej)');
					return false;			
				}
			}
		}
		
		if (document.forms[0].elements[i].name.toString()=="uczestnik_imie")
		if (document.forms[0].elements[i].value == "")
		{
			alert('Uzupełnij pole: Imię (osoby uczestniczącej)');
			return false;
		}		
		
		if (document.forms[0].elements[i].name.toString()=="uczestnik_nazwisko")
		if (document.forms[0].elements[i].value == "")
		{
			alert('Uzupełnij pole: Nazwisko (osoby uczestniczącej)');
			return false;
		}
		
		if (document.forms[0].elements[i].name.toString()=="uczestnik_miejscowosc")
		if (document.forms[0].elements[i].value == "")
		{
			alert('Uzupełnij pole: Miejscowość (osoby uczestniczącej)');
			return false;
		}
		
		if (document.forms[0].elements[i].name.toString()=="uczestnik_kod")
		if (document.forms[0].elements[i].value == "")
		{
			alert('Uzupełnij pole: Kod pocztowy (osoby uczestniczącej)');
			return false;
		}		

		if (document.forms[0].elements[i].name.toString()=="uczestnik_ulica")
		if (document.forms[0].elements[i].value == "")
		{
			alert('Uzupełnij pole: Ulica (osoby uczestniczącej)');
			return false;
		}	
		
		if (document.forms[0].elements[i].name.toString()=="uczestnik_nr_domu")
		if (document.forms[0].elements[i].value == "")
		{
			alert('Uzupełnij pole: Nr domu (osoby uczestniczącej)');
			return false;
		}							
		
	}
}

function open_close_reservation(element)
{
	if (element.checked)
	{
		document.getElementById("rezerwuj_impreze").disabled=false;
		document.getElementById("rezerwuj_impreze").style.background="#960000";						
	}
	else
	{
		document.getElementById("rezerwuj_impreze").disabled=true;	
		document.getElementById("rezerwuj_impreze").style.background="silver";		
	}
}

function open_help()
{
	document.getElementById("help_1").style.display="block";
	document.getElementById("help_2").style.display="block";
	document.getElementById("help_3").style.display="block";
	document.getElementById("help_4").style.display="block";
}

function wybierz_wyjazd_lub_liczbe_uczestnikow()
{
	document.getElementById("wybrany_odjazd_lub_liczba_uczestnikow").value="1";
	document.forms[0].submit();
}

function sprawdzFormNewsletter(element)
{ 
	for (i=0;i<document.forms[0].elements.length;i++)
	{
		if (document.forms[0].elements[i].name.toString()=="newsletter")
		{
			if (document.forms[0].elements[i].value == "")
			{
				alert('Uzupełnij pole: Podaj e-mail');
				return false;
			} else
			{
				if (check_email(document.forms[0].elements[i].value)==false)
				{
					alert('Podaj poprawny e-mail');
					return false;			
				}
			}
		}	
	}
}

function print_page()
{
	var tresc = "";
	tresc = '<h2>' + document.getElementById("top").innerHTML + '</h2>';				
	tresc = tresc + document.getElementById("opis").innerHTML;
				
	stopka = '<div style="border-top: 1px solid #bbbbbb; text-align: center; padding: 15px; font-family: Verdana; font-size: 11px; color: #5c5c5c;">Ściągawakacyjna.pl - www.sciagawakacyjna.pl</div>';

	Okno=window.open('','Do_druku','toolbar=yes, menubar=no, location=no, personalbar=no, scrollbars=yes, directories=no, status=no, resizable=no, width=800, height=600');
	Okno.document.write ('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">');
	Okno.document.write ('<html><head><title>Ściągawakacyjna.pl - PRINT PAGE</title><meta name="copyright" content="Copyright (c) sciagawakacyjna.pl" /><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2" />');
				
	Okno.document.write ('<style type="text/css"><!--');
	Okno.document.write ('.div_tresc_1 { margin: 0px; padding: 15px; font-family: Verdana; font-size: 11px; color: #5c5c5c; }');
	Okno.document.write ('.div_tresc_1 h2 {	margin: 0px; margin-bottom: 20px; padding: 0px; font-family: Verdana; font-size: 22px; font-weight: normal;	color: #003b83;	}');
	Okno.document.write ('.div_tresc_1 p { font-family: Verdana, Arial, Sans-Serif;	font-size: 11px; padding-bottom: 15px; margin: 0px; border-style: none;	line-height: 150%; color: #49586b; }');
	Okno.document.write ('.srodtytul { font-family: Verdana; font-size: 13px; font-weight: bold; color: #123972; text-align:left; }');
	Okno.document.write ('.uwaga { font-family: Verdana; font-size: 12px; font-weight: bold; color: red; text-align:left; }');
	Okno.document.write ('.wstep { font-family: Verdana; font-size: 12px; font-style: italic; color: #5483bd; text-align:left; }');
	Okno.document.write ('--></style>');
	Okno.document.write ('</head>');
	Okno.document.write ('<body style="margin:10px;">');

	Okno.document.write ('<div class="div_tresc_1"> '+tresc+'</div>'+stopka+'</body></html>');
	Okno.document.close();
	Okno.focus();
	Okno.print();
}

