	function show_uploadForm() {
		show_html('upload');
	}
	
	function show_emailForm(id) {
		show_window();
		$.ajax({
			type: "GET",
			url: "themes/cp2/ajaxer.php",
			data: "c=data&key=email&paste_id=" + id,
			success: function(msg) {
				//check the data that came back
				$('#float_panel').append(msg);
			},
			error: function(XMLHttpRequest, textStatus, errorThrown) {
				$('#float_panel').append('<p class="error">Error communicating with server: ' + textStatus + errorThrown + "</p>");
			},
			complete: function(XMLHttpRequest, textStatus) {
				$('#float_panel').removeClass('loading');
			}
		});
		return false;		
	}
	
	//ajax saves, and notifies via alert
	function save_paste(key) {
	$('#status').addClass('loading');
		status('saving...');
		var postdata = {
			c: "save",
			a: "revise",
			'key': key,
			"code": editAreaLoader.getValue('code_holder')
		};
		$.ajax({
			type: "POST",
			url: "ajaxer.php",
			data: postdata, //"c=save&a=branch&key=" + key + "&code=" + editAreaLoader.getValue('code_holder'),
			success: function(msg) {
				var data = dejson(msg);
				if (data.result) {
					status('saved!');
				} else {
					status('error: ' + data.data);
				}	
			},
			error: function(XMLHttpRequest, textStatus, errorThrown) {
				status('Error communicating with server: ' + textStatus + errorThrown + "");
			},
			complete: function(XMLHttpRequest, textStatus) {
				//$('#status').removeClass('loading');
			}
		});
		return false;
	}
	
	//posts?
	function save_branch(key) {
		$('#status').addClass('loading');
		status('saving...');
		var postdata = {
			c: "save",
			a: "branch",
			'key': key,
			'name': $('input[name=name]').val(),
			'language': $('select[name=language]').val(),
			"code": editAreaLoader.getValue('code_holder')
		};
		$.ajax({
			type: "POST",
			url: "ajaxer.php",
			data: postdata, //"c=save&a=branch&key=" + key + "&code=" + editAreaLoader.getValue('code_holder'),
			success: function(msg) {
				var data = dejson(msg);
				if (data.result) {
					status('saved! redirecting...');
					document.location = 'index.php?paste_id=' + data.data;
				} else {
					status('error: ' + data.data);
				}	
			},
			error: function(XMLHttpRequest, textStatus, errorThrown) {
				status('Error communicating with server: ' + textStatus + errorThrown + "");
			},
			complete: function(XMLHttpRequest, textStatus) {
				//$('#status').removeClass('loading');
			}
		});
		return false;
	}

	
	function show_html(key) {
		//alert('showing properties for page ' + page_id);
		show_window();
		$.ajax({
			type: "GET",
			url: "themes/cp2/ajaxer.php",
			data: "c=data&key=" + key,
			success: function(msg) {
				//check the data that came back
				$('#float_panel').append(msg);
			},
			error: function(XMLHttpRequest, textStatus, errorThrown) {
				$('#float_panel').append('<p class="error">Error communicating with server: ' + textStatus + errorThrown + "</p>");
			},
			complete: function(XMLHttpRequest, textStatus) {
				$('#float_panel').removeClass('loading');
			}
		});
		return false;

	}

	
	function show_pasteProperties(key) {
		show_window();
		$.ajax({
			type: "GET",
			url: "ajaxer.php",
			data: "c=paste_properties&paste_id=" + key,
			success: function(msg) {
				//check the data that came back
				$('#float_panel').append(msg);
			},
			error: function(XMLHttpRequest, textStatus, errorThrown) {
				$('#float_panel').append('<p class="error">Error communicating with server: ' + textStatus + errorThrown + "</p>");
			},
			complete: function(XMLHttpRequest, textStatus) {
				$('#float_panel').removeClass('loading');
			}
		});
		return false;
	}
	
	function remove_publicKey(key) {
		$('.key_list').empty().addClass('loading');
		$.ajax({
			type: "GET",
			url: "ajaxer.php",
			data: "c=public_key&a=remove&key=" + key,
			success: function(msg) {
				var data = dejson(msg);
				if (data.result) {
					var out = "<table>";
					for(var i=0; i < data.data.length; i++) {
						var key = data.data[i];
						out += "<tr><td class=\"key\">" + key + "</td><td class=\"options\"><a href=\"#\" onclick=\"if (confirm('Remove this key?')) remove_publicKey('" + key + "');\">x</a></td></tr>\n";
					}
					out += "</table>";
					$('.key_list').html(out);
										
				} else {
					$('.key_list').html('<p class="error">An unknown error has occured. TBH, this should not have happened.</p>');
				}
			},
			error: function(XMLHttpRequest, textStatus, errorThrown) {
				$('.key_list').html('<p class="error">Error communicating with server: ' + textStatus + errorThrown + "</p>");
			},
			complete: function(XMLHttpRequest, textStatus) {
				$('.key_list').removeClass('loading');
			}
		});
		return false;
	
	}
	
		function add_key(form) {
		//add key
		//load key list
		var key = $(form).find('input[name=key]').val();
		if (key.length != 32	) {
			alert('keylength must be whatsit... greater, probably? (32 chars)');
			return false;
		}
		//maybe move this function out
		//into an add key list function?
		$('.key_list').empty().addClass('loading');
		$.ajax({
			type: "GET",
			url: "ajaxer.php",
			data: "c=public_key&a=add&key=" + key,
			success: function(msg) {
				var data = dejson(msg);
				if (data.result) {
					var out = "<table>";
					for(var i=0; i < data.data.length; i++) {
						var key = data.data[i];
						out += "<tr><td class=\"key\">" + key + "</td><td class=\"options\"><a href=\"#\" onclick=\"if (confirm('Remove this key?')) remove_publicKey('" + key + "');\">x</a></td></tr>\n";
					}
					out += "</table>";
					$('.key_list').html(out);
										
				} else {
					$('.key_list').html('<p class="error">An unknown error has occured. TBH, this should not have happened.</p>');
				}
			},
			error: function(XMLHttpRequest, textStatus, errorThrown) {
				$('.key_list').html('<p class="error">Error communicating with server: ' + textStatus + errorThrown + "</p>");
			},
			complete: function(XMLHttpRequest, textStatus) {
				$('.key_list').removeClass('loading');
			}
		});
		return false;
	
	}
	
	function show_publicKeys(paste_id) {
		show_window();
		//maybe move this function out
		//into an add key list function?
		$.ajax({
			type: "GET",
			url: "ajaxer.php",
			data: "c=public_key",
			success: function(msg) {
				var data = dejson(msg);
				if (data.result) {
					var out = "<div class=\"padder\">";
					out +="<div class=\"key_list\">";
					out += "<table>";
					for(var i=0; i < data.data.length; i++) {
						var key = data.data[i];
						out += "<tr><td class=\"key\">" + key + "</td><td class=\"options\"><a href=\"#\" onclick=\"if (confirm('Remove this key?')) remove_publicKey('" + key + "');\">x</a></td></tr>\n";
					}
					out += "</table>";
					out += "</div>";
					out += "<form method=\"post\" action=\"index.php\" onsubmit=\"add_key(this); return false;\">";
					out += "<fieldset><legend>Add a public key</legend>";
					out += "<input type=\"hidden\" name=\"c\" value=\"public_key\" />";
					out += "<input type=\"hidden\" name=\"a\" value=\"add\" />";
					out += "<input type=\"text\" name=\"key\" style=\"width: 400px;\" />";
					out += "</fieldset>";
					out += "<input type=\"submit\" class=\"button\" value=\"Add the key\" />";
					out += "<input type=\"button\" class=\"button\" value=\"Refresh the page\" onclick=\"document.location='index.php?paste_id="+paste_id+"';\"/>";
					out += "</form>";
					
					
					
					out += "</div>";
					$('#float_panel').append(out);
					
					//add form
					//refresh page (use paste_id)
					
				} else {
					$('#float_panel').append('<p class="error">An unknown error has occured. TBH, this should not have happened.</p>');
				}
			},
			error: function(XMLHttpRequest, textStatus, errorThrown) {
				$('#float_panel').append('<p class="error">Error communicating with server: ' + textStatus + errorThrown + "</p>");
			},
			complete: function(XMLHttpRequest, textStatus) {
				$('#float_panel').removeClass('loading');
			}
		});
		return false;
	}
	
	
	function mail_form(f) {
	
		status('Mailing...');
		var paste_id = $(f).find('input[name=paste_id]').val();
		var name = $(f).find('input[name=name]').val();
		var email = $(f).find('input[name=email]').val();
		var data_string = 'paste_id=' + paste_id + '&name=' + name + '&email=' + email;
		$.ajax({
			type: "GET",
			url: "email.php",
			data: ""			+ data_string,
			success: function(msg) {
				//check the data that came back
				var data = dejson(msg);
				if(data.result) {
					status('Success!');
					console_write('Email sent!');
					hide_window();
				} else {
					status('Email could not be sent.');
					error(data.data);
				}
			},
			error: function(XMLHttpRequest, textStatus, errorThrown) {
				status('Communication error!');
				error('Error communicating with server: ' + textStatus + errorThrown);
			},
			complete: function(XMLHttpRequest, textStatus) {
				status_clear();
			}
		});
	
		return false;	
	}

	

	function show_window() {
		$('#float_panel :not(:first-child)').remove();
		$('#float_panel').show('normal').addClass('loading');
		$('#body').addClass('unfocused');
	}
	
	function hide_window() {
		$('#float_panel').hide('normal');
		$('#body').removeClass('unfocused');
	}
	
	function status(str) {
	$('#status').text(str).addClass('loading');
}

function status_clear() {
	$('#status').empty().removeClass('loading');
}
