var startDate;

$(document).ready(onLoad);

// once the document is loaded
function onLoad() {

	// hide the results for now
	$("#results").hide();
	
	// when the encode or decode button is clicked do stuff
	$("#encode").click(encodeClicked);
	$("#decode").click(decodeClicked);
}

// encode has been clicked
function encodeClicked() {

	// query the encoder
	$.post("base64.php", { 
		method: "encode", 
		data: $("#data").attr("value")
	}, function(xml) { resultsRetrieved(xml) }, "xml");
}

// decode has been clicked
function decodeClicked() {

	// query the decoder
	$.post("base64.php", { 
		method: "decode", 
		data: $("#data").attr("value")
	}, function(xml) { resultsRetrieved(xml) }, "xml");
}

// the requested XML has been received
function resultsRetrieved(xml) {

	// get the data from the XML
	root = $("base64", xml);
	method = root.find("method").text();
	data = root.find("data").text();
	result = root.find("result").text();

	// set context of various nodes in the HTML
	$("#results-data").html(result);

	// show the results div
	$("#results").show();
	$("#results-bottom").show();
}