//-------------------------------------------------------------------------------------------
// MediaPortal.kiev.ua Custom JavaScript File (c) 2008 Butcher http://www.mediaportal.kiev.ua
//-------------------------------------------------------------------------------------------

  // Функция DRAW_SITE_OLD (с) Butcher, MediaPortal.kiev.ua
  // Отображает "время жизни" сайта
  function draw_site_old( )
  {
    d0 = new Date( "February 26, 2008" );
    d1 = new Date();
    dt = ( d1.getTime( ) - d0.getTime( ) ) / ( 1000 * 60 * 60 * 24 ) + 365;
    document.write( "Сайт в сети <b>" + Math.round( dt ) + "</b>-й день" );
  }
 
  // Функция TOGGLEBLOCK (с) Butcher, MediaPortal.kiev.ua
  // Переключает видимость блока
  function toggleblock( mp_block_id, add_block_to_hidding )
  {
    togglecategory( mp_block_id, add_block_to_hidding );
    return true;
  }

  // Функция TOGGLECATEGORY (с) Butcher, MediaPortal.kiev.ua
  // Переключает видимость элемента страницы, сохраняя информацию в cookie
  function togglecategory( fid, add )
  {
    saved = new Array();
    clean = new Array();
    if( tmp = get_mp_cookie( "hidding_blocks" ) )
    {
      saved = tmp.split( ',' );
    }
    for( i = 0 ; i < saved.length; i++ )
    {
      if( saved[i] != fid && saved[i] != '' )
      {
        clean[clean.length] = saved[i];
      }
    }
    if( add == 2 )
    {
      hide_mp_div( mp_get_by_id( "fc_" + fid ) );
      hide_mp_div( mp_get_by_id( "fo_" + fid ) );
    }
    else if( add )
    {
      clean[ clean.length ] = fid;
      show_mp_div( mp_get_by_id( "fc_" + fid ) );
      hide_mp_div( mp_get_by_id( "fo_" + fid ) );
    }
    else
    {
      show_mp_div( mp_get_by_id( "fo_" + fid ) );
      hide_mp_div( mp_get_by_id( "fc_" + fid ) );
    }
    set_mp_cookie( "hidding_blocks", clean.join( ',' ), 1 );

    return true;
  }

  // Функция CLEAR_MP_COOKIE (с) Butcher, MediaPortal.kiev.ua
  // Очищает указанный cookie пользователя
  function clear_mp_cookie( cookie_id )
  {
    set_mp_cookie( cookie_id, '', 1 );

    return true;
  }

  // Функция ADD_TO_MP_COOKIE (с) Butcher, MediaPortal.kiev.ua
  // Добавляет идентификатор в cookie пользователя
  function add_to_mp_cookie( cookie_id, id )
  {
    if( id == null )
    {
      return false;
    }
    var cookie = get_mp_cookie( cookie_id );
    if( cookie && cookie.search( id ) != -1 )
    {
      return true;
    }
    if( !cookie )
    {
      set_mp_cookie( cookie_id, id, 1 );
    }
    else
    {
      set_mp_cookie( cookie_id, cookie + ',' + id, 1 );
    }
    return true;
  }

  // Функция DELETE_FROM_MP_COOKIE (с) Butcher, MediaPortal.kiev.ua
  // Удаляет идентификатор из cookie пользователя
  function delete_from_mp_cookie( cookie_id, id )
  {
    saved = new Array();
    clean = new Array();

    if( tmp = get_mp_cookie( cookie_id ) )
    {
      saved = tmp.split( ',' );
    }

    for( i = 0 ; i < saved.length; i++ )
    {
      if( saved[i] != id && saved[i] != '' )
      {
        clean[clean.length] = saved[i];
      }
    }
    set_mp_cookie( cookie_id, clean.join( ',' ), 1 );

    return true;
  }

  // Функция ADD_TO_ARRAY (с) Butcher, MediaPortal.kiev.ua
  // Добавляет элемент в массив, если он отсутствует в этом массиве и возвращает этот массив
  function add_to_array( input_array, value )
  {
    if( !mp_in_array( value, input_array ) )
    {
      input_array.push( value );
    }

    return input_array;
  }

  // Функция REMOVE_FROM_ARRAY (с) Butcher, MediaPortal.kiev.ua
  // Удаляет элемент массива, если его значение совпадает с заданным, возвращая массив без этого элемента
  function remove_from_array( input_array, value )
  {
    var i = 0;
    var output_array = new Array();
    if( input_array instanceof Array )
    {
      for( i = 0; i < input_array.length; i++ )
      {
        if( input_array[i] == value )
        {
          delete input_array[i];
        }
      }
      for( i = 0; i < input_array.length; i++ )
      {
        if( input_array[i] )
        {
          output_array = add_to_array( output_array, input_array[i] );
        }
      }
    }

    return output_array;
  }

  // Функция GET_MP_COOKIE (с) Butcher, MediaPortal.kiev.ua
  // Возвращает содержимое cookie пользователя
  function get_mp_cookie( name )
  {
    cname = name + '=';
    cpos = document.cookie.indexOf( cname );
    if( cpos != -1 )
    {
      cstart = cpos + cname.length;
      cend = document.cookie.indexOf( ';', cstart );
      if( cend == -1 )
      {
        cend = document.cookie.length;
      }
      return unescape( document.cookie.substring( cstart, cend ) );
    }
    return null;
  }

  // Функция SET_MP_COOKIE (с) Butcher, MediaPortal.kiev.ua
  // Создает cookie с заданным содержимым
  function set_mp_cookie( name, value, sticky )
  {
    expire = '';
    if( sticky )
    {
      expire = "; expires=Wed, 1 Jan 2020 00:00:00 GMT";
    }
    document.cookie = name + '=' + value + "; path=" + '/' + expire + ';';

    return true;
  }

  // Функция SHOW_MP_DIV (с) Butcher, MediaPortal.kiev.ua
  // Делает div сраницы видимым
  function show_mp_div( element )
  {
    if( !element )
    {
      var element = mp_get_by_id( element );
      if( !element )
      {
        return false;
      }
    }
    element.style.display = '';
    return true;
  }

  // Функция SHOW_MP_ELEMENT (с) Butcher, MediaPortal.kiev.ua
  // Делает элемент сраницы скрытым
  function show_mp_element( id )
  {
    var element = mp_get_by_id( id );
    if( !element )
    {
      return false;
    }
    show_mp_div( element );
    return true;
  }

  // Функция HIDE_MP_DIV (с) Butcher, MediaPortal.kiev.ua
  // Делает div сраницы скрытым
  function hide_mp_div( element )
  {
    if( !element )
    {
      var element = mp_get_by_id( element );
      if( !element )
      {
        return false;
      }
    }
    element.style.display = "none";
    return true;
  }

  // Функция HIDE_MP_ELEMENT (с) Butcher, MediaPortal.kiev.ua
  // Делает элемент сраницы скрытым
  function hide_mp_element( id )
  {
    var element = mp_get_by_id( id );
    if( !element )
    {
      return false;
    }
    hide_mp_div( element );
    return true;
  }

  // Функция MP_GET_BY_ID (с) Butcher, MediaPortal.kiev.ua
  // Возвращает элемент страницы с заданным идентификатором
  function mp_get_by_id( id )
  {
    var element = null;
    if( document.getElementById )
    {
      element = document.getElementById( id );
    }
    else if( document.all )
    {
      element = document.all[id];
    }
    else if( document.layers )
    {
      element = document.layers[id];
    }

    return element;
  }

  // Функция HIDE_HIDDED_BLOCKS_DIVS (с) Butcher, MediaPortal.kiev.ua
  // Скрывает скрытые блоки страницы
  function hide_hidded_blocks_divs( )
  {
    hidded_blocks = new Array();
    if( tmp = get_mp_cookie( "hidding_blocks" ) )
    {
      hidded_blocks = tmp.split( ',' );
    }
    for( i = 0 ; i < hidded_blocks.length; i++ )
    {
      current_block_opened = mp_get_by_id( "fo_" + hidded_blocks[i] );
      current_block_closed = mp_get_by_id( "fc_" + hidded_blocks[i] );
      if( current_block_opened && current_block_closed )
      {
        if( current_block_opened.style.display != "none" )
        {
          show_mp_div( current_block_closed );
          hide_mp_div( current_block_opened );
        }
        else
        {
          show_mp_div( current_block_opened );
          hide_mp_div( current_block_closed );
        }
      }
    }

    return true;
  }

  // Функция MM_PRELOADIMAGES (с) Butcher, MediaPortal.kiev.ua
  // Подгружает заданные изображения в кэш браузера
  function MM_preloadImages( )
  {
    if( document.images )
    {
      if( !document.MM_p )
      {
        document.MM_p = new Array();
      }
      var i, j = document.MM_p.length, a = MM_preloadImages.arguments;
      for( i = 0; i < a.length; i++ )
      {
        if( a[i].indexOf( '#' ) != 0 )
        {
          document.MM_p[j] = new Image;
          document.MM_p[j++].src = a[i];
        }
      }
    }

    return true;
  }

  // Функция DRAWCLOCK (с) Butcher, MediaPortal.kiev.ua
  // Отображает идущие часы на странице
  function drawclock( )
  {
    var d = new Date();
    var s = d.getSeconds( );
    var m = d.getMinutes( );
    var h = d.getHours( );
    if( s < 10 )
    {
      s = '0' + s;
    }
    if( m < 10 )
    {
      m = '0' + m;
    }
    if( h < 10 )
    {
      h = '0' + h;
    }
    document.getElementById( "clock" ).innerHTML = h + ':' + m + ':' + s;
    setTimeout( "drawclock()", 1000 );

    return true;
  }

  // Функция DRAW_CURRENT_DATE (с) Butcher, MediaPortal.kiev.ua
  // Отображает текущую дату на странице
  function draw_current_date( )
  {
    var d = new Date( );
    var day = d.getDay( );
    var date = d.getDate( );
    var month = d.getMonth( );
    var year = d.getFullYear( );
    switch( day )
    {
      case( 1 ): day = "Понедельник"; break;
      case( 2 ): day = "Вторник"; break;
      case( 3 ): day = "Среда"; break;
      case( 4 ): day = "Четверг"; break;
      case( 5 ): day = "Пятница"; break;
      case( 6 ): day = "Суббота"; break;
      case( 0 ): day = "Воскресение"; break;
      default: break;
    }
    switch( month )
    {
      case( 0 ): month = "января"; break;
      case( 1 ): month = "февраля"; break;
      case( 2 ): month = "марта"; break;
      case( 3 ): month = "апреля"; break;
      case( 4 ): month = "мая"; break;
      case( 5 ): month = "июня"; break;
      case( 6 ): month = "июля"; break;
      case( 7 ): month = "августа"; break;
      case( 8 ): month = "сентября"; break;
      case( 9 ): month = "октября"; break;
      case( 10 ): month = "ноября"; break;
      case( 11 ): month = "декабря"; break;
      default: break;
    } 
    document.write( day + ", " + date + ' ' + month + ' ' + year );

    return true;
  }

  // Функция SEARCHFIELD_CLICK (с) Butcher, MediaPortal.kiev.ua
  // Обработчик нажатия в форме быстрого поиска
  function searchfield_click( element )
  {
    if( searchfield_clicked == false )
    {
      element.value = '';
      element.style.color = "#000000";
      element.style.textAlign = "left";
      searchfield_clicked = true;
    }
    element.focus();

    return true;
  }

  // Функция SUBMIT_SEARCH (с) Butcher, MediaPortal.kiev.ua
  // Обработчик/парсер подтверждения в форме быстрого поиска
  function submit_search( )
  {
    var search_field = mp_get_by_id( "search_field" );
    if( search_field.value == "Введите фразу для поиска..." || search_field.value.length == 0 )
    {
      alert( "Вы не ввели ни одного символа в поисковой запрос" );
    }
    else if( search_field.value.length < 3 )
    {         
      alert( "Вы ввели в строку поиска меньше трех символов" );
    }
    else
    {
      document.search_form.submit();
    }

    return false;
  }

  // Функция TOGGLE_DISABLED_BLOCKS (с) Butcher, MediaPortal.kiev.ua
  // Переключатель видимости отключенных блоков страницы
  function toggle_disabled_blocks( id, add )
  {
    saved = new Array();
    clean = new Array();
    if( tmp = get_mp_cookie( "disabled_blocks" ) )
    {
      saved = tmp.split( ',' );
    }
    for( i = 0 ; i < saved.length; i++ )
    {
      if( saved[i] != id && saved[i] != "" )
      {
        clean[clean.length] = saved[i];
      }
    }
    if( add )
    {
      clean[ clean.length ] = id;
    }
    set_mp_cookie( "disabled_blocks", clean.join( ',' ), 1 );

    return true;
  }

  // Функция CHECK_BLOCK_DISABLED (с) Butcher, MediaPortal.kiev.ua
  // Проверка, является ли заданный блок отключенным на странице
  function check_block_disabled( id )
  {
    var disabled_blocks = new Array();

    if( tmp = get_mp_cookie( "disabled_blocks" ) )
    {
      disabled_blocks = tmp.split( ',' );
    }
    if( mp_in_array( id, disabled_blocks ) )
    {
      return true;
    }

    return false;
  }

  // Функция MP_IN_ARRAY (с) Butcher, MediaPortal.kiev.ua
  // Проверка, является ли заданный элемент элементом заданного массива
  function mp_in_array( needle, haystack )
  {
    var key;
    for( key in haystack )
    {
      if( haystack[key] == needle )
      {
        return true;
      }
    }
 
    return false;
  }

  // Функция TOGGLEVIEW (с) Butcher, MediaPortal.kiev.ua
  // Переключение видимости заданного элемента страницы
  function toggleview( id )
  {
    var element = mp_get_by_id( id );
    if( element == null )
    {
      return false;
    }
    if( element.style.display == "none" )
    {
      element.style.display = '';
    }
    else
    {
      element.style.display = "none";
    }

    return true;
  }

  // Функция ISSET (с) Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  // Проверка существования переменной
  function isset( )
  {
    var a = arguments;
    var l = a.length;
    var i = 0;
    if( l == 0 )
    { 
      throw new Error( "Empty isset" ); 
    }
    while( i != l )
    {
      if( typeof( a[i] ) == "undefined" || a[i] === null )
      { 
        return false; 
      }
      else
      { 
        i++; 
      }
    }

    return true;
  }

  // Функция SET_BLOCK_PRIORITY (с) Butcher, MediaPortal.kiev.ua
  // Изменение приоритета сортировки для определенного блока
  function set_block_priority( id, priority )
  {
    var saved = new Array();
    var clean = new Array();
    var separator = '|';
    var new_value = '';
    var cookie = get_mp_cookie( "blocks_priority" );
    if( parseInt( id ) < 1 )
    {
      id = 1;
    }
    new_value = id + separator + priority;
    if( cookie )
    {
      saved = cookie.split( ',' );
      for( i = 0 ; i < saved.length; i++ )
      {
        if( saved[i].search( id ) == -1 && saved[i] != "" )
        {
          add_to_array( clean, saved[i] );
        }
      }
      add_to_array( clean, new_value );
      set_mp_cookie( "blocks_priority", clean.join( ',' ), 1 );
    }
    else
    {
      set_mp_cookie( "blocks_priority", new_value, 1 );
    }

    return true;
  }

  function set_rel_category( element, id )
  {
    var cookie_id = "disabled_rel_categories";
    if( element.checked == true )
    {
      delete_from_mp_cookie( cookie_id, id );
    }
    else
    {
      add_to_mp_cookie( cookie_id, id );
    }
    return true;  
  }

  // Функция MAKE_BOOKMARK (с) Butcher, MediaPortal.kiev.ua
  // Добавление сайта в закладки / избранное
  function make_bookmark( )
  {
    if( document.all )
    {
      window.external.AddFavorite( "http://www.mediaportal.kiev.ua", "Мой любимый сайт - MediaPortal" );
    }
  }

  // Функция SETSTARTPAGE (с) Butcher, MediaPortal.kiev.ua
  // Добавление сайта в закладки / избранное
  function setStartPage( obj )
  {
    if( document.all )
    {
      obj.style.behavior = "url(#default#homepage)";
      obj.setHomePage( "http://www.mediaportal.kiev.ua" );
    }
    else if( window.sidebar )
    {
      window.location.href = "index.php?do=static&page=set_homepage_firefox";
    }
    else if( window.opera )
    {
      window.location.href = "index.php?do=static&page=set_homepage_opera";
    }
  }

  function mp_switch_top_releasers( what_to_switch, set_cookie )
  {
    var name = "top_releasers_";
    var active_bgcolor = active_tab_bgcolor;
    var active_color = active_tab_color;
    var bgcolor = tab_bgcolor;
    var color = tab_color;
    var active_cursor = "default";
    var cursor = "pointer";
    var link_all = mp_get_by_id( name + 'link_all' );
    var link_month = mp_get_by_id( name + 'link_month' );
    var link_today = mp_get_by_id( name + 'link_today' );
    var div_all = mp_get_by_id( name + 'div_all' );
    var div_month = mp_get_by_id( name + 'div_month' );
    var div_today = mp_get_by_id( name + 'div_today' );

    if( what_to_switch == "today" )
    {
      if( link_all )
      {
        link_all.style.backgroundColor = bgcolor;
        link_all.style.color = color;
        link_all.style.cursor = cursor;
      }
      if( link_month )
      {
        link_month.style.backgroundColor = bgcolor;
        link_month.style.color = color;
        link_month.style.cursor = cursor;
      }
      if( link_today )
      {
        link_today.style.backgroundColor = active_bgcolor;
        link_today.style.color = active_color;
        link_today.style.cursor = active_cursor;
      }
      hide_mp_div( div_all );
      hide_mp_div( div_month );
      show_mp_div( div_today );
    }
    else if( what_to_switch == "month" )
    {
      if( link_all )
      {
        link_all.style.backgroundColor = bgcolor;
        link_all.style.color = color;
        link_all.style.cursor = cursor;
      }
      if( link_month )
      {
        link_month.style.backgroundColor = active_bgcolor;
        link_month.style.color = active_color;
        link_month.style.cursor = active_cursor;
      }
      if( link_today )
      {
        link_today.style.backgroundColor = bgcolor;
        link_today.style.color = color;
        link_today.style.cursor = cursor;
      }
      hide_mp_div( div_all );
      show_mp_div( div_month );
      hide_mp_div( div_today );
    }
    else if( what_to_switch == "all" )
    {
      if( link_all )
      {
        link_all.style.backgroundColor = active_bgcolor;
        link_all.style.color = active_color;
        link_all.style.cursor = active_cursor;
      }
      if( link_month )
      {
        link_month.style.backgroundColor = bgcolor;
        link_month.style.color = color;
        link_month.style.cursor = cursor;
      }
      if( link_today )
      {
        link_today.style.backgroundColor = bgcolor;
        link_today.style.color = color;
        link_today.style.cursor = cursor;
      }
      show_mp_div( div_all );
      hide_mp_div( div_month );
      hide_mp_div( div_today );
    }
    else
    {
      return false;
    }
    if( set_cookie )
    {
      set_mp_cookie( "top_releasers", what_to_switch, 1 );
    }

    return true;  
  }

  function mp_switch_release( what_to_switch, set_cookie )
  {
    var name = "release_";
    var active_bgcolor = active_tab_bgcolor;
    var active_color = active_tab_color;
    var bgcolor = tab_bgcolor;
    var color = tab_color;
    var active_cursor = "default";
    var cursor = "pointer";
    var link_website = mp_get_by_id( name + 'link_website' );
    var link_forum = mp_get_by_id( name + 'link_forum' );
    var link_input = mp_get_by_id( name + 'link_input' );
    var div_website = mp_get_by_id( name + 'div_website' );
    var div_forum = mp_get_by_id( name + 'div_forum' );
    var div_input = mp_get_by_id( name + 'div_input' );

    if( what_to_switch == "input" )
    {
      if( link_website )
      {
        link_website.style.backgroundColor = bgcolor;
        link_website.style.color = color;
        link_website.style.cursor = cursor;
      }
      if( link_forum )
      {
        link_forum.style.backgroundColor = bgcolor;
        link_forum.style.color = color;
        link_forum.style.cursor = cursor;
      }
      if( link_input )
      {
        link_input.style.backgroundColor = active_bgcolor;
        link_input.style.color = active_color;
        link_input.style.cursor = active_cursor;
      }
      hide_mp_div( div_website );
      hide_mp_div( div_forum );
      show_mp_div( div_input );
    }
    else if( what_to_switch == "forum" )
    {
      if( link_website )
      {
        link_website.style.backgroundColor = bgcolor;
        link_website.style.color = color;
        link_website.style.cursor = cursor;
      }
      if( link_forum )
      {
        link_forum.style.backgroundColor = active_bgcolor;
        link_forum.style.color = active_color;
        link_forum.style.cursor = active_cursor;
      }
      if( link_input )
      {
        link_input.style.backgroundColor = bgcolor;
        link_input.style.color = color;
        link_input.style.cursor = cursor;
      }
      hide_mp_div( div_website );
      show_mp_div( div_forum );
      hide_mp_div( div_input );
    }
    else if( what_to_switch == "website" )
    {
      if( link_website )
      {
        link_website.style.backgroundColor = active_bgcolor;
        link_website.style.color = active_color;
        link_website.style.cursor = active_cursor;
      }
      if( link_forum )
      {
        link_forum.style.backgroundColor = bgcolor;
        link_forum.style.color = color;
        link_forum.style.cursor = cursor;
      }
      if( link_input )
      {
        link_input.style.backgroundColor = bgcolor;
        link_input.style.color = color;
        link_input.style.cursor = cursor;
      }
      show_mp_div( div_website );
      hide_mp_div( div_forum );
      hide_mp_div( div_input );
    }
    else
    {
      return false;
    }

    return true;  
  }

  function mp_switch_upload_source( what_to_switch, set_cookie )
  {
    var name = "upload_image_source_";
    var link_pc = mp_get_by_id( name + 'link_pc' );
    var link_url = mp_get_by_id( name + 'link_url' );
    var div_pc = mp_get_by_id( name + 'div_pc' );
    var div_url = mp_get_by_id( name + 'div_url' );

    if( what_to_switch == "pc" )
    {
      if( link_pc )
      {
        link_pc.style.backgroundColor = active_tab_bgcolor;
        link_pc.style.color = active_tab_color;
        link_pc.style.cursor = active_tab_cursor;
      }
      if( link_url )
      {
        link_url.style.backgroundColor = tab_bgcolor;
        link_url.style.color = tab_color;
        link_url.style.cursor = tab_cursor;
      }
      hide_mp_div( div_url );
      show_mp_div( div_pc );
    }
    else if( what_to_switch == "url" )
    {
      if( link_pc )
      {
        link_pc.style.backgroundColor = tab_bgcolor;
        link_pc.style.color = tab_color;
        link_pc.style.cursor = tab_cursor;
      }
      if( link_url )
      {
        link_url.style.backgroundColor = active_tab_bgcolor;
        link_url.style.color = active_tab_color;
        link_url.style.cursor = active_tab_cursor;
      }
      hide_mp_div( div_pc );
      show_mp_div( div_url );
    }
    else
    {
      return false;
    }
    if( set_cookie )
    {
      set_mp_cookie( "upload_image_source", what_to_switch, 1 );
    }

    return true;  
  }

  // Функция STR_REPLACE (с) Butcher, MediaPortal.kiev.ua
  // Замена подстроки в строке:
  function str_replace( search, replace, subject )
  {
    return subject.split(search).join(replace);
  }

  // Функция GET_ELEMENT_VALUE (с) Butcher, MediaPortal.kiev.ua
  // Получение значения элемента:
  function get_element_value( id )
  {
    var element = mp_get_by_id( id );
    if( element )
    {
      return element.value;
    }
    return false;
  }

  // Функция IS_ARRAY (с) Butcher, MediaPortal.kiev.ua
  // Проверка, является ли заданный элемент массивом:
  function is_array( mixed_var )
  {
    var key = '';
    if( !mixed_var )
    {
      return false;
    }
    if( typeof mixed_var === "object" )
    {
      if( mixed_var.hasOwnProperty )
      {
        for( key in mixed_var )
        {
          if( false === mixed_var.hasOwnProperty( key ) )
          {
            return false;
          }
        }
      }
      return true;
    }
    return false;
  }

/*
  // Функция SETLINKTYPEVALUE (с) Butcher, MediaPortal.kiev.ua
  // Переключение radio-элементов для опции "тип ссылки":
  function setLinkTypeValue( NewValue )
  {
    var FormId = "";
    if( document.forms["entryform"] )
    {
      FormId = "entryform";
    }
    else if( document.forms["addnews"] )
    {
      FormId = "addnews";
    }
    else
    {
      return;
    }
    var LinkTypeElements = document.forms[FormId].elements["link_type"];
    if( !LinkTypeElements )
    {
	  return;
    }
	var LinkTypeLength = LinkTypeElements.length;
	if( LinkTypeLength == undefined )
    {
	  LinkTypeElements.checked = ( LinkTypeElements.value == NewValue.toString() );
	  return;
	}
	for( var i = 0; i < LinkTypeLength; i++ )
    {
	  LinkTypeElements[i].checked = false;
	  if( LinkTypeElements[i].value == NewValue.toString() )
      {
	    LinkTypeElements[i].checked = true;
	  }
	}
  }

  // Функция SETLINKTYPEVALUEAJAX (с) Butcher, MediaPortal.kiev.ua
  // Переключение radio-элементов для опции "тип ссылки" для ajax-редактирования:
  function setLinkTypeValueAjax( id, NewValue )
  {
    var LinkTypeElements = document.forms["edit-form-" + id].elements["link_type_" + id];
    if( !LinkTypeElements )
    {
	  return;
    }
	var LinkTypeLength = LinkTypeElements.length;
	if( LinkTypeLength == undefined )
    {
	  LinkTypeElements.checked = ( LinkTypeElements.value == NewValue.toString() );
	  return;
	}
	for( var i = 0; i < LinkTypeLength; i++ )
    {
	  LinkTypeElements[i].checked = false;
	  if( LinkTypeElements[i].value == NewValue.toString() )
      {
	    LinkTypeElements[i].checked = true;
	  }
	}
  }
*/

  // Функция GET_MULTIPLE_SELECT_VALUES (с) Butcher, MediaPortal.kiev.ua
  // Получение всех значений из элемента типа "select":
  function get_multiple_select_values( id )
  {
    var out = new Array();
    var element = mp_get_by_id( id );
    if( element && element.options )
    {
      for( var i = 0; i < element.options.length; i++ )
      {
        if( element.options[i].selected )
        {
          out.push( element.options[i].value );
        }
      }
    }
    return out;
  }

  // Функция GET_MULTIPLE_SELECT_VALUES (с) Butcher, MediaPortal.kiev.ua
  // Получение всех значений из элемента типа "select":
  function edit_categories( select_id, destination_id )
  {
    var values = get_multiple_select_values( select_id );
    var element = mp_get_by_id( destination_id );
    if( element )
    {
      element.value = values.join( ',' );
    }
  }

  // Функция GET_RADIOGROUP_VALUE (с) Butcher, MediaPortal.kiev.ua
  // Получение всех значений из элемента типа "select":
  function get_radiogroup_value( name, formname )
  {
    var radiobuttons = document["forms"][formname][name];
    var out = "";
    if( radiobuttons )
    {
      for( var i = 0; i < radiobuttons.length; i++ )
      {
        if( radiobuttons[i].checked == true )
        {
          out = radiobuttons[i].value;
          break;
        }
      }
    }
    return out;
  }

  // Функция AJAXCHANGEFORUMLINK (с) Butcher, MediaPortal.kiev.ua
  // Изменение ссылки на тему форума после ajax-редактирования релизов/новостей:
  function ajaxChangeForumLink( id, link, type )
  {
    var out = "";
    if( link && type && link.length && type.length )
    {
      out += "<a href=\"http://forum.mediaportal.kiev.ua/index.php?showtopic=" + link + "\" target=\"_new\"><img src=\"/templates/media_modern/images/";
      if( type == "more" )
      {
        out += "read_more_on_mediaportal_kiev_ua.gif";
      }
      else if( type == "download" )
      {
        out += "download_from_mediaportal_kiev_ua.gif";
      }
      out += "\" border=\"0\"></a>";      
    }
    return out;
  }

  // Функция HIGHLIGHT_NASHNET_BG (с) Butcher, MediaPortal.kiev.ua
  // Смена фона при наведении на ссылку нашнета:
  function highlight_nashnet_bg( action )
  {
    var element = mp_get_by_id( "nashnet_bg" );
    if( element )
    {
      if( action == 1 )
      {
        element.className = "right_active";
      }
      else if( action == 0 )
      {
        element.className = "right";
      }
    }
  }

  // Функция PRELOAD_IMAGES (с) Butcher, MediaPortal.kiev.ua
  // Предзагрузка изображения на страницу:
  function preload_images( images )
  {
    var image = null;
    if( document.images )
    {
      if( is_array( images ) == false )
      {
        images = new Array( images );
      }
      for( image in images )
      {
        preloaded_image = new Image( 1, 1 );
        preloaded_image.src = image;
      }
    }
  }

  // Функция DOVOTE (с) Butcher, MediaPortal.kiev.ua
  // Ajax - голосование:
  function doVote( event, vote_id )
  {
    var vote_check = "";

    if( event == "vote" )
    {
      var frm = document.vote;
      for( var i = 0; i < frm.elements.length; i++ )
      {
        var elmnt = frm.elements[i];
        if( elmnt.type=="radio" && elmnt.checked == true )
        {
          vote_check = elmnt.value;
          break;
        }
      }
    }

    var ajax = new dle_ajax();
    ajax.onShow( "" );
    var varsString = "";
    ajax.setVar( "vote_id", vote_id );
    ajax.setVar( "vote_action", event );
    ajax.setVar( "vote_check", vote_check );
    ajax.setVar( "vote_skin", "media_modern" );
    ajax.requestFile = dle_root + "engine/ajax/vote.php";
    ajax.method  = "GET";
    ajax.element = "vote_body";
    ajax.sendAJAX( varsString );
  }

  // Функция VOTENAV (с) Butcher, MediaPortal.kiev.ua
  // Ajax - смена голосования:
  function voteNav( vote_id, skin, category_id )
  {
    var ajax = new dle_ajax();
    ajax.onShow( "" );
    var varsString = "";
    ajax.setVar( "vote_id", vote_id );
    ajax.setVar( "vote_action", "change" );
    ajax.setVar( "vote_skin", skin );
    ajax.setVar( "category_id", category_id );
    ajax.requestFile = dle_root + "engine/ajax/vote.php";
    ajax.method  = "GET";
    ajax.element = "vote-layer";
    ajax.sendAJAX( varsString );
  }

  // Функция ADDSLASHES (с) Kevin van Zonneveld, http://kevin.vanzonneveld.net
  // Экранирует кавычки в строке:
  function addslashes( str )
  {
    return ( str + '' ).replace(/([\\"'])/g, "\\$1").replace(/\u0000/g, "\\0");
  }

  // Функция MP_SWITCH_VOTELINKS (с) Butcher, MediaPortal.kiev.ua
  // Переключение между вкладками при просмотре голосований:
  function mp_switch_votelinks( what_to_switch )
  {
    var name           = "votes_link_";
    var divname        = "votes_div_";
    var active_bgcolor = active_tab_bgcolor;
    var active_color   = active_tab_color;
    var bgcolor        = tab_bgcolor;
    var color          = tab_color;
    var active_cursor  = "default";
    var cursor         = "pointer";
    var link_current   = mp_get_by_id( name    + "current"       );
    var link_disabled  = mp_get_by_id( name    + "disabled"      );
    var div_current    = mp_get_by_id( divname + "current"       );
    var div_disabled   = mp_get_by_id( divname + "disabled"      );
    var help_current   = mp_get_by_id( "voteinfo_current_help"   );
    var help_disabled  = mp_get_by_id( "voteinfo_disabled_help"  );

    show_vote_row( "voteinfo_" + previous_showed_div );
    if( what_to_switch == "current" )
    {
      if( link_current )
      {
        link_current.style.backgroundColor = active_bgcolor;
        link_current.style.color = active_color;
        link_current.style.cursor = active_cursor;
      }
      if( link_disabled )
      {
        link_disabled.style.backgroundColor = bgcolor;
        link_disabled.style.color = color;
        link_disabled.style.cursor = cursor;
      }
      if( help_current )
      {
        help_current.style.display = "block";
      }
      if( help_disabled )
      {
        help_disabled.style.display = "none";
      }
      hide_mp_div( div_disabled );
      show_mp_div( div_current  );
    }
    else if( what_to_switch == "disabled" )
    {
      if( link_current )
      {
        link_current.style.backgroundColor = bgcolor;
        link_current.style.color = color;
        link_current.style.cursor = cursor;
      }
      if( link_disabled )
      {
        link_disabled.style.backgroundColor = active_bgcolor;
        link_disabled.style.color = active_color;
        link_disabled.style.cursor = active_cursor;
      }
      if( help_current )
      {
        help_current.style.display = "none";
      }
      if( help_disabled )
      {
        help_disabled.style.display = "block";
      }
      hide_mp_div( div_current  );
      show_mp_div( div_disabled );
    }
    else
    {
      return false;
    }
    previous_showed_div = what_to_switch + "_help";

    return true;  
  }

  var searchfield_clicked = false;
  var active_tab_bgcolor  = "#608ad8";
  var active_tab_color    = "#ffffff";
  var active_tab_cursor   = "default";
  var tab_bgcolor         = "#ffffff";
  var tab_color           = "#000000";
  var tab_cursor          = "pointer";
