// Wintertree Spell Check Applet
// JavaScript support functions for the Set Options form
// Copyright (c) 2001 Wintertree Software Inc.
// www.wintertree-software.com
//
// $Id: SetOptions.js,v 2.1 2006/06/15 13:20:24 wsi Exp wsi $

// This source file is dependent on SpellCheckApplet.js

var CASE_SENSITIVE_OPT = (1 << 0);
var IGNORE_ALL_CAPS_WORD_OPT = (1 << 1);
var IGNORE_CAPPED_WORD_OPT = (1 << 2);
var IGNORE_MIXED_CASE_OPT = (1 << 3);
var IGNORE_MIXED_DIGITS_OPT = (1 << 4);
var REPORT_DOUBLED_WORD_OPT = (1 << 6);
var SUGGEST_SPLIT_WORDS_OPT = (1 << 15);
var IGNORE_DOMAIN_NAMES_OPT = (1 << 16);

// Populate the Options form with the current option values
// Set the check boxes with the initial option values
document.setOptions.caseSensitiveBtn.checked = (options & CASE_SENSITIVE_OPT);
document.setOptions.ignoreAllCapsWordsBtn.checked = (options & IGNORE_ALL_CAPS_WORD_OPT);
document.setOptions.ignoreCappedWordsBtn.checked = (options & IGNORE_CAPPED_WORD_OPT);
document.setOptions.ignoreMixedCaseBtn.checked = (options & IGNORE_MIXED_CASE_OPT);
document.setOptions.ignoreMixedDigitsBtn.checked = (options & IGNORE_MIXED_DIGITS_OPT);
document.setOptions.reportDoubledWordsBtn.checked = (options & REPORT_DOUBLED_WORD_OPT);
document.setOptions.suggestSplitWordsBtn.checked = (options & SUGGEST_SPLIT_WORDS_OPT);
document.setOptions.ignoreDomainNamesBtn.checked = (options & IGNORE_DOMAIN_NAMES_OPT);

// Respond to an OK button press by saving the selected options into a variable
// named "options" and returning to the previous page
function onOkBtn() {
    // Build an option mask
    if (document.setOptions.caseSensitiveBtn.checked) {
        options |= CASE_SENSITIVE_OPT;
    }
    else {
        options &= ~CASE_SENSITIVE_OPT;
    }
    if (document.setOptions.ignoreAllCapsWordsBtn.checked) {
        options |= IGNORE_ALL_CAPS_WORD_OPT;
    }
    else {
        options &= ~IGNORE_ALL_CAPS_WORD_OPT;
    }
    if (document.setOptions.ignoreCappedWordsBtn.checked) {
        options |= IGNORE_CAPPED_WORD_OPT;
    }
    else {
        options &= ~IGNORE_CAPPED_WORD_OPT;
    }
    if (document.setOptions.ignoreMixedCaseBtn.checked) {
        options |= IGNORE_MIXED_CASE_OPT;
    }
    else {
        options &= ~IGNORE_MIXED_CASE_OPT;
    }
    if (document.setOptions.ignoreMixedDigitsBtn.checked) {
        options |= IGNORE_MIXED_DIGITS_OPT;
    }
    else {
        options &= ~IGNORE_MIXED_DIGITS_OPT;
    }
    if (document.setOptions.reportDoubledWordsBtn.checked) {
        options |= REPORT_DOUBLED_WORD_OPT;
    }
    else {
        options &= ~REPORT_DOUBLED_WORD_OPT;
    }
    if (document.setOptions.suggestSplitWordsBtn.checked) {
        options |= SUGGEST_SPLIT_WORDS_OPT;
    }
    else {
        options &= ~SUGGEST_SPLIT_WORDS_OPT;
    }
    if (document.setOptions.ignoreDomainNamesBtn.checked) {
        options |= IGNORE_DOMAIN_NAMES_OPT;
    }
    else {
        options &= ~IGNORE_DOMAIN_NAMES_OPT;
    }

    saveCookie();

    history.back();
}

// Return to the previous page without saving the options
function onCancelBtn() {
    history.back();
}

