//--------------------------------------------------------------------------------------------------
// Generic_Tree
//--------------------------------------------------------------------------------------------------
function Generic_Tree_Node()
{
	// Properties
	this.id			= null;
	this.children	= null;
	this.prefix		= null;
	this.onscreen	= false;
	this.level		= 0;
}

function Generic_Tree()
{
	// Properties
	this.tree			= null;
	this.container_id	= null;
	this.var_name		= null;
	this.img_path		= '/design/img/tree/';
	this.update_saved_tree = 1;

	// Methods
	this.appendHTML = function(obj, html)
	{
		if (typeof(obj.insertAdjacentHTML) != 'undefined')
		{
			obj.insertAdjacentHTML('beforeEnd', html);
		}
		else
		{
			obj.innerHTML += html;
		}
	}

	this.out = function(/*tr=this.tree, container_id=this.container_id, level=0*/)
	{
		var tr				= arguments.length > 0 ? arguments[0] : this.tree,
			container_id	= arguments.length > 1 ? arguments[1] : this.container_id,
			table			= document.getElementById(container_id),
			level			= arguments.length > 2 ? arguments[2] : 0;

		for (var n = 0; n < tr.length; n++)
		{
			tr[n].level = level + 1;

			var has_children = (tr[n].children && tr[n].children != null),
				children_container_id = this.prefix + tr[n].id + '_ch',
				row = table.insertRow(-1);

			// [+] [-]
			var pm_cell = row.insertCell(-1);
			this.appendPM(pm_cell, tr[n], has_children);

			// icon
			var icon_cell = row.insertCell(-1);
//			icon_cell.vAlign = 'top';
			icon_cell.style.width = '16px';
			this.appendIcon(icon_cell, tr[n]);

			var main_cell = row.insertCell(-1);
			main_cell.style.width = '100%';
			this.appendNodeInfo(main_cell, tr[n], has_children);

			// область для child-ов
			if (has_children)
			{
				row = table.insertRow(-1);

				var child_cell = row.insertCell(-1);
				child_cell.innerHTML = '';

				child_cell = row.insertCell(-1);
				child_cell.innerHTML = '';

				child_cell = row.insertCell(-1);
				child_cell.innerHTML =
					'<table cellspacing="0" cellpadding="0" border="0" width="100%" id="' + children_container_id +
					'" style="display: none;"></table>';

				this.onCreateChildArea(children_container_id, tr[n]);
			}

			this.onAfterAppend(tr[n]);
		}
	}

	this.createCaption = function(node, has_children)
	{
		var caption = node.caption;

		if (has_children)
			caption =
				'<a href="#" onclick="' + this.var_name + '.ec(\'' + this.prefix + node.id + '\'); return false;">' +
				caption + '</a>';

		return caption;
	}

	this.onAfterAppend = function(node)
	{
		// GAG
	}

	this.onCreateChildArea = function(children_container_id, node)
	{
		// GAG
	}

	this.lookup = function(id/*, tr=this.tree*/)
	{
		var tr = arguments.length > 1 ? arguments[1] : this.tree;

		for (var n = 0; n < tr.length; n++)
		{
			if (tr[n].id == id)
			{
				return tr[n];
			}
			else if(tr[n].children && tr[n].children != null)
			{
				var result = this.lookup(id, tr[n].children);

				if (result)
					return result;
			}
		}
	}

	this.removePrefix = function(id)
	{
		return this.prefix
			? (new String(id)).substr(this.prefix.length)
			: id;
	}

	this.ec = function(blk_id/*, node = null*/)
	{
		var blk			= document.getElementById(blk_id + '_ch'),
			need_open	= blk.style.display == 'none',
			node 		= arguments.length > 1 ? arguments[1] : this.lookup(this.removePrefix(blk_id));

		if (need_open && !node.onscreen)
		{
			node.onscreen = true;
			this.out(node.children, blk_id + '_ch', node.level);
		}

		blk.style.display = need_open ? 'block' : 'none';

		var pm = document.getElementById(blk_id + '_pm');
		if (pm)
		{
			pm.src = this.getPmSrc(node, need_open)
		}

		this.onec(blk_id, node, need_open);
	}

	this.getPmSrc = function(node, need_open)
	{
		return this.img_path + (need_open ? 'minus' : 'plus') + '.gif';
	}

	this.appendIcon = function(container, node)
	{
		// GAG
	}

	this.appendPM = function(container, node, has_children)
	{
		var pm_id, pm_src;

		if (has_children)
		{
			pm_id = ' id="' + this.prefix + node.id + '_pm"';
			pm_src = 'plus.gif';
		}
		else
		{
			pm_id = '';
			pm_src = 'null.gif';
		}

		container.innerHTML = '<img width="15" border="0" src="' + this.img_path + pm_src + '"' + pm_id + ' />';
		container.className = 'tree-pm';

		if (has_children)
			container.innerHTML =
				'<a href="#" onclick="' + this.var_name + '.ec(\'' + this.prefix + node.id +
				'\'); return false;">' + container.innerHTML + '</a>';
	}

	this.appendNodeInfo = function(container, node)
	{
		container.className = 'tree-node' + (node.level == 1 ? '-first' : '');
	}

	this.onec = function(blk_id, tree, need_open)
	{
		// GAG
	}

	this.mySprintf = function(pattern, params)
	{
		return pattern.replace(/#([^#]+)#/g, function($0,$1) { return params[$1]; });
	}

	this.cloneHash = function(old_hash, new_hash)
	{
		if (typeof(new_hash) != 'object')
			new_hash = {};

		for (var key in old_hash)
		{
    		if (typeof(old_hash[key]) == 'object')
				this.cloneHash(old_hash[key], new_hash[key]);
			else
				new_hash[key] = old_hash[key];
		}
	}

	this.updateSavedTree = function(blk_id, need_open)
	{
		if (!this.update_saved_tree)
			return;

		var url = 'set_ec_tree.php?' + this.DNSID + '&open=' + (need_open ? 1 : 0) + '&id=' + blk_id + '&' + Math.random(),
			id = 'te_if_' + blk_id,
			ifr;

		if (!(ifr = document.getElementById(id)))
		{
			ifr = document.createElement('iframe');
			ifr.id = id;
			ifr.border = 0;
			ifr.width = ifr.height = 1;
			ifr.style.visibility = 'hidden';
			ifr.src = url;
			document.body.appendChild(ifr);
		}
		else
			ifr.src = url;
	}

	this.doExpandTree = function()
	{
		this.update_saved_tree = false;
		this.expandTree();
		this.update_saved_tree = true;
	}

	this.expandTree = function(/*tree = this.tree, level = 0, parents = []*/)
	{
		var tree = arguments.length > 0 ? arguments[0] : this.tree,
			level = arguments.length > 1 ? arguments[1] : 0,
			parents = arguments.length > 2 ? arguments[2] : [];

		for (var i = 0; i < tree.length; i++)
		{
			if (typeof(this.expand) == 'object' ? this.expand[tree[i].id] : this.expand)
			{
				// look for parents that isn't on screen and place it on screen
				for (var j = 0; j<level; j++)
					if (!parents[j].onscreen)
					{
						parents[j].onscreen = true;
						this.out(parents[j].children, parents[j].id + '_ch', parents[j].level);
					}

				if (tree[i].children && tree[i].children != null)
					this.ec(this.prefix + tree[i].id, tree[i]);
			}

			if (tree[i].children && tree[i].children != null)
			{
				parents[level] = tree[i];
				this.expandTree(tree[i].children, level + 1, parents);
			}
		}
	}
}

//--------------------------------------------------------------------------------------------------
// Structure_Tree
//--------------------------------------------------------------------------------------------------
function Structure_Tree_Node(id, caption, icon, tools)
{
	this.id = id;
	this.caption = caption;
	this.icon = icon;
	this.tools = tools;
}
Structure_Tree_Node.prototype = new Generic_Tree_Node;

function Structure_Tree(tree, container_id, var_name, DNSID, prefix)
{
	this.tree = tree;
	this.container_id = container_id;
	this.var_name = var_name;
	this.DNSID = DNSID;
	this.prefix = prefix;
	this.img_path = '/design/img/tree/';
	this.icons = {'g' : 'group'};
	this.tool_tmpl = '<a href="#url#" title="#title#" #extra#><img src="#img_path##src#" width="16" height="16"></a>';
	this.tool_new_window = false;
	this.tools = {
		1 : {'url' : 'order.php?id=#id#', 'title' : 'Порядок', 'src' : 'order.gif'},
		2 : {'url' : 'edit.php?id=#id#', 'title' : 'Редактировать', 'src' : 'any_edit.gif'},
		3 : {'url' : 'edit.php?parent_id=#id#', 'title' : 'Добавить', 'src' : 'any_add.gif'},
		4 : {'url' : 'drop.php?id=#id#', 'title' : 'Удалить', 'src' : 'any_del.gif', 'confirm' : 1},
		5 : {'url' : '../structure_banner/?structure_id=#id#', 'title' : 'Баннеры', 'src' : 'ico_img.gif'}
	};
	this.expand = false;

	this.getIconSrc = function(icon_id/*, open = false*/)
	{
		var open = arguments.length > 1 ? arguments[1] : false;
		return this.img_path + this.icons[icon_id] + (open ? '_open' : '') + '.gif';
	}

	this.makeTool = function(node, params)
	{
		var p = {},
			url_params = {'DNSID' : this.DNSID, 'id' : node.id};

		this.cloneHash(params, p);

		p['url'] = this.mySprintf(p['url'], url_params);
		p['extra'] = this.tool_new_window ? 'target="_blank"' : '';

		if (p['confirm'])
		{
			if (p['extra'])
				p['extra'] += ' '

			p['extra'] += 'onClick="return confirm(\'Вы уверены?\')"'

			p['confirm'] = null;
		}

		p['img_path'] = this.img_path;

		return this.mySprintf(this.tool_tmpl, p);
	}

	this.appendIcon = function(container, node)
	{
		container.innerHTML =
			'<img src="' + this.getIconSrc(node.icon) + '" class="tree-icon" id="' + this.prefix + node.id + '_icon" />';
	}

	this.appendNodeInfo = function(container, node, has_children)
	{
		if (node.icon == 'dl')
		{
			container.style.backgroundImage = 'url(' + this.img_path + 'dash.gif)';
			container.style.backgroundRepeat = 'repeat-x';
			container.style.backgroundPosition = 'center';
			return;
		}

		var html = '<span class="tree-level-' + Math.min(node.level, 2) + '">' + this.createCaption(node, has_children) + '</span>';

		// tools
		var tools = '';
		for (var n = 0; n < node.tools.length; n++)
		{
			var tool = this.tools[node.tools[n]];

			if (tool)
				tools += '&nbsp;' + this.makeTool(node, tool);
		}
		if (tools)
			html += tools;

		container.innerHTML = html;
	}

	this.onec = function(blk_id, node, need_open)
	{
		document.getElementById(blk_id + '_icon').src = this.getIconSrc(node.icon, need_open);
		this.updateSavedTree(blk_id, need_open);
	}
}
Structure_Tree.prototype = new Generic_Tree;


//--------------------------------------------------------------------------------------------------
// Structure_Tree
//--------------------------------------------------------------------------------------------------
function BcTree_Tree_Node(id, caption, icon, tools)
{
	this.id = id;
	this.caption = caption;
	this.icon = icon;
	this.tools = tools;
}
BcTree_Tree_Node.prototype = new Generic_Tree_Node;

function BcTree_Tree(tree, container_id, var_name, DNSID, prefix)
{
	this.tree = tree;
	this.container_id = container_id;
	this.var_name = var_name;
	this.DNSID = DNSID;
	this.prefix = prefix;
	this.img_path = '/design/img/tree/';
	this.icons = {'g' : 'group'};
	this.tool_tmpl = '<a href="#url#" title="#title#" #extra#><img src="#img_path##src#" width="16" height="16"></a>';
	this.tool_new_window = false;
	this.tools = {
		1 : {'url' : 'order.php?id=#id#', 'title' : 'Порядок', 'src' : 'order.gif'},
		2 : {'url' : 'edit.php?id=#id#', 'title' : 'Редактировать', 'src' : 'any_edit.gif'},
		3 : {'url' : 'edit.php?parent_id=#id#', 'title' : 'Добавить', 'src' : 'any_add.gif'},
		4 : {'url' : 'drop.php?id=#id#', 'title' : 'Удалить', 'src' : 'any_del.gif', 'confirm' : 1},
		5 : {'url' : 'sublist.php?bc_tree_id=#id#', 'title' : 'Визитки', 'src' : 'ind.gif'}
	};
	this.expand = false;

	this.getIconSrc = function(icon_id/*, open = false*/)
	{
		var open = arguments.length > 1 ? arguments[1] : false;
		return this.img_path + this.icons[icon_id] + (open ? '_open' : '') + '.gif';
	}

	this.makeTool = function(node, params)
	{
		var p = {},
			url_params = {'DNSID' : this.DNSID, 'id' : node.id};

		this.cloneHash(params, p);

		p['url'] = this.mySprintf(p['url'], url_params);
		p['extra'] = this.tool_new_window ? 'target="_blank"' : '';

		if (p['confirm'])
		{
			if (p['extra'])
				p['extra'] += ' '

			p['extra'] += 'onClick="return confirm(\'Вы уверены?\')"'

			p['confirm'] = null;
		}

		p['img_path'] = this.img_path;

		return this.mySprintf(this.tool_tmpl, p);
	}

	this.appendIcon = function(container, node)
	{
		container.innerHTML =
			'<img src="' + this.getIconSrc(node.icon) + '" class="tree-icon" id="' + this.prefix + node.id + '_icon" />';
	}

	this.appendNodeInfo = function(container, node, has_children)
	{
		if (node.icon == 'dl')
		{
			container.style.backgroundImage = 'url(' + this.img_path + 'dash.gif)';
			container.style.backgroundRepeat = 'repeat-x';
			container.style.backgroundPosition = 'center';
			return;
		}

		var html = '<span class="tree-level-' + Math.min(node.level, 2) + '">' + this.createCaption(node, has_children) + '</span>';

		// tools
		var tools = '';
		for (var n = 0; n < node.tools.length; n++)
		{
			var tool = this.tools[node.tools[n]];

			if (tool)
				tools += '&nbsp;' + this.makeTool(node, tool);
		}
		if (tools)
			html += tools;

		container.innerHTML = html;
	}

	this.onec = function(blk_id, node, need_open)
	{
		document.getElementById(blk_id + '_icon').src = this.getIconSrc(node.icon, need_open);
		this.updateSavedTree(blk_id, need_open);
	}
}
BcTree_Tree.prototype = new Generic_Tree;


//--------------------------------------------------------------------------------------------------
// Phonebook_Department_Tree
//--------------------------------------------------------------------------------------------------
function Phonebook_Department_Tree_Node(id, caption, icon, tools)
{
	this.id = id;
	this.caption = caption;
	this.icon = icon;
	this.tools = tools;
}
Phonebook_Department_Tree_Node.prototype = new Structure_Tree_Node;

function Phonebook_Department_Tree(tree, container_id, var_name, DNSID, prefix, path)
{
	this.path = path;
	this.tree = tree;
	this.container_id = container_id;
	this.var_name = var_name;
	this.DNSID = DNSID;
	this.prefix = prefix;
	this.img_path = '/design/img/phonebook/';
	this.icons = {'g' : 'group'};
	this.tool_tmpl = '<a href="#url#" title="#title#" #extra#><img src="#img_path##src#" width="16" height="16"></a>';
	this.tool_new_window = false;
	this.tools = {
		1 : {'url' : 'order.php?id=#id#', 'title' : 'Порядок', 'src' : 'order.gif'},
		2 : {'url' : 'edit.php?id=#id#', 'title' : 'Редактировать', 'src' : 'any_edit.gif'},
		3 : {'url' : 'edit.php?parent_id=#id#', 'title' : 'Добавить', 'src' : 'any_add.gif'},
		4 : {'url' : 'drop.php?id=#id#', 'title' : 'Удалить', 'src' : 'any_del.gif', 'confirm' : 1},
		5 : {'url' : '../structure_banner/?structure_id=#id#', 'title' : 'Баннеры', 'src' : 'ico_img.gif'}
	};
	this.expand = false;

	this.getIconSrc = function(icon_id/*, open = false*/)
	{
		var open = arguments.length > 1 ? arguments[1] : false;
		return this.img_path + this.icons[icon_id] + (open ? '_open' : '') + '.gif';
	}

	this.createCaption = function(node, has_children)
	{
		var caption = node.caption;
		caption = '<span class="linkto" onclick="document.getElementById(\'letter\').value=\'\';document.getElementById(\'department\').value=' + node.id + ';document.getElementById(\'submit_btn\').value=\'\';document.getElementById(\'search_persons\').submit()">' +
			caption + '</span>';
		if (current_department && current_department == node.id)
		{
			caption = '<b>' + caption + '</b>';
			//if (has_children) this.ec(node.id)
		}
		return caption;
	}

	this.appendIcon = function(container, node)
	{
		container.innerHTML =
			'<img src="' + this.getIconSrc(node.icon) + '" height="0" width="0" class="tree-icon" id="' + this.prefix + node.id + '_icon" />';
	}

	this.appendNodeInfo = function(container, node, has_children)
	{
		if (node.icon == 'dl')
		{
			container.style.backgroundImage = 'url(' + this.img_path + 'dash.gif)';
			container.style.backgroundRepeat = 'repeat-x';
			container.style.backgroundPosition = 'center';
			return;
		}

		var html = '<span class="tree-level-' + Math.min(node.level, 2) + '">' + this.createCaption(node, has_children) + '</span>';

		// tools
		var tools = '';
		for (var n = 0; n < node.tools.length; n++)
		{
			var tool = this.tools[node.tools[n]];

			if (tool)
				tools += '&nbsp;' + this.makeTool(node, tool);
		}
		if (tools)
			html += tools;

		container.innerHTML = html;
	}

	this.onec = function(blk_id, node, need_open)
	{
		document.getElementById(blk_id + '_icon').src = this.getIconSrc(node.icon, need_open);
		this.updateSavedTree(blk_id, need_open);
	}

	this.updateSavedTree = function(blk_id, need_open)
	{
		if (!this.update_saved_tree)
			return;

		var url = this.path + 'set_ec_tree.php?' + this.DNSID + '&open=' + (need_open ? 1 : 0) + '&id=' + blk_id + '&' + Math.random(),
			id = 'te_if_' + blk_id,
			ifr;

		if (!(ifr = document.getElementById(id)))
		{
			ifr = document.createElement('iframe');
			ifr.id = id;
			ifr.border = 0;
			ifr.width = ifr.height = 1;
			ifr.style.visibility = 'hidden';
			ifr.src = url;
			document.body.appendChild(ifr);
		}
		else
			ifr.src = url;
	}
}


//--------------------------------------------------------------------------------------------------
// FP_Tree
//--------------------------------------------------------------------------------------------------
function FP_Tree_Node(id, caption, icon, url, tools)
{
	this.id = id;
	this.caption = caption;
	this.icon = icon;
	this.url = url;
	this.tools = tools;
}
FP_Tree_Node.prototype = new Generic_Tree_Node;

function FP_Tree(tree, container_id, var_name, DNSID, prefix)
{
	this.tree = tree;
	this.container_id = container_id;
	this.var_name = var_name;
	this.DNSID = DNSID;
	this.prefix = prefix;
	this.img_path = '/design/img/fp-tree/';
	this.icons = {'g' : 'group'};
	this.tool_tmpl = '<a href="#url#" title="#title#" #extra#><img src="#img_path##src#" width="16" height="16"></a>';
	this.tool_new_window = false;
	this.tools = {};
	this.expand = false;

	this.appendIcon = function(container, node) {}

	this.appendNodeInfo = function(container, node, has_children) {}

	this.createCaption = function(node, has_children)
	{
		var caption = node.caption;

		return node.url == '' ? caption : '<a href="' + node.url + '">' + caption + '</a>';
	}

	this.onec = function(blk_id, node, need_open)
	{
		this.updateSavedTree(blk_id, need_open);
	}

	this.getPmSrc = function(node, need_open)
	{
		return this.img_path + (need_open ? 'minus' : 'plus') + (node.level == 1 ? '0' : '') + '.gif';
	}

	this.appendPM = function(container, node, has_children)
	{
		if (node.level > 2)
			return;

		var pm_id, pm_src, html = '';

		if (has_children)
		{
			pm_id = ' id="' + this.prefix + node.id + '_pm"';
			pm_src = node.level == 1 ? 'plus0.gif' : 'plus.gif';
		}
		else
		{
			pm_id = '';
			pm_src = node.level == 1 ? 'null0.gif' : 'null.gif';
		}

		html = '<img class="tree-pm' + (node.level == 1 ? '-0' : '') + '" src="' + this.img_path + pm_src + '"' + pm_id + ' />';

		if (has_children)
			html =
				'<a href="#" onclick="' + this.var_name + '.ec(\'' + this.prefix + node.id +
				'\'); return false;">' + html + '</a>';

		container.innerHTML += html;
	}

	this.out = function(/*tr=this.tree, container_id=this.container_id, level=0*/)
	{
		var tr				= arguments.length > 0 ? arguments[0] : this.tree,
			container_id	= arguments.length > 1 ? arguments[1] : this.container_id,
			table			= document.getElementById(container_id),
			level			= arguments.length > 2 ? arguments[2] : 0;

		for (var n = 0; n < tr.length; n++)
		{
			tr[n].level = level + 1;

			var has_children = (tr[n].children && tr[n].children != null),
				children_container_id = this.prefix + tr[n].id + '_ch',
				row = table.insertRow(-1),
				cell = row.insertCell(-1);

			cell.className = "tree-level-" + Math.min(level, 2);

			// [+] [-]
			this.appendPM(cell, tr[n], has_children);

			// caption
			cell.innerHTML += this.createCaption(tr[n], has_children);

			// область для child-ов
			if (has_children)
			{
				row = table.insertRow(-1);
				var child_cell = row.insertCell(-1);

				child_cell.innerHTML =
					'<table cellspacing="0" cellpadding="0" border="0" width="100%" id="' + children_container_id +
					'" style="display:none"></table>';

				this.onCreateChildArea(children_container_id, tr[n]);
			}

			this.onAfterAppend(tr[n]);
		}
	}
}
FP_Tree.prototype = new Generic_Tree;

//--------------------------------------------------------------------------------------------------
// PubCategory_Tree
//--------------------------------------------------------------------------------------------------
function PubCategory_Tree_Node(id, caption, icon, url, tools)
{
	this.id = id;
	this.caption = caption;
	this.icon = icon;
	this.url = url;
	this.tools = tools;
}
PubCategory_Tree_Node.prototype = new Structure_Tree_Node;

function PubCategory_Tree(tree, container_id, var_name, DNSID, prefix)
{
	this.tree = tree;
	this.container_id = container_id;
	this.var_name = var_name;
	this.DNSID = DNSID;
	this.prefix = prefix;
	this.img_path = '/design/img/tree/';
	this.icons = {'g' : 'group'};
	this.tool_tmpl = '<a href="#url#" title="#title#" #extra#><img src="#img_path##src#" width="16" height="16"></a>';
	this.tool_new_window = false;
	this.tools = {
		1 : {'url' : 'order.php?id=#id#', 'title' : 'Порядок', 'src' : 'order.gif'},
		2 : {'url' : 'edit.php?id=#id#', 'title' : 'Редактировать', 'src' : 'any_edit.gif'},
		3 : {'url' : 'edit.php?parent_id=#id#', 'title' : 'Добавить', 'src' : 'any_add.gif'},
		4 : {'url' : 'drop.php?id=#id#', 'title' : 'Удалить', 'src' : 'any_del.gif', 'confirm' : 1},
		5 : {'url' : '/admin/pub/?category_id=#id#', 'title' : 'Публикации', 'src' : 'ind.gif'}
	};
	this.expand = false;
}
PubCategory_Tree.prototype = new Structure_Tree;

//--------------------------------------------------------------------------------------------------
// PubCategory_Tree
//--------------------------------------------------------------------------------------------------
function CorruptCategory_Tree_Node(id, caption, icon, url, tools)
{
    this.id = id;
    this.caption = caption;
    this.icon = icon;
    this.url = url;
    this.tools = tools;
}
CorruptCategory_Tree_Node.prototype = new Structure_Tree_Node;

function CorruptCategory_Tree(tree, container_id, var_name, DNSID, prefix)
{
    this.tree = tree;
    this.container_id = container_id;
    this.var_name = var_name;
    this.DNSID = DNSID;
    this.prefix = prefix;
    this.img_path = '/design/img/tree/';
    this.icons = {'g' : 'group'};
    this.tool_tmpl = '<a href="#url#" title="#title#" #extra#><img src="#img_path##src#" width="16" height="16"></a>';
    this.tool_new_window = false;
    this.tools = {
        1 : {'url' : 'order.php?id=#id#', 'title' : 'Порядок', 'src' : 'order.gif'},
        2 : {'url' : 'edit.php?id=#id#', 'title' : 'Редактировать', 'src' : 'any_edit.gif'},
        3 : {'url' : 'edit.php?parent_id=#id#', 'title' : 'Добавить', 'src' : 'any_add.gif'},
        4 : {'url' : 'drop.php?id=#id#', 'title' : 'Удалить', 'src' : 'any_del.gif', 'confirm' : 1},
        5 : {'url' : '/admin/corrupt/?category_id=#id#', 'title' : 'Публикации', 'src' : 'ind.gif'}
    };
    this.expand = false;
}
CorruptCategory_Tree.prototype = new Structure_Tree;

//--------------------------------------------------------------------------------------------------
// AdminGroupCategory_Tree
//--------------------------------------------------------------------------------------------------
function AdminGroupCategory_Tree_Node(id, caption, icon, url, tools)
{
    this.id = id;
    this.caption = caption;
    this.icon = icon;
    this.url = url;
    this.tools = tools;
}
AdminGroupCategory_Tree_Node.prototype = new Structure_Tree_Node;

function AdminGroupCategory_Tree(tree, container_id, var_name, DNSID, prefix)
{
    this.tree = tree;
    this.container_id = container_id;
    this.var_name = var_name;
    this.DNSID = DNSID;
    this.prefix = prefix;
    this.img_path = '/design/img/tree/';
    this.icons = {'g' : 'group'};
    this.tool_tmpl = '<a href="#url#" title="#title#" #extra#><img src="#img_path##src#" width="16" height="16"></a>';
    this.tool_new_window = false;
    this.tools = {
        1 : {'url' : 'order.php?id=#id#', 'title' : 'Порядок', 'src' : 'order.gif'},
        2 : {'url' : 'edit.php?id=#id#', 'title' : 'Редактировать', 'src' : 'any_edit.gif'},
        3 : {'url' : 'edit.php?parent_id=#id#', 'title' : 'Добавить', 'src' : 'any_add.gif'},
        4 : {'url' : 'drop.php?id=#id#', 'title' : 'Удалить', 'src' : 'any_del.gif', 'confirm' : 1},
        5 : {'url' : '/admin/admin/?group_id=#id#', 'title' : 'Администраторы', 'src' : 'ind.gif'}
    };
    this.expand = false;
}
AdminGroupCategory_Tree.prototype = new Structure_Tree;

//--------------------------------------------------------------------------------------------------
// BcTree_Tree
//--------------------------------------------------------------------------------------------------
function BcTree_Tree_Node1(id, caption, icon, url, tools)
{
	this.id = id;
	this.caption = caption;
	this.icon = icon;
	this.url = url;
	this.tools = tools;
}
BcTree_Tree_Node.prototype = new Structure_Tree_Node;

function BcTree_Tree1(tree, container_id, var_name, DNSID, prefix)
{
	this.tree = tree;
	this.container_id = container_id;
	this.var_name = var_name;
	this.DNSID = DNSID;
	this.prefix = prefix;
	this.img_path = '/design/img/tree/';
	this.icons = {'g' : 'group'};
	this.tool_tmpl = '<a href="#url#" title="#title#" #extra#><img src="#img_path##src#" width="16" height="16"></a>';
	this.tool_new_window = false;
	this.tools = {
		1 : {'url' : 'order.php?id=#id#', 'title' : 'Порядок', 'src' : 'order.gif'},
		2 : {'url' : 'edit.php?id=#id#', 'title' : 'Редактировать', 'src' : 'any_edit.gif'},
		3 : {'url' : 'edit.php?parent_id=#id#', 'title' : 'Добавить', 'src' : 'any_add.gif'},
		4 : {'url' : 'drop.php?id=#id#', 'title' : 'Удалить', 'src' : 'any_del.gif', 'confirm' : 1},
		5 : {'url' : 'sublist.php?category_id=#id#', 'title' : 'Визитки', 'src' : 'ind.gif'}
	};
	this.expand = false;
}
BcTree_Tree.prototype = new Structure_Tree;

//--------------------------------------------------------------------------------------------------
// FaqCategory_Tree
//--------------------------------------------------------------------------------------------------
function FaqCategory_Tree_Node(id, caption, icon, url, tools)
{
	this.id 	 = id;
	this.caption = caption;
	this.icon    = icon;
	this.url     = url;
	this.tools   = tools;
}
FaqCategory_Tree_Node.prototype = new Structure_Tree_Node;

function FaqCategory_Tree(tree, container_id, var_name, DNSID, prefix)
{
	this.tree = tree;
	this.container_id = container_id;
	this.var_name  = var_name;
	this.DNSID     = DNSID;
	this.prefix    = prefix;
	this.img_path  = '/design/img/tree/';
	this.icons 	   = {'g' : 'group'};
	this.tool_tmpl = '<a href="#url#" title="#title#" #extra#><img src="#img_path##src#" width="16" height="16"></a>';
	this.tool_new_window = false;
	this.tools = {
		1 : {'url' : 'order.php?id=#id#', 'title' : 'Порядок', 'src' : 'order.gif'},
		2 : {'url' : 'edit.php?id=#id#', 'title' : 'Редактировать', 'src' : 'any_edit.gif'},
		3 : {'url' : 'edit.php?parent_id=#id#', 'title' : 'Добавить', 'src' : 'any_add.gif'},
		4 : {'url' : 'drop.php?id=#id#', 'title' : 'Удалить', 'src' : 'any_del.gif', 'confirm' : 1},
		5 : {'url' : '/admin/faq/?category_id=#id#', 'title' : 'Публикации', 'src' : 'ind.gif'},
		6 : {'url' : 'favourite.php?id=#id#', 'title' : 'Вопрос месяца', 'src' : 'any_fav.gif'}
	};
	this.expand = false;
}
FaqCategory_Tree.prototype = new Structure_Tree;

//--------------------------------------------------------------------------------------------------
// PlanCategory_Tree
//--------------------------------------------------------------------------------------------------
function PlanCategory_Tree_Node(id, caption, icon, url, tools)
{
	this.id = id;
	this.caption = caption;
	this.icon = icon;
	this.url = url;
	this.tools = tools;
}
PlanCategory_Tree_Node.prototype = new Structure_Tree_Node;

function PlanCategory_Tree(tree, container_id, var_name, DNSID, prefix)
{
	this.tree = tree;
	this.container_id = container_id;
	this.var_name = var_name;
	this.DNSID = DNSID;
	this.prefix = prefix;
	this.img_path = '/design/img/tree/';
	this.icons = {'g' : 'group'};
	this.tool_tmpl = '<a href="#url#" title="#title#" #extra#><img src="#img_path##src#" width="16" height="16"></a>';
	this.tool_new_window = false;
	this.tools = {
		1 : {'url' : 'order.php?id=#id#', 'title' : 'Порядок', 'src' : 'order.gif'},
		2 : {'url' : 'edit.php?id=#id#', 'title' : 'Редактировать', 'src' : 'any_edit.gif'},
		3 : {'url' : 'edit.php?parent_id=#id#', 'title' : 'Добавить', 'src' : 'any_add.gif'},
		4 : {'url' : 'drop.php?id=#id#', 'title' : 'Удалить', 'src' : 'any_del.gif', 'confirm' : 1},
		5 : {'url' : '/admin/plan/?category_id=#id#', 'title' : 'Планы', 'src' : 'ind.gif'}
	};
	this.expand = false;
}
PlanCategory_Tree.prototype = new Structure_Tree;

//--------------------------------------------------------------------------------------------------
// MeasureCategory_Tree
//--------------------------------------------------------------------------------------------------
function MeasureCategory_Tree_Node(id, caption, icon, url, tools)
{
	this.id = id;
	this.caption = caption;
	this.icon = icon;
	this.url = url;
	this.tools = tools;
}
MeasureCategory_Tree_Node.prototype = new Structure_Tree_Node;

function MeasureCategory_Tree(tree, container_id, var_name, DNSID, prefix)
{
	this.tree = tree;
	this.container_id = container_id;
	this.var_name = var_name;
	this.DNSID = DNSID;
	this.prefix = prefix;
	this.img_path = '/design/img/tree/';
	this.icons = {'g' : 'group'};
	this.tool_tmpl = '<a href="#url#" title="#title#" #extra#><img src="#img_path##src#" width="16" height="16"></a>';
	this.tool_new_window = false;
	this.tools = {
		1 : {'url' : 'order.php?id=#id#', 'title' : 'Порядок', 'src' : 'order.gif'},
		2 : {'url' : 'edit.php?id=#id#', 'title' : 'Редактировать', 'src' : 'any_edit.gif'},
		3 : {'url' : 'edit.php?parent_id=#id#', 'title' : 'Добавить', 'src' : 'any_add.gif'},
		4 : {'url' : 'drop.php?id=#id#', 'title' : 'Удалить', 'src' : 'any_del.gif', 'confirm' : 1},
		5 : {'url' : '/admin/measure/?category_id=#id#', 'title' : 'Мероприятия', 'src' : 'ind.gif'}
	};
	this.expand = false;
}
MeasureCategory_Tree.prototype = new Structure_Tree;

//--------------------------------------------------------------------------------------------------
// ReceptionCategory_Tree
//--------------------------------------------------------------------------------------------------
function ReceptionCategory_Tree_Node(id, caption, icon, url, tools)
{
	this.id = id;
	this.caption = caption;
	this.icon = icon;
	this.url = url;
	this.tools = tools;
}
ReceptionCategory_Tree_Node.prototype = new Structure_Tree_Node;

function ReceptionCategory_Tree(tree, container_id, var_name, DNSID, prefix)
{
	this.tree = tree;
	this.container_id = container_id;
	this.var_name = var_name;
	this.DNSID = DNSID;
	this.prefix = prefix;
	this.img_path = '/design/img/tree/';
	this.icons = {'g' : 'group'};
	this.tool_tmpl = '<a href="#url#" title="#title#" #extra#><img src="#img_path##src#" width="16" height="16"></a>';
	this.tool_new_window = false;
	this.tools = {
		1 : {'url' : 'order.php?id=#id#', 'title' : 'Порядок', 'src' : 'order.gif'},
		2 : {'url' : 'edit.php?id=#id#', 'title' : 'Редактировать', 'src' : 'any_edit.gif'},
		3 : {'url' : 'edit.php?parent_id=#id#', 'title' : 'Добавить', 'src' : 'any_add.gif'},
		4 : {'url' : 'drop.php?id=#id#', 'title' : 'Удалить', 'src' : 'any_del.gif', 'confirm' : 1},
		5 : {'url' : '../reception/?category_id=#id#', 'title' : 'Сообщения', 'src' : 'ind.gif'}
	};
	this.expand = false;
}
ReceptionCategory_Tree.prototype = new Structure_Tree;

//--------------------------------------------------------------------------------------------------
// G2p_FP_Tree
//--------------------------------------------------------------------------------------------------
function G2p_Fp_Tree_Node(id, caption, url)
{
	this.id = id;
	this.caption = caption;
	this.url = url;
}
G2p_Fp_Tree_Node.prototype = new Generic_Tree_Node;

function G2p_Fp_Tree(tree, container_id, var_name, DNSID, prefix)
{
	this.tree = tree;
	this.container_id = container_id;
	this.var_name = var_name;
	this.DNSID = DNSID;
	this.prefix = prefix;
	this.img_path = '/design/img/g2p/';
	this.expand = false;

	this.appendNodeInfo = function(container, node, has_children) {}

	this.createCaption = function(node, has_children)
	{
		var caption = node.caption;

		return node.url == '' ? caption : '<a href="' + node.url + '">' + caption + '</a>';
	}

	this.onec = function(blk_id, node, need_open)
	{
		this.updateSavedTree(blk_id, need_open);
	}

	this.appendPM = function(container, node, has_children)
	{
		var pm_id, pm_src, html = '';

		pm_src = node.level == 1 ? 'li.gif' : 'li2.gif';

		if (has_children)
		{
			pm_id = ' id="' + this.prefix + node.id + '_pm"';
		}
		else
		{
			pm_id = '';
			if (node.level == 1)
				pm_src = 'null.gif';
		}

		html = '<img class="tree-pm" src="' + this.img_path + pm_src + '"' + pm_id + ' border="0" />';

		if (has_children)
			html =
				'<a href="#" onclick="' + this.var_name + '.ec(\'' + this.prefix + node.id +
				'\'); return false;">' + html + '</a>';

		container.innerHTML += html;
	}

	this.out = function(/*tr=this.tree, container_id=this.container_id, level=0*/)
	{
		var tr				= arguments.length > 0 ? arguments[0] : this.tree,
			container_id	= arguments.length > 1 ? arguments[1] : this.container_id,
			table			= document.getElementById(container_id),
			level			= arguments.length > 2 ? arguments[2] : 0;

		for (var n = 0; n < tr.length; n++)
		{
			tr[n].level = level + 1;

			var has_children = (tr[n].children && tr[n].children != null),
				children_container_id = this.prefix + tr[n].id + '_ch',
				row = table.insertRow(-1),
				cell = row.insertCell(-1);

			cell.className = "tree-level-" + Math.min(level, 2);

			// [+] [-]
			this.appendPM(cell, tr[n], has_children);

			// caption
			cell.innerHTML += this.createCaption(tr[n], has_children);

			// область для child-ов
			if (has_children)
			{
				row = table.insertRow(-1);
				var child_cell = row.insertCell(-1);

				child_cell.innerHTML =
					'<table cellspacing="0" cellpadding="0" border="0" width="100%" id="' + children_container_id +
					'" style="display:none"></table>';

				this.onCreateChildArea(children_container_id, tr[n]);
			}

			this.onAfterAppend(tr[n]);
		}
	}
}
G2p_Fp_Tree.prototype = new Generic_Tree;


//--------------------------------------------------------------------------------------------------
// msu_FP_Tree
//--------------------------------------------------------------------------------------------------
function msu_Fp_Tree_Node(id, caption, url)
{
	this.id = id;
	this.caption = caption;
	this.url = url;
}
msu_Fp_Tree_Node.prototype = new Generic_Tree_Node;

function msu_Fp_Tree(tree, container_id, var_name, DNSID, prefix)
{
	this.tree = tree;
	this.container_id = container_id;
	this.var_name = var_name;
	this.DNSID = DNSID;
	this.prefix = prefix;
	this.img_path = '/design/img/msu/';
	this.expand = true;

	this.appendNodeInfo = function(container, node, has_children) {}

	this.createCaption = function(node, has_children)
	{
		var caption = node.caption;

		return node.url == '' ? caption : '<div class="tree-item"><a href="' + node.url + '">' + caption + '</a></div>';
	}

	this.onec = function(blk_id, node, need_open)
	{
		this.updateSavedTree(blk_id, need_open);
	}

	this.appendPM = function(container, node, has_children)
	{
		var pm_id, pm_src, html = '';

		pm_src = node.level == 1 ? 'li.gif' : 'null.gif';

		if (has_children)
		{
			pm_id = ' id="' + this.prefix + node.id + '_pm"';
		}
		else
		{
			pm_id = '';
			if (node.level == 1)
				pm_src = 'null.gif';
		}

		html = '<img class="tree-pm" src="' + this.img_path + pm_src + '"' + pm_id + ' border="0" />';

		if (has_children)
			html =
				'<a href="#" onclick="' + this.var_name + '.ec(\'' + this.prefix + node.id +
				'\'); return false;">' + html + '</a>';

		//html = '<td>' + html + '</td>';

		container.innerHTML += html;
	}

	/*

	this.createCaption = function(node, has_children)
	{
		var caption = node.caption;

		if (has_children)
			caption =
				'<a href="#" onclick="' + this.var_name + '.ec(\'' + this.prefix + node.id + '\'); return false;">' +
				caption + '</a>';

		return caption;
	}*/

	this.out = function(/*tr=this.tree, container_id=this.container_id, level=0*/)
	{
		var tr				= arguments.length > 0 ? arguments[0] : this.tree,
			container_id	= arguments.length > 1 ? arguments[1] : this.container_id,
			table			= document.getElementById(container_id),
			level			= arguments.length > 2 ? arguments[2] : 0;

		for (var n = 0; n < tr.length; n++)
		{
			tr[n].level = level + 1;

			var has_children = (tr[n].children && tr[n].children != null),
				children_container_id = this.prefix + tr[n].id + '_ch',
				row = table.insertRow(-1),
				cell = row.insertCell(-1);

			cell.className = "tree-level-" + Math.min(level, 2);

			// [+] [-]
			this.appendPM(cell, tr[n], has_children);

			// caption
			cell.innerHTML += this.createCaption(tr[n], has_children);

			// область для child-ов
			if (has_children)
			{
				row = table.insertRow(-1);
				var child_cell = row.insertCell(-1);

				child_cell.innerHTML =
					'<table cellspacing="0" cellpadding="0" border="0" width="100%" id="' + children_container_id +
					'" style="display:none"></table>';

				this.onCreateChildArea(children_container_id, tr[n]);
			}

			this.onAfterAppend(tr[n]);
		}
	}
}
msu_Fp_Tree.prototype = new Generic_Tree;

//--------------------------------------------------------------------------------------------------
// Culture_FP_Tree
//--------------------------------------------------------------------------------------------------
function Culture_FP_Tree_Node(id, caption, icon, url, tools)
{
	this.id = id;
	this.caption = caption;
	this.icon = icon;
	this.url = url;
	this.tools = tools;
}
Culture_FP_Tree_Node.prototype = new Generic_Tree_Node;

function Culture_FP_Tree(tree, container_id, var_name, DNSID, prefix)
{
	this.tree = tree;
	this.container_id = container_id;
	this.var_name = var_name;
	this.DNSID = DNSID;
	this.prefix = prefix;
	this.img_path = '/design/img/culture/fp-tree/';
	this.icons = {'g' : 'group'};
	this.tool_tmpl = '<a href="#url#" title="#title#" #extra#><img src="#img_path##src#" width="16" height="16"></a>';
	this.tool_new_window = false;
	this.tools = {};
	this.expand = false;

	this.appendIcon = function(container, node) {}

	this.appendNodeInfo = function(container, node, has_children) {}

	this.createCaption = function(node, has_children)
	{
		var caption = node.caption;

		return node.url == '' ? caption : '<a href="' + node.url + '">' + caption + '</a>';
	}

	this.onec = function(blk_id, node, need_open)
	{
		this.updateSavedTree(blk_id, need_open);
	}

	this.getPmSrc = function(node, need_open)
	{
		return this.img_path + (need_open ? 'minus' : 'plus') + (node.level == 1 ? '0' : '') + '.gif';
	}

	this.appendPM = function(container, node, has_children)
	{
		if (node.level > 2)
			return;

		var pm_id, pm_src, html = '';

		if (has_children)
		{
			pm_id = ' id="' + this.prefix + node.id + '_pm"';
			pm_src = node.level == 1 ? 'plus0.gif' : 'plus.gif';
		}
		else
		{
			pm_id = '';
			pm_src = node.level == 1 ? 'null0.gif' : 'null.gif';
		}

		html = '<img class="tree-pm' + (node.level == 1 ? '-0' : '') + '" src="' + this.img_path + pm_src + '"' + pm_id + ' />';

		if (has_children)
			html =
				'<a href="#" onclick="' + this.var_name + '.ec(\'' + this.prefix + node.id +
				'\'); return false;">' + html + '</a>';

		container.innerHTML += html;
	}

	this.out = function(/*tr=this.tree, container_id=this.container_id, level=0*/)
	{
		var tr				= arguments.length > 0 ? arguments[0] : this.tree,
			container_id	= arguments.length > 1 ? arguments[1] : this.container_id,
			table			= document.getElementById(container_id),
			level			= arguments.length > 2 ? arguments[2] : 0;

		for (var n = 0; n < tr.length; n++)
		{
			tr[n].level = level + 1;

			var has_children = (tr[n].children && tr[n].children != null),
				children_container_id = this.prefix + tr[n].id + '_ch',
				row = table.insertRow(-1),
				cell = row.insertCell(-1);

			cell.className = "tree-level-" + Math.min(level, 2);

			// [+] [-]
			this.appendPM(cell, tr[n], has_children);

			// caption
			cell.innerHTML += this.createCaption(tr[n], has_children);

			// область для child-ов
			if (has_children)
			{
				row = table.insertRow(-1);
				var child_cell = row.insertCell(-1);

				child_cell.innerHTML =
					'<table cellspacing="0" cellpadding="0" border="0" width="100%" id="' + children_container_id +
					'" style="display:none"></table>';

				this.onCreateChildArea(children_container_id, tr[n]);
			}

			this.onAfterAppend(tr[n]);
		}
	}
}
Culture_FP_Tree.prototype = new Generic_Tree;

//--------------------------------------------------------------------------------------------------
// ScenarioCategory_Tree
//--------------------------------------------------------------------------------------------------
function ScenarioCategory_Tree_Node(id, caption, icon, url, tools)
{
	this.id = id;
	this.caption = caption;
	this.icon = icon;
	this.url = url;
	this.tools = tools;
}
ScenarioCategory_Tree_Node.prototype = new Structure_Tree_Node;

function ScenarioCategory_Tree(tree, container_id, var_name, DNSID, prefix)
{
	this.tree = tree;
	this.container_id = container_id;
	this.var_name = var_name;
	this.DNSID = DNSID;
	this.prefix = prefix;
	this.img_path = '/design/img/tree/';
	this.icons = {'g' : 'group'};
	this.tool_tmpl = '<a href="#url#" title="#title#" #extra#><img src="#img_path##src#" width="16" height="16"></a>';
	this.tool_new_window = false;
	this.tools = {
		1 : {'url' : 'order.php?id=#id#', 'title' : 'Порядок', 'src' : 'order.gif'},
		2 : {'url' : 'edit.php?id=#id#', 'title' : 'Редактировать', 'src' : 'any_edit.gif'},
		3 : {'url' : 'edit.php?parent_id=#id#', 'title' : 'Добавить', 'src' : 'any_add.gif'},
		4 : {'url' : 'drop.php?id=#id#', 'title' : 'Удалить', 'src' : 'any_del.gif', 'confirm' : 1},
		5 : {'url' : '../scenario/?category_id=#id#', 'title' : 'Сценарии', 'src' : 'ind.gif'}
	};
	this.expand = false;
}
ScenarioCategory_Tree.prototype = new Structure_Tree;

//--------------------------------------------------------------------------------------------------
// CardCategory_Tree
//--------------------------------------------------------------------------------------------------
function CardCategory_Tree_Node(id, caption, icon, url, tools)
{
	this.id = id;
	this.caption = caption;
	this.icon = icon;
	this.url = url;
	this.tools = tools;
}
CardCategory_Tree_Node.prototype = new Structure_Tree_Node;

function CardCategory_Tree(tree, container_id, var_name, DNSID, prefix)
{
	this.tree = tree;
	this.container_id = container_id;
	this.var_name = var_name;
	this.DNSID = DNSID;
	this.prefix = prefix;
	this.img_path = '/design/img/tree/';
	this.icons = {'g' : 'group'};
	this.tool_tmpl = '<a href="#url#" title="#title#" #extra#><img src="#img_path##src#" width="16" height="16"></a>';
	this.tool_new_window = false;
	this.tools = {
		1 : {'url' : 'order.php?id=#id#', 'title' : 'Порядок', 'src' : 'order.gif'},
		2 : {'url' : 'edit.php?id=#id#', 'title' : 'Редактировать', 'src' : 'any_edit.gif'},
		3 : {'url' : 'edit.php?parent_id=#id#', 'title' : 'Добавить', 'src' : 'any_add.gif'},
		4 : {'url' : 'drop.php?id=#id#', 'title' : 'Удалить', 'src' : 'any_del.gif', 'confirm' : 1},
		5 : {'url' : '../card/?category_id=#id#', 'title' : 'Формуляры', 'src' : 'ind.gif'}
	};
	this.expand = false;
}
CardCategory_Tree.prototype = new Structure_Tree;


//--------------------------------------------------------------------------------------------------
// Persons_Export_Tree
//--------------------------------------------------------------------------------------------------
function Persons_Export_Tree_Node(id, caption, icon)
{
	this.id = id;
	this.caption = caption;
	this.icon = icon;
}
Persons_Export_Tree_Node.prototype = new Generic_Tree_Node;

function Persons_Export_Tree(tree, container_id, var_name, DNSID, prefix)
{
	this.tree = tree;
	this.container_id = container_id;
	this.var_name = var_name;
	this.DNSID = DNSID;
	this.prefix = prefix;
	this.img_path = '/design/img/tree/';
	this.icons = {'g' : 'group'};

	this.expand = false;

	this.getIconSrc = function(icon_id/*, open = false*/)
	{
		var open = arguments.length > 1 ? arguments[1] : false;
		return this.img_path + this.icons[icon_id] + (open ? '_open' : '') + '.gif';
	}

	this.appendNodeInfo = function(container, node, has_children)
	{
		if (node.icon == 'dl')
		{
			container.style.backgroundImage = 'url(' + this.img_path + 'dash.gif)';
			container.style.backgroundRepeat = 'repeat-x';
			container.style.backgroundPosition = 'center';
			return;
		}

		var html = '<input onclick="' + this.var_name + '.metka('+node.id+', ts)" id="ch_' + node.id + '" type="checkbox"><span class="tree-level-' + Math.min(node.level, 2) + '">' + this.createCaption(node, has_children) + '</span>';

		container.innerHTML = html;
	}

	this.onec = function(blk_id, node, need_open)
	{
		this.updateSavedTree(blk_id, need_open);
	}

	this.createCaption = function(node, has_children)
	{
		var caption = node.caption;

		if (has_children)
			caption =
				'<a href="#" onclick="' + this.var_name + '.ec(\'' + this.prefix + node.id + '\'); return false;">' +
				caption + '</a>';

		return caption;
	}

	this.ec = function(blk_id/*, node = null*/)
	{
		var blk			= document.getElementById(blk_id + '_ch'),
			need_open	= blk.style.display == 'none',
			node 		= arguments.length > 1 ? arguments[1] : this.lookup(this.removePrefix(blk_id));

		if (need_open && !node.onscreen)
		{
			node.onscreen = true;
			this.out(node.children, blk_id + '_ch', node.level);
		}

		blk.style.display = need_open ? 'block' : 'none';

		var pm = document.getElementById(blk_id + '_pm');
		if (pm)
		{
			pm.src = this.getPmSrc(node, need_open)
		}

		this.onec(blk_id, node, need_open);

		obj1 = document.getElementById(blk_id + '_pm');
		ss = obj1.src;
		s = obj1.src.substr(ss.length - 8, 8);
        if (s == 'inus.gif')
        {
			obj2 = document.getElementById('ch_' + blk_id);
			if ((obj2.style.background != 'gray') && (obj2.style.background != '#808080'))
				this.metka(blk_id, ts);
		};
	}

    var struc = new Array();

	this.formir_struc = function(node, par)
	{
		if (node)
			for (i in node)
			{
				struc[node[i].id] = node[i];
				struc[node[i].id]['parent'] = par;
				if (node[i].children) this.formir_struc(node[i].children, node[i]);
			};
	}

	this.formir_struc(ts);
    this.metka1 = function(id,node)
	{
		ch =! document.getElementById('ch_'+id).checked;
		this.r_metka(id,node,ch);
		if (!ch) this.del_parents(id,node);
		else this.check_add_parents(id,node);
	}


	this.metka = function(id, node)
	{
		ch = document.getElementById('ch_'+id).checked;
		this.r_metka(id, node, ch);
		if (!ch) this.del_parents(id,node);
		else this.check_add_parents(id,node);
	}

	this.del_parents = function(id,node)
	{
		par = struc[id]['parent'];
		if (par)
		{
			obj1 = document.getElementById('ch_'+par.id)
			obj1.checked = false;
			b=false;
			for (i in par.children)
			{
				obj = document.getElementById('ch_' + par.children[i].id)
				b = b || (obj.checked);
				b = b || (obj.style.background == 'gray')||(obj.style.background=='#808080');
			}

			if (b) obj1.style.background='gray'; else obj1.style.background='';
			this.del_parents(par.id,node);
		}
	}

	this.check_all = function(node)
	{
		for (i in node)	this.r_metka(node[i].id,node,true);
	}

	this.uncheck_all = function(node)
	{
		for (i in node)	this.r_metka(node[i].id,node,false);
	}

	this.check_add_parents = function(id,node)
	{
		par = struc[id]['parent'];
		if (par)
		{
			b = true;
			b1 = false;
			for (i in par.children)
			{
				obj = document.getElementById('ch_'+par.children[i].id);
				b = b && obj.checked;
				b1 = b1 || obj.checked;
				b1 = b1 || (obj.style.background == 'gray') || (obj.style.background == '#808080');
			}
			obj1 = document.getElementById('ch_'+par.id);
			if (b)
			{
				obj1.checked = true;
				obj1.style.background = '';
			} else if (b1) obj1.style.background = 'gray';
			this.check_add_parents(par.id,node);
		};
	}

	this.r_metka = function(id,node,ch)
	{
		obj = document.getElementById('ch_' + id);
		b = true;
		obj1 = document.getElementById(id + '_pm');
		if (obj1)
		{
			ss = obj1.src;
			s = obj1.src.substr(ss.length - 8, 8);
       		if (s == 'plus.gif') b = false;
		};
		if (obj)
		{
			obj.checked = ch;
			obj.style.background = '';
			if (b)
			{
				temp = struc[id];
				this.r_metka_ch(temp.children,ch);
			}
		}
	}

	this.r_metka_ch = function(node, ch)
	{
		if (node) for (i in node)
		{
			this.r_metka(node[i].id, node,ch);
		};
	}

}
Persons_Export_Tree.prototype = new Generic_Tree;

//--------------------------------------------------------------------------------------------------
// Gmap_Object_Category_Tree
//--------------------------------------------------------------------------------------------------
function Gmap_Object_Category_Tree_Node(id, caption, icon, tools)
{
	this.id = id;
	this.caption = caption;
	this.icon = icon;
	this.tools = tools;
}
Gmap_Object_Category_Tree_Node.prototype = new Generic_Tree_Node;

function Gmap_Object_Category_Tree(tree, container_id, var_name, DNSID, prefix)
{
	this.tree = tree;
	this.container_id = container_id;
	this.var_name = var_name;
	this.DNSID = DNSID;
	this.prefix = prefix;
	this.img_path = '/design/img/tree/';
	this.icons = {'g' : 'group'};
	this.tool_tmpl = '<a href="#url#" title="#title#" #extra#><img src="#img_path##src#" width="16" height="16"></a>';
	this.tool_new_window = false;
	this.tools = {
		1 : {'url' : 'order.php?id=#id#', 'title' : 'Порядок', 'src' : 'order.gif'},
		2 : {'url' : 'edit.php?id=#id#', 'title' : 'Редактировать', 'src' : 'any_edit.gif'},
		3 : {'url' : 'edit.php?parent_id=#id#', 'title' : 'Добавить', 'src' : 'any_add.gif'},
		4 : {'url' : 'drop.php?id=#id#', 'title' : 'Удалить', 'src' : 'any_del.gif', 'confirm' : 1},
		5 : {'url' : '../structure_banner/?structure_id=#id#', 'title' : 'Баннеры', 'src' : 'ico_img.gif'},
		6 : {'url' : '../gmap_object_type/?category_id=#id#', 'title' : 'Типы объектов', 'src' : 'ind.gif'},
		7 : {'url' : '../gmap_object/?category_id=#id#', 'title' : 'Объекты', 'src' : 'ind.gif'}
	};
	this.expand = false;

	this.getIconSrc = function(icon_id/*, open = false*/)
	{
		var open = arguments.length > 1 ? arguments[1] : false;
		return this.img_path + this.icons[icon_id] + (open ? '_open' : '') + '.gif';
	}

	this.makeTool = function(node, params)
	{
		var p = {},
			url_params = {'DNSID' : this.DNSID, 'id' : node.id};

		this.cloneHash(params, p);

		p['url'] = this.mySprintf(p['url'], url_params);
		p['extra'] = this.tool_new_window ? 'target="_blank"' : '';

		if (p['confirm'])
		{
			if (p['extra'])
				p['extra'] += ' '

			p['extra'] += 'onClick="return confirm(\'Вы уверены?\')"'

			p['confirm'] = null;
		}

		p['img_path'] = this.img_path;

		return this.mySprintf(this.tool_tmpl, p);
	}

	this.appendIcon = function(container, node)
	{
		container.innerHTML =
			'<img src="' + this.getIconSrc(node.icon) + '" class="tree-icon" id="' + this.prefix + node.id + '_icon" />';
	}

	this.appendNodeInfo = function(container, node, has_children)
	{
		if (node.icon == 'dl')
		{
			container.style.backgroundImage = 'url(' + this.img_path + 'dash.gif)';
			container.style.backgroundRepeat = 'repeat-x';
			container.style.backgroundPosition = 'center';
			return;
		}

		var html = '<span class="tree-level-' + Math.min(node.level, 2) + '">' + this.createCaption(node, has_children) + '</span>';

		// tools
		var tools = '';
		for (var n = 0; n < node.tools.length; n++)
		{
			var tool = this.tools[node.tools[n]];

			if (tool)
				tools += '&nbsp;' + this.makeTool(node, tool);
		}
		if (tools)
			html += tools;

		container.innerHTML = html;
	}

	this.onec = function(blk_id, node, need_open)
	{
		document.getElementById(blk_id + '_icon').src = this.getIconSrc(node.icon, need_open);
		this.updateSavedTree(blk_id, need_open);
	}
}
Gmap_Object_Category_Tree.prototype = new Generic_Tree;

