function setOptions(chosen) {
var waitdropdown = document.NZLIncomeRequest.WaitingPeriod;
 
waitdropdown.options.length = 0;
if (chosen == "Essential+Indemnity") {
  waitdropdown.options[waitdropdown.options.length] = new Option('8 Weeks','8 Weeks');
}
else if (chosen == "Start+Up") {
  waitdropdown.options[waitdropdown.options.length] = new Option('Please Select','None');
  waitdropdown.options[waitdropdown.options.length] = new Option('4 Weeks','4 Weeks');
  waitdropdown.options[waitdropdown.options.length] = new Option('8 Weeks','8 Weeks');
}
else {
  waitdropdown.options[waitdropdown.options.length] = new Option('Please Select','None');
  waitdropdown.options[waitdropdown.options.length] = new Option('2 Weeks','2 Weeks');
  waitdropdown.options[waitdropdown.options.length] = new Option('4 Weeks','4 Weeks');
  waitdropdown.options[waitdropdown.options.length] = new Option('8 Weeks','8 Weeks');
  waitdropdown.options[waitdropdown.options.length] = new Option('13 Weeks','13 Weeks');
  waitdropdown.options[waitdropdown.options.length] = new Option('26 Weeks','26 Weeks');
  waitdropdown.options[waitdropdown.options.length] = new Option('52 Weeks','52 Weeks');
  waitdropdown.options[waitdropdown.options.length] = new Option('104 Weeks','104 Weeks');
}

var payperiod = document.NZLIncomeRequest.TPDPaymentPeriod;

payperiod.options.length = 0;
if (chosen == "Essential+Indemnity") {
  payperiod.options[payperiod.options.length] = new Option('Please Select','None');
  payperiod.options[payperiod.options.length] = new Option('5 years','5 years');
  payperiod.options[payperiod.options.length] = new Option('To age 65','To age 65');
} else if (chosen == "Start+Up") {
  payperiod.options[payperiod.options.length] = new Option('Please Select','None');
  payperiod.options[payperiod.options.length] = new Option('6 months','6 months');
  payperiod.options[payperiod.options.length] = new Option('12 months','12 months');
}
else {
  payperiod.options[payperiod.options.length] = new Option('Please Select','None');
  payperiod.options[payperiod.options.length] = new Option('1 year','1 year');
  payperiod.options[payperiod.options.length] = new Option('2 years','2 years');
  payperiod.options[payperiod.options.length] = new Option('5 years','5 years');
  payperiod.options[payperiod.options.length] = new Option('To age 65','To age 65');
  payperiod.options[payperiod.options.length] = new Option('To age 70','To age 70');
}

var grossIncome = parseFloat(document.NZLIncomeRequest.AnnualIncome.value);
var incomeProtection = parseFloat(document.NZLIncomeRequest.IncomeProtection.value);

var monthlyIncome = grossIncome/12;
var fiftyPercent = FmtPrice(monthlyIncome*.50);
var seventyfivePercent = FmtPrice(monthlyIncome*.75);

if (chosen == "Essential+Indemnity" || chosen == "Comprehensive+Indemnity") {
if (incomeProtection > seventyfivePercent) {
alert('Maximum Income Protection is 75% or gross income\nPlease enter a value of ' + seventyfivePercent + ' or less');
document.NZLIncomeRequest.IncomeProtection.value = seventyfivePercent;
}
}
else {
if (incomeProtection > fiftyPercent) {
alert('Maximum Income Protection is 50% or gross income\nPlease enter a value of ' + fiftyPercent + ' or less');
document.NZLIncomeRequest.IncomeProtection.value = fiftyPercent;
}

}
}

function FmtPrice(result) {
                    result = ConvNumber(result, 2, ".");
                    return result;
}

function ConvNumber(expr, decplaces, point) {

	var str = "" + Math.round(eval(expr) * Math.pow(10,decplaces));
	while (str.length <= decplaces) {
		str = "0" + str;
	}
	var decpoint = str.length - decplaces;
	return (str.substring(0,decpoint) + point + str.substring(decpoint,str.length));
}

function ValidateNum(checkVal) {

	returnVal = parseFloat(checkVal);

	if(isNaN(returnVal)) return false;
	else if(returnVal < 0) return false;
	else return true;
}

