// 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(3);
}
 
//      $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 Outside the United States

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

//      $50,000                     $100,000                       $500,000                     $1,000,000
rates_sri[0][0]="03201605";  rates_sri[0][1]="03601815";  rates_sri[0][2]="04001980";  rates_sri[0][3]="04302160";  // solo child
rates_sri[1][0]="02901440";  rates_sri[1][1]="03401695";  rates_sri[1][2]="04001995";  rates_sri[1][3]="04502250";  // 19-29
rates_sri[2][0]="03401725";  rates_sri[2][1]="04001995";  rates_sri[2][2]="05302640";  rates_sri[2][3]="06103045";  // 30-39
rates_sri[3][0]="05802895";  rates_sri[3][1]="06503240";  rates_sri[3][2]="07303645";  rates_sri[3][3]="08104035";  // 40-49
rates_sri[4][0]="10004995";  rates_sri[4][1]="11405700";  rates_sri[4][2]="12206075";  rates_sri[4][3]="12906450";  // 50-59
rates_sri[5][0]="12506240";  rates_sri[5][1]="15007500";  rates_sri[5][2]="16408190";  rates_sri[5][3]="18509240";  // 60-64
rates_sri[6][0]="14607290";  rates_sri[6][1]="16007995";  rates_sri[6][2]="16808400";  rates_sri[6][3]="19109540";  // 65-69
rates_sri[7][0]="21910950";  rates_sri[7][1]="30815390";  rates_sri[7][2]="-1";        rates_sri[7][3]="-1";        // 70-79
rates_sri[8][0]="38319140";  rates_sri[8][1]="-1";        rates_sri[8][2]="-1";        rates_sri[8][3]="-1";        // 80+
rates_sri[9][0]="02001005";  rates_sri[9][1]="02501245";  rates_sri[9][2]="02701350";  rates_sri[9][3]="03001515";  // 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]="03101500"; rates_mnui[0][1]="03401800"; rates_mnui[0][2]="03701875"; rates_mnui[0][3]="03901950"; rates_mnui[0][4]="04302100"; // solo child
rates_mnui[1][0]="03101590"; rates_mnui[1][1]="03601800"; rates_mnui[1][2]="03901950"; rates_mnui[1][3]="04102100"; rates_mnui[1][4]="04602250"; // 19-29
rates_mnui[2][0]="03601800"; rates_mnui[2][1]="04102100"; rates_mnui[2][2]="05002550"; rates_mnui[2][3]="05502700"; rates_mnui[2][4]="06103150"; // 30-39
rates_mnui[3][0]="05802850"; rates_mnui[3][1]="06403150"; rates_mnui[3][2]="06903450"; rates_mnui[3][3]="07203600"; rates_mnui[3][4]="07903900"; // 40-49
rates_mnui[4][0]="09504800"; rates_mnui[4][1]="10805400"; rates_mnui[4][2]="11605700"; rates_mnui[4][3]="12006000"; rates_mnui[4][4]="12706300"; // 50-59
rates_mnui[5][0]="12106000"; rates_mnui[5][1]="14307050"; rates_mnui[5][2]="15207500"; rates_mnui[5][3]="15907950"; rates_mnui[5][4]="18909450"; // 60-64
rates_mnui[6][0]="14006900"; rates_mnui[6][1]="15507650"; rates_mnui[6][2]="16408100"; rates_mnui[6][3]="17008400"; rates_mnui[6][4]="19810050"; // 65-69
rates_mnui[7][0]="22010950"; 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]="01700900"; rates_mnui[9][1]="02301200"; rates_mnui[9][2]="02401275"; rates_mnui[9][3]="02601350"; rates_mnui[9][4]="02701500"; // dep. child
// "xxxyyyyy" where xxx is the monthly rate, and yyyyy is the rate for an extra 15 days yyy.yy 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 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.	
	
	// 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][1]=1.30;     dedRates[0][2]=1.5;  // $0
dedRates[0][0]=1.1;     dedRates[1][1]=1.10;     dedRates[1][2]=1.1;  // $100 and $125
dedRates[1][0]=1.0;     dedRates[2][1]=1.0;      dedRates[2][2]=1.0;  // $250
dedRates[2][0]=0.9;     dedRates[3][1]=0.9;      dedRates[3][2]=0.9;  // $500
dedRates[3][0]=0.8;     dedRates[4][1]=0.8;      dedRates[4][2]=0.8;  // $1000
dedRates[4][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
  
  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);
}
//-->