
//  -- Start - Spell Checker Script --  
var cookieName = "SpellCheckApplet";

var fieldsToCheck;
var curFieldToCheck = 0;

function checkNextField() {
    document.SpellCheckApplet.setText(fieldsToCheck[curFieldToCheck].value);
    document.SpellCheckApplet.check();
    waitForSpellCheck();
}
function onCheckSpelling() {
    if (!navigator.javaEnabled()) {
        alert("Java must be enabled in your browser to use the spelling checker.");
        return;
    }

    if (document.SpellCheckApplet.getStatus() == 0) {
        document.SpellCheckApplet.check();
        return;
    }
    var options = document.SpellCheckApplet.getOptions();
    var cookies = document.cookie;
    var pos = cookies.indexOf(cookieName);
    var s;
    if (pos >= 0) {
        var start = pos + cookieName.length;
        var end = cookies.indexOf(";", start);
        if (end < 0) {
            end = cookies.length;
        }
        var scCookie = unescape(cookies.substring(start, end));
        end = scCookie.indexOf(":");
        if (end < 0) {
            end = scCookie.length;
        }
        s = scCookie.substring(0, end);
        options = s - 0;
        if (options != 0) {
            document.SpellCheckApplet.setOptions(options);
        }
        if (end != scCookie.length) {
            start = end + 1;
            s = scCookie.substring(start, scCookie.length);
            document.SpellCheckApplet.setUserDictionary(s);
        }
    }
    // Start checking spelling.
    fieldsToCheck = new Array();
    for (var i = 0; i < arguments.length; ++i) {
        fieldsToCheck[i] = arguments[i];
    }
    curFieldToCheck = 0;
    checkNextField();
}

function waitForSpellCheck() {
    var status = document.SpellCheckApplet.getStatus();
    if (status != 0) {
        if (status == 1) {
            fieldsToCheck[curFieldToCheck].value = document.SpellCheckApplet.getText();
            var nextYear = new Date();
            nextYear.setFullYear(nextYear.getFullYear() + 1);
            options = document.SpellCheckApplet.getOptions();
            var userDict = document.SpellCheckApplet.getUserDictionary();
            document.cookie = cookieName +
              escape(options.toString() + ":" + userDict) +
              "; expires=" + nextYear.toGMTString();


            if (++curFieldToCheck < fieldsToCheck.length) {
                checkNextField(fieldsToCheck);
            }
            else {
                alert("Spelling check complete.");
            }
        }
        else if (status < 0) {
            alert("An error occured while checking spelling.");
        }
    }
    else {
        setTimeout("waitForSpellCheck()", 100);
    }
}
// -- End - Spell Checker Script -- 
