var cacheInfo = {};
var ie = navigator.appName == "Microsoft Internet Explorer";
var info_time;
var info_show;
var show_help = 0;
var timeoutHelpShow=333;
var is_dressed = false; //не показывать подсказку когда одеваем
var is_confirm = false;
var old_tid;
var defaultSlotImages = {
  'inventarSlot':layout_url+'/img/inv/slots/00-00-00-00.gif',
  'trousers':layout_url+'/img/inv/slots/breeches.gif',
  'armour':layout_url+'/img/inv/slots/armor.gif',
  'amulet':layout_url+'/img/inv/slots/00-00-00-00.gif',
  'helmet':layout_url+'/img/inv/slots/head.gif',
  'boots':layout_url+'/img/inv/slots/shoes.gif',
  'weapon2':layout_url+'/img/inv/slots/hend_left.gif',
  'glove':layout_url+'/img/inv/slots/00-00-00-00.gif',
  'bracelets':layout_url+'/img/inv/slots/hend_left_fist.gif',
  'ring2':layout_url+'/img/inv/slots/00-00-00-00.gif',
  'book':layout_url+'/img/inv/slots/00-00-00-00.gif',
  'weapon1':layout_url+'/img/inv/slots/hend_right.gif',
  'ring1':layout_url+'/img/inv/slots/00-00-00-00.gif'
};

function getCoords(obj)
{
	var o=typeof(obj) == 'string' ? gebi(obj) : obj
	var ret={'l':o.offsetLeft,'t':o.offsetTop,'w':o.offsetWidth,'h':o.offsetHeight}
	while(o=o.offsetParent){
		ret.l+=o.offsetLeft
		ret.t+=o.offsetTop
	}
	return ret
}

function showPopup(obj, e, act, name, cf, show, act2)
{
	if (is_confirm) return false;
	var row = '';
	var tid = obj.getAttribute('tid');
	var btn = obj.getAttribute('btn');
	var alignment = (obj.getAttribute('alignment')) ? obj.getAttribute('alignment') : 0;
	switch (act)
	{
		case 'getFromPostItem': //get
		{
			var tarr = obj.getAttribute('tid').split('_');
			var cf = tarr[2]; //заменяем на почту
			break;
		}
		case 'delFromDrop': //send
		{
    		var row = 'drop';
			break;
		}
		case 'openBoxPres': case 'openCover': //send
		{
    		var row = 'infouser';
			break;
		}
	}

	if (document.getElementById('id_show_popup'))
	{
        var info = document.getElementById('id_show_popup');
        var popupP = obgItems[tid];
        if (!obgItems[tid]) return;
        if (old_tid != tid || tid == 'present')
        {
	        for(var p in popupP)
	        {
				if (document.getElementById(p))
				{
					if (p == 'show_give' || p == 'show_need' || p == 'show_pres' || p == 'show_pres_from' || p == 'show_desc' || p == 'fate_show' || p == 'show_day' || p == 'show_p_fish' || p == 'show_p_curr' || p == 'show_p_florint' || p == 'show_p_point_npc')
					{
						if (document.getElementById(p))
						{
							document.getElementById(p).style.display = popupP[p];
						}
						if (p == 'show_ps' && document.getElementById('show_ps1'))
						{
							document.getElementById('show_ps1').style.display = popupP[p];
						}
					} else if (document.getElementById(p) && document.getElementById(p).tagName == 'IMG')
					{
						document.getElementById(p).src = popupP[p];
					} else
					if (document.getElementById(p))
					{
						document.getElementById(p).innerHTML = popupP[p];
					}
				}
	        }
	        old_tid = tid;
        }
		if (show == 1)
		{
			obj.style.cursor = 'default';
			obj.onclick = '';

      var coefRightCursor = 30;

      var ex = e.clientX + document.body.scrollLeft + coefRightCursor; //координата курсора
			var ey = e.clientY + document.body.scrollTop;

      if (info)
			{
				var oHeight = info.offsetHeight;;
				var oWidth = info.offsetWidth;
				if (info.offsetHeight<10 || info.offsetWidth<10)
				{
					info.style.visibility = 'hidden';
					info.style.display = '';
					oHeight = info.offsetHeight;
					oWidth = info.offsetWidth;
					info.style.visibility = '';
					info.style.display = 'none';
				}

			  var x = ex;
				if ((oWidth+x-document.body.scrollLeft+10) > document.body.clientWidth)
				{
					var x = ex - oWidth-coefRightCursor*2;
				}
			  var y = ey;
				if ((oHeight+y-document.body.scrollTop) > document.body.clientHeight)
				{
				  var y = ey - oHeight-5;
				}
				if ((oHeight - ey)>0)
				{
					y = ey;
				}

				info.style.left = x;
				info.style.top = (alignment == 'c') ? y : document.body.scrollTop;
				info.style.display = '';

				var coord = getCoords(obj);
				var cx = ex-coord.l;
				var cy = ey-coord.t;

		    if (parseInt(btn) == 1)
				{
				    try{obj.style.cursor = 'pointer'} catch(e){}
	          if (cx >= (40 + coefRightCursor) && cy > 40)
	          {
	            obj.style.backgroundImage = 'url(' + (layout_url + '/img/inv/14.gif') + ')';
	            obj.onclick = function(){try{showPopup(obj, e, act, name, cf, 0, act2); trowItem(tid, row, cf)}catch(e){}}
	          } else
	          {
	            obj.style.backgroundImage = 'url(' + (layout_url + '/img/inv/11.gif') + ')';
	  					obj.onclick = function(){try{showPopup(obj, e, act, name, cf, 0, act2); eval(act+'(tid, name, cf)')}catch(e){}}
	          }
				}

        if (parseInt(btn) == 2 || parseInt(btn) == 3 || parseInt(btn) == 6)
				{
					try{obj.style.cursor = 'pointer'} catch(e){}
          obj.style.backgroundImage = 'url(' + (layout_url + '/img/inv/1'+btn+'.gif') + ')';
					obj.onclick = function(){try{showPopup(obj, e, act, name, cf, 0, act2); eval(act+'(tid, name, cf)')}catch(e){}}
				}

        if (parseInt(btn) == 4)
				{
					try{obj.style.cursor = 'pointer'} catch(e){}
          obj.style.backgroundImage = 'url(' + (layout_url + '/img/inv/1'+btn+'.gif') + ')';
          obj.onclick = function(){try{showPopup(obj, e, act, name, cf, 0, act2); trowItem(tid, row, cf)}catch(e){}}
				}

        if (parseInt(btn) == 7)
				{
					try{obj.style.cursor = 'pointer'} catch(e){}
          if (cx >= (40 + coefRightCursor) && cy < 20)
          {
            obj.style.backgroundImage = 'url(' + (layout_url + '/img/inv/19.gif') + ')';
            var item = obj.getAttribute('item');
            obj.onclick = function(){try{showPopup(obj, e, act, name, cf, 0, act2); eval('usedFX(item, name, cf)')}catch(e){}}
          } else
          {
            obj.style.backgroundImage = 'url(' + (layout_url + '/img/inv/17.gif') + ')';
 	  				obj.onclick = function(){try{showPopup(obj, e, act, name, cf, 0, act2); eval(act+'(tid, name, cf)')}catch(e){}}
          }
				}
        if (parseInt(btn) == 8)
				{
					try{obj.style.cursor = 'pointer'} catch(e){}
          if (cx >= (40 + coefRightCursor) && cy >40)
          {
            obj.style.backgroundImage = 'url(' + (layout_url + '/img/inv/14.gif') + ')';
            obj.onclick = function(){try{showPopup(obj, e, act, name, cf, 0, act2); trowItem(tid, row, cf)}catch(e){}}
          } else
          {
            obj.style.backgroundImage = 'url(' + (layout_url + '/img/inv/18.gif') + ')';
  					obj.onclick = function(){try{showPopup(obj, e, act, name, cf, 0, act2); eval(act+'(tid, name, cf)')}catch(e){}}
          }
				}
				document.onmousemove=function(e) {showPopup(obj, e||event, act, name, cf, 1, act2);}
			}
		} else
		{
			if (info)
			{
				info.style.display = 'none';
				document.onmousemove=function(){}
	      if (act != 'noshow')
				{
					obj.style.backgroundImage = '';
				}
			}
		}
	}
}

function hideHelp()
{
  show_help = 0;
  clearTimeout(info_show);
  if ($('showInfo'))
  {
	 var tb=$('showInfo');
	 tb.hide();
  }
}

function showControls(slot)
{
  slot = $(slot);
	var divs = slot.getElementsByTagName('DIV');
	$(divs[2]).show();
	return;
}

function hideControls(slot)
{
	slot = $(slot);
	var divs = slot.getElementsByTagName('DIV');
	$(divs[2]).hide();
}

function showHelp(id, obj, where, type)
{
  if (is_confirm) return false;
  if (show_help == 0)
  {
    setTimeout("show_help = 1;", timeoutHelpShow);
    return;
  }

  if (is_dressed) return;

  if (cacheInfo[where] && cacheInfo[where][id])
  {
    setResult(id, obj, where);
	} else
	{
    JsHttpRequest.query(
      'GET index.php',
      {
        file: 'inventar',
        backend: 1,
        op: where,
        type: type,
        slot: id
      },
		  function(result, debugMessages)
		  {
        if (result)
        {
          if (!cacheInfo[where])
          {
            cacheInfo[where] = {};
          }
          cacheInfo[where][id] = result;
          setResult(id, obj, where);
        }
			},
			true
		);
	}
}

function set_money(money)
{
	if($('show_silver'))
  {
    $('show_silver').innerHTML = money['silver'];
  }
	if($('show_copper'))
	{
		$('show_copper').innerHTML = money['copper'];
	}
}

function set_weight(weight)
{
	if($('weight'))
	{
		$('weight').innerHTML = weight['weight_real']+"/"+weight['weight_max'];
	}
}

function setResult(id, obj, where)
{
  var info = new Array();
  info = cacheInfo[where][id];
  stuffItemInfo(info);
 	var tb=$('showInfo');
  tb.show();
}

function tip_mv(event)
{
  if (is_confirm) return false;
  infoMove(event);
  /*
	clearTimeout(info_time);
	info_time=setTimeout(function ()
		{
			hideHelp();
		},3000);
 */
}

function infoMove(event)
{
  if (event)
  {
    setTimeout("show_help = 1;", timeoutHelpShow);
    var tb=$('showInfo');
  	eventClientX = ie ? window.event.clientX : event.clientX;
  	eventClientY = ie ? window.event.clientY : event.clientY;
  	var dimensions = Element.getDimensions(tb);
    var element_width = dimensions.width;
  	var element_height = dimensions.height;
  	var scroll=document.viewport.getScrollOffsets();

    if ( (element_width + eventClientX) >= (getWindowWidth()) )
    {
      eventClientX = eventClientX - element_width;
    }

    if ( (eventClientY + scroll[1]) >= getWindowHeight() /2 )
    {
      eventClientY = eventClientY - element_height - 20;
    }

  	tb.style.left = eventClientX + 5 ;
  	tb.style.top = eventClientY + scroll[1];
  }
}

function getWindowWidth()
{
  var innerWidth;
  if (navigator.appVersion.indexOf('MSIE')>0)
  {
    innerWidth = document.body.clientWidth;
  }
  else
  {
    innerWidth = window.innerWidth;
  }
  return innerWidth;
}

function getWindowHeight()
{
  var innerHeight;
  if (navigator.appVersion.indexOf('MSIE')>0)
  {
    innerHeight = document.body.clientHeight;
  }
  else
  {
    innerHeight = window.innerHeight;
  }
  return innerHeight;
}

function sendMs(h, m, msg)
{
  if (top.fr_send)
  {
    msg = top.fr_send.m(h, m, 'Система', '3' , 'people' , 'Red' , msg,'[]');
    top.fr_send.writeMsg0(msg,0);
  }
}

//-------

// Снять
function undressI(clothSlot)
{
  if (is_confirm) {return;}
  var capacity      = parseInt($('capacity').innerHTML);
  var capacity_all  = parseInt($('capacity_all').innerHTML);
  if (capacity>=capacity_all)
  {
    is_confirm = true;
    var win2 = new cWindow('alert', {'onOk': confirm_close});
    win2.setTitle('Система');
    win2.setContent('Сумка заполнена!');
    win2.show();
    return true;
  }
  location.href = 'index.php?file=inventar_dress&acts=undress&slotId='+clothSlot;
}

function del_table_tr(id)
{
	var tr=document.getElementById(id);
	if (tr)
	{
		var length=tr.cells.length;
		for (f=0; f<(length); f++) {tr.deleteCell(0);}
	}
}

// Получает вещи по кнопке
function getSlots(id, file)
{
	location.href="index.php?file="+file+"&button="+id;
}

//использовать
function used200(id, name)
{
  if (id && !is_confirm)
  {
    is_confirm = true;
    var win = new cWindow('confirm', {'onOk': _used200, 'onCancel': confirm_close}, {'id':id});
    win.setTitle('&nbsp;');
    win.setContent('Использовать «'+name+'» ?');
    win.show();
  }
}
function _used200()
{
  is_confirm = false;
  this.hide();
  location.href = 'index.php?file=inventar&op=use_group_200&slotId='+this.params.id;
}

//скушать
function eat(id, name, cf)
{
	if (id && !is_confirm)
    {
    	is_confirm = true;
		var win = new cWindow('confirm', {'onOk': _eat, 'onCancel': confirm_close}, {'id':id});
        win.setTitle('&nbsp;');
        win.setContent('Съесть «'+name+'» ?');
        win.show();
	}
}
function _eat()
{
	is_confirm = false;
	this.hide();
    location.href = 'index.php?file=inventar_dress&acts=use_food&slotId='+this.params.id;
}

function move(id, name)
{
	if (id && !is_confirm)
    {
		var win = new cWindow('confirm', {'onOk': _move, 'onCancel': confirm_close}, {'id':id});
        win.setTitle('');
        win.setContent('Использовать «'+name+'» ?');
        win.show();
	    is_confirm = true;
	}
}
function _move()
{
	is_confirm = false;
	this.hide();
    location.href = 'index.php?file=inventar&op=used_move&slotId='+this.params.id;
}

// Уничтожить
function trowItem(id, row, from)
{
  if (row == 'infouser')
  {
	var win = new cWindow('confirm', {'onOk': _throw, 'onCancel': confirm_close}, {'id':id, 'row': row});
    win.setTitle('&nbsp;');
    win.setContent('Вы действительно хотите<br>удалить подарок от "'+from+'"?<input type="hidden" id="q'+win.windowElement.id+'" value="1">');
    win.show();
	is_confirm = true;
	return;
  }
  if (id && !is_confirm)
  {
    var qValue = parseInt(document.getElementById('q_slot_'+id).innerHTML);
    if(qValue > 1)
    {
      var win = new cWindow('confirm', {'onOk': _throw, 'onCancel': confirm_close}, {'id':id, 'row': row});
      win.setTitle('&nbsp;');
      win.setContent('Введите сколько вы хотите уничтожить?<br /><input type="text" class="text" style="border: 1px inset #291C0D;width:50px;height:17px; background-color:#EBE4C6;text-align:center;" id="q'+win.windowElement.id+'" value="'+qValue+'">');
      win.show();
    } else
    {
      var win = new cWindow('confirm', {'onOk': _throw, 'onCancel': confirm_close}, {'id':id, 'row': row});
      win.setTitle('&nbsp;');
      win.setContent('Вы точно хотите уничтожить?<input type="hidden" id="q'+win.windowElement.id+'" value="1">');
      win.show();
    }
    is_confirm = true;
  }
  return false;
}
function _throw()
{
  var quantity = $('q' + this.windowElement.id) ? parseInt($('q' + this.windowElement.id).value) : 0;
  is_confirm = false;
  this.hide();
  location.href = 'index.php?file=inventar&row='+this.params.row+'&op=throw&slot='+this.params.id+'&quantity='+quantity;
}

// Одеть
function dress(id, name, cf)
{
  if (id && !is_confirm)
  {
    var old_id = id;
    if (cf && cf == 1)
    {
      var win = new cWindow('confirm', {'onOk': _dress, 'onCancel': confirm_close, 'btnName': 'Одеть'}, {'id':id});
      win.setContent('Эта вещь после одевания,<br>будет привязана к вам общей судьбой');
      win.show();
      is_confirm = true;
    } else
    {
      location.href = 'index.php?file=inventar_dress&acts=dress&slotId='+id;
    }
  }
}

function _dress()
{
    location.href = 'index.php?file=inventar_dress&acts=dress&slotId='+this.params.id;
}

// Изучить
function learn(id, name, open)
{
  if (id && !is_confirm)
  {
    var win = new cWindow('confirm', {'onOk': _learn, 'onCancel': confirm_close}, {'id':id, 'open': open});
    win.setContent('Изучить '+name+'?');
    is_confirm = true;
    win.show();
  }
  return false;
}
function _learn()
{
  this.hide();
  is_confirm = false;
  location.href = 'index.php?file=inventar_dress&acts=study&slotId='+this.params.id+'&open='+this.params.open;
}

function confirm_close()
{
  is_confirm = false;
  this.hide();
}

function urlFarriery(id)
{
  window.location.href='index.php?file=farriery&id='+id+'&act=add';
}

// Распаковать
function unpack(id, name)
{
  if (id && !is_confirm)
  {
    var win = new cWindow('confirm', {'onOk': _unpack, 'onCancel': confirm_close}, {'id':id});
    win.setContent('Распаковать?');
    is_confirm = true;
    win.show();
  }
  return false;
}
function _unpack()
{
  this.hide();
  is_confirm = false;
  location.href = 'index.php?file=inventar&op=unpack&slot='+this.params.id;
}

function present(id, name, cf)
{
  if (id && !is_confirm)
  {
    var win = new cWindow('confirm', {'onOk': _present, 'onCancel': confirm_close}, {'id':id});
    win.setTitle('Подарить');
    win.setContent('<form name="pres"><input type="hidden" name="file" value="inventar"><input type="hidden" name="op" value="present"><input type="hidden" name="slot" value="'+id+'"><span class="txt">Имя адресата:</span><br><input maxlength="30" type="text" class="forma_in txt" name="name" id="name"> <a href="javascript:void(0)" onClick="this.href=\'index.php?file=infouser&login=\'+document.getElementById(\'name\').value; return true;" target="_blank"><img src="'+layout_url+'/xfn/img/inf.gif" alt="Информация" title="Информация" border="0"></a><br><span class="txt">Пожелание: (до 80 символов)</span><br><textarea name="txt" class="txt" style="border:solid 1px #c69c6d; color: #735515; background:#f1deb9;" cols="40" rows="2" onBlur="ismaxlength(this, 80);" onKeyUp="ismaxlength(this, 80);"></textarea></form>');
    is_confirm = true;
    win.show();
  }
  return false;
}
function _present()
{
  this.hide();
  is_confirm = false;
  document.pres.submit();
}

//одевание магии в книгу
function toBook(id, name, cf)
{
  if (id && !is_confirm)
  {
    var qValue = parseInt(document.getElementById('q_slot_'+id).innerHTML);
    if(qValue > 1)
    {
      var win = new cWindow('confirm', {'onOk': _toBook, 'onCancel': confirm_close}, {'id':id});
      win.setContent('&nbsp;');
      win.setContent('Введите сколько вы хотите положить<br>«'+name+'»<br /><input type="text" class="text" style="border: 1px inset #291C0D;width:50px;height:17px; background-color:#EBE4C6;text-align:center;" id="q'+win.windowElement.id+'" value="'+qValue+'">');
      win.show();
    } else
    {
      var win = new cWindow('confirm', {'onOk': _toBook, 'onCancel': confirm_close}, {'id':id});
      win.setContent('&nbsp;');
      win.setContent('Вы точно хотите положить в книгу<br>«'+name+'»?<br><input type="hidden" id="q'+win.windowElement.id+'" value="1">');
      win.show();
    }
    is_confirm = true;
  }
  return false;
}
function _toBook()
{
	var quantity = $('q' + this.windowElement.id) ? parseInt($('q' + this.windowElement.id).value) : 0;
	this.hide();
	is_confirm = false;
	location.href = 'index.php?file=inventar&op=tobook&id='+this.params.id+'&q='+quantity;
}

function fromBook(id, name)
{
    if (id && !is_confirm)
	{
		var win = new cWindow('confirm', {'onOk': _fromBook, 'onCancel': confirm_close}, {'id':id});
		win.setTitle('&nbsp;');
		win.setContent('Удалить из книги<br>«'+name+'»?<br><br><font color="red"><b>Внимание!<br>Доставать магию из Книги и перекладывать в Рюкзак нельзя! Если Вы подтвердите это действие, выбранная магия будет удалена из Вашего Рюкзака!</b></font>');
		is_confirm = true;
		win.show();
	}
}
function _fromBook()
{
  	this.hide();
	is_confirm = false;
	location.href = 'index.php?file=inventar&op=frombook&id='+this.params.id;
}

function toMod(id, name)
{
	if (!is_confirm)
	{
		var win = new cWindow('confirm', {'onOk': _toMod, 'onCancel': confirm_close}, {'id':id});
		win.setTitle('&nbsp;');
		win.setContent('Поместить в корзину<br>«'+name+'»?');
		is_confirm = true;
		win.show();
	}
}
function _toMod()
{
  	this.hide();
	is_confirm = false;
	location.href = 'index.php?file=farriery&p=2&act=tomod&p=2&id='+this.params.id;
}

function repairMod(id, name)
{
	if (!is_confirm)
	{
		var win = new cWindow('confirm', {'onOk': _repairMod, 'onCancel': confirm_close}, {'id':id});
		win.setTitle('&nbsp;');
		win.setContent('Восстановить<br>«'+name+'»?');
		is_confirm = true;
		win.show();
	}
}
function _repairMod()
{
  	this.hide();
	is_confirm = false;
	location.href = 'index.php?file=farriery&p=2&act=repairmod';
}

function fromMod(id, name)
{
	if (!is_confirm)
	{
		var win = new cWindow('confirm', {'onOk': _fromMod, 'onCancel': confirm_close}, {'id':id});
		win.setTitle('&nbsp;');
		win.setContent('Поместить в корзину<br>«'+name+'»?');
		is_confirm = true;
		win.show();
	}
}
function _fromMod()
{
  	this.hide();
	is_confirm = false;
	location.href = 'index.php?file=farriery&act=frommod&p=2&id='+this.params.id;
}

function actMod(id, name)
{
	if (!is_confirm)
	{
		var win = new cWindow('confirm', {'onOk': _actMod, 'onCancel': confirm_close}, {'id':id});
		win.setTitle('&nbsp;');
		win.setContent('Трансформировать<br>«'+name+'»?');
		is_confirm = true;
		win.show();
	}
}
function _actMod()
{
  	this.hide();
	is_confirm = false;
	location.href = 'index.php?file=farriery&act=actmod&p=2';
}

function takeMod(id, name)
{
	if (!is_confirm)
	{
		var win = new cWindow('confirm', {'onOk': _takeMod, 'onCancel': confirm_close}, {'id':id});
		win.setTitle('&nbsp;');
		win.setContent('Забрать<br>«'+name+'»?');
		is_confirm = true;
		win.show();
	}
}
function _takeMod()
{
  	this.hide();
	is_confirm = false;
	location.href = 'index.php?file=farriery&act=takemod&p=2';
}

function toBench(id, name)
{
	if (!is_confirm)
	{
		var win = new cWindow('confirm', {'onOk': _toBench, 'onCancel': confirm_close}, {'id':id});
		win.setTitle('&nbsp;');
		win.setContent('Поместить в корзину<br>«'+name+'»?');
		is_confirm = true;
		win.show();
	}
}
function _toBench()
{
  	this.hide();
	is_confirm = false;
	location.href = 'index.php?file=farriery&p=3&act=tobench&id='+this.params.id;
}

function cncBench(id, name, map)
{
	if (!is_confirm)
	{
		var win = new cWindow('confirm', {'onOk': _cncBench, 'onCancel': confirm_close}, {'id':id, 'map': map});
		win.setTitle('&nbsp;');
		win.setContent('Отменить<br>«'+name+'»?');
		is_confirm = true;
		win.show();
	}
}
function _cncBench()
{
  	this.hide();
	is_confirm = false;
	location.href = 'index.php?file='+this.params.map+'&act=cncbench&p=3&id='+this.params.id;
}

function actBench(id, name, veksel, map)
{
	if (!is_confirm)
	{
		var win = new cWindow('confirm', {'onOk': _actBench, 'onCancel': confirm_close}, {'id':id, 'veksel':veksel, 'map': map});
		win.setTitle('&nbsp;');
		win.setContent('Модифицировать<br>«'+name+'» '+(veksel>0?'<br>за вексель':'')+' ?');
		is_confirm = true;
		win.show();
	}
}
function _actBench()
{
  	this.hide();
	is_confirm = false;
   	var d_color = document.getElementById('d_color').value;
	var d_pref = document.getElementById('d_pref').value;
	var d_suf = document.getElementById('d_suf').value;
	location.href = 'index.php?file='+this.params.map+'&act=actbench&p=3&d_color='+d_color+'&d_pref='+d_pref+'&d_suf='+d_suf+'&v='+this.params.veksel;
}

function takeBench(id, name, map)
{
	if (!is_confirm)
	{
		var win = new cWindow('confirm', {'onOk': _takeBench, 'onCancel': confirm_close}, {'id':id, 'map': map});
		win.setTitle('&nbsp;');
		win.setContent('Забрать<br>«'+name+'»?');
		is_confirm = true;
		win.show();
	}
}
function _takeBench()
{
  	this.hide();
	is_confirm = false;
	location.href = 'index.php?file='+this.params.map+'&act=takebench&p=3';
}

function gUrlOpen(url)
{
	window.open(url);
}

function openBoxPres(id, name)
{
	if (id && !is_confirm)
	{
		var win = new cWindow('confirm', {'onOk': _openBoxPres, 'onCancel': confirm_close}, {'id':id});
		win.setTitle('&nbsp;');
		win.setContent('Открыть<br>«'+name+'»?');
		is_confirm = true;
		win.show();
	}
}
function _openBoxPres()
{
  	this.hide();
	is_confirm = false;
	location.href = 'index.php?file=inventar&op=open110&id='+this.params.id;
}
function aAlert(msg)
{
	if (is_confirm) return;
  var win = new cWindow('alert', {'onOk': confirm_close});
	win.setTitle('Система');
	win.setContent(msg);
	win.show();
  return false;
}

function used101(id, name)
{
	if (id && !is_confirm)
	{
		var win = new cWindow('confirm', {'onOk': _used101, 'onCancel': confirm_close}, {'id':id});
		win.setTitle('&nbsp;');
		win.setContent('Использовать<br>«'+name+'»?');
		is_confirm = true;
		win.show();
	}
}
function _used101()
{
  	this.hide();
	is_confirm = false;
	location.href = 'index.php?file=inventar&op=used101&id='+this.params.id;
}

function used998(id, name)
{
	if (id && !is_confirm)
	{
		var win = new cWindow('confirm', {'onOk': _used998, 'onCancel': confirm_close}, {'id':id});
		win.setTitle('&nbsp;');
		win.setContent('Использовать<br>«'+name+'»?');
		is_confirm = true;
		win.show();
	}
}
function _used998()
{
  	this.hide();
	is_confirm = false;
	location.href = 'index.php?file=inventar&op=used998&id='+this.params.id;
}

function toCage(id, name)
{
	if (id && !is_confirm)
	{
		var win = new cWindow('confirm', {'onOk': _toCage, 'onCancel': confirm_close}, {'id':id});
		win.setTitle('&nbsp;');
		win.setContent('Распаковать<br>«'+name+'»?');
		is_confirm = true;
		win.show();
	}
}
function _toCage()
{
  	this.hide();
	is_confirm = false;
	location.href = 'index.php?file=inventar&op=tocage&id='+this.params.id;
}

function used502(id, name)
{
	if (id && !is_confirm)
	{
		var win = new cWindow('confirm', {'onOk': _used502, 'onCancel': confirm_close}, {'id':id});
		win.setTitle('&nbsp;');
		win.setContent('Открыть<br>«'+name+'»?');
		is_confirm = true;
		win.show();
	}
}
function _used502()
{
  	this.hide();
	is_confirm = false;
	location.href = 'index.php?file=inventar&op=used502&id='+this.params.id;
}

function usedFX(id, name)
{
 if (id && !is_confirm)
	{
    var win = new cWindow('confirm', {'onOk': _usedFX, 'onCancel': confirm_close}, {'id':id});
		win.setTitle('&nbsp;');
		win.setContent('Использовать<br>«'+name+'»?');
		is_confirm = true;
		win.show();
  }
}
function _usedFX()
{
  this.hide();
	is_confirm = false;
  JsHttpRequest.query(
      'GET index.php',
      {
        'file': 'inventar',
        'backend': 1,
        'op': 'usedFX',
        'id': this.params.id
      },
      function(result, debugMessages)
      {
        if (result)
        {
          if (result['status'] && result['status'] == 'ok')
          {
            msg = top.fr_send.m(''+result['h']+'', ''+result['m']+'', 'Система', '3' , 'people' , 'Blue' , ''+result['msg']+'','[]');
		        top.fr_send.writeMsg0(msg,0);
            top.frames['mainT'].hFlash(1);
            parent.frames['LocX'].location='index.php?file=mLoc&refresh=1';
          }
          if (result['msg'] && !is_confirm)
          {
            var win = new cWindow('alert');
		        win.setTitle('Система');
		        win.setContent(result['msg']);
		        win.show();
          }
        }
      }.bind(this),
      true
    );
}

function toSkinner(id, name)
{
	if (id && !is_confirm)
	{
		var win = new cWindow('confirm', {'onOk': _toSkinner, 'onCancel': confirm_close}, {'id':id});
		win.setTitle('&nbsp;');
		win.setContent('Изучить<br>«'+name+'»?');
		is_confirm = true;
		win.show();
	}
}
function _toSkinner()
{
  	this.hide();
	is_confirm = false;
	location.href = 'index.php?file=inventar&op=toSkinner&id='+this.params.id;
}
function toProfession(id, name)
{
	if (id && !is_confirm)
	{
		var win = new cWindow('confirm', {'onOk': _toProfession, 'onCancel': confirm_close}, {'id':id});
		win.setTitle('&nbsp;');
		win.setContent('Изучить<br>«'+name+'»?');
		is_confirm = true;
		win.show();
	}
}
function _toProfession()
{
  	this.hide();
	is_confirm = false;
	location.href = 'index.php?file=inventar&op=toProfession&id='+this.params.id;
}

var id_addPatch = 0;
var id_patch_rune = '';
function addPatchZch_old(id, name)
{
	if (id && !is_confirm)
	{
		var win = new cWindow('confirm', {'onOk': _addPatchZch, 'onCancel': confirm_close}, {'id':id});
		win.setTitle('&nbsp;');
		win.setContent('Использовать<br>«'+name+'»?');
		is_confirm = true;
		win.show();
	}
}
function addPatchZch(id, name)
{
  if (id)
  {
	id_addPatch = id;
	id_patch_rune = name;
	JsHttpRequest.query(
      'GET index.php',
      {
        'file': 'inventar',
        'backend': 1,
        'op': 'addPatchZch',
        'id': id,
        'useItem': '1'
      },
      function(result, debugMessages)
      {
        if (result)
        {
          if (result['msg'] && !is_confirm)
          {
            var winU = new cWindow('alert',{'btnName': 'Закрыть'});
		        winU.setTitle(name);
		        winU.setContent(result['msg']);
		        winU.show();
          }
          if (result['obj'] && !is_confirm)
          {
            for (var ii in result['obj'])
            {
              if (!obgItems[''+ii+''])
              {
                obgItems[''+ii+''] = result['obj'][''+ii+''];
              }
            }
          }
        }
      }.bind(this),
      true
    );
  }
}

function addPatchZchUse(id, name)
{
  if (id)
	{
		var win = new cWindow('confirm', {'onOk': _addPatchZchUse, 'onCancel': confirm_close}, {'id':id});
		win.setTitle(id_patch_rune);
		win.setContent('Использовать на <br>«'+name+'»?');
		is_confirm = true;
		win.show();
	}
}
function _addPatchZchUse()
{
  this.hide();
  is_confirm = false;
	location.href = 'index.php?file=inventar&op=addPatchZch&useItem=2&id_on='+this.params.id+'&id='+id_addPatch;
}

function itemBreak(id, name)
{
  if (id && !is_confirm)
	{
		var win = new cWindow('confirm', {'onOk': _itemBreak, 'onCancel': confirm_close}, {'id':id});
		win.setTitle('Система');
		win.setContent('Разломать<br>«'+name+'»?');
		is_confirm = true;
		win.show();
	}
}

function _itemBreak()
{
  this.hide();
  is_confirm = false;
	location.href = 'index.php?file=profession&prf=3&brk=1&id_break_item='+this.params.id;
}

function addUnBind(id, name)
{
  if (id && !is_confirm)
	{
		var win = new cWindow('confirm', {'onOk': _addUnBind, 'onCancel': confirm_close}, {'id':id});
		win.setTitle('Система');
		win.setContent('Добавить<br>«'+name+'»?');
		is_confirm = true;
		win.show();
	}
}
function _addUnBind()
{
  this.hide();
  is_confirm = false;
	location.href = 'index.php?file=farriery&p=4&add=1&id_item='+this.params.id;
}

function putToCover(id, name, f)
{
	if (id && !is_confirm)
	{
		var win = new cWindow('confirm', {'onOk': _putToCover, 'onCancel': c_close}, {'id':id, 'f':f});
		win.setTitle('Система');
		win.setContent('Добавить<br>«'+name+'»?');
		win.show();
		is_confirm = true;
	}
}
function _putToCover()
{
	this.hide();
	is_confirm = false;
	location.href = 'index.php?file='+this.params.f+'&type=3&add_cover=1&id='+this.params.id+getNameTxt();
}

function takeFromCover(id, name, f)
{
	if (id && !is_confirm)
	{
		var win = new cWindow('confirm', {'onOk': _takeFromCover, 'onCancel': c_close}, {'id':id, 'f':f});
		win.setTitle('Система');
		win.setContent('Забрать<br>«'+name+'»?');
		win.show();
		is_confirm = true;
	}
}
function _takeFromCover()
{
	this.hide();
	is_confirm = false;
	location.href = 'index.php?file='+this.params.f+'&type=3&del_cover=1&id='+this.params.id+getNameTxt();
}

function putToCoverItem(id, name, f)
{
	if (id && !is_confirm)
	{
		var qValue = parseInt(document.getElementById('q_slot_'+id).innerHTML);
		if(qValue > 1)
		{
		  var win = new cWindow('confirm', {'onOk': _putToCoverItem, 'onCancel': c_close}, {'id':id, 'f':f});
		  win.setTitle('&nbsp;');
		  win.setContent('Введите сколько вы хотите добавить?<br /><input type="text" class="text" style="border: 1px inset #291C0D;width:50px;height:17px; background-color:#EBE4C6;text-align:center;" id="q'+win.windowElement.id+'" value="'+qValue+'">');
		  win.show();
		} else
		{
		  var win = new cWindow('confirm', {'onOk': _putToCoverItem, 'onCancel': c_close}, {'id':id, 'f':f});
		  win.setTitle('&nbsp;');
		  win.setContent('Добавить?<input type="hidden" id="q'+win.windowElement.id+'" value="1">');
		  win.show();
		}
		is_confirm = true;
	}
}
function _putToCoverItem()
{
	var quantity = $('q' + this.windowElement.id) ? parseInt($('q' + this.windowElement.id).value) : 0;
	this.hide();
	is_confirm = false;
	location.href = 'index.php?file='+this.params.f+'&type=3&add_present=1&id='+this.params.id+'&q='+quantity+getNameTxt();
}

function takeFromCoverItem(id, name, f)
{
	if (id && !is_confirm)
	{
		var qValue = parseInt(document.getElementById('q_slot_'+id).innerHTML);
		if(qValue > 1)
		{
		  var win = new cWindow('confirm', {'onOk': _takeFromCoverItem, 'onCancel': c_close}, {'id':id, 'f':f});
		  win.setTitle('&nbsp;');
		  win.setContent('Введите сколько вы хотите отменить?<br /><input type="text" class="text" style="border: 1px inset #291C0D;width:50px;height:17px; background-color:#EBE4C6;text-align:center;" id="q'+win.windowElement.id+'" value="'+qValue+'">');
		  win.show();
		} else
		{
		  var win = new cWindow('confirm', {'onOk': _takeFromCoverItem, 'onCancel': c_close}, {'id':id, 'f':f});
		  win.setTitle('&nbsp;');
		  win.setContent('Отменить?<input type="hidden" id="q'+win.windowElement.id+'" value="1">');
		  win.show();
		}
		is_confirm = true;
	}
}
function _takeFromCoverItem()
{
	var quantity = $('q' + this.windowElement.id) ? parseInt($('q' + this.windowElement.id).value) : 0;
	this.hide();
	is_confirm = false;
	location.href = 'index.php?file='+this.params.f+'&type=3&del_present=1&id='+this.params.id+'&q='+quantity+getNameTxt();
}

function c_close()
{
  is_confirm = false;
  this.hide();
}

function getNameTxt()
{
  var to = document.getElementById('to').value;
  var txt = document.getElementById('txt').value;
  return '&to='+to+'&txt='+txt;
}

function openCover(id, name)
{
	if (id && !is_confirm)
	{
		var win = new cWindow('confirm', {'onOk': _openCover, 'onCancel': c_close}, {'id':id});
		win.setTitle('&nbsp;');
		win.setContent('Открыть «'+name+'»?');
		win.show();
		is_confirm = true;
	}
}
function _openCover()
{
	this.hide();
	is_confirm = false;
	location.href = 'index.php?file=infouser&openCover=1&id='+this.params.id;
}
function openCoverPunish(id, name)
{
	if (id && !is_confirm)
	{
		var win = new cWindow('confirm', {'onOk': _openCoverPunish, 'onCancel': c_close}, {'id':id});
		win.setTitle('&nbsp;');
		win.setContent('Открыть «'+name+'»?');
		win.show();
		is_confirm = true;
	}
}
function _openCoverPunish()
{
	this.hide();
	is_confirm = false;
	location.href = 'index.php?file=infouser&openCover=2&id='+this.params.id;
}
