$(document).ready(function(){
    /*подключение jquery плагинов*/
    $(document).placeholder();
    $('#datepick').datepicker({ dateFormat: 'dd.mm.yy' });
    $('#passpdatepick').datepicker({ dateFormat: 'dd.mm.yy' });
    /*подключение jquery плагинов*/
    
    $('.send_feedback').click(function(){
        var err = 0;
        $('.req').each(function(){
            if( ($(this).val() == '') || ($(this).val() == null) || ($(this).val() == undefined) || ($(this).val() == false)){
                name = '#for_'+ $(this).attr('name');
                $(name).show();
                err = 2;
            }
            else {
                name = '#for_'+ $(this).attr('name');
                $(name).hide();
            }
        });
        if( !$('input[name=captcha_word]').val() ){
            document.getElementById('for_captcha_code').style.display = 'block';
            err = 2;
        }
        else {
            document.getElementById('for_captcha_code').style.display = 'none';
            }
        
        if( err == 2 ){
            return false;
        }
        $('#form_feedback').submit();
    });
    
    $('input.register_but').click(function(){
        var err = 0;
        captchatext = $('#captcha_word').val();
        captchacode = $('#captcha_code').val();
        email = $('#regEmail').val();
        if( $('#confirm').attr('checked') == undefined || $('#ireadthissh').attr('checked') == undefined ){
            $('#wrongCaptcha').html("Необходимо подтвердить правильность введенных данных и факт ознакомления с документами.");
            $('#wrongCaptcha').dialog();
            return false;
        }
        $('.req').each(function(){
            if( ($(this).val() == '') || ($(this).val() == null) || ($(this).val() == undefined) || ($(this).val() == false)){
                name = '#for_'+ $(this).attr('name');
                $(name).show();
                err = 2;
            }
            else {
                name = '#for_'+ $(this).attr('name');
                $(name).hide();
            }
        });
        if( !$('#captcha_word').val() ){
            document.getElementById('for_captcha_code').style.display = 'block';
            err = 2;
        }
        else {
            document.getElementById('for_captcha_code').style.display = 'none';
        }
        if( err > 1 ){
            return false;
        }
        else {
            $.ajax({
                url: "/ajax/email.php?email="+email,
                success: function(response){
                    if( !(response == 'ok') ){
                        $('#wrongCaptcha').html("Пользователь с таким email уже зарегистрирован");
                        $('#wrongCaptcha').dialog();
                        return false;
                    }
                    else{
                        $.ajax({
                            url: "/ajax/captcha.php?code="+captchacode+"&text=" + captchatext,
                            success: function(response){
                                if( response == 'ok' ){
                                    $('#form_feedback').submit();
                                }
                                else {
                                    $('.feedback_page_second_col img').attr('src', '/bitrix/tools/captcha.php?captcha_code=' + response);
                                    $('#captcha_code').val(response);
                                    $('#wrongCaptcha').html("Captcha код неверен");
                                    $('#wrongCaptcha').dialog();
                                    return false;
                                }
                            }
                        });
                    }
                }
            });
        }
    });
    
    
    $('body').click(function(){
        $('div.dropdown_menu').hide();
    });
    
    $('div.cabinet').click(function(event){
        $('div.dropdown_menu').toggle();
        event.stopPropagation();
    });

    
    $('#unblock_details').click(function(){
        $(".feedback_page_second_col > input").each(function(){
            $(this).attr({
                disabled : false
            });
        });
        $("#save_details_but").attr({disabled : false});
        $(".feedback_page_second_col > input.req").each(function(){
            $(this).attr({
                required : 'true'
            });
        });
        return false;
    });
    
    $('#save_withdraw').click(function(){
        var err = 0;
        if( $('#withdrawFile').val() == "" ) {
            $('#wrongCaptcha').html("Необходимо прикрепить файл");
            $('#wrongCaptcha').dialog({
                modal: true,
                buttons: {
                    "Продолжить": function() {
                        $(this).dialog("close");
                    }
                }
            });
            return false;
        }
        
        if( $('#sumWithdraw').val() == false || $('#sumWithdraw').val() == undefined || $('#sumWithdraw').val() == ''){
                err = 1;
        }
        if( document.getElementById('confirmDeals').checked == false ) {
            $('#wrongCaptcha').html("Подтвердите, что нет открытых сделок");
            $('#wrongCaptcha').dialog({
                modal: true,
                buttons: {
                    "Продолжить": function() {
                        $(this).dialog("close");
                    }
                }
            });
            return false;
        }
        if( document.getElementById('confirmComm').checked == false ) {
            $('#wrongCaptcha').html("Подтвердите, что Вы согласны на комиссию");
            $('#wrongCaptcha').dialog({
                modal: true,
                buttons: {
                    "Продолжить": function() {
                        $(this).dialog("close");
                    }
                }
            });
            return false;
        }
        if(err == 0){
            $('#formDetails').attr({'action' : '', 'target' : '_self'}).submit();
            return true;
        }
        else {
            $('#wrongCaptcha').html("Укажите сумму и прикрепите файл");
            $('#wrongCaptcha').dialog({
                modal: true,
                buttons: {
                    "Продолжить": function() {
                        $(this).dialog("close");
                    }
                }
            });
            return false;
        }
    });
    
    $('#save_details_but').click(function(){
        var err = 0;
        $(".feedback_page_second_col > input.req").each(function(){
            if( $(this).val() == false || $(this).val() == undefined || $(this).val() == ''){
                err = 1;
            }
        });
        if(err == 0){
            if($('#BeneficiaryBankAccount').val().length == 20){
                data = $("#BeneficiaryBankAccount").val();
                symbols = data[5]+data[6]+data[7];
                
                if( symbols != 840 ){
                    $('#wrongCaptcha').html("6, 7, и 8 цифры номера счета получателя платежа должены быть 840");
                    $('#wrongCaptcha').dialog({
                        modal: true,
                        buttons: {
                            "Продолжить": function() {
                                $(this).dialog("close");
                            }
                        }
                    });
                    return false;
                }
            }
            else {
                if($('#nonstandart').val() != 1){
                    $('#wrongCaptcha').html("Введенный вами номер счета получателя имеет нестандартный вид");
                    $('#wrongCaptcha').dialog({
                        modal: true,
                        buttons: {
                            "Исправить": function() {
                                $(this).dialog("close");
                                $('#BeneficiaryBankAccount').val("").focus();
                            },
                            "Продолжить": function() {
                                $(this).dialog("close");
                                $('#nonstandart').val('1');
                            }
                        }
                    });
                    return false;
                }
            }
            $(".feedback_page_second_col > input.req").each(function(){
                data = $(this).val();
                if( /[А-яё]+/ig.test(data) ){
                    $('#wrongCaptcha').html("Форма должна содержать только латинские символы");
                    $('#wrongCaptcha').dialog({
                        modal: true,
                        buttons: {
                            "Продолжить": function() {
                                $(this).dialog("close");
                            }
                        }
                    });
                    return false;
                }
                else {
                }
            });
            if( document.getElementById('confirm').checked == false ) {
                $('#wrongCaptcha').html("Подтвердите правильность введенных данных");
                $('#wrongCaptcha').dialog({
                    modal: true,
                    buttons: {
                        "Продолжить": function() {
                            $(this).dialog("close");
                        }
                    }
                });
                return false;
            }
        }
        else {
            $('#wrongCaptcha').html("Не все требуемые поля заполнены");
            $('#wrongCaptcha').dialog({
                modal: true,
                buttons: {
                    "Продолжить": function() {
                        $(this).dialog("close");
                    }
                }
            });
            return false;
        }
    });
    
    $('#printInvoice').click(function(){
        if(checkform()){
            $('#formDetails').attr({'action' : '/print/index.php', 'target' : '_blank'}).submit();
        }
    });
    
    $('#printTransfer').click(function(){
        if(checkform_transfer()){
            $('#formDetails').attr({'action' : '/print/index.php', 'target' : '_blank'}).submit();
        }
    });
    
    
    /*tabs on user messages page*/
    $('div.tab_write').click(function(){
        $("#tab_write").removeClass("hidden");
        $("#tab_complaint").addClass("hidden");
        $(this).removeClass('tab_write_unactive');
        $('div.tab_complaint').addClass("tab_complaint_unactive");
    });
    
    $('div.tab_complaint').click(function(){
        $("#tab_write").addClass("hidden");
        $("#tab_complaint").removeClass("hidden");
        $(this).removeClass('tab_complaint_unactive');
        $('div.tab_write').addClass("tab_write_unactive");
    });
    /**/
    
    $('#departamentList').change(function(){
        if( $(this).val() == "" ){
            $('#resultMess').text("Выберите адресата");
            $('#resultMess').show().css("color", "red");
        }
        else {
            $('#resultMess').text("");
            $('#resultMess').hide().css("color", "#000");
        }
    });
    
    $('input.hidden_input').change(function(){
        fname = $(this).val();
        name = (fname.match(/(?:^|\/|\\)([^\\\/]+)$/)[1]);
        $(this).prev().prev().val(name);
    });

    $('#save_transfer').click(function(){
        var err = 0;
        
        $(".transfer_user_page_second_col input.req").each(function(){
            if( $(this).val() == false || $(this).val() == undefined || $(this).val() == ''){
                err = 1;
            }
        });
        if(err == 0){

            if( document.getElementById('confirm').checked == false ) {
                $('#wrongCaptcha').html("Подтвердите правильность введенных данных");
                $('#wrongCaptcha').dialog();
                return false;
            }
            
            if( $('#withdrawFile').val() == "" ) {
                $('#wrongCaptcha').html("Необходимо прикрепить файл");
                $('#wrongCaptcha').dialog();
                return false;
            }
            
            if( document.getElementById('confirmDeals').checked == false ) {
                $('#wrongCaptcha').html("Подтвердите, что нет открытых сделок");
                $('#wrongCaptcha').dialog();
                return false;
            }
            
            $('#formDetails').attr({'action' : '', 'target' : '_self'}).submit();
        }
        else {
            $('#wrongCaptcha').html("Не все требуемые поля заполнены");
            $('#wrongCaptcha').dialog();
            return false;
        }
    });
    
    
    /*************************/
    $('div.user_name > span').click(function(){
        arId = $(this).attr('id').split("_");
        id = arId[1];
        if(!$(this).hasClass('selected')){
            $(this).addClass('selected');
            $("#data_" + id).removeClass('hidden');
        }
        else{
            $(this).removeClass('selected');
            $("#data_" + id).addClass('hidden');
        }
    });
    
    $('div.serviceman_user_list > p').click(function(){
        arId = $(this).attr('id').split("_");
        id = arId[1];
        
        if(!$(this).hasClass('selected')){
            $('div.user_list_elem > p').each(function(){
                $(this).removeClass('selected');
            });
            $(this).addClass('selected');
            
            $("div.service_user_data").load('/ajax/userdata.php?id=' + id + "&mode=show");
            if( $(this).hasClass('unreaded') ){
                $('div.serviceman_messages_list_wr > div').load('/ajax/usermess.php?id=' + id +"&unread=y");
            }
            else{
                $('div.serviceman_messages_list_wr > div').load('/ajax/usermess.php?id=' + id);
            }
        }
        else{
            return false;
        }
    });
    /*************************/
    
    $('div.complaints_list > p').click(function(){
        arId = $(this).attr('id').split("_");
        id = arId[1];
        $('#userid').attr('title', id);
        if(!$(this).hasClass('selected')){
            $('div.user_list_elem > p').each(function(){
                $(this).removeClass('selected');
            });
            $(this).addClass('selected');
            $("div.service_user_data").load('/ajax/partner_usersdata.php?id=' + id + "&mode=show");
            $('div.serviceman_messages_list_wr > div').load('/ajax/complaint.php?id=' + id);
        }
        else{
            return false;
        }
    });
    /*************************/
    $('div.user_list_elem > p').live('click',function(){
        arId = $(this).attr('id').split("_");
        id = arId[1];
        $('#userid').attr('title', id);
        if(!$(this).hasClass('selected')){
            $('div.user_list_elem > p').each(function(){
                $(this).removeClass('selected');
            });
            $(this).addClass('selected');
            if($(this).hasClass('complaint')){
                $("div.service_user_data").load('/ajax/partner_usersdata.php?id=' + id + "&mode=show");
            }
            else {
                $("div.service_user_data").load('/ajax/userdata.php?id=' + id + "&mode=show");
            }
            if( $(this).hasClass('unreaded') ){
                $('div.serviceman_messages_list_wr > div').load('/ajax/usermess.php?id=' + id +"&unread=y");
            }
            else{
                if($(this).hasClass('complaint')){
                    $('div.serviceman_messages_list_wr > div').load('/ajax/complaint.php?id=' + id + "&mode=complaint");
                }
                else {
                    $('div.serviceman_messages_list_wr > div').load('/ajax/usermess.php?id=' + id);
                }
            }
        }
        else{
            return false;
        }
    });
    /*************************/
    /*************************/
    $('div.user_list_elem > span').click(function(){
        arId = $(this).attr('id').split("_");
        id = arId[1];
        $('#userid').attr('title', id);
        if(!$(this).hasClass('selected')){
            $('div.user_list_elem > span').each(function(){
                $(this).removeClass('selected');
            });
            $(this).addClass('selected');
            $('div.serviceman_messages_list_wr > div').load('/ajax/asklist.php?id=' + id);
        }
        else{
            return false;
        }
    });
    /*************************/
    $('td.partner_name > p').click(function(){
        arId = $(this).attr('id').split("_");
        id = arId[1];
        $('#userid').attr('title', id);
        
        if(!$(this).hasClass('selected')){
            $('td.partner_name > p').each(function(){
                $(this).removeClass('selected');
            });
            $(this).addClass('selected');
            $("div.scroll_pane_users").load('/ajax/userlist.php?id=' + id);
            $("div.service_user_data").load('/ajax/partner_usersdata.php?id=' + id + "&mode=show");
            if( $(this).hasClass('unreaded') ){
                $('div.serviceman_messages_list_wr > div').load('/ajax/usermess.php?id=' + id +"&unread=y");
            }
            else{
                $('div.serviceman_messages_list_wr > div').load('/ajax/usermess.php?id=' + id);
            }
        }
        else{
            return false;
        }
    });
    /*************************/
    $('div.scroll_pane_users').click(function(event){
        var clicked = $(event.target);
        if( clicked.is('p') ){
            rawId = $(clicked).attr('id');
            arId = rawId.split("_");
            id = arId[1];
            $('#userid').attr('title', id);
            if(!$(clicked).hasClass('selected')){
                $('div.user_list_elem > p').each(function(){
                    $(this).removeClass('selected');
                });
                $(clicked).addClass('selected');
                $("div.service_user_data").load('/ajax/partner_usersdata.php?id=' + id + "&mode=show");
                if( $(this).hasClass('unreaded') ){
                    $('div.serviceman_messages_list_wr > div').load('/ajax/usermess.php?id=' + id +"&unread=y");
                }
                else{
                    $('div.serviceman_messages_list_wr > div').load('/ajax/usermess.php?id=' + id);
                }
            }
            else{
                return false;
            }
        }
    });
    /*************************/
    /*$('div.readed_chkbx input').change(function(){
        arId = $(this).attr('id').split("_");
        val = this.checked;
        id = arId[1];
        $.ajax({
            url: "/ajax/readed.php?id=" + id + "&val=" + val,
            async : false,
            cache : false,
            dataType : "script"
        });
    });*/
    
    $('div.serviceman_messages_list_wr, div.partner_users_list_wr').click(function(event){
        var clicked = $(event.target);
        if( clicked.attr('type') == "checkbox" ){
            rawId = clicked.attr('id');
            arId = rawId.split("_");
            id = arId[1];
            val = document.getElementById(rawId).checked;
            if($('#'+rawId).hasClass('complaint_chkbx')){
                $.ajax({
                    url: "/ajax/readed.php?id=" + id + "&val=" + val + "&complaint=y",
                    async : false,
                    cache : false,
                    dataType : "script"
                });
            }
            else {
                $.ajax({
                    url: "/ajax/readed.php?id=" + id + "&val=" + val,
                    async : false,
                    cache : false,
                    dataType : "script"
                });
            }
        }
    });
    /*************************/
    $('#userData').submit(function(){
            datas = $(this).serialize();
        if($('#director').val() == "true"){
            $.ajax({
                url: "/ajax/partner_usersdata.php",
                type: "post",
                data: datas,
                success: function(responce){
                    if( responce !== null && responce !== "" && responce !== undefined )
                        $('#error').html(responce);
                    else 
                        $('#error').html("Сохранено");
                    $('#error').dialog();
                }
            });
        }
        else {
            $.ajax({
                url: "/ajax/userdata.php",
                type: "post",
                data: datas,
                success: function(responce){
                    if( responce !== null && responce !== "" && responce !== undefined )
                        $('#error').html(responce);
                    else 
                        $('#error').html("Сохранено");
                    $('#error').dialog();
                }
            });
        }
        return false;
    });
    
    $('#userFilter').keyup(function(){
        var key = $(this).val();
        //var reg = new RegExp("^"+key, "ig");
        var reg = new RegExp(key, "ig");
        $('.user_list_elem > p').each(function(){
            text = $(this).text();
            if ( reg.test(text) ) {
                $(this).parent().show();
            }
            else {
                $(this).parent().hide();
            }
        });
    });
    
    $("#sortLine > select").change(function() { 
        value = this.value;
        name = this.name;
        id = $('#userid').attr('title');
        if( id ){
            $('div.serviceman_messages_list_wr > div').load('/ajax/usermess.php?mode=' + name + '&value=' + value + '&id=' + id);
        }
    });
    
    
    $('#complain').click(function(){
        $('#tab_complaint').removeClass('hidden');
        $('#tab_write').addClass('hidden');
    });
    $('#writeMess').click(function(){
        $('#tab_complaint').addClass('hidden');
        $('#tab_write').removeClass('hidden');
    });
    
    $('.delete_msg').live('click', function(){
        var rawId = $(this).attr('id');
        var ar_id = rawId.split('_');
        $.ajax({
            url: "/ajax/delmsg.php",
            data: "id=" +ar_id[1],
            success: function(responce){
                if( !responce ) {
                    $('tr#line_' + ar_id[1]).remove();
                }
            }
        });
    });
    
});

function checkDep(){
    if($('#departamentList').val() == ""){
        $('#resultMess').text("Выберите адресата");
        $('#resultMess').show().css("color", "red");
        return false;
    }
    else {
        //$('#messToService').submit();
    }
}

function depositSumCheck(){
    if($('#sum').val() == ""){
        $('#error').html("Введите сумму");
        $('#error').dialog();
        return false;
    }
    else {
        if(document.getElementById('confirm').checked !== true){
            $('#error').html("Подтвердите согласие");
            $('#error').dialog();
            return false;
        }
        else{
            $('#depositSum').submit();
        }
    }
}

function depositDocCheck(){
    if($('#document').val() == ""){
        $('#error').html("Выберите файл");
        $('#error').dialog();
        return false;
    }
    else {
        if($.trim($('#sum_input').val()).length == 0){
            $('#error').html("Введите сумму");
            $('#error').dialog();
            return false;
        }
        if(document.getElementById('confirmDoc').checked !== true){
            $('#error').html("Подтвердите согласие");
            $('#error').dialog();
            return false;
        }
        else{
            $('#depositDoc').submit();
        }
    }
}

function ctrlEnter(event, elem){
    if((event.ctrlKey) && ((event.keyCode == 0xA)||(event.keyCode == 0xD))){
        text = elem.value;
        arId = arId = $(elem).attr('id').split("_");
        id = arId[1];
        answBy = $('#service_' + id).val();
        section = $('#section_' + id).val();
        $.ajax({
            url: "/ajax/answer.php",
            type: "post",
            data: {
                answer: text, 
                service: answBy,
                section: section
            },
            success: function(responce){
                if( responce !== null && responce !== "" && responce !== undefined ){
                    $('#error').html(responce);
                }
                else {
                    $('#error').html("Сохранено");
                    $(elem).val('');
                }
                $('#error').dialog();
                
            }
        });
    }
}
function sendAnswer(event, elem){
    if((event.ctrlKey) && ((event.keyCode == 0xA)||(event.keyCode == 0xD))){
        text = elem.value;
        arId = arId = $(elem).attr('id').split("_");
        id = arId[1];
        section = $('#section_' + id).val();
        $.ajax({
            url: "/ajax/answerbydir.php",
            type: "post",
            data: {
                answer: text, 
                section: section,
                elem: id
            },
            success: function(responce){
                if( responce !== null && responce !== "" && responce !== undefined ){
                    $('#error').html(responce);
                }
                else {
                    $('#error').html("Сохранено");
                    $(elem).val('');
                }
                $('#error').dialog();
                
            }
        });
    }
}

function sendAnswerOnQuestion(event, elem){
    if((event.ctrlKey) && ((event.keyCode == 0xA)||(event.keyCode == 0xD))){
        text = elem.value;
        arId = arId = $(elem).attr('id').split("_");
        id = arId[1];
        $.ajax({
            url: "/ajax/sendAnswerOnComplaint.php",
            type: "post",
            data: {
                answer: text, 
                elem: id
            },
            success: function(responce){
                if( responce !== null && responce !== "" && responce !== undefined ){
                    $('#error').html(responce);
                }
                else {
                    $('#error').html("Сохранено");
                    $(elem).val('');
                }
                $('#error').dialog();
                
            }
        });
    }
}

function add_to_partner(elem){
    rawId = $(elem).attr('class');
    arId = rawId.split("_");
    id = arId[1];
    val = document.getElementById($(elem).attr('id')).checked;
    $.ajax({
        url: "/ajax/addtopartner.php?id=" + id + "&val=" + val,
        async : false,
        cache : false,
        dataType : "script"
    });
}

function checkform(){
    var err = 0;
    $(".feedback_page_second_col > input.req").each(function(){
        if( $(this).val() == false || $(this).val() == undefined || $(this).val() == ''){
            err = 1;
        }
    });
    if(err == 0){

        if($('#BeneficiaryBankAccount').val().length == 20){
            data = $("#BeneficiaryBankAccount").val();
            symbols = data[5]+data[6]+data[7];
            
            if( symbols != 840 ){
                $('#wrongCaptcha').html("6, 7, и 8 цифры номера счета получателя платежа должены быть 840");
                $('#wrongCaptcha').dialog({
                    modal: true,
                    buttons: {
                        "Продолжить": function() {
                            $(this).dialog("close");
                        }
                    }
                });
                return false;
            }
        }
        else {
            if($('#nonstandart').val() != 1){
                $('#wrongCaptcha').html("Введенный вами номер счета получателя имеет нестандартный вид");
                $('#wrongCaptcha').dialog({
                    modal: true,
                    buttons: {
                        "Исправить": function() {
                            $(this).dialog("close");
                            $('#BeneficiaryBankAccount').val("").focus();
                        },
                        "Продолжить": function() {
                            $(this).dialog("close");
                            $('#nonstandart').val('1');
                        }
                    }
                });
                return false;
            }
        }

        $(".feedback_page_second_col > input.req").each(function(){
            data = $(this).val();
            if( /[А-яё]+/ig.test(data) ){
                $('#wrongCaptcha').html("Форма должна содержать только латинские символы");
                $('#wrongCaptcha').dialog();
                return false;
            }
            else {
            }
        });
                
        if( $(this).hasClass('save_withdraw') ){
            if( document.getElementById('confirmDeals').checked == false ) {
                $('#wrongCaptcha').html("Подтвердите, что нет открытых сделок");
                $('#wrongCaptcha').dialog();
                return false;
            }
            if( document.getElementById('confirmComm').checked == false ) {
                $('#wrongCaptcha').html("Подтвердите, что Вы согласны на комиссию");
                $('#wrongCaptcha').dialog();
                return false;
            }
        }
        return true;
    }
    else {
        $('#wrongCaptcha').html("Не все требуемые поля заполнены");
        $('#wrongCaptcha').dialog();
        return false;
    }
}

function checkform_transfer(){
    var err = 0;
    $(".transfer_user_page_second_col input.req").each(function(){
        if( !$(this).hasClass('abs') ){
            if( $(this).val() == false || $(this).val() == undefined || $(this).val() == ''){
                err = 1;
            }
        }
    });
    if(err == 0){
        if( document.getElementById('confirm').checked == false ) {
            $('#wrongCaptcha').html("Подтвердите, что введенные данные верны");
            $('#wrongCaptcha').dialog();
            return false;
        }
        else if( document.getElementById('confirmDeals').checked == false ) {
            $('#wrongCaptcha').html("Подтвердите, что нет открытых сделок");
            $('#wrongCaptcha').dialog();
            return false;
        }
        else {
            return true;
        }
    }
    else {
        $('#wrongCaptcha').html("Не все требуемые поля заполнены");
        $('#wrongCaptcha').dialog();
        return false;
    }
}
function onlyDigits(e)
{
  // Make sure to use event.charCode if available
  var key = (typeof e.charCode == 'undefined' ? e.keyCode : e.charCode);

  // Ignore special keys
  if (e.ctrlKey || e.altKey || key < 32)
    return true;

  key = String.fromCharCode(key);
  return /[\d\.]/.test(key);
}
