var active = null;

$(document).ready(function(){
  newsletter_przyciski();
  active = $('#akcja').val();	
});

function newsletter_przyciski(){
  $('.nsl_radio').click (function () {
	 $('.nsl_radio').removeClass('active');
	 $('.nsl_radio img').attr('src', 'grafa/newsletter/radio_off.png');
	 
    var id = $(this).attr('id');	
    var plik = $('#'+id+' img').attr('src').replace('_off','_on');	
    $('#'+id+' img').attr('src',plik);
	 $('#'+id).addClass('active');	 
	 $('#akcja').val(id);
	 active = id;
  });
	
  $('#email').click (function () {
    $(this).val('');	
  });	
	
  $('#nsl_submit').click (function () {
	  if($('#email').val() == '' || $('#email').val() == 'wpisz adres email'){
	    alert('prosimy wpisać adres email');
		 return false;	
	  }	
	  var email = $('#email').val();	
	  pokaz_logo_ajax('#nsl_ajax', 2, 'sprawdzam dane proszę czekać');
	  $('#newsletter_pola').hide();	
		
	  $.ajax({
		  type: 'GET',
		  url: 'ajax.php',
		  data: 'modul=newsletter&email='+email+'&akcja='+active,
		  success: function(odp){
		    if(odp == 0){
	         alert('Podany email jest nieprawidłowy');
				$('#newsletter_pola').show();
				$('#nsl_ajax').html('');
		      return false;				   
			 }
		    else if(odp == 1){
	         alert('Podany email już jest zapisany w naszej bazie');
				$('#newsletter_pola').show();
				$('#nsl_ajax').html('');
		      return false;				   
			 }			 
		    else if(odp == 2){
	         alert('Podany email nie figuruje w naszej bazie');
				$('#newsletter_pola').show();
				$('#nsl_ajax').html('');
		      return false;				   
			 }			 			 
		    else if(odp == 3){
				$('#nsl_ajax').html('<span class="ajax2">Zgłoszenie zostało przesłane, prosimy potwierdzić poprzez email</span>');
		      return false;				   
			 }			 			 
		  }		
		}); 		
  });
}	
