/*
+--------------------------------------------------------------------------
|	TeccoSite Engine
|	========================================
|	by Denis Evteev
|	(c) 2006 Tecco Systems Ltd.
|	========================================
|	Web: http://www.teccosoft.com
|	Email: info@teccosoft.com
+---------------------------------------------------------------------------
|
|	Module name: JavaScript GLOBAL
|	Module version: 1.0
|	Module purpose: JavaScript functions
|
+---------------------------------------------------------------------------
|
|	> Created: --
|	> Modified: --
|
+---------------------------------------------------------------------------
*/

//==========================================
// Ссылка на элемент по его ID
//==========================================

function 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;
}

//==========================================
// Получение cookie
//==========================================

function get_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;
}

//==========================================
// Сохранить cookie
//==========================================

function set_cookie( name, value, sticky )
{
	expire = "";
	domain = "";
	path   = "/";

	if ( sticky )
	{
		expire = "; expires=Wed, 1 Jan 2020 00:00:00 GMT";
	}

	if ( vars_cookie_domain != "" )
	{
		domain = '; domain=' + vars_cookie_domain;
	}

	/*if ( ipb_var_cookie_path != "" )
	{
		path = ipb_var_cookie_path;
	}*/

	document.cookie = name + "=" + value + "; path=" + path + expire + domain + ';';
}

//==========================================
// Скрыть DIV элемент
//==========================================

function hide_div( itm )
{
	if ( ! itm ) return;

	itm.style.display = "none";
}

//==========================================
// Показать DIV элемент
//==========================================

function show_div( itm )
{
	if ( ! itm ) return;

	itm.style.display = "";
}

//==========================================
// Раскрытие / скрытие меню
//==========================================

function set_menu_state( mkey, expand )
{
	saved = new Array();
	clean = new Array();

	//-----------------------------------
	// Загружаем имеющуюся информацию из
	// cookie
	//-----------------------------------

	if ( tmp = get_cookie('acp_menu_states') )
	{
		saved = tmp.split(",");
	}

	//-----------------------------------
	// Удаляем значение, если оно уже
	// присутствует
	//-----------------------------------

	for( i = 0 ; i < saved.length; i++ )
	{
		if ( saved[i] != mkey && saved[i] != "" )
		{
			clean[clean.length] = saved[i];
		}
	}

	//-----------------------------------
	// Раскрыть меню?
	//-----------------------------------

	if ( expand )
	{
		show_div( getbyid( mkey+'_expanded' ) );
		hide_div( getbyid( mkey+'_collapsed' ) );
	}
	else
	{		clean[ clean.length ] = mkey;
		show_div( getbyid( mkey+'_collapsed' ) );
		hide_div( getbyid( mkey+'_expanded' ) );
	}

	set_cookie( 'acp_menu_states', clean.join(','), 1 );

	tmp = clean.join(',');
}

//==========================================
// Раскрыть/свернуть подменю
//==========================================

var script = 0;

function toggle_submenu( elem, sid, mid )
{
script = 1;

mid  = 'cat_'+mid+'\d{0,3}';
img  = getbyid( 'img_'+sid );

if( img.alt == '+' )
{
 img.alt = '-';
 img.src = 'skins/default/public/images/menu_arrow_down.gif';

 if( elem.nodeName == 'IMG' ) elem = elem.parentNode;

 elem = elem.parentNode.nextSibling;

 if( elem.nodeType == 3 ) elem = elem.nextSibling;

 if( elem && elem.nodeType == 1 )
 {
  while( elem.id.match( mid ) )
  {
//убираю явное отображение display = "none" со страниц
   elem.className=elem.className.replace('_hid','');//elem.style.display = "";

   elem = elem.nextSibling;

   if( elem && elem.nodeType == 3 ) elem = elem.nextSibling;

   if( !elem || elem.nodeType != 1 ) break;
  }
 }
}
else
{
 img.alt = '+';
 img.src = 'skins/default/public/images/menu_arrow_right.gif';

 if( elem.nodeName == 'IMG' ) elem = elem.parentNode;

 elem = elem.parentNode.nextSibling;

 if( elem.nodeType == 3 ) elem = elem.nextSibling;

 if( elem && elem.nodeType == 1 )
 {
  while( elem.id.match( mid ) )
  {
//убираю явное отображение display = "none" со страниц
   elem.className=elem.className+'_hid';//style.display = "none";

   elem = elem.nextSibling;

   if( elem && elem.nodeType == 3 ) elem = elem.nextSibling;

   if( !elem || elem.nodeType != 1 ) break;
  }
 }
}
}

function check_for_dynamic()
{
	if(script == 1)
	{
		 script = 0;
		 return false;
	}
}
function ChooseLen() {
	M = window.document.MainForm.tbMessage.value.length;
	window.document.MainForm.tbCount.value = M;
}