// Rollover Function

function swapImage(imageID, imagePath) {
	var imgID;
	imgID = document.getElementById(imageID);
	imgID.src = imagePath;
}

// Calculator Functions

function calculateMileage() {
	var mileage = parseInt(window.document.forms[0].Mileage.value);
	var parking = Number(window.document.forms[0].Parking.value);
	if (isNaN(mileage)) {
		window.document.forms[0].Mileage.value=0;
		mileage = 0
	}
	subTotal1 = (mileage * 21);
	window.document.forms[0].SubTotal1.value = subTotal1;
	
	var subTotal2 = ((subTotal1 * 44.5) / 100);
	window.document.forms[0].SubTotal2.value = formatCurrency(subTotal2);
	
	if (isNaN(parking)) {
		window.document.forms[0].Parking.value=0;
		parking = 0;
	}
	subTotal3 = subTotal2 + parking;
	window.document.forms[0].SubTotal3.value = formatCurrency(subTotal3);
	window.document.forms[0].DriveAloneCost.value = "$" + subTotal3;
	var passengerCount = parseInt(window.document.forms[0].PassengerCount.value);
	if (isNaN(passengerCount)) {
		window.document.forms[0].PassengerCount.value=0;
		passengerCount = 0;
	}
	subTotal7 = (subTotal3 / passengerCount);
	window.document.forms[0].SubTotal7.value = formatCurrency(subTotal7);
	
	subTotal8 = (subTotal3 - subTotal7);
	window.document.forms[0].SubTotal8.value = formatCurrency(subTotal8);
	
	var vanFare = Number(window.document.forms[0].VanFare.value);
	if (isNaN(vanFare)) {
		window.document.forms[0].VanFare.value=0;
		vanFare = 0;
	}
	subTotal9 = (subTotal3 - vanFare);
	window.document.forms[0].SubTotal9.value = formatCurrency(subTotal9);
	
	var busFare = Number(window.document.forms[0].BusFare.value);
	var busParking = Number(window.document.forms[0].BusParking.value);
	if (isNaN(busFare)) {
		window.document.forms[0].BusFare.value=0;
		busFare = 0;
	}
	if (isNaN(busParking)) {
		window.document.forms[0].busParking.value=0;
		busParking = 0;
	}

	subTotal5 = busFare + busParking;
	window.document.forms[0].SubTotal5.value = formatCurrency(subTotal5);
	
	subTotal6 = (subTotal3 - subTotal5);
	window.document.forms[0].SubTotal6.value = formatCurrency(subTotal6);	
}

function formatCurrency(Price)	{
	Price = String(Price);
	var result = Price.search(/\./);
	if (result < 1) {
		Price = Price + ".00";
	}
	aryPrice = Price.split(".", 2);
	BeforeDecimal = aryPrice[0]
	AfterDecimal = aryPrice[1].substring(0,2);
	Price = "$" + BeforeDecimal + "." + AfterDecimal;
	return(Price);
}

// Man, and I thought Dreamweaver javascript was ugly 





function addClass(element,name) {
  if (!element.className) {
    element.className = name;
  } else {
    element.className+= " ";
    element.className+= name;
  }
}

function alternateRows() {
	if (!document.getElementsByTagName("table")) return;
	var tables = document.getElementsByTagName("table");
	for (var i = 0; i<tables.length; i++) {
		if (tables[i].className.match("alternate")) {
			var tablerow = tables[i].getElementsByTagName("tr");
      for (var j=0; j<tablerow.length; j=j+2) {
        addClass(tablerow[j],"oddrow");
      }
    }
  }
}

// From Simon Willison: http://simon.incutio.com/archive/2004/05/26/addLoadEvent
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent(alternateRows);