function sendPostcard() {
	// Pull the values out of the form to be sent up to the server.
	var params = {
		fromName:		$("fromName").value,
		fromAddress:	$("fromAddress").value,
		toName:			$("toName").value,
		toAddress:		$("toAddress").value,
		type:			$("type").value
	};
	params = JSON.encode(params);

	var req = new Request.JSON({
		url:		"http://getanimated.iinet.net.au/cgi-bin/send-postcard.cgi",
		method:		"post",
		data:		params,
		urlEncoded:	0,
		isSuccess:	function() { return true; },
		onComplete:	function(ret) {
			/* This function handles the return from the postcard CGI script.
			 * The ret parameter will contain ret.success, which will be either
			 * 0 or 1 depending on whether the request was successful, and
			 * optionally ret.message if the request failed, which will contain
			 * an error message. */

            var message;
			if (ret.success == 0 && ret.message) {
                message = "Sorry, we couldn't send your message at this time. " + ret.message;
			}
			else {
                message = "A postcard has been sent to " + $("toName").value + " on your behalf.";
			}

            var contentArea = $("postcard_form");
            var fader = new Fx.Tween(contentArea);
            fader.addEvent("complete", function() {
                contentArea.set("text", message);
                contentArea.fade("in");
            });
            fader.start("opacity", 0);
		}
	});
	req.setHeader("Content-Type", "text/javascript");
	req.send();

	// Stop the form submission going through and reloading the page.
	return false;
}

function updatePostcardThumb(select) {
    var thumbnail = select.options[select.selectedIndex].getAttribute("thumbnail");
    
    // Start the image loading.
    var image = $(document).createElement("img");
    image.src = thumbnail;

    var preview = $("preview");
    var fader = new Fx.Tween(preview);
    fader.addEvent("complete", function() {
        preview.src = thumbnail;
        preview.fade("in");
    });
    fader.start("opacity", 0);
}

// vim: set cin ai ts=4 sw=4 et:
