var xmlhttp

function unequip(type)
{

xmlhttp=GetXmlHttpObject();

if (xmlhttp==null)
  {
  alert ("Your browser does not support XMLHTTP!");
  return;
  }

var url="game.php?view=unequip";
url=url+"&type="+type;
url=url+"&sid="+Math.random();

if (xmlhttp.readyState==4)
  {
  document.getElementById(type).innerHTML=xmlhttp.responseText;
  }

xmlhttp.open("GET",url,true);
xmlhttp.send(null);

if(type=='weapon') {
	loadtext = '<img src="/images/quest/items/weapons/noweapon.gif" align="left" style="margin-right: 5px;" /><strong>No weapon</strong><br />Go to your <a href="game.php?view=inventory">inventory</a> to equip a weapon';
} else {
	loadtext = '<img src="/images/quest/items/armor/noarmor.gif" align="left" style="margin-right: 5px;" /><strong>No armor</strong><br />Go to your <a href="game.php?view=inventory">inventory</a> to wear armor';
}
	document.getElementById(type).innerHTML=loadtext;

//xmlhttp.onreadystatechange=stateChanged(type);
  
}

function hidenote(noteid, hideall)
{

xmlhttp=GetXmlHttpObject();

if (xmlhttp==null)
  {
  alert ("Your browser does not support XMLHTTP!");
  return;
  }

var url="game.php?view=hidenote";

if(hideall == 1) {
	url=url+"&all=true";
} else {
	url=url+"&id="+noteid;
}

url=url+"&sid="+Math.random();

xmlhttp.open("GET",url,true);
xmlhttp.send(null);

if(hideall == 1) {
	document.getElementById('allnotifications').className='inventory_blank';
} else {
	document.getElementById('notification_'+noteid).className='inventory_blank';
}

//xmlhttp.onreadystatechange=stateChanged(type);
  
}

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}

function sellitem(itemid) {
	var quantity = prompt("How many would you like to sell?","1");
	document.location = 'game.php?view=sell&id='+itemid+'&quantity='+quantity;
}

function tradeitem(itemid) {
	var quantity = prompt("How many would you like to trade?","1");
	document.location = 'game.php?view=trade&doid='+itemid+'&quantity='+quantity;
}

function removetrade(itemid, tradeid) {
	var quantity = prompt("How many would you like to remove?","1");
	document.location = 'game.php?view=trade&act=edit&do=remove&tradeid='+tradeid+'&itemid='+itemid+'&quantity='+quantity;
}

function addtrade(itemid, tradeid) {
	var quantity = prompt("How many would you like to add?","1");
	document.location = 'game.php?view=trade&act=edit&do=add&tradeid='+tradeid+'&itemid='+itemid+'&quantity='+quantity;
}

function removeoffer(itemid, offerid) {
	var quantity = prompt("How many would you like to remove?","1");
	document.location = 'game.php?view=trade&act=offers&do=remove&offerid='+offerid+'&itemid='+itemid+'&quantity='+quantity;
}

function addoffer(itemid, offerid) {
	var quantity = prompt("How many would you like to add?","1");
	document.location = 'game.php?view=trade&act=offers&do=add&offerid='+offerid+'&itemid='+itemid+'&quantity='+quantity;
}

function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}

function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}

function inventory(type, posid, name, npc, equipable) {
	
	if(document.getElementById('item_'+posid).className == 'inventory_selected' && document.getElementById('inventory_info').alt == posid) {
		
		document.getElementById('item_'+posid).className='inventory';
		document.getElementById('inventory_info').className='inventory_blank';
		
	} else {
		
		document.getElementById('item_'+posid).className='inventory_selected';
		document.getElementById('inventory_info').className='inventory_item';
		document.getElementById('inventory_info').alt=posid;
		
		if(type == 'weapon' || type == 'armor') {
			
			if(equipable == 0) {
				equiptext=', Your level is not high enough to equip this item';
			} else {
				equiptext=", <a href=\"game.php?view=equip&id="+posid+"\">Equip item</a>";
			}
			
			document.getElementById('inventory_info').innerHTML=document.getElementById('itemimg_'+posid).innerHTML+"<strong style=\"margin-left: 5px;\">"+name+"</strong><br /><span style=\"cursor: pointer; margin-left: 5px;\" onclick=\"sellitem('"+posid+"')\">Sell for "+npc+" credits</span>, <span style=\"cursor: pointer;\" onclick=\"tradeitem('"+posid+"')\">Trade item</span>"+equiptext+"";
		} else {
			document.getElementById('inventory_info').innerHTML=document.getElementById('itemimg_'+posid).innerHTML+"<strong style=\"margin-left: 5px;\">"+name+"</strong><br /><span style=\"cursor: pointer; margin-left: 5px;\" onclick=\"sellitem('"+posid+"')\">Sell for "+npc+" credits</span>, <span style=\"cursor: pointer;\" onclick=\"tradeitem('"+posid+"')\">Trade item</span>";
		}
		
	}
	
}

function storebuy(itemid) {
	var quantity = prompt("How many would you like to buy?","1");
	document.location = 'game.php?view=store&id='+itemid+'&quantity='+quantity;
}