// routefinder questionnaire display
// v1.0 by Antony Espindola
// (c) 2001 Threadneedle

function ThisPage() {
var iPos;

  iPos = sURL.indexOf("pg=");
  if (iPos < 0) {
    return "1";
  } else {
    return sURL.substr(iPos+3,1);
  }
}

function MakePage(pagenum) {
var sOutput = "";

  switch (pagenum) {
    case "2":
      sOutput = sOutput + ShowQuestion("3");
      sOutput = sOutput + ShowQuestion("4");
      break;
    case "3":
      sOutput = sOutput + ShowQuestion("5");
      sOutput = sOutput + ShowQuestion("6");
      sOutput = sOutput + ShowQuestion("7");
      break;
    case "4":
      sOutput = sOutput + "<tr>\n<td valign=\"top\" class=\"mainCopy\">\n";
      sOutput = sOutput + CalcResults();
      break;
    case "5":
      sOutput = sOutput + "<tr>\n<td valign=\"top\" class=\"mainCopy\">\n";
      sOutput = sOutput + "<br><b>All Investor Types</b><p>\n";
      sOutput = sOutput + ShowResults("ABC");
      break;
    default:
      sOutput = sOutput + ShowQuestion("1");
      sOutput = sOutput + ShowQuestion("2");
  }

  return sOutput;
}

function ShowQuestion(qnum) {
var sOutput = "";
var question = "";
var iLoop = "";
answer = new Array(3);

sOutput = "<tr>\n<td valign=\"top\" class=\"mainCopy\" colspan=\"3\"><br>\n";

  switch (qnum) {
    case "2":
       sOutput = sOutput + "2. You might increase your chances of improving your pension by taking more investment risks. Are you:\n<br><br>\n</td>\n";
      answer[0] = "Willing to take a lot more risk with some of your money?";
      answer[1] = "Willing to take a little more risk with some of your money?";
      answer[2] = "Not happy taking risks?";
      break;
    case "3":
       sOutput = sOutput + "3. Are you happy to invest in company shares (also called equities) or unit trusts, PEPs and ISAs that invest in company shares?\n<br><br>\n</td>\n";
      answer[0] = "Yes, and I understand the risks involved.";
      answer[1] = "Yes, but I would also like to have some less risky investments.";
      answer[2] = "No, I don’t feel comfortable with the risks.";
      sOutput = sOutput + "<td rowspan=\"8\" valign=\"top\"><br><img src=\"images/ill_style.gif\"></td>\n";
      break;
    case "4":
       sOutput = sOutput + "4. How long you invest for is just as important as what you invest in. As a rule, equities have generally been the best choice for long-term investors. How long will it be before you stop work?\n<br><br>\n</td>\n";
      answer[0] = "More than 20 years’ time.";
      answer[1] = "5-20 years’ time.";
      answer[2] = "5 years or less.";
      break;
    case "5":
       sOutput = sOutput + "5. It’s important that your pension investments keep pace with your salary increases. If you are expecting your salary to increase it may be appropriate to take more risk with your investment. Which of the following statements best describes what you are expecting?\n<br><br>\n</td>\n";
      answer[0] = "My salary should increase substantially.";
      answer[1] = "My salary should increase, but only in line with inflation. I’m not expecting any big increases.";
      answer[2] = " My salary will not increase and it may even go down. (This may be the case if you are close to retirement or planning to work part-time etc.)";
      sOutput = sOutput + "<td rowspan=\"12\" valign=\"top\"><br><img src=\"images/ill_style.gif\"></td>\n";
      break;
    case "6":
       sOutput = sOutput + "6. Just two months after you put money into a long-term investment, the price falls by 20%. You think it’s probably still a good long-term investment. But what do you do?\n<br><br>\n</td>\n";
      answer[0] = "Buy more. It was a good investment before, so now it is a cheap investment too!";
      answer[1] = "Do nothing and wait for the investment to return to its previous level.";
      answer[2] = "Sell to avoid further worry and buy something else.";
      break;
    case "7":
       sOutput = sOutput + "7. Which would you choose?\n<br><br>\n</td>\n";
      answer[0] = "A 20% chance to win £50,000.";
      answer[1] = "A 50% chance to win £15,000.";
      answer[2] = "£2,000 in cash.";
      break;
    default :
       sOutput = sOutput + "1. We all want to retire with a good level of income – but which is the most important to you?\n<br><br>\n</td>\n";
      answer[0] = "I would like to have the best possible standard of living when I retire. In trying to achieve this, I’m ready to take a higher level of investment risk.";
      answer[1] = "Although retiring in comfort is important to me, I’d rather take a moderate level of investment risk, even if it brings lower returns.";
      answer[2] = "I’d prefer to keep any investment risks at a low level, even if this means I get a smaller pension.";
      sOutput = sOutput + "<td rowspan=\"8\" valign=\"top\"><br><img src=\"images/ill_style.gif\"></td>\n";
  }

  sOutput = sOutput + "</tr>\n";
  for (iLoop=0;iLoop<=2;iLoop++) {
    sOutput = sOutput + "<tr>\n";
    sOutput = sOutput + "<td valign=\"top\" class=\"mainCopy\" width=\"1%\"><b>";
    sOutput = sOutput + (String.fromCharCode(65+iLoop));
    sOutput = sOutput + "</b></td>\n";
    sOutput = sOutput + "<td valign=\"top\" class=\"mainCopy\" width=\"1%\">";
    sOutput = sOutput + "<input type=\"radio\" name=\"q_" + (qnum) + "\" value=\"" + (iLoop+1) + "\"></td>\n";
    sOutput = sOutput + "<td valign=\"top\" class=\"mainCopy\">" + answer[iLoop] + "</td>\n";
    sOutput = sOutput + "</tr>\n";
  }
  return sOutput;
}

function GoPage(pagenum) {
var sNewURL = "kitbag_quest_main.asp?";
var sName;
var bChecked;
var iLoop;
var iPos;
var iMin;
var iMax;

  switch (pagenum) {
    case "2":
      sNewURL = sNewURL + "pg=3";
      iMin = 3;
      iMax = 4;
      break;
    case "3":
      sNewURL = sNewURL + "pg=4";
      iMin = 5;
      iMax = 7;
      break;
    default:
      sNewURL = sNewURL + "pg=2";
      iMin = 1;
      iMax = 2;
  }

  for (iLoop=iMin;iLoop<=iMax;iLoop++) {
    sName = "q_" + iLoop;
    bChecked = false;
    for (i=0;i<document.forms.routefinder.elements(sName).length;i++) {
      if (document.forms.routefinder.elements(sName)[i].checked) {
        sNewURL = sNewURL + "&q_" + iLoop + "=" + document.forms.routefinder.elements(sName)[i].value;
        bChecked = true;
      }
    }
    if (!bChecked) {
      alert("Please select an answer for Question " + iLoop + ".");
      return;
    }
  }
  for (iLoop=1;iLoop<=7;iLoop++) {
    if (!((iLoop<iMax) && (iLoop>iMin))) {
      iPos = sURL.indexOf("q_"+iLoop+"=");
      if (iPos >= 0) {
        sNewURL = sNewURL + "&q_" + iLoop + "=" + sURL.substr(iPos+4,1);
      }
    }
  }
  document.location = sNewURL;
}

function CalcResults() {
var sOutput = "";
var cntA = 0;
var cntB = 0;
var cntC = 0;
var iLoop;
var iPos;

  for (iLoop=1;iLoop<=7;iLoop++) {
    iPos = sURL.indexOf("q_"+iLoop+"=");
    if (iPos >= 0) {
      switch (sURL.substr(iPos+4,1)) {
        case "1":
          cntA++;
          break;
        case "2":
          cntB++;
          break;
        case "3":
          cntC++;
          break;
      }
    }
  }


  sOutput = sOutput + "<br><b>You have answered " + cntA + "A" + Pluralise(cntA) + ", " + cntB + "B" + Pluralise(cntB) + ", " + cntC + "C" + Pluralise(cntC) + ". "
  if ((cntA > cntB) && (cntA > cntC)) {
    sOutput = sOutput + "You have answered mostly As.<p>This suggests:";
    sOutput = sOutput + ShowResults("A");
  } else if ((cntB > cntA) && (cntB > cntC)) {
    sOutput = sOutput + "You have answered mostly Bs.<p>This suggests:";
    sOutput = sOutput + ShowResults("B");
  } else if ((cntC > cntA) && (cntC > cntB)) {
    sOutput = sOutput + "You have answered mostly Cs.<p>This suggests:";
    sOutput = sOutput + ShowResults("C");
  } else if (cntA == cntB) {
    sOutput = sOutput + "You have answered equal As and Bs.<p>Please read both descriptions below:";
    sOutput = sOutput + ShowResults("AB");
  } else if (cntB == cntC) {
    sOutput = sOutput + "You have answered equal Bs and Cs.<p>Please read both descriptions below:";
    sOutput = sOutput + ShowResults("BC");
  } else if (cntA == cntC) {
    sOutput = sOutput + "You have answered equal As and Cs.<p>Please read both descriptions below:";
    sOutput = sOutput + ShowResults("AC");
  }
  return sOutput;
}

function Pluralise(cnt) {
  if (cnt == 1) {
    return "";
  } else {
    return "s";
  }
}

function ShowResults(type) {
var sOutput = "";
var sImage = "";

  if (type.indexOf("A") >= 0) {
    sOutput = sOutput + "</b><p>You have an <b>adventurous</b> approach to investment. You aim for the highest possible returns and accept a high level of risk in order to get them. You are ready to take the rough with the smooth, knowing full well that investment values may go down as well as up, especially in the short term. <br><br>";
    sImage = "images/ill_adventure.gif";
  }
  if (type.indexOf("B") >= 0) {
    sOutput = sOutput + "</b><p>You appear to have a <b>moderate</b> approach to investment. While you may be comfortable taking some risks so that your capital will grow, you don't want to see the value of your investments going up and down like a yo-yo. Or, it might be that you prefer an even investment path, one that does not rise and fall too steeply.<br><br>";
    sImage = "images/ill_middle.gif";
  }
  if (type.indexOf("C") >= 0) {
    sOutput = sOutput + "</b><p>You are most likely to prefer a <b>conservative</b> approach to investment. Although you want your investments to grow, you are not prepared to take many risks to achieve this. Protecting the value of your investments is important to you.<br><br>";
    sImage = "images/ill_cautiously.gif";
  }
  sOutput = sOutput + "<b>Important Information</b><br>\n";
  sOutput = sOutput + "It's important that, once in a while, you check that your pension investment arrangements are still right for you, particularly if your personal circumstances change. This Routefinder could help you, but please remember that:\n";
  sOutput = sOutput + "<ul>\n";
  sOutput = sOutput + "<li> The Routefinder is designed to help you decide what kind of investor you might be. It won't provide all the answers, so you shouldn't rely on it as a definitive investment guide. It does not constitute investment advice and must not be taken as a recommendation that any particular course of action is best or suitable for you.</li>\n";
  sOutput = sOutput + "<li> You are responsible for your own investment decisions. Threadneedle Pensions Limited does not give investment advice.</li>\n";
  sOutput = sOutput + "<li> If you are uncertain about your choices or your attitude to risk, you should consult an independent financial adviser.</li>\n";
  sOutput = sOutput + "<li> Past performance is no guarantee of future returns and the value of investments can fall as well as rise since their value depends on the value of the underlying holdings. Exchange rate fluctuations may also alter the value of your investment.</li>\n";
  sOutput = sOutput + "</ul>\n";
  sOutput = sOutput + "</td>\n";
  sOutput = sOutput + "<td width=\"10\">&nbsp;</td>\n";
  sOutput = sOutput + "<td valign=\"top\"><br><img src=\"" + sImage + "\"></td>\n</tr>\n";

  return sOutput;
}