var training = {
	init : function(data)
	{
		$("#ttype").removeOption(/./);
		$("#ttype").addOption('', '');	
		for (var i = 0; i < data.length; i++)
		{
			$('#ttype').addOption(data[i], data[i]);	
		}
		$("#ttype").selectOptions('');
		
		$(window).bind('load', function() {
			$("#tform").validate({
			   rules: {
			     ttype: {
				   required: true	
				 },
				 tphone: {
				   required: true	
				 },
				 temail: {
			       required: true,
			       email: true
			     }
			   },
			   messages: {
			     ttype: {
				   required: "Wybierz typ szkolenia<br />"
				 },
			     tphone: {
				   required: "Podaj swój numer telefonu<br />"
				 },				 
				 temail: {
			       required: "Podaj swój adres email<br />",
			       email: "Niepoprawny adres email<br />"
			     }
			   },
			   errorLabelContainer: $("#terr"),
			   submitHandler: function(form) {
					$.post('http://'+location.host+'/code/training/mail.php', {t: $('#ttype').val(), d: $('#tdate').val(), f: $('#tfirstname').val(), s: $('#tsurname').val(), p: $('#tphone').val(), m: $('#temail').val(), i: $('#tinfo').val()}, trainingConfirm);
		       }
			});
			
			$('#ttype').click( function(event) {
	 			$('#tnfo').html('');
			});

			$('#ttype').keydown( function(event) {
	 			$('#tnfo').html('');
			});
			
			$('#tdate').keydown( function(event) {
	 			$('#tnfo').html('');
			});
			
			$('#tfirstname').keydown( function(event) {
	 			$('#tnfo').html('');
			});
			
			$('#tsurname').keydown( function(event) {
	 			$('#tnfo').html('');
			});
			
			$('#tphone').keydown( function(event) {
	 			$('#tnfo').html('');
			});
			
			$('#temail').keydown( function(event) {
	 			$('#tnfo').html('');
			});			

			$('#tinfo').keydown( function(event) {
	 			$('#tnfo').html('');
			});		
			
			$('#tsend').click( function(event) {
	 			$('#tnfo').html('');
			});

			$('#tsend').keydown( function(event) {
	 			$('#tnfo').html('');
			});
				
		});			
	}
};

function trainingConfirm(data, textStatus) {
	if (textStatus == 'success')
	{
		$('#tnfo').html('Dziękujemy za zapisanie się na szkolenie<br />Wkrótce skontaktujemy się z Tobą');
		$("#ttype").selectOptions('');
	}
}
