// 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
// revised October 2009 for new data

// base rates - page 19

var cost41	=	new Array(7,11,18,5); 
var cost46	=	new Array(7,11,23,5); 
var cost51	=	new Array(8,12,26,5); 
var cost56	=	new Array(9,13,29,5); 
var cost61	=	new Array(10,15,31,5); 
var cost66	=	new Array(11,16,34,5); 
var cost71	=	new Array(12,18,36,5); 


// 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,	cost41);

createLocation ("Abingdon (Washington) (10/1 - 3/31)",	82,	cost46);
createLocation ("Abingdon (Washington) (4/1 - 5/31)",	82,	cost46);
createLocation ("Abingdon (Washington) (6/1 - 9/30)",	82,	cost46);
createLocation ("Blacksburg (Montgomery)",	98,	cost46);
createLocation ("Charlottesville (Albemarle & Greene County)",	112,	cost56);
createLocation ("Chesapeake / Suffolk (10/1 - 5/31)",	87,	cost56);
createLocation ("Chesapeake / Suffolk (6/1 -8/31)",	103,	cost56);
createLocation ("Chesapeake / Suffolk (9/1 -9/30)",	87,	cost56);
createLocation ("Chesterfield / Henrico (Chesterfield and Henrico Counties)",	92,	cost51);
createLocation ("Fredericksburg (City of Fredericksburg, Spotsylvania)",	78,	cost56);
createLocation ("Hampton City / Newport News",	80,	cost56);
createLocation ("James City / York Co / Williamsburg (10/1 - 3/31)",	72,	cost51);
createLocation ("James City / York Co / Williamsburg (4/1 - 8/31)",	94,	cost51);
createLocation ("James City / York Co / Williamsburg (9/1 - 9/30)",	72,	cost51);
createLocation ("Loudoun (Loudoun County)",	135,	cost61);
createLocation ("Lynchburg (Campbell County)",	83,	cost51);
createLocation ("Manassas (City Limits)",	93,	cost46);
createLocation ("Norfolk / Portsmouth",	95,	cost61);
createLocation ("Richmond (City Limits)",	125,	cost66);
createLocation ("Roanoke (City Limits)",	103,	cost51);
createLocation ("Stafford / Prince William (Stafford and Prince Williams Counties)",	95,	cost46);
createLocation ("Virginia Beach (Virginia Beach) (10/1-5/31)",	89,	cost56);
createLocation ("Virginia Beach (Virginia Beach) (6/1-8/31)",	148,	cost56);
createLocation ("Virginia Beach (Virginia Beach) (9/1-9/30)",	89,	cost56);
createLocation ("Wallops Island (Accomack County) (10/1-6/30)",	87,	cost56);
createLocation ("Wallops Island (Accomack County) (7/1-8/31)",	128,	cost56);
createLocation ("Wallops Island (Accomack County) (9/1-9/30)",	87,	cost56);
createLocation ("Warrenton (Fauquier)",	101,	cost46);


createLocation ("For Alexandria, Falls Church, Fairfax and Arlington use Washington, D.C. options below",	70,	cost41);
createLocation ("----",											70,	cost41);


////////////////////////
// out-of-state data //
//////////////////////

createLocation ("Standard Out-of-state",										88,	cost46);

createLocation ("Austin, TX (Travis) (10/1 - 10/31)",	121,	cost71);
createLocation ("Austin, TX (Travis) (11/1 - 8/31)",	115,	cost71);
createLocation ("Austin, TX (Travis) (9/1 - 9/30)",	121,	cost71);
createLocation ("Atlanta, GA (Fulton, Cobb, DeKalb counties)",	140,	cost56);
createLocation ("Baltimore, MD (10/1 - 11/30)",	161,	cost71);
createLocation ("Baltimore, MD (12/1 - 2/28)",	135,	cost71);
createLocation ("Baltimore, MD (3/1 - 9/30)",	161,	cost71);
createLocation ("Baltimore County, MD",	103,	cost61);
createLocation ("Boston/Cambridge, MA (Suffolk, City of Cambridge )(10/1 - 10/31)",	240,	cost71);
createLocation ("Boston/Cambridge, MA (Suffolk, City of Cambridge) (11/1 - 3/31)",	168,	cost71);
createLocation ("Boston/Cambridge, MA (Suffolk, City of Cambridge) (4/1 - 6/30)",	231,	cost71);
createLocation ("Boston/Cambridge, MA (Suffolk, City of Cambridge) (7/1 -8/31)",	205,	cost71);
createLocation ("Boston/Cambridge, MA (Suffolk, City of Cambridge) (9/1 -96/30)",	240,	cost71);
createLocation ("Charleston, SC (Charleston, Berkeley, Dorchester Counties)",	142,	cost56);
createLocation ("Charlotte, NC (Mecklenburg County)",	100,	cost51);
createLocation ("Chicago. IL (Cook, Lake Counties) (9/1-11/30)",	205,	cost71);
createLocation ("Chicago, IL (Cook, Lake Counties) (12/1-4/30)",	158,	cost71);
createLocation ("Chicago, IL (Cook, Lake Counties) (5/1-6/30)",	211,	cost71);
createLocation ("Chicago, IL (Cook, Lake Counties) (7/1-8/31)",	176,	cost71);
createLocation ("Cincinnati, OH (Hamilton, Clermont Counties)",	115,	cost56);
createLocation ("Cleveland, OH (Cuyahoga County)",	109,	cost56);
createLocation ("Dallas, TX (Dallas County and City Limits) (10/1-12/31)",	117,	cost71);
createLocation ("Dallas, TX (Dallas County and City Limits) (1/1-3/31)",	122,	cost71);
createLocation ("Dallas, TX (Dallas County and City Limits) (4/1-9/30)",	117,	cost71);
createLocation ("Denver / Aurora, CO (Denver, Adams, Arapahoe, and Jefferson)",	158,	cost66);
createLocation ("Detroit, MI (Wayne County)",	104,	cost56);
createLocation ("Floral Park/Garden City/Glen Cove/ Great Neck/ Roslyn, NY (Nassau County)",	161,	cost66);
createLocation ("Houston, TX (L.B. Johnson Space Center and Fort Bend, Harris, Montgomery Counties)",	118,	cost71);
createLocation ("Kansas City, MO (Cass, Clay, Jackson, Platte Counties)",	107,	cost56);
createLocation ("Las Vegas, NV (Clark County) (6/1-12/31)",	109,	cost71);
createLocation ("Las Vegas, NV (Clark County) (1/1 - 5/31)",	118,	cost71);
createLocation ("Los Angeles, CA (Los Angeles, Orange, Ventura Counties and Edwards AFB)",	135,	cost71);

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)",	340,	cost71,	note);
createLocation ("Manhattan, NY (see note) (1/1-3/31)",	209,	cost71,	note);
createLocation ("Manhattan, NY (see note) (4/1-6/30)",	318,	cost71,	note);
createLocation ("Manhattan, NY (see note) (7/1-8/31)",	279,	cost71,	note);
createLocation ("Manhattan, NY (see note) (9/1-9/30)",	340,	cost71,	note);
createLocation ("Miami, FL (Miami-Dade County) (10/1-12/31)",	128,	cost66);
createLocation ("Miami, FL (Miami-Dade County) (1/1-3/31)",	152,	cost66);
createLocation ("Miami, FL (Miami-Dade County) (4/1-9/30)",	117,	cost66);
createLocation ("Minneapolis / St. Paul, MN (Hennepin, Ramsey Counties)",	137,	cost71);
createLocation ("Nashville, TN (Davidson)",	119,	cost66);
createLocation ("Newark, NJ (Essex, Bergen, Hudson, Passaic Counties)",	130,	cost61);
createLocation ("New Orleans, LA (Jefferson, Orleans, Plaquemine Parishes, St. Bernard) (10/1-6/30)",	133,	cost71);
createLocation ("New Orleans, LA (Jefferson, Orleans, Plaquemine Parishes, St. Bernard) (7/1-9/30)",	104,	cost71);
createLocation ("Orlando, FL (Orange County) (10/1-12/31)",	108,	cost56);
createLocation ("Orlando, FL (Orange County) (1/1-3/31)",	117,	cost56);
createLocation ("Orlando, FL (Orange County) (4/1-9/30)",	108,	cost56);
createLocation ("Philadelphia, PA (Philadelphia County) (10/1 - 11/30)",	170,	cost66);
createLocation ("Philadelphia, PA (Philadelphia County) (12/1 - 8/31)",	153,	cost66);
createLocation ("Philadelphia, PA (Philadelphia County) (9/1 - 9/30)",	170,	cost66);
createLocation ("Palm Springs, CA (Riverside) (9/1 - 12/31)",	111,	cost71);
createLocation ("Palm Springs, CA (Riverside) (1/1 -5/31)",	129,	cost71);
createLocation ("Palm Springs, CA (Riverside) (6/1 - 8/31)",	90,	cost71);
createLocation ("Phoenix/Scottsdale, AZ (Maricopa County) (10/1-12/31)",	120,	cost71);
createLocation ("Phoenix/Scottsdale, AZ (Maricopa County) (1/1-5/31)",	140,	cost71);
createLocation ("Phoenix/Scottsdale, AZ (Maricopa County) (6/1-8/31)",	89,	cost71);
createLocation ("Phoenix/Scottsdale, AZ (Maricopa County) (9/1-9/30)",	120,	cost71);
createLocation ("Pittsburgh, PA (Allegheny County)",	119,	cost71);
createLocation ("San Antonio, TX (Bexar County)",	117,	cost66);
createLocation ("San Diego, CA (San Diego County)",	147,	cost71);
createLocation ("San Francisco, CA (San Francisco County) (10/1-10/31)",	192,	cost71);
createLocation ("San Francisco, CA (San Francisco County) (11/1-8/31)",	166,	cost71);
createLocation ("San Francisco, CA (San Francisco County) (9/1-9/30)",	192,	cost71);
createLocation ("Savannah, GA (Chatham County)",	106,	cost56);
createLocation ("Seattle, WA (King County)",	159,	cost71);

note="St. Louis, MO include St. Louis City and St. Louis, St. Charles Counties, Crawford, Franklin, Jefferson, Lincoln, Warren and Washington. ";

createLocation ("St. Louis, MO (see note)",	110,	cost66,	note);
createLocation ("Tampa/St. Petersburg, FL (Pinellas and Hillsborough) (10/1 - 12/31)",	101,	cost51);
createLocation ("Tampa/St. Petersburg, FL (Pinellas and Hillsborough) (1/1 - 3/31)",	120,	cost51);
createLocation ("Tampa/St. Petersburg, FL (Pinellas and Hillsborough) (4/1 - 9/30)",	101,	cost51);

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) (9/1-10/31)",	229,	cost71,	note);
createLocation ("Washington, DC (see note) (11/1-2/28)",	207,	cost71,	note);
createLocation ("Washington, DC (see note) (3/1-6/30)",	226,	cost71,	note);
createLocation ("Washington, DC (see note) (7/1-8/31)",	170,	cost71,	note);
createLocation ("White Plains/Tarrytown/ New Rochelle/Yonkers, NY (Westchester County)",	164,	cost71);




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;
	var tta = ""
	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;
		tta = calcStrtw;
		if (theform["rounding"].checked && theform["travelDay" + n].checked && ( calcStrtw % 1 != 0)
){
			calcStrtw = Math.round(parseInt(calcStrtw) + 0.50);
			tta = calcStrtw + "<br />(rounded up from " + tta + ")";
		}
		writeText ("total"+n,calcStr.replace(/\*/gi, 'x') + " = $" + tta);
		totalStr += calcStrtw + " + ";
	}
	totalStr = totalStr.substr(0,totalStr.length-2);
	total = eval(totalStr);
	total = (total.toFixed) ? total.toFixed(2):total;
	writeText ("total", totalStr + " = $" + total);
}

