function validate(evt) {
  var theEvent = evt || window.event;
  var key = theEvent.keyCode || theEvent.which || theEvent.charCode;
  var keyPlain = key;
  key = String.fromCharCode(key);
  var regex = /[0-9]|\,/;
  if (!regex.test(key) && (keyPlain != 8 && keyPlain != 46 && keyPlain != 63272)) {
    theEvent.returnValue = false;
    if (theEvent.preventDefault) theEvent.preventDefault();
  }
  var input = $(theEvent.target);
  var value = input.val();
}

var initList = initList || [];
initList.push(function() {
  $('.content.tab1 input').each(function(index, value) {
    var $this = $(this);
    if ($this.hasClass('in_1_1_1') || $this.hasClass('in_1_2_1')) {
      $this.maskMoney({
        suffix: 'g Hg',
        allowNegative: false,
        thousands: ' ',
        decimal: ',',
        precision: 0
      });
    } else if ($this.hasClass('in_1_1_2') || $this.hasClass('in_1_2_2')) {
      $this.maskMoney({
        suffix: 'g Hg',
        allowNegative: false,
        thousands: ' ',
        decimal: ',',
        precision: 2
      });
    } else {
      $this.maskMoney({
        suffix: 'g Sin',
        allowNegative: false,
        thousands: ' ',
        decimal: ',',
        precision: 0
      });
    }
  });

  $('.content.tab2 input').each(function(index, value) {
    var $this = $(this);
    if ($this.hasClass('in_2_1_1') || $this.hasClass('in_2_2_1') || $this.hasClass('in_2_1_3') || $this.hasClass('in_2_2_3')) {
      $this.maskMoney({
        suffix: 'mol',
        allowNegative: false,
        thousands: ' ',
        decimal: ',',
        precision: 2
      });
    } else {
      $this.maskMoney({
        suffix: '',
        allowNegative: false,
        thousands: ' ',
        decimal: ',',
        precision: 3
      });
    }
  })

  sg.showPoster = function(item) {
    var classItem = '.poster' + item;
    var layer = $('<div>').addClass('black-layer').click(function() {
      sg.hidePoster(item);
    });
    $(classItem).addClass('slideInLeft').show().before(layer);
  }
  sg.hidePoster = function(item) {
    var classItem = '.poster' + item;
    $(classItem).hide().removeClass('slideInLeft');
    $('.black-layer').remove();
  }

  sg.check = function(exe){
    var inputs_search = '.content.tab'+exe+' .inputs_box input';
    var inputs = $(inputs_search);
    var right = true;
    inputs.each(function(index, value){
      var $this = $(this);
      var split_value = exe==1? 'g':'m';
      var value = $this.val().split(split_value)[0];
      console.log(value);
      var correct = $this.attr('data-sg-correct');
      if(value != correct){
        $(this).addClass('wrong');
        right = false;
      }else{
        $this.removeClass('wrong');
        $(this)[0].readOnly = true;
      }
    });

    if(right){
      sg.sound('success');
    }else{
      var layer = $('<div>').addClass('black-layer').click(function() {
        $('.black-layer').remove();
      });
      var inputs_box = ".content.tab" + exe + ' .inputs_box';
      $(inputs_box).before(layer);
      sg.sound('error');
    }
  }
});