// http://randomfoo.net/sandbox/mozilla/getselection/

function insert_code( type ) {
        var ta = document.getElementById( "text" );
        var d = new Date() ;
	var string;
        var string = "(" + ( d.getYear() + 1900 ) + "-"
                     + pad( d.getMonth() + 1 ) + "-"
                     + pad( d.getDate() ) + ")";
	switch( type ) {
		case "link":
			string = '<a href="" title=""></a>' ;
			break ;
		case "quote":
			string = '<quote></quote>' ;
			break ;
	}

        cursor = ta.selectionStart;
        before = (ta.value).substring(0, cursor);
        after = (ta.value).substr(cursor, ta.textLength);

        ta.value = before + string + after;

        ta.focus();
        ta.selectionStart = cursor + string.length;
        ta.selectionEnd = cursor + string.length;
}
function pad( number ) {
        return ( number < 10 ) ? "0" + number : number ;
}
