function goto(template, value)
{
	if(value.id == 0)
		return
	var myTemplate = new Template(template);
	window.location = myTemplate.evaluate(value);
}
function gotodelete(template, value)
{
	if(value.id == 0)
		return
	console.log(template, value);
	if(confirm('Are you sure you want to delete this?'))
	{
		var myTemplate = new Template(template);
		window.location = myTemplate.evaluate(value);
	}
}
function showOrder(id)
{
	$$('.order').invoke('hide');
	$('order-' + id).show();
}

Event.observe(window, 'load', function(){
	setTimeout('clearAlerts();', 1000);
	$$('.alert').each(function(el){
		Event.observe(el, 'click', function(){clearAlerts();});
	});
});

function clearAlerts()
{
	$$('.alert').each(function(el){
		new Effect.Fade(el);
	});
}

function money(mnt)
{
    mnt -= 0;
    mnt = (Math.round(mnt*100))/100;
    return (mnt == Math.floor(mnt)) ? mnt + '.00' 
              : ( (mnt*10 == Math.floor(mnt*10)) ? 
                       mnt + '0' : mnt);
}
function clearDropdown(id)
{
	$(id).innerHTML = '';
}
function updateDropdown(id, values)
{
	var k = 0;
	for(i in values)
	{
		if(typeof values[i] == "object")
		{
			var optgroup = document.createElement('optgroup');
			optgroup.label = i;
			for(j in values[i])
			{
				var option = document.createElement('option');
				option.value = j;
				option.innerHTML = values[i][j];
				optgroup.appendChild(option);
			}
			$(id).appendChild(optgroup);
		}
		else if(typeof values[i] == "string")
		{
			var option = document.createElement('option');
			option.value = i;
			option.innerHTML = values[i];
			$(id).appendChild(option);
		}
	}
	$(id).options.selectedIndex = 0;
}
