var result;
var last_sel_xcid = "";
var cur_edited_menu_lang = 0;
function FIND(item) {
	if (document.all) return(document.all[item]);
	if (document.getElementById) return(document.getElementById(item));
	return(false);
}


function on_close_win()
{
	result = false;
}

function getCookieVal( offset )
{
    var endstr = document.cookie.indexOf (";", offset);

    if (endstr == -1)
        endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
}


function getcookie (name)
{
    var arg  = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i    = 0;

    while (i < clen)
    {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg)
          return getCookieVal (j);
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break;
    }
    return "";
}


function DeleteCookie (name)
{
    var exp  = new Date();
    var cval = getcookie (name);

    exp.setTime (exp.getTime() - 1);  // This cookie is history
    document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}



function cl_chek1(el)
{
	flag = el.checked;
	ItemValue = 0;
	if(flag) ItemValue = 1;
	for(i=0;i<document.ftreeadmin.elements.length;i++)
	{
		if(document.ftreeadmin.elements[i].name.indexOf(el.value)==0)
		{
			id = document.ftreeadmin.elements[i].value;
			document.ftreeadmin.elements['itemdel['+id+']'].value = ItemValue;
			document.ftreeadmin.elements['msgdel['+id+']'].checked = flag;
			document.ftreeadmin.elements['msgdel['+id+']'].disabled = flag;
		}
	}
	el.disabled = false;
}

function cl_disc_ch(id,full_str,gr_num)
{
	document.fdiscount.temp_porog.value = gr_num;
	document.fdiscount.temp_id.value = id;
	document.fdiscount.temp_full_str.value = full_str;
	for(i=0;i<document.fdiscount.elements.length;i++)
	{
		if(document.fdiscount.elements[i].name.indexOf('item_'+full_str)==0)
		{
			document.fdiscount.elements[i].checked = true;
		}
	}
}

function set_new_val()
{
	if(document.fdiscount.temp_id.value != "-1")
	{
		full_str = document.fdiscount.temp_full_str.value;
		id = document.fdiscount.temp_id.value;
		gr_num = document.fdiscount.temp_porog.value;
		temp_val = document.fdiscount.elements['dis['+id+']['+gr_num+']'].value;
		for(i=0;i<document.fdiscount.elements.length;i++)
		{
			if(document.fdiscount.elements[i].name.indexOf('item_'+full_str)==0 && document.fdiscount.elements[i].checked==true)
			{
				document.fdiscount.elements[i].checked = false;
				id_el = document.fdiscount.elements[i].value;
				document.fdiscount.elements['dis['+id_el+']['+gr_num+']'].value = temp_val;
			}
		}
	}
	document.fdiscount.temp_porog.value = "-1";
	document.fdiscount.temp_id.value = "-1";
	document.fdiscount.temp_full_str.value = "-1";
}

function add_el_list(cid,ctype,xcid,el_id)
{
	if (result) result.close();
	left_pos = (screen.width - 460)/2;
	top_pos = (screen.height - 380)/2;
	eval("result=window.open('/admin/popup/add_connect_el/'+cid+'/'+ctype+'/'+xcid+'/'+el_id+'/','Addnewelement','resizable=no,menubar=no,status=no,scrollbars=yes,width=460,height=380,left="+left_pos+",top="+top_pos+"')");
	result.focus();
}


function add_el_list_top(cid,ctype,xcid,el_id)
{
	if (result) result.close();
	left_pos = (screen.width - 460)/2;
	top_pos = (screen.height - 380)/2;
	eval("result=window.open('/admin/popup/add_connect_el_top/'+cid+'/'+ctype+'/'+xcid+'/'+el_id+'/','Addnewelement','resizable=no,menubar=no,status=no,scrollbars=yes,width=460,height=380,left="+left_pos+",top="+top_pos+"')");
	result.focus();
}


function add_el_list_con_publ(el_id)
{
	if (result) result.close();
	left_pos = (screen.width - 460)/2;
	top_pos = (screen.height - 380)/2;
	eval("result=window.open('/admin/popup/add_connect_publ/'+el_id+'/','Addnewpubl','resizable=no,menubar=no,status=no,scrollbars=yes,width=460,height=380,left="+left_pos+",top="+top_pos+"')");
	result.focus();
}
function del_el_listcat(el_inp)
{
	var div_mas = new Array();
	var temp_val1 = '';
	for(var i=0;i<document.all.tags('div').length;i++)
	{
		div_mas[document.all.tags('div')[i].id] = document.all.tags('div')[i];
	}
	for(i=0;i<document.Article.elements.length;i++)
	{
		if(document.Article.elements[i].name=="f"+el_inp) main_inp = document.Article.elements[i];
		if(document.Article.elements[i].name.indexOf('del_el_')==0)
		{
			del_el_id = document.Article.elements[i].value;
			if(document.Article.elements[i].checked==true)
			{
				div_mas[del_el_id].style.display="none";
			}
			else
			{
				temp_val1 += ':' + del_el_id + ':';
			}
		}
	}
	main_inp.value = temp_val1;
}

function insert_into_list(el_id,el_name,el_inp)
{
	eval("el_inp_val = document.Article.f"+el_inp+".value");
	for(var i=0;i<document.all.tags('div').length;i++)
	{
		if(document.all.tags('div')[i].name=="maindiv") maindiv_el = document.all.tags('div')[i];
	}
	if(el_inp_val.indexOf(':'+el_id+':')==-1)
	{
		temp_text = "<div name=div_el_"+el_id+" id="+el_id+">";
		temp_text += "<table cellpadding=2 cellpadding=2 border=0 width=500>";
		temp_text += "<tr bgcolor=#eeeeee><td class=nav>"+el_name+"</td>";
		temp_text += "<td width=100 align=center><input type=checkbox name=del_el_"+el_id+" value="+el_id+" class=search></td>";
		temp_text += "</tr></table></div>";
		maindiv_el.innerHTML = temp_text+maindiv_el.innerHTML;
		eval("document.Article.f"+el_inp+".value = '"+el_inp_val+":"+el_id+":'");
	}
}


function insert_into_list_group(id,name,mode)
{
	if (mode==1)
	{
		for(var i=0;i<document.all.tags('div').length;i++)
		{
			if(document.all.tags('div')[i].name==("div_"+id)) 
			{maindiv_el = document.all.tags('div')[i];}
		}
		if(maindiv_el.innerHTML.indexOf(name)==-1)
		{
			temp_text = "<div>"+name+"</div>";
			maindiv_el.innerHTML = maindiv_el.innerHTML+temp_text;
		}
	}
	
	if (mode ==-1)
	{

		for(var i=0;i<document.all.tags('div').length;i++)
		{
			if(document.all.tags('div')[i].name==("div_"+id)) 
			{maindiv_el = document.all.tags('div')[i];}
		}
		maindiv_el.innerHTML = "";
/*
		if(maindiv_el.innerHTML.indexOf(name)!=-1)
		{
			temp_text = name;
			re = new RegExp(temp_text,"g");
			maindiv_el.innerHTML = maindiv_el.innerHTML.replace(re,"");
		}
*/
	}
}


function insert_into_list_top(el_id,el_name,el_inp)
{
	eval("el_inp_val = document.Article.f"+el_inp+".value");
	for(var i=0;i<document.all.tags('div').length;i++)
	{
		if(document.all.tags('div')[i].name=="maindiv") maindiv_el = document.all.tags('div')[i];
	}
	if(el_inp_val.indexOf(':'+el_id+':')==-1)
	{
		temp_text = "<div name=div_el_"+el_id+" id="+el_id+">";
		temp_text += "<table cellpadding=2 cellpadding=2 border=0 width=500>";
		temp_text += "<tr bgcolor=#eeeeee><td class=nav>"+el_name+"</td>";
		temp_text += "<td width=100 align=center><input type=checkbox name=del_el_"+el_id+" value="+el_id+" class=search></td>";
		temp_text += "</tr></table></div>";
		maindiv_el.innerHTML = temp_text+maindiv_el.innerHTML;
		eval("document.Article.f"+el_inp+".value = '"+el_inp_val+":"+el_id+":'");
	}
}



function open_help(help_url)
{
	if (result) result.close();
	left_pos = (screen.width - 878)/2;
	top_pos = (screen.height - 555)/2;
	eval("result=window.open('"+help_url+"','Help_System','resizable=no,menubar=no,status=yes,scrollbars=yes,width=878,height=555,left="+left_pos+",top="+top_pos+"')");
	result.focus();
}

function SetCookie(sName, sValue)
{
  document.cookie = sName + "=" + escape(sValue) + "; expires=Tue, 14 Dec 2010 23:59:59 GMT; path=/;";
}

function cms_nav_off(name)
{ 
	if (name != cur_fix_menu)
		if(document.images[name] != null) document.images[name].src = '/img/admin/left/icon1.gif';
}
function cms_nav_on(name)
{
	if(document.images[name] != null) document.images[name].src = '/img/admin/left/icon2.gif';
}
function cms_nav_fix(name)
{ 
	old_fix = cur_fix_menu;
	cur_fix_menu = name;
	if(old_fix != '' && name != old_fix) cms_nav_off(old_fix);
}


function open_menu_items(id){
	if (FIND('admin_menu' + id).style.display == 'none')
	{ 
		nstr = getcookie('admin_menu_off');
		var re = new RegExp(":"+id+":", "g"); 
		nstr = nstr.replace(re,"");
		SetCookie('admin_menu_off', nstr);
		FIND('admin_menu' + id).style.display = 'block'; 
	}
	else 
	{
		nstr = getcookie('admin_menu_off') + ":" + id + ":";
		SetCookie('admin_menu_off', nstr);
		FIND('admin_menu' + id).style.display = 'none';
	}
//	alert(nstr);
}


function go_throw_menu(id, m_op)
{
	var top_el = window.event.srcElement;
	
	
	if (id != '' && m_op != 2) 
	{
		el_top_pos = FIND('parent_table_' + id).offsetTop + FIND('top_table_' + id).parentElement.offsetTop;
		el_left_pos = FIND('parent_table_' + id).offsetLeft + FIND('top_table_' + id).parentElement.offsetLeft + FIND('parent_table_' + id).clientWidth - 2;
//		alert (el_top_pos);
	}
//	alert ( el_top_pos + ' ' + top_el.tagName + ' ' + top_el.offsetLeft);
	if (m_op == 1)
	{
		if (id != '' && FIND('top_menu_' + id).style.top < 1 && FIND('top_menu_' + id).style.left < 1)
		{
			FIND('top_menu_' + id).style.top = el_top_pos;
			FIND('top_menu_' + id).style.left =  el_left_pos;
		}
		if (id != '')
		{
			tmp_counter = open_menus_id.length - 1;
			to_level = FIND('parent_table_' + id).getAttribute('menu_level');
			while (tmp_counter > (to_level - 1))
			{
//				alert(tmp_counter + ' ' + open_menus_id + ' ' + 'top_menu_' + open_menus_id[tmp_counter]);
				if (FIND('top_menu_' + open_menus_id[tmp_counter]))
				{
					FIND('top_menu_' + open_menus_id[tmp_counter]).style.display = 'none';
				}
				delete(open_menus_id[tmp_counter]);
				tmp_counter--;
			}
			open_menus_id[to_level] = id;
		}
		FIND('top_menu_' + id).style.display = 'block';
	}
	else if (m_op == 0) 
	{
		FIND('top_menu_' + id).style.display = 'none';
	}
	else if (m_op == 2)
	{
		if (id != 0)
		{
			tmp_counter = open_menus_id.length - 1;
			to_level = FIND('parent_table_' + id).getAttribute('menu_level');
//			alert (tmp_counter + ' ' + to_level);
			while (tmp_counter > to_level - 1)
			{
				if (FIND('top_menu_' + open_menus_id[tmp_counter]))
				{
					FIND('top_menu_' + open_menus_id[tmp_counter]).style.display = 'none';
				}
				delete(open_menus_id[tmp_counter]);
				tmp_counter--;
			}
//			open_menus_id[to_level] = id;
		}
	}
}

function set_throw_menu(m_set)
{
	cur_top_menu_open = m_set;
}

function cms_menu_context(mid, mtype, cid, parent)
{
// (FIND('menu_context']);
	FIND('menu_context').style.left = document.body.scrollLeft + this.event.clientX - 5;
	FIND('menu_context').style.top = document.body.scrollTop + this.event.clientY - 5;
	s_content = FIND('pre_menu_cont_top').innerHTML;
	if(mtype == 4 && cid>0) s_content += FIND('pre_menu_cont_m2').innerHTML;
	if(mtype == 0 || mtype == 3 || mtype == 4) s_content += FIND('pre_menu_cont_m1').innerHTML;
	if(mtype == 1) s_content += FIND('pre_menu_cont_m3').innerHTML;
	if(mtype == 4) 	s_content += FIND('pre_menu_cont_m4').innerHTML;
	s_content += FIND('pre_menu_cont_bot').innerHTML;
	re = new RegExp("set__mid","g");
	new_content = s_content.replace(re,mid);
	re = new RegExp("set_parent","g");
	new_content = new_content.replace(re,parent);
	re = new RegExp("set__cid","g");
	new_content = new_content.replace(re,cid);
//	FIND('menu_context'].innerHTML = new_content;


	var okPopup = window.createPopup();
	okPopup.document.createStyleSheet('/styles/stylesadmin.css');
	okPopup.document.body.style.backgroundImage = "url('/img/all_bg.gif')";
	okPopup.document.body.innerHTML = new_content;
	okPopup.show(0, 0, 210, 0);
    var realHeight = okPopup.document.body.scrollHeight;
    okPopup.hide();
	okPopup.show(0, 0, 210, realHeight, event.srcElement);

	
//	FIND('menu_context'].style.display = 'block';
//	this.event.returnValue = false;
}


function cms_menu_cat_context(cid)
{
	FIND('menu_context').style.left = document.body.scrollLeft + this.event.clientX - 5;
	FIND('menu_context').style.top = document.body.scrollTop + this.event.clientY - 5;
	s_content = FIND('pre_menu_cont').innerHTML;
	re = new RegExp("set__cid","g");
	new_content = s_content.replace(re,cid);
	FIND('menu_context').innerHTML = new_content;
	FIND('menu_context').style.display = 'block';
	this.event.returnValue = false;
}

function cms_menu_click()
{
	FIND('menu_context').style.display="none";
}

function show_left_menu()
{
	if (parent.FIND('cms_all_menu').style.width == '1px')
	{
//		parent.FIND('cms_all_menu').style.show_left_menu = 'block';
//		parent.FIND('cms_all_menu').parentNode.width = "190";
		parent.FIND('cms_all_menu').style.width = '190px';
		parent.FIND('cms_menu_frame').style.width = '190px';

		cms_left_menu_button.src = '/img/admin/icon/back2_ic.gif';
		SetCookie('admin_menu_hide' , 0);
	}
	else
	{
//		parent.FIND('cms_all_menu').style.display = 'none';
		parent.FIND('cms_all_menu').style.width = '1px';
		parent.FIND('cms_menu_frame').style.width = '1px';
//		parent.FIND('cms_all_menu').parentNode.width = "20";
		FIND('cms_left_menu_button').src = '/img/admin/icon/forward2_ic.gif';
		SetCookie('admin_menu_hide' , 1);
	}
}

function cms_content_list_sel()
{
	var tmp_counter = 0;
	while (FIND('op_all_' + tmp_counter))
	{
		if (FIND('op_all_' + tmp_counter).checked == true)
			FIND('op_all_' + tmp_counter).checked = false;
		else
			FIND('op_all_' + tmp_counter).checked = true;
		tmp_counter++;
	}
}


function cms_menu_show_razd(id)
{
	if (FIND('cms_left_menu_tree_m_' + id) && FIND('cms_left_menu_tree_m_' + id).firstChild.innerHTML != '')
	{
		if (FIND('cms_left_menu_tree_m_' + id).style.display == 'block')
		{
			FIND('cms_left_menu_tree_m_' + id).style.display = 'none';
//			SetCookie('admin_menu_cat_on[' + id + ']', 0);
			nstr = getcookie('openm');
			var re = new RegExp(":"+id+":", "g"); 
			nstr = nstr.replace(re,"");
			DeleteCookie('openm');			
			SetCookie('openm', nstr);
		}
		else
		{
			FIND('cms_left_menu_tree_m_' + id).style.display = 'block';
//			SetCookie('admin_menu_cat_on[' + id + ']', 1);
			str = getcookie('openm');
			DeleteCookie('openm');			
			
			str = str+":" + id + ":";
			SetCookie('openm', str);
		}
	}
}



function cms_menu_show_cat(id)
{
	if (FIND('cms_left_menu_tree_' + id) && FIND('cms_left_menu_tree_' + id).firstChild.innerHTML != '')
	{
		if (FIND('cms_left_menu_tree_' + id).style.display == 'block')
		{
			FIND('cms_left_menu_tree_' + id).style.display = 'none';
//			SetCookie('admin_menu_cat_on[' + id + ']', 0);

			nstr = getcookie('open');
			var re = new RegExp(":"+id+":", "g"); 
			nstr = nstr.replace(re,"");
			DeleteCookie('open');			
			SetCookie('open', nstr);
		}
		else
		{
			FIND('cms_left_menu_tree_' + id).style.display = 'block';
//			SetCookie('admin_menu_cat_on[' + id + ']', 1);

			str = getcookie('open');
			DeleteCookie('open');			
			
			str = str+":" + id + ":";
			SetCookie('open', str);

		}
	}

}




function cms_menu_show_xcid_2(id, cid)
{
	
	if (top.cms_menu_frame.FIND('cms_left_menu_cat_tree_' + id))
	{
		
			top.cms_menu_frame.FIND('cms_left_menu_cat_tree_' + id).style.display = 'block';
//			SetCookie('admin_menu_subtree_on[' + id + ']', 1);
			
			str = getcookie('openx');
			DeleteCookie('openx');			
			str = str+":" + id + ":";
			SetCookie('openx', str);

		
	}
	
	id = cid;

	if (top.cms_menu_frame.FIND('cms_left_menu_tree_' + id) && top.cms_menu_frame.FIND('cms_left_menu_tree_' + id).firstChild.innerHTML != '')
	{
			top.cms_menu_frame.FIND('cms_left_menu_tree_' + id).style.display = 'block';
//			SetCookie('admin_menu_cat_on[' + id + ']', 1);
			str = getcookie('open');
			DeleteCookie('open');			
			str = str+":" + id + ":";
			SetCookie('open', str);
	}
}



function cms_menu_show_xcid(id)
{
	if (FIND('cms_left_menu_cat_tree_' + id))
	{
		if (FIND('cms_left_menu_cat_tree_' + id).style.display == 'block')
		{
			FIND('cms_left_menu_cat_tree_' + id).style.display = 'none';
//			SetCookie('admin_menu_subtree_on[' + id + ']', 0);

			nstr = getcookie('openx');
			var re = new RegExp(":"+id+":", "g"); 
			nstr = nstr.replace(re,"");
			
			DeleteCookie('openx');			
			SetCookie('openx', nstr);
		}
		else
		{
			FIND('cms_left_menu_cat_tree_' + id).style.display = 'block';
//			SetCookie('admin_menu_subtree_on[' + id + ']', 1);
			
			str = getcookie('openx');
			DeleteCookie('openx');			
			str = str+":" + id + ":";
			SetCookie('openx', str);

		}
	}
}

function cms_left_menu_sel_xcid()
{
	if (last_sel_xcid != "" && document.all[last_sel_xcid])
	{
		document.all[last_sel_xcid].className = 'menu';
	}
	last_sel_xcid = this.event.srcElement.id;
	document.all[last_sel_xcid].className = 'menu_sel_xc';
}




function cms_show_menu_submenu(cid)
{
	s_content = FIND('cms_pre_cont_menu').innerHTML;
	re = new RegExp("set__cid","g");
	new_content = s_content.replace(re,cid);
	var oPopup = window.createPopup();
	oPopup.document.createStyleSheet('/styles/stylesadmin.css');
	oPopup.document.body.style.backgroundImage = "url('/img/all_bg.gif')";
	oPopup.document.body.innerHTML = new_content;
	oPopup.show(0, 0, 210, 0);
    var realHeight = oPopup.document.body.scrollHeight;
    oPopup.hide();
	oPopup.show(0, 0, 210, realHeight, event.srcElement);
}


function cms_menu_context_1(mid, mtype, cid)
{
	FIND('menu_context').style.left = document.body.scrollLeft + this.event.clientX - 5;
	FIND('menu_context').style.top = document.body.scrollTop + this.event.clientY - 5;
	s_content = FIND('pre_menu_cont_top').innerHTML;
	if(mtype == 4 && cid>0) s_content += FIND('pre_menu_cont_m2').innerHTML;
	if(mtype == 0 || mtype == 3 || mtype == 4) s_content += FIND('pre_menu_cont_m1').innerHTML;
	if(mtype == 1) s_content += FIND('pre_menu_cont_m3').innerHTML;
	if(mtype == 4) s_content += FIND('pre_menu_cont_m4').innerHTML;
	s_content += FIND('pre_menu_cont_bot').innerHTML;
	re = new RegExp("set__mid","g");
	new_content = s_content.replace(re,mid);
	re = new RegExp("set__cid","g");
	new_content = new_content.replace(re,cid);
	FIND('menu_context').innerHTML = new_content;
	FIND('menu_context').style.display = 'block';
	this.event.returnValue = false;
}




function cms_show_menu_sub_submenu(cid, xcid, xcparent)
{
	if (cms_show_menu_sub_submenu.arguments[3]) 
		FIND('show_prop_ctype1').style.display = 'block';
	else
		FIND('show_prop_ctype1').style.display = 'none';
	s_content = FIND('cms_pre_cont_sub_menu').innerHTML;
	re = new RegExp("set__cid","g");
	s_content = s_content.replace(re,cid);
	re = new RegExp("sel__xcid","g");
	s_content = s_content.replace(re,xcid);
	re = new RegExp("sel__xcparent","g");
	new_content = s_content.replace(re,xcparent);
	
	var oPopup = window.createPopup();
	oPopup.document.createStyleSheet('/styles/stylesadmin.css');
	oPopup.document.body.style.backgroundImage = "url('/img/all_bg.gif')";
	oPopup.document.body.innerHTML = new_content;
	oPopup.show(0, 0, 210, 0);
    var realHeight = oPopup.document.body.scrollHeight;
    oPopup.hide();
	oPopup.show(0, 0, 210, realHeight, event.srcElement);
}

function cms_show_cat_menu()
{
	if (FIND('cms_catalog_content_menu'))
	{
		if (FIND('cms_catalog_content_menu').style.display == 'block')
		{
			FIND('cms_catalog_content_menu').style.display = 'none'
			FIND('up_down_icon').src  = '/img/admin/icon/down_ic.gif';
			SetCookie('admin_show_catalogs', 1);
		}
		else
		{
			FIND('cms_catalog_content_menu').style.display = 'block'
			FIND('up_down_icon').src  = '/img/admin/icon/up_ic.gif';
			SetCookie('admin_show_catalogs', 0);
		}
	}
}

function cms_show_str_menu()
{
	if (FIND('cms_str_content_menu'))
	{
		if (FIND('cms_str_content_menu').style.display == 'block')
		{
			FIND('cms_str_content_menu').style.display = 'none'
			FIND('up_down_icon2').src  = '/img/admin/icon/down_ic.gif';
			SetCookie('admin_show_str', 1);
		}
		else
		{
			FIND('cms_str_content_menu').style.display = 'block'
			FIND('up_down_icon2').src  = '/img/admin/icon/up_ic.gif';
			SetCookie('admin_show_str', 0);
		}
	}
}


function cms_add_new_tree()
{
	FIND('cms_tree_name').style.display = 'block';
	tree_edit_form.cms_tree_sub_mode.value = 'add_x';
	tree_edit_form.xcname.value = '';
}

function cms_tree_edit (xcid, langid)
{
//	alert('dd');
	FIND('cms_tree_name').style.display = 'block';
	tree_edit_form.xcname.value = FIND('hidden_lang_names_' + xcid + '_' + langid).value;
	tree_edit_form.cms_tree_sub_mode.value = 'edit_x';
	tree_edit_form.cms_tree_langid.value = langid;
	tree_edit_form.cms_tree_xcid.value = xcid;
	tree_edit_form.xcname.focus();
} 

function cms_update_all_tree(xcparent)
{
	if (tree_edit_form.cms_tree_sub_mode.value == 'edit_x')
	{
		if (tree_edit_form.cms_tree_langid.value == '0')
		{
			FIND('cms_tree_element_' + tree_edit_form.cms_tree_xcid.value).innerHTML = tree_edit_form.xcname.value;
			top.cms_menu_frame.FIND('cms_xc_left_menu_' + tree_edit_form.cms_tree_xcid.value).innerHTML = tree_edit_form.xcname.value;
		}
		FIND('hidden_lang_names_' + tree_edit_form.cms_tree_xcid.value + '_' + tree_edit_form.cms_tree_langid.value).value = tree_edit_form.xcname.value; 
	}
	else
	{
		
	}
	FIND('cms_tree_name').style.display = 'none';
	return true;
}

function cms_add_x(new_xcid, xcparent, cid, xcname)
{
	if (FIND('cms_left_menu_tree_' + cid))
	{
		s_content = '<table cellpadding="0" cellspacing="0"><tr><td id=cms_open_xc_'+new_xcid+'><img src=/img/blank.gif width=10 height=9 border=0>&nbsp;</td>';
		s_content += '<td><a target=cms_work_frame href=/admin/catalog_content/'+cid + '/'+xcparent+'/'+new_xcid+'/ class=menu oncontextmenu="cms_show_menu_sub_submenu('+cid+','+new_xcid+','+xcparent+');" id=cms_xc_left_menu_'+new_xcid+'>'+xcname+'</a></td></tr></table>';
//	alert (s_content);
		var new_div = document.createElement('<div style=padding-left:5 width=100% height=18 id=cms_tree_xcid_'+new_xcid+'>');
		new_div.innerHTML = s_content;
		if (xcparent < 1)
		{
			FIND('cms_left_menu_tree_' + cid).firstChild.appendChild(new_div);
			if (FIND('cms_left_menu_tree_' + cid).style.display == 'none')
				FIND('cms_left_menu_tree_' + cid).style.display == 'block';
		}
		if (xcparent > 0)
		{
			if (!FIND('cms_left_menu_cat_tree_' + xcparent))
			{
				new_sub_div = document.createElement('<div style="padding-left:7;display:block;" width=100% id=cms_left_menu_cat_tree_'+xcparent+'>');
				if (FIND('cms_tree_xcid_' + xcparent).nextSibling)
					FIND('cms_tree_xcid_' + xcparent).parentNode.insertBefore(new_sub_div, FIND('cms_tree_xcid_' + xcparent).nextSibling);
				else
					FIND('cms_tree_xcid_' + xcparent).parentNode.appendChild(new_sub_div);
				FIND('cms_open_xc_'+xcparent).innerHTML = '<a href=javascript:void(0); onClick="cms_menu_show_xcid('+xcparent+')";><img src=/img/admin/icon/papka_ic2.gif width=10 height=9 border=0 alt="Открыть папку"></a>&nbsp;';
			}
			FIND('cms_left_menu_cat_tree_' + xcparent).appendChild(new_div);
			if (FIND('cms_left_menu_cat_tree_' + xcparent).style.display == 'none')
				FIND('cms_left_menu_cat_tree_' + xcparent).style.display = 'block';
		}
	}	
}


function cms_add_mx(new_xcid, xcparent, cid, xcname,mtype,mid_cid)
{
	if (FIND('cms_left_menu_tree_m_' + cid))
	{
		s_content = '<table cellpadding="0" cellspacing="0"><tr><td id=cms_open_m_'+new_xcid+'><img src=/img/blank.gif width=10 height=9 border=0>&nbsp;</td>';
		s_content += '<td><a target=cms_work_frame href=/admin/menu/'+xcparent+'/'+new_xcid+'/edit_a/  class=menu oncontextmenu="cms_menu_context('+new_xcid+','+mtype+','+ mid_cid +','+xcparent+');" id=cms_m_left_menu_'+new_xcid+'>'+xcname+'</a></td></tr></table>';
//	alert (s_content);
		var new_div = document.createElement('<div style=padding-left:5 width=100% height=18 id=cms_tree_m_'+new_xcid+'>');
		new_div.innerHTML = s_content;

//		if (xcparent < 1)

		if (xcparent > 0)
		{
			FIND('cms_left_menu_tree_m_' + cid).firstChild.appendChild(new_div);
			if (FIND('cms_left_menu_tree_m_' + cid).style.display == 'none')
				FIND('cms_left_menu_tree_m_' + cid).style.display == 'block';
		}

		if (FIND('im_'+cid)) FIND('im_'+cid).src = '/img/admin/icon/papka_ic2.gif';


		if (xcparent > 0)
		{
//			if (!FIND('cms_left_menu_m_tree_' + xcparent])
//			{

//alert('cms_tree_m_' + xcparent+' '+FIND('cms_tree_m_' + xcparent]);


//document.write('cms_tree_m_' + xcparent);

//				new_sub_div = document.createElement('<div style="padding-left:7;display:block;" width=100% id=cms_left_menu_m_tree_'+xcparent+'>');
//				if (FIND('cms_tree_m_' + xcparent].nextSibling)
///					FIND('cms_tree_m_' + xcparent].parentNode.insertBefore(new_sub_div, FIND('cms_tree_m_' + xcparent].nextSibling);
//				else
//					FIND('cms_tree_m_' + xcparent].parentNode.appendChild(new_sub_div);
//				FIND('cms_open_m_'+xcparent].innerHTML = '<a href=javascript:void(0); onClick="cms_menu_show_mid('+xcparent+')";><img src=/img/admin/icon/papka_ic2.gif width=10 height=9 border=0 alt="Открыть папку"></a>&nbsp;';
//			}
//			FIND('cms_left_menu_m_tree_' + xcparent].appendChild(new_div);
//			if (FIND('cms_left_menu_m_tree_' + xcparent].style.display == 'none')
//				FIND('cms_left_menu_m_tree_' + xcparent].style.display = 'block';
		}
	}	
}

function cms_del_x(cid, xcdel)
{
	var tmp_counter = 0;
	if (xcdel.length > 0)
		while (tmp_counter < xcdel.length)
		{
			if (FIND('cms_tree_xcid_' + xcdel[tmp_counter]))
				FIND('cms_tree_xcid_' + xcdel[tmp_counter]).removeNode(true);
			if (FIND('cms_left_menu_cat_tree_' + xcdel[tmp_counter]))
				FIND('cms_left_menu_cat_tree_' + xcdel[tmp_counter]).removeNode(true);
			tmp_counter++;
		}
}

function cms_del_x1(cid, n)
{
			if (FIND('cms_tree_xcid_' + n))
				FIND('cms_tree_xcid_' + n).removeNode(true);
			if (FIND('cms_left_menu_cat_tree_' + n))
				FIND('cms_left_menu_cat_tree_' + n).removeNode(true);
}


function cms_del_m1(cid, n,es)
{

	if (FIND('mid_node_' + n))
		FIND('mid_node_' + n).removeNode(true);

	if (FIND('mid_node_2_' + n))
		FIND('mid_node_2_' + n).removeNode(true);

	if (FIND('mid_node_3_' + n))
		FIND('mid_node_3_' + n).removeNode(true);

	if (FIND('cms_tree_m_' + n))
		FIND('cms_tree_m_' + n).removeNode(true);
	if (FIND('cms_left_menu_m_tree_' + n))
		FIND('cms_left_menu_m_tree_' + n).removeNode(true);
	if (es==1)
	{if (FIND('im_'+cid)) FIND('im_'+cid).src = '/img/admin/icon/papka_ic1.gif';}
}


function fields_prop_change(cid, xcparent, fid, langid)
{
	var str;
	str = '/admin/catalog/' + cid + '/f/';
	if (xcparent > 0) str += xcparent + '/';
	str += 'get_fname/' + fid + '/' + langid + '/';
	top.cms_left_hidden.location.href = str;
	document.field_name_form.field_langid.value = langid;
	document.field_name_form.field_fid.value = fid;
	field_src_element_x = this.event.clientX;
	field_src_element_y = this.event.clientY;
}

function fields_prop_popup()
{
	FIND('field_name_change_text').value = document.field_name_form.field_name.value;
	FIND('field_change_div').style.left = field_src_element_x
	FIND('field_change_div').style.top = field_src_element_y;
	FIND('field_change_div').style.display = 'block';
}

function fields_prop_save()
{
	field_name_form.field_name.value = FIND('field_name_change_text').value;
	document.field_name_form.submit();
	FIND('field_change_div').style.display='none';
}

function body_lang(lang)
{
//	document.images['normaltab1'].click();
	ae_editsourceinline(1,false);
	ae_onSubmit();	
	var content = this.document.all.ae_tx_content1.value;
	document.Article['menu_body[' + cur_edited_menu_lang + ']'].value = content;
	content = document.Article['menu_body[' + lang + ']'].value;
/*	addUrl = "http://" + cms_host_var;
	re = new RegExp("src=\"","g");
	content = content.replace(re,"src=\"" + addUrl);
	re = new RegExp(" class=","g");
	content = content.replace(re," myclass=");
	re = new RegExp(" style=","g");
	content=content.replace(re," mystyle=");
*/
	this.document.all.DHTMLSafe1.DOM.body.innerHTML = content;	
//	document.all['ae_tx_content1'].value = document.Article['menu_body[' + lang + ']'].value;
	cur_edited_menu_lang = lang;
}


function save_menu_content()
{
	ae_editsourceinline(1,false);
	ae_onSubmit();
	var content = this.document.all.ae_tx_content1.value;
	document.Article['menu_body[' + cur_edited_menu_lang + ']'].value = content;
}



function cms_add_to_box(fid)
{
	FIND('box_add_div').style.top = document.body.scrollTop + this.event.clientY - 5;
	FIND('box_add_div').style.left = document.body.scrollLeft + this.event.clientX - 5;
	FIND('box_add_div').style.display = 'block';
	document.forms['box_add_form'].added_fid.value = fid;
} 

function cms_insert_into_box(fid, fname, bid)
{
	if (!document.forms.Article['f' + fid])
	{
		var box = document.forms.Article['f' + fid + '[]'];
		var extended_box =  1;
	}
	else
		var box = document.forms.Article['f' + fid];
	var oOption = document.createElement("OPTION");
	box.options.add(oOption);
	oOption.innerText = fname;
	oOption.Value = bid;
	box.options[box.options.length - 1].selected = true;
	FIND('box_add_div').style.display = 'none';
	document.forms.box_add_form['box_add_value[0]'].value = '';
	if (extended_box && box.size < 5) box.size ++;
}

function add_box_check()
{
	if (document.forms.box_add_form['box_add_value[0]'].value == '') 
	{
		alert('Поле не должно быть пустым');
		return false;
	}
	else 
		return true;
}

