$(document).ready(function(){

	// Contact form
	$("a#send").click(function() {
		
		//Setup any needed variables
		var input_name  = $('#name').val(),
		input_email     = $('#email').val(),
        input_phone     = $('#phone').val(),
		input_message   = $('#msg').val(),
		response_text   = $('span#informmessage');
        
      if (input_name == "" || input_name == "Имя") {
      $("span#message_error").html('поле Имя не заполнено').show();
      $("input#name").focus();
      return false;
    }
            

	  if (input_email == "" || input_email == "@mail") {
      $("span#message_error").html('поле Email не заполнено').show();
      $("input#email").focus();
      return false;
    }
	
	var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
	if(!emailReg.test(input_email)) {
	$("span#message_error").html('Email введен некорректно').show();
    $("input#email").focus();
      return false;
	}
    
     if (input_phone == "" || input_phone == "Телефон") {
      $("span#message_error").html('поле Телефон не заполнено').show();
      $("input#phone").focus();
      return false;
    }
	
	  if (input_message == "" || input_message == "Запишите здесь свое сообщение") {
	  $("span#message_error").html('поле Сообщение не заполнено').show();
	  $("textarea#msg").focus();
	  return false;
    } 
        
		//Hide any previous response text

		//Change response text to 'loading...'
		//response_text.html('<p>Loading...</p>').show();

		//Make AJAX request
		$.post('/phpmailer/sendmail.php', {name: input_name, email: input_email, phone : input_phone, message: input_message}, function(data){
		    $("span#message_error").hide();
            $("form#validate_form").hide();
			response_text.html('Ваше сообщение успешно отправлено').show();
		});

		//Cancel default action
		return false;
		
	});
	
});
