function add_tag(tag, type, input) {
	var content_area = document.post_form.content;
	
	var startpos = content_area.selectionStart;
	var endpos = content_area.selectionEnd;
	var text = content_area.value.slice(startpos,endpos);
	var start_slice = content_area.value.slice(0,startpos);
	var end_slice = content_area.value.slice(endpos);
	
	if (type == 1) {
		var insert_tag = "[" + tag + "]" + text + "[/" + tag + "]";
	}
	
	if (type == 2) {
		if (tag == "color") {
			var input = prompt("Specify a font color:","")
		}
		if (!input) {
			alert("You must enter a value.");
			return false;
		}
		var insert_tag = "[" + tag + "=" + input + "]" + text + "[/" + tag + "]";
	}

	if (type == 3) {
		if (tag == "link") {
			var input = prompt("Specify a URL:","http://")
		}
		if (tag == "image") {
			var input = prompt("Specify the image URL:","http://");
		}
		if (tag == "mail") {
				var input = prompt("Specify an email address:","");
		}		
		if (!input) {
			alert("You must enter a value.");
			return false;
		}
		var insert_tag = "[" + tag + "=" + input + "]" + input + "[/" + tag + "]";
	}
	
	if (type == 4) {
		if (tag == "image") {
			var input = prompt("Specify the image URL:","http://");
		}		
		if (!input) {
			alert("You must enter a value.");
			return false;
		}
		var insert_tag = "[" + tag + "=" + input + "]";
	}
	
	content_area.value = start_slice + insert_tag + end_slice;
	content_area.focus;
}