function funcUse(id, useAction, personal, iname)
{
	if(useAction == 'wear')
	{
		if(personal == 1)
		{
			if(confirm("Вы действительно хотите одеть именную вещь?\nПосле одевания вещь нельзя будет больше передать."))
			{
				window.TOP.main.mainpanel.ref_inv.location.href="ref_inv.php?wear=" + id;
			}
		}
		else
		{
			window.TOP.main.mainpanel.ref_inv.location.href="ref_inv.php?wear=" + id;
		}
	}
	else if(useAction == 'unwear')
	{
		window.TOP.main.mainpanel.ref_inv.location.href="ref_inv.php?unwear=" + id;
  }
	else if(useAction == 'auction')
	{
		//if(parent.frames['auction_add_lot'])
			//alert(parent.frames['auction_add_lot']);
		window.parent.auction_add_lot.location.href="auction_add_lot.php?add_item=" + id;
		//parent.frames['auction_add_lot'].location.href="auction_add_lot.php?add_item=" + id;
	}
	else if(useAction == 'add_to_present')
	{
		window.parent.form.present_item_id.value = id;
		window.parent.present_item_id_str.innerHTML = iname;
	//	window.parent.getElementById("present_item_id_str").innerHTML = iname;
	}
	else if(useAction == 'open_present')
	{
		if(confirm('Вы действительно хотите открыть подарок?'))
		{
			location.href="info_user.php?name=" + iname + "&open_present=" + id;
		}
	}
	else if(useAction == 'heal')
	{
		location.href="item_heal.php?heal_wound=" + id;
	}
	else
	{}
}

function funcBuildActionUse(id, useAction)
{
    if(useAction == 'auction')
	{
		window.parent.auction_add_lot.location.href="auction_add_lot.php?add_buildAction=" + id;
	}
}

function funcInfo(id)
{
//	window.open('info_item.php?itemId='+id,id,'width=700,height=550,resizable=yes,scrollbars=yes');
	window.TOP.game.open("item_info", id);
}

function funcUp(id)
{
	window.TOP.game.open("item_up", id);
}

function funcDrop(id, useAction, iname)
{
	if(useAction == "open_present") // delete present
	{
		if(confirm('Вы действительно хотите выбросить подарок?'))
		{
			location.href="info_user.php?name=" + iname + "&delete_present=" + id;
		}
	}
	else
	{
		if(confirm('Вы действительно хотите выбросить эту вещь?'))
		{
			window.TOP.main.mainpanel.ref_inv.location.href="ref_inv.php?drop=" + id;
		}
	}
}

function funcQuote(id)
{
	window.TOP.chat_menu.insertItem(id);
}

var ItemTypeStr =
{
"0": "",
"1":"Шлем",
"2":"Одежда&nbsp;(Верх)",
"3":"Одежда&nbsp;(Низ)",
"4":"Браслет",
"5":"Пояс",
"6":"Обувь",
"7":"Амулет",
"8":"Оружие",

"9":"Щит",
"9.100":"Оружие&nbsp;(Вместо&nbsp;Щита)",

"10":"Кольцо",
"11":"Перчатки",
"12":"Нижняя&nbsp;Одежда",
"13":"Оберег",
"14":"Наплечники",
"15":"Серьги",
"30":"Боевой&nbsp;Свиток",
"40":"Вещь&nbsp;на&nbsp;Продажу",

"50":"Ресурс",
"50.1":"Ископаемое",
"50.51":"Материал (Камень)",
"50.52":"Материал (Шкура)",
"50.53":"Материал (Кожа)",
"50.54":"Материал (Кость)",
"50.55":"Материал (Метал)",
"50.56":"Материал (Древесина)",
"50.57":"Материал (Маг. Металл)",
"50.59":"Материал (Драг. Металл)",
"50.60":"Материал (Ткань)",
"50.64":"Материал (Маг. Шкура)",
"50.65":"Материал (Очищенный Маг. Металл)",
"50.66":"Материал (Мореная Маг. Древесина)",
"50.67":"Материал (Выделанная Маг. Кожа)",

"60":"Рецепт",
"70":"Подарок",
"71":"Руна",
"74":"Еда",
"75":"Лекарство",
"84":"Эликсиры",
"80":"Зелье",
"81":"Свиток",
"82":"Книга",
"82.1":"Регистрационная Книга",
"83":"Свиток",
"84":"Эликсир",
"85":"Сундук",
"86":"Ключ",
"87":"Модификатор",
"88":"Инструмент",
"err":"<font color=ff0000>(error_type)</font>"};

function ConvertItemTypeToStr(_type, subtype)
{
   return ItemTypeStr[_type + '.' + subtype] || ItemTypeStr[_type] || ItemTypeStr['err'];
}


function ConvertStatCodeToString($code)
{
	if($code == "hp")
		return "Жизнь";
	else if($code == "mana")
		return "Мана";

	else if($code == "crit")
		return "Критический&nbsp;Удар";
	else if($code == "dodge")
		return "Уворот";
	else if($code == "crit_m")
		return "Критический&nbsp;Удар&nbsp;Магии";
	else if($code == "dodge_m")
		return "Уворот&nbsp;от&nbsp;Магии";
	else if($code == "block")
		return "Блок";
	else if($code == "block_m")
		return "Блок&nbsp;Магии";


	else if($code == "damage_poison")
		return "Атака&nbsp;Ядом";
	else if($code == "defence_poison")
		return "Защита&nbsp;от&nbsp;Яда";


	else if($code == "defence_undead")
		return "Защита&nbsp;от&nbsp;Нежити";
	else if($code == "damage_undead")
		return "Атака&nbsp;по&nbsp;Нежити";

	else if($code == "defence_orc")
		return "Защита&nbsp;от&nbsp;Орков";
	else if($code == "damage_orc")
		return "Атака&nbsp;по&nbsp;Оркам";




	else if($code == "knockback")
		return "Ответный&nbsp;Удар";

	else if($code == "quality")
		return "Качество";

	else if($code == "delay")
		return "Перезарядка";
	else if($code == "ballista_crit")
		return "Критический&nbsp;Удар";
	else if($code == "prepare")
		return "Подготовка";
	else if($code == "shoots")
		return "Стрелы";
	else if($code == "damage_min")
		return "Минимальный&nbsp;Урон";
	else if($code == "damage_max")
		return "Максимальный&nbsp;Урон";


	else if($code == "damage_troopers")
		return "Атака&nbsp;Пехоты";
	else if($code == "damage_horses")
		return "Атака&nbsp;Всадников";
	else if($code == "damage_rangers")
		return "Атака&nbsp;Стрелков";
	else if($code == "damage_all")
		return "Атака&nbsp;Всех";

	else if($code == "damage_light")
		return "Атака&nbsp;Света";
	else if($code == "damage_dark")
		return "Атака&nbsp;Тьмы";

	else if($code == "damage_fire")
		return "Атака&nbsp;Огня";
	else if($code == "damage_water")
		return "Атака&nbsp;Воды";
	else if($code == "damage_sky")
		return "Атака&nbsp;Воздуха";
	else if($code == "damage_earth")
		return "Атака&nbsp;Земли";

	else if($code == "defence_fire")
		return "Защита&nbsp;от&nbsp;Огня";
	else if($code == "defence_water")
		return "Защита&nbsp;от&nbsp;Воды";
	else if($code == "defence_sky")
		return "Защита&nbsp;от&nbsp;Воздуха";
	else if($code == "defence_earth")
		return "Защита&nbsp;от&nbsp;Земли";


	else if($code == "defence_troopers")
		return "Защита&nbsp;Пехоты";
	else if($code == "defence_horses")
		return "Защита&nbsp;Всадников";
	else if($code == "defence_rangers")
		return "Защита&nbsp;Стрелков";
	else if($code == "defence_all")
		return "Защита&nbsp;Всех";

	else if($code == "defence_light")
		return "Защита&nbsp;от&nbsp;Света";
	else if($code == "defence_dark")
		return "Защита&nbsp;от&nbsp;Тьмы";

	else if($code == "defence_all_magic")
		return "Защита&nbsp;от&nbsp;Всей&nbspМагии";


	else if($code == "luck")
		return "Удача";
	else if($code == "speed")
		return "Скорость";
	else if($code == "karma")
		return "Карма";
	else if($code == "lie")
		return "Обман";
	else if($code == "speak")
		return "Красноречие";
	else if($code == "steal")
		return "Воровство";
	else if($code == "crack")
		return "Взлом";


	else if($code == "mining")
		return "Шахтерство";
	else if($code == "hunting")
		return "Охота";
	else if($code == "searching")
		return "Собирательство";
	else if($code == "hiring")
		return "Навык&nbsp;Наемника";
	else if($code == "blacksmith")
		return "Кузнечное&nbsp;Дело";
	else if($code == "tailoring")
		return "Шитье";
	else if($code == "alchemy")
		return "Алхимия";
	else if($code == "enginering")
		return "Инженерия";
	else if($code == "science")
		return "Наука";
	else if($code == "archeology")
		return "Археология";
	else if($code == "thief")
		return "Воровство";
	else if($code == "healing")
		return "Лечение";
	else if($code == "teacher")
		return "Обучение";
	else if($code == "cooking")
		return "Готовка";
	else if($code == "farming")
		return "Фермерство";
	else if($code == "fishing")
		return "Рыбалка";
	else if($code == "steklo")
		return "Стеклодувное&nbsp;Дело";
	else if($code == "building")
		return "Строительство";
	else if($code == "magician")
		return "Зачарование";
	else if($code == "jawerly")
		return "Ювелирное&nbsp;Дело";
	else if($code == "pooring")
		return "Попрошайничество";
	else if($code == "lumbering")
		return "Навык&nbsp;Лесоруба";
	else if($code == "training")
		return "Навык&nbsp;Тренера";
	else if($code == "mastering")
		return "Навык&nbsp;Мастерового";




	else if($code == "mod_hp")
		return "Жизнь";

	else if($code == "mod_loot")
		return "Лут";


	else if($code == "reg_hp")
		return "Регенерация";

	else if($code == "com_reg_hp")
		return "Регенерация в Бою";

	else if($code == "conc")
		return "Концентрация";

	else if($code == "wound")
		return "Травматизм";
	else if($code == "defence_wound")
		return "Защита&nbsp;от&nbsp;Травматизма";

	else if($code == "poison")
		return "Яд";
		
		
	else if($code == "damage_side")
		return "Атака Склонности";		
		
		
	else if($code == "damage_light_all")
		return "Атака&nbsp;Света";
	else if($code == "damage_dark_all")
		return "Атака&nbsp;Тьмы";

	else if($code == "damage_fire_all")
		return "Атака&nbsp;Огня";
	else if($code == "damage_water_all")
		return "Атака&nbsp;Воды";
	else if($code == "damage_sky_all")
		return "Атака&nbsp;Воздуха";
	else if($code == "damage_earth_all")
		return "Атака&nbsp;Земли";



	return $code;
}

var itemSortMenus =
{
"rootv":[["filter=all", "", "root"]],
"socketDrill": [["filter=all", "Вещи", "items"]],
"root": [["filter=all", "Все"],
        ["filter=items", "Вещи", "items"],
        ["filter=resources", "Ресурсы", "resources"],
        ["filter=instruments", "Инструменты", null],
        ["filter=presents", "Подарки", null],
        ["filter=scrolls", "Свитки", "scrolls"],
        ["filter=potions", "Зелья", "potions"],
        ["filter=quests", "Квесты", null],
        ["filter=food", "Еда", null],
        ["filter=other", "Прочее", "other"]],

potions: [["fts=75.1", "Лекарства"],
	  ["fts=84", "Эликсиры"]],

"items": [["fts=1", "Шлем"],
          ["fts=2", "Одежда&nbsp;(Верх)"],
          ["fts=3", "Одежда&nbsp;(Низ)"],

          ["fts=4", "Браслет"],
          ["fts=5", "Пояс"],

          ["fts=6", "Обувь"],
          ["fts=7", "Амулет"],
          ["fts=8", "Оружие"],
          ["fts=9.100", "Оружие&nbsp;(Вместо&nbsp;Щита)"],
          ["fts=9", "Щит"],
          ["fts=10", "Кольцо"],
          ["fts=11", "Перчатки"],
          ["fts=12", "Нижняя&nbsp;Одежда"],
          ["fts=13", "Оберег"],
          ["fts=14", "Наплечники"],
          ["fts=15", "Серьги"]],

resources: [["fts=50.51|50.52|50.53|50.54|50.55|50.56|50.57|50.59|50.60|50.61|50.62|50.63", "Материал", "mt"],
            ["fts=50.1", "Ископаемое"],
            ["fts=50.2", "Руда"],
            ["fts=50.3", "Туша"],
            ["fts=50.4", "Ингридиент"],
            ["fts=50.5", "Ингридиент (Концентрат)"],
            ["fts=50.6", "Ингридиент (Продукт)"],
            ["fts=50.7", "Драг. Камень"],
            ["fts=50.8", "Магический Камень"],
            ["fts=50.10", "Осколок Метеорита"]],

mt: [["fts=50.51", "Камень"],
     ["fts=50.52", "Шкура"],
     ["fts=50.53", "Кожа"],
     ["fts=50.54", "Кость"],
     ["fts=50.55", "Металл"],
     ["fts=50.56", "Древесина"],
     ["fts=50.57", "Маг. Металл"],
     ["fts=50.59", "Драг. Металл"],
     ["fts=50.60", "Ткань"],
     ["fts=50.64", "Маг. Шкура"],
     ["fts=50.63", "Волшебная Древесина"],
	 ["fts=50.65", "Очищенный Маг. Металл"],
	 ["fts=50.66", "Мореная Маг. Древесина"],
	 ["fts=50.67", "Выделанная Маг. Кожа"]],

scrolls: [["fts=30", "Боевой&nbsp;Свиток"],
          ["fts=83|81", "Свиток"],
          ["fts=60", "Рецепт"]],


other: [["fts=71", "Руна"],
        ["fts=40", "Вещь&nbsp;на&nbsp;Продажу"],
        ["fts=72", "Реликвия"],
        ["fts=73", "Фишка"],
        ["fts=85", "Сундук"],
        ["fts=85", "Ключ"],
        ["fts=87", "Модификатор"],
        ["fts=82", "Книга"],
        ["fts=82.1", "Регистрационная Книга"]]
};

function showTsMenuItem()
{
   this.className += " hhover";
}
function hideTsMenuItem()
{
   this.className = this.className.replace(" hhover", "");
}

function createTsMenu(bs, _data, _pref, _class, _pos)
{
   var _callee = arguments.callee;
   var pref   = _pref  || "";
   _class  = _class || "";
   _pos    = _pos || null;
   var cpos = _pos || 0;

   var divc  = _pos ? _callee.__blank.cloneNode(true) : document.createElement('div');

	var prf = bs + (bs[0] == "#" || bs.indexOf("?") != -1 ? '' : '?');

   var menub = _pos ? CPath(divc, '0.1.0.0') : divc;

   divc.className = "tsMenuDivc" + _class + ( _pos ? "  " + "tsMenuDivc" + _class + _pos : "");
	
   for (var i = 0; i < _data.length; i++)
   {
      var div  = document.createElement('div');
      var a    = document.createElement('a');

      div.className = "tsMenuDiv" + _class + ( _pos ? "  " + "tsMenuDiv" + _class + _pos : "");

      a.href      =  prf + _data[i][0];
      a.innerHTML = _data[i][1] + pref;

      a.className = "tsMenuA";

      div.appendChild(a);

      div.onmouseenter = showTsMenuItem;
      div.onmouseleave = hideTsMenuItem;

      if (_data[i][2])
      {
         var subdiv = createTsMenu(bs, itemSortMenus[_data[i][2]], null, "aa", cpos + 1);

         a.className += " tsMenuA-hchild";

         div.appendChild(subdiv);
      }

      menub.appendChild(div);
   }

   return divc;

}
documentReady(function()
{
   var div = document.createElement("div");
   div.innerHTML = "<div class=\"rec-base-tdtx\"><div class=\"rec-base-tdtx-tl\"><div class=\"rec-base-tdtx-tr\"><div class=\"rec-base-tdtx-tc\"></div></div></div><div class=\"rec-base-tdtx-cl\"><div class=\"rec-base-tdtx-cr\"><div class=\"rec-base-tdtx-cc\"></div></div></div><div class=\"rec-base-tdtx-bl\"><div class=\"rec-base-tdtx-br\"><div class=\"rec-base-tdtx-bc\"></div></div></div></div>";

   window.createTsMenu.__blank = div;
}
);

