 $(document).ready(function(){
    $("#email").focus();
    $("#forgotPassword, #forgotPasswordMessage").click(function(){
       $("#loginErrorMessage").hide("slow");
       $("#titleLogin").text("Забыли пароль?");
       $("#forgotDescription").show("slow");
       $('#loginPassword').attr("disabled", true); 
       $("#loginPasswordContainer").hide("slow");
       $("#loginOptions").hide("slow");
       $("#btnSearch span").text("Отправить");
       $("#btnSearch").addClass("fl");
       $("#btnCancel").show("slow");
       $("#loginEmail").focus();
    });
    
    $("#btnCancel").click(function(){
       $("#titleLogin").text("Логин:");
       $("#forgotDescription").hide("slow");
       $('#loginPassword').removeAttr("disabled");
       $("#loginPasswordContainer").show("slow");
       $("#loginOptions").show("slow");
       $("#btnSearch span").text("Вход");
       $("#btnSearch").removeClass("fl");
       $("#btnCancel").hide("slow");
       $("#loginEmail").focus();
    });
    
    $("#loginForm").validate({
      rules: {
        loginPassword: {
            required: true
        },
        loginEmail: {
            //email: true,
            required: true
        }
      }
    });
    
    //$("#commentForm").validate();
    
    $("a.tDisabled").click(function(){ alert("Функция в разработке. Приносим свои извинения за неудобства."); return false; })
    
    $(".actionNoComments").click(function(){ alert("Эта функция только для зарегистрированных пользователей.\nПожалуйста зарегистрируйтесь или залогиньтесь."); return false });
    
    $("#commentForm").validate({
      submitHandler: function(form) {
              $("#btnSendComment").replaceWith("Публикую... ");
              form.submit();
              return false;
      }
    });
      
    $("#inviteFriendForm").validate({
      rules: {
        inviteEmail: {
            email: true,
            required: true
        }
      },
      submitHandler: function(form) {
         //$("#btnInvite").replaceWith("Приглашаю...");
         placePreloader("invitationStatus");
         $.ajax({
             url : "/friend/sendInvitationToEmail.php",
             data : { inviteEmail: $("#inviteEmail").val() },
             cache : false,
             type: "POST",
             error : function(XMLHttpRequest, textStatus, errorThrown){
                alert(errorThrown);
             },
             success: function(data){
                $("#invitationStatus").html("Приглашение отослано на<br />" + $("#inviteEmail").val() + "<br />Еще одно?");
                $("#inviteEmail").val("");
                $("#inviteEmail").focus();
             }
         });
         return false;
      }
    });

 });
 function placePreloader(elementID)
 {
     $("#"+elementID).html('<img src="http://www.ngtu.ru/css/img/preloader.gif" />');
     return false;
 }
 
 function downloadPartView(url, elementID, data, type, showPreloader, whereShowPreloader)
 {
    if (showPreloader) placePreloader(whereShowPreloader);
    $.ajax({
        url : url,
        data : data,
        cache : false,
        type: type,
        error : function(XMLHttpRequest, textStatus, errorThrown){
           //console.log or alert error
           alert(errorThrown);
        },
        success: function(data){
           $("#"+elementID).html(data);
           return false;
        }
    });
    return false;
}