  $(document).ready(function () {
        $("#contact_name, #contact_email, #contact_body, #code").keyup(function() {
          checkFields();
        });

        used = 0;
	$('#loginForm a:eq(0), #loginForm2 a:eq(0)').click(function (e) {
		e.preventDefault();
		$('#loginformContent').modal();
	});
	$('#showFeedForm:eq(0), #showFeedFormSt:eq(0)').click(function (e) {
	    if (!used) {
		e.preventDefault();
		$('#feedbackForm').modal_mod({containerCss: 'width: 1900px;'});
	    }
	});
	
	$("#contact_form").click(
	
    function () {
    
    	if (!$("#contact_name").val()) {
    	  alert('Ошибка: введите Ваше имя');
    	  return 1;
    	} else if (!$("#contact_email").val()) {
    	  alert('Ошибка: введите адрес электронной почты');
    	  return 1;
    	} else if (!$("#contact_body").val()) {
    	  alert('Ошибка: введите текст сообщения');
    	  return 1;
    	}
    
      winHeight = $("#modalContainerMod").height();
      requestType = 'feedbackRequest';
      $.ajax({
        type: "POST",
        data: "code="+encodeURIComponent($("#code").val())+"&name="+encodeURIComponent($("#contact_name").val())+"&body="+encodeURIComponent($("#contact_body").val())+"&email="+encodeURIComponent($("#contact_email").val())+"&emotion="+encodeURIComponent($("#contact_emotion").val()),
        dataType: "text",
        url: "/mail/sent.php"
      });	
    });
  // --------------
  $("#feedbackFormLoading").ajaxStart(function(){
   $(this).show();
   $("#feedbackFormTable").hide();
   if ($("#modalContainerMod").height()) {
       $("#modalContainerMod").height(winHeight);
   }
  });
  $("#feedbackFormLoading").ajaxStop(function(){
   $(this).hide();
  });
  $("#feedbackFormComplete").ajaxComplete(function(event, xhr, settings){
  	 if (settings.url != '/mail/sent.php')
        	  return 0;
     $("#feedbackFormLoading").hide();
     if (xhr.responseText=='error:code ') {
       $("#feedbackFormTable").show();
       alert('Ошибка: введен неверный код');
     } else if (xhr.responseText=='error:name ') {
       $("#feedbackFormTable").show();
       alert('Ошибка: введите Ваше имя');
     } else if (xhr.responseText=='error:email ') {
       $("#feedbackFormTable").show();
       alert('Ошибка: введите адрес электронной почты');
     } else if (xhr.responseText=='error:body ') {
       $("#feedbackFormTable").show();
       alert('Ошибка: введите текст сообщения');
     } else {
       $(this).show();
       used = 1;
     }
 });
});

        function checkFields() {
          if (!$("#contact_name").val() || !$("#contact_email").val() || !$("#contact_body").val() || $("#code").val().length<4 || $("#contact_emotion").val()==0) {
            $("#contact_form").attr("disabled", "disabled");
            return 0;
          }
          $("#contact_form").removeAttr("disabled", "disabled");
        }

	function selectEmotion(id) {
		for(i=1; i<=3; i++) {
			if (i==id) {
				if (document.getElementById('emotion'+i).className == 'radiobtn')
				  document.getElementById('emotion'+id).className = 'radiobtn choosen';
				else
					document.getElementById('emotion'+i).className = 'radiobtn';
			} else
			  document.getElementById('emotion'+i).className = 'radiobtn';
		}
		$("#contact_emotion").val(id);
		checkFields();
	}