// Copyright Neil Ramsden 2005-2007. All rights reserved.

// Choosing the plural suffix flowchart definition
// Neil Ramsden
// double.js
// 1 Feb 07 NR
//	Bug-fixing deterministic case.
// 5 Jan 06 -> 28 Feb 06 NR
//	Assorted suggestions from Melvyn and Pete B.
// 30 Dec 05 -> 4 Jan 06

//---------------------------------------------------------------------------

/* Global variables
*/

//string constants

var /*const*/ _change_it = 'make the necessary change and ';
var /*const*/ _be_safe = '<br><br>(to be safe, check the result in your dictionary)';

var /*const*/ _oes_list = '<li>buffalo</li><li>calico</li><li>cargo</li><li>domino</li><li>echo</li><li>embargo</li><li>grotto</li><li>halo</li><li>hero</li><li>innuendo</li><li>mango</li><li>memento</li><li>mosquito</li><li>motto</li><li>negro</li><li>no</li><li>peccadillo</li><li>portico</li><li>potato</li><li>salvo</li><li>tomato</li><li>tornado</li><li>torpedo</li><li>veto</li><li>volcano</li>'
var /*const*/ _us_list = '<li>bus</li><li>octopus</li>'

var /*const*/ _lifted = 'you suspect that the word has a spelling lifted straight from Latin, Greek or French'
var /*const*/ _not_lifted = 'the spelling probably isn\'t lifted straight from Latin, Greek or French'


//advice constants

var /*const*/ _add_s = new Advice('just add &lt;-s&gt;');
var /*const*/ _add_es = new Advice('add &lt;-es&gt;');
var /*const*/ _change_and_add_es = new Advice(_change_it + 'add &lt;-es&gt;');
var /*const*/ _changeYToI = new Advice('change the ' + spelling('y') +
              ' to ' + spelling('i') + ' and add &lt;-es&gt;');

var /*const*/ _use_i = new Advice('change the &lt;-us&gt; to &lt;-i&gt;' + _be_safe);
var /*const*/ _use_ae = new Advice('change the &lt;-a&gt; to &lt;-ae&gt;' + _be_safe);
var /*const*/ _use_es = new Advice('change the &lt;-is&gt; to &lt;-es&gt;' + _be_safe);
var /*const*/ _use_on_a = new Advice('change the &lt;-on&gt; to &lt;-a&gt;' + _be_safe);
var /*const*/ _use_um_a = new Advice('change the &lt;-um&gt; to &lt;-a&gt;' + _be_safe);

var /*const*/ _add_x = new Advice('add the letter &lt;-x&gt;');

//repeated choice constants

var /*const*/ _native = new Choice(
    [
      { text: 'the suffix will add an extra syllable to the word, eg. &lt;branches&gt;',
        action: _add_es
      },

      { text: 'the word ends with ' + spelling('y'),
        action: new Choice(
        [
          { text: 'the letter before that ' + spelling('y') + ' is a consonant',
            action: _changeYToI 
          },
          { text: 'the letter before that ' + spelling('y') + ' is a vowel',
            action: _add_s
          }
        ])
      },

      { text: 'the word ends with &lt;-o&gt; and is in this list:<ul>' + _oes_list + '</ul>',
        action: _add_es
      },

      { text: 'the word isn\'t any of these',
        action: _add_s
      }

    ]);


function _notNative(advice)
//generate choice list providing an advice action for non-native case
{
  return new Choice(
    [
      { text: _lifted,
        action: advice
      },
      { text: _not_lifted,
        action: _native
      }
    ]);
}


//flow chart

var /*const*/ flowChart = new Choice(
    [
      { text: 'the word ends with &lt;-a&gt;',
        action: _notNative(_use_ae)
      },

      { text: 'the word ends with &lt;-eau&gt;',
        action: _add_x
      },

      { text: 'the word ends with &lt;-is&gt;',
        action: _notNative(_use_es)
      },

      { text: 'the word ends with &lt;-o&gt;',
        action: new Choice(
        [
          {text: 'the word is in this list:<ul>' + _oes_list + '</ul>',
           action: _add_es
          },

          {text: 'the word isn\'t in this list',
           action: _add_s
          }
        ])
      },

      { text: 'the word ends with &lt;-on&gt;',
        action: _notNative(_use_on_a)
      },

      { text: 'the word ends with &lt;-um&gt;',
        action: _notNative(_use_um_a)
      },


      { text: 'the word ends with &lt;-us&gt;',
        action: new Choice(
        [
          { text: 'the word is  in this list:<ul>' + _us_list + '</ul>',
            action: _add_es
          },
          { text: _lifted,
            action: _use_i
          },
          { text: _not_lifted,
            action: _native
          }
        ])
      },

      { text: 'the word doesn\'t end with &lt;-a&gt;, &lt;-eau&gt;, &lt;-is&gt;, &lt;-o&gt;, &lt;-on&gt;, &lt;-um&gt; or &lt;-us&gt;',
        action: _native
      }

    ]);
