$(document).ready(function() {
});

var d; // save description with br, to use if cancel
function editDescription(){
	des = $("#description_hidden").html();
	d = $("#description").html(); // with <br />
	w = $("#description").width();
	h = $("#description").height();
	
	if(h < 100)
		h = 100;
		
	$("#edit_button").hide();
	$("#description").html('<textarea style="width:'+w+'px;height:'+h+'px" id="description_area">'+des+'</textarea>');
	$("#description").append('<div><input type="button" value="Change" onclick="changeDescription()"/><input type="button" value="Cancel" onclick="cancelDescription()"/></div>');	
}

function changeDescription(){
	d = $("#description_area").val();
	$.ajax({
	    url: 'controller/profile/editable.php',
		data: 'content='+d,
	    type: 'POST',
	    dataType: 'html',
	    timeout: 20000,
	    error: function(XMLHttpRequest, textStatus, errorThrown){
	        alert('Some problem occurred while trying to update your profile description: '+textStatus);
	    },
	    success: function(j){
			if(d == "")
				d = 'This artist has no description';
			$("#description").html(j.replace(/\n/g,'<br />'));
			$("#description_hidden").html(j);
			$("#edit_button").show();
	    }
	});
		
}

function cancelDescription(){
	$("#description").html(d);
	$("#edit_button").show();
}