/* This file defines the product chooser (choice tree) for Similac. */

var product_chooser = {en: null, fr: null};

/*

Product Chooser defined by a tree of Question objects.

A Question has text (the question to ask) and at least two Answer objects.

An Answer has
 answer (a string)
 answer in long-form (for summary)
 either another Question, or a ProductList.

A ProductList is just an array of Product objects (at least one, may be more.)

A Product has
  an id ("similac_advance_neosure")
  a title (human readable)
  a thumbnail image pathname relative to Web
  a pathname to the product page (relative to Web)
  descriptive text.

(It might be better to generate this code from a config file.  It would be easier for Web Dev or even PM to edit, and if we integrated it with the product data we could avoid duplicating data (e.g. we would not have to repeat the pathname to the product page, product thumbnail, etc.  Also the syntax is tricky.   Even I get lost in this tree of curly braces, parenthesis, and square brackets.

We only need to store the ID of the product, then we can do Xpath to lookup title and relative-url from en/products/config.xml (Products/item/Productslist/item).  But to do that, we need to assign meaningful ids to products, not guids.  Note also that the current config xmlhas products grouped under product classes, which is kind of annoying for the Xpath.

On the other hand, this would all be extra work and might make us go over budget.)

The Product Chooser is implemented by class ChoiceTreeViewer.  ChoiceTreeViewer constructor takes two arguments: the root (first) question, and some options for display.  It displays the questions in a popup.

*/

// product chooser in English
var pc = new ChoiceTreeViewer(
  new Question("Are you looking for a product for:",
      [
        new Answer("Infants", "Infant feeding",
            new Question("Was your baby born prematurely?",
                [
                  new Answer("Yes", "Premature",
                      new ProductList(
                          [
                             new Product("similac_advance_neosure",
                                         "Similac Advance Neosure",
                                         "local/images/callout7.gif",
                                         "en/products/similac_advance_neosure/",
                                         "FIXME: Neosure description <b>bold</b> &quot; apos'")
                          ])),
                  new Answer("No", "Full-term",
                      new Question("How old is your baby",
                          [
                            new Answer("0-6 months", "less than 6 months",
                                new Question("Which of the following best applies to your baby?",
                                    [
                                      new Answer("My baby is doing great!", "My Baby is Doing Great",
                                          new Question("Prefer Milk- or soy-based?",
                                              [
                                                new Answer("Milk", "Milk-based",
                                                    new ProductList(
                                                        [
                                                          new Product("similac_advance_step1_omega3_omega6",
                                                                      "Similac Advance",
                                                                      "local/images/callout1.gif",
                                                                      "en/products/similac_advance_step1_omega3_omega6/",
                                                                      "FIXME"),
                                                          new Product("similac_step1_iron",
                                                                      "Similac with Iron",
                                                                      "local/images/callout3.gif",
                                                                      "en/products/similac_step1_iron/",
                                                                      "FIXME"),
                                                          new Product("similac_step1_regular",
                                                                      "Similac Regular",
                                                                      "local/images/callout4.gif",
                                                                      "en/products/similac_step1_regular/",
                                                                      "FIXME")
                                                         ])),
                                                    new Answer("Soy", "Soy",
                                                        new ProductList(
                                                            [
                                                              new Product("isomil_advance_omega3_omega6",
                                                                          "Isomil Advance",
                                                                          "local/images/callout17.gif",
                                                                          "en/products/isomil_advance_omega3_omega6/",
                                                                          "FIXME"),
                                                              new Product("isomil",
                                                                          "Similac Isomil",
                                                                          "local/images/callout9.gif",
                                                                          "en/products/isomil/",
                                                                          "Isomil fixme")
                                                            ]))
                                                ])),
                                      new Answer("Gas & fussiness due to lactose sensitivity", "Gas & fussiness due to lactose sensitivity",
                                          new Question("Prefer Milk- or soy-based?",
                                              [
                                                new Answer("Milk", "Milk-based",
                                                    new ProductList(
                                                        [
                                                          new Product("similac_sensitive_lactosefree",
                                                                      "Similac for Babies Sensitive to Lactose",
                                                                      "local/images/callout8.gif",
                                                                      "en/products/similac_sensitive_lactosefree/",
                                                                      "lactose-free fixme")
                                                         ])),
                                                new Answer("Soy", "Soy-based",
                                                    new ProductList(
                                                        [
                                                          new Product("isomil_advance_omega3_omega6",
                                                                      "Similac Isomil with Omegas",
                                                                      "local/images/callout17.gif",
                                                                      "en/products/isomil_advance_omega3_omega6/",
                                                                      ""),
                                                          new Product("",
                                                                      "Similac Isomil",
                                                                      "local/images/callout9.gif",
                                                                      "",
                                                                      "")
                                                        ]))
                                            ])),
                                      new Answer("Cow's milk restriction", "Cow's milk restriction",
                                          new ProductList(
                                              [
                                                new Product("isomil_advance_omega3_omega6",
                                                            "Similac Isomil with Omegas",
                                                            "local/images/callout17.gif",
                                                            "en/products/isomil_advance_omega3_omega6/",
                                                            ""),
                                                 new Product("similac_isomil",
                                                             "Similac Isomil",
                                                             "local/images/callout9.gif",
                                                             "en/products/similac_isomil/",
                                                             "")
                                              ])),
                                      new Answer("Needs hypoallergenic formula", "Needs hypoallergenic formula",
                                          new ProductList(
                                              [
                                                new Product("alimentum",
                                                            "Alimentum",
                                                            "local/images/callout18.gif",
                                                            "en/products/alimentum/",
                                                            "")
                                              ])),
                                      new Answer("Dehydrated", "Dehydrated",
                                          new ProductList(
                                              [
                                                new Product("pedialyte",
                                                            "Pedialyte",
                                                            "local/images/callout13.gif",
                                                            "en/products/pedialyte/",
                                                            "")
                                               ])) 
                                    ])),       // end of 0-6 months answer

                                    new Answer("6 months and over", "6 months and over",
                                        new Question( "Which of the following best applies to your baby?",
                                            [
                                              new Answer("My baby is doing great!", "My baby is doing great!",
                                                  new Question( "Prefer Milk- or soy-based?",
                                                      [
                                                        new Answer("Milk", "Milk-based",
                                                            new ProductList(
                                                                [
                                                                  new Product("similac_gogrow_step2_omega3_omega6",
                                                                              "Similac Go & Grow with Omegas",
                                                                              "local/images/callout17.gif",
                                                                              "en/products/similac_gogrow_step2_omega3_omega6/",
                                                                              ""),
                                                                  new Product("similac_gogrow_step2",
                                                                              "Similac Go & Grow",
                                                                              "local/images/callout6.gif",
                                                                              "en/products/similac_gogrow_step2/",
                                                                              ""),
                                                                  new Product("similac_step1_regular",
                                                                              "Similac Regular",
                                                                              "local/images/callout4.gif",
                                                                              "en/products/similac_step1_regular/",
                                                                              ""),
                                                                  new Product("similac_advance_step1_omega3_omega6",
                                                                              "Similac Advance",
                                                                              "local/images/callout1.gif",
                                                                              "en/products/similac_advance_step1_omega3_omega6/",
                                                                              ""),
                                                                  new Product("similac_step1_iron",
                                                                              "Similac with Iron",
                                                                              "local/images/callout3.gif",
                                                                              "en/products/similac_step1_iron/",
                                                                              "")
                                                                ])),
                                                        new Answer("Soy", "Soy-based",
                                                                   new ProductList(
                                                                       [
                                                                           new Product("isomil_step2",
                                                                                       "Similac Isomil Step 2",
                                                                                       "local/images/callout10.gif",
                                                                                       "en/products/isomil_step2/",
                                                                                       ""),
                                                                  new Product("isomil_advance_omega3_omega6",
                                                                              "Similac Isomil with Omegas",
                                                                              "local/images/callout17.gif",
                                                                              "en/products/isomil_advance_omega3_omega6/",
                                                                              ""),
                                                                  new Product("isomil",
                                                                              "Similac Isomil",
                                                                              "local/images/callout9.gif",
                                                                              "en/products/isomil/",
                                                                              "")
                                                                       ]) )
                                                      ])),
                                      new Answer("Gas & fussiness due to lactose sensitivity", "Gas & fussiness due to lactose sensitivity",
                                                 new Question( "Prefer Milk- or soy-based?",
                                                               [
                                                                   new Answer("Milk",  "Milk-based",
                                                                              new ProductList(
                                                                                  [
                                                                                      new Product("similac_sensitive_lactosefree",
                                                                                                  "Similac for Babies Sensitive to Lactose",
                                                                                                  "local/images/callout8.gif",
                                                                                                  "en/products/similac_sensitive_lactosefree/",
                                                                                                  "")
                                                                                  ])),
                                                                   new Answer("Soy", "Soy-based",
                                                                              new ProductList(
                                                                                  [
                                                                                      new Product("isomil_step2",
                                                                                                  "Similac Isomil Step 2",
                                                                                                  "local/images/callout10.gif",
                                                                                                  "en/products/",
                                                                                                  ""),
                                                                                      new Product("isomil_advance_omega3_omega6",
                                                                                                  "Similac Isomil with Omegas",
                                                                                                  "local/images/callout17.gif",
                                                                                                  "en/products/isomil_advance_omega3_omega6/",
                                                                                                  ""),
                                                                                      new Product("isomil",
                                                                                                  "Similac Isomil",
                                                                                                  "local/images/callout9.gif",
                                                                                                  "en/products/isomil/",
                                                                                                  "")
                                                                                   ]))
                                                               ])),
                                      new Answer("Cow's milk restriction", "Cow's milk restriction",
                                                 new ProductList(
                                                     [
                                                         new Product("isomil_step2",
                                                                     "Similac Isomil Step 2",
                                                                     "local/images/callout10.gif",
                                                                     "en/products/isomil_step2/",
                                                                     ""), 
                                                         new Product("isomil_advance_omega3_omega6",
                                                                     "Similac Isomil with Omegas",
                                                                     "local/images/callout17.gif",
                                                                     "en/products/isomil_advance_omega3_omega6/",
                                                                     ""), 
                                                         new Product("isomil",
                                                                     "Similac Isomil",
																	 "local/images/callout9.gif",
                                                                     "en/products/isomil/",
                                                                     "")
                                                     ])),
                                      new Answer("Needs hypoallergenic formula",  "Needs hypoallergenic formula",
                                                 new ProductList(
                                                     [
                                                         new Product("alimentum",
                                                                     "Alimentum",
                                                                     "local/images/callout18.gif",
                                                                     "en/products/alimentum/",
                                                                     "")
                                                     ])),
                                      new Answer("Dehydrated",  "Dehydrated",
                                                 new ProductList(
                                                     [
                                                         new Product("pedialyte",
                                                                     "Pedialyte",
                                                                     "local/images/callout13.gif",
                                                                     "en/products/pedialyte/",
                                                                     "")
                                                     ]))
                                            ]))
                          ]))    // end of "No" answer to question re premature
               ])),                // end of "Infants" answer. The other answer is much shorter
        new Answer("Pregnant women and breastfeeding moms",  "Pregnant women and breastfeeding moms",
            new ProductList(
                [
                  new Product("similac_mom",
                              "Similac Mom",
                              "local/images/similac_mom.gif",
                              "en/products/similac_mom/",
                              "")
                  ]))
              ]),
  //options for choice tree viewer  
 {
     title: "Similac Product Finder",
	 start_again: "Start Again",
	 picked: "You picked"
 }
);


product_chooser["en"] = pc;

// TODO: add French
product_chooser
["fr"] = pc;

