// Javascript common to all pages - usually in header or footer

var locationStr = self.location.href.toLowerCase();
//alert('self.location = ' + locationStr);
var pageTypeStr = locationStr.substring(0,4);
//alert('pageTypeStr = ' + pageTypeStr);

// To change class of specified id. Both params are strings
 function classChange( id, newclass )
  {
    element = document.getElementById(id);
    if(element)
      element.className = newclass ;
  }

function makeArray() {
	 for (i = 0; i<makeArray.arguments.length; i++)
		  this[i + 1] = makeArray.arguments[i];
}

function formatDate(theDate) {
//	document.write('<BR><BR><BR>' + "Running formatDate on: " + theDate + '<BR>');
	var day  = theDate.getDate();
//	document.write("day = " + day + '<BR>');
	var month = theDate.getMonth() + 1;
//	document.write("month = " + month + '<BR>');
	var yy = theDate.getYear();
//	document.write("yy = " + yy + '<BR>');
	var year = (yy < 1000) ? yy + 1900 : yy;
//	document.write("year = " + year + '<BR>');
	return day + "/" + month + "/" + year
}

var months = new makeArray('January','February','March',
	'April','May','June','July','August','September',
	'October','November','December');

var last = document.lastModified;
var lastmoddate = new Date(last);
var todaydate = new Date();

function newWindow(file,window) {
	msgWindow=open(file,window,'width=400,height=480');
	if (msgWindow.opener == null) msgWindow.opener = self;
}


// The next 2 variables and 3 functions are used to write the fare tables 
var rate14 = 0.538;  // this is price per mile for 1-4 passengers from this location
var rate58 = 0.591;  // this is price per mile for 5-8 passengers from this location

function fareCalc(d,r) {
  var cost = Math.ceil(d*r*10)/10; // rounds up to nearest 10p
  return cost.toFixed(2)
}

function doRow(n) {
	var outstr = "";
	outstr = outstr + "<TR>";
	outstr = outstr + "<TD>&nbsp;" + places[n] + "\</TD>" +
		"<TD>&nbsp;&pound; " + fareCalc(dist[n],rate14) + "\</TD>" +
		"<TD>&nbsp;&pound; " + fareCalc(dist[n],rate58) + "\</TD>" ;
	outstr = outstr + "\</TR>";
	document.write(outstr)
}

function doTable() {
	//alert("length = " + places.length)
	for(i=0; i<places.length; i++) { 
		doRow(i); 
	}
}
	
