function displayShop(ret) {
var tmphtml = "
Select an item to buy it:
";
for(var key in ret.items){
if(ret.items.hasOwnProperty(key)){
var category = ret.items[key];
tmphtml += "";
tmphtml += "
"+key+"
";
tmphtml += "
";
for(var i=0; i < category.length; i++) {
tmphtml += "- ";
tmphtml += "";
tmphtml += "
";
}
tmphtml += "
";
tmphtml += "
";
}
}
document.getElementById("tab2").innerHTML = tmphtml;
}
function displayInventory(items) {
for(var i=0; i < items.length; i++) {
addItem(items[i]);
}
}
function buildShop() {
sendRequest("craftmine.php", "op=buildShop", function(ret) {
displayShop(ret);
debitAccount(ret.cost);
});
}
function addItem(ret) {
var itemhtml = "";
itemhtml += "";
itemhtml += "";
var invcontent = document.getElementById("tab3");
if(invcontent.children.length <= 1)
{
var tmphtml = "Your bag contains the following items:
";
tmphtml += "";
tmphtml += itemhtml;
tmphtml += "
"
invcontent.innerHTML = tmphtml;
} else
invcontent.getElementsByTagName('ul')[0].innerHTML += itemhtml;
showInfo("The "+ ret.name + " has been successfully purchased");
}
function buyItem(name) {
sendRequest("craftmine.php", "op=buyItem&item="+name, function(ret) {
addItem(ret);
debitAccount(ret.cost);
});
}
function useItem(name) {
sendRequest("craftmine.php", "op=useItem&item="+name, function(ret) {
});
}