function get_session_id() {
  var sid = window.location.search.match(/SessionID=([0-9a-zA-Z]+)/);
  sid != null ? sid = RegExp.$1 : 0;
  return sid;
}

function quick_results_show_button(val, s_type) {
  s_type == undefined ? s_type = 'quick' : 0;
  var obj = $('#div_hide_' + s_type + '_results');
  val == 1 ? obj.show() : obj.hide();
}

function quick_results_toggle_button(obj, val, s_type) {
  s_type == undefined ? s_type = 'quick' : 0;
  if ($('#div_' + s_type + '_results_loading').length)
    return;
  var arr = val == 1 ? { 0:'button', 1:'button_off' } : { 0:'button_off', 1:'button' };
  $(obj).addClass(arr[0]);
  $(obj).removeClass(arr[1]);
}

function quick_results_toggle(b_hide, s_type) {
  if (typeof b_hide != 'number') {
    s_type = b_hide;
    b_hide = 0;
  }
  b_hide != 1 ? b_hide = 0 : 0;
  s_type == undefined ? s_type = 'quick' : 0;
  d = new Date();
  var arr = b_hide == 1 ? { 0:'#efefef', 1:0.75 } : { 0:'#fff', 1:1 };
  var obj = s_type != 'quick' ? $('#div_' + s_type + '_results') : $('#div_' + s_type + '_all_results');
  obj.css('backgroundColor', arr[0]);
  obj.fadeTo(1, arr[1]);
  var sid = get_session_id();
  var arr_post = { key: 'hide_' + s_type + '_results', val: b_hide, t: d.getTime() };
  sid != null ? arr_post['SessionID'] = sid : 0;
  $.post(
    "/include/settings.ajax.php",
    arr_post,
    function(data) {
      if (data != '') {
        var arr_data = data.split(':');
        var s_type = arr_data[0].replace(/hide_([a-z]+)_results/, '$1');
        var s_all = s_type == 'quick' ? '_all' : '';
        var arr = arr_data[1] == '1' || arr_data[2] == '0' ? { 0:s_type + s_all, 1:'undo_' + s_type } : { 0:'undo_' + s_type, 1:s_type + s_all };
        $('#div_' + arr[0] + '_results').hide();
        $('#div_' + arr[1] + '_results').show();
      }
    }
  );
}


