$(document).ready(function () {
  
  //moodal win
  $('.fialova a#chcitaky').click(function (e) {
    e.preventDefault();
  	$('#dialog').modal();
  	this.hide();
  });
  
  $('.fialova a.chcitaky').click(function (e) {
    e.preventDefault();
  	$('#dialog').modal();
  	this.hide();
  });
  
  //external hrefs
  $('#content a').filter(function() {   
    return this.hostname && this.hostname !== location.hostname;   
  }).addClass('external')   
  .click(function() {   
    window.open(this.href);
    return false;
  });
  
  $('#prehled a').click(function() { 
    window.open(this.href,'_self');
    //alert(this.href);
  }); 
  
  $('.prehled a').click(function() { 
    window.open(this.href,'_self');
    //alert(this.href);
  }); 
  
  $('#detail a').click(function() { 
    window.open(this.href,'_self');
    //alert(this.href);
  });  
  
  $('.detail a').click(function() { 
    window.open(this.href,'_self');
    //alert(this.href);
  });  
  
  //ajax form
	$("#z_submit").click(function(){					   				   
		$(".error").hide();
    //getUrchinTracker("/registrace-dm");
    pageTracker._trackEvent('Formulare','Registrace DM',$(this).attr('id'));
		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		
		var emailToVal = $("#z_email").val();
		if(emailToVal == '') {
			$("#emailTo").after('<span class="error">Prosím, vložte emailovou adresu, na kterou chcete zpravodaj zasílat.</span>');
			hasError = true;
		} else if(!emailReg.test(emailToVal)) {	
			$("#emailTo").after('<span class="error">Prosím, vložte email ve správném formátu.</span>');
			hasError = true;
		}
		
		if(hasError == false) {
			$(this).hide();
			$("#sendEmail li.buttons").append('<img src="/fileadmin/virtua_sys/img/loading.gif" alt="Odesílám" id="loading" />');
			
			$.post("/fileadmin/virtua_sys/inc/regmail.php",
   				{ z_email: emailToVal },
   					function(data){
						$("#zpravodaj").slideUp("normal", function() {
							$("#zpravodaj").before('<p>Vaši emailovou adresu jsme přidali k odběratelům zpravodaje.</p>');											
						});
   					}
				 );
		}
		
		return false;
	});
}); 