$(document).ready(function(){

jQuery.fn.centerScreen = function(loaded) {
                var obj = this;
                if(!loaded) {
                        obj.css('top', $(window).height()/2-this.height()/2);
                        obj.css('left', $(window).width()/2-this.width()/2);
                        $(window).resize(function() { obj.centerScreen(!loaded); });
                } else {
                        obj.stop();
                        obj.animate({ top: $(window).height()/2-this.height()/2, left: $
(window).width()/2-this.width()/2}, 200, 'linear');
                }
        }
        
    $('#popupDiv').centerScreen();
    $('#popupDiv a').click(function(){
    	$('#popupDiv').fadeOut('normal');
    });

	Cufon.replace('div.naglowek p', {
	  fontSize: '18px'
	});

}); 

  function DOPVAL_Email(aValue)
  {
  	var formatEmail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; 
  	
  	if(aValue.length == 0) {
  	  return false;
  	}
    var firstChar = aValue.substring(0, 1);
  	if(firstChar == '.') {
  	  return false;
  	}
  //working original	  var formatEmail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  	//var formatEmail = /^[^@\s]+\@[^@\s]+\.[^@\s]+/;	// E-mail format is some text, a @, some text, a ., some text. Note that the texts can't contain @
  	if (formatEmail.test(aValue))
  	{
  		return true;
  	}
  	return false;
  }
  
    function formularz(){
        imie_nazwisko = document.getElementById('form_imie_nazwisko').value;
        email = document.getElementById('form_email').value;
        tresc = document.getElementById('form_tresc').value;
        
        blad = '';
        error = false;
        
        if(imie_nazwisko.length<3){
          blad+='\n - popraw pole imię i nazwisko';
          error = true;
        }
        if(!DOPVAL_Email(email)){
          blad+='\n - niepoprawny adres email';
          error = true;
        }
        if(tresc.length<5){
          blad+='\n - nie wprowadzono zapytania';
          error = true;
        }
        if(error){
          alert('Wystąpiły błędy:'+blad);
        } else {
          return true;
        }
        return false;
      }
