 function lib_open_img_window(src,width,height){
   if(width==0)
     width=500;
   width+=20;
   if(height==0)
     height=400;
   height+=20;
   if(height>600)
     height=600;
   var left = (screen.availWidth/2) - (width/2);
   var top = (screen.availHeight/2) - (height/2);
   info=window.open('/img_preview.php?src='+src,'info','resizable=1, scrollbars=1, toolbar=0, status=0, width='+width+', height='+height+', left='+left+', top='+top);
   info.focus();
 }
function open_window(src, id, width, height){
   if(width==0)   width=500;
   width+=20;
   if(height==0)  height=400;
   height+=20;
   if(height>600)  height=600;
   var left = (screen.availWidth/2) - (width/2);
   var top = (screen.availHeight/2) - (height/2);
   info=window.open('/'+src+'?id='+id,'photo','resizable=1, scrollbars=1, toolbar=0, status=0, width='+width+', height='+height+', left='+left+', top='+top);
   info.focus();
 }


function sendVote(id,direct){
    if ( id > 0 && direct != '' ){
        $('#vote_up_'+id).html('<img src="/img/spacer.gif" width="7" height="10" />');
        $('#vote_down_'+id).html('<img src="/img/spacer.gif" width="7" height="10" />');
        $('#vote_up_'+id).addClass('up_str_null');
        $('#vote_down_'+id).addClass('down_str_null');
        
        $.post(
        '/votes.php',
        {
            act: "vote",
            id: id,
            direct: direct
        },
        function (data){
            res_list = data.split("<!--split-->");
            var good = res_list[0];
            var msg = res_list[1];
            if ( good == 'good' ){
                if ( msg > 0 ){
                    $('#vote_data_'+id).attr('class','up_ball');
                }
                else if( msg == 0 ){
                    $('#vote_data_'+id).attr('class','null_ball');
                }
                else{
                    msg = '&minus;'+Math.abs(msg);
                    $('#vote_data_'+id).attr('class','down_ball');
                }
                if ( msg != '' ){
                    $('#vote_data_'+id).html(msg);
                }
            }
            else{
            }
        }
        );
    }
}



/**
 * Авторизация пользователя
 */

function peopAuthSbmt(){
    var login = $('#logintext').attr('value');
    var password = $('#passwordtext').attr('value');
    $('#login_form .msg').css('visibility','hidden');
    if ( login != '' && password != '' ){
        /// Передача данных раздела
        $.post(
        '/profile_login.php',
        {
            act: "login_jx",
            login: login,
            password: password
        },
        function(result){
            if ( result == '1' ){
                window.location.replace('/profile');
            }
            else{
                $('#login_form .msg').text('Неверный логин или пароль.');
                //$('#forum_auth .msg').html(result);
                $('#login_form .msg').css('visibility','visible');
            }
        });
    }
}



/**
 * Переключение меню подблоков списка докладов пользователя
 */
function titleLinkToggle(parent_id){
    $('.title_link span').hide();
    $('.title_link a').show();
    $('#'+parent_id+'_l a').hide();
    $('#'+parent_id+'_l span').show();
    $('.events_data').hide();
    $('#'+parent_id).show();
}


/**
 * Заявка на доклад
 */
function profileRepSbmt(form){
    $('#but').attr('disabled','disable');
    $.ajaxUpload
    ({
        url: '/profile_forms.php?act=send_rep',
        secureuri: false,
        uploadform: form,
        type: 'POST',
        dataType: 'html',
        success: function (data, status){
            res_list = data.split("<!--split-->");
            var good = res_list[0];
            var msg = res_list[1];
            if ( good == 'good' ){
                $('#msg').html(msg);
                $('#msg').show();
                $('#block_data').hide();
            }
            else{
                $('#msg').html('<span class="alert">'+msg+'</span>');
                $('#msg').show();
            }
            $('#but').attr('disabled','');
        },
        error: function (data, status){
            $('#report_form .msg').html('<span class="msgText errorText">Ошибка отправки данных формы</span>');
            $('#but').attr('disabled','');
        }
    });
}

function addText(text,field_to){
    var value = $('#'+field_to).attr('value');
    if ( value == undefined ){
        value = '';
    }
    value += text;
    $('#'+field_to).attr('value',value);
}

function addTextFrom(txt_from,field_to){
    var text = $('#'+txt_from).html();
    var value = $('#'+field_to).attr('value');
    if ( value == undefined ){
        value = '';
    }
    value += text;
    $('#'+field_to).attr('value',value);
}

function addTags(tag_id,field_to){
    var value = $('#'+field_to).attr('value');
    if ( value != '' && value != undefined ){
        addText(', ',field_to);
    }
    addTextFrom('tag_'+tag_id,field_to)
}



/**
 * Материалы для доклада
 */

function profileSrcSbmt(form,ev_id){
    $('#src_but_'+ev_id).attr('disabled','disable');
    $.ajaxUpload
    ({
        url: '/profile_forms.php?act=send_src&id='+ev_id,
        secureuri: false,
        uploadform: form,
        type: 'POST',
        dataType: 'html',
        success: function (data, status){
            res_list = data.split("<!--split-->");
            var good = res_list[0];
            var msg = res_list[1];
            var ev_id = res_list[2];
            if ( good == 'good' ){
                $('#msg_'+ev_id).html(msg);
                $('#msg_'+ev_id).show();
                $('#block_data_'+ev_id).hide();
            }
            else{
                $('#msg_'+ev_id).html('<span class="alert">'+msg+'</span>');
                $('#msg_'+ev_id).show();
            }
            $('#src_but_'+ev_id).attr('disabled','');
        },
        error: function (data, status){
            alert('Ошибка отправки данных формы');
        }
    });
}


/**
 * Форматирование чисел
 */

function number_format(_number, _cfg){
  function obj_merge(obj_first, obj_second){
    var obj_return = {};
    for (key in obj_first){
      if (typeof obj_second[key] !== 'undefined') obj_return[key] = obj_second[key];
      else obj_return[key] = obj_first[key];
      }
    return obj_return;
  }
  function thousands_sep(_num, _sep){
    if (_num.length <= 3) return _num;
    var _count = _num.length;
    var _num_parser = '';
    var _count_digits = 0;
    for (var _p = (_count - 1); _p >= 0; _p--){
      var _num_digit = _num.substr(_p, 1);
      if (_count_digits % 3 == 0 && _count_digits != 0 && !isNaN(parseFloat(_num_digit))) _num_parser = _sep + _num_parser;
      _num_parser = _num_digit + _num_parser;
      _count_digits++;
      }
    return _num_parser;
  }
  if (typeof _number !== 'number'){
    _number = parseFloat(_number);
    if (isNaN(_number)) return false;
  }
  var _cfg_default = {before: '', after: '', decimals: 2, dec_point: '.', thousands_sep: ','};
  if (_cfg && typeof _cfg === 'object'){
    _cfg = obj_merge(_cfg_default, _cfg);
  }
  else _cfg = _cfg_default;
  _number = _number.toFixed(_cfg.decimals);
  if(_number.indexOf('.') != -1){
    var _number_arr = _number.split('.');
    var _number = thousands_sep(_number_arr[0], _cfg.thousands_sep) + _cfg.dec_point + _number_arr[1];
  }
  else var _number = thousands_sep(_number, _cfg.thousands_sep);
  return _cfg.before + _number + _cfg.after;
}