/*
	2009-02-25	Author: Aoki Makoto GZL03577@nifty.com
*/
IconPallet = {
	_pallet:  null,
	_txtarea: null,
	
	
	open: function ( i_pallet, i_txtarea ) {
		this._pallet  = i_pallet;
		this._txtarea = i_txtarea;
		
		this._pallet.style.display = '';
		this._pallet.style.visibility = 'visible';
		
		this._pallet.focus();
		this._pallet.onblur = function () {
			this.style.display = 'none';
			this.style.visibility = 'hidden';
		}
	},
	
	close: function () {
		this._pallet.onblur();
	},

	insert: function ( i_buf ) {
		if( !this._txtarea ) {
		 	return;
		}
		
		var e = this._txtarea;
		
		if ( typeof(document.selection) != 'undefined' ) {
			e.focus();
			document.selection.createRange().text = i_buf;

		} else if ( typeof(e.selectionStart) != 'undefined' ) {
			var len = e.textLength;
			var st  = e.selectionStart;
			var ed  = e.selectionEnd;
			e.value = e.value.substring(0, st) + i_buf + e.value.substr(ed, len);
			e.setSelectionRange(st + i_buf.length, st + i_buf.length);

		} else {
			e.value = e.value + i_buf;
		}

		this.close();
	}
}


