$(document).ready(function(){

	
	// Contact form
	$("form#contact_form").submit(function() {
		
		//Setup any needed variables
		var input_name  = $('#name_cf').val(),
		input_email     = $('#email_cf').val(),
        input_phone     = $('#phone_cf').val(),
        input_company   = $('#company_cf').val(),
		input_message   = $('#message_cf').val(),
		response_text   = $('#main_content #response_cf');
        
      if (input_name == "" || input_name == "Имя") {
      $("span#name_error").show();
      $("input#name_cf").focus();
      return false;
    }
            

	  if (input_email == "") {
      $("span#email_error").show();
      $("input#email_cf").focus();
      return false;
    }
	
	var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
	if(!emailReg.test(input_email)) {
	$("span#email_error2").show();
    $("input#email_cf").focus();
      return false;
	}
    
     if (input_phone == "") {
      $("span#phone_error").show();
      $("input#phone_cf").focus();
      return false;
    }
	
	  if (input_message == "" || input_message == "Запишите здесь свое сообщение") {
	  $("span#msg_error").show();
	  $("textarea#message_cf").focus();
	  return false;
    } 
        
		//Hide any previous response text
		response_text.hide();

		//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, company : input_company, message: input_message}, function(data){
			response_text.html(data);
            $("#reset_cf").click();
		});

		//Cancel default action
		return false;
		
	});
	
});
