//Double Combo Box with Description Code- by Randall Wald (http://www.rwald.com)
//Visit JavaScript Kit (http://javascriptkit.com) for script
//Credit must stay intact for use
var open_in_newwindow=1;    // Set 1 to open links in new window, 0 for no.
var ramp_cost=6375.00;      // ADA Ramp Cost
var buspad=31250.00;        // Bus Pad Installation Cost
var curb_inst=18.00;     	// Curb Installation Cost
var curb_rem_inst=22.22;    // Curb Removal and Installation Cost
//var sw_res_ft= 9000.00;			 Sidewalk Installation Cost
var sw_res_ft= 22395.69;			// Sidewalk Installation Cost
var sw_new_res_len=350;

var sw_res_length= 50;			// Sidewalk Installation Cost - length of a city lot in ft
var sw_res_overhead= 1.25;			// Sidewalk Installation Cost - overhead management costs
var sw_res_addl= 2000;			// Sidewalk Installation Cost - additional project cost
var sw_residential= 55000.00;			// Sidewalk Installation Cost
var sw_commercial=62500.00;      // Sidewalk Removal and Installation Cost
var traffsig=160000.00;		// Traffic Signal Installation 
var schoolflashrs=11000.00;		// school flashing beacons - roadside mounted
var schoolflashoh=18000.00;		// school flashing beacons - overhead mounted
var stopsigns=100.00;		//Stop Signs
var bikelanes=43750.00;		//Bike Lanes
var pavemark=37500.00;  	// Pavement Markings
var speedhumps20ft = 13250.00;		// Speed Humps 20ft Road
var speedhumps28ft = 15000.00;		// Speed Humps 28ft Road
var speedhumps36ft = 17500.00;		// Speed Humps 36ft Road
var speedhumps44ft = 21250.00;		// Speed Humps 44ft Road

var num_calctypes = 12; // This is the number of categories, including the first, blank, category. Change this number to add/remove types

var instype_array = new Array(num_calctypes);

instype_array[0] = new Array("Select a calculation type"); // Select Type Statement

instype_array[1] = new Array("Not Applicable"); // ADA Ramp Installation

instype_array[2] = new Array("Not Applicable"); // Bike Lanes Installation

instype_array[3] = new Array("Not Applicable"); // Bus Pad Installation

instype_array[4] = new Array("-- Select One --",
"Install Only",
"Removal and Install"); // Curb Installation

instype_array[5] = new Array("Not Applicable"); // Pavement Markings Installation

instype_array[6] = new Array("-- Select One --",
"Roadside Mounted",
"Overhead Mounted"); // School Flashing Beacon Installation

instype_array[7] = new Array("-- Select One --",
"Residential Block",
"Commercial Block"); // Sidewalk Installation Blocks

instype_array[8] = new Array("Not Applicable"); // Sidewalk Installation FT

instype_array[9] = new Array("-- Select One --",
"20ft Wide Road",
"28ft Wide Road",
"36ft Wide Road",
"44ft Wide Road"); // Speed Humps

instype_array[10] = new Array("Not Applicable"); // Stop Sign Installation

instype_array[11] = new Array("Not Applicable"); // Traffic Signal Installation

var varlab1_array = new Array(num_calctypes);

varlab1_array[0] = new Array("");

varlab1_array[1] = new Array("Number of Corners"); // ADA Ramp Installation

varlab1_array[2] = new Array("Number of Miles"); // Bike Lanes

varlab1_array[3] = new Array("Number of Pads"); // Bus Pad Istallation

varlab1_array[4] = new Array("Number of Linear Feet"); // Curb Installation

varlab1_array[5] = new Array("Number of Miles"); // Pavement Markings

varlab1_array[6] = new Array("Number of School Zones"); // School Flashing Beacon Installation

varlab1_array[7] = new Array("Number of Blocks"); // Sidewalk Installation Blocks

varlab1_array[8] = new Array("Number of Feet"); // Sidewalk Installation FT

varlab1_array[9] = new Array("Number of Sets"); // Speed Hump Installation

varlab1_array[10] = new Array("Number of Stop Signs"); // Stop Signs Installation

varlab1_array[11] = new Array("Number of Traffic Signals"); // Traffic Signal Installation

var text_array = new Array(num_calctypes);

text_array[0] = new Array("Here's how you use this cost estimator:\n\n1.First, you select the type of calculation you want to perform in the 'Calculation Type' drop-down.\n\n2.Then, enter the requested variable(s).\n\n3.Then, click the 'Calculate' button, or click Clear to reset back to the orginal page.\n\nIf you ever need to see this help again, just go back to the top option in the 'Calculation Type' box."); // These are general instructions. Change them if you want, or keep them if you don't.

text_array[1] = new Array("ADA Ramp installation includes truncated dome material and installation, concrete, and curb.  Cost per ramp is $6,375.\n\nPlease enter 'Number of Corners' and press the 'Calculate' button.\n\nTruncated Dome:  red colored, detectable warning device on pedestrian curb ramps 24 inches deep and extending the full width of the curb ramp to warn visually impaired pedestrians of the crossing. See http://www.sanantonio.gov/publicworks/streets/pdf/truncatd_dome.pdf");

text_array[2] = new Array("Bike Lane cost is $43,750 per mile for one side of the street and includes pavement markings and signage.\n\nPlease enter 'Number of Miles' and press the 'Calculate' button. ");

text_array[3] = new Array("Bus Pad cost is $31,250 per pad.\n\nPlease enter 'Number of Pads' and press the 'Calculate' button. ");

text_array[4] = new Array("Curb installation - Please select 'Type of Installation', enter 'Number of Linear Feet', and press the 'Calculate' button.", "Curb installation - 'Install Only' valid if there is not an existing curb to be removed. $18.00 per linear foot. Enter the 'Number of Linear Feet', and press the 'Calculate' button.", "Curb installation - 'Remove and Install' price includes cost to remove existing curb. $22.22 per linear foot. Enter the 'Number of Linear Feet', and press the 'Calculate' button.");

text_array[5] = new Array("Pavement Marking cost is $37,500 per mile.\n\nPlease enter 'Number of Miles' and press the 'Calculate' button. ");

text_array[6] = new Array("School Flashing Signal installation - Flashing signal cost is $11,000 per school zone for roadside installation and $18,000 per school zone for overhead installation.\n\nPlease enter 'Type of Installation', 'Number of School Zones' and press the 'Calculate' button.\n\nNote: Each school zone includes cost and installation of two sets of flashing signals. One set for each side of the road.", "School Flashing Signal installation - 'Roadside Mounted' is a sign type installation. $11,000.00 per school zone.\n\nEnter the 'Number of School Zones', and press the 'Calculate' button.\n\nNote: Each school zone includes cost and installation of two sets of flashing signals. One set for each side of the road.", "School Flashing Signal installation - 'Overhead Mounted' is a mast arm type installation. $18,000.00 per school zone.\n\nEnter the 'Number of School Zones', and press the 'Calculate' button.\n\nNote: Each school zone includes cost and installation of two sets of flashing signals. One set for each side of the road.");

text_array[7] = new Array("Sidewalk installation - Please select 'Type of Installation', enter 'Number of Blocks', and press the 'Calculate' button.", "Sidewalk installation - 'Residential Block' assumes installation of 4 foot wide sidewalk. $55,000 per block, 350 ft block length. Enter the 'Number of Blocks', and press the 'Calculate' button.", "Sidewalk installation - 'Commercial Block' assumes installation of 4-ft wide sidewalks. $62,500 per block, 350 ft block length. Enter the 'Number of Blocks', and press the 'Calculate' button.");

text_array[8] = new Array("Sidewalk installation - Calculated by foot for residential city lots only. Calculation assumes removal of existing sidewalk and installation of 4 foot wide sidewalk. \n\nPlease enter 'Number of Feet', and press the 'Calculate' button.");

text_array[9] = new Array("Speed Hump installation - Speed Humps installation cost is determined by the width of the road. There must be 1000 ft of pavement with no stop signs or traffic signals.  1 set of speed humps consists of the following:\n\n20ft wide road = 4 cushions\n28ft wide road= 6 cushions\n36ft wide road = 8 cushions\n44ft wide road = 10 cushions\n\nPlease enter 'Type of Installation', 'Number of Sets', and press the 'Calculate' button.", "Speed Hump installation - 1 set of speed humps on a 20ft road (4 cushions)=$13,250.00. There must be 1000 ft of pavement with no stop signs or traffic signals.\n\nEnter the 'Number of Sets' and press the 'Calculate' button.", "Speed Hump installation - 1 set of speed humps on a 28ft road (6 cushions)=$15,000.00. There must be 1000 ft of pavement with no stop signs or traffic signals.\n\nEnter the 'Number of Sets' and press the 'Calculate' button.", "Speed Hump installation - 1 set of speed humps on a 36ft road (8 cushions)=$17,500.00. There must be 1000 ft of pavement with no stop signs or traffic signals.\n\nEnter the 'Number of Sets' and press the 'Calculate' button.", "Speed Hump installation - 1 set of speed humps on a 44ft road (8 cushions)=$21,250.00. There must be 1000 ft of pavement with no stop signs or traffic signals.\n\nEnter the 'Number of Sets' and press the 'Calculate' button.");

text_array[10] = new Array("Stop Sign installation - Stop sign installation cost is $100.00 per sign.\n\nPlease enter 'Number of Stop Signs' and press the 'Calculate' button.");

text_array[11] = new Array("Traffic Signal installation - Traffic signal installation cost is $160,000 per signal.\n\nPlease enter 'Number of Traffic Signals' and press the 'Calculate' button.\n\nEstimated cost for a typical traffic signal installation to include survey, design, environmental study, traffic signal timing plan development and implementation, equipment and construction.   Actual cost may change based existing conditions.");


function switch_select()

{

  for (loop = window.document.pwcalcform.apptype.options.length-1; loop > 0; loop--)
  {
    window.document.pwcalcform.apptype.options[loop] = null;
  }

  for (loop = 0; loop < instype_array[window.document.pwcalcform.calctype.selectedIndex].length; loop++)
  {
    window.document.pwcalcform.apptype.options[loop] = new Option(instype_array[window.document.pwcalcform.calctype.selectedIndex][loop]);
  }

  window.document.pwcalcform.apptype.selectedIndex = 0;
}
  
function switch_text()

{
  window.document.pwcalcform.textarea_1.value = text_array[window.document.pwcalcform.calctype.selectedIndex][window.document.pwcalcform.apptype.selectedIndex];
  window.document.pwcalcform.CostEstVar1Lbl.value = varlab1_array[window.document.pwcalcform.calctype.selectedIndex];
  window.document.pwcalcform.CostEstVar1.value = "";
  window.document.pwcalcform.totalcost.value = "";
}

function box()

{
  if (window.document.pwcalcform.apptype.selectedIndex == 0)
  {
    alert("Select Calculation Type");
  } else {
    if (open_in_newwindow==1)
    window.open(url_array[window.document.pwcalcform.calctype.selectedIndex][window.document.pwcalcform.apptype.selectedIndex],"_blank");
    else
    window.location=url_array[window.document.pwcalcform.calctype.selectedIndex][window.document.pwcalcform.apptype.selectedIndex]
  }
}

function set_orig()

{
  window.document.pwcalcform.calctype.selectedIndex = 0;
  switch_select();
  switch_text();
  window.document.pwcalcform.apptype.selectedIndex = 0;
  window.document.pwcalcform.CostEstVar1Lbl.value = "";
  window.document.pwcalcform.CostEstVar1.value = "";
  window.document.pwcalcform.totalcost.value = "";
  
}

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 calculate_value(pwcalcform) {
    // Call to the calculation functions.  Add functions as calc types are added
	if (window.document.pwcalcform.calctype.selectedIndex == 0)
	{
		alert ("Please select 'Calculation Type'");
	}
	else if (window.document.pwcalcform.calctype.selectedIndex == 1)
	{
		calculate_ramp(pwcalcform)
	}
	else if (window.document.pwcalcform.calctype.selectedIndex == 2)
	{
		calculate_bikelanes(pwcalcform)
	}
	else if (window.document.pwcalcform.calctype.selectedIndex == 3)
	{
		calculate_buspad(pwcalcform)
	}
	else if (window.document.pwcalcform.calctype.selectedIndex == 4)
	{
		calculate_curb(pwcalcform)
	}
	else if (window.document.pwcalcform.calctype.selectedIndex == 5)
	{
		calculate_pavemark(pwcalcform)
	}
	else if (window.document.pwcalcform.calctype.selectedIndex == 6)
	{
		calculate_schoolbeacons(pwcalcform)
	}
	else if (window.document.pwcalcform.calctype.selectedIndex == 7)
	{
		calculate_sw(pwcalcform)
	}
	else if (window.document.pwcalcform.calctype.selectedIndex == 8)
	{
		calculate_sw_ft(pwcalcform)
	}
	else if (window.document.pwcalcform.calctype.selectedIndex == 9)
	{
		calculate_speedhumps(pwcalcform)
	}
	else if (window.document.pwcalcform.calctype.selectedIndex == 10)
	{
		calculate_stopsign(pwcalcform)
	}

	else if (window.document.pwcalcform.calctype.selectedIndex == 11)
	{
		calculate_traffsig(pwcalcform)
	}

	else
	{
		alert ("Please select 'Calculation Type'");
	}

	
}


function calculate_ramp(pwcalcform) {
var numcorners = document.pwcalcform.CostEstVar1.value;
var total = 0;

  if (numcorners == "")
  {
   	alert ("Please enter 'Number of Corners'");
	return;
  }
  else
  {
  	total = numcorners * ramp_cost
  	
  }
  
  if (total < 0)
  		total = 0
  		
  document.pwcalcform.totalcost.value = formatCurrency(total)

}

function calculate_curb(pwcalcform) {
var numcurbfeet = document.pwcalcform.CostEstVar1.value;
var total = 0;


  if (numcurbfeet == "")
  {

  	alert ("Please enter 'Number of Linear Feet'");
	return;
  }
  else
  {

  	if (window.document.pwcalcform.apptype.selectedIndex == 0)
	{
		alert ("Please select 'Type of Installation'");
		return;
	}
	else if (window.document.pwcalcform.apptype.selectedIndex == 1)
	{
		total = numcurbfeet * curb_inst //Install only
	}
	else
	{
		total = numcurbfeet * curb_rem_inst //Remove & Install
	}
  }
  
  if (total < 0)
  		total = 0

  document.pwcalcform.totalcost.value = formatCurrency(total)

}

function calculate_sw_ft(pwcalcform) {
var swfeet = document.pwcalcform.CostEstVar1.value;
var total = 0;

  if (swfeet == "")
  {
  	alert ("Please enter 'Number of Feet'");
	return;
  }
  else
  {
	
	total = ((sw_res_ft/sw_new_res_len) * swfeet) * sw_res_overhead;//Install only
	//total = (swfeet * (sw_res_ft/sw_res_length) * sw_res_overhead) +  sw_res_addl; Install only

  }
  if (total <= 0)
  {
  		total = 0
  }
  else if (total <=10000)
  {
  		total = total + 2000;
  }

  document.pwcalcform.totalcost.value = formatCurrency(total)

}


function calculate_sw(pwcalcform) {
var swblock = document.pwcalcform.CostEstVar1.value;
var total = 0;
  if (swblock == "")
  {
  	alert ("Please enter 'Number of Blocks'");
	return;
  }
  else
  {
  	if (window.document.pwcalcform.apptype.selectedIndex == 0)
	{
		alert ("Please select 'Type of Installation'");
		return;
	}
	else if (window.document.pwcalcform.apptype.selectedIndex == 1)
	{
		total = swblock * sw_residential //Install only
	}
	else
	{
		total = swblock * sw_commercial //Remove & Install
	}

  }
  
  if (total < 0)
  		total = 0

  document.pwcalcform.totalcost.value = formatCurrency(total)

}

function calculate_schoolbeacons(pwcalcform) {
var numsigs = document.pwcalcform.CostEstVar1.value;
var total = 0;
  if (numsigs == "")
  {
  	alert ("Please enter 'Number of School Zones'");
	return;
  }
  else
  {
  	if (window.document.pwcalcform.apptype.selectedIndex == 0)
	{
		alert ("Please select 'Type of Installation'");
		return;
	}
	else if (window.document.pwcalcform.apptype.selectedIndex == 1)
	{
		total = numsigs * schoolflashrs //roadside
	}
	else
	{
		total = numsigs * schoolflashoh  //overhead
	}

  }
  
  if (total < 0)
  		total = 0

  document.pwcalcform.totalcost.value = formatCurrency(total)

}


function calculate_buspad(pwcalcform) {
var numpads = document.pwcalcform.CostEstVar1.value;
var total = 0;
  if (numpads == "")
  {
  	alert ("Please enter 'Number of Pads'");
	return;
  }
  else
  {
  	total = numpads * buspad
  }
  
  if (total < 0)
  		total = 0

  document.pwcalcform.totalcost.value = formatCurrency(total)

}

function calculate_traffsig(pwcalcform) {
var numsig = document.pwcalcform.CostEstVar1.value;
var total = 0;
  if (numsig == "")
  {
  	alert ("Please enter 'Number of Traffic Signals to Install'");
	return;
  }
  else
  {
  	total = numsig * traffsig
  }
  
  if (total < 0)
  		total = 0

  document.pwcalcform.totalcost.value = formatCurrency(total)

}

function calculate_stopsign(pwcalcform) {
var numsigns = document.pwcalcform.CostEstVar1.value;
var total = 0;
  if (numsigns == "")
  {
  	alert ("Please enter 'Number of Traffic Signals to Install'");
	return;
  }
  else
  {
  	total = numsigns * stopsigns
  }
  
  if (total < 0)
  		total = 0

  document.pwcalcform.totalcost.value = formatCurrency(total)

}

function calculate_bikelanes(pwcalcform) {
var nummiles = document.pwcalcform.CostEstVar1.value;
var total = 0;
  if (nummiles == "")
  {
  	alert ("Please enter 'Number of Miles'");
	return;
  }
  else
  {
  	total = nummiles * bikelanes
  }
  
  if (total < 0)
  		total = 0

  document.pwcalcform.totalcost.value = formatCurrency(total)

}

function calculate_pavemark(pwcalcform) {
var nummiles = document.pwcalcform.CostEstVar1.value;
var total = 0;
  if (nummiles == "")
  {
  	alert ("Please enter 'Number of Miles'");
	return;
  }
  else
  {
  	total = nummiles * pavemark
  }
  
  if (total < 0)
  		total = 0

  document.pwcalcform.totalcost.value = formatCurrency(total)

}

function calculate_speedhumps(pwcalcform) {
var numsets = document.pwcalcform.CostEstVar1.value;
var total = 0;
  if (numsets == "")
  {
  	alert ("Please enter 'Number of Sets'");
	return;
  }
  else
  {
  	if (window.document.pwcalcform.apptype.selectedIndex == 0)
	{
		alert ("Please select 'Type of Installation'");
		return;
	}
	else if (window.document.pwcalcform.apptype.selectedIndex == 1)
	{
		total = numsets * speedhumps20ft 
	}
	else if (window.document.pwcalcform.apptype.selectedIndex == 2)
	{
		total = numsets * speedhumps28ft 
	}
    else if (window.document.pwcalcform.apptype.selectedIndex == 3)
	{
		total = numsets * speedhumps36ft 
	}
	else
	{
		total = numsets * speedhumps44ft  
	}

  }
  
  if (total < 0)
  		total = 0

  document.pwcalcform.totalcost.value = formatCurrency(total)

}


window.onload=set_orig

