function posttocart($formobject){
	var url = '/cart/add';
	new Ajax.Request(url, {
		method: 'post',
		postBody : Form.serialize($formobject), 
		onSuccess: function(transport) {
			$('shop-cart').innerHTML=transport.responseText;
		},
		onFailure: function(transport) {
			$('shop-cart').innerHTML="fail.";
		}
	});
}

function slugomatic(fromInput, toInput)
{
	text = $(fromInput).value;
	text = text.replace(/^\s+|\s+$/g, '').replace(/[^\w ]/g,'').replace(/ +/g,'').substr(0, 50);
	$(toInput).value = text.toLowerCase();
}  

function launchImageManager($element) {
	mcImageManager.open(
		'form', 
		$element, 
		'', 
		'', 
		{
			document_base_url : "/",
			relative_urls : true,
			remove_script_host : true
		}
	);
}

function changeImage(url,target) {
	$( target ).innerHTML = "<img src=\"/image.php?file=/" + url + "&width=160&height=160\"  />";
	return true;		
}

Event.observe(window, 'load', function() {
	if($('thumbnail') && $('thumbnail').value != "") {
		$('thumbnail_image').innerHTML = "<img src=\"/image.php?file=" + $('thumbnail').value + "&width=160\" alt=\"\" />";
	}
	if($('heroimage') && $('heroimage').value != "") {
		$('hero_image').innerHTML = "<img src=\"/image.php?file=" + $('heroimage').value + "&width=160\" alt=\"\" />";
	}
	new Ajax.Updater('shop-cart', '/cart/');
}); 

