// JavaScript Document

<!--
// Copyright 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));

// 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 PATRIOT AMERICA - For non-US Citizens

var rates_img = new MakeArray(10);
    for (var i=0; i<10; i++){
        rates_img[i] = new MakeArray(4);
    }
    
//      $50,000                   $100,000                       $500,000                $1,000,000 
rates_img[0][0]="03902025"; rates_img[0][1]="04602400"; rates_img[0][2]="05903000"; rates_img[0][3]="06603375"; // solo child
rates_img[1][0]="04302175"; rates_img[1][1]="05002625"; rates_img[1][2]="06403300"; rates_img[1][3]="07603825"; // 19-29
rates_img[2][0]="05602850"; rates_img[2][1]="06703375"; rates_img[2][2]="08404275"; rates_img[2][3]="09704875"; // 30-39
rates_img[3][0]="08404275"; rates_img[3][1]="09604875"; rates_img[3][2]="12606375"; rates_img[3][3]="14207200"; // 40-49
rates_img[4][0]="12006075"; rates_img[4][1]="14707425"; rates_img[4][2]="17809000"; rates_img[4][3]="20610350"; // 50-59
rates_img[5][0]="14207200"; rates_img[5][1]="17408775"; rates_img[5][2]="20710425"; rates_img[5][3]="24812525"; // 60-64
rates_img[6][0]="16208175"; rates_img[6][1]="20810500"; rates_img[6][2]="22611400"; rates_img[6][3]="27013575"; // 65-69
rates_img[7][0]="21911025"; rates_img[7][1]="-1";       rates_img[7][2]="-1";       rates_img[7][3]="-1";       // 70-79
rates_img[8][0]="38119125"; rates_img[8][1]="-1";       rates_img[8][2]="-1";       rates_img[8][3]="-1";       // 80+
rates_img[9][0]="02601350"; rates_img[9][1]="02801500"; rates_img[9][2]="03601875"; rates_img[9][3]="03902025"; // dep. child
// "xxxyyyyy" where xxx is the monthly rate, and yyy.yy is the rate for an extra 15 days 


// 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(10);
    for (var i=0; i<10; i++) {
        rates_sri[i] = new MakeArray(4);
    }

//      $50,000                      $100,000                      $500,000                   $1,000,000
rates_sri[0][0]="04602295";  rates_sri[0][1]="05402700";  rates_sri[0][2]="06803405";  rates_sri[0][3]="07603795"; // solo child
rates_sri[1][0]="04602295";  rates_sri[1][1]="05302640";  rates_sri[1][2]="07203600";  rates_sri[1][3]="08104050"; // 19-29
rates_sri[2][0]="06103045";  rates_sri[2][1]="07203600";  rates_sri[2][2]="09604800";  rates_sri[2][3]="10705340"; // 30-39
rates_sri[3][0]="09204590";  rates_sri[3][1]="10305145";  rates_sri[3][2]="14107050";  rates_sri[3][3]="15507740"; // 40-49
rates_sri[4][0]="14107050";  rates_sri[4][1]="17108550";  rates_sri[4][2]="20510245";  rates_sri[4][3]="24212090"; // 50-59
rates_sri[5][0]="17108550";  rates_sri[5][1]="21510740";  rates_sri[5][2]="26613290";  rates_sri[5][3]="30515240"; // 60-64
rates_sri[6][0]="21910950";  rates_sri[6][1]="-1";        rates_sri[6][2]="-1";        rates_sri[6][3]="-1";       // 65-69
rates_sri[7][0]="27613800";  rates_sri[7][1]="-1";        rates_sri[7][2]="-1";        rates_sri[7][3]="-1";       // 70-79
rates_sri[8][0]="48024000";  rates_sri[8][1]="-1";        rates_sri[8][2]="-1";        rates_sri[8][3]="-1";       // 80+
rates_sri[9][0]="02801395";  rates_sri[9][1]="03201605";  rates_sri[9][2]="04202100";  rates_sri[9][3]="04502250"; // dep. child

//  "xxxyyyyy" where xxx is the monthly rate, and yyyyy is the rate for an extra 15 days yyy.yy  01/07/04 JRivero

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

var rates_mnui = new MakeArray(10);
    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]="03801950"; rates_mnui[0][1]="04502250"; rates_mnui[0][2]="05302700"; rates_mnui[0][3]="05402700"; rates_mnui[0][4]="06503300"; // solo child
rates_mnui[1][0]="04202100"; rates_mnui[1][1]="04902550"; rates_mnui[1][2]="06203000"; rates_mnui[1][3]="06303150"; rates_mnui[1][4]="07503750"; // 18-29
rates_mnui[2][0]="05502850"; rates_mnui[2][1]="06603300"; rates_mnui[2][2]="08104050"; rates_mnui[2][3]="08304200"; rates_mnui[2][4]="09604800"; // 30-39
rates_mnui[3][0]="08304200"; rates_mnui[3][1]="09504800"; rates_mnui[3][2]="11805850"; rates_mnui[3][3]="12606300"; rates_mnui[3][4]="14107050"; // 40-49
rates_mnui[4][0]="11906000"; rates_mnui[4][1]="14607350"; rates_mnui[4][2]="17407500"; rates_mnui[4][3]="17808850"; rates_mnui[4][4]="20510200"; // 50-59
rates_mnui[5][0]="15807950"; rates_mnui[5][1]="21610800"; rates_mnui[5][2]="22911400"; rates_mnui[5][3]="23011550"; rates_mnui[5][4]="25612750"; // 60-64
rates_mnui[6][0]="20010050"; rates_mnui[6][1]="25012450"; rates_mnui[6][2]="27713800"; rates_mnui[6][3]="27813950"; rates_mnui[6][4]="30015000"; // 65-69
rates_mnui[7][0]="25412750"; rates_mnui[7][1]="-1";       rates_mnui[7][2]="-1";       rates_mnui[7][3]="-1";       rates_mnui[7][4]="-1";       // 70-79
rates_mnui[8][0]="50025050"; rates_mnui[8][1]="-1";       rates_mnui[8][2]="-1";       rates_mnui[8][3]="-1";       rates_mnui[8][4]="-1";       // 80+
rates_mnui[9][0]="02801350"; rates_mnui[9][1]="02701425"; rates_mnui[9][2]="03301650"; rates_mnui[9][3]="03401650"; rates_mnui[9][4]="03801950"; // dep. child
//  "xxxyyyyy" where xxx is the monthly rate, and yyy.yy is the rate for an extra 15 days   

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 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;

//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; //7-13-7 Trevor - overrode value since radio buttons are gone

  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 Length = LForm.Months.selectedIndex;
     Months = Math.floor(Length);
  var LengthDays = LForm.Days.selectedIndex;
     Days = Math.floor(LengthDays);
     FortNight = 0;
  if (Days!= 0) FortNight = 1;

// 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 = parseInt(rates_img[ApplicantAge][coverageAmt].substring(0,3), 10);
			//NEW 022705

	 	if (ApplicantAge == 8) {
MM_popupMsg('NOTE: Maximum Coverage for the 80+ age group is:\r$10,000 for Patriot America\r$15,000 for Liasion International\r$10,000 for Atlas America')
	 }
	 
	if (ApplicantAge == 7) {
MM_popupMsg2('NOTE: Maximum Coverage for the 70-79 age group is:\r$50,000 for Patriot America\r$50,000 for Liasion International\r$50,000 for Atlas America')
	 }
	 	 
	 //NEW 022705
  }
    
  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 += parseInt( rates_img[SpouseAge][coverageAmt].substring(0,3), 10 );
        }
    }
  if (Children)  { 
    // add the kids' rate times the number of kids
    monthlyPremium += ( parseInt(rates_img[9][coverageAmt].substring(0,3), 10) * Children ); 
  }
  totalPremium = (monthlyPremium * Months);
  
  if ((Days!= 0) && (Months==0) && (Days <= 5))  {
    // get the special 15 day rates for all the people, and add them in to the total
    //totalPremium += parseInt(rates_img[ApplicantAge][coverageAmt].substring(3,6), 10);
    DayPremium = parseInt(rates_img[ApplicantAge][coverageAmt].substring(3,9), 10)/100;
	totalPremium += (DayPremium * 5)/15;
		if (SpouseAge >=0 ) {
            DayPremium  = parseInt(rates_img[SpouseAge][coverageAmt].substring(3,9), 10)/100;
	        totalPremium += (DayPremium * 5)/15;
    }
    DayPremium  = (parseInt(rates_img[9][coverageAmt].substring(3,9), 10)/100) * Children;
	totalPremium += (DayPremium * 5)/15;
	
   } else {
	  if (FortNight) { 
    // get the special 15 day rates for all the people, and add them in to the total
    //totalPremium += parseInt(rates_img[ApplicantAge][coverageAmt].substring(3,6), 10);
    DayPremium = parseInt(rates_img[ApplicantAge][coverageAmt].substring(3,9), 10)/100;
	totalPremium += (DayPremium * Days)/15;
		if (SpouseAge >=0 ) {
            DayPremium  = parseInt(rates_img[SpouseAge][coverageAmt].substring(3,9), 10)/100;
	        totalPremium += (DayPremium * Days)/15;
    }
    DayPremium  = (parseInt(rates_img[9][coverageAmt].substring(3,9), 10)/100) * Children;
	totalPremium += (DayPremium * Days)/15;
  }
  }

  totalPremium = totalPremium * dedRates[deductibleAmt][IMG] * factors;
   // Terrorism Rider 02/10/05
  if (factors2!=1) {
  totalPremiumTerrorism = 0; //7-13-7 Trevor - overrode value since radio buttons are gone
  
  totalPremium = totalPremium + totalPremiumTerrorism}
   // Terrorism Rider 02/10/05
  premium_img.value = '$' + fix (totalPremium);
}

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

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

// 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 Length = LForm.Months.selectedIndex;
     Months = Math.floor(Length);
  var LengthDays = LForm.Days.selectedIndex;
     Days = Math.floor(LengthDays);
     FortNight = 0;
  if (Days!= 0) FortNight = 1;

// 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 {
    // get the monthly premium rate out of the rates array up top
    monthlyPremium = parseInt(rates_sri[ApplicantAge][coverageAmt].substring(0,3), 10);
  }
    
  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_img.value = "N/A";
            return;
        } else {
        // get anothe premium rate from the top array, and add it
        monthlyPremium += parseInt( rates_sri[SpouseAge][coverageAmt].substring(0,3), 10 );
        }
    }
  if (Children)  { 
    // add the kids' rate times the number of kids
    monthlyPremium += ( parseInt(rates_sri[9][coverageAmt].substring(0,3), 10) * Children ); 
  }
  totalPremium = (monthlyPremium * Months);
        // 041904 BEGINS
  if ((Days!= 0) && (Months==0) && (Days <= 10))  {
    // get the special 15 day rates for all the people, and add them in to the total
    //totalPremium += parseInt(rates_img[ApplicantAge][coverageAmt].substring(3,6), 10);
    DayPremium = parseInt(rates_sri[ApplicantAge][coverageAmt].substring(3,9), 10)/100;
	totalPremium += (DayPremium * 10)/15;
		if (SpouseAge >=0 ) {
            DayPremium  = parseInt(rates_sri[SpouseAge][coverageAmt].substring(3,9), 10)/100;
	        totalPremium += (DayPremium * 10)/15;
    }
    DayPremium  = (parseInt(rates_sri[9][coverageAmt].substring(3,9), 10)/100) * Children;
	totalPremium += (DayPremium * 10)/15;
	
   } else {
  if (FortNight) { 
    // get the special 15 day rates for all the people, and add them in to the total
    //totalPremium += parseInt(rates_img[ApplicantAge][coverageAmt].substring(3,6), 10);
    DayPremium = parseInt(rates_sri[ApplicantAge][coverageAmt].substring(3,9), 10)/100;
	totalPremium += (DayPremium * Days)/15;
		if (SpouseAge >=0 ) {
        DayPremium = parseInt(rates_sri[SpouseAge][coverageAmt].substring(3,9), 10)/100;
		totalPremium += (DayPremium * Days)/15;
    }
    DayPremium = (parseInt(rates_sri[9][coverageAmt].substring(3,9), 10)/100) * Children;
	totalPremium += (DayPremium * Days)/15;
  }
  }

  totalPremium = totalPremium * dedRates[deductibleAmt][SRI] * factors;
  premium_sri.value = '$' + fix (totalPremium);
}

/////////

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

// 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 Length = LForm.Months.selectedIndex;
     Months = Math.floor(Length);
  var LengthDays = LForm.Days.selectedIndex;
     Days = Math.floor(LengthDays);
     FortNight = 0;
  if (Days!= 0) FortNight = 1;

// 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 = parseInt(rates_mnui[ApplicantAge][coverageAmt].substring(0,3), 10);
  }
    
  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 += parseInt( rates_mnui[SpouseAge][coverageAmt].substring(0,3), 10 );
        }
    }
  if (Children)  { 
    // add the kids' rate times the number of kids
    monthlyPremium += ( parseInt(rates_mnui[9][coverageAmt].substring(0,3), 10) * Children ); 
  }
  totalPremium = (monthlyPremium * Months);

  if ((Days!= 0) && (Months==0) && (Days <= 7))  {
    // get the special 15 day rates for all the people, and add them in to the total
    //totalPremium += parseInt(rates_mnui[ApplicantAge][coverageAmt].substring(3,6), 10);
    DayPremium = parseInt(rates_mnui[ApplicantAge][coverageAmt].substring(3,9), 10)/100;
	totalPremium += (DayPremium * 7)/15;
		if (SpouseAge >=0 ) {
            DayPremium  = parseInt(rates_mnui[SpouseAge][coverageAmt].substring(3,9), 10)/100;
	        totalPremium += (DayPremium * 7)/15;
    }
    DayPremium  = (parseInt(rates_mnui[9][coverageAmt].substring(3,9), 10)/100) * Children;
	totalPremium += (DayPremium * 7)/15;
	
   } else {
	  if (FortNight) { 
    // get the special 15 day rates for all the people, and add them in to the total
    //totalPremium += parseInt(rates_mnui[ApplicantAge][coverageAmt].substring(3,6), 10);
    DayPremium = parseInt(rates_mnui[ApplicantAge][coverageAmt].substring(3,9), 10)/100;
	totalPremium += (DayPremium * Days)/15;
		if (SpouseAge >=0 ) {
            DayPremium  = parseInt(rates_mnui[SpouseAge][coverageAmt].substring(3,9), 10)/100;
	        totalPremium += (DayPremium * Days)/15;
    }
    DayPremium  = (parseInt(rates_mnui[9][coverageAmt].substring(3,9), 10)/100) * Children;
	totalPremium += (DayPremium * Days)/15;
  }
  }

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