function listboxItemSelected(oList1,oList2){
  if(oList2!=null){
    clearComboOrList(oList2);
    if(oList1.selectedIndex == -1){
      oList2.options[oList2.options.length] = new Option('Please make a selection from the list', '');
    } else {
      fillListbox(oList2, oList1.name + '=' + oList1.options[oList1.selectedIndex].value);
    }
  }
  calcPremium();
}

function clearComboOrList(oList){
  for (var i = oList.options.length - 1; i >= 0; i--){
    oList.options[i] = null;
  }
  oList.selectedIndex = -1;
//  if (oList.onchange) oList.onchange();
}

function fillListbox(oList, vValue) {
  if(vValue != '') {
    if(assocArray[vValue]) {
      var arrX = assocArray[vValue];
      for(var i = 0; i < arrX.length; i = i + 2){
        if(arrX[i] != 'EOF') oList.options[oList.options.length] = new Option(arrX[i + 1], arrX[i]);
	  }
//	  if(oList.options.length == 1){
	    oList.selectedIndex=0;
//	    if (oList.onchange)	oList.onchange();
//	  }
    }else {
      oList.options[0] = new Option('None found', '');
    }
  }
}

if(!assocArray) {
  var assocArray = new Object();

  assocArray["planType=Preferred Plus"] = new Array(
    "0","$ 0",
    "99","$ 99",
    "1000","$ 1,000",
    "5000","$ 5,000",
    "10000","$ 10,000",
    "EOF");
	
  assocArray["planType=Preferred"] = new Array(
    "0","$ 0",
    "250","$ 250",
    "1000","$ 1,000",
    "5000","$ 5,000",
    "10000","$ 10,000",
    "EOF");
	
  assocArray["planType=Standard"] = new Array(
    "0","$ 0",
    "250","$ 250",
    "1000","$ 1,000",
    "5000","$ 5,000",
    "10000","$ 10,000",
    "EOF");
}



// This function toggles off the pared check box for a particular question. 
// Thus only one check box can be true 
function toggleOff(clicked,uncheck) {
  if (clicked.checked) {
     uncheck.checked = false;
  }
}

// This function modify a number into two digits floating number
function Modify(value) {
  var str = "" + Math.round(value*100);
  var len = str.length;
  return (str=="0")?"":(str.substring(0,len-2)+"."+str.substring(len-2,len));
}  

// Open the remote window  
function launch(n) {
  var assessmentWin = window.open('', 'assessment', 'scrollbars=yes,resizable=yes,width=600,height=650')

  if(n == 1) {
     var topUpHtml = '<html><head><title>Top-ups and Existing Coverage Credits</title></head><body bgcolor="#f5f5f5"><H3>Top-ups and Existing Coverage Credits</H3>' +
'If you are one of the many snowbirds who already have Out-of-Canada medical insurance, but with a limited number of travel days (perhaps through a former employer), you can choose to have your Medipac Travel Insurance Policy begin on the day your other coverage expires. Simply select the Effective Date you want your Medipac policy to begin and "buy the number of extra days you need." This is called "topping-up," and Medipac offers this feature at a low fee of $20.' +
'<p>We cannot advise you on your non-Medipac plan, so please make sure your other coverage:' +
'<p><ul><li> will allow top-ups,' +
'<p><li> is in full force and effect for you and your spouse and does not expire early, and' +
'<p><li> provides adequate coverage with a minimum benefit maximum of $1,000,000.</ul>' +
'<p><b>BEWARE</b> of any plan with a low maximum benefit, as a major accident or illness can cause severe financial loss. Medipac does not recommend the Top-Up option unless your other coverage has a benefit maximum of $1,000,000 or more. Other policy maximums of $100,000 are very common and we have seen some as low as $10,000. Do not rely on these low-limit plans; purchase Medipac coverage for your entire trip.' +
'<p>Many annual policies, and almost all credit card plans, do <b>NOT</b> allow "topping up" of their plans. If you travel for longer than their maximum trip duration, you may very well have <b>no coverage at all</b> for any part of your trip! For the protection of our clients, Medipac will not accept top-ups to any credit card plans, unless you submit a letter from your credit card provider stating that they allow top-ups and will not terminate your coverage for a longer trip.' +
'<p><b>WARNING:</b> In all top-up plans, eligibility conditions and pre-existing conditions will apply on the effective date of your Medipac Travel Insurance Policy, <b>NOT</b> on the date of your departure. If you have a change in your health status prior to that effective date, you must contact Medipac International Inc. for a full refund.' +
'<p><font size=2><a href="javascript: self.close();">Close This Window</A></font>' +
'</BODY></HTML>';

	 assessmentWin.focus()
	 assessmentWin.document.write(topUpHtml)
	 assessmentWin.document.close()		  
  }

  if(n == 2) {
     var federalSuperHtml = '<html><head><title>Federal Superannuates Important Notice</title></head><body bgcolor="#f5f5f5"><H3>Federal Superannuates Important Notice</H3>' +
'Many retired civil servants, military personnel and retired RCMP officers participate in the Public Service Health Care Plan (PSHCP), which now provides up to $500,000 CAD in basic travel medical benefits, for the first 40 days of any trip. Effective April 1, 2006, the PSHCP announced major changes to your program. Medipac recommends that you become very familiar with your new policy and its provisions, many of which have been changed. Medipac also cautions that the $500,000 CAD limit may not provide full protection in the event of a major accident or illness while travelling.' +
'<p>To properly protect the many thousands of Federal Superannuates who choose Medipac, we have <b>substantially enhanced our policy and pricing</b>. Full coverage of up to $2,000,000 USD is available with many additional benefits that are not included in your Federal Superannuate plan. You can take advantage of this feature by purchasing coverage for your entire trip and deducting the Federal Superannuate Coverage Credit from your premium. If you choose this feature, you receive:' +
'<p><ul><li> a rate reduction in the form of Federal Superannuate Coverage Credits (shown on the bottom of each rate table),' +
'<p>       <li> Medipac\'s extensive benefits, for your entire trip, using your existing plan as a deductible of $500,000 CAD during the first 40 travel days,' +
'<p>       <li> access to Medipac Assist\'s medical team 24 hours a day commencing on your first day of travel,' +
'<p>       <li> non-medical benefits such as Return of Vehicle, Bringing a Relative to Bedside and Out-of Pocket Expenses, without any deductible, and' +
'<p>       <li> all the above benefits for the first 40 days of ALL OTHER TRIPS you may take until October 1, 2007. In other words...a <b>FREE 40-day Annual Plan</b>.</ul>' +
'<p>Medipac strongly recommends that you take advantage of this broad and comprehensive protection for your trip, and reduce your premium cost with our Federal Superannuate Credit.' +
'<p>We are very aware that many Superannuates choose to "take a chance" during their first 40 trip days and buy a top-up plan. The Medipac plan would then be effective when the PSHCP ends, at the 40-day point. This is usually cheaper, but it does require you to re-qualify any pre-existing conditions at Medipac\'s effective date, in the middle of your trip. Although we cannot recommend that you do this, you will be very pleased with our top-up rates and reduced top-up fees.' +
'<p>Whether you choose the Superannuate Credit or the Top-Up Option, all Medipac\'s generous discounts continue to apply.' +
'<p><font size=2><a href="javascript: self.close();">Close This Window</A></font>' +
'</BODY></HTML>';

	 assessmentWin.focus()
	 assessmentWin.document.write(federalSuperHtml)
	 assessmentWin.document.close()		  
  }

  if(n == 3) {
     var planTypeHtml = '<html><head><title>Plan Type</title></head><body bgcolor="#f5f5f5"><H3>Plan Type</H3>' +
'<H4>Q: What is the difference between the Preferred Plus, Preferred and Standard plans?</H4>' +
'<p>The only difference between the <b>Preferred Plus</b>, <b>Preferred</b> and <b>Standard</b> plans is the rate level. Individuals who are able to answer <b>NO</b> to a series of medical questions, qualify for the <b>Preferred Plus</b> or <b>Preferred</b> category and a reduced price. In no way do people that pay the <b>Standard</b> rate have less coverage or are necessarily excluded from coverage for that condition!' +
'<p><font size=2><a href="javascript: self.close();">Close This Window</A></font>' +
'</BODY></HTML>';

	 assessmentWin.focus()
 	 assessmentWin.document.write(planTypeHtml)
	 assessmentWin.document.close()
  }

  if (n == 4) {
     var deductibleHtml = '<html><head><title>Deductible</title></head><body bgcolor="#f5f5f5"><H3>Deductible</H3>' +
'<h4>Q: What is the deductible option and how does it work?</h4>' +
'<p>Deductibles are the amount of the claim that the client is responsible for paying. By choosing a deductible amount, your premium may be lower. We offer deductibles ranging from $0 to $10,000 U.S., depending on the plan type. Please remember that the deductible must be paid first, before the claim can be processed.' +
'<p><font size=2><a href="javascript: self.close();">Close This Window</A></font>' +
'</BODY></HTML>';

	 assessmentWin.focus()
 	 assessmentWin.document.write(deductibleHtml)
	 assessmentWin.document.close()
  }
  
  if (n == 5) {
     var addonHtml = '<html><head><title>Annual Multi-trip Add-on</title></head><body bgcolor="#f5f5f5"><H3>Annual Multi-trip Add-on</H3>' +
'This optional Annual Multi-trip Add-on, often referred to as a Multi-Trip plan, is the perfect addition to your Medipac Travel Insurance Policy. Our surveys show that many long-term travellers take other short trips during the year, including cruises and in-Canada jaunts. This option allows you to cover all of these trips on one Medipac policy.' +
'<p><b>If you choose to purchase this Option</b>, you are covered for an unlimited number of trips in a 12-month period for:' +
'<p><ul><li> <b>up to 23 days</b> per trip for <b>international travel</b>, and' +
'<p><li> <b>up to 60 days</b> per trip for travel <b>in Canada</b> anywhere outside your home province or territory.</ul>' +
'<p><b>Did You Know</b> that our Provincial Health Insurance Plans <b>DO NOT COVER</b> many emergency expenses incurred in Canada such as medication, ambulance, paramedical services or air evacuations? Additional non-medical costs, including return of your vehicle, bringing a family member to your bedside, out-of-pocket expenses and emergency dental expenses are now also covered by your Medipac policy, for all of your trips.' +
'<p><b>Convenient Features</b>' +
'<p><ul><li> You can choose to have your Annual Multi-trip Add-on begin at any time between your purchase date and your departure date.' +
'<p><li> You can extend or top up your Annual Multi-trip Add-on by calling Team Medipac.' +
'<p><li> You are not required to notify Medipac before you depart on any short trip. You are, however, required to <b>provide proof of your departure and return dates</b>, in the event of a claim.</ul>' +
'<p><b>Please Remember</b>' +
'<p><ul><li> The <b><a href="productpolicy.html#6">Pre-existing Condition clause</a></b> applies prior to each and every trip, so be certain you are in compliance prior to travel.' +
'<p><li> The Medipac Annual Multi-trip Add-on is not valid for any trip in excess of 23 days internationally (60 days within Canada) without written approval from Medipac International, Inc.</ul>' +
'<p><font size=2><a href="javascript: self.close();">Close This Window</A></font>' +
'</BODY></HTML>';

	 assessmentWin.focus()
 	 assessmentWin.document.write(addonHtml)
	 assessmentWin.document.close()
  }  
}



/////////calcPremium1()
function calcFedSuperCredit(deductible, age) {
  var superannuate = new Array();
  superannuate[0] = '25,65,90,120,160,240,300,500';
  superannuate[1] = '23,60,80,110,130,220,280,450';
  superannuate[2] = '20,45,60,85,110,150,200,350';
  superannuate[3] = '15,35,45,50,65,100,145,245';

  if((deductible == 0) || (deductible == 99) || (deductible == 250) ) {
     var superRow = superannuate[0];
  }else if (deductible == 1000) {
     var superRow = superannuate[1];
  }else if (deductible == 5000) {
     var superRow = superannuate[2];
  }else if (deductible == 10000) {
     var superRow = superannuate[3];
  }
	   
  var divideSuper = superRow.split(',');
  
  if (age <= 55) var federalSuper = divideSuper[0];
  if ( (age >= 56) && (age <= 60) ) var federalSuper = divideSuper[1];
  if ( (age >= 61) && (age <= 65) ) var federalSuper = divideSuper[2];
  if ( (age >= 66) && (age <= 70) ) var federalSuper = divideSuper[3];
  if ( (age >= 71) && (age <= 75) ) var federalSuper = divideSuper[4];
  if ( (age >= 76) && (age <= 79) ) var federalSuper = divideSuper[5];
  if ( (age >= 80) && (age <= 85) ) var federalSuper = divideSuper[6];
  if (age >= 86) var federalSuper = divideSuper[7];
  
  federalSuper = parseInt(federalSuper);
  return federalSuper;
}


function calcAnnualAddOnRate(planType, deductible, age) {

  var rows = new Array();
  rows[0] = 'null';
  rows[1] = '50,65,81,98,116,166,258,314';     //Preferred PLUS $99 Deductible
  rows[2] = '46,59,72,83,100,146,225,274';      //Preferred PLUS $1000
  rows[3] = '41,50,59,68,81,116,173,212';       //Preferred PLUS $5000
  rows[4] = '37,45,52,59,69,98,144,176';       //Preferred PLUS $10000
  rows[5] = '68,81,110,152,177,258,366,440';    //Preferred $250
  rows[6] = '55,65,97,123,143,203,300,383';    //Preferred $1000
  rows[7] = '45,53,78,98,113,164,237,295';     //Preferred $5000
  rows[8] = '41,49,69,86,99,142,202,251';      //Preferred $10000
  rows[9] = '118,129,138,207,281,426,607,931';  //Standard $250
  rows[10] = '100,115,120,178,243,369,525,814';  //Standard $1000
  rows[11] = '77,87,95,142,194,289,406,616';     //Standard $5000
  rows[12] = '68,77,84,124,167,248,347,524';     //Standard $10000

  var row = 0;
  if((planType == "Preferred Plus") && ((deductible == 0) || (deductible == 99))) {row = 1;}
  if((planType == "Preferred Plus") && (deductible == 1000)) {row = 2;}
  if((planType == "Preferred Plus") && (deductible == 5000)) {row = 3;}
  if((planType == "Preferred Plus") && (deductible == 10000)) {row = 4;}
  if((planType == "Preferred") && ((deductible == 0) || (deductible == 250))) {row = 5;}
  if((planType == "Preferred") && (deductible == 1000)) {row = 6;}
  if((planType == "Preferred") && (deductible == 5000)) {row = 7;}
  if((planType == "Preferred") && (deductible == 10000)) {row = 8;}
  if((planType == "Standard") && ((deductible == 0) || (deductible == 250))) {row = 9;}
  if((planType == "Standard") && (deductible == 1000)) {row = 10;}
  if((planType == "Standard") && (deductible == 5000)) {row = 11;}
  if((planType == "Standard") && (deductible == 10000)) {row = 12;}  
  
  // Get the row from rows array with the premium 
  var premiumRow = rows[row];

  // Put all premiums from a premiumRow into an array  
  var dividePremium = premiumRow.split(',');

  // Get the right Premium for the Age
  var premium = 0;
  if (age <= 55) premium = dividePremium[0];
  if ( (age >= 56) && (age <= 60) ) premium = dividePremium[1];
  if ( (age >= 61) && (age <= 65) ) premium = dividePremium[2];
  if ( (age >= 66) && (age <= 70) ) premium = dividePremium[3];
  if ( (age >= 71) && (age <= 75) ) premium = dividePremium[4];
  if ( (age >= 76) && (age <= 79) ) premium = dividePremium[5];
  if ( (age >= 80) && (age <= 85) ) premium = dividePremium[6];
  if (age >= 86) premium = dividePremium[7];

  premium = parseInt(premium);
  return premium;
}

function calcLongTripRate(planType, deductible, tripApplied, age) {

var rows = new Array();
rows[0] = 'null';
//Preferred PLUS 99 Plan Type
rows [1] = '98,118,129,192,248,374,598,896';
rows [2] = '119,146,158,232,298,446,719,998';
rows [3] = '129,167,179,273,326,492,797,1113';
rows [4] = '147,191,211,319,395,566,998,1296';
rows [5] = '159,199,225,339,442,636,1106,1398';
rows [6] = '177,210,231,359,455,679,1193,1520';
rows [7] = '189,224,239,386,495,699,1279,1675';
rows [8] = '211,272,283,438,557,840,1494,1890';
rows [9] = '227,293,298,470,606,936,1598,2019';
rows [10] = '243,298,314,499,662,973,1693,2129';
rows [11] = '256,334,359,533,708,997,1774,2271';
rows [12] = '279,378,395,584,787,1125,2028,2477';
rows [13] = '296,398,433,621,839,1196,2179,2664';
rows [14] = '316,415,456,665,898,1267,2273,2732';
rows [15] = '329,449,496,699,948,1318,2368,2842';
rows [16] = '364,497,596,751,1013,1419,2533,3246';
rows [17] = '398,543,639,796,1084,1572,2696,3434';
rows [18] = '434,566,658,811,1135,1621,2739,3497';
rows [19] = '526,658,723,893,1217,1723,3088,3845';
rows [20] = '557,706,810,962,1354,1885,3248,4052';
rows [21] = '594,759,888,1042,1519,2018,3439,4306';
//Preferred PLUS 1000 Plan Type
rows [22] = '86,99,113,168,217,327,523,784';
rows [23] = '99,128,138,199,261,390,629,873';
rows [24] = '113,146,157,239,285,431,697,974';
rows [25] = '129,167,185,279,346,495,873,1134';
rows [26] = '139,174,197,297,387,557,968,1223';
rows [27] = '155,184,202,314,398,594,998,1330';
rows [28] = '165,196,209,338,433,612,1119,1466';
rows [29] = '185,238,248,383,487,735,1298,1654';
rows [30] = '199,256,261,411,530,819,1398,1767';
rows [31] = '213,261,275,437,579,851,1481,1863';
rows [32] = '224,292,314,466,620,872,1552,1987';
rows [33] = '244,331,346,511,689,984,1775,2167';
rows [34] = '259,348,379,543,734,1047,1898,2331';
rows [35] = '277,363,399,582,786,1109,1989,2391';
rows [36] = '288,393,434,612,830,1153,2072,2487';
rows [37] = '319,435,522,657,886,1242,2216,2840';
rows [38] = '348,475,559,697,949,1376,2359,2998';
rows [39] = '380,495,576,710,993,1418,2397,3060';
rows [40] = '460,576,633,781,1065,1508,2702,3364';
rows [41] = '487,618,709,842,1185,1649,2842,3546';
rows [42] = '520,664,777,912,1329,1766,2999,3768';
//Preferred PLUS 5000 Plan Type
rows [43] = '66,79,87,129,167,252,399,598';
rows [44] = '79,99,107,157,198,298,485,674';
rows [45] = '87,113,121,184,220,332,538,751';
rows [46] = '99,129,142,215,267,382,674,875';
rows [47] = '107,134,152,229,298,429,747,944';
rows [48] = '119,142,156,242,307,458,799,1026';
rows [49] = '128,151,161,261,334,472,863,1131';
rows [50] = '142,184,191,296,376,567,1008,1276';
rows [51] = '153,192,201,317,409,632,1079,1363';
rows [52] = '164,199,212,337,447,657,1143,1437';
rows [53] = '173,225,242,360,478,673,1197,1533';
rows [54] = '188,255,267,394,531,759,1369,1672';
rows [55] = '199,269,292,419,566,807,1471,1798';
rows [56] = '213,280,308,449,598,855,1534,1844';
rows [57] = '222,303,335,472,640,890,1598,1918';
rows [58] = '246,335,398,498,684,958,1698,2191';
rows [59] = '269,367,431,537,732,1061,1820,2318';
rows [60] = '293,382,444,547,766,1094,1849,2360';
rows [61] = '355,444,488,603,821,1163,2084,2595';
rows [62] = '376,477,547,649,914,1272,2192,2735';
rows [63] = '399,512,599,703,1025,1362,2321,2907';
//Preferred Plus 10000 Plan Type
rows [64] = '55,67,73,108,139,211,338,497';
rows [65] = '67,82,89,131,168,252,399,564';
rows [66] = '73,94,99,154,184,278,449,629';
rows [67] = '83,108,119,180,223,320,564,732';
rows [68] = '90,112,127,192,250,359,625,790';
rows [69] = '99,119,131,199,257,384,674,859';
rows [70] = '107,127,135,218,280,395,723,946';
rows [71] = '119,154,159,247,315,475,844,1068';
rows [72] = '128,166,170,266,342,529,899,1141';
rows [73] = '137,171,177,282,374,549,957,1198';
rows [74] = '145,189,199,298,398,563,998,1283';
rows [75] = '158,214,223,329,445,636,1146,1396';
rows [76] = '167,225,245,351,474,676,1231,1498';
rows [77] = '179,234,258,376,498,716,1284,1544';
rows [78] = '186,254,280,395,536,745,1338,1599';
rows [79] = '199,281,337,424,572,799,1431,1834';
rows [80] = '225,307,361,448,612,888,1523,1940';
rows [81] = '245,320,372,458,641,916,1548,1976';
rows [82] = '297,372,408,505,688,973,1745,2172';
rows [83] = '315,399,458,544,765,1065,1835,2289';
rows [84] = '336,429,502,589,858,1140,1943,2433';
//Preferred 250 Plan Type
rows [85] = '128,161,176,286,357,537,798,1213';
rows [86] = '156,195,214,348,435,645,970,1358';
rows [87] = '166,227,243,388,476,698,1114,1498';
rows [88] = '194,255,286,432,535,764,1342,1759';
rows [89] = '218,264,298,459,596,855,1492,1890';
rows [90] = '241,287,311,486,625,920,1598,1998';
rows [91] = '255,314,327,524,662,944,1729,2257';
rows [92] = '286,384,390,599,758,1133,2041,2559';
rows [93] = '299,394,406,644,836,1263,2160,2768';
rows [94] = '326,398,435,684,898,1298,2298,2872';
rows [95] = '347,461,479,720,971,1361,2415,2998';
rows [96] = '376,512,549,818,1070,1515,2745,3353';
rows [97] = '405,545,592,860,1142,1584,2988,3598';
rows [98] = '442,564,624,912,1229,1696,3054,3698';
rows [99] = '455,621,684,964,1292,1820,3200,3849';
rows [100] = '498,682,819,998,1419,1926,3427,4417';
rows [101] = '546,744,877,1078,1490,2127,3639,4657';
rows [102] = '584,778,896,1115,1566,2197,3698,4735';
rows [103] = '720,898,982,1236,1676,2357,4189,5205';
rows [104] = '758,969,1096,1325,1870,2589,4407,5488';
rows [105] = '820,1027,1203,1436,2101,2775,4669,5814';
//Preferred 1000 Plan Type
rows [106] = '112,139,169,248,312,469,698,1061';
rows [107] = '137,171,187,298,381,564,849,1198';
rows [108] = '145,198,213,339,416,611,975,1311';
rows [109] = '169,223,249,378,468,668,1174,1539';
rows [110] = '191,231,261,399,522,748,1298,1654';
rows [111] = '211,251,272,425,547,798,1397,1748';
rows [112] = '223,275,286,459,579,826,1513,1975';
rows [113] = '248,336,342,524,663,991,1786,2239';
rows [114] = '262,345,355,564,731,1105,1890,2422';
rows [115] = '285,353,381,598,786,1136,1992,2513';
rows [116] = '299,398,419,629,848,1191,2113,2623';
rows [117] = '329,448,480,716,936,1325,2398,2934';
rows [118] = '354,477,518,753,999,1386,2614,3148';
rows [119] = '387,493,546,798,1076,1484,2672,3236';
rows [120] = '398,543,598,843,1130,1593,2798,3368';
rows [121] = '435,597,716,873,1241,1685,2999,3865';
rows [122] = '478,647,767,943,1297,1861,3184,4075';
rows [123] = '499,679,784,976,1368,1923,3236,4143';
rows [124] = '630,786,859,1082,1466,2062,3665,4554';
rows [125] = '663,848,959,1159,1636,2265,3856,4802';
rows [126] = '717,899,1052,1257,1839,2428,4086,5087';
//Preferred 5000 Plan Type
rows [127] = '86,108,119,193,241,362,539,819';
rows [128] = '105,132,144,235,294,435,655,917';
rows [129] = '112,153,164,262,321,471,752,998';
rows [130] = '131,172,193,292,361,515,906,1187';
rows [131] = '147,178,199,310,398,577,998,1276';
rows [132] = '163,194,210,328,422,621,1079,1349';
rows [133] = '172,212,221,354,447,637,1167,1523';
rows [134] = '193,259,265,404,511,765,1378,1727';
rows [135] = '199,266,274,435,564,852,1458,1869';
rows [136] = '219,272,294,462,599,876,1551,1939';
rows [137] = '234,311,323,486,655,918,1630,2024';
rows [138] = '254,346,370,552,722,1022,1853,2263';
rows [139] = '273,368,396,581,771,1069,2017,2429';
rows [140] = '298,381,421,615,830,1145,2061,2496';
rows [141] = '307,419,462,648,872,1229,2160,2598';
rows [142] = '336,460,553,674,958,1298,2314,2981';
rows [143] = '369,498,592,728,999,1436,2456,3144';
rows [144] = '394,525,599,753,1057,1483,2496,3196';
rows [145] = '486,606,663,834,1131,1591,2828,3513';
rows [146] = '511,654,740,894,1262,1748,2975,3704';
rows [147] = '553,693,812,969,1418,1873,3152,3924';
//Preferred 10000 Plan Type
rows [148] = '72,91,99,161,199,298,451,685';
rows [149] = '88,110,121,196,246,364,548,767';
rows [150] = '94,128,137,219,269,394,629,846';
rows [151] = '109,144,161,244,299,431,758,994';
rows [152] = '123,149,168,259,337,483,843,1068';
rows [153] = '136,162,176,274,353,520,903,1129';
rows [154] = '144,177,185,296,374,533,977,1275';
rows [155] = '162,217,222,338,428,640,1153,1446';
rows [156] = '169,223,229,364,472,713,1220,1564';
rows [157] = '184,229,246,381,498,733,1298,1623';
rows [158] = '196,261,271,399,549,769,1364,1694';
rows [159] = '212,289,310,462,599,856,1551,1895';
rows [160] = '229,308,335,486,645,895,1688,2033';
rows [161] = '249,319,353,515,695,958,1725,2089';
rows [162] = '257,351,386,544,730,1028,1798,2175';
rows [163] = '281,385,463,564,802,1088,1937,2495';
rows [164] = '309,421,495,609,842,1196,2056,2631';
rows [165] = '328,438,506,630,885,1242,2089,2675';
rows [166] = '407,507,555,698,947,1331,2367,2941';
rows [167] = '428,547,619,748,1056,1463,2490,3101';
rows [168] = '463,580,679,811,1187,1568,2638,3285';
//Standard 250 Plan Type
rows [169] = '239,283,298,487,629,934,1245,2165';
rows [170] = '282,354,366,589,756,998,1398,2497';
rows [171] = '322,379,411,668,827,1039,1455,2771';
rows [172] = '341,428,498,785,944,1258,1960,3154';
rows [173] = '374,445,534,839,1096,1468,2212,3498';
rows [174] = '417,461,549,889,1178,1635,2347,3789';
rows [175] = '436,528,582,953,1235,1694,2489,3996';
rows [176] = '498,635,696,1126,1415,1898,2778,4656';
rows [177] = '535,669,751,1234,1574,2097,2996,4998';
rows [178] = '576,699,798,1298,1698,2235,3205,5262';
rows [179] = '598,779,868,1369,1749,2341,3299,5607';
rows [180] = '655,860,984,1548,1998,2554,3695,5998';
rows [181] = '698,912,1039,1598,2098,2691,4067,6583';
rows [182] = '769,945,1097,1746,2349,2934,4364,6766';
rows [183] = '789,988,1154,1818,2499,2998,4455,6997';
rows [184] = '834,1091,1424,1896,2748,3285,4989,7996';
rows [185] = '923,1209,1579,2128,2888,3739,5455,8363';
rows [186] = '998,1277,1649,2198,2998,3897,5784,8658';
rows [187] = '1214,1462,1845,2471,3415,4284,6669,9511';
rows [188] = '1275,1563,2082,2687,3849,4747,6995,9996';
rows [189] = '1372,1677,2296,2940,4371,5132,7687,10654';
//Standard 1000 Plan Type
rows [190] = '199,248,261,426,549,817,1089,1894';
rows [191] = '247,310,319,515,662,873,1299,2185';
rows [192] = '282,332,359,598,724,909,1443,2425';
rows [193] = '298,375,436,687,826,1098,1715,2760';
rows [194] = '327,386,467,734,959,1285,1936,3061';
rows [195] = '365,399,480,778,1031,1431,1998,3315';
rows [196] = '382,462,499,834,1081,1495,2048,3497';
rows [197] = '436,556,619,985,1238,1661,2431,4074';
rows [198] = '468,585,657,1080,1377,1835,2622,4373';
rows [199] = '498,612,698,1136,1497,1927,2796,4604';
rows [200] = '523,682,760,1198,1558,1998,2887,4906';
rows [201] = '573,753,861,1355,1748,2235,3233,5248';
rows [202] = '611,797,909,1398,1836,2355,3559,5760';
rows [203] = '673,827,960,1528,2055,2567,3819,5920';
rows [204] = '689,865,998,1591,2187,2623,3898,6122';
rows [205] = '730,955,1246,1659,2398,2874,4365,6997';
rows [206] = '799,1058,1382,1862,2527,3272,4773,7318';
rows [207] = '873,1117,1443,1923,2623,3410,4998,7576';
rows [208] = '1062,1279,1614,2162,2988,3749,5835,8322';
rows [209] = '1116,1368,1822,2351,3368,4154,6121,8747';
rows [210] = '1196,1467,1998,2573,3825,4491,6726,9322';
//Standard 5000 Plan Type
rows [211] = '159,189,199,329,425,629,840,1461';
rows [212] = '189,239,247,398,510,674,944,1685';
rows [213] = '217,256,277,451,558,698,982,1870';
rows [214] = '229,289,336,530,637,849,1323,2129';
rows [215] = '252,300,358,566,740,991,1493,2361';
rows [216] = '281,311,371,597,795,1098,1584,2558';
rows [217] = '294,356,393,643,834,1151,1671,2697';
rows [218] = '336,429,469,760,955,1281,1875,3143';
rows [219] = '361,452,507,833,1062,1415,2022,3374';
rows [220] = '389,472,539,876,1146,1498,2163,3552';
rows [221] = '409,526,598,924,1181,1580,2227,3785';
rows [222] = '442,581,664,1045,1349,1724,2496,3998';
rows [223] = '471,615,701,1079,1416,1816,2745,4444';
rows [224] = '519,638,740,1179,1586,1980,2946,4567';
rows [225] = '533,667,779,1227,1687,2024,2999,4723';
rows [226] = '563,736,961,1280,1855,2217,3368,5397';
rows [227] = '623,816,1066,1436,1929,2524,3682,5645';
rows [228] = '674,862,1113,1484,1998,2630,3898,5844';
rows [229] = '819,987,1245,1668,2299,2892,4502,6420';
rows [230] = '861,1055,1405,1814,2598,3204,4722,6747';
rows [231] = '926,1132,1550,1985,2950,3464,5189,7191';
//Standard 10000 Plan Type
rows [232] = '139,159,168,275,355,528,698,1223';
rows [233] = '159,199,208,333,427,564,788,1411';
rows [234] = '182,214,232,377,467,587,822,1498';
rows [235] = '193,242,281,444,533,711,1107,1782';
rows [236] = '211,251,298,474,619,829,1250,1976';
rows [237] = '236,260,310,498,667,924,1326,2141';
rows [238] = '246,298,329,538,698,953,4131,2258';
rows [239] = '281,359,393,636,799,1072,1570,2631';
rows [240] = '299,378,424,697,889,1185,1693,2824';
rows [241] = '325,395,451,733,949,1263,1811,2973';
rows [242] = '338,440,498,773,998,1323,1864,3168';
rows [243] = '369,486,556,888,1129,1443,2088,3389';
rows [244] = '394,515,587,903,1198,1498,2298,3719';
rows [245] = '434,534,620,986,1327,1658,2466,3823';
rows [246] = '446,558,649,1027,1412,1694,2517,3953';
rows [247] = '471,616,799,1071,1553,1856,2819,4498';
rows [248] = '521,683,892,1198,1632,2113,3082,4725';
rows [249] = '564,722,932,1249,1694,2202,3268,4892';
rows [250] = '686,826,1042,1396,1929,2420,3768,5374';
rows [251] = '720,883,1176,1518,2175,2682,3952,5648';
rows [252] = '775,948,1297,1661,2470,2898,4343,5998';

  if (planType == "Preferred Plus") var planValue = 0;
  else if (planType == "Preferred") var planValue = 1;
  else if (planType == "Standard") var planValue = 2;
  
  if ((deductible == 0) || (deductible == 99) || (deductible == 250)) var deductibleValue = 0;
  if (deductible == 1000) var deductibleValue = 1;
  if (deductible == 5000) var deductibleValue = 2;
  if (deductible == 10000) var deductibleValue = 3;
  
     // Get Trip Length Applied for in Days
  if (tripApplied == 50) var termValue = 1;
  if (tripApplied == 60) var termValue = 2;
  if (tripApplied == 66) var termValue = 3;
  if (tripApplied == 75) var termValue = 4;
  if (tripApplied == 82) var termValue = 5;
  if (tripApplied == 90) var termValue = 6;
  if (tripApplied == 96) var termValue = 7;
  if (tripApplied == 105) var termValue = 8;
  if (tripApplied == 112) var termValue = 9;
  if (tripApplied == 120) var termValue = 10;
  if (tripApplied == 126) var termValue = 11;
  if (tripApplied == 135) var termValue = 12;
  if (tripApplied == 142) var termValue = 13;
  if (tripApplied == 150) var termValue = 14;
  if (tripApplied == 156) var termValue = 15;
  if (tripApplied == 165) var termValue = 16;
  if (tripApplied == 175) var termValue = 17;
  if (tripApplied == 183) var termValue = 18;
  if (tripApplied == 190) var termValue = 19;
  if (tripApplied == 200) var termValue = 20;
  if (tripApplied == 212) var termValue = 21;

  var row = planValue * 84 + deductibleValue * 21 + termValue;

  // Get the row from rows array with the premium 
  var premiumRow = rows[row];

  // Put all premiums from a premiumRow into an array  
  var dividePremium = premiumRow.split(',');

  // Get the right Premium for the Age
  var premium = 0;
  if (age <= 55) premium = dividePremium[0];
  if ( (age >= 56) && (age <= 60) ) premium = dividePremium[1];
  if ( (age >= 61) && (age <= 65) ) premium = dividePremium[2];
  if ( (age >= 66) && (age <= 70) ) premium = dividePremium[3];
  if ( (age >= 71) && (age <= 75) ) premium = dividePremium[4];
  if ( (age >= 76) && (age <= 79) ) premium = dividePremium[5];
  if ( (age >= 80) && (age <= 85) ) premium = dividePremium[6];
  if (age >= 86) premium = dividePremium[7];
 
  premium = parseInt(premium);
  return premium;
}

function calcShortTripRate(planType, deductible, tripApplied, age) {   
var rows = new Array();
rows[0] = 'null';
//Preferred Plus $99
rows [1] = '24,27,39,40,42,48,64,75';
rows [2] = '27,30,43,46,50,64,91,112';
rows [3] = '30,36,50,63,69,94,144,181';
rows [4] = '31,42,59,73,84,116,181,231';
rows [5] = '34,50,67,87,99,141,223,286';
rows [6] = '35,53,72,95,110,156,251,323';
rows [7] = '39,61,84,112,131,188,307,397';
rows [8] = '40,68,92,126,147,213,348,450';
rows [9] = '46,74,100,137,160,235,386,502';
rows [10] = '49,80,109,151,176,259,428,556';
rows [11] = '50,82,111,154,180,267,442,574';
rows [12] = '56,95,121,171,202,302,506,661';
rows [13] = '60,102,124,179,212,322,543,711';
//Preferred Plus $1,000
rows [14] = '22,23,37,38,40,45,59,69';
rows [15] = '23,27,38,43,46,59,83,100';
rows [16] = '24,34,47,55,63,85,128,159';
rows [17] = '29,39,53,65,74,104,160,202';
rows [18] = '31,44,62,75,88,125,197,250';
rows [19] = '32,48,67,83,96,138,221,282';
rows [20] = '35,55,76,96,114,166,269,345';
rows [21] = '36,59,85,108,128,187,305,393';
rows [22] = '38,66,91,117,139,206,338,436';
rows [23] = '42,72,99,128,153,227,375,483';
rows [24] = '44,73,101,131,157,233,385,498';
rows [25] = '49,84,109,144,174,264,441,572';
rows [26] = '52,91,112,149,183,280,473,615';
//Preferred Plus $5,000
rows [27] = '21,22,33,34,38,41,50,59';
rows [28] = '22,23,34,39,42,50,68,83';
rows [29] = '23,30,43,49,54,70,101,127';
rows [30] = '24,34,48,57,64,85,127,159';
rows [31] = '28,38,53,65,74,101,153,195';
rows [32] = '29,40,59,70,82,111,171,219';
rows [33] = '31,47,66,82,94,133,207,267';
rows [34] = '32,49,71,90,106,149,233,303';
rows [35] = '33,53,76,96,114,163,258,335';
rows [36] = '36,58,84,106,125,179,284,372';
rows [37] = '37,59,85,108,128,184,293,382';
rows [38] = '40,69,89,117,140,205,333,437';
rows [39] = '45,73,91,120,145,217,354,469';
//Preferred Plus $10,000
rows [40] = '21,22,31,33,35,38,46,53';
rows [41] = '22,23,33,37,39,46,61,72';
rows [42] = '24,27,39,46,49,62,90,110';
rows [43] = '24,30,44,51,57,75,110,136';
rows [44] = '25,34,48,59,65,88,132,166';
rows [45] = '26,35,51,64,71,96,147,186';
rows [46] = '27,40,57,72,82,113,177,226';
rows [47] = '29,41,61,79,91,126,199,254';
rows [48] = '30,45,66,86,99,139,220,282';
rows [49] = '31,49,70,93,107,151,242,311';
rows [50] = '33,50,71,94,109,155,250,320';
rows [51] = '35,56,74,102,118,172,281,365';
rows [52] = '38,61,75,104,122,180,299,390';
//Preferred $250
rows [53] = '0,0,58,64,67,81,102,122';
rows [54] = '0,0,66,77,84,107,144,178';
rows [55] = '0,0,83,104,113,154,220,282';
rows [56] = '0,0,94,122,136,188,277,359';
rows [57] = '0,0,108,142,159,226,340,443';
rows [58] = '0,0,117,157,176,252,380,499';
rows [59] = '0,0,133,184,207,303,463,609';
rows [60] = '0,0,147,204,232,342,523,695';
rows [61] = '0,0,159,223,253,375,580,771';
rows [62] = '0,0,167,238,273,410,637,849';
rows [63] = '0,0,171,245,280,421,657,877';
rows [64] = '0,0,183,269,310,475,751,1007';
rows [65] = '0,0,191,285,330,509,807,1085';
//Preferred $1,000
rows [66] = '0,0,57,63,66,78,96,116';
rows [67] = '0,0,65,75,81,100,134,168';
rows [68] = '0,0,80,99,110,145,205,264';
rows [69] = '0,0,91,116,129,175,256,335';
rows [70] = '0,0,102,135,151,211,313,414';
rows [71] = '0,0,111,148,166,234,350,464';
rows [72] = '0,0,127,173,195,279,424,567';
rows [73] = '0,0,140,192,218,314,480,644';
rows [74] = '0,0,150,209,239,346,531,714';
rows [75] = '0,0,158,222,256,375,583,788';
rows [76] = '0,0,161,229,262,387,600,812';
rows [77] = '0,0,171,249,288,434,685,931';
rows [78] = '0,0,178,263,307,465,736,1003';
//Preferred $5,000
rows [79] = '0,0,56,60,62,69,85,99';
rows [80] = '0,0,61,68,73,89,114,138';
rows [81] = '0,0,73,88,95,123,168,211';
rows [82] = '0,0,81,100,111,147,209,264';
rows [83] = '0,0,91,115,128,174,250,322';
rows [84] = '0,0,96,125,140,192,279,362';
rows [85] = '0,0,110,145,164,228,337,440';
rows [86] = '0,0,119,159,178,256,381,498';
rows [87] = '0,0,127,173,195,280,420,550';
rows [88] = '0,0,131,184,208,303,459,606';
rows [89] = '0,0,135,187,213,311,473,624';
rows [90] = '0,0,140,202,232,347,535,711';
rows [91] = '0,0,145,211,244,369,574,763';
//Preferred $10,000
rows [92] = '0,0,53,54,58,64,75,86';
rows [93] = '0,0,57,63,66,77,96,114';
rows [94] = '0,0,65,75,82,102,136,169';
rows [95] = '0,0,71,86,92,120,167,208';
rows [96] = '0,0,79,95,105,140,198,252';
rows [97] = '0,0,83,104,113,153,219,281';
rows [98] = '0,0,91,117,130,179,262,338';
rows [99] = '0,0,99,128,143,199,294,382';
rows [100] = '0,0,105,137,154,217,323,422';
rows [101] = '0,0,106,144,162,232,351,460';
rows [102] = '0,0,108,147,165,238,361,475';
rows [103] = '0,0,110,155,176,262,405,537';
rows [104] = '0,0,112,160,184,276,431,575';
//Standard $250
rows [105] = '0,0,66,77,86,102,126,171';
rows [106] = '0,0,81,101,114,141,184,261';
rows [107] = '0,0,108,145,169,217,294,432';
rows [108] = '0,0,128,176,208,272,375,556';
rows [109] = '0,0,150,211,251,333,462,693';
rows [110] = '0,0,164,234,280,374,521,784';
rows [111] = '0,0,193,280,338,455,637,966';
rows [112] = '0,0,215,315,381,514,725,1101';
rows [113] = '0,0,235,346,421,570,804,1227';
rows [114] = '0,0,252,376,459,626,887,1358';
rows [115] = '0,0,258,388,474,645,917,1403';
rows [116] = '0,0,285,435,536,737,1053,1620';
rows [117] = '0,0,302,465,574,793,1135,1751';
//Standard $1,000
rows [118] = '0,0,63,72,80,93,114,154';
rows [119] = '0,0,74,92,105,128,165,234';
rows [120] = '0,0,98,129,151,193,259,382';
rows [121] = '0,0,114,156,184,240,329,490';
rows [122] = '0,0,133,185,221,292,403,610';
rows [123] = '0,0,146,205,246,327,455,689';
rows [124] = '0,0,171,245,295,396,554,846';
rows [125] = '0,0,190,273,333,448,631,966';
rows [126] = '0,0,206,301,367,495,699,1075';
rows [127] = '0,0,220,326,398,543,770,1189';
rows [128] = '0,0,225,334,411,560,794,1228';
rows [129] = '0,0,246,374,463,637,910,1416';
rows [130] = '0,0,260,399,494,683,981,1530';
//Standard $5,000
rows [131] = '0,0,59,66,71,83,98,127';
rows [132] = '0,0,67,82,91,109,136,186';
rows [133] = '0,0,85,109,127,158,208,297';
rows [134] = '0,0,98,130,153,196,261,379';
rows [135] = '0,0,111,152,182,236,318,468';
rows [136] = '0,0,121,168,201,262,357,528';
rows [137] = '0,0,140,197,240,316,435,646';
rows [138] = '0,0,153,220,269,356,491,735';
rows [139] = '0,0,167,240,295,393,545,817';
rows [140] = '0,0,174,258,319,427,597,901';
rows [141] = '0,0,179,265,328,440,615,929';
rows [142] = '0,0,192,293,366,497,701,1068';
rows [143] = '0,0,201,311,390,532,755,1153';
//Standard $10,000
rows [144] = '0,0,57,64,68,77,90,116';
rows [145] = '0,0,65,76,84,99,122,165';
rows [146] = '0,0,80,100,114,141,184,260';
rows [147] = '0,0,91,118,135,172,228,328';
rows [148] = '0,0,103,138,160,205,277,404';
rows [149] = '0,0,111,150,175,228,308,454';
rows [150] = '0,0,128,175,208,272,374,555';
rows [151] = '0,0,140,195,231,305,422,630';
rows [152] = '0,0,151,213,253,336,466,700';
rows [153] = '0,0,158,226,273,365,510,770';
rows [154] = '0,0,161,233,280,375,526,795';
rows [155] = '0,0,171,255,311,421,597,911';
rows [156] = '0,0,178,269,329,451,640,982';

  if (planType == "Preferred Plus") var planValue = 0;
  else if (planType == "Preferred") var planValue = 1;
  else if (planType == "Standard") var planValue = 2;

  if ((deductible == 0) || (deductible == 99) || (deductible == 250)) var deductibleValue = 0;
  if (deductible == 1000) var deductibleValue = 1;
  if (deductible == 5000) var deductibleValue = 2;
  if (deductible == 10000) var deductibleValue = 3;

  // Get Trip Length Applied for in Days
  if (tripApplied == 3) var termValue = 1;
  if (tripApplied == 6) var termValue = 2;
  if (tripApplied == 9) var termValue = 3;
  if (tripApplied == 12) var termValue = 4;
  if (tripApplied == 15) var termValue = 5;
  if (tripApplied == 18) var termValue = 6;
  if (tripApplied == 21) var termValue = 7;
  if (tripApplied == 24) var termValue = 8;
  if (tripApplied == 27) var termValue = 9;
  if (tripApplied == 30) var termValue = 10;
  if (tripApplied == 33) var termValue = 11;
  if (tripApplied == 36) var termValue = 12;
  if (tripApplied == 40) var termValue = 13;

  var row = planValue * 52 + deductibleValue * 13 + termValue;  
  
  // Get the row from rows array with the premium 
  var premiumRow = rows[row];

  // Put all premiums from a premiumRow into an array  
  var dividePremium = premiumRow.split(',');

  // Get the right Premium for the Age
  var premium;
  if (age <= 55) premium = dividePremium[0];
  if ( (age >= 56) && (age <= 60) ) premium = dividePremium[1];
  if ( (age >= 61) && (age <= 65) ) premium = dividePremium[2];
  if ( (age >= 66) && (age <= 70) ) premium = dividePremium[3];
  if ( (age >= 71) && (age <= 75) ) premium = dividePremium[4];
  if ( (age >= 76) && (age <= 79) ) premium = dividePremium[5];
  if ( (age >= 80) && (age <= 85) ) premium = dividePremium[6];
  if (age >= 86) premium = dividePremium[7];

  premium = parseInt(premium);
  return premium;
}


/////////checkAnnualPlanAddOn()
function checkAnnualPlanAddOn(theField) {
  var f = document.m;
  var tripLength = getComboValue(f.tripLength);

  if(tripLength < 23) {
     theField.checked = false;
     f.tripLength.focus()
     alert ('Annual Multi-trip Add-on is available only if you purchased a single trip plan of 23 days or longer.')
  }
}

// This function gets the value of a Combo Box and returns it.
function getComboValue(theField) {
  var index = theField.selectedIndex;
  if(index == -1) {return true;} // avoids an error message from succesive calls to unselected combo boxes from calcPremium() 
  var choice = theField.options[index].value;
  return choice;
}

function roundOff(value, precision) {
   value = "" + value //convert value to string
   precision = parseInt(precision);
   var whole = "" + Math.round(value * Math.pow(10, precision));
   var decPoint = whole.length - precision;
   if(decPoint != 0) {
      result = whole.substring(0, decPoint);
      result += ".";
      result += whole.substring(decPoint, whole.length);
   }else {
      result = "0." + whole;
   }
   result = parseFloat(result);
   return result;
}

function calcPremium() {
  var f = document.m;
  var tripLength = getComboValue(f.tripLength);
  var planType = getComboValue(f.planType);
  var deductible = getComboValue(f.deductible);
  var age = getComboValue(f.age);
  var province = getComboValue(f.province);
  if((province == 'P.E.I.') || (province == 'Northwest Territories') || (province == 'Yukon Territories') || (province == 'Nunavut')) {
    f.discountPerc.value = '10%';
  }else{
    f.discountPerc.value = '5%';
  }

  if( (tripLength != '') && (planType != '') && (deductible != '') && (age != '') ) {
    // Single Trip Rate
	var singleTripRate;
    if((tripLength >= 41) && (tripLength <= 212)) {
   	    singleTripRate = calcLongTripRate(planType, deductible, tripLength, age);
    }
    if((tripLength >= 3) && (tripLength <= 40)) {
   	    singleTripRate = calcShortTripRate(planType, deductible, tripLength, age);
		
		if(singleTripRate == 0) {
		   alert('Short Term Rates of 40 days or less for Applicants under age 61 and a Plan Type Preferred or Standard are not available.')
		   f.singleTripRate.value = 'Not Available';
		   f.totalDiscount.value = 'Not Available';
		   f.subtotalA.value = 'Not Available';
		   f.annualAddOnRate.value = 'Not Available';
		   f.rateSubtotal.value = 'Not Available';
		   f.zeroDedRate.value = 'Not Available';
		   f.subtotalB.value = 'Not Available';
		   f.smoked.value = 'Not Available';
		   f.topUpFee.value = 'Not Available';
		   f.totalPremium.value = 'Not Available';
		   return false;
		}
    }
    f.singleTripRate.value = '$' + Modify(singleTripRate);

	// SUBTRACT Total discount
	var totalDiscount = 0;
    if(f.discountPerc.value != '') {
	   var discountPerc = f.discountPerc.value;
	   var end = discountPerc.indexOf("%");
	   discountPerc = discountPerc.substring(0, end);
	   discountPerc = parseInt(discountPerc);
	   totalDiscount = singleTripRate * (discountPerc/100);
	   totalDiscount = roundOff(totalDiscount, 2); // return is a float noumber
	   f.totalDiscount.value = '$' + totalDiscount;
    }
	var subtotalA = singleTripRate - totalDiscount;
	subtotalA = roundOff(subtotalA, 2);
	f.subtotalA.value = '$' + subtotalA;
	
	
    // Annual Add-on Rate
    if(f.annualAddOn.checked == true) {
       var annualAddOnRate = calcAnnualAddOnRate(planType, deductible, age);
       f.annualAddOnRate.value = '$' + Modify(annualAddOnRate);
	   subtotalA = subtotalA + annualAddOnRate;
	}else {
       f.annualAddOnRate.value = '';
	}

	// Rate Subtotal
  	var rateSubtotal = subtotalA;
	f.rateSubtotal.value = '$' + Modify(rateSubtotal);
	
	// Add 10% to the $99 deductible rate if taking a $0 deductible (Preferred Plus only)
	var tenPercent = 0;
    if(deductible == 0) {
	   tenPercent = (rateSubtotal / 10);
	   f.zeroDedRate.value = '$' + Modify(tenPercent);
	}else {
	   f.zeroDedRate.value = '';
	}

	// Subtotal
  	var subtotalB = subtotalA + tenPercent;
	f.subtotalB.value = '$' + Modify(subtotalB);
	
	// ADD 10% if you have smoked cigarettes
	var tenPercentCigar = 0;
    if(f.smoker.checked == true) {
	   tenPercentCigar = (subtotalB / 10);
       f.smoked.value = '$' + Modify(tenPercentCigar);
	}else {
       f.smoked.value = '';
	}
	
	// $20 Top Up Fee OR Subtract Federal Superannuate Credit
	var topUpFeeOrFedSuperCredit = 0;
    // If Top Up Coverage AND Federal Superannuate are unchecked - we have regular application 
    if((f.topUpCoverage.checked == false) && (f.federalSuperannuate.checked == false)) { 
	   topUpFeeOrFedSuperCredit = 0; 
    }
    // If Top Up Coverage is checked AND Federal Superannuate is unchecked then add topUpFee = $20 to the permium 
    else if((f.topUpCoverage.checked == true) && (f.federalSuperannuate.checked == false)) {
       topUpFeeOrFedSuperCredit = 20;
    }
    // If Top Up Coverage is unchecked AND Federal Superannuate is checked then - we have Federal Superanuate Request
    else if((f.topUpCoverage.checked == false) && (f.federalSuperannuate.checked == true)) {
       topUpFeeOrFedSuperCredit = calcFedSuperCredit(deductible, age);
	   var creditFlag = 1;
    }
	
	if(topUpFeeOrFedSuperCredit == 0) {
  	   f.topUpFee.value = '';	
	}else {
  	   f.topUpFee.value = '$' + Modify(topUpFeeOrFedSuperCredit);
	}
	
	// Total Premium Per Applicant
	var totalPremium;
	if(creditFlag == 1) {
	   totalPremium = subtotalB + tenPercentCigar - topUpFeeOrFedSuperCredit;
	}else {
	   totalPremium = subtotalB + tenPercentCigar + topUpFeeOrFedSuperCredit;
	}

	f.totalPremium.value = '$' + Modify(totalPremium);
  }
  // Clear the fields 
  else {
    f.singleTripRate.value = '';
    f.totalDiscount.value = '';
    f.subtotalA.value = '';
    f.annualAddOnRate.value = '';
    f.rateSubtotal.value = '';
    f.zeroDedRate.value = '';
    f.subtotalB.value = '';
    f.smoked.value = '';
    f.topUpFee.value = '';
    f.totalPremium.value = '';
  }
  
  // Validate Plan Type & Deductible Fields 
  if( ((planType == 'Preferred Plus') && (deductible == 250)) || ((planType == 'Preferred') && (deductible == 99)) || ((planType == 'Standard') && (deductible == 99)) ) {
      f.singleTripRate.value = 'Not Available';
      f.annualAddOnRate.value = 'Not Available';
      f.rateSubtotal.value = 'Not Available';
      f.zeroDedRate.value = 'Not Available';
      f.topUpFee.value = 'Not Available';
      f.totalPremium.value = 'Not Available';  
  }    
}


