var currentObj;
var currentTable = 0;
var tables       = [];

var gmapHashTab         = [];
var gmarkHashTab        = [];
var gmarkManagerHashTab = [];
var gdirHashTab         = [];
var toDirHashTab        = [];
var fromDirHashTab      = [];
var currentGmapID       = "" ;		


function popupMarkerInfo(mapID, idx)
{
	gmap     = gmapHashTab[mapID];
	gmarkers = gmarkHashTab[mapID];

	var bounds = new GLatLngBounds();
	point    = gmarkers[idx].getLatLng();
	bounds.extend(point);

	zoomLevel = Math.min(18, gmap.getBoundsZoomLevel(bounds));

	var MapTypes = gmap.getMapTypes(); 
	for (var m = 0; m < MapTypes.length; m++)
		zoomLevel = Math.min(zoomLevel, MapTypes[m].getMaximumResolution());

	gmap.setCenter(point, zoomLevel - 1);

	gmarkers[idx].initialize(gmap);
	GEvent.trigger(gmarkers[idx],"click");	 

}




function sm(idx)
{
popupMarkerInfo("mapBANK", idx);
window.location="#top";
}



//===================================================================================================================
//===================================================================================================================



var cutno    = true;
var geocoder = (typeof GClientGeocoder == 'function') ? new GClientGeocoder() : "";
var gmap;

var bank      = "";
var address   = "";
var addr_orig = "";
var mainoff   = false;

var before = [];

function createMarker(point, markerOptions, desc) 
{
var marker = new GMarker(point, markerOptions);

if (desc !== undefined)
{
	var mapID = currentGmapID;

	if (gdirHashTab[mapID] !== undefined)
	{
		var i     = gmarkHashTab[mapID].length;
		var name  = "";


		// The info window version with the "to here" form open
		toDirHashTab[mapID][i] = desc + '<small><br/><br/>Directions: <b>To here<\/b> - <a href="javascript:fromhere(' + i + ',\'' + mapID + '\')">From here<\/a>' +
			'<br>Start address:<form action="javascript:getDirections(\'' + mapID + '\')">' +
			'<input type="text" SIZE=40 MAXLENGTH=40 name="saddr" id="saddr" value="" /><br>' +
			'<INPUT value="Get Directions" TYPE="SUBMIT"><br>' +
			'Walk <input type="checkbox" name="walk" id="walk" /> &nbsp; Avoid Highways <input type="checkbox" name="highways" id="highways" />' +
			'<input type="hidden" id="daddr" value="' + name + "@"+ point.lat() + ',' + point.lng() + '"/></small>';

		// The info window version with the "from here" form open
		fromDirHashTab[mapID][i] = desc + '<small><br/><br/>Directions: <a href="javascript:tohere(' + i + ',\'' + mapID + '\')">To here<\/a> - <b>From here<\/b>' +
			'<br>End address:<form action="javascript:getDirections(\'' + mapID + '\')">' +
			'<input type="text" SIZE=40 MAXLENGTH=40 name="daddr" id="daddr" value="" /><br>' +
			'<INPUT value="Get Directions" TYPE="SUBMIT"><br>' +
			'Walk <input type="checkbox" name="walk" id="walk" /> &nbsp; Avoid Highways <input type="checkbox" name="highways" id="highways" />' +
			'<input type="hidden" id="saddr" value="' + name + "@"+ point.lat() + ',' + point.lng() + '"/></small>';

		// The inactive version of the direction info
		desc = desc + '<small><br/><br/>Directions: <a href="javascript:tohere(' + i + ',\'' + mapID + '\')">' + 
			'To here<\/a> - <a href="javascript:fromhere(' + i + ',\'' + mapID + '\')">From here<\/a></small>';
	}
		
	GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml(desc, {pixelOffset:new GSize(32,5)});});  

}

return marker;
}




function addToMap(response)
{
if (typeof response.Placemark == "undefined")
  {
	address=address.substring( address.indexOf(cutno ? " " : ",") + 1 );
	while (address[0] == ' ') {address = address.substring(1);}
	cutno = false;
	
	if (address.length > 2)
	  {
	   geocoder.getLocations(address, addToMap);
	   return;
	  }
	  
     // no marker to display => hide map
	 if (typeof gmap == "undefined")
	   {document.getElementById("mapBANK").style.display = "none"; }

	  before[addr_orig] = -1;
	 return;	  
  }

var firstrun = false;

// not yet defined
if (typeof gmap == "undefined")
  {	
    gmap = new GMap2(document.getElementById("mapBANK"));
    gmap.addControl(new GLargeMapControl());
    gmap.addControl(new GMapTypeControl());

	currentGmapID                 = "mapBANK";
	gmapHashTab[currentGmapID]    = gmap;
	gmarkHashTab[currentGmapID]   = [];
    toDirHashTab[currentGmapID]   = [];
	fromDirHashTab[currentGmapID] = [];

	gdirHashTab[currentGmapID]    = new GDirections(gmap, document.getElementById(currentGmapID + "Directions"));


	var reasons=[];
	reasons[G_GEO_SUCCESS]            = "Success";
	reasons[G_GEO_MISSING_ADDRESS]    = "Missing Address: The address was either missing or had no value.";
	reasons[G_GEO_UNKNOWN_ADDRESS]    = "Unknown Address:  No corresponding geographic location could be found for the specified address.";
	reasons[G_GEO_UNAVAILABLE_ADDRESS]= "Unavailable Address:  The geocode for the given address cannot be returned due to legal or contractual reasons.";
	reasons[G_GEO_BAD_KEY]            = "Bad Key: The API key is either invalid or does not match the domain for which it was given";
	reasons[G_GEO_TOO_MANY_QUERIES]   = "Too Many Queries: The daily geocoding quota for this site has been exceeded.";
	reasons[G_GEO_SERVER_ERROR]       = "Server error: The geocoding request could not be successfully processed.";
	reasons[G_GEO_BAD_REQUEST]        = "A directions request could not be successfully parsed.";
	reasons[G_GEO_MISSING_QUERY]      = "No query was specified in the input.";
	reasons[G_GEO_UNKNOWN_DIRECTIONS] = "Could not compute directions between the points.";

	GEvent.addListener(gdirHashTab[currentGmapID], "error", function() 
	  {
		var code   = gdirHashTab[currentGmapID].getStatus().code;
		var reason = (reasons[code]) ? reasons[code] : "Code " + code;
		alert("Failed to obtain directions, " + reason);
  	  });

    firstrun = true;
  }
  
document.getElementById("mapBANK").style.display = ""; 

var markerOptions = { };
if (!mainoff)
  {
	var tinyIcon = new GIcon();
	tinyIcon.image = "o.png";
	tinyIcon.shadow = "os.png";
	tinyIcon.iconSize = new GSize(12, 20);
	tinyIcon.shadowSize = new GSize(22, 20);
	tinyIcon.iconAnchor = new GPoint(6, 20);
	tinyIcon.infoWindowAnchor = new GPoint(5, 1);
	markerOptions = { icon:tinyIcon };
  }

before[addr_orig] = gmarkHashTab[currentGmapID].length;

var back = "";

if (typeof currentObj != "undefined")
{
  var obj = currentObj.parentNode;
  back = "<br/><a href='#" + obj.cells[1].innerHTML + "'>Back to list</a>";
  obj.cells[1].innerHTML += "<a name='" + obj.cells[1].innerHTML + "'></a>";
}


place = response.Placemark[0];
point = new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]);
gmap.setCenter(point, 13);
marker = createMarker(point, markerOptions, "<small><b>" + bank+ "</b><br/>" + address + back + "</small>");
gmap.addOverlay(marker);

gmarkHashTab[currentGmapID].push(marker);

if (!firstrun)
	{sm(before[addr_orig]);}
}

function load(addr, bnk, main)
{
  bank      = bnk;
  address   = addr;
  addr_orig = addr;
  mainoff   = main;

 // fix for PO BOX
 if (address.toUpperCase().indexOf(" BOX") != -1)
	{address=address.substring( address.indexOf(",")+1 );}

  if (typeof before[addr_orig] != "undefined")
  {
	var cnt = before[addr_orig];
	if (cnt >=0 ) {sm(cnt);}
    return;
  }


  geocoder.getLocations(address, addToMap);
  window.location="#top";
}

function P(obj)
{
var addr = obj.parentNode.cells[3].innerHTML;
var bnk  = obj.parentNode.cells[2].innerHTML;
currentObj = obj;

load(addr, bnk, 0);
}


//===================================================================================================================
//===================================================================================================================


function Sw(c, n)
{
document.getElementById(eval(c)).style.display = 'none';
document.getElementById(n).style.display = '';
document.getElementById('n' + eval(c)).className = 'ffiec';
document.getElementById('n' + n).className = 'ffiec active';
document.getElementById('n' + n).blur();
eval(c + " = n;");
}


//===================================================================================================================
//===================================================================================================================

//*****************************************************************************
// Filename: sortTable.js
// Description: This javascript file can be applied to convert record tables
// in a HTML file to be client-side sortable by associating title columns with
// sort events. 
//
// COPYRIGHT (C) 2002 HAN J. YU
// THIS PROGRAM IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY IT 
// UNDER THE TERMS OF THE GNU GENERAL PUBLIC LICENSE AS PUBLISHED BY THE FREE 
// SOFTWARE FOUNDATION; EITHER VERSION 2 OF THE LICENSE, OR (AT YOUR OPTION) 
// ANY LATER VERSION. THIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE 
// USEFUL, BUT WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF 
// MERCHANTABILITY OF FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU GENERAL 
// PUBLIC LICENSE FOR MORE DETAILS. 
//
// YOU SHOULD HAVE RECEIVED A COPY OF THE GNU GENERAL PUBLIC LICENSE ALONG 
// WITH THIS PROGRAM; IF NOT, WRITE TO: 
//
// THE FREE SOFTWARE FOUNDATION, INC., 
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 
//
// Bugs/Comments: han@velocityhsi.com

var table;				// Table object
var ttable;				// Title Table object
var tableId;				// Current Table ID
var ttableId;				// Current Title Table ID
var tableIdArray = [];		// Holds Tabld IDs
var sortDirArray = [];		// Holds sort direction (descending)  
var tableCount = 0;			// Total table count
var rowArray = [];		// Data row array
var titleRowArray = [];	// Contains row pointer for titles
var titleInnerHTMLArray = [];	// Contains innerHTML for title cells
var titleSpanCountArray = [];	// Contains the row-span count
var titleRowCellArray = [];	// Dynamically constructed title cells
var titleSpanCellArray = [];	// Title elelments from row-spanned
var colSpanArray = [];		// Rows col-spanned
var colTitleFilled = [];	// Indicates whether title is filled
var sortIndex;				// Selected index for sort
var nRow, actualNRow, maxNCol;		// Various table stats
var origColor;				// Holds original default color
var isIE;				// True if IE
var separateTitle = false;		// Has separate title table
var linkEventString =			// What's insider <a> tag
	'onMouseOver=\'setCursor(this);\' ' +
	'onClick="setCursorWait(this);setTimeout(\'sortTable(';
var cellPropArray = [		// Cell properties to preserve
	"align", "vAlign", "bgColor",
	"noWrap", "width", "height", 
	"borderColor",
	"borderColorLight",
	"borderColorDark"];
var colsToIgnoreArray;			// Col indexes to ignore (Array)
var colsToIgnore;			// Col indexes to ignore

// Configurable constants
var useImg = false;		// Uses images if true
var ascChrFile = "up.gif";	// Image for ascending sort
var desChrFile = "down.gif";	// Image for descending sort
var ascChr = "&uarr;";		// Symbol for ascending sort
var desChr = "&darr;";		// Symbol for descending sort
var useCustomTitleFont = false;	// Uses custom fonts for titles
var titleFont = "Trebuchet MS";	// Title Font
var selectedColor = "blue";	// Color for sort focus
var defaultColor = "black";	// Default color for sort off-focus
var recDelimiter = '|';		// Char used as a record separator
var cellPropDelimiter = ",";	// Char used as a cell prop separator
var updownColor = 'red';	// Specified the color for up/downs
var doSortUponLoad = true;	// Do the sort upon page load
var defaultSortColumn = 0;	// Indicates the default sort column index
var useEuroDate = false;	// Set if Euro Date format is used
var highlightSelCell = true;	// Set if selected cell needs to be highlighted
var cellHighlightColor = "red";	// Color for cell highlight
var cCellPropArray = [];
var currentRow, innerHTML, newInnerHTML, cellIndex;


function indexExist(x, index)
{
	var found = false;
	for (var i=0; i<x.length; i++)
	{
		if (index == x[i])
		{
			found = true;
			break;
		}
	}
	return found;
}


function findTableIndex(id)
{
	for (var i=0; i<tableCount; i++)
    {
		if (tableIdArray[i] == id)
			{return(i);}
    }
	return(-1);
}


function redrawTitle(isSort)
{
	var reAnchor, reUpDown, reLabel, cellAlign, makeBold;
	var cellOnmouseover, cellOnmouseout;
 	var cellClass;
	var cmd;
	var tIndex;

	cellAlign = "";
	makeBold = false;
	reAnchor = / *\<a[^\>]*\>(.*) *\<\/a\>/i;
	reUpDown = /\<font[^\>]* *id=.*updown.*[^\>]*\>.*\<\/font\>/i;
	reLabel = /\>([^\<]*)\</g;

	tIndex = findTableIndex(table.id);

	// Re-drawing the title row
	for (var j=0; j<maxNCol; j++)
	{
	   currentRow = titleRowArray[j];
	   innerHTML = String(titleInnerHTMLArray[j]);
	   cellIndex = (titleRowCellArray[j].cellIndex!==undefined)?titleRowCellArray[j].cellIndex:j;
	   
		// Skips the columns if set to ignore
	   if (colsToIgnore !== null)
	      {if (indexExist(colsToIgnoreArray,cellIndex)) {continue;}}
		 
		// Recording cell settings
	   for (var k=0; k<cellPropArray.length; k++)
	      {		   
		 cmd = "cCellPropArray[k]=titleRowCellArray[j]."+cellPropArray[k]+";";
		 eval(cmd);
	      }
	   cellClass = titleRowCellArray[j].getAttribute('className');
	   
	   currentRow.deleteCell(cellIndex);
	   currentRow.insertCell(cellIndex);
	   
		// Setting the font type for the title
	   if (cellAlign !== "")
	      {currentRow.cells[cellIndex].align = cellAlign;}
	   if (titleRowCellArray[j].tagName == "TH")
		 {makeBold = true;}
	   
		// Restoring cell settings
	   for (var k=0; k<cellPropArray.length; k++)
	      {
		 cmd = "currentRow.cells[cellIndex]."+cellPropArray[k]+" = cCellPropArray["+k+"];";
		 eval(cmd);
	      }

	   currentRow.cells[cellIndex].setAttribute('className', cellClass, 0);

		if (titleSpanCountArray[j] > 1)
			{currentRow.cells[cellIndex].rowSpan = titleSpanCountArray[j];}

		newTitle = '';
		if (j == sortIndex && isSort)
		{
		   newTitle = '<font id=updown color=' + updownColor + '>&nbsp;';
		   if (sortDirArray[tIndex])
		      {
			 if (useImg)
			    {newTitle += '<img src="' + desChrFile + '" alt="' +desChr + '">';}
			 else
			    {newTitle += desChr;}
		      }
		   else
		      {
			 if (useImg)
			    {newTitle += '<img src="' + ascChrFile + '" alt="' + ascChr + '">';}
			 else
			    {newTitle += ascChr;}
		      }
		   newTitle += '</font>';
		} 
		// Remove carriage return, linefeed, and tab
		innerHTML = innerHTML.replace(/\r|\n|\t/g, "");
		if (makeBold)
		{
		   if (innerHTML.match(reLabel))
		      {innerHTML=innerHTML.replace(reLabel, "<b>$1</b>");}
		   else
		      {innerHTML=innerHTML.replace(/(^.*$)/, "<b>$1</b>");}
		}

	   innerHTML = innerHTML.replace(reUpDown, "");
	   innerHTML = innerHTML.replace(reAnchor, "$1");
	   newInnerHTML ='<a ' + linkEventString + j + ',' +tIndex + ',' + 1 + ',' + 1 + ')\', 1);">';
	   if (useCustomTitleFont)
	      {newInnerHTML += '<font face="' + titleFont + '">' + innerHTML + '</font>';}
	   else
	      {newInnerHTML += innerHTML;}
	   newInnerHTML += '</a>' + newTitle;
	   
	   currentRow.cells[cellIndex].innerHTML = newInnerHTML;
	   titleRowCellArray[j] = currentRow.cells[cellIndex];
	}
}


function checkBrowser()
{
	if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion, 10) >= 4))
	{
		isIE = true;
		return true;
	}
	// For some reason, appVersion returns 5 for Netscape 6.2 ...
	else if ((navigator.appName == "Netscape") && (navigator.appVersion.indexOf("5.") >= 0))
	{
		isIE = false;
		return true;
	}
	
	return false;
}




function initTable(obj,ignore)
{

   checkBrowser();
   var tIndex;
   
	// Cols to ignore
   colsToIgnore = ignore;
   if (colsToIgnore !== null) 
      {colsToIgnoreArray = ignore.split(",");}
   else
      {colsToIgnore = null;}
   
	// Local variables
   var countCol;
   var currentCell;
   var nColSpan, nRowSpannedTitleCol, colPos;
   var titleFound = false;
   var skipRow = false;
   var rNRowSpan, rNColSpan, parentNodeName;
   var cCellContent, cCellSetting;
   var sObj;
   var ctable;
   var doneftable = false;
   var cmd;
   var tableLoaded = false;

   
   table = document.getElementById(obj);

	// Check whether it's an object
   if (table === null) {return;}

	// Check whether it's a table
   if (table.tagName != "TABLE") {return;}

	// No need to re-init if it's already done
   if (tableId == table.id && table.tainted === false) {return;}


	// Setting table id
   tableId = table.id;
	nRow = table.rows.length;
   if (nRow < 1) {return;}


	// Initializing the max col number with the size of last data row
   maxNCol = table.rows[nRow-1].cells.length;

	// Initializing arrays
   rowArray = [];
   colSpanArray = [];
   colTitleFilled = [];
   titleRowArray = [];
   titleInnerHTMLArray = [];
   titleSpanCountArray = [];
   titleRowCellArray = [];
	
   for (var i=1; i<maxNCol; i++)
      {colTitleFilled[i] = false;}


	// Initialization of local variables
	actualNRow = 0;			// Number of actual data rows
	rNRowSpan = 0;			// Remaining rows in the row span
	rNColSpan = 0;			// Remaining cols in the col span
	nRowSpannedTitleCol = 0;	// Number of title cols from row span

	// Loop through rows
	for (var i=0; i<nRow; i++)
	{
	   ctable = table;
	   skipRow = false;
		
               // Skip if it's THEAD, TFOOT
	   if (ctable.rows[i].parentNode !== null)
	      {
		 parentNodeName = ctable.rows[i].parentNode.nodeName;
		 parentNodeName.toUpperCase();

		 if (parentNodeName == 'THEAD' || parentNodeName == 'TFOOT' || parentNodeName == 'CAPTION')
		    {skipRow = true;}
	      }	
	   nColSpan = 1; 
       colPos = 0;
		// Loop through columns
		// Initializing
	   for (var j=0; j<ctable.rows[i].cells.length; j++)
	      {
		   if (ctable.rows[i].cells[j].colSpan > 1 && rNColSpan === 0)
		      { 
			 nColSpan = ctable.rows[i].cells[j].colSpan;
			 colPos += nColSpan;
		      }
		   else
			 {colPos++;}
		}

	   
		// Setting up the title cells
	   if (titleFound === false && nColSpan == 1 && rNRowSpan === 0 && rNColSpan === 0)
	      {
		 colSpanArray[i] = true;
		 titleFound = true;
		 
			// Using indivisual cell as an array element
		 countCol = 0;
		 for (var j=0;j<ctable.rows[i].cells.length+ nRowSpannedTitleCol; j++)
		    {
		       if (colTitleFilled[j] !== true)
			  {
			     titleRowCellArray[j] = ctable.rows[i].cells[countCol];
			     titleRowArray[j]     = ctable.rows[i];
			     countCol++;
			  }
		       else
			  {titleRowCellArray[j] = titleSpanCellArray[j];}
		       
		       titleInnerHTMLArray[j] = String(titleRowCellArray[j].innerHTML);
		       titleSpanCountArray[j] = titleRowCellArray[j].rowSpan;
		    }
	      }

		// Setting up the data rows
	   else if (titleFound === true && nColSpan == 1 && rNRowSpan === 0 && !skipRow)
	      {
		 rowArray[actualNRow]=[];

		 for (var j=0; j<ctable.rows[i].cells.length; j++)
		    {
		       if (ctable.rows[i].cells[j].rowSpan > 1) 
			  {return;}
		       rowArray[actualNRow][j]=String(ctable.rows[i].cells[j].innerHTML);
		      }
		 
		 if (ctable.rows[i].cells.length > maxNCol)
		       {return;}

		 actualNRow++;
		 colSpanArray[i] = false;
	      }
	   else if (nColSpan == 1 && rNRowSpan === 0 && rNColSpan === 0 && titleFound === false && !skipRow)
	      {colSpanArray[i] = false;}
	   else
	      {colSpanArray[i] = true;}
		
		// Counters for row/column spans
	   if (rNRowSpan > 0) 
	      {rNRowSpan--;}
	   if (rNColSpan > 0) 
	      {rNColSpan--;}
	}


   
	// If the row number is < 1, no need to do anything ...
   if (actualNRow < 1) 
      {return;}
   
	// Sorting upon loading the page
   tIndex = findTableIndex(table.id);
   if (tIndex >= 0) 
      {tableLoaded = true;}

   if (!tableLoaded)
      {
	 tableIdArray[tableCount] = table.id;
	 sortDirArray[tableCount] = false;
	 tIndex = tableCount;
	 tableCount++;
      }
   
	// Re-drawing the title row
   redrawTitle(false);
   
	// Sort if doSortUponLoad is set
   if (doSortUponLoad) 
      {
	 sortTable(defaultSortColumn, table.id, 0, 0);
	 if (!tableLoaded) 
	    {sortDirArray[tIndex] = true;}
      }


}

function isDate(x)
{
	var xDate;
	xDate = new Date(x);
	if (xDate.toString() == 'NaN' || xDate.toString() == 'Invalid Date')
		{return false;}
	else
		{return true;}
}

function compare(a, b)
{


	// Getting the table index
   var tIndex = findTableIndex(table.id);
   var dir= (!sortDirArray[tIndex])?1:-1;
   
	// Needed in case the data conversion is necessary
   var aToBeCompared, bToBeCompared;
   
	// Remove HTML tags 
   reRowText = /(\< *[^\>]*\>|\&nbsp\;|\(.*\))|m2|m3|pln|\$|,|\(|\)/gi;
   aRowContent = a[sortIndex].replace(reRowText, "");
   bRowContent = b[sortIndex].replace(reRowText, "");

   if (isDate(aRowContent[sortIndex]) && isDate(bRowContent[sortIndex]))
      {
	 aToBeCompared = new Date(aRowContent);
	 bToBeCompared = new Date(bRowContent);
      }
   else if (!isNaN(aRowContent) && !isNaN(bRowContent))
	{
	   aToBeCompared = parseFloat(aRowContent, 10);
	   bToBeCompared = parseFloat(bRowContent, 10);
	}
   else
      {
	 aToBeCompared = aRowContent.toUpperCase();
	 bToBeCompared = bRowContent.toUpperCase();
      }

   if (aToBeCompared < bToBeCompared)
      {return -dir;}
   
   if (aToBeCompared > bToBeCompared)
      {return dir;}

   return 0;
}


function setCursorDefault()
{
	if (isIE && document.all)
    {
		for (var i=0;i<document.all.length;i++) 
			{document.all(i).style.cursor = '';}
    }
	else
		{document.body.style.cursor = '';}
}


function setColor(obj,mode)
{
	return;

	if (mode == "selected")
	{
		// Remember the original color
		if (obj.style.color != selectedColor) 
			{defaultColor = obj.style.color;}
		obj.style.color = selectedColor;

		if (highlightSelCell)
			{obj.bgColor = cellHighlightColor;}
	}
	else
	{	
		// Restoring original color and re-setting the status bar
		obj.style.color = defaultColor;
		if (highlightSelCell) {obj.bgColor = defaultColor;}
		window.status = '';
	}
}



function sortTable(index,tobj,doInit,isIndex)
{


	var obj, tIndex;
	if (isIndex !== null)
      {
		if (isIndex)
		{
			tIndex = tobj;
			// Look up the table object
			obj = tableIdArray[tobj];
		}	
		else
		{
			tIndex = findTableIndex(tobj.id);
			obj = tobj;
		}
     }

	// Re-inializing the table object
	if (doInit) 
	   {initTable(obj,colsToIgnore);}

	// Local variables
	var rowContent, rowProp, cellProp;
	var rowCount;
	var rowIndex;
 	var cellClass, cellOnClick, cellMouseOver, cellMouseOut;
	var cmd;
	
	// Can't sort past the max allowed column size
	if (index < 0 || index >= maxNCol) {return;}
	
	// Assignment of sort index
	sortIndex = index;
	// Doing the sort using JavaScript generic function for an Array
	rowArray.sort(compare);
   
	// Re-drawing the title row
   if (doInit || doSortUponLoad) 
      {redrawTitle(true);}


	// Re-drawing the table
   rowCount = 0;
   for (var i=0; i<nRow; i++)
      {
	 if (colSpanArray[i])
	    {continue;}
	 
	 for (var j=0; j<maxNCol; j++)
	    {table.rows[i].cells[j].innerHTML =rowArray[rowCount][j];}
	 
	 rowCount++;
	 
      }

	// Switching btw descending/ascending sort
   if (doInit)
      {sortDirArray[tIndex]=!sortDirArray[tIndex];}
   setCursorDefault();
}







function convertEuroDate(x)
{
	var reExp = /^ *(\d{2})\-(\d{2})\-(\d{4}) *$/g;
	var dArray;
	if (x.match(reExp))
		{x = x.replace(reExp, "$2\/$1\/$3");	}
	return(x);
}


function setCursor(obj)
{
	var rowText, reRowText;

	reRowText = /(\< *[^\>]*\>|\&nbsp\;)/g;
	// Show hint text at the browser status bar
	rowText = String(obj.innerHTML);

	// Remove up/down 
	rowText = rowText.replace(/\<font id\=updown.*\<\/font\>/ig, "");
	// Remove HTML tags and &nbsp;
	rowText = rowText.replace(reRowText, "");
	// Remove carriage return, linefeed, and tab
	rowText = rowText.replace(/\r|\n|\t/g, "");
	
	// Setting window's status bar
	window.status = "Click to sort by  '" + String(rowText)+"'";

	// Setting title
	obj.title = "Click to sort by '" + String(rowText)+"'";

	// Change the mouse cursor to pointer or hand
	if (isIE)
		{obj.style.cursor = "hand";}
	else
		{obj.style.cursor = "pointer";}
}

function setCursorWait(obj)
{
	if (isIE && document.all)
    {
		for (var i=0;i<document.all.length;i++) 
			{document.all(i).style.cursor = 'wait';}
    }
	else
	{
		obj.style.cursor = 'wait';
		document.body.style.cursor = 'wait';
	}
}





//===================================================================================================================
//===================================================================================================================

function getDirections(mapID) 
{
	// ==== Set up the walk and avoid highways options ====
	var opts = {};
	if (document.getElementById("walk").checked)
		{opts.travelMode = G_TRAVEL_MODE_WALKING;}

	if (document.getElementById("highways").checked)
		{opts.avoidHighways = true;}

	// ==== set the start and end locations ====
	var saddr = document.getElementById("saddr").value;
	var daddr = document.getElementById("daddr").value;

	gdirHashTab[mapID].load("from: " + saddr + " to: " + daddr, opts);
}


// This function picks up the click and opens the corresponding info window
function myclick(i, mapID) 
{
	gmarkHashTab[mapID][i].openInfoWindowHtml(htmls[i]);
}

// functions that open the directions forms
function tohere(i, mapID) 
{
	gmarkHashTab[mapID][i].openInfoWindowHtml(toDirHashTab[mapID][i]);
}

function fromhere(i, mapID) 
{
	gmarkHashTab[mapID][i].openInfoWindowHtml(fromDirHashTab[mapID][i]);
}



//===================================================================================================================
//===================================================================================================================
var pDefaultPaddingTop    = 20;
var pDefaultPaddingRight  = 20;
var pDefaultPaddingBottom = 20;
var pDefaultPaddingLeft   = 20;

var bDefaultPaddingTop    = 0;
var bDefaultPaddingRight  = 10;
var bDefaultPaddingBottom = 20;
var bDefaultPaddingLeft   = 70;


var pPaddingTop    = pDefaultPaddingTop;
var pPaddingRight  = pDefaultPaddingRight;
var pPaddingBottom = pDefaultPaddingBottom;
var pPaddingLeft   = pDefaultPaddingLeft;


var bPaddingTop    = bDefaultPaddingTop;
var bPaddingRight  = bDefaultPaddingRight;
var bPaddingBottom = bDefaultPaddingBottom;
var bPaddingLeft   = bDefaultPaddingLeft;

var maxValExternal = -1;

if(typeof BarDraw != 'function') {



function PieDraw(cnt, DatasetIN, xTicksIN)
{
var Dataset = [];
var xTicks  = [];
for (var i = 0; i < DatasetIN.length; i++) 
 {
	Dataset[i] = [i, DatasetIN[i]];
	xTicks[i]  = {v: i, label: xTicksIN[i]};
 }

var hColor = Color.fromHexString;
var colorSchemePie = [hColor("#BEA7D9"), hColor("#C3D9A7"), hColor("#FFFA94"), hColor("#F7B0B0"), hColor("#8F8FF1"), hColor("#FFD6AD"), hColor("#ADD6FF"), hColor("#CBFF7E"), hColor("#FFC774"), hColor("#DDD8B9"), hColor("#EB8686"), hColor("#D6AD33")];


if (navigator.userAgent.indexOf('NT 5.0') == -1 || (navigator.userAgent.indexOf('MSIE 6') == -1 && navigator.userAgent.indexOf('MSIE 5') == -1)){
var options = {
"IECanvasHTC": "/js/iecanvas.htc",
"colorScheme": colorSchemePie , 
"padding": {top: pPaddingTop, right: pPaddingRight, bottom: pPaddingBottom, left: pPaddingLeft},
"axisLabelWidth" : 100,
"pieRadius" : 0.38,
"xTicks": xTicks};
function drawBarGraph() {
var layout = new PlotKit.Layout('pie', options);
layout.addDataset('dataset', Dataset);
layout.evaluate();
var canvas = MochiKit.DOM.getElement('bg' + cnt);
var plotter = new PlotKit.SweetCanvasRenderer(canvas, layout, options);
plotter.render();
}
MochiKit.DOM.addLoadEvent(drawBarGraph);}

// force default settings
pPaddingTop    = pDefaultPaddingTop;
pPaddingRight  = pDefaultPaddingRight;
pPaddingBottom = pDefaultPaddingBottom;
pPaddingLeft   = pDefaultPaddingLeft;
}


function BarDraw(cnt, Series, DatasetIN, xTicksIN, colors)
{
var xTicks  = [];
for (var i = 0; i < xTicksIN.length; i++) 
	{xTicks[i]  = {v: i, label: xTicksIN[i]};}
 
if (navigator.userAgent.indexOf('NT 5.0') == -1 || (navigator.userAgent.indexOf('MSIE 6') == -1 && navigator.userAgent.indexOf('MSIE 5') == -1)){

var hColor = Color.fromHexString;
var colorScheme = [hColor("#BEA7D9"), hColor("#C3D9A7"), hColor("#FFFA94"), hColor("#F7B0B0"), hColor("#8F8FF1"), hColor("#FFD6AD"), hColor("#ADD6FF"), hColor("#CBFF7E"), hColor("#FFC774"), hColor("#DDD8B9"), hColor("#EB8686"), hColor("#D6AD33")];

if (DatasetIN.length <= 2)
  {colorScheme[0] = Color.fromString("rgb(174, 145, 207)");}

if (DatasetIN.length == 2)
  {colorScheme[1] = Color.fromString("rgb(180, 207, 145)");}


var maxVal = -1;
for (var i = 0; i < DatasetIN.length; i++) 
{
     for (var d = 0; d < DatasetIN[i].length; d++) 
		{maxVal = Math.max(maxVal, DatasetIN[i][d]);}
}

maxVal = Math.max(maxVal, maxValExternal);


var mult = Math.pow(10, parseInt(Math.log(maxVal) / Math.LN10, 10));
var base = (maxVal >= 10) ? (maxVal + "").charAt(0) : 0;

while (base * mult < maxVal)
	{base = parseFloat(base) + 0.5;}

maxVal = base * mult;
var yPrec = (maxVal < 10) ? 1 : 0;


var options = {
"IECanvasHTC": "/js/iecanvas.htc",
"colorScheme": colorScheme, 
"padding": {top: bPaddingTop, right: bPaddingRight, bottom: bPaddingBottom, left: bPaddingLeft},
"xTicks": xTicks,
"yTickPrecision" : yPrec,
"yAxis":[0, maxVal]
};
function drawBarGraph() {
var layout = new PlotKit.Layout('bar', options);
for (var i = 0; i < DatasetIN.length; i++) 
  {
     var Dataset = [];
     for (var d = 0; d < DatasetIN[i].length; d++) 
	     {Dataset[d] = [d, DatasetIN[i][d]];}
	layout.addDataset(Series[i], Dataset);  
  }
	
layout.evaluate();


for (var i = 0; i < layout.yticks.length; i++)
{
if (layout.yticks[i][1] > 1000)
{
	var tick = layout.yticks[i][1];
	var off  = tick.length - 3;

	while (off > 0)
	{
		tick = tick.substr(0, off) + "," + tick.substr(off);
		off -= 3;
	}

	layout.yticks[i][1] = tick; 
}
}


var canvas = MochiKit.DOM.getElement('bg' + cnt);
var plotter = new PlotKit.SweetCanvasRenderer(canvas, layout, options);
plotter.render();
if (Series.length > 1)
  {
	legend = new PTPlotLegend('legend' + cnt, layout, plotter);
	legend.showLegend();
  }
}
MochiKit.DOM.addLoadEvent(drawBarGraph);}

// force default settings
bPaddingTop    = bDefaultPaddingTop;
bPaddingRight  = bDefaultPaddingRight;
bPaddingBottom = bDefaultPaddingBottom;
bPaddingLeft   = bDefaultPaddingLeft;

maxValExternal = -1;
}


}
	
//===================================================================================================================
//===================================================================================================================
function initSingleTable()
{
if (currentTable >= tables.length)
  {return;}

initTable(tables[currentTable++], null);
setTimeout(initSingleTable, 100);
}

function initAllTables(tabs)
{
tables = tabs;
setTimeout(initSingleTable, 0);
}
