// ==UserScript==
// @name          Del.icio.us Post Butler
// @namespace     http://arantius.com/misc/greasemonkey/
// @description	  Make the del.icio.us post form friendlier.
// @include       http://del.icio.us/*v=*
// ==/UserScript==

//
// Description limiter inspired by:
//  http://philwilson.org/code/greasemonkey/deliciousdescription.user.js
//

var maxNotesLen=255;
var notesEl=document.getElementById('notes');
var notesDisp=notesEl.parentNode.nextSibling.nextSibling;

function enforceMaxNotesLen(event) {
	var curLen=notesEl.value.length;

	// set the border color as indicator
	if (curLen<maxNotesLen) {
		notesEl.style.border='1px solid #707070;';
		notesDisp.className='smaller';
	} else if (curLen==maxNotesLen) {
		notesEl.style.border='1px solid red;';
		notesDisp.className='smaller important';
	} else {
		notesEl.value=notesEl.value.substr(0, maxNotesLen);
		curLen=notesEl.value.length;

		notesEl.style.border='1px solid red;';
		notesDisp.className='smaller important';
	}

	// set the label
	notesDisp.innerHTML=curLen+' used,<br />'+(maxNotesLen-curLen)+' left';
}

notesEl.addEventListener('keyup', enforceMaxNotesLen, true);
notesEl.addEventListener('change', enforceMaxNotesLen, true);

// er? if we set border without this padding, it looks weird
notesEl.style.padding='1px';
// make it match the other labels
notesDisp.className='smaller';
// make it a little bigger
notesEl.rows='4';

enforceMaxNotesLen(); // one time, to set the label

// fast submit possible, focus tags field
document.getElementById('tags').focus();
