
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();


/*-------------------------------------------------------------------------*/
// 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;
}

function SetClass(xid,xclass){
var bTest = document.getElementById(xid);     
      if (bTest!=null) 
      { 
           bTest.className=xclass;       
      }

}

function showAddCommForm()
{
    $('add_comment_button').hide();
    $('idCommForm').show();
}

function hideCommForm()
{
    $('idCommForm').hide();
    $('add_comment_button').show();
}

function openMenu(v){
    
    switch(v)
    {
        case 'info':
            window.location.href = '/guide/about.php';
        break;
        case 'gold':
            window.location.href = '/guide/goldinfo.php';
        break;
        case 'news':
            window.location.href = '/guide/news.php';
        break;
        case 'library':
            window.location.href = '/guide/library.php';
        break;
        case 'forum':
             window.location.href = '/guide/forum.php';
        break;
    }
}

var is_conf = false;
var alert_url;
var alert_mode;
function confirmDel(what, url, mode)
{
  if (is_conf) return;
  is_conf = true;
  if (what == "topic"){var txt = "топик?";} else {var txt = "коментарий?";}
  var win = new cWindow('confirm', {'onOk': _confirmDel, 'onCancel': confirm_cls}, {'url': url});
  win.setTitle('&nbsp;');
  win.setContent("Вы уверены, что хотите<br>удалить данный " + txt);
  win.show();
}

function _confirmDel()
{
  location.href = this.params.url;
}

function confirm_cls()
{
  this.hide();
  is_conf = false;
}

function moveRubric(url)
{
    alert_url=url;
    showConfirm('Перенести', "Рубрика:" + rubric_select ? rubric_select : '');
    alert_mode = 'move';
}

function delComm()
{
  switch(alert_mode)
  {
    case 'move':
          window.location.href = alert_url + '&rid='+$('move_rubrics').value + '&my_submit=1';
          hideConfirm();
          return true;
    break;
    default:
      if (alert_url)
      {
        window.location.href = alert_url;
        return true;
      } 
      else
      {
        return false;
      }
    break;
  }

}

function setTitle() {
    if ($('lib_title'))
    {
		
       if  ($('dedication_id'))
	   {
	    $('dedication_id').innerHTML = $('lib_title').innerHTML;
        $('lib_title').parentNode.removeChild($('lib_title'));
	   }
    }
}

function ismaxlength(elem, count)
{
  if (!count)
  {
    count=10;
  }
  if (elem)
  {
    if (elem.value.length>count)
    {
      elem.value=elem.value.substring(0,count);
    }
  }
}

function sh_d(id)
{
	if (id && document.getElementById(id))
	{
		var t = document.getElementById(id);
		var s = t.getAttribute('s');
		if (s)
		{
           t.style.display = (s) ? 'none' : '';
		   t.s = (s) ? 0 : 1;
		} else
		{
           t.style.display = '';
		   t.s = 1;
		}
	}
}

function showNews(id)
{
	if (document.getElementById('r'+id))
	{
		var n = document.getElementById('r'+id);
	 	var s = document.getElementById('sp'+id);
		if ((n.style.display == 'none'))
		{
			n.style.display = '';
			s.innerHTML = 'свернуть';
		} else
		{
			s.innerHTML = 'подробнее';
			n.style.display = 'none';
		}
	}
}


function MM_preloadImages() { // v3.0
	var d = document;
	if (d.images) {
		if (!d.MM_p)
			d.MM_p = new Array();
		var i, j = d.MM_p.length, a = MM_preloadImages.arguments;
		for (i = 0; i < a.length; i++)
			if (a[i].indexOf("#") != 0) {
				d.MM_p[j] = new Image;
				d.MM_p[j++].src = a[i];
			}
	}
}
