var prev_selected = new Array();

function changePrice(amount,name)
{
    if(typeof(amount) == 'undefined') {
	amount = 0;
    }

    //alert(' amount = ' + amount + ' name = ' + name +  ' oldvalue = ' + prev_selected[name]);
    var price = document.getElementById('price').innerHTML;
    var newprice = price;
    if(prev_selected[name] != 0) {
	if(prev_selected[name] < 0) {
		var undo = price + "+" + Math.abs(prev_selected[name]);		
	} else {
		var undo = price + "-" + prev_selected[name];
	}
	//alert('undoing with ' + undo);
	newprice = eval(undo);
    }
    if(amount > 0) {
    	var func = newprice + "+" + amount;
    } else {
    	var func = newprice + amount;
    }
    //alert('doing ' + func);
    newprice = eval(func);
    document.getElementById('price').innerHTML=newprice.toFixed(2);
    document.getElementById('pricebottom').innerHTML=newprice.toFixed(2);
    if(document.getElementById('pricediv') != null && document.getElementById('pricediv').firstChild != null) {
    	document.getElementById('pricediv').firstChild.nodeValue=newprice.toFixed(2);
    }
    prev_selected[name] = amount;
}

function changeDisplay(id,value,pcode)
{
    document.getElementById(id).innerHTML=value;
    if(typeof(pcode) != 'undefined') {
	var url = "/store/shop.php?p=" + pcode + ".html";
	document.getElementById(id).href=url;
    }
}

function changeThumbnail(imageField,image)
{
    	if(typeof(image) == 'undefined') {
		var newimage = "/images/spacer.gif";
	} else {
		var newimage = "/images/" + image;
	}
	imageField.src = newimage;
}
