// JavaScript Document

<!--

// Insurancetogo.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 international, all 3 premium levels, monthly and 1/2 monthly
// these rates come from the fax section labeled EXPATRIOT PLUS (For US Citizens)

var rates_img = new MakeArray(11);
    for (var i=0; i<11; i++){
        rates_img[i] = new MakeArray(3);
    }
      
//     $500,000            $1,000,000        $2,000,000  
rates_img[0][0]=32;  rates_img[0][1]=36;  rates_img[0][2]=41;   rates_img[0][3]=46;  rates_img[0][4]=52;    // solo child
rates_img[1][0]=32;  rates_img[1][1]=37;  rates_img[1][2]=43;   rates_img[1][3]=48;  rates_img[1][4]=54;    // 18-25
rates_img[2][0]=32;  rates_img[2][1]=37;  rates_img[2][2]=43;   rates_img[2][3]=48;  rates_img[2][4]=54;    // 26-29
rates_img[3][0]=37;  rates_img[3][1]=43;  rates_img[3][2]=57;   rates_img[3][3]=63;  rates_img[3][4]=72;    // 30-39
rates_img[4][0]=59;  rates_img[4][1]=66;  rates_img[4][2]=73;   rates_img[4][3]=81;  rates_img[4][4]=99;    // 40-49
rates_img[5][0]=96;  rates_img[5][1]=109; rates_img[5][2]=122;  rates_img[5][3]=136; rates_img[5][4]=153;   // 50-59
rates_img[6][0]=109; rates_img[6][1]=129; rates_img[6][2]=153;  rates_img[6][3]=180; rates_img[6][4]=201;   // 60-64
rates_img[7][0]=129; rates_img[7][1]=138; rates_img[7][2]=158;  rates_img[7][3]=189; rates_img[7][4]=243;   // 65-69
rates_img[8][0]=189; rates_img[8][1]=-1;  rates_img[8][2]=-1;   rates_img[8][3]=-1;  rates_img[8][4]=-1;    // 70-79
rates_img[9][0]=378; rates_img[9][1]=-1;  rates_img[9][2]=-1;   rates_img[9][3]=-1;  rates_img[9][4]=-1;    // 80+
rates_img[10][0]=18; rates_img[10][1]=23; rates_img[10][2]=27;  rates_img[10][3]=28; rates_img[10][4]=34;   // dep. child


// rates for sri liason international, all 4 premium levels
// these rates come from the fax section labeled SRI LIASON INTERNATIONAL - Traveling Outside 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]=32;  rates_sri[0][1]=36;  rates_sri[0][2]=40;  rates_sri[0][3]=43;  // solo child
rates_sri[1][0]=29;  rates_sri[1][1]=34;  rates_sri[1][2]=40;  rates_sri[1][3]=45;  // 19-25
rates_sri[2][0]=29;  rates_sri[2][1]=34;  rates_sri[2][2]=40;  rates_sri[2][3]=45;  // 26-29
rates_sri[3][0]=34;  rates_sri[3][1]=40;  rates_sri[3][2]=53;  rates_sri[3][3]=61;  // 30-39
rates_sri[4][0]=58;  rates_sri[4][1]=65;  rates_sri[4][2]=73;  rates_sri[4][3]=81;  // 40-49
rates_sri[5][0]=100; rates_sri[5][1]=114; rates_sri[5][2]=122; rates_sri[5][3]=129; // 50-59
rates_sri[6][0]=125; rates_sri[6][1]=150; rates_sri[6][2]=164; rates_sri[6][3]=185; // 60-64
rates_sri[7][0]=146; rates_sri[7][1]=160; rates_sri[7][2]=168; rates_sri[7][3]=191; // 65-69
rates_sri[8][0]=219; rates_sri[8][1]=308; rates_sri[8][2]=-1;  rates_sri[8][3]=-1;  // 70-79
rates_sri[9][0]=383; rates_sri[9][1]=-1;  rates_sri[9][2]=-1;  rates_sri[9][3]=-1;  // 80+
rates_sri[10][0]=20; rates_sri[10][1]=25; rates_sri[10][2]=27; rates_sri[10][3]=30; // dep. child

// rates for ATLAS International
// 

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]=31;  rates_mnui[0][1]=34;   rates_mnui[0][2]=37;   rates_mnui[0][3]=39;   rates_mnui[0][4]=43;  // solo child
rates_mnui[1][0]=31;  rates_mnui[1][1]=36;   rates_mnui[1][2]=39;   rates_mnui[1][3]=41;   rates_mnui[1][4]=46;  // 19-25
rates_mnui[2][0]=31;  rates_mnui[2][1]=36;   rates_mnui[2][2]=39;   rates_mnui[2][3]=41;   rates_mnui[2][4]=46;  // 25-29
rates_mnui[3][0]=36;  rates_mnui[3][1]=41;   rates_mnui[3][2]=50;   rates_mnui[3][3]=55;   rates_mnui[3][4]=61;  // 30-39
rates_mnui[4][0]=58;  rates_mnui[4][1]=64;   rates_mnui[4][2]=69;   rates_mnui[4][3]=72;   rates_mnui[4][4]=79;  // 40-49
rates_mnui[5][0]=95;  rates_mnui[5][1]=108;  rates_mnui[5][2]=116;  rates_mnui[5][3]=120;  rates_mnui[5][4]=127; // 50-59
rates_mnui[6][0]=121; rates_mnui[6][1]=143;  rates_mnui[6][2]=152;  rates_mnui[6][3]=159;  rates_mnui[6][4]=189; // 60-64
rates_mnui[7][0]=140; rates_mnui[7][1]=155;  rates_mnui[7][2]=164;  rates_mnui[7][3]=170;  rates_mnui[7][4]=198; // 65-69
rates_mnui[8][0]=220; 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]=17; rates_mnui[10][1]=23;  rates_mnui[10][2]=24;  rates_mnui[10][3]=26;  rates_mnui[10][4]=27; // dep. child
//  "xxx monthly  02/10/05 JRivero

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.	
	
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.3;      dedRates[0][2]=1.25; // $0
dedRates[1][0]=1.1;     dedRates[1][1]=1.1;      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;

  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];
					//NEW 022705

	 	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;

  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);
//alert(totalPremium);
  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);
}