$(function(){	
  $('.showTip').tipsy({gravity: 'w'});
  $('.showTipE').tipsy({gravity: 'e'});
  $('.showTipNE').tipsy({gravity: 'ne'});
  $('.showTipS').tipsy({gravity: 's'});    
  $('textarea.resizable:not(.processed)').TextAreaResizer();
  $('iframe.resizable:not(.processed)').TextAreaResizer();    			
});
    
$(document).ready(function() {	
  $('.showTip').tipsy({gravity: 'w'});
  $('.showTipE').tipsy({gravity: 'e'});
  $('.showTipNE').tipsy({gravity: 'ne'});
  $('.showTipS').tipsy({gravity: 's'});    
  
  $('textarea.resizable:not(.processed)').TextAreaResizer();
  $('iframe.resizable:not(.processed)').TextAreaResizer();          
       
  $(".toggle_container").hide();
  $(".selectedcontainer").show();          
  $("h3.trigger").click(function(){
		$(this).toggleClass("active").next().slideToggle(200);
		return false;
	});
	   	
	$(".GoUP").click(function(){$( 'html, body' ).animate( { scrollTop: 0 }, 'slow' );});
  $('.tooltip').tooltip({ 
      track: true, 
      delay: 0, 
      showURL: false,
      fade: 250
  });
  
  $("a.fancy").fancybox({
					"titlePosition"		: "inside",
  				"overlayColor"		: "#000",
  				"overlayOpacity"	: 0.9
	});
	$("a.okno").fancybox({
					"titlePosition"		: "inside",
  				"overlayColor"		: "#000",
  				"overlayOpacity"	: 0.9
	});
  

  $("#printPage").click(function() {  
    window.print();  
    return false;  
  });
  
  $("#validate").keyup(function(){		
		var email = $("#validate").val();
	
		if(email != 0)
		{
			if(isValidEmailAddress(email))
			{
				$("#validEmail").css({
					"background-image": "url('validYes.png')"
				});
			} else {
				$("#validEmail").css({
					"background-image": "url('validNo.png')"
				});
			}
		} else {
			$("#validEmail").css({
				"background-image": "none"
			});			
		}		
  });
});

function isValidEmailAddress(emailAddress) {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(emailAddress);
} 
	  
var povinne_barva = "#FFFF80";
var aname = "Vyplňte prosím Vaše jméno";
var amessage = "Pro odeslání vzkazu je třeba zanechat nějaký vzkaz :)";
var aemail = "Zadali jste neplatný formát Vašeho emailu";
var aantispam = "Vyplňte prosím číslo dle výpočtu";

function validatePodatelna(formular)
{     
  if (formular.podatelna_jmeno.value=="")
  {
      alert(aname);
      formular.podatelna_jmeno.focus();
      formular.podatelna_jmeno.style.backgroundColor=povinne_barva;
      return false;
  }  
  else if (formular.podatelna_adresa.value != "")
  {
      var re = new RegExp("^[^.]+(\.[^.]+)*@([^.]+[.])+[a-z]{2,4}$");
      if (!re.test(formular.podatelna_adresa.value))
      {
          alert(aemail);
          formular.podatelna_adresa.focus();
	        formular.podatelna_adresa.style.backgroundColor=povinne_barva;
          return false;
      }
  }
  else if (formular.podatelna_text.value == "")
  {
      alert(amessage);
      formular.podatelna_text.focus();
      formular.podatelna_text.style.backgroundColor=povinne_barva;
      return false;
  }
  else if (formular.podatelna_antispam.value == "")
  {
      alert(aantispam);
      formular.podatelna_antispam.focus();
      formular.podatelna_antispam.style.backgroundColor=povinne_barva;
      return false;
  }          
  else
    return true;
}
