$(document).ready(function(){
	$('a.mailto').click(function(ev){
		ev.preventDefault();
		var mail = $(this).attr('id');

		var form=
		"<div id='mailform' style='display: none'>" +
		"<div style='font-size: 15px; font-weight: bold; padding-bottom: 15px;'>Форма обратной связи<hr size=1 color=black></div>" +
		"<b>Ваше имя</b><br><input type=text id='yourname' style='width: 300px'><br><br>" +
		"<b>Ваш e-mail</b><br><input type=text id='yourmail' style='width: 300px'><br><br>" +
		"<b>Сообщение:</b><br><textarea id='yourmessage' style='width: 300px; height: 100px'></textarea><br><br>" +
		"<div align=right><input type=button id='sendbtn' value='Отправить'></div>" +
		"</div>"

		if($('#mailform').html()==null) 
		{
			$("body").append(form);

			$('#sendbtn').bind('click', function(){
				//alert('aaa')
				if($('#yourname').attr('value')!='' && $('#yourmail').attr('value')!='' && $('#yourmessage').attr('value')!='')
				{
					$.ajax({
						type: 'POST',
						data: 'n='+$('#yourname').attr('value')+'&e='+$('#yourmail').attr('value')+'&m='+$('#yourmessage').attr('value')+'&sm='+mail,
						url: '/modules/contacts/ajax.php',
						beforeSend: function(){
							$('#mailform').html("<img src='/template/images/ajax-loader.gif'>");
						},
						success: function(data){
							$('#mailform').html(data);
						},
						error: function(){
							$('#mailform').html('Ошибка');
						}
					});
				}
				else alert('Необходимо заполнить все поля');
			});
		}

		$.lightbox("#mailform", {'modal': true, 'width':300, 'height':300}, function() {});
	});
});
