// JavaScript Document


// Insuranetogo.com
// function RComp renamed to RCompIMG
// created RCompSRI and RCompWAL
// and the giant 2d arrays used to get basic rates

function MakeArray( n ) {
   if( n <= 0 ) {
      this.length = 0;
      return this;
   }
     
   this.length = n;
   for( var i = 1; i <= n; i++ ) {
      this[ i ] = 0;
   }
   return this;
}

/*=========*/

function roundOff(arg){
  return parseFloat( Math.round(arg * 100) / 100);
}

/*========*/

function formatNum(arg){
  // if an int, add .00 to the end. ex: 5 becomes 5.00
  // if a float with only one decimal place, add a 0. ex: 5.1 becomes 5.10
  // if a float with nothing before the decimal point, add a 0. ex: .50 becomes 0.50
  arg = arg + "";

  if (arg.indexOf('.') == -1)
    arg += ".00";
  else {
    if ( arg.charAt(arg.indexOf('.')+2) == "")
      arg += "0";
    if (arg.charAt(0) == '.')
      arg = "0" + arg;
  }
  return arg;
}

/*=========*/

function fix(nbr) {

    return formatNum(roundOff(nbr));


// it makes some incorrect assumptions about what to do with cents
// superceded by formatNum and roundOff, which are much smarter

// this code remove by KS 2/5/00
/*

  nbr = parseInt(nbr);
  // Round the pennies.
  nbr = Math.floor(nbr) + (Math.round((nbr - Math.floor(nbr)) * 100) / 100);
  nbr = nbr+"";  // Convert it to a string.
  var dec = nbr.indexOf(".", 0);
  if (dec == -1) return nbr + ".00";
  if (nbr.length < dec + 3) return nbr + "0";
  return nbr.substring(0, dec + 3);
*/
}

/*=========*/

function RComp (LForm){
    RCompIMG (LForm);
    RCompSRI (LForm);
    RCompMNUI (LForm);
}

//-->


<!--
// rates for patriot america, all 3 premium levels, monthly and 1/2 monthly

var rates_img = new MakeArray(11);
    for (var i=0; i<11; i++){
        rates_img[i] = new MakeArray(2);
    }
    
//     $500,000           $1,000,000  
rates_img[0][0]=39;  rates_img[0][1]=46;  rates_img[0][2]=59;  rates_img[0][3]=66;  // solo child
rates_img[1][0]=43;  rates_img[1][1]=50;  rates_img[1][2]=64;  rates_img[1][3]=76;  // 18-25
rates_img[2][0]=43;  rates_img[2][1]=50;  rates_img[2][2]=64;  rates_img[2][3]=76;  // 26-29
rates_img[3][0]=55;  rates_img[3][1]=57;  rates_img[3][2]=84;  rates_img[3][3]=97;  // 30-39
rates_img[4][0]=84;  rates_img[4][1]=96;  rates_img[4][2]=126; rates_img[4][3]=142; // 40-49
rates_img[5][0]=120; rates_img[5][1]=147; rates_img[5][2]=178; rates_img[5][3]=206; // 50-59
rates_img[6][0]=142; rates_img[6][1]=174; rates_img[6][2]=207; rates_img[6][3]=248; // 60-64
rates_img[7][0]=162; rates_img[7][1]=208; rates_img[7][2]=226; rates_img[7][3]=270; // 65-69
rates_img[8][0]=219; rates_img[8][1]=-1;  rates_img[8][2]=-1;  rates_img[8][3]=-1;  // 70-79
rates_img[9][0]=381; rates_img[9][1]=01;  rates_img[9][2]=-1;  rates_img[9][3]=-1;  // 80+
rates_img[10][0]=26; rates_img[10][1]=28; rates_img[10][2]=36; rates_img[10][3]=39; // dep. child

// rates for sri liason international, all 4 premium levels
// these rates come from the fax section labeled SRI LIASON INTERNATIONAL - Traveling to the United States

var rates_sri = new MakeArray(11);
    for (var i=0; i<11; i++) {
        rates_sri[i] = new MakeArray(4);
    }

//      $50,000             $100,000             $500,000           $1,000,000
rates_sri[0][0]=46;  rates_sri[0][1]=53;  rates_sri[0][2]=68;  rates_sri[0][3]=76;  // solo child
rates_sri[1][0]=46;  rates_sri[1][1]=53;  rates_sri[1][2]=72;  rates_sri[1][3]=81;  // 19-25
rates_sri[2][0]=46;  rates_sri[2][1]=53;  rates_sri[2][2]=72;  rates_sri[2][3]=81;  // 26-29
rates_sri[3][0]=61;  rates_sri[3][1]=72;  rates_sri[3][2]=96;  rates_sri[3][3]=107; // 30-39
rates_sri[4][0]=92;  rates_sri[4][1]=103; rates_sri[4][2]=141; rates_sri[4][3]=155; // 40-49
rates_sri[5][0]=141; rates_sri[5][1]=171; rates_sri[5][2]=205; rates_sri[5][3]=242; // 50-59
rates_sri[6][0]=171; rates_sri[6][1]=215; rates_sri[6][2]=266; rates_sri[6][3]=305; // 60-64
rates_sri[7][0]=219; rates_sri[7][1]=-1;  rates_sri[7][2]=-1;  rates_sri[7][3]=-1;  // 65-69
rates_sri[8][0]=276; rates_sri[8][1]=-1;  rates_sri[8][2]=-1;  rates_sri[8][3]=-1;  // 70-79
rates_sri[9][0]=480; rates_sri[9][1]=-1;  rates_sri[9][2]=-1;  rates_sri[9][3]=-1;  // 80+
rates_sri[10][0]=28; rates_sri[10][1]=32; rates_sri[10][2]=42; rates_sri[10][3]=45; // dep. child

// rates for ATLAS AMERICA
// updated factors 04/08/04 - revised rates 05

var rates_mnui = new MakeArray(11);
    for (var i=0; i<11; i++){
        rates_mnui[i] = new MakeArray(5);
    }
    
//      $50,000               $100,000              $250,000            $500,000              $1,000,000       
rates_mnui[0][0]=38;  rates_mnui[0][1]=45;  rates_mnui[0][2]=53;  rates_mnui[0][3]=54;   rates_mnui[0][4]=65;   // solo child
rates_mnui[1][0]=42;  rates_mnui[1][1]=49;  rates_mnui[1][2]=62;  rates_mnui[1][3]=63;   rates_mnui[1][4]=75;   // 18-25
rates_mnui[2][0]=42;  rates_mnui[2][1]=49;  rates_mnui[2][2]=62;  rates_mnui[2][3]=63;   rates_mnui[2][4]=75;   // 26-29
rates_mnui[3][0]=55;  rates_mnui[3][1]=66;  rates_mnui[3][2]=81;  rates_mnui[3][3]=83;   rates_mnui[3][4]=96;   // 30-39
rates_mnui[4][0]=83;  rates_mnui[4][1]=95;  rates_mnui[4][2]=118; rates_mnui[4][3]=126;  rates_mnui[4][4]=141;  // 40-49
rates_mnui[5][0]=119; rates_mnui[5][1]=146; rates_mnui[5][2]=174; rates_mnui[5][3]=178;  rates_mnui[5][4]=205;  // 50-59
rates_mnui[6][0]=158; rates_mnui[6][1]=216; rates_mnui[6][2]=229; rates_mnui[6][3]=230;  rates_mnui[6][4]=256;  // 60-64
rates_mnui[7][0]=200; rates_mnui[7][1]=250; rates_mnui[7][2]=277; rates_mnui[7][3]=278;  rates_mnui[7][4]=300;  // 65-69
rates_mnui[8][0]=254; rates_mnui[8][1]=-1;  rates_mnui[8][2]=-1;  rates_mnui[8][3]=-1;   rates_mnui[8][4]=-1;   // 70-79
rates_mnui[9][0]=500; rates_mnui[9][1]=-1;  rates_mnui[9][2]=-1;  rates_mnui[9][3]=-1;   rates_mnui[9][4]=-1;   // 80+
rates_mnui[10][0]=25; rates_mnui[10][1]=27; rates_mnui[10][2]=33; rates_mnui[10][3]=34;  rates_mnui[10][4]=38;  // dep. child
//  "xxx" where xxx is the monthly rate 

var SportsRiders = new MakeArray(3);
    SportsRiders[0] = 1.2;      // sports rider multiple for IMG
    SportsRiders[1] = 1.15;     // sports rider multiple for SRI
    SportsRiders[2] = 1.2;     // sports rider multiple for MNUI. Updated 04/30/03 Old rider 1.12.
	
// Incidental Home Country Rider 	New 05/05/03
	
var IncidentalHomeRiders = new MakeArray(3);
    IncidentalHomeRiders[0] = 1;      // Incidental Home Country Rider rider for IMG. Included
    IncidentalHomeRiders[1] = 1;     // Incidental Home Country Rider rider for SRI. Included
    IncidentalHomeRiders[2] = 1;     // Incidental Home Country Rider rider for MNUI.	Included
		
	// Terrorism Rider New 02/10/05

var TerrorismRiders = new MakeArray(3);
    TerrorismRiders[0] = 0.25;      // IMG
    TerrorismRiders[1] = 1;     // SRI 
    TerrorismRiders[2] = 1;     // MNUI

// deductible rates for IMG and SRI   
dedRates = new MakeArray(6);
    for (var i=0; i<6; i++){
        dedRates[i] = new MakeArray(3);
    }
    
//  IMG                     SRI    						MNUI
dedRates[0][0]=1.25;    dedRates[0][1]=1.30;     dedRates[0][2]=1.5;  // $0
dedRates[1][0]=1.1;     dedRates[1][1]=1.10;     dedRates[1][2]=1.1;  // $100 and $125
dedRates[2][0]=1.0;     dedRates[2][1]=1.0;      dedRates[2][2]=1.0;  // $250
dedRates[3][0]=0.9;     dedRates[3][1]=0.9;      dedRates[3][2]=0.9;  // $500
dedRates[4][0]=0.8;     dedRates[4][1]=0.8;      dedRates[4][2]=0.8;  // $1000
dedRates[5][0]=0.7;     dedRates[5][1]=0.7;      dedRates[5][2]=0.7;  // $2500

// constants
var IMG=0;
var SRI=1;
var MNUI=2;

/*=========*/

function RCompIMG (LForm){
  var monthlyPremium;
  var spousePremium;
  var totalPremium;

// inputs: this bit is in both functions - sloppy, but programmer was out of time.
// if you (whoever) get a chance, this should be calced in RComp, and passed to 
// all the subroutines
  var ApplicantAge      = LForm.applicant_age.selectedIndex;
  var SpouseAge         = LForm.spouse_age.selectedIndex - 1; // 0 is "no spouse"
  var deductibleAmt     = LForm.deductible_img.selectedIndex;
  var coverageAmt       = LForm.coverage_img.selectedIndex;

  var factors           = (LForm.sports_img[0].checked ? SportsRiders[IMG] : 1);
   //021005 Terrorism  Rider

  var factors2          = 1;
  
  var Children = 0;
    if (LForm.children[1].checked) Children = 1;
    if (LForm.children[2].checked) Children = 2;
    if (LForm.children[3].checked) Children = 3;
    		// Update 5 children 05/05/03
	if (LForm.children[4].checked) Children = 4;
	if (LForm.children[5].checked) Children = 5;
  var Months = 6 + LForm.length.selectedIndex; // note, the select starts with 6 months

// output fields
  var premium_img = LForm.total_rate_img;

  if (rates_img[ApplicantAge][coverageAmt] == -1 ) {
    // oops, this level of coverage isn't even offered for this age group!
    monthlyPremium =0;
    premium_img.value = "N/A";
    return;
  } else {
    // get the monthly premium rate out of the rates array up top
    monthlyPremium = rates_img[ApplicantAge][coverageAmt];
  }
    
  if (SpouseAge >= 0) {
        if (rates_img[SpouseAge][coverageAmt] == -1) {
            // oops, this level of coverage isn't even offered for this age group!
            monthlyPremium=0;
            premium_img.value = "N/A";
            return;
        } else {
        // get anothe premium rate from the top array, and add it
        monthlyPremium += rates_img[SpouseAge][coverageAmt];
        }
    }
  if (Children)  { 
    // add the kids' rate times the number of kids
    monthlyPremium += ( rates_img[10][coverageAmt] * Children ); 
  }
  totalPremium = (monthlyPremium * Months);
  totalPremium = totalPremium * dedRates[deductibleAmt][IMG] * factors;
     // Terrorism Rider 02/10/05
  if (factors2!=1) {
  totalPremiumTerrorism = 0;
  
  totalPremium = totalPremium + totalPremiumTerrorism}
   // Terrorism Rider 02/10/05
  premium_img.value = '$' + fix (totalPremium);
}

/*========*/

function RCompSRI (LForm) {
  var monthlyPremium;
  var spousePremium;
  var totalPremium;
  var renRate =1;       // this is the multiplier for the Renewal Option checkbox on the form
                        // I didn't know what to do with it, so it's just set to 1, which has no effect
                        // please change this, if you know how this option should change the premiums
  var homeRate = 1.1    // Home Country Coverage
  var factors=1;

// inputs
  var ApplicantAge      = LForm.applicant_age.selectedIndex;
  var SpouseAge         = LForm.spouse_age.selectedIndex - 1; // 0 is "no spouse"
  var deductibleAmt     = LForm.sriDeductible.selectedIndex;
  var coverageAmt       = LForm.coverage_sri.selectedIndex;

  var factors           = (LForm.sports_sri[0].checked ? SportsRiders[SRI] : 1);
  
  var Children = 0;
    if (LForm.children[1].checked) Children = 1;
    if (LForm.children[2].checked) Children = 2;
    if (LForm.children[3].checked) Children = 3;
			// Update 5 children 05/05/03
	if (LForm.children[4].checked) Children = 4;
	if (LForm.children[5].checked) Children = 5;
  var Months = 6 + LForm.length.selectedIndex; // note, the select starts with 6 months

// output fields
  var premium_sri = LForm.total_rate_sri;

  
  
  if (rates_sri[ApplicantAge][coverageAmt] == -1 ) {
    // oops, this level of coverage isn't even offered for this age group!
    monthlyPremium =0;
    premium_sri.value = "N/A";
    return;
  } else {
    monthlyPremium = rates_sri[ApplicantAge][coverageAmt];

	 	if (ApplicantAge == 9) {
MM_popupMsg('NOTE: Maximum Coverage for the 80+ age group is:\r$15,000 for Liaison International\r$10,000 for Atlas')
	 }
	 
	if (ApplicantAge == 8) {
MM_popupMsg2('NOTE: Maximum Coverage for the 70-79 age group is:\r$50,000 for ExPatriot Plus\r$50,000 for Liaison International\r$50,000 for Atlas')
	 }
	 	 
  }
    
  if (SpouseAge >= 0) {
        if (rates_sri[SpouseAge][coverageAmt] == -1) {
            // oops, this level of coverage isn't even offered for this age group!
            monthlyPremium=0;
            premium_sri.value = "N/A";
            return;
        } else {
        monthlyPremium += rates_sri[SpouseAge][coverageAmt];
        }
    }
  if (Children)  { monthlyPremium += ( rates_sri[10][coverageAmt] * Children ); }
  totalPremium = (monthlyPremium * Months);
  totalPremium = totalPremium * dedRates[deductibleAmt][SRI] * factors;
  premium_sri.value = '$' + fix (totalPremium);
}


/*=======*/

function RCompMNUI (LForm){
  var monthlyPremium;
  var spousePremium;
  var totalPremium;

// inputs: this bit is in both functions - sloppy, but programmer was out of time.
// if you (whoever) get a chance, this should be calced in RComp, and passed to 
// all the subroutines
  var ApplicantAge      = LForm.applicant_age.selectedIndex;
  var SpouseAge         = LForm.spouse_age.selectedIndex - 1; // 0 is "no spouse"
  var deductibleAmt     = LForm.deductible_mnui.selectedIndex;
  var coverageAmt       = LForm.coverage_mnui.selectedIndex;

  var factors           = (LForm.sports_mnui[0].checked ? SportsRiders[MNUI] : 1);
  // New Incidental Home Country Rider 05/05/03
  //var factors2          = (LForm.incidentalhome_mnui[0].checked ? IncidentalHomeRiders[MNUI] : 1);
  

  var Children = 0;
    if (LForm.children[1].checked) Children = 1;
    if (LForm.children[2].checked) Children = 2;
    if (LForm.children[3].checked) Children = 3;
    		// Update 5 children 05/05/03
	if (LForm.children[4].checked) Children = 4;
	if (LForm.children[5].checked) Children = 5;
  var Months = 6 + LForm.length.selectedIndex; // note, the select starts with 6 months

// output fields
  var premium_mnui = LForm.total_rate_mnui;

  if (rates_mnui[ApplicantAge][coverageAmt] == -1 ) {
    // oops, this level of coverage isn't even offered for this age group!
    monthlyPremium =0;
    premium_mnui.value = "N/A";
    return;
  } else {
    // get the monthly premium rate out of the rates array up top
    monthlyPremium = rates_mnui[ApplicantAge][coverageAmt];
  }
    
  if (SpouseAge >= 0) {
        if (rates_mnui[SpouseAge][coverageAmt] == -1) {
            // oops, this level of coverage isn't even offered for this age group!
            monthlyPremium=0;
            premium_mnui.value = "N/A";
            return;
        } else {
        // get anothe premium rate from the top array, and add it
        monthlyPremium += rates_mnui[SpouseAge][coverageAmt];
        }
    }
  if (Children)  { 
    // add the kids' rate times the number of kids
    monthlyPremium += ( rates_mnui[10][coverageAmt] * Children ); 
  }
  totalPremium = (monthlyPremium * Months);
  totalPremium = totalPremium * dedRates[deductibleAmt][MNUI] * factors;
    // New Incidental Home Country Rider 05/05/03
  //totalPremium = totalPremium * factors2;
     // New Policy's fee $5 BEGINS
 // totalPremium = totalPremium + 5; 01/07/04
  // New Policy's fee $5 ENDS
  premium_mnui.value = '$' + fix (totalPremium);
}

function MM_popupMsg(msg) { //v1.0
  alert(msg);}
function MM_popupMsg2(msg) { //v1.0
  alert(msg);
}
//-->