// ==UserScript==
// @name          Technorati and Delicious Tags for Bloggers bookmarklet
// @description	  Changes the Bookmarklet Post Blogger form to include a tags field.
// @namespace     http://www.mamata.com.br/greasemonkey
// @include       http://blogger.com/*
// @include       http://www.blogger.com/*

//by Fabricio Zuardi (http://idomyownstunts.blogspot.com)
// Modified by Bryan Price (http://www.bytehead.org/) to make it conducive to being XHTML compliant
//Modified by John Jewitt (http://blogfresh.blogspot.com) to generate technorati and delicious tags at the same time. Please replace my username jrfj44 with your username in the delicious URL
//Modified by Esben Fjord (http://www.esbenfjord.dk) to support the Blogger bookmarklet
// ==/UserScript==

(function() {
	
	var post_options = document.getElementById("postArea");
	var tags_field = document.createElement("div");
	var tags_field_html = "";
	tags_field_html += "<table width='100%'><tr><th style='background:#D9D9D9;margin:2px 3px 0px 0px;padding:2px 4px 2px 2px;text-align:right;border-bottom:solid #C9C9C9 1px;border-right:solid #C9C9C9 1px;font-size:10px;font-weight:normal;color:black;width:10%;'>Tags: </th><td width='100%'><input type='text' name='tags' id='f-tags' style='border-left:solid #999999 1px;border-top:solid #999999 1px;border-bottom:solid gray 1px;border-right:solid black 1px;font-size:10px;color:black;background:#ffffff;padding:1px;margin:2px 0px 2px 2px;width:81%;'/> <input value='Add' type='button' onclick='appendTags()'></td></tr></table>";tags_field.innerHTML = tags_field_html;
	post_options.parentNode.insertBefore(tags_field,post_options)
	appendTags = function(){
		var tags_str = document.getElementById('f-tags').value;
		var tags_arr = tags_str.split(' ')
		var tags_html = '<div class="tag_list">Tags: <span>'
		for(var i=0;i<tags_arr.length;i++){
			tags_html += '<a href="http://del.icio.us/esse/'+tags_arr[i]+'" rel="tag">'+tags_arr[i]+'</a> '
		}
		tags_html += "</span></div>"
		var text_area = document.getElementById('postBody')
		var div_index = text_area.value.indexOf("<div class='tag_list'>");
		if(div_index > 0){
			text_area.value = text_area.value.substr(0,div_index)+tags_html;
		}else{
			text_area.value += tags_html;
		}
	}
	
})();