
/* Skrypt */
bodyHeight = 0;
scrOfY = 0;
windowHeight = 0;
top_height = 0;
wys = 0;
szer = 0;

$(document).ready(function() {
	$(".imgShow").click(function () {	
		showTB();
		return false;
	});
	

  $(".zwin_rozwin").toggle(
  function () {
      
      $(".zwin_rozwin").html("rozwiń");
      $(".zwin_rozwin").next().slideUp();
    },
    function () {
      $(".zwin_rozwin").html("zwiń");
      $(".zwin_rozwin").next().slideDown();
    });

	
});

function showTB(){
	$("body").prepend("<div class='BoxWrap'><div class='wiecej'></div></div>");
	szer = $(".BoxWrap").width();
	wys = $(".BoxWrap").height();
	window_size();
	updateTB();
	$(".BoxWrap").prepend("<div id='close'><img src='/uploads/images/grafika/close.gif' onclick='closeBox();' /></div>");
	$("body").prepend("<div id='TB_Window'></div>");
	$("#TB_Window").hide();
	$("#TB_Window").css("opacity","0.7");
	$("#TB_Window").css("height",bodyHeight);
	$("#TB_Window").fadeIn(100);
	var _url = window.location;
	
	$(".BoxWrap").css("margin-left","-"+(szer/2)+"px");
	
	$(".BoxWrap").append("<div class='formularz'><h2>Wyślij adres tej strony</h2><form id='myForm' action='/uploads/images/skrypty/polec.php' method='POST'><label>Podaj swoję imię i nazwisko: *</label><input type='text' name='imie' class='pole_short' /><label>Podaj e-mail adresata: *</label><input type='text' name='email' class='pole_short' /><label>Komentarz:</label><textarea rows='3' cols='16'  name='tekst' class='pole_area' ></textarea><input type='hidden' class='www' name='www' value='"+_url+"' /><p>(*) Pola wymagane</p><input type='submit' class='ffsubmit' value='Wyślij' /></form></div>");
	
	
	$(".BoxWrap").fadeIn(200);
	
	$(".BoxWrap .formularz .ffsubmit").click(function () {
	 przetwarzaj_dane();
		$('#myForm').ajaxForm(function() { 
    	//alert("Dziękujemy za wysłanie wiadomości!");
			$(".BoxWrap .formularz input").val("");
			$(".BoxWrap .formularz textarea").val("");
			$(".BoxWrap .formularz .ffsubmit").val("Wyślij");
			$(".BoxWrap .formularz .www").val(_url);
			
		 
    }); 
		
	});
	
	$("#TB_Window").click(function(){
		closeBox();
	});
}

function przetwarzaj_dane ()
{
  var brakuje_danych=false;
  var formularz=document.forms[0];
  var napis="";

  if (formularz.imie.value == ""){
    napis += "Podaj Imię i Nazwisko\n";
    brakuje_danych=true;
  }

  if (formularz.email.value == ""){
    napis += "Podaj e-maila\n";
    brakuje_danych=true;
  }

if (!brakuje_danych){
$(".BoxWrap .formularz h2").html("Wiadomość wysłana");
  return true;
}
else{
  alert (napis);
  $(".BoxWrap .formularz h2").html("Wyślij adres tej strony");
  return false;
} 

}

function closeBox(){
	$("#TB_Window").remove();
	$(".loader").remove();
  $(".BoxWrap").remove();
}

function window_size(){
	scrOfY = document.documentElement.scrollTop;
	bodyHeight = document.body.offsetHeight;
	windowHeight = document.documentElement.clientHeight;
}

function updateTB(){
	top_height = (windowHeight/2)- (wys/2) + scrOfY;
	$(".BoxWrap").css("top",top_height+"px");
}

function newsletter ()
{
  var brakuje_danych=false;
  var formularz=document.forms[1];
  var napis="";
  var reg;
  var wyn;

  reg = /^[a-zA-Z0-9]{1,30}@[a-zA-Z0-9]+(\.[a-zA-Z0-9]+)+$/;
	wyn = formularz.email.value.match(reg);
	
	if (wyn == null) { 
  napis += "Podaj adres e-mail\n";
	brakuje_danych=true; 
  }

  if (formularz.imie.value == ""){
    napis += "Podaj Imię\n";
    brakuje_danych=true;
  }
  
  if (formularz.imie.value == ""){
    napis += "Podaj Nazwisko\n";
    brakuje_danych=true;
  }
  
  if (formularz.zawod.value == ""){
    napis += "Podaj Zawód\n";
    brakuje_danych=true;
  }
  
  if (formularz.miejscowosc.value == ""){
    napis += "Podaj Miejscowość\n";
    brakuje_danych=true;
  }
  
  if (formularz.wojewodztwo.value == ""){
    napis += "Podaj Województwo\n";
    brakuje_danych=true;
  }

  if (!brakuje_danych){
    return true;
  }

  else{
    alert (napis);
    return false;
  } 

}

$(document).ready(function() {
  $(".nauczyciel").click(function(){
    $(".nauczy").toggle();
  });
  if($(".nauczyciel").is(":checked")){
    $(".nauczy").show();
  }
});


