//------------------------------------------
// Invision Power Board 2.1.7
// Global JS File
// (c) 2003 Invision Power Services, Inc.
//
// http://www.invisionboard.com
//------------------------------------------

//==========================================
// Set up
//==========================================

var input_red       = "input-warn";
var input_green     = "input-ok";
var input_ok_box    = "input-ok-content";
var input_warn_box  = "input-warn-content";

var img_blank       = "blank.gif";
var img_tick        = "aff_tick.gif";
var img_cross       = "aff_cross.gif";

// Sniffer based on http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html

var uagent          = navigator.userAgent.toLowerCase();
var is_safari       = ( ( uagent.indexOf( "safari" ) != -1 ) || ( navigator.vendor == "Apple Computer, Inc." ) );
var is_opera        = ( uagent.indexOf( "opera" ) != -1 );
var is_webtv        = ( uagent.indexOf( "webtv" ) != -1 );
var is_ie           = ( ( uagent.indexOf( "msie" ) != -1 ) && ( !is_opera ) && ( !is_safari ) && ( !is_webtv ) );
var is_ie4          = ( ( is_ie ) && ( uagent.indexOf( "msie 4." ) != -1 ) );
var is_moz          = ( ( navigator.product == "Gecko" )  && ( !is_opera ) && ( !is_webtv ) && ( !is_safari ) );
var is_ns           = ( ( uagent.indexOf( "compatible" ) == -1 ) && ( uagent.indexOf( "mozilla" ) != -1 ) && ( !is_opera ) && ( !is_webtv ) && ( !is_safari ) );
var is_ns4          = ( ( is_ns ) && ( parseInt( navigator.appVersion ) == 4 ) );
var is_kon          = ( uagent.indexOf( "konqueror" ) != -1 );

var is_win          = ( ( uagent.indexOf( "win" ) != -1 ) || ( uagent.indexOf( "16bit" ) != -1 ) );
var is_mac          = ( ( uagent.indexOf( "mac" ) != -1 ) || ( navigator.vendor == "Apple Computer, Inc." ) );
var ua_vers         = parseInt( navigator.appVersion );

var ipb_pages_shown = 0;
var ipb_pages_array = new Array();

/*-------------------------------------------------------------------------*/
// DST Auto correction
/*-------------------------------------------------------------------------*/

function global_dst_check( tzo, dst )
{
    var thisoffset = tzo + dst;
    var dstoffset  = new Date().getTimezoneOffset() / 60;
    var dstset     = 0;
    var url        = ipb_var_base_url + "act=xmlout&do=dst-autocorrection&md5check=" + ipb_md5_check;
    
    if( Math.abs( thisoffset + dstoffset ) == 1 )
    {
      try
      {
        //----------------------------------
        // Fancy first...
        //----------------------------------
        xml_dst_set( url + "&xml=1" );
        dstset = 1;
      }
      catch( e )
      {
        dstset = 0;
      }
        
      //----------------------------------
      // No fancy?
      //----------------------------------
      if( dstset == 0 )
      {
        window.location = url;
      }
    }
  }

/*-------------------------------------------------------------------------*/
// Get cookie
/*-------------------------------------------------------------------------*/

  function my_getcookie( name )
  {
    cname = ipb_var_cookieid + 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 cookie
/*-------------------------------------------------------------------------*/

function my_setcookie( name, value, sticky )
{
    expire = "";
    domain = "";
    path   = "/";
    
    if ( sticky )
    {
        expire = "; expires=Wed, 1 Jan 2020 00:00:00 GMT";
    }
    
    if ( ipb_var_cookie_domain != "" )
    {
        domain = '; domain=' + ipb_var_cookie_domain;
    }
    
    if ( ipb_var_cookie_path != "" )
    {
        path = ipb_var_cookie_path;
    }
    
    document.cookie = ipb_var_cookieid + name + "=" + value + "; path=" + path + expire + domain + ';';
}

/*-------------------------------------------------------------------------*/
// Lang replace
/*-------------------------------------------------------------------------*/

function lang_build_string()
{
    if ( ! arguments.length || ! arguments )
    {
        return;
    }
    
    var string = arguments[0];
    
    for( var i = 1 ; i < arguments.length ; i++ )
    {
        var match  = new RegExp('<%' + i + '>', 'gi');
        string = string.replace( match, arguments[i] );
    }
    
    return string;
}

/*-------------------------------------------------------------------------*/
// Pop up MyAssistant window
/*-------------------------------------------------------------------------*/

function buddy_pop()
{
    var not_loaded_yet = 0;
    
    if ( use_enhanced_js )
    {
        try
        {
            xml_myassistant_init();
            not_loaded_yet = 1;
        }
        catch( e )
        {
            //alert(e);
            not_loaded_yet = 0;
        }
    }
    
    if ( ! not_loaded_yet )
    {
        ipb_var_base_url = ipb_var_base_url.replace( '&amp;', '&' );
        window.open( ipb_var_base_url + 'act=buddy','BrowserBuddy','width=250,height=500,resizable=yes,scrollbars=yes');
    }
}

/*-------------------------------------------------------------------------*/
// Multi Page jumps
/*-------------------------------------------------------------------------*/

function do_multi_page_jump( pages_id )
{
    var pages       = 1;
    var cur_st      = ipb_var_st;
    var cur_page    = 1;
    var total_posts = ipb_pages_array[ pages_id ][2];
    var per_page    = ipb_pages_array[ pages_id ][1];
    var url_bit     = ipb_pages_array[ pages_id ][0];
    var userPage    = parseInt( document.getElementById( 'st-'+pages_id ).value );
    
    //-----------------------------------
    // Fix up URL BIT
    //-----------------------------------
    
    url_bit = url_bit.replace( new RegExp( "&amp;", "g" ) , '&' );
    
    //-----------------------------------
    // Work out pages
    //-----------------------------------
    
    if ( total_posts % per_page == 0 )
    {
        pages = total_posts / per_page;
    }
    else
    {
        pages = Math.ceil( total_posts / per_page );
    }
    
    if ( cur_st > 0 )
    {
        cur_page = cur_st / per_page; cur_page = cur_page -1;
    }

    if ( userPage > 0  )
    {
        if ( userPage < 1 )     {    userPage = 1;  }
        if ( userPage > pages ) { userPage = pages; }
        if ( userPage == 1 )    {     start = 0;    }
        else { start = (userPage - 1) * per_page; }
        
        window.location = url_bit + "&st=" + start;
        return false;
    }
}

/*-------------------------------------------------------------------------*/
// Hide / Unhide menu elements
/*-------------------------------------------------------------------------*/

function pages_st_focus( pages_id )
{
    document.getElementById( 'st-'+pages_id ).focus();
}

/*-------------------------------------------------------------------------*/
// Hide / Unhide menu elements
/*-------------------------------------------------------------------------*/

function ShowHide(id1, id2)
{
    if (id1 != '') toggleview(id1);
    if (id2 != '') toggleview(id2);
}
    
/*-------------------------------------------------------------------------*/
// Get element by id
/*-------------------------------------------------------------------------*/

function my_getbyid(id)
{
    itm = null;
    
    if (document.getElementById)
    {
        itm = document.getElementById(id);
    }
    else if (document.all)
    {
        itm = document.all[id];
    }
    else if (document.layers)
    {
        itm = document.layers[id];
    }
    
    return itm;
}

/*-------------------------------------------------------------------------*/
// Show/hide toggle
/*-------------------------------------------------------------------------*/

function toggleview(id)
{
    if ( ! id ) return;
    
    if ( itm = my_getbyid(id) )
    {
        if (itm.style.display == "none")
        {
            my_show_div(itm);
        }
        else
        {
            my_hide_div(itm);
        }
    }
}

/*-------------------------------------------------------------------------*/
// Set DIV ID to hide
/*-------------------------------------------------------------------------*/

function my_hide_div(itm)
{
    if ( ! itm ) return;
    
    itm.style.display = "none";
}

/*-------------------------------------------------------------------------*/
// Set DIV ID to show
/*-------------------------------------------------------------------------*/

function my_show_div(itm)
{
    if ( ! itm ) return;
    
    itm.style.display = "";
}

/*-------------------------------------------------------------------------*/
// Change cell colour
/*-------------------------------------------------------------------------*/

function change_cell_color( id, cl )
{
    itm = my_getbyid(id);
    
    if ( itm )
    {
        itm.className = cl;
    }
}

/*-------------------------------------------------------------------------*/
// Toggle category
/*-------------------------------------------------------------------------*/

function togglecategory( fid, add )
{
    saved = new Array();
    clean = new Array();

    //-----------------------------------
    // Get any saved info
    //-----------------------------------
    
    if ( tmp = my_getcookie('collapseprefs') )
    {
        saved = tmp.split(",");
    }
    
    //-----------------------------------
    // Remove bit if exists
    //-----------------------------------
    
    for( i = 0 ; i < saved.length; i++ )
    {
        if ( saved[i] != fid && saved[i] != "" )
        {
            clean[clean.length] = saved[i];
        }
    }
    
    //-----------------------------------
    // Add?
    //-----------------------------------
    
    if ( add )
    {
        clean[ clean.length ] = fid;
        my_show_div( my_getbyid( 'fc_'+fid  ) );
        my_hide_div( my_getbyid( 'fo_'+fid  ) );
    }
    else
    {
        my_show_div( my_getbyid( 'fo_'+fid  ) );
        my_hide_div( my_getbyid( 'fc_'+fid  ) );
    }
    
    my_setcookie( 'collapseprefs', clean.join(','), 1 );
}

/*-------------------------------------------------------------------------*/
// locationjump
/*-------------------------------------------------------------------------*/

function locationjump(url)
{
    window.location = ipb_var_base_url + url;
}

/*-------------------------------------------------------------------------*/
// CHOOSE SKIN
/*-------------------------------------------------------------------------*/

function chooseskin(obj)
{
    choosebox = obj.options[obj.selectedIndex].value;
    extravars = '';
    
    if ( choosebox != -1 && ! isNaN( choosebox ) )
    {
        if ( document.skinselectorbox.skinurlbits.value )
        {
            extravars = '&' + document.skinselectorbox.skinurlbits.value;
            
            //----------------------------------
            // Strip out old skin change stuff
            // setskin=1&skinid=2
            //----------------------------------
            
            extravars = extravars.replace( /setskin=\d{1,}/g, ''  );
            extravars = extravars.replace( /skinid=\d{1,}/g , ''  );
            extravars = extravars.replace( /&{1,}/g         , '&' );
            extravars = extravars.replace( /s=&/g           , ''  );
        }
        
        locationjump( 'setskin=1&skinid=' + choosebox + extravars );
    }
}

/*-------------------------------------------------------------------------*/
// CHOOSE LANG
/*-------------------------------------------------------------------------*/

function chooselang(obj)
{
    choosebox = obj.options[obj.selectedIndex].value;
    extravars = '';
    
    if ( document.langselectorbox.langurlbits.value )
    {
        extravars = '&' + document.langselectorbox.langurlbits.value;

        //----------------------------------
        // Strip out old skin change stuff
        // setskin=1&skinid=2
        //----------------------------------
            
        extravars = extravars.replace( /setlanguage=\d{1,}/g, ''  );
        extravars = extravars.replace( /cal_id=&/g, ''  );
        extravars = extravars.replace( /langid=\w{1,}/g , ''  );
        extravars = extravars.replace( /&{1,}/g         , '&' );
        extravars = extravars.replace( /s=&/g           , ''  );
    }
    
    locationjump( 'setlanguage=1&langid=' + choosebox + extravars );
}

/*-------------------------------------------------------------------------*/
// pop up window
/*-------------------------------------------------------------------------*/

function PopUp(url, name, width,height,center,resize,scroll,posleft,postop)
{
    showx = "";
    showy = "";
    
    if (posleft != 0) { X = posleft }
    if (postop  != 0) { Y = postop  }
    
    if (!scroll) { scroll = 1 }
    if (!resize) { resize = 1 }
    
    if ((parseInt (navigator.appVersion) >= 4 ) && (center))
    {
        X = (screen.width  - width ) / 2;
        Y = (screen.height - height) / 2;
    }
    
    if ( X > 0 )
    {
        showx = ',left='+X;
    }
    
    if ( Y > 0 )
    {
        showy = ',top='+Y;
    }
    
    if (scroll != 0) { scroll = 1 }
    
    var Win = window.open( url, name, 'width='+width+',height='+height+ showx + showy + ',resizable='+resize+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no');
}

/*-------------------------------------------------------------------------*/
// Array: Get stack size
/*-------------------------------------------------------------------------*/

function stacksize(thearray)
{
    for (i = 0 ; i < thearray.length; i++ )
    {
        if ( (thearray[i] == "") || (thearray[i] == null) || (thearray == 'undefined') )
        {
            return i;
        }
    }
    
    return thearray.length;
}

/*-------------------------------------------------------------------------*/
// Array: Push stack
/*-------------------------------------------------------------------------*/

function pushstack(thearray, newval)
{
    arraysize = stacksize(thearray);
    thearray[arraysize] = newval;
}

/*-------------------------------------------------------------------------*/
// Array: Pop stack
/*-------------------------------------------------------------------------*/

function popstack(thearray)
{
    arraysize = stacksize(thearray);
    theval = thearray[arraysize - 1];
    delete thearray[arraysize - 1];
    return theval;
}

/*-------------------------------------------------------------------------*/
// Converts "safe" innerHTML back to normal template
/*-------------------------------------------------------------------------*/

function innerhtml_template_to_html( t )
{
    t = t.replace( /&lt;%(\d+?)&gt;/ig, "<%$1>" );
    t = t.replace( /%3C%(\d+?)%3E/ig  , "<%$1>" );
    return t;
}

/*-------------------------------------------------------------------------*/
// Global freeze events
/*-------------------------------------------------------------------------*/

function global_cancel_bubble(obj, extra)
{
    if ( ! obj || is_ie)
    {
        if ( extra )
        {
            window.event.returnValue = false;
        }
        
        window.event.cancelBubble = true;
        
        return window.event;
    }
    else
    {
        obj.stopPropagation();
        
        if ( extra )
        {
            obj.preventDefault();
        }
        
        return obj;
    }
}

/*-------------------------------------------------------------------------*/
// Get left posititon of object
/*-------------------------------------------------------------------------*/

function _get_obj_leftpos(obj)
{
    var left = obj.offsetLeft;
    
    while( (obj = obj.offsetParent) != null )
    {
        left += obj.offsetLeft;
    }
    
    return left;
}

/*-------------------------------------------------------------------------*/
// Get top position of object
/*-------------------------------------------------------------------------*/

function _get_obj_toppos(obj)
{
    var top = obj.offsetTop;
    
    while( (obj = obj.offsetParent) != null )
    {
        top += obj.offsetTop;
    }
    
    return top;
}

/*-------------------------------------------------------------------------*/
// Center a div on the screen
/*-------------------------------------------------------------------------*/

function center_div()
{
    this.divname = '';
    this.divobj  = '';
}

/*-------------------------------------------------------------------------*/
// Main run function
/*-------------------------------------------------------------------------*/

center_div.prototype.move_div = function()
{
    try
    {
        this.divobj = document.getElementById( this.divname );
    }
    catch(e)
    {
        return;
    }
    
    //----------------------------------
    // Figure width and height
    //----------------------------------
    
    var my_width  = 0;
    var my_height = 0;
    
    if ( typeof( window.innerWidth ) == 'number' )
    {
        //----------------------------------
        // Non IE
        //----------------------------------
      
        my_width  = window.innerWidth;
        my_height = window.innerHeight;
    }
    else if ( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
    {
        //----------------------------------
        // IE 6+
        //----------------------------------
        
        my_width  = document.documentElement.clientWidth;
        my_height = document.documentElement.clientHeight;
    }
    else if ( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
    {
        //----------------------------------
        // Old IE
        //----------------------------------
        
        my_width  = document.body.clientWidth;
        my_height = document.body.clientHeight;
    }
    
    //----------------------------------
    // Show...
    //----------------------------------
    
    this.divobj.style.position = 'absolute';
    this.divobj.style.display  = 'block';
    this.divobj.style.zIndex   = 99;
    
    //----------------------------------
    // Get div height && width
    //----------------------------------
    
    var divheight = parseInt( this.divobj.style.Height );
    var divwidth  = parseInt( this.divobj.style.Width );
    
    divheight = divheight ? divheight : 200;
    divwidth  = divwidth  ? divwidth  : 400;
    
    //----------------------------------
    // Get current scroll offset
    //----------------------------------
    
    var scrolly = this.getYscroll();
    
    //----------------------------------
    // Finalize...
    //----------------------------------
    
    var setX = ( my_width  - divwidth  ) / 2;
    var setY = ( my_height - divheight ) / 2 + scrolly;
    
    setX = ( setX < 0 ) ? 0 : setX;
    setY = ( setY < 0 ) ? 0 : setY;
    
    this.divobj.style.left = setX + "px";
    this.divobj.style.top  = setY + "px";
}

/*-------------------------------------------------------------------------*/
// Hide div
/*-------------------------------------------------------------------------*/

center_div.prototype.hide_div = function()
{
    try
    {
        if ( ! this.divobj )
        {
            return;
        }
        else
        {
            this.divobj.style.display  = 'none';
        }
    }
    catch(e)
    {
        return;
    }
}

/*-------------------------------------------------------------------------*/
// Get YScroll
/*-------------------------------------------------------------------------*/

center_div.prototype.getYscroll = function()
{
    var scrollY = 0;
    
    if ( document.documentElement && document.documentElement.scrollTop )
    {
        scrollY = document.documentElement.scrollTop;
    }
    else if ( document.body && document.body.scrollTop )
    {
        scrollY = document.body.scrollTop;
    }
    else if ( window.pageYOffset )
    {
        scrollY = window.pageYOffset;
    }
    else if ( window.scrollY )
    {
        scrollY = window.scrollY;
    }
    
    return scrollY;
}

function OpenSpoiler(id)
{
        var obj = "";    

        // Check browser compatibility
        if(document.getElementById)
            obj = document.getElementById(id).style;
        else if(document.all)
            obj = document.all[id];
        else if(document.layers)
            obj = document.layers[id];
        else
            return 1;

        // Do the magic :)
        if(obj.display == "")
            obj.display = "none";
        else if(obj.display != "none")
            obj.display = "none";
        else
            obj.display = "block";
}

// MODIFIED BY BUTCHER:
  function generate_random_password( pass_length )
  {
    if( pass_length < 1 )
    {
      return false;
    }
    var symbols_array = new Array( '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' );
    var password = "";
    var element_number = 0;
    var i = 0;
    for( i = 0; i < pass_length; i++ )
    {
      element_number = Math.floor( Math.random() * symbols_array.length );
      password = password + symbols_array[element_number];
    }
    return password;
  }

  function highlight_forum_row( action, forum_id )
  {
    var new_background = "#e2ebf3";
    var old_background = "";
    var element = null;
    var highlight_forum_elements = new Array( /*"forum_" + forum_id + "_left",*/ "forum_" + forum_id + "_row1", "forum_" + forum_id + "_row2", "forum_" + forum_id + "_row3", "forum_" + forum_id + "_row4"/*, "forum_" + forum_id + "_right"*/ );
    for( var i = 0; i < highlight_forum_elements.length; i++ )
    {
      var forum_element = highlight_forum_elements[i];
      if( element = my_getbyid( forum_element ) )
      {
        if( action == 1 )
        {
          element.style.backgroundColor = new_background;
        }
        else if( action == 0 )
        {
          element.style.backgroundColor = old_background;
        }
      }
      element = null;
    }
  }

  //function highlight_last_message_link( element, action )
  //{
  //  if( element )
  //  {
      
      
      
      
  //  }
  //}

  // Функция MM_PRELOADIMAGES (с) Butcher, MediaPortal.kiev.ua
  // Подгружает заданные изображения в кэш браузера
  function MM_preloadImages( )
  {
    var images_path      = "style_images/mediaportal/";
    var image_to_preload = "";
    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;
          image_to_preload = a[i];
          if( image_to_preload.indexOf( "/" ) != -1 )
          {
            image_to_preload = images_path + "" + image_to_preload;
          }
          document.MM_p[j++].src = image_to_preload;
        }
      }
    }

    return true;
  }
// END MODIFICATION


  function mp_preload_images( images )
  {
    if( !document.images )
    {
      //alert( "Images not supported" );
      return false;
    }
    var images_path = "style_images/mediaportal/";
    var aImages     = new Array;
    var nImages     = images.length;
    for( var i = 0; i < images.length; i++ )
    {
      var oImage = new Image();
      aImages.push( oImage );
      var theImage = images[i];
      if( theImage.indexOf( "/" ) != -1 )
      {
        theImage = images_path + "" + theImage;
      }
      oImage.src = theImage;
      //alert( "Image preloaded successfully: " + theImage );
    }

    return true;
  }

  function act( element )
  {
    if( !element || !element.src || element.src.indexOf( "_active." ) != -1 )
    {
      return false;
    }
    var old_src = element.src;
    var new_src = old_src.substring( 0, old_src.lastIndexOf( "." ) ) + "_active" + old_src.substring( old_src.lastIndexOf( "." ) );
    element.src = new_src;
    return;
  }

  function inact( element )
  {
    var parasite_string = "_active.";
    if( !element || !element.src || element.src.indexOf( parasite_string ) == -1 )
    {
      return false;
    }
    var old_src = element.src;
    var new_src = old_src.substring( 0, old_src.lastIndexOf( parasite_string ) ) + "." + old_src.substring( old_src.lastIndexOf( parasite_string ) + parasite_string.length );
    element.src = new_src;
    return;
  }

  function toggle_image_in_quote( element, action )
  {
    if( element && element.nodeName == "DIV" && element.childNodes[0] && element.childNodes[1] && ( action == "show" || action == "hide" ) )
    {
      if( action == "show" )
      {      
        element.childNodes[0].style.display = "none";
        element.childNodes[1].style.display = "table";
      }
      else if( action == "hide" )
      {      
        element.childNodes[0].style.display = "table";
        element.childNodes[1].style.display = "none";
      }
    }
    return;
  }

  function clear_selection( element )
  {
    var def_value = element.value;
    element.value = "";
    element.value = def_value;
    code_selected = 0;
    return;
  }

  function code_select( element )
  {
    if( code_selected == 1 )
    {
      code_unselect( element );
      return false;
    }
    else if( code_selected == 0 )
    {
      //element.focus();
      element.select();
      code_selected = 1;
      //element.title = "Нажмите правую кнопку мыши, затем \"копировать\", левую - для отмены выделения";
    }
    return;
  }

  function code_select_flag( val )
  {
    code_selected = val;
    return;
  }

  function code_unselect( element )
  {
    if( code_selected == 1 )
    {
      clear_selection( element );
    }
    //element.title = "";
    return;
  }

  function get_selected_text()
  {
    var txt = "";
    /*
    if( window.getSelection )
    {
      txt = window.getSelection();
      txt = "1";
      alert( window.getSelection() );
    }
    else*/ if( document.getSelection )
    {
      txt = document.getSelection();
      //txt = "2";
    }
    else if( document.selection )
    {
      txt = document.selection.createRange();
      txt = "3";
    }

    return txt;
  }

  function findPosX( obj )
  {
    if( !obj )
    {
      return 0;
    }
    var curleft = 0;
    if( obj.offsetParent )
    {
      while( 1 )
      {
        curleft += obj.offsetLeft;
        if( !obj.offsetParent )
        {
          break;
        }
        obj = obj.offsetParent;
      }
    } 
    else if( obj.x )
    {
      curleft += obj.x;
    }

    return curleft;
  }

  function findPosY( obj )
  {
    if( !obj )
    {
      return 0;
    }
    var curtop = 0;
    if( obj.offsetParent )
    {
      while(1)
      {
        curtop += obj.offsetTop;
        if( !obj.offsetParent )
        {
          break;
        }
        obj = obj.offsetParent;
      }
    }
    else if( obj.y )
    {
      curtop += obj.y;
    }

    return curtop;
  }

  function quote_user_link( element, user_id )
  {
    var newdiv = document.createElement( "div" );
    if( newdiv )
    {
    //newdiv.innerHTML  = "<table cellpadding=\"0\" cellspacing=\"0\"><tbody><tr><td><nobr>Смотреть профиль пользователя</nobr></td></tr><tr><td style=\"background-image: none;\" onClick=\"quote_user_link_close( this.parentNode.parentNode.parentNode.parentNode );\"><nobr>Отмена</nobr></td></tr></tbody></table>";
      newdiv.innerHTML  = "<table cellpadding=\"0\" cellspacing=\"0\"><tbody><tr><td onMouseOut=\"quote_user_link_close( this );\" onClick=\"quote_open_user_profile( this, " + parseInt( user_id ) + " );\"><nobr>Смотреть профиль пользователя</nobr></td></tr></tbody></table>";
      newdiv.className  = "quote_user_link";
      newdiv.style.left = findPosX( element ) - 5 + "px";
      newdiv.style.top  = findPosY( element ) - 2 + "px"; // - 22
      document.body.appendChild( newdiv );
      newdiv.setAttribute( "onmouseout", "quote_user_link_close( this );" );
      quote_profile_div = 1;
    }

    return;
  }

  function quote_user_link_close( element )
  {
    if( element.parentNode )
    {
      element = element.parentNode.parentNode.parentNode.parentNode;
    }
    else
    {
      return;
    }
    if( quote_profile_div == 1 && element && element.nodeName == "div" )
    {
      document.body.removeChild( element );
      quote_profile_div = 0;
    }
    return;
  }

  function quote_open_user_profile( element, user_id )
  {
    quote_user_link_close( element );
    var new_window = window.open( ipb_var_base_url + "showuser=" + user_id, "mp_user_" + user_id + "_details" );

    if( new_window && window.focus )
    {
      new_window.focus();
    }
    return;
  }
/*
  function ___spoiler_toggle___( object )
  {
    if( object.nodeName != "IMG" || object.nodeType != 1 )
    {
      return;
    }

    var spoiler_table = object.parentNode.parentNode.parentNode.parentNode;

    if( spoiler_table.nodeName != "TABLE" || spoiler_table.nodeType != 1 )
    {
      return;
    }

    var hidden_tr = spoiler_table.childNodes[0].childNodes[2];
    if( hidden_tr.nodeName != "TR" || hidden_tr.nodeType != 1 )
    {
      return;
    }

    var object_src = object.src;

    if( hidden_tr.style.display == "none" )
    {
      hidden_tr.style.display = "";
      object.src = object_src.substring( 0, object_src.lastIndexOf( "/" ) + 1 ) + "spoiler_minus_active.gif";
    }
    else
    {
      hidden_tr.style.display = "none";
      object.src = object_src.substring( 0, object_src.lastIndexOf( "/" ) + 1 ) + "spoiler_plus_active.gif";
    }

    return;
  }
*/

  function spoiler_toggle( object )
  {
    if( object.nodeName != "IMG" || object.nodeType != 1 )
    {
      return;
    }

    var spoiler_table = object.parentNode.parentNode.parentNode.parentNode;

    if( spoiler_table.nodeName != "TABLE" || spoiler_table.nodeType != 1 )
    {
      return;
    }

    var spoiler_tbody = find_node_object( spoiler_table, "TBODY", 1 );
    if( spoiler_tbody == null )
    {
      return;
    }

    var hidden_tr = find_node_object( spoiler_tbody, "TR", 3 )
    if( hidden_tr == null )
    {
      return;
    }

    var object_src = object.src;

    if( hidden_tr.style.display == "none" )
    {
      hidden_tr.style.display = "";
      object.src = object_src.substring( 0, object_src.lastIndexOf( "/" ) + 1 ) + "spoiler_minus_active.gif";
    }
    else
    {
      hidden_tr.style.display = "none";
      object.src = object_src.substring( 0, object_src.lastIndexOf( "/" ) + 1 ) + "spoiler_plus_active.gif";
    }

    return;
  }

  function find_node_object( object, child_name, child_position )
  {
    if( !object || !object.childNodes.length || counter <= 0 )
    {
      return null;
    }

    var counter = 0;
    var i       = 0;

    for( i = 0; i < object.childNodes.length; i++ )
    {
      if( object.childNodes[i].tagName == child_name )
      {
        counter++;
        if( counter == child_position )
        {
          return object.childNodes[i];
        }
      }
    }
    return null;
  }

  function toggle_element( element, state ) {
    if( !is_object( element ) ) {
      element = get_by_id( element );
    }

    if( is_object( element ) && element.style && is_boolean( state ) ) {
      element.style.display = state === true ? "" : "none";
      return true;
    }

    return false;
  }

  function show_element( element )
  {
    return toggle_element( element, true );
  }

  function hide_element( element )
  {
    return toggle_element( element, false );
  }

  function get_by_id( id )
  {
    var element = null;
    
    if( !id ) {
      return 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;
  }

  function is_object( element ) {
    return ( element && typeof element == "object" ) ? true : false;
  }

  function is_boolean( variable ) {
    if( variable === true || variable === false ) {
      return true;
    }
    return false;
  }

  function rules_changed( index )
  {
    var selector1 = document.getElementById( "rules" + 1 );
    var selector2 = document.getElementById( "rules" + 2 );
    var selector3 = document.getElementById( "rules" + 3 );

    if( selector1 && selector2 && selector3 ) {
      if( index == 1 ) {
        if( selector1.value == 0 ) {
          if( selector2.value == 0 ) {
            my_hide_div( selector2 );
          }
        } else {
          my_show_div( selector2 );
        }
      } else if( index == 2 ) {
        if( selector2.value == 0 ) {
          if( selector3.value == 0 ) {
            my_hide_div( selector3 );
          }
        } else {
          my_show_div( selector3 );
        }
        rules_changed( 1 );
      } else {
        rules_changed( 1 );
        rules_changed( 2 );
      }
    }

    return;
  }
