/*	external_dictionaries.js
	copyleft Tancrède Bastié 2005-2008

requires:

index:
	copyPaste()
	openKanjiFree()
*/

function copyPaste() {
/*	copy and paste question or answers to external dictionaries 'jump-forms'
	copie et colle la question ou les réponses dans les formulaires vers des dictionaires externes
*/
	var buffer = this.forTextNode.data;
	pasteTarget.value = buffer.replace(/ー/g, "ウ");
	/*	extract single kanji (for kanji dictionnary)
		extrait un seul kanji (pour le dictionnaire de kanji)
	*/
	if (typeof this.kanjiIndex == "undefined") {
		this.kanjiIndex = -1;
		var i = 0;
	}
	else var i = this.kanjiIndex + 1;
	while (i < buffer.length) {
		if ((buffer.charCodeAt(i) >= 0x4E00) && (buffer.charCodeAt(i) <= 0x9FFF)) {
			pasteKanjiTarget.value = buffer.charAt(i);
			this.kanjiIndex = i;
			return;
		}
		i += 1;
	}
	i = 0;
	while (i < this.kanjiIndex) {
		if ((buffer.charCodeAt(i) >= 0x4E00) && (buffer.charCodeAt(i) <= 0x9FFF)) {
			pasteKanjiTarget.value = buffer.charAt(i);
			this.kanjiIndex = i;
			return;
		}
		i += 1;
	}
}


function openKanjiFree() {
/*	open external kanji dictionnary
	ouvre le dictionnaire de kanji externe
*/
	var charCode = pasteKanjiTarget.value.charCodeAt(0);
	if ((charCode >= 0x4E00) && (charCode <= 0x9FFF)) window.open("http://kanji.free.fr/kanji.php?unicode=" + Math.hexadecimal(charCode));
	return false;
}

addLoadEvent(
	function () {
		pasteKanjiTarget = document.getElementById("inputKanjiFree");
		onEnter(pasteKanjiTarget, openKanjiFree);
		document.getElementById("buttonKanjiFree").onclick = openKanjiFree;
	}
);
