var cat = "";
function ajaxXML(urlPost, dataPost, successFunc, errorFunc) {
	$.ajax({
		  url: urlPost,
		  type: "POST",
		  data: dataPost,
		  dataType: "xml",
		  success: successFunc,
		  error: errorFunc
	   }
	);
}

function listMovies(xml) {
	$("div#result ul").remove();
	$("div#result").append($("<ul></ul>"));
	$("movies item", xml).each(function(){
		var newRow = $("<li></li>");
		var newAnchor = $("<a></a>");
		var newDiv = $("<div></div>");
		var dateDiv = $("<div></div>");
		var newImg = $("<img></img>");
		var oid = $("oid", this).text();
		var title = $("title", this).text();
		var image = $("image", this).text();

		newAnchor.attr("href", "/new.jsp?oid=" + oid);

		newImg.attr("src", "/" + image);
		newDiv.append(newImg);
		newDiv.append(title);
		dateDiv.html($("date", this).text());
		newDiv.append(dateDiv);
		newAnchor.append(newDiv);
		newRow.html(newAnchor);
		$("div#result ul").append(newRow);
	});
}

function error(xml) {
	alert("Något gick fel, testa igen!");
}

function getMovies(value) {
	ajaxXML("/actions/getMovies.jsp", "&cat=" + value, listMovies, error);
}