$(function($){
    $(':password').InptLang();
  });
(function() {
  
  jQuery.InptLang = {};
  jQuery.InptLang.indicator = $('<span class="InptLang" />');
  jQuery.InptLang.target;
  jQuery.InptLang.layout;
  jQuery.InptLang.show = function(layout){
    this.layout = layout;
    this.indicator.text(layout);
    this.target.after(this.indicator);
  };
  jQuery.InptLang.hide = function(){
    this.target = null;
    this.layout = null;
    this.indicator.remove();
  };
  jQuery.fn.InptLang = function()
  {
	var txt = $('#p_4').text();
    this.each(function(){
      $(this).focus(function(){
        jQuery.InptLang.target = $(this);
      });
      $(this).blur(function(){
        jQuery.InptLang.hide();
		$('#p_4').text(txt).show();
      });
      $(this).keypress(function(e){
        var c = (e.charCode == undefined ? e.keyCode : e.charCode);
        var layout = jQuery.InptLang.layout;
        if (c >= 97/*a*/  && c <= 122/*z*/ && !e.shiftKey ||
            c >= 65/*A*/  && c <= 90/*Z*/  &&  e.shiftKey ||
             (c == 91/*[*/  && !e.shiftKey ||
              c == 93/*]*/  && !e.shiftKey ||
              c == 123/*{*/ &&  e.shiftKey ||
              c == 125/*}*/ &&  e.shiftKey ||
              c == 96/*`*/  && !e.shiftKey ||
              c == 126/*~*/ &&  e.shiftKey ||
              c == 64/*@*/  &&  e.shiftKey ||
              c == 35/*#*/  &&  e.shiftKey ||
              c == 36/*$*/  &&  e.shiftKey ||
              c == 94/*^*/  &&  e.shiftKey ||
              c == 38/*&*/  &&  e.shiftKey ||
              c == 59/*;*/  && !e.shiftKey ||
              c == 39/*'*/  && !e.shiftKey ||
              c == 44/*,*/  && !e.shiftKey ||
              c == 60/*<*/  &&  e.shiftKey ||
              c == 62/*>*/  &&  e.shiftKey) && layout != 'EN') {
          layout = '[en]';
        } else if (c >= 65/*A*/ && c <= 90/*Z*/  && !e.shiftKey ||
                   c >= 97/*a*/ && c <= 122/*z*/ &&  e.shiftKey) {
          layout = '[EN]';
        } else if (c >= 1072/*а*/ && c <= 1103/*я*/ && !e.shiftKey ||
                   c >= 1040/*А*/ && c <= 1071/*Я*/ &&  e.shiftKey ||
                   (c == 1105/*ё*/ && !e.shiftKey ||
                    c == 1025/*Ё*/ &&  e.shiftKey ||
                    c == 8470/*№*/ &&  e.shiftKey ||
                    c == 59/*;*/   &&  e.shiftKey ||
                    c == 44/*,*/   &&  e.shiftKey) && layout != 'RU') {
          layout = '[ru]';
        } else if (c >= 1040/*А*/ && c <= 1071/*Я*/ && !e.shiftKey ||
                   c >= 1072/*а*/ && c <= 1103/*я*/ &&  e.shiftKey) {
          layout = '[RU]';
        }
        if (layout) {
            //jQuery.InptLang.show(layout);
            $('#p_4').text(layout).show();
        }
      });
    });
  };
})();
