var spell_formname, spell_fieldname;
function spellCheck(formName, fieldName)
{
var spellform = document.forms.spell_form;
spell_formname = formName;
spell_fieldname = fieldName;
spellform.spellstring.value = document.forms[formName][fieldName].value;
openSpellWin(640, 480);
spellform.submit();
return true;
}
var wordindex = -1, offsetindex = 0;
var ignoredWords = [];
function misp(word, start, end, suggestions)
{
this.word = word;
this.start = start;
this.end = end;
this.suggestions = suggestions;
}
function replaceWord()
{
var strstart = "";
var strend;
if (misps[wordindex].start != 0)
strstart = mispstr.slice(0, misps[wordindex].start + offsetindex);
strend = mispstr.slice(misps[wordindex].end + 1 + offsetindex);
mispstr = strstart + document.forms.spellingForm.changeto.value + strend;
offsetindex += document.forms.spellingForm.changeto.value.length - misps[wordindex].word.length;
misps[wordindex].word = document.forms.spellingForm.changeto.value;
nextWord(false);
}
function replaceAll()
{
var strend;
var idx;
var origword;
var localoffsetindex = offsetindex;
origword = misps[wordindex].word;
for (idx = wordindex; idx < misps.length; idx++)
{
misps[idx].start += localoffsetindex;
misps[idx].end += localoffsetindex;
}
localoffsetindex = 0;
for (idx = 0; idx < misps.length; idx++)
{
if (misps[idx].word == origword)
{
var strstart = "";
if (misps[idx].start != 0)
strstart = mispstr.slice(0, misps[idx].start + localoffsetindex);
strend = mispstr.slice(misps[idx].end + 1 + localoffsetindex);
mispstr = strstart + document.forms.spellingForm.changeto.value + strend;
localoffsetindex += document.forms.spellingForm.changeto.value.length - misps[idx].word.length;
}
misps[idx].start += localoffsetindex;
misps[idx].end += localoffsetindex;
}
ignoredWords[origword] = true;
offsetindex = 0;
nextWord(false);
}
function highlightWord()
{
var strstart = "";
var strend;
if (misps[wordindex].start != 0)
strstart = mispstr.slice(0, misps[wordindex].start + offsetindex);
strend = mispstr.slice(misps[wordindex].end + 1 + offsetindex);
var divptr, newValue;
divptr = document.getElementById("spellview");
newValue = htmlspecialchars(strstart) + '<span class="highlight" id="h1">' + misps[wordindex].word + '</span>' + htmlspecialchars(strend);
setInnerHTML(divptr, newValue.replace(/_\|_/g, '<br />'));
var spellview_height = typeof(document.getElementById("spellview").currentStyle) != "undefined" ? parseInt(document.getElementById("spellview").currentStyle.height) : document.getElementById("spellview").offsetHeight;
var word_position = document.getElementById("h1").offsetTop;
var current_position = document.getElementById("spellview").scrollTop;
if (spellview_height <= (word_position + current_position))
document.getElementById("spellview").scrollTop = word_position + current_position - spellview_height + 32;
}
function nextWord(ignoreall)
{
if (ignoreall)
ignoredWords[misps[wordindex].word] = true;
if (wordindex >= 0)
{
misps[wordindex].start += offsetindex;
misps[wordindex].end += offsetindex;
}
wordindex++;
if (misps.length <= wordindex)
{
var divptr;
divptr = document.getElementById("spellview");
setInnerHTML(divptr, htmlspecialchars(mispstr).replace(/_\|_/g, "<br />"));
while (document.forms.spellingForm.suggestions.options.length > 0)
document.forms.spellingForm.suggestions.options[0] = null;
alert(txt['done']);
document.forms.spellingForm.change.disabled = true;
document.forms.spellingForm.changeall.disabled = true;
document.forms.spellingForm.ignore.disabled = true;
document.forms.spellingForm.ignoreall.disabled = true;
mispstr = mispstr.replace(/_\|_/g, "\n");
window.opener.document.forms[spell_formname][spell_fieldname].value = mispstr;
window.opener.document.forms[spell_formname][spell_fieldname].focus();
window.close();
return true;
}
if (typeof(ignoredWords[misps[wordindex].word]) != "undefined")
{
nextWord(false);
return false;
}
while (document.forms.spellingForm.suggestions.options.length > 0)
document.forms.spellingForm.suggestions.options[0] = null;
if (misps[wordindex].suggestions.length)
{
for (var sugidx = 0; sugidx < misps[wordindex].suggestions.length; sugidx++)
{
var newopt = new Option(misps[wordindex].suggestions[sugidx], misps[wordindex].suggestions[sugidx]);
document.forms.spellingForm.suggestions.options[sugidx] = newopt;
if (sugidx == 0)
{
newopt.selected = true;
document.forms.spellingForm.changeto.value = newopt.value;
document.forms.spellingForm.changeto.select();
}
}
}
if (document.forms.spellingForm.suggestions.options.length == 0)
document.forms.spellingForm.changeto.value = "";
highlightWord();
return false;
}
function htmlspecialchars(thetext)
{
thetext = thetext.replace(/\</g, "&lt;");
thetext = thetext.replace(/\>/g, "&gt;");
thetext = thetext.replace(/\n/g, "<br />");
thetext = thetext.replace(/\ \ /g, " &nbsp;");
return thetext;
}
function openSpellWin(width, height)
{
window.open("", "spellWindow", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=" + width + ",height=" + height);
}