// -----------------------------------------------------------------------------

$(document).ready(function (){
    
    $("#checkBills").click(function(){

        $(".preloader").hide();
        $("#loginForm").find(".login").show();
        $("#loginForm").find(".passRecovery").hide();
        $("#loginForm").find("input").each(function(){
            if ( "submit" != this.type && "button" != this.type ) {
                this.value = "";
            }
        });
        $("#loginForm").find('.rightlogin_ch').html('');
        $("#loginForm").find(".successPass").hide();
        // форма логинизации
        $("#loginForm").show();

    });

        // кнопка войти
        $("#loginSubmit").click(function(){
            //готовим прелоадер
            $("#loginForm").find('.rightlogin_ch').html('');
            $(".preloader").show();
            $.post("/member_login_jx.php",
                   { login : $("#memberEmail").val(),
                     password : $("#memberPassword").val()
                   },
                   loginResponse);
                   return false;
        });

        $("#loginForm").find(".close").click(function(){
            $("#loginForm").hide();
        });

    $("#recoveryLink").click(function(){
        $("#loginForm").find(".login").hide();
        $("#loginForm").find(".passRecovery").show();
        $("#loginForm").find('.rightlogin_ch').html('');
    });

    $("#recoverySubmit").click(function(){
        $("#loginForm").find('.rightlogin_ch').html('');
        $(".preloader").show();
        $.post("/member_recovery_password_jx.php",
               {
                   login : $("#recoveryEmail").val()
               },
               recoveryResponse);
               return false;
    });
});

function loginResponse(response){
    $(".preloader").hide();
    if ( response == "member_login_success" ) {
        location.href = '/balance';
        return false;
    }
    //$(".rightlogin_ch").html(response);
    alert(response);
    return false;
}

function recoveryResponse(response){
    $(".preloader").hide();
    if ( response == "member_recovery_success" ) {
        $("#loginForm").find(".passRecovery").hide();
        $("#loginForm").find(".successPass").show();
        return false;
    }
    //$("#loginForm").find('.rightlogin_ch').html(response);
    alert(response);
    return false;
}

// -----------------------------------------------------------------------------

$(document).ready(function(){

    $('.memberAgreement').click(function(){
        $("#activateCardPrs").show();
    });
    $("#activateCardForm").find(".close").click(function(){
        $("#activateCardForm").hide();
    });

    $("#activateCardPrs").find(".close").click(function(){
        $("#activateCardPrs").hide();
    });

    $("#activateCard").click(function(){
        $(".rightlogin_ch").html('');
        $("#activateCardForm").find(".inputs").show();
        $("#activateCardForm").find(".userLicence").hide();

        $("#activateCardForm").show();
        $("#activateCardForm").find(".close").click(function(){
            $("#activateCardForm").hide();
            $("#activateCardForm").find("input, select").each(function(){
                if ( this.type != "submit" && this.type != "button" ) {
                    this.value = "";
                }
            });
        });
    });

    //memberActivateSuccess
    $("#memberActivate").click(function(){
        $(".rightlogin_ch").html('');
        var query = "";
        $("#activateCardForm").find("input, select").each(function(){
            if ( this.type != "submit" && this.type != "button" && this.id != "" ) {
                if ( query != "" ) {
                    query += ", ";
                }
                query += this.id + ":'" + encodeURIComponent(this.value) + "'";
            }
        });

        eval("var option = {" + query + "}");
        $.post("/member_activate_card.php", option, memberActivate);
    });

    $("#memberActivateSuccess").click(function(){
        $(".rightlogin_ch").html('');
        var query = "";
        $("#activateCardForm").find("input, select").each(function(){
            if ( this.type != "submit" && this.type != "button" && this.id != "" ) {
                if ( query != "" ) {
                    query += ", ";
                }
                query += this.id + ":'" + encodeURIComponent(this.value) + "'";
            }
        });

        eval("var option = {" + query + ", member_activate : 'success'}");
        $("#activateCardForm").find(".rightlogin_ch").html('');
        //activatePrelodaer.show();
        $.post("/member_activate_card.php", option, memberActivate);
    });
});

function memberActivate(response){
//    activatePrelodaer.hide();
      //  alert(response);
      if ( response == "validate_activate_card_success" ) {
         $("#activateCardForm").find(".inputs").hide();
         $("#activateCardForm").find(".userLicence").show();
         return false;
      }
      if ( response == "activate_card_success" ) {
         $("#activateCardForm").hide();
         $("#endActiv").show();
         $("#endActiv").find(".close").click(function(){
             $("#endActiv").hide();
         });
         $("#activateCardForm").find("input, select").each(function(){
            if ( this.type != "submit" && this.type != "button" ) {
                this.value = "";
            }
         });
         return false;
      }
      $("#activateCardForm").find(".inputs").show();
      $("#activateCardForm").find(".userLicence").hide();
      //$("#activateCardForm").find(".rightlogin_ch").html(response);
      alert(response);
      return false;
}

function member_birthday_change()
{
    var val = "";
    val += $("#member_day")  .val() + "-";
    val += $("#member_month").val() + "-";
    val += $("#member_year") .val();
    $("#member_birthday").val(val);
}