function buttonInventory()
{
   top.game.open("inventory");
	//parent.mainpanel.loc.location.href="p_inv.php";
}

function buttonArmy()
{

   top.game.open("army");
	//parent.mainpanel.loc.location.href="p_unt.php";
}

function buttonSpellbook()
{
   top.game.open("spellbook");
}

function buttonSkills()
{
   top.game.open("skills");
	//parent.mainpanel.loc.location.href="p_skl.php";
}

function buttonMap()
{
	alert("Карта не доступна.\n\rСервис в разработке.");
//	parent.mainpanel.loc.location.href="p_map.php";
}

function buttonJournal()
{
   top.game.open("journal");
	//parent.mainpanel.loc.location.href="p_journal.php";
}

function buttonPartner()
{
   top.game.open("partner");
	//parent.mainpanel.loc.location.href="p_partner.php";
}

function buttonAdditional()
{
   top.game.open("additional");
//	alert("Дополнительные услуги не доступны.\n\rСервис в разработке.");
	//parent.mainpanel.loc.location.href="p_additional.php";
}

function buttonUnique()
{
	parent.mainpanel.loc.location.href="p_unq.php";
}

function buttonUnwearAll()
{
	window.top.main.mainpanel.ref_inv.location.href="ref_inv.php?unwearall=1";
}

function openPerkDialog()
{
   top.game.open("skills", 2);
	//parent.mainpanel.loc.location.href="p_skl.php?curSel=2";
}


function buttonUseSet()
{
}

function buttonDeleteSet()
{
	if(confirm("Удалить выбраный набор?"))
	{
	}
}

function buttonSaveSet()
{
	var reply = prompt("Введите название нового набора", "");

	if(reply == "")
	{
		alert("Поле названия набора не должно быть пустым");
		return;
	}

	if(reply.length > 32)
	{
		alert("Поле названия набора не должно быть длинее 32 символа");
		return;
	}

	window.top.main.mainpanel.ref_inv.location.href="ref_inv.php?saveset="+reply; 
}

function openPresentDialog(id)
{
   top.game.open("send_present", id);
// 	parent.loc.location.href="send_present.php?item_id="+id;
}

function openSocketsDialog(id)
{
   top.game.open("item_rune", id);
// 	parent.loc.location.href="item_rune.php?item_id="+id;
}

function openIdentificationDialog(id)
{
   top.game.open("item_identification", id);
// 	parent.loc.location.href="item_identification.php?item_id="+id;
}

function openClanBook(id)
{
   top.game.open("item_clan_book", id);
//	if(confirm('Открыв Клановую Книгу Вы автоматически станете главой клана и не сможете продать или передать книгу. Вы уверены что хотите сделать это?'))
//	{
// 		parent.loc.location.href="item_clan_book.php?item=" + id;
//	}
}

function openNameChangeDialog(id)
{
   top.game.open("item_name_change", id);
  // parent.loc.location.href="item_name_change.php?item=" + id;
}

function openSideChangeDialog(id)
{
	if(confirm('Вы действительно хотите изменить свою склонность? Если вы состоите в клане, то будете автоматически отчислены!'))
	{
		window.top.chat.ref_dummy.location.href = "user_change_side.php?scrollId=" + id;
	}	
}

function openGenderChangeDialog(id)
{
	if(confirm('Вы действительно хотите изменить пол своего персонажа?'))
	{
		window.top.chat.ref_dummy.location.href = "user_change_gender.php?scrollId=" + id;
	}	
}

function openPanaceyaChangeDialog(id)
{
	if(confirm('Вы действительно хотите излечить все свои раны и болезни?'))
	{
		window.top.chat.ref_dummy.location.href = "user_heal_all.php?scrollId=" + id;
	}	
}

function openStatChangeDialog(id)
{
	if(confirm('Вы действительно хотите перераспределить характеристики?'))
	{
		window.top.chat.ref_dummy.location.href = "user_change_stats.php?scrollId=" + id;
	}
}

function openPerkChangeDialog(id)
{
	if(confirm('Вы действительно хотите перераспределить перки?'))
	{
		window.top.chat.ref_dummy.location.href = "user_change_perks.php?scrollId=" + id;
	}
}

function openItemMorphDialog(id)
{
   top.game.open("user_item_morph", id);
	//parent.loc.location.href = "user_item_morph.php?scrollId=" + id;
}

function openAttackDialog(id)
{
   top.game.open("item_attack", id);
//	parent.loc.location.href="item_attack.php?item_id="+id;
}

function openSideDialog()
{
   top.game.open("user_pick_side");
	//parent.mainpanel.loc.location.href="user_pick_side.php";
}

function openElementDialog()
{
   top.game.open("user_pick_element");
	//parent.mainpanel.loc.location.href="user_pick_element.php";
}

function openStatDialog()
{
   top.game.open("user_pick_stats");
	//parent.mainpanel.loc.location.href="user_pick_stats.php";
}

function openHealItem(item_id)
{
   top.game.open("item_heal", item_id);
//   parent.loc.location.href="item_heal.php?item_id="+item_id;
}

function openQuestItem(item_id)
{
	parent.loc.location.href="item_quest_"+item_id+".php";
}


function useQuestItem(item_id)
{
	window.top.chat.ref_dummy.location.href = "item_quest_"+item_id+".php";
}


function doResurection()
{
	window.top.chat.ref_dummy.location.href = 'ref_ressurection.php';
}

function openCombatLog(combat_id)
{
	window.open('info_combat.php?combat_id='+combat_id,'_blank','width=1000,height=600,resizable=yes,scrollbars=yes');
}

function openCurrentCombatLog(username)
{
	window.open('info_combat.php?user_name='+username,'_blank','width=1000,height=600,resizable=yes,scrollbars=yes');
}

function UpdateExpirement(exp_cur, exp_max)
{
	if(window)
	{
		if(window.top)
		{
			if(window.top.main)
			{
				if(window.top.main.player)
				{
					if(window.top.main.player.stats)
					{
						window.top.main.player.stats.SetExpCur(exp_cur);
						window.top.main.player.stats.SetExpMax(exp_max);
					}
				}
			}
		}
	}
}

function setRespawnTime(tm)
{
   var currentTime = parseInt(+new Date / 1000, 10);
   var dtime       = parseInt(tm, 10) || -1;

   window.userDeadTime = (dtime) + currentTime;
}

function setFoodIconTimer(tm)
{
   var currentTime = parseInt(+new Date / 1000, 10);
   var dtime       = parseInt(tm, 10) || -1;

   window.userFoodIconTime = (dtime) + currentTime;

   setTimeout(function(){g("userFoodIcon").parentNode.removeChild(g("userFoodIcon"));}, tm * 1000);
}

function getFoodTimeStr()
{
try{
   var currentTime = parseInt(+new Date / 1000, 10);
   var dtime       = window.userFoodIconTime;

   if (currentTime > (dtime))
   {
      g("userFoodIcon").parentNode.removeChild(g("userFoodIcon"));
   }
   else
   {
      var mins = parseInt((dtime - currentTime) / 60, 10);
      var timeStr = mins == 0 ? "меньше минуты" : mins + " мин.";

      return "<b>Вы Сыты!<br>" + timeStr + "</b>";
   }
}catch(e){}
}

function TryResurection()
{
   var currentTime = parseInt(+new Date / 1000, 10);
   var dtime       = window.userDeadTime;

   if (currentTime > (dtime))
   {
      doResurection();
   }
}



function getRespawnTimeStr()
{
try{
   var currentTime = parseInt(+new Date / 1000, 10);
   var dtime       = window.userDeadTime;

   if (currentTime > (dtime))
   {
      return "Нажмите для воскрешения!";
   }
   else
   {
      var mins = parseInt((dtime - currentTime) / 60, 10);
      var timeStr = mins == 0 ? "меньше минуты" : mins + " мин.";

      return "<b>Мёртв!<br>" + timeStr + "</b>";
   }
}catch(e){}
}
