                                      // warstwy rozwijane

function toggle(id){
  var a = document.getElementById('a' + id);
  var div = document.getElementById('W' + id);
  
  if(div.style.display == 'block'){
    div.style.display = 'none';
    a.style.background = 'url(img/pages/strzala_bok.gif) no-repeat';
  } else {
    div.style.display = 'block'
    a.style.background = 'url(img/pages/strzala_dol.jpg) no-repeat';
  }
}
                                    // end warstwy
									
function walidacja_praca()
{
	opc1 = document.getElementById('Praca_potwiedzam_prawdziwosc').checked;
	if(!opc1){
		alert('Proszę zaznaczyć potwierdzenie poprawności danych');
		return false;
		}
	opc2 = document.getElementById('Praca_zgoda').checked;
	if(!opc1){
		alert('Proszę wyrazić zgodę na przetwarzanie danych');
		return false;
		}
	if(!document.getElementById('PracaStanowisko').value || !document.getElementById('PracaName').value || !document.getElementById('PracaAdres').value || !document.getElementById('PracaMiasto').value || !document.getElementById('PracaUlica').value || !document.getElementById('PracaSzkoly').value || !document.getElementById('PracaSzkolenia').value || !document.getElementById('PracaDoswiadczenie').value|| !document.getElementById('PracaJezyki').value|| !document.getElementById('PracaDlaczego').value){
		alert('Proszę uzupełnić wymagane dane');
		return false;
		}
	reg = /^[0-9]{2}-[0-9]{3}$/;
	wyn = document.getElementById('PracaKod').value.match(reg);
	if((!document.getElementById('PracaKod').value) || wyn == null)
		{
				alert("Proszę poprawnie uzupełnić pole 'Kod pocztowy'");
				return false;
		};
	if((!document.getElementById('PracaTelefon').value) || (isNaN(document.getElementById('PracaTelefon').value)))
		{
				alert("Proszę poprawnie uzupełnić pole 'Numer telefonu'");
				return false;
		};	
	reg = /^[a-zA-Z0-9ąćęłńóśżźĄĆĘŁŃÓŚŻŹ_\-\.]{1,30}@[a-zA-Z0-9ąćęłńóśżźĄĆĘŁŃÓŚŻŹ]+(\.[a-zA-Z0-9ąćęłńóśżźĄĆĘŁŃÓŚŻŹ]+)+$/;
	wyn = document.getElementById('PracaMail').value.match(reg);
	if(!document.getElementById('PracaMail').value || wyn == null)
	{
				alert("Proszę poprawnie uzupełnić pole 'Adres e-mail'");
				return false;
		};
	
	return true;
}

function walidacja_kontakt()
{
	if(!document.getElementById('ContactSkadJestem').value || !document.getElementById('ContactTresc').value ){
		alert('Proszę uzupełnić wymagane dane');
		return false;
		}
	reg = /^[a-zA-Z0-9ąćęłńóśżźĄĆĘŁŃÓŚŻŹ_\-\.]{1,30}@[a-zA-Z0-9ąćęłńóśżźĄĆĘŁŃÓŚŻŹ]+(\.[a-zA-Z0-9ąćęłńóśżźĄĆĘŁŃÓŚŻŹ]+)+$/;
	wyn = document.getElementById('ContactMail').value.match(reg);
	if((!document.getElementById('ContactMail').value) || wyn == null)
	{
				alert("Proszę poprawnie uzupełnić pole 'Adres e-mail'");
				return false;
		};
	reg = /^[0-9]{2}-[0-9]{3}$/;
	wyn = document.getElementById('ContactKod').value.match(reg);
	if((document.getElementById('ContactKod').value!='') && wyn == null)
		{
				alert("Proszę poprawnie uzupełnić pole 'Kod pocztowy'");
				return false;
		};
	if(document.getElementById('ContactTelefon').value!='' && (isNaN(document.getElementById('ContactTelefon').value)))
		{
				alert("Proszę poprawnie uzupełnić pole 'Numer telefonu'");
				return false;
		};
	return true;
}

function walidacja_pressroom()
{
	if(!document.getElementById('PressroomName').value || !document.getElementById('PressroomRedakcja').value || !document.getElementById('PressroomTresc').value ){
		alert('Proszę uzupełnić wymagane dane');
		return false;
		}
	reg = /^[a-zA-Z0-9ąćęłńóśżźĄĆĘŁŃÓŚŻŹ_\-\.]{1,30}@[a-zA-Z0-9ąćęłńóśżźĄĆĘŁŃÓŚŻŹ]+(\.[a-zA-Z0-9ąćęłńóśżźĄĆĘŁŃÓŚŻŹ]+)+$/;
	wyn = document.getElementById('PressroomMail').value.match(reg);
	if((!document.getElementById('PressroomMail').value) || wyn == null)
	{
				alert("Proszę poprawnie uzupełnić pole 'Adres e-mail'");
				return false;
		};
	if((!document.getElementById('PressroomTelefon').value) || (isNaN(document.getElementById('PressroomTelefon').value)))
		{
				alert("Proszę poprawnie uzupełnić pole 'Numer telefonu'");
				return false;
		};
	return true;
}

function walidacja_dla_partnerow()
{
	if(!document.getElementById('Dla_partnerowName').value || !document.getElementById('Dla_partnerowFirma').value || !document.getElementById('Dla_partnerowTresc').value ){
		alert('Proszę uzupełnić wymagane dane');
		return false;
		}
	reg = /^[a-zA-Z0-9ąćęłńóśżźĄĆĘŁŃÓŚŻŹ_\-\.]{1,30}@[a-zA-Z0-9ąćęłńóśżźĄĆĘŁŃÓŚŻŹ]+(\.[a-zA-Z0-9ąćęłńóśżźĄĆĘŁŃÓŚŻŹ]+)+$/;
	wyn = document.getElementById('Dla_partnerowMail').value.match(reg);
	if((!document.getElementById('Dla_partnerowMail').value) || wyn == null)
	{
				alert("Proszę poprawnie uzupełnić pole 'Adres e-mail'");
				return false;
		};
	if((!document.getElementById('Dla_partnerowTelefon').value) || (isNaN(document.getElementById('Dla_partnerowTelefon').value)))
		{
				alert("Proszę poprawnie uzupełnić pole 'Numer telefonu'");
				return false;
		};
	return true;
}

function walidacja_przeslij_przepis()
{
	if(!document.getElementById('Przeslij_przepisImie').value || !document.getElementById('Przeslij_przepisMiejscowosc').value || !document.getElementById('Przeslij_przepisPrzepisNa').value || !document.getElementById('Przeslij_przepisCzas').value  || !document.getElementById('Przeslij_przepisSkladniki').value || !document.getElementById('Przeslij_przepisSposob').value ){
		alert('Proszę uzupełnić wymagane dane');
		return false;
		}
	reg = /^[a-zA-Z0-9ąćęłńóśżźĄĆĘŁŃÓŚŻŹ_\-\.]{1,30}@[a-zA-Z0-9ąćęłńóśżźĄĆĘŁŃÓŚŻŹ]+(\.[a-zA-Z0-9ąćęłńóśżźĄĆĘŁŃÓŚŻŹ]+)+$/;
	wyn = document.getElementById('Przeslij_przepisMail').value.match(reg);
	if((!document.getElementById('Przeslij_przepisMail').value) || wyn == null)
	{
				alert("Proszę poprawnie uzupełnić pole 'Adres e-mail'");
				return false;
		};
	return true;
}

function copyFile(what) 
{
	 what.form.fileName.value = what.form.Przeslij_przepisPicture.value;
}

function popup(url, width, height) {
        width1=width/2;
		height1=height/2;
		x=screen.availWidth/2-width1;
		y=screen.availHeight/2-height1;
		var Win = window.open(url,"displayWindow",'width=' + width + ',height=' + height + ',resizable=0, scrollbars=0, menubar=no,status=1, left='+x+', top='+y );
		Win.focus();
};

function quiz(id){
	nr_warstwy = 'q' + id;
	for(i=1;i<4;i++)
	{
		warstwa = 'q' + i;
		document.getElementById(warstwa).style.display = 'none';
	}
	document.getElementById(nr_warstwy).style.display = 'block';
}

function quiz_2(id){
	nr_warstwy = 'q' + id;
	for(i=0;i<=4;i++)
	{
		warstwa = 'q' + i;
		document.getElementById(warstwa).style.display = 'none';
	}
	document.getElementById(nr_warstwy).style.display = 'block';
}

function _search(id, pages){
	nr_warstwy = 'q' + id;
	for(i=1;i<=pages;i++)
	{
		warstwa = 'q' + i;
		document.getElementById(warstwa).style.display = 'none';
	}
	document.getElementById(nr_warstwy).style.display = 'block';
}

function przepisy(id){
	nr_warstwy = 'q' + id;
	
	for(i=1;i<20;i++)
	{
		warstwa = 'q' + i;
		if(document.getElementById(warstwa))document.getElementById(warstwa).style.display = 'none';
	}
	document.getElementById(nr_warstwy).style.display = 'block';
}


function check_title()
{
	if($('#ContactTemat').val()=='reklamacja')
	{
		$('#box-form').load('contacts/send_complaint');
	}
	else
	{
		if($('#ContactTemat').length)
			$('#box-form').load('contacts/send_contact/'+$('#ContactTemat').val());
		else
			$('#box-form').load('contacts/send_contact/'+$('#ComplaintTemat').val());
	}
}

function send_contact_form()
{
	url = 'contacts/send_contact';
	postData = $('#ContactForm').serialize();
	
	$.post(url, postData, function(data){
		if(data == 'ok')
		{
			$('#box-form-err').hide();
			$('#box-form').html('<span class="blue" style="margin-left:20px">Dziękujemy. Formularz został wysłany.</span>');
		}
		else if(data == 'no-send')
		{
			$('#box-form-err').show();
			$('#box-form-err').html('<span class="blue">Formularz nie został wysłany. Wystąpił błąd aplikacji, proszę spróbować jeszcze raz.</span>');
		}
		else
		{
			$('#box-form-err').show();
			$('#box-form-err').html('<span class="blue">Formularz nie został wysłany. Proszę wypełnić wymagane pola.</span>');
		}
	});
}

function send_complaint_form()
{
	url = 'contacts/send_complaint';
	postData = $('#ComplaintForm').serialize();
	
	$.post(url, postData, function(data){
		if(data == 'ok')
		{
			$('#box-form-err').hide();
			$('#box-form').html('<span class="blue" style="margin-left:20px">Dziękujemy. Formularz został wysłany.</span>');
		}
		else if(data == 'no-send')
		{
			$('#box-form-err').show();
			$('#box-form-err').html('<span class="blue">Formularz nie został wysłany. Wystąpił błąd aplikacji, proszę spróbować jeszcze raz.</span>');
		}
		else
		{
			$('#box-form-err').show();
			$('#box-form-err').html('<span class="blue">Formularz nie został wysłany. Proszę wypełnić wymagane pola.</span>');
		}
	});
}
