function AjaxRecover()
{
    $.ajax({
        type: "POST",
        dataType: "json",
        async: true,
        url: "/osp_moduls/cabinet/recover.ajaxhandler.php",
        data: {
            "login":$('.arf_value_login').val(),
            "email":$('.arf_value_email').val(),
            "catalogue":$('.arf_value_catalogue').val(),
            "sub":$('.arf_value_sub').val()
        },
        success: function(msg) {
            if(msg.data.result=="success"){
                showOnSuccess(msg.data.message);
            } else {
                var message='Неверные данные!';
                if(msg.data.message) {
                    message=msg.data.message;
                }
                showAjaxRecoverForm(message);
            }
        }
    });

    hideAjaxRecoverForm();
}

function hideAjaxRecoverForm()
{
    $('.ajax_recover_form').remove();
}

function showAjaxRecoverForm(message)
{
    var messageHtml='';
    if(message) {
        messageHtml='\
            <tr>\
                <td colspan="2">\
                    <div class="arf_message">\
                        '+message+'\
                    </div>\
                </td>\
            </tr>\
        ';
    }

    var jForm=$('\
        <div class="ajax_recover_form">\
            <input type="hidden" class="arf_value_catalogue arf_value" value="' + netcatPage.catalogue + '">\
            <input type="hidden" class="arf_value_sub arf_value" value="' + netcatPage.sub + '">\
            <table>\
                <tbody>\
                    <tr>\
                        <td>\
                            <span class="arf_text">Логин: </span>\
                        </td>\
                        <td>\
                            <input class="arf_value_login arf_value" type="text" />\
                        </td>\
                    </tr>\
                    <tr>\
                        <td>\
                            <span class="arf_text">E-mail: </span>\
                        </td>\
                        <td>\
                            <input class="arf_value_email arf_value" type="text" />\
                        </td>\
                    </tr>\
                    '+messageHtml+'\
                </tbody>\
            </table>\
        </div>\
    ');

    jForm.keyup(function(event){
        if (event.keyCode == '13') {
            AjaxRecover();
        }
    });

    jForm.dialog({
        title:'Восстановление пароля',
        buttons: {
            "Восстановить": function() {
                AjaxRecover();
            }
        },
        close: function(event, ui) {
            hideAjaxRecoverForm();
        },
        position: 'center',
        width   : ajaxRecoverFormWidth
    });
}

function showOnSuccess(message)
{
    $('\
        <div class="ajax_recover_form">\
            <table>\
                <tbody>\
                    <tr>\
                        <td>\
                            <div>'+message+'</div>\
                        </td>\
                    </tr>\
                </tbody>\
            </table>\
        </div>\
    ').dialog({
        title: "Поздравляем",
        position: 'center',
        width   : ajaxRecoverFormWidth 
    });
}
