﻿ // tagTollCosts format is (NorthernRampsPrice, SouthernRampsPrice, isTollPlaza)
 tagTollCosts = new Array()
 tagTollCosts[0] = new Array(".00",".00","0",0.0) // I-25
 tagTollCosts[1] = new Array(".00",".00","0",1.0)  // Jamaica
 tagTollCosts[2] = new Array(".00",".90","0",1.7)  // Peoria
 tagTollCosts[3] = new Array("2.00","2.00","1") // Plaza A
 tagTollCosts[4] = new Array(".90",".00","0",3.5) // Chambers
 tagTollCosts[5] = new Array(".90",".00","0",4.4) // Jordan Rd
 tagTollCosts[6] = new Array(".00",".00","0",5.2) // Parker Rd
 tagTollCosts[7] = new Array(".00",".90","0",8.6) // Gartrell Rd
 tagTollCosts[8] = new Array(".00",".90","0",10.4) // Smoky Hill
 tagTollCosts[9] = new Array(".00",".90","0",13.2) // Quincy
 tagTollCosts[10] = new Array("2.25","2.25","1") // Plaza B
 tagTollCosts[11] = new Array(".90",".00","0",16.2) // Jewell
 tagTollCosts[12] = new Array(".90",".00","0",19.0) // 6th Parkway
 tagTollCosts[13] = new Array(".00",".00","0",20.3) // I-70
 tagTollCosts[14] = new Array("2.25","2.25","1") // Plaza C
 tagTollCosts[15] = new Array(".90",".00","0",24.3) // 56th Ave
 tagTollCosts[16] = new Array(".90",".00","0",25.3) // 64th Ave
 tagTollCosts[17] = new Array(".00",".00","0",27.6) // Pena Blvd
 tagTollCosts[18] = new Array("2.25","2.25","1") // Plaza D
 tagTollCosts[19] = new Array(".90",".00","0",30.2) // 96th Ave
 tagTollCosts[20] = new Array(".90",".00","0",31.3) // 104th
 tagTollCosts[21] = new Array(".90",".00","0",33.8) // 120th
 tagTollCosts[22] = new Array(".00",".00","0",35.3) // I-76
 tagTollCosts[23] = new Array(".00",".90","0",38.1) // US 85
 tagTollCosts[24] = new Array("2.25","2.25","1") // Plaza E
 tagTollCosts[25] = new Array(".90",".00","0",43.5) // Colorado
 tagTollCosts[26] = new Array(".90",".00","0",44.5) // York
 tagTollCosts[27] = new Array(".00",".00","0",46.1) // I-25
 tagTollCosts[28] = new Array(".00",".80","0",48.1) // Sheridan Pkwy
 tagTollCosts[29] = new Array("3.10","3.10","1",48.9) // Plaza NWP
 tagTollCosts[30] = new Array(".80",".00","0",53) // US 287
 tagTollCosts[31] = new Array(".00",".00","0",55.6) // 96th St
 
 
  // plateTollCosts format is (NorthernRampsPrice, SouthernRampsPrice, isTollPlaza)
 plateTollCosts = new Array()
 plateTollCosts[0] = new Array(".00",".00","0",0.0) // I-25
 plateTollCosts[1] = new Array(".00",".00","0",1.0)  // Jamaica
 plateTollCosts[2] = new Array(".00","1.00","0",1.7)  // Peoria
 plateTollCosts[3] = new Array("2.25","2.25","1") // Plaza A
 plateTollCosts[4] = new Array("1.00",".00","0",3.5) // Chambers
 plateTollCosts[5] = new Array("1.00",".00","0",4.4) // Jordan Rd
 plateTollCosts[6] = new Array(".00",".00","0",5.2) // Parker Rd
 plateTollCosts[7] = new Array(".00","1.00","0",8.6) // Gartrell Rd
 plateTollCosts[8] = new Array(".00","1.00","0",10.4) // Smoky Hill
 plateTollCosts[9] = new Array(".00","1.00","0",13.2) // Quincy
 plateTollCosts[10] = new Array("2.50","2.50","1") // Plaza B
 plateTollCosts[11] = new Array("1.00",".00","0",16.2) // Jewell
 plateTollCosts[12] = new Array("1.00",".00","0",19.0) // 6th Parkway
 plateTollCosts[13] = new Array(".00",".00","0",20.3) // I-70
 plateTollCosts[14] = new Array("2.50","2.50","1") // Plaza C
 plateTollCosts[15] = new Array("1.00",".00","0",24.3) // 56th Ave
 plateTollCosts[16] = new Array("1.00",".00","0",25.3) // 64th Ave
 plateTollCosts[17] = new Array(".00",".00","0",27.6) // Pena Blvd
 plateTollCosts[18] = new Array("2.50","2.50","1") // Plaza D
 plateTollCosts[19] = new Array("1.00",".00","0",30.2) // 96th Ave
 plateTollCosts[20] = new Array("1.00",".00","0",31.3) // 104th
 plateTollCosts[21] = new Array("1.00",".00","0",33.8) // 120th
 plateTollCosts[22] = new Array(".00",".00","0",35.3) // I-76
 plateTollCosts[23] = new Array(".00","1.00","0",38.1) // US 85
 plateTollCosts[24] = new Array("2.50","2.50","1") // Plaza E
 plateTollCosts[25] = new Array("1.00",".00","0",43.5) // Colorado
 plateTollCosts[26] = new Array("1.00",".00","0",44.5) // York
 plateTollCosts[27] = new Array(".00",".00","0",46.1) // I-25
 plateTollCosts[28] = new Array(".00","1.00","0",48.1) // Sheridan Pkwy
 plateTollCosts[29] = new Array("3.10","3.10","1",48.9) // Plaza NWP
 plateTollCosts[30] = new Array("1.00",".00","0",53) // US 287
 plateTollCosts[31] = new Array(".00",".00","0",55.6) // 96th St
 
 exitCycle = 1
 function imageCalc(exitIndex){
  if (exitCycle % 2 == 0){
  window.document.forms[0].offRamp.selectedIndex = exitIndex
  }else{
  window.document.forms[0].onRamp.selectedIndex = exitIndex
  window.document.forms[0].offRamp.selectedIndex = 0
  }
  exitCycle ++
  formValidate()
 }
 
 function formValidate(){
  window.document.forms[0].TagToll.value = ""
  window.document.forms[0].PlateToll.value = ""
  window.document.forms[0].Miles.value = ""
  rndTrip = (window.document.forms[0].rndTrip.checked)?2:1;
  numAxles = parseFloat(window.document.forms[0].numAxles.options[window.document.forms[0].numAxles.selectedIndex].value);
  onRamp = parseFloat(window.document.forms[0].onRamp.options[window.document.forms[0].onRamp.selectedIndex].value);
  offRamp = parseFloat(window.document.forms[0].offRamp.options[window.document.forms[0].offRamp.selectedIndex].value);
  if ((isNaN(onRamp))||(isNaN(offRamp))){
   return;
  }
  
  
  if (onRamp == offRamp){
   alert("Please select an Exit Point that is different from your Entrance Point");
   window.document.forms('calcForm').offRamp.selectedIndex = 0;
   return;
  }
  
  if (onRamp < offRamp){
   dirTravel = 0 /***Northbound Traffic***/
  } else if (onRamp > offRamp) {
   dirTravel = 1 /***Southbound Traffic***/
  }
  
  tollCalc(onRamp,offRamp,dirTravel)
 }
 
 function tollCalc(onRamp,offRamp,dirTravel){
  if (dirTravel == 0){
   /***Northbound Traffic - Use Northern ramp price for onramp and Southern ramp price for offramp***/
   TagTollTotal = (parseFloat(tagTollCosts[onRamp][0]) + parseFloat(tagTollCosts[offRamp][1]));
   
   /***Add cost for any plazas between onramp and offramp (tollcost * number of axles)***/
   for (x = onRamp; x <= offRamp; x++){
    if (tagTollCosts[x][2] == 1){
     TagTollTotal += parseFloat(tagTollCosts[x][0])*numAxles;
    }
   }
  }
  
  if (dirTravel == 1){
   /***Southbound Traffic - Use Southern ramp price for onramp and Northern ramp price for offramp***/
   TagTollTotal = (parseFloat(tagTollCosts[onRamp][1]) + parseFloat(tagTollCosts[offRamp][0]));
   
   /***Add cost for any plazas between onramp and offramp (tollcost * number of axles)***/
   for (x = offRamp; x <= onRamp; x++){
    if (tagTollCosts[x][2] == 1){
     TagTollTotal += parseFloat(tagTollCosts[x][1])*numAxles;
    }
   }
  }
  
  
  if (dirTravel == 0){
   /***Northbound Traffic - Use Northern ramp price for onramp and Southern ramp price for offramp***/
   PlateTollTotal = (parseFloat(plateTollCosts[onRamp][0]) + parseFloat(plateTollCosts[offRamp][1]));
   
   /***Add cost for any plazas between onramp and offramp (tollcost * number of axles)***/
   for (x = onRamp; x <= offRamp; x++){
    if (plateTollCosts[x][2] == 1){
     PlateTollTotal += parseFloat(plateTollCosts[x][0])*numAxles;
    }
   }
  }
  
  if (dirTravel == 1){
   /***Southbound Traffic - Use Southern ramp price for onramp and Northern ramp price for offramp***/
   PlateTollTotal = (parseFloat(plateTollCosts[onRamp][1]) + parseFloat(plateTollCosts[offRamp][0]));
   
   /***Add cost for any plazas between onramp and offramp (tollcost * number of axles)***/
   for (x = offRamp; x <= onRamp; x++){
    if (plateTollCosts[x][2] == 1){
     PlateTollTotal += parseFloat(plateTollCosts[x][1])*numAxles;
    }
   }
  }
  
  TagTollTotal = TagTollTotal * rndTrip
  PlateTollTotal = PlateTollTotal * rndTrip
  window.document.forms[0].TagToll.value = formatCurrency(TagTollTotal);
  window.document.forms[0].PlateToll.value = formatCurrency(PlateTollTotal);
  mileCalc(onRamp,offRamp,dirTravel)
 }
 
 function mileCalc(onRamp,offRamp,dirTravel){
  if (dirTravel == 0){
   milesTotal = tagTollCosts[offRamp][3] - tagTollCosts[onRamp][3]
  }
  if (dirTravel == 1){
   milesTotal = tagTollCosts[onRamp][3] - tagTollCosts[offRamp][3]
  }
  milesTotal = milesTotal * rndTrip
  window.document.forms[0].Miles.value = formatDecimal(milesTotal, 2)
 }
 
 function formatCurrency(num) {
  num = num.toString().replace(/\$|\,/g,'');
  if(isNaN(num))
  num = "0";
  sign = (num == (num = Math.abs(num)));
  num = Math.floor(num*100+0.50000000001);
  cents = num%100;
  num = Math.floor(num/100).toString();
  if(cents<10)
  cents = "0" + cents;
  for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
  num = num.substring(0,num.length-(4*i+3))+','+
  num.substring(num.length-(4*i+3));
  return (((sign)?'':'-') + '$' + num + '.' + cents);
 }
 
 function formatDecimal (expr, decplaces) {
 // raise incoming value by power of 10 times the
 // number of decimal places; round to an integer; convert to string
 var str = "" + Math.round (eval(expr) * Math.pow(10,decplaces))
 // pad small value strings with zeros to the left of rounded number
 while (str.length <= decplaces) {
  str = "0" + str
 }
 // establish location of decimal point
 var decpoint = str.length - decplaces
 // assemble final result from: (a) the string up to the position of
 // the decimal point; (b) the decimal point; and (c) the balance
 // of the string. Return finished product.
 return str.substring(0,decpoint) + "." +
 str.substring(decpoint,str.length);
 }

 function I25TollTable() {
 var rate_window25=window.open("Default.aspx?pn=tollTable","rate_window25","toolbar=no,location=no,scrollbars=yes,resizable=yes,width=830,height=620");
 rate_window25.focus();
 }