// David Carter-Tod
// dcartertod is my userid at vccs.edu
// August 2003
// revised June 2004 for new data for after July 2004
// revised January 2006 for new data
// revised October 2006 for new data and simplified code
// revised October 2007 for new data 
// revised October 2008 for new data

// base rates - page 17

var cost39	=	new Array(7,11,18,3);  //39
var cost44	=	new Array(8,12,21,3);  //44
var cost49	=	new Array(9,13,24,3);  //49
var cost54	=	new Array(10,15,26,3); //54
var cost59	=	new Array(11,16,29,3); //59
var cost64	=	new Array(12,18,31,3); //64


// this is better I think

var locs = new Array();

function createLocation(locname,lodging,cost,note) {
	// note: switched parameter order to facilitate checking against documentation
	if (note === undefined) {
		note = "";
	}
	var thisLocation = new Array(locname, cost, lodging, note);
	locs.push (thisLocation);
}

////////////////////
// in-state data //
//////////////////

var note = '';

createLocation ("Standard In-State",					70,	cost39);

createLocation ("Abingdon (Washington) (10/1 - 3/31)",				79,	cost49);
createLocation ("Abingdon (Washington) (4/1 - 5/31)",				72,	cost49);
createLocation ("Abingdon (Washington) (6/1 - 9/30)",				79,	cost49);
createLocation ("Blacksburg (Montgomery)",				80,	cost54);
createLocation ("Charlottesville (Albemarle & Green County)",				100,	cost44);
createLocation ("Chesapeake / Suffolk (10/1 - 3/31)",				89,	cost44);
createLocation ("Chesapeake / Suffolk (4/1 -5/31)",				97,	cost44);
createLocation ("Chesapeake / Suffolk (6/1 -8/31)",				107,	cost44);
createLocation ("Chesapeake / Suffolk (9/1 -9/30)",				89,	cost44);
createLocation ("Chesterfield / Henrico County",				93,	cost49);
createLocation ("Fredericksburg (Spotsylvania)",				74,	cost54);
createLocation ("Hampton City / Newport News",				81,	cost44);
createLocation ("James City / York Co / Williamsburg (10/1 - 3/31)",				75,	cost54);
createLocation ("James City / York Co / Williamsburg (4/1 - 8/31)",				97,	cost54);
createLocation ("James City / York Co / Williamsburg (9/1 - 9/30)",				75,	cost54);
createLocation ("Loudoun (Loudoun County)",				140,	cost59);
createLocation ("Lynchburg (Campbell County)",				78,	cost44);
createLocation ("Manassas (City Limits)",				101,	cost39);
createLocation ("Norfolk / Portsmouth",				96,	cost59);
createLocation ("Richmond (City Limits) (10/1 - 10/31)",				129,	cost54);
createLocation ("Richmond (City Limits) (11/1 - 8/31)",				123,	cost54);
createLocation ("Richmond (City Limits) (9/1 - 9/30)",				129,	cost54);
createLocation ("Roanoke (City Limits)",				96,	cost44);
createLocation ("Stafford / Prince Williams County",				95,	cost44);
createLocation ("Virginia Beach (10/1-5/31)",				88,	cost54);
createLocation ("Virginia Beach (6/1-8/31)",				151,	cost54);
createLocation ("Virginia Beach (9/1-9/30)",				88,	cost54);
createLocation ("Wallops Island (Accomack County) (10/1-6/30)",				87,	cost49);
createLocation ("Wallops Island (Accomack County) (7/1-8/31)",				121,	cost49);
createLocation ("Wallops Island (Accomack County) (9/1-9/30)",				87,	cost49);
createLocation ("Warrenton (Fauquier)",				99,	cost44);

createLocation ("For Alexandria, Falls Church, Fairfax and Arlington use Washington, D.C. options below",	70,	cost39);
createLocation ("----",											70,	cost39);


////////////////////////
// out-of-state data //
//////////////////////

createLocation ("Standard Out-of-state",										88,	cost44);

createLocation ("Austin, TX (Travis) (10/1 - 3/31)",				114,	cost54);
createLocation ("Austin, TX (Travis) (4/1 - 8/31)",				107,	cost54);
createLocation ("Austin, TX (Travis) (9/1 - 9/30)",				114,	cost54);
createLocation ("Atlanta, GA (Fulton, Cobb, DeKalb Counties)",				141,	cost49);
createLocation ("Baltimore, MD (10/1 - 10/31)",				172,	cost59);
createLocation ("Baltimore, MD (11/1 - 8/31)",				157,	cost59);
createLocation ("Baltimore, MD (9/1 - 9/30)",				172,	cost59);
createLocation ("Baltimore County, MD",				106,	cost54);
createLocation ("Boston/Cambridge, MA (Suffolk, City of Cambridge )(10/1 - 10/31)",				256,	cost64);
createLocation ("Boston/Cambridge, MA (Suffolk, City of Cambridge) (11/1 - 8/31)",				203,	cost64);
createLocation ("Boston/Cambridge, MA (Suffolk, City of Cambridge) (9/1 - 9/30)",				256,	cost64);
createLocation ("Charleston, SC (Charleston, Berkeley,Dorchester Counties)",				141,	cost54);
createLocation ("Charlotte, NC (Mecklenburg County)",				97,	cost49);
createLocation ("Chicago. IL (Cook, Lake Counties)(10/1-11/30)",				218,	cost64);
createLocation ("Chicago, IL (Cook, Lake Counties) (12/1-4/30)",				157,	cost64);
createLocation ("Chicago, IL (Cook, Lake Counties) (5/1-6/30)",				209,	cost64);
createLocation ("Chicago, IL (Cook, Lake Counties) (7/1-8/31)",				177,	cost64);
createLocation ("Chicago, IL (Cook, Lake Counties) (9/1-9/30)",				218,	cost64);
createLocation ("Cincinnati, OH (Hamilton, Clermont Counties)",				112,	cost54);
createLocation ("Cleveland, OH (Cuyahoga County)",				110,	cost54);
createLocation ("Dallas, TX (Dallas County and City Limits) (10/1-12/31)",				115,	cost59);
createLocation ("Dallas, TX (Dallas County and City Limits) (1/1-3/31)",				129,	cost59);
createLocation ("Dallas, TX (Dallas County and City Limits) (4/1-9/30)",				115,	cost59);
createLocation ("Denver / Aurora, CO (Denver, Adams, Arapahoe, and Jefferson)",				149,	cost49);
createLocation ("Detroit, MI (Wayne County)",				107,	cost49);
createLocation ("Floral Park/Garden City/Glen Cove/ Great Neck/ Roslyn, NY (Nassau County)",				162,	cost64);
createLocation ("Houston, TX (L.B. Johnson Space Center and Fort Bend, Harris, Montgomery Counties)",				110,	cost59);
createLocation ("Kansas City, MO (Cass, Clay, Jackson, Platte Counties)",				107,	cost49);
createLocation ("Las Vegas, NV (Clark County) (10/1-12/31)",				105,	cost64);
createLocation ("Las Vegas, NV (Clark County) (1/1 - 5/31)",				126,	cost64);
createLocation ("Las Vegas, NV (Clark County) (6/1 -9/30)",				105,	cost64);
createLocation ("Los Angeles, CA (Los Angeles, Orange, Ventura Counties and Edwards AFB)",				128,	cost64);
note="Manhattan, NY includes Boroughs of Manhattan, Bronx, Brooklyn and Queens and Staten Island and Counties of Kings, New York and Richmond";
createLocation ("Manhattan, NY (see note)(10/1-12/31)",				360,	cost64, note);
createLocation ("Manhattan, NY (see note)(1/1-6/30)",				285,	cost64, note);
createLocation ("Manhattan, NY (see note)(7/1-8/31)",				259,	cost64, note);
createLocation ("Manhattan, NY (see note)(9/1-9/30)",				360,	cost64, note);
createLocation ("Miami, FL (Miami-Dade County) (10/1-2/28)",				149,	cost59);
createLocation ("Miami, FL (Miami-Dade County) (3/1-9/30)",				121,	cost59);
createLocation ("Minneapolis / St. Paul, MN (Hennepin, Ramsey Counties)",				130,	cost64);
createLocation ("Nashville, TN (Davidson)",				117,	cost54);
createLocation ("Newark, NJ (Essex, Bergen, Hudson, Passaic Counties)",				133,	cost49);
createLocation ("New Orleans, LA (Jefferson, Orleans, Plaquemine Parishes, St. Bernard) (10/1-6/30)",				140,	cost59);
createLocation ("New Orleans, LA (Jefferson, Orleans, Plaquemine Parishes, St. Bernard) (7/1-9/30)",				101,	cost59);
createLocation ("Orlando, FL (Orange County) (10/1-12/31)",				109,	cost49);
createLocation ("Orlando, FL (Orange County) (1/1-3/31)",				133,	cost49);
createLocation ("Orlando, FL (Orange County) (4/1-9/30)",				109,	cost49);
createLocation ("Philadelphia, PA (Philadelphia County) (10/1 - 11/30)",				166,	cost64);
createLocation ("Philadelphia, PA (Philadelphia County) (12/1 - 8/31)",				155,	cost64);
createLocation ("Philadelphia, PA (Philadelphia County) (9/1 - 9/30)",				166,	cost64);
createLocation ("Palm Springs, CA (Riverside) (10/1 - 12/31)",				114,	cost59);
createLocation ("Palm Springs, CA (Riverside) (1/1 -4/30)",				139,	cost59);
createLocation ("Palm Springs, CA (Riverside) (5/1 - 8/31)",				97,	cost59);
createLocation ("Palm Springs, CA (Riverside) (9/1 - 9/30)",				114,	cost59);
createLocation ("Phoenix/Scottsdale, AZ (Maricopa County) (10/1-12/31)",				122,	cost59);
createLocation ("Phoenix/Scottsdale, AZ (Maricopa County) (1/1-4/30)",				160,	cost59);
createLocation ("Phoenix/Scottsdale, AZ (Maricopa County) (5/1-8/31)",				96,	cost59);
createLocation ("Phoenix/Scottsdale, AZ (Maricopa County) (9/1-9/30)",				122,	cost59);
createLocation ("Pittsburgh, PA (Allegheny County)",				114,	cost54);
createLocation ("San Antonio, TX (Bexar County)",				117,	cost54);
createLocation ("San Diego, CA (San Diego County) (10/1-12/31)",				137,	cost64);
createLocation ("San Diego, CA (San Diego County) (1/1-8/31)",				147,	cost64);
createLocation ("San Diego, CA (San Diego County) (9/1-9/30)",				137,	cost64);
createLocation ("San Francisco, CA (San Francisco County) (10/1-10/31)",				185,	cost64);
createLocation ("San Francisco, CA (San Francisco County) (11/1-8/31)",				164,	cost64);
createLocation ("San Francisco, CA (San Francisco County) (9/1-9/30)",				185,	cost64);
createLocation ("Savannah, GA (Chatham County)",				108,	cost49);
createLocation ("Seattle, WA (King County)",				158,	cost64);
createLocation ("St. Louis, MO (St. Louis, St. Charles Counties, Crawford, Franklin, Jefferson, Lincoln, Warren and Washington)",				111,	cost59);
createLocation ("Tampa/St. Petersburg, FL (Pinellas and Hillsborough) (10/1 - 12/31)",				104,	cost54);
createLocation ("Tampa/St. Petersburg, FL (Pinellas and Hillsborough) (1/1 - 3/31)",				127,	cost54);
createLocation ("Tampa/St. Petersburg, FL (Pinellas and Hillsborough) (4/1 - 9/30)",				104,	cost54);
note="Washington, DC, includes: Virginia Cities of Alexandria, Falls Church, Fairfax; Virginia counties of Arlington, Fairfax; and, Maryland counties of Montgomery and Prince George's.";
createLocation ("Washington, DC (see note) (10/1-10/31)",				233,	cost64, note);
createLocation ("Washington, DC (see note) (11/1-6/30)",				209,	cost64, note);
createLocation ("Washington, DC (see note) (7/1-8/31)",				165,	cost64, note);
createLocation ("Washington, DC (see note) (9/1-9/30)",				233,	cost64, note);
createLocation ("White Plains/Tarrytown/ New Rochelle/Yonkers, NY (Westchester County)",				164,	cost59);




function writeText(id,txt){
	// moderately browser compatible way to fill elements
	if (document.getElementById){
		x = document.getElementById(id);
		x.innerHTML = '';
		x.innerHTML = txt;
	}
	else if (document.all){
		x = document.all[id];
		x.innerHTML = txt;
	}
}

function getUniqueEl(id){
	// moderately browser compatible way to fill elements
	if (document.getElementById){
		x = document.getElementById(id);
	}
	else if (document.all){
		x = document.all[id];
	}
	return (x);
}

if (!document.getElementById && !document.all && document.layers){
		alert ("This page does not work with Netscape 4 versions");
}

function writeLocations(){
	// iterate the locs array and fill out the options list
	for (var i=0; i<locs.length; i++){
		var thisloc = locs[i][0].toLowerCase();
		thisloc = (thisloc.indexOf("-state") > 1) ? locs[i][0]:"&nbsp;&nbsp;" + locs[i][0];
		document.writeln ("<option value=\"" + locs[i][0] + "\">" + thisloc + "</option>");
	}
}

function fillDays(sIndex){
	// write out the form elements for the days
	sIndex = (sIndex==0) ? 1:sIndex-1;
	var theform = document.forms["mainform"];
	var numdays = parseInt(theform.days.value);
	var ttr = "";
	var n = 0;
	var isTravel;
	for (var i=0; i<numdays; i++){
		n = i+1;
		ttr += ("<p><span id=\"dayPara\"><strong>Day " + n + "</strong>&nbsp;&nbsp;&nbsp;");
		isTravel = i==0||i==numdays-1?" checked":"";
		ttr += ("Travel Day?<input type=\"checkbox\" name=\"travelDay" + n + "\" onClick=\"update();\"" + isTravel + "></span><br />");
		ttr += "<table id=\"dayTable\"><tr><th>Meal</th><th>Provided?</th></tr>";
		ttr += ("<tr><td align=\"right\"><label for=\"Breakfast" + n + "\">Breakfast ($" + locs[sIndex][1][0] + "):</label></td><td align=\"center\"><input type=\"checkbox\" name=\"Breakfast" + n + "\" id=\"Breakfast" + n + "\" onClick=\"update();\"></td></tr>\r");
		ttr += ("<tr><td align=\"right\"><label for=\"Lunch" + n + "\">Lunch ($" + locs[sIndex][1][1] + "):</label></td><td align=\"center\"><input type=\"checkbox\" name=\"Lunch" + n + "\" id=\"Lunch" + n + "\" onClick=\"update();\"></td></tr>\r");
		ttr += ("<tr><td align=\"right\"><label for=\"Dinner" + n + "\">Dinner ($" + locs[sIndex][1][2] + "):</label></td><td align=\"center\"><input type=\"checkbox\" name=\"Dinner" + n + "\" id=\"Dinner" + n + "\" onClick=\"update();\"></td></tr>\r");
		ttr += ("<tr><td align=\"right\">Incidentals:</td><td align=\"center\">$" + locs[sIndex][1][3] + "</td></tr>\r");
		ttr += ("<tr><th align=\"right\">Day Total:</td><td align=\"center\"><span id=\"total" + n + "\"></span></td></tr>");
		ttr += "</table>";
	}
	writeText ("dayText",ttr);
	update();
	dt = document.getElementById("ttotal");
	dt.style.display = "block";
	var destination = locs[sIndex][0];
	var brackets = destination.indexOf("(");
	destination = brackets!=-1 ? destination.substr(0,brackets-1):destination;
	destination = destination.lastIndexOf("/")!=-1 ? destination.substr(destination.lastIndexOf("/")+1):destination;
	destination = destination.indexOf(",")!=-1 ? destination:destination + ", VA";
	writeText ("aboutLoc","<strong>The lodging rate for " + locs[sIndex][0] + " is $" + locs[sIndex][2] + "</strong> (excluding taxes and surcharges). 150% of $" + locs[sIndex][2] + " is $" + locs[sIndex][2]*1.5 + ". " + locs[sIndex][3] + " <A HREF=\"http://maps.google.com/maps?f=d&q=" + escape(destination) + "\">Driving Directions</A>.");
}

function update(){
	// update the calculations
	var theform = document.forms["mainform"];
	var numdays = parseInt(theform.days.value);
	var n = 0;
	var calcStr = ""
	var sIndex = theform.where.selectedIndex-1;
	var dt;
	var totalStr = "";
	var total = 0;
	for (var i=0; i<numdays; i++){
		n = i+1;
		calcStr = eval(locs[sIndex][1][0]+locs[sIndex][1][1]+locs[sIndex][1][2]);
		calcStr += theform["Breakfast" + n].checked?"-"+locs[sIndex][1][0]:"";
		calcStr += theform["Lunch" + n].checked?"-"+locs[sIndex][1][1]:"";
		calcStr += theform["Dinner" + n].checked?"-"+locs[sIndex][1][2]:"";
		calcStr = theform["travelDay" + n].checked?"("+calcStr+") * 0.75":calcStr;
		calcStr = "(" + calcStr + ") + " + locs[sIndex][1][3];
		calcStrtw = eval(calcStr);
		calcStrtw = (calcStrtw.toFixed) ? calcStrtw.toFixed(2):calcStrtw;
		writeText ("total"+n,calcStr.replace(/\*/gi, 'x') + " = $" + calcStrtw);
		totalStr += calcStrtw + " + ";
	}
	totalStr = totalStr.substr(0,totalStr.length-2);
	total = eval(totalStr);
	total = (total.toFixed) ? total.toFixed(2):total;
	writeText ("total", totalStr + " = $" + total);
}

