
function new_freecap()
{
	// loads new freeCap image
	if(document.getElementById)
	{
		// extract image name from image source (i.e. cut off ?randomness)
		thesrc = document.getElementById("freecap").src;
		thesrc = thesrc.substring(0,thesrc.lastIndexOf(".")+4);
		// add ?(random) to prevent browser/isp caching
		document.getElementById("freecap").src = thesrc+"?"+Math.round(Math.random()*100000);
	} else {
		alert("Sorry, cannot autoreload freeCap image\nSubmit the form and a new freeCap will be loaded");
	}
}

function setAdventureCreateNumPaths() {
	var el = document.getElementById('numoptions');
	var path1 = document.getElementById('path1wrapper');
	var path2 = document.getElementById('path2wrapper');
	var path3 = document.getElementById('path3wrapper');
	path1.style.display = 'block';
	path2.style.display = 'block';
	path3.style.display = 'block';
	if (el.value < 3)
		path3.style.display = 'none';
	if (el.value < 2)
		path2.style.display = 'none';
	if (el.value < 1)
		path1.style.display = 'none';
}

function showAdminControls() {
	var showac = document.getElementById('showadmincontrols');
	var ac = document.getElementById('admincontrols');
	showac.style.display = 'none';
	ac.style.display = 'block';
}

function popupwin(url, h, w) {
	var load = window.open(url,'','scrollbars=no,menubar=no,height=' + h + ',width=' + w + ',resizable=yes,toolbar=no,location=no,status=no');
	return false;
}

function showanswer(answer) {
	alert(answer);
	return false;
}

function replaceButtonText(buttonId, text)
{
  if (document.getElementById)
  {
    var button=document.getElementById(buttonId);
    if (button)
    {
	  button.disabled=true;
      if (button.childNodes[0])
      {
        button.childNodes[0].nodeValue=text;
      }
      else if (button.value)
      {
        button.value=text;
      }
      else //if (button.innerHTML)
      {
        button.innerHTML=text;
      }
    }
  }
}

var itemsInCart = 0;
var bigCart = 0;
function addItemToCart(buttonId)
{
	if (buttonId == 'addcart3b')
	{
		bigCart = 1;
		alert('You carefully transfer your purchases to your new online cart, and return the old one to the cart collection area.');
	}
	if (itemsInCart < 3 || bigCart == 1)
	{
		replaceButtonText(buttonId, 'Added');
		itemsInCart++;
		if (itemsInCart == 3 && bigCart == 0)
		{
			alert('You have a very small online cart, and it is now full. You may want to buy a bigger one.');
			var obj = document.getElementById('buycart');
			obj.style.display = 'block';
		}
	}
	else
		alert('You try to fit this item in your online cart, but it falls out. You pick it up off the online floor, and put it back on the online shelf. You may want to buy a bigger online cart.');
}

function showforum ()
{
	var obj = document.getElementById('hiddenforum');
	obj.style.display = 'block';
}
