
    // city name graphics

var cityNameGraphics = new Array();
cityNameGraphics[ALBANY_DOWNTOWN] = ['albany_ny.gif', 'albany_ny.gif'];
cityNameGraphics[ANN_ARBOR_UM] = ['annarbor_mi.gif', 'annarbor_mi.gif'];
cityNameGraphics[ATLANTIC_CITY_BOARDWALK] = ['atlanticcity_nj.gif', 'atlanticcity_nj.gif'];
cityNameGraphics[BALTIMORE_PENN_STATION] = ['baltimore_md.gif', 'baltimore_md.gif'];
cityNameGraphics[BALTIMORE_TRAVEL_PLAZA] = ['baltimore_md.gif', 'baltimore_md.gif'];
cityNameGraphics[BALTIMORE_WHITE_MARSH] = ['baltimore_md.gif', 'baltimore_md.gif'];
cityNameGraphics[BOSTON_SOUTH_STATION] = ['boston_ma.gif', 'boston_ma.gif'];
cityNameGraphics[BUFFALO_AIRPORT] = ['buffalo_ny.gif', 'buffalo_ny.gif'];
cityNameGraphics[BUFFALO_TRANSPORTATION_CENTER] = ['buffalo_ny.gif', 'buffalo_ny.gif'];
cityNameGraphics[CHAMPAIGN_ILLINOIS_TERMINAL] = ['champaign_il.gif', 'champaign_il.gif'];
cityNameGraphics[CHICAGO_UNION_STATION] = ['chicago_il.gif', 'chicago_il.gif'];
cityNameGraphics[CINCINNATI_DOWNTOWN] = ['cincinnati_oh.gif', 'cincinnati_oh.gif'];
cityNameGraphics[CLEVELAND_TOWER_CITY] = ['cleveland_oh.gif', 'cleveland_oh.gif'];
cityNameGraphics[COLUMBIA_WABASH] = ['columbia_mo.gif', 'columbia_mo.gif'];
cityNameGraphics[COLUMBUS_DOWNTOWN] = ['columbus_oh.gif', 'columbus_oh.gif'];
cityNameGraphics[COLUMBUS_OSU] = ['columbus_oh.gif', 'columbus_oh.gif'];
cityNameGraphics[DES_MOINES_DOWNTOWN] = ['desmoines_ia.gif', 'desmoines_ia.gif'];
cityNameGraphics[DETROIT_DOWNTOWN] = ['detroit_mi.gif', 'detroit_mi.gif'];
cityNameGraphics[DETROIT_WSU] = ['detroit_mi.gif', 'detroit_mi.gif'];
cityNameGraphics[INDIANAPOLIS_DOWNTOWN] = ['indianapolis_in.gif', 'indianapolis_in.gif'];
cityNameGraphics[IOWA_CITY_UI] = ['iowacity_ia.gif', 'iowacity_ia.gif'];
cityNameGraphics[KANSAS_CITY_DOWNTOWN] = ['kansascity_mo.gif', 'kansascity_mo.gif'];
cityNameGraphics[MADISON_HUXLEY] = ['madison_wi.gif', 'madison_wi.gif'];
cityNameGraphics[MADISON_DUTCH_MILL] = ['madison_wi.gif', 'madison_wi.gif'];
cityNameGraphics[MEMPHIS_MATA] = ['memphis_tn.gif', 'memphis_tn.gif'];
cityNameGraphics[MILWAUKEE_AMTRAK] = ['milwaukee_wi.gif', 'milwaukee_wi.gif'];
cityNameGraphics[MILWAUKEE_RYAN_ROAD] = ['milwaukee_wi.gif', 'milwaukee_wi.gif'];
cityNameGraphics[MINNEAPOLIS_CENTRAL] = ['minneapolis_mn.gif', 'minneapolis_mn.gif'];
cityNameGraphics[MINNEAPOLIS_METRODOME] = ['minneapolis_mn.gif', 'minneapolis_mn.gif'];
cityNameGraphics[NEW_YORK_CHINATOWN] = ['newyork_ny.gif', 'newyork_ny.gif'];
cityNameGraphics[NEW_YORK_PENN] = ['newyork_ny.gif', 'newyork_ny.gif'];
cityNameGraphics[NEW_YORK_PORT_AUTHORITY] = ['newyork_ny.gif', 'newyork_ny.gif'];
cityNameGraphics[NEW_YORK_SOHO] = ['newyork_ny.gif', 'newyork_ny.gif'];
cityNameGraphics[NORMAL_AMTRAK] = ['normal_il.gif', 'normal_il.gif'];
cityNameGraphics[PHILADELPHIA_30TH_STREET] = ['philadelphia_pa.gif', 'philadelphia_pa.gif'];
cityNameGraphics[PHILADELPHIA_CHERRY_HILL_MALL] = ['cherryhill_nj.gif', 'philadelphia_pa.gif'];
cityNameGraphics[PHILADELPHIA_CHINATOWN] = ['philadelphia_pa.gif', 'philadelphia_pa.gif'];
cityNameGraphics[PITTSBURGH_CONVENTION_CENTER] = ['pittsburgh_pa.gif', 'pittsburgh_pa.gif'];
cityNameGraphics[RIDGEWOOD_ROUTE_17] = ['ridgewood_nj.gif', 'ridgewood_nj.gif'];
cityNameGraphics[ROCHESTER_AMTRAK] = ['rochester_ny.gif', 'rochester_ny.gif'];
cityNameGraphics[ROCHESTER_HENRIETTA] = ['rochester_ny.gif', 'rochester_ny.gif'];
cityNameGraphics[ST_LOUIS_UNION] = ['stlouis_mo.gif', 'stlouis_mo.gif'];
cityNameGraphics[STATE_COLLEGE_PENN_STATE] = ['statecollege_pa.gif', 'statecollege_pa.gif'];
cityNameGraphics[SYRACUSE_REGIONAL] = ['syracuse_ny.gif', 'syracuse_ny.gif'];
cityNameGraphics[TOLEDO_SOUTHWYCK] = ['toledo_oh.gif', 'toledo_oh.gif'];
cityNameGraphics[TORONTO_COACH] = ['toronto_on_canada.gif', 'toronto_on_canada.gif'];
cityNameGraphics[WASHINGTON_BETHESDA] = ['bethesda_md.gif', 'washington_dc.gif'];
cityNameGraphics[WASHINGTON_CHINATOWN] = ['washington_dc.gif', 'washington_dc.gif'];
cityNameGraphics[WASHINGTON_DUPONT] = ['washington_dc.gif', 'washington_dc.gif'];
cityNameGraphics[WASHINGTON_GREENBELT] = ['greenbelt_md.gif', 'washington_dc.gif'];
cityNameGraphics[WASHINGTON_MCPHERSON] = ['washington_dc.gif', 'washington_dc.gif'];
cityNameGraphics[WASHINGTON_ROSSLYN] = ['arlington_va.gif', 'washington_dc.gif'];
cityNameGraphics[WASHINGTON_UNION_STATION] = ['washington_dc.gif', 'washington_dc.gif'];

    // functions

function start() {

    if (createHttpRequest() === null) {
        alert('This page will not function correctly because, well, your browser is kind of old. Sorry.');
        return;
    }

    var routes = new Array();

    var originNeighborhoodCodes = getOrigin();
    var destinationNeighborhoodCodes = getDestination();
    for (var i = 0; i < routeFunctions.length; i++) {
        var current = routeFunctions[i]();
        for (var j = 0; j < current.length; j++) {
            var startNeighborhoodCode = current[j].startLocation.neighborhoodCode;
            var endNeighborhoodCode = current[j].endLocation.neighborhoodCode;
            if (originNeighborhoodCodes.contains(startNeighborhoodCode) && destinationNeighborhoodCodes.contains(endNeighborhoodCode))
                routes.push(current[j]);
        }
    }

    if (routes.length === 0) {
        showBody();
        return;
    }

    var processingCells = new Array();

    var processingDiv = document.getElementById('processingDiv');
    var processingTbody = document.getElementById('processingTbody');
    for (var i = 0; i < routes.length; i++) {
        var tr = document.createElement('tr');
        tr.style.fontSize = '12px';
        tr.style.color = 'gray';
        tr.style.fontWeight = 'bold';
        var cell = document.createElement('td');
        cell.style.textAlign = 'left';
        var text = document.createTextNode(routes[i].operator.name);
        cell.appendChild(text);
        tr.appendChild(cell);
        cell = document.createElement('td');
        cell.style.textAlign = 'right';
        text = document.createTextNode('searching');
        cell.appendChild(text);
        tr.appendChild(cell);
        processingTbody.appendChild(tr);
        processingCells.push(cell);
    }
    processingDiv.style.marginTop = '-' + (70 + routes.length * 5).toString() + 'px';
    processingDiv.style.display = 'block';

    var results = new Array();
    var date = new Date(getDate());
    var dateString = ((date.getMonth() + 1).toString().length < 2 ? '0' + (date.getMonth() + 1).toString() : (date.getMonth() + 1).toString()) + '/' + (date.getDate().toString().length < 2 ? '0' + date.getDate().toString() : date.getDate().toString()) + '/' + date.getFullYear().toString();
    var cachePrevent = (new Date()).getTime().toString();
    var nbrPendingRequests = routes.length;
    for (var i = 0; i < routes.length; i++) {
        var queryString = 'key=' + encodeURIComponent(dateString + '.' + getNbrPassengers().toString() + '.' + routes[i].operator.name + '.' + routes[i].startLocation.neighborhoodCode.toString() + '.' + routes[i].endLocation.neighborhoodCode.toString());
        var xmlHttpRequest = createHttpRequest();
        xmlHttpRequest.onreadystatechange = function(newScopeXmlHttpRequest, newScopeI) {
            return function() {
                if (newScopeXmlHttpRequest.readyState === 4) {
                    if (newScopeXmlHttpRequest.status === 200) {
                        var responseObject = eval('(' + newScopeXmlHttpRequest.responseText + ')');
                        results[newScopeI] = responseObject;
                        processingCells[newScopeI].style.color = 'green';
                        processingCells[newScopeI].childNodes[0].nodeValue = 'complete';
                    }
                    else {
                        results[newScopeI] = [];
                        processingCells[newScopeI].style.color = 'red';
                        processingCells[newScopeI].childNodes[0].nodeValue = 'unavailable';
                    }
                    if (--nbrPendingRequests === 0)
                        setTimeout(function() { processResults(routes, results); }, 1000);
                }
            }
        }(xmlHttpRequest, i);
        xmlHttpRequest.open('GET', 'search?' + queryString + '&cachePrevent=' + encodeURIComponent(cachePrevent), true);
        xmlHttpRequest.send(null);
    }
}

function processResults(routes, results) {

    date = new Date(getDate());
    var nbrPassengers = getNbrPassengers();
    var timeOfDay = getTimeOfDay();

    var tickets = new Array();

    for (var i = 0; i < results.length; i++) {
        for (var j = 0; j < results[i].length; j++) {
            var result = results[i][j];
            var ticket = new Ticket(routes[i].operator, routes[i].startLocation, routes[i].endLocation, result.departTime, result.arriveTime, result.basePrice, result.price);
            if (!hasPassed(ticket.departTime, date, timeZones[ticket.startLocation.neighborhoodCode]) && inTimeFrame(ticket.departTime, timeOfDay))
                tickets.push(ticket);
        }
    }

    if (tickets.length === 0) {
        showBody();
        return;
    }

    for (var i = 0; i < tickets.length - 1; i++) {

        for (var j = 0; j < tickets.length - 1; j++) {

            var ticketj = tickets[j];
            var basePricej = toCents(ticketj.basePrice);
            var timej = toMilitaryTime(ticketj.departTime);

            var ticketjj = tickets[j + 1];
            var basePricejj = toCents(ticketjj.basePrice);
            var timejj = toMilitaryTime(ticketjj.departTime);

            if (timej > timejj) {
                var temp = tickets[j];
                tickets[j] = tickets[j + 1];
                tickets[j + 1] = temp;
            }
            else if (timej === timejj) {
                if (basePricej > basePricejj) {
                    var temp = tickets[j];
                    tickets[j] = tickets[j + 1];
                    tickets[j + 1] = temp;
                }
            }
        }
    }

    var tbody = document.getElementById('departureSort');
    while(tbody.hasChildNodes())
        tbody.removeChild(tbody.firstChild);

    for (var i = 0; i < tickets.length; i++) {

        appendTicketDom(tbody, tickets[i], date, nbrPassengers);
        if (i + 1 < tickets.length) {
            var row = document.createElement('tr');
            tbody.appendChild(row);
            var cell = document.createElement('td');
            cell.colSpan = '6';
            cell.innerHTML = '&nbsp;';
            row.appendChild(cell);
        }
    }

    for (var i = 0; i < tickets.length - 1; i++) {

        for (var j = 0; j < tickets.length - 1; j++) {

            var ticketj = tickets[j];
            var basePricej = toCents(ticketj.basePrice);
            var timej = toMilitaryTime(ticketj.departTime);

            var ticketjj = tickets[j + 1];
            var basePricejj = toCents(ticketjj.basePrice);
            var timejj = toMilitaryTime(ticketjj.departTime);

            if (basePricej > basePricejj) {
                var temp = tickets[j];
                tickets[j] = tickets[j + 1];
                tickets[j + 1] = temp;
            }
            else if (basePricej === basePricejj) {
                if (timej > timejj) {
                    var temp = tickets[j];
                    tickets[j] = tickets[j + 1];
                    tickets[j + 1] = temp;
                }
            }
        }
    }

    tbody = document.getElementById('basePriceSort');
    while(tbody.hasChildNodes())
        tbody.removeChild(tbody.firstChild);

    for (var i = 0; i < tickets.length; i++) {

        appendTicketDom(tbody, tickets[i], date, nbrPassengers);
        if (i + 1 < tickets.length) {
            var row = document.createElement('tr');
            tbody.appendChild(row);
            var cell = document.createElement('td');
            cell.colSpan = '6';
            cell.innerHTML = '&nbsp;';
            row.appendChild(cell);
        }
    }

    var cheapestTicketBasePrice = null;
    var cheapestWifiBasePrice = null;
    var cheapestPowerBasePrice = null;
    for (var i = 0; i < tickets.length; i++) {

        var ticket = tickets[i];

        if (cheapestTicketBasePrice === null || toCents(ticket.basePrice) < toCents(cheapestTicketBasePrice))
            cheapestTicketBasePrice = ticket.basePrice;
        if (ticket.operator.wifi)
            if (cheapestWifiBasePrice === null || toCents(ticket.basePrice) < toCents(cheapestWifiBasePrice))
                cheapestWifiBasePrice = ticket.basePrice;
        if (ticket.operator.power)
            if (cheapestPowerBasePrice === null || toCents(ticket.basePrice) < toCents(cheapestPowerBasePrice))
                cheapestPowerBasePrice = ticket.basePrice;
    }

    cheapestTicketBasePrice = cheapestTicketBasePrice.replace('.00', '');
    if (cheapestWifiBasePrice !== null)
        cheapestWifiBasePrice = cheapestWifiBasePrice.replace('.00', '');
    if (cheapestPowerBasePrice !== null)
        cheapestPowerBasePrice = cheapestPowerBasePrice.replace('.00', '');

    var innerHTML = '';
    innerHTML += '<table cellspacing="0" cellpadding="0" style="margin-left:auto; margin-right:auto; margin-bottom:15px; text-align:center;">';
    innerHTML += '<tbody>';
    innerHTML += '<tr>';
    innerHTML += '<td style="width:110px; height:90px; background-image:url(images/box.gif);"><img src="images/tickets.gif" alt="Bus Tickets" title="Bus Tickets" style="display:block; margin-left:auto; margin-right:auto;"/>Bus tickets<br/>from <span style="color:#505050;">' + escapeHtml(cheapestTicketBasePrice) + '</span></td>';
    if (cheapestWifiBasePrice !== null) {
        innerHTML += '<td style="width:10px;">&nbsp;</td>';
        innerHTML += '<td style="width:110px; height:90px; background-image:url(images/box.gif);"><img src="images/wifi.gif" alt="Free Wifi" title="Free Wifi" style="display:block; margin-left:auto; margin-right:auto;"/>Buses with<br/>free wifi<br/>from <span style="color:#505050;">' + escapeHtml(cheapestWifiBasePrice) + '</span></td>';
    }
    if (cheapestPowerBasePrice !== null) {
        innerHTML += '<td style="width:10px;">&nbsp;</td>';
        innerHTML += '<td style="width:110px; height:90px; background-image:url(images/box.gif);"><img src="images/power.gif" alt="Power Outlets" title="Power Outlets" style="display:block; margin-left:auto; margin-right:auto;"/>Buses with<br/>power outlets<br/>from <span style="color:#505050;">' + escapeHtml(cheapestPowerBasePrice) + '</span></td>';
    }
    innerHTML += '</tr>';
    innerHTML += '</tbody>'
    innerHTML += '</table>';
    document.getElementById('firstSection').innerHTML += innerHTML;

    showBody();
}

function appendTicketDom(tbody, ticket, date, nbrPassengers) {

    var departMilitary = toMilitaryTime(ticket.departTime);
    var arriveMilitary = toMilitaryTime(ticket.arriveTime);

    var timeZoneDifference = getTimeZoneOffset(timeZones[ticket.startLocation.neighborhoodCode], date) - getTimeZoneOffset(timeZones[ticket.endLocation.neighborhoodCode], date);
    timeZoneDifference = (timeZoneDifference < 0 ? -1 : 1) * ((Math.floor(Math.abs(timeZoneDifference) / 60) * 100) + (Math.abs(timeZoneDifference) % 60));
    arriveMilitary = addMilitary(arriveMilitary, -1 * timeZoneDifference);

    var timeDifference = addMilitary(arriveMilitary, -1 * departMilitary);
    var timeDifferenceString = '';
    if (timeDifference >= 100) {
        timeDifferenceString += Math.floor(timeDifference / 100).toString() + 'hr ';
        timeDifference = timeDifference % 100;
    }
    if (timeDifference > 0)
        timeDifferenceString += timeDifference.toString() + 'min ';

        // first row
    var tr = document.createElement('tr');
    tr.style.fontSize = '0px';
    tbody.appendChild(tr);
    var cell = document.createElement('td');
    tr.appendChild(cell);
    var image = document.createElement('img');
    image.src = 'images/topleft.gif';
    image.width = '15';
    image.height = '15';
    image.border = '0';
    image.style.display = 'block';
    cell.appendChild(image);
    cell = document.createElement('td');
    cell.style.minWidth = '75px';
    cell.style.borderTop = '1px solid #dddddd';
    cell.innerHTML = '&nbsp;';
    tr.appendChild(cell);
    cell = document.createElement('td');
    cell.style.borderTop = '1px solid #dddddd';
    cell.innerHTML = '&nbsp;';
    tr.appendChild(cell);
    cell = document.createElement('td');
    cell.style.borderTop = '1px solid #dddddd';
    cell.innerHTML = '&nbsp;';
    tr.appendChild(cell);
    cell = document.createElement('td');
    cell.style.borderTop = '1px solid #dddddd';
    cell.innerHTML = '&nbsp;';
    tr.appendChild(cell);
    cell = document.createElement('td');
    tr.appendChild(cell);
    image = document.createElement('img');
    image.src = 'images/topright.gif';
    image.width = '15';
    image.height = '15';
    image.border = '0';
    image.style.display = 'block';
    cell.appendChild(image);

        // second row
    tr = document.createElement('tr');
    tbody.appendChild(tr);
    cell = document.createElement('td');
    cell.style.borderLeft = '1px solid #dddddd';
    cell.innerHTML = '&nbsp;';
    tr.appendChild(cell);

    cell = document.createElement('td');
    cell.style.minWidth = '75px';
    cell.style.textAlign = 'center';
    tr.appendChild(cell);
    image = document.createElement('img');
    image.src = 'images/logos/' + encodeURIComponent(ticket.operator.logoURL);
    image.style.marginRight = 'auto';
    image.style.marginLeft = 'auto';
    image.style.verticalAlign = 'middle';
    image.style.display = 'block';
    image.style.marginBottom = '3px';
    cell.appendChild(image);
    var text = document.createTextNode(ticket.operator.name);
    cell.appendChild(text);
    var a; // begin comment on the next line to turn off yelp ratings
    if (ticket.operator.rating !== null) {

        if (ticket.operator.name === 'Megabus' && (timeZones[ticket.startLocation.neighborhoodCode] === CST || timeZones[ticket.endLocation.neighborhoodCode] === CST)) {
            ticket.operator.rating = '3.0';
            ticket.operator.yelpURL = 'http://www.yelp.com/biz/megabus-chicago';
        }
        else if (ticket.operator.name === 'Greyhound' && (timeZones[ticket.startLocation.neighborhoodCode] === CST || timeZones[ticket.endLocation.neighborhoodCode] === CST)) {
            ticket.operator.rating = '2.5';
            ticket.operator.yelpURL = 'http://www.yelp.com/biz/greyhound-bus-lines-chicago-3';
        }
        else if (ticket.operator.name === 'New Century' && (ticket.startLocation.neighborhoodCode === NEW_YORK_CHINATOWN || ticket.endLocation.neighborhoodCode === NEW_YORK_CHINATOWN)) {
            ticket.operator.rating = '3.0';
            ticket.operator.yelpURL = 'http://www.yelp.com/biz/new-century-travel-philadelphia';
        }
        a = document.createElement('a');
        a.href = ticket.operator.yelpURL;
        a.target = '_blank';
        cell.appendChild(a);
        image = document.createElement('img');
        image.src = 'images/ratings/' + encodeURIComponent(ticket.operator.rating) + '.png';
        image.title = ticket.operator.rating + ' star rating';
        image.style.marginRight = 'auto';
        image.style.marginLeft = 'auto';
        image.style.verticalAlign = 'middle';
        image.style.display = 'block';
        image.style.marginTop = '5px';
        image.style.border = '0';
        a.appendChild(image);
    } // end comment here

    cell = document.createElement('td');
    tr.appendChild(cell);
    var div = document.createElement('div');
    div.style.marginBottom = '5px';
    cell.appendChild(div);
    text = document.createTextNode(toDayString(date) + ' ' + toMonthString(date) + ' ' + date.getDate());
    div.appendChild(text);
    div = document.createElement('div');
    cell.appendChild(div);
    var b = document.createElement('b');
    div.appendChild(b);
    text = document.createTextNode(ticket.departTime);
    b.appendChild(text);
    text = document.createTextNode(' depart ');
    div.appendChild(text);
    a = document.createElement('a');
    a.href = ticket.startLocation.mapURL;
    a.target = '_blank';
    div.appendChild(a);
    text = document.createTextNode(ticket.startLocation.name);
    a.appendChild(text);
    div = document.createElement('div');
    cell.appendChild(div);
    b = document.createElement('b');
    div.appendChild(b);
    text = document.createTextNode(ticket.arriveTime);
    b.appendChild(text);
    text = document.createTextNode(' arrive ');
    div.appendChild(text);
    a = document.createElement('a');
    a.href = ticket.endLocation.mapURL;
    a.target = '_blank';
    div.appendChild(a);
    text = document.createTextNode(ticket.endLocation.name);
    a.appendChild(text);
    div = document.createElement('div');
    div.style.color = 'gray';
    div.style.marginTop = '5px';
    div.style.fontSize = '11px';
    cell.appendChild(div);
    text = document.createTextNode(timeDifferenceString + 'bus ride');
    div.appendChild(text);

    cell = document.createElement('td');
    tr.appendChild(cell);
    image = document.createElement('img');
    image.src = 'images/restroom.gif';
    image.alt = 'Restroom';
    image.title = 'Restroom';
    image.style.verticalAlign = 'middle';
    image.style.marginRight = '18px';
    if (!ticket.operator.restroom)
        image.style.visibility = 'hidden';
    cell.appendChild(image);
    image = document.createElement('img');
    image.src = 'images/wifi.gif';
    image.alt = 'Free Wifi';
    image.title = 'Free Wifi';
    image.style.verticalAlign = 'middle';
    image.style.marginRight = '15px';
    if (!ticket.operator.wifi)
        image.style.visibility = 'hidden';
    cell.appendChild(image);
    image = document.createElement('img');
    image.src = 'images/power.gif';
    image.alt = 'Power Outlets';
    image.title = 'Power Outlets';
    image.style.verticalAlign = 'middle';
    image.style.marginRight = '20px';
    if (!ticket.operator.power)
        image.style.visibility = 'hidden';
    cell.appendChild(image);

    cell = document.createElement('td');
    cell.style.textAlign = 'center';
    tr.appendChild(cell);
    div = document.createElement('div');
    div.style.marginBottom = '6px';
    div.style.color = 'gray';
    div.style.fontSize = '11px';
    div.style.lineHeight = '100%';
    cell.appendChild(div);
    text = document.createTextNode(nbrPassengers === 1 ? '1 ticket for' : nbrPassengers.toString() + ' tickets for');
    div.appendChild(text);
    div = document.createElement('div');
    div.style.fontSize = '20px';
    div.style.fontWeight = 'bold';
    div.style.lineHeight = '100%';
    cell.appendChild(div);
    text = document.createTextNode(ticket.basePrice);
    div.appendChild(text);
    div = document.createElement('div');
    div.style.marginBottom = '8px';
    div.style.fontSize = '11px';
    div.style.lineHeight = '100%';
    cell.appendChild(div);
    text = document.createTextNode(ticket.price + ' total');
    div.appendChild(text);
    image = document.createElement('img');
    image.src = 'images/purchase1.gif';
    image.style.marginLeft = 'auto';
    image.style.marginRight = 'auto';
    image.style.cursor = 'pointer';
    image.onclick = function() {
        if (ticket.operator.name === 'Greyhound') {
            if (!confirm('Greyhound charges an $18 ticketing fee on purchases in which the cardholder is not a passenger. Do you accept this fee?'))
                return;
            else {
                ticket.price = parseInt(ticket.price.replace(/\$|\./g, ''));
                ticket.price -= 0;
                ticket.price += 1800;
                ticket.price = ticket.price.toString();
                ticket.price = '$' + ticket.price.substring(0, ticket.price.length - 2) + '.' + ticket.price.substring(ticket.price.length - 2, ticket.price.length);
            }
        }
        var url = window.location.href;
        var queryString = url.substring(url.indexOf('?'));
        queryString += '&dateString=' + encodeURIComponent(((date.getMonth() + 1).toString().length < 2 ? '0' + (date.getMonth() + 1).toString() : (date.getMonth() + 1).toString()) + '/' + (date.getDate().toString().length < 2 ? '0' + date.getDate().toString() : date.getDate().toString()) + '/' + date.getFullYear().toString());
        queryString += '&operatorName=' + encodeURIComponent(ticket.operator.name) + '&operatorURL=' + encodeURIComponent(ticket.operator.url) + '&operatorLogoURL=' + encodeURIComponent(ticket.operator.logoURL);
        queryString += '&startLocationName=' + encodeURIComponent(ticket.startLocation.name) + '&startLocationMapURL=' + encodeURIComponent(ticket.startLocation.mapURL) + '&startLocationNeighborhoodCode=' + encodeURIComponent(ticket.startLocation.neighborhoodCode);
        queryString += '&endLocationName=' + encodeURIComponent(ticket.endLocation.name) + '&endLocationMapURL=' + encodeURIComponent(ticket.endLocation.mapURL) + '&endLocationNeighborhoodCode=' + encodeURIComponent(ticket.endLocation.neighborhoodCode);
        queryString += '&departTime=' + encodeURIComponent(ticket.departTime);
        queryString += '&arriveTime=' + encodeURIComponent(ticket.arriveTime);
        queryString += '&basePrice=' + encodeURIComponent(ticket.basePrice);
        queryString += '&price=' + encodeURIComponent(ticket.price);
        window.location.href = 'purchase.html' + queryString;
    }
    cell.appendChild(image);

    cell = document.createElement('td');
    cell.style.borderRight = '1px solid #dddddd';
    cell.innerHTML = '&nbsp;';
    tr.appendChild(cell);

        // third row
    tr = document.createElement('tr');
    tr.style.fontSize = '0px';
    tbody.appendChild(tr);
    cell = document.createElement('td');
    cell.style.verticalAlign = 'bottom';
    tr.appendChild(cell);
    image = document.createElement('img');
    image.src = 'images/bottomleft.gif';
    image.width = '15';
    image.height = '15';
    image.border = '0';
    image.style.display = 'block';
    cell.appendChild(image);
    cell = document.createElement('td');
    cell.style.minWidth = '75px';
    cell.style.borderBottom = '1px solid #dddddd';
    cell.innerHTML = '&nbsp;';
    tr.appendChild(cell);
    cell = document.createElement('td');
    cell.style.borderBottom = '1px solid #dddddd';
    cell.innerHTML = '&nbsp;';
    tr.appendChild(cell);
    cell = document.createElement('td');
    cell.style.borderBottom = '1px solid #dddddd';
    cell.innerHTML = '&nbsp;';
    tr.appendChild(cell);
    cell = document.createElement('td');
    cell.style.borderBottom = '1px solid #dddddd';
    cell.innerHTML = '&nbsp;';
    tr.appendChild(cell);
    cell = document.createElement('td');
    cell.style.verticalAlign = 'bottom';
    tr.appendChild(cell);
    image = document.createElement('img');
    image.src = 'images/bottomright.gif';
    image.width = '15';
    image.height = '15';
    image.border = '0';
    image.style.display = 'block';
    cell.appendChild(image);

/*    innerHTML += '<tr style="font-size:0px;"><td><img src="images/topleft.gif" width="15" height="15" border="0" style="display:block;"/></td><td style="border-top:1px solid #dddddd;">&nbsp;</td><td style="border-top:1px solid #dddddd;">&nbsp;</td><td style="border-top:1px solid #dddddd;">&nbsp;</td><td style="border-top:1px solid #dddddd;">&nbsp;</td><td><img src="images/topright.gif" width="15" height="15" border="0" style="display:block;"/></td></tr>';
    innerHTML += '<tr>';
    innerHTML += '<td style="border-left:1px solid #dddddd;">&nbsp;</td>';
    innerHTML += '<td style="text-align:center;"><img src="images/logos/' + encodeURIComponent(ticket.operator.logoURL) + '" style="margin-right:auto; margin-left:auto; vertical-align:middle; display:block; margin-bottom:3px;"/>' + escapeHtml(ticket.operator.name) + '</td>';
    innerHTML += '<td><div style="margin-bottom:5px;">' + escapeHtml(toMonthString(date) + ' ' + date.getDate()) + '</div><div><b>' + escapeHtml(ticket.departTime) + '</b> depart <a href="' + ticket.startLocation.mapURL + '" target="_blank">' + escapeHtml(ticket.startLocation.name) + '</a></div><div><b>' + escapeHtml(ticket.arriveTime) + '</b> arrive <a href="' + ticket.endLocation.mapURL + '" target="_blank">' + escapeHtml(ticket.endLocation.name) + '</a></div><div style="color:gray; margin-top:5px; font-size:11px;">' + escapeHtml(timeDifferenceString) + 'bus ride</div></td>';
    innerHTML += '<td><img src="images/wifi.gif" alt="Wifi" title="Wifi" style="vertical-align:middle; margin-right:10px;' + (ticket.operator.wifi ? '' : escapeHtml(' visibility:hidden;')) + '"/><img src="images/power.gif" alt="Power" title="Power" style="vertical-align:middle; margin-right:10px;' + (ticket.operator.power ? '' : escapeHtml(' visibility:hidden;')) + '"/><img src="images/tv.gif" alt="TV" title="TV" style="vertical-align:middle;' + (ticket.operator.tv ? '' : escapeHtml(' visibility:hidden;')) + '"/></td>';
    innerHTML += '<td style="text-align:center;"><div style="color:gray; font-size:11px;">' + (nbrPassengers === 1 ? escapeHtml('1 ticket for') : escapeHtml(nbrPassengers.toString() + ' tickets for')) + '</div><div style="font-size:24px; font-weight:bold;">' + escapeHtml(ticket.basePrice) + '</div><img src="images/purchase1.gif" style="margin-left:auto; margin-right:auto; cursor:pointer;"/></td>';
    innerHTML += '<td style="border-right:1px solid #dddddd;">&nbsp;</td>';
    innerHTML += '</tr>';
    innerHTML += '<tr style="font-size:0px;"><td style="vertical-align:bottom;"><img src="images/bottomleft.gif" width="15" height="15" border="0" style="display:block;"/></td><td style="border-bottom:1px solid #dddddd;">&nbsp;</td><td style="border-bottom:1px solid #dddddd;">&nbsp;</td><td style="border-bottom:1px solid #dddddd;">&nbsp;</td><td style="border-bottom:1px solid #dddddd;">&nbsp;</td><td style="vertical-align:bottom;"><img src="images/bottomright.gif" width="15" height="15" border="0" style="display:block;"/></td></tr>';
*/
}

function showBody() {

    document.getElementById('processingDiv').style.display = 'none';
    document.getElementById('body').style.display = 'block';
}

function changeSort(select) {

    var departureSortNode = document.getElementById('departureSort');
    var departureSortParent = departureSortNode.parentNode;
    var departureSortSibling = departureSortNode.nextSibling;

    var basePriceSortNode = document.getElementById('basePriceSort');
    var basePriceSortParent = basePriceSortNode.parentNode;
    var basePriceSortSibling = basePriceSortNode.nextSibling;

    departureSortParent.removeChild(departureSortNode);
    basePriceSortParent.removeChild(basePriceSortNode);

    departureSortParent.insertBefore(basePriceSortNode, departureSortSibling);
    basePriceSortParent.insertBefore(departureSortNode, basePriceSortSibling);

    document.getElementById('sortBy1').options[select.selectedIndex].selected = true;
    document.getElementById('sortBy2').options[select.selectedIndex].selected = true;
}

function getOrigin() {

    var originNeighborhoodCodes = getParameter('origin');
    originNeighborhoodCodes = originNeighborhoodCodes.split(',');
    for (var i = 0; i < originNeighborhoodCodes.length; i++)
        originNeighborhoodCodes[i] = parseInt(originNeighborhoodCodes[i]);

    return originNeighborhoodCodes;
}

function getDestination() {

    var destinationNeighborhoodCodes = getParameter('destination');
    destinationNeighborhoodCodes = destinationNeighborhoodCodes.split(',');
    for (var i = 0; i < destinationNeighborhoodCodes.length; i++)
        destinationNeighborhoodCodes[i] = parseInt(destinationNeighborhoodCodes[i]);

    return destinationNeighborhoodCodes;
}

function getDate() {

    var date = getParameter('date');
    date = parseInt(date);
    return date;
}

function getTimeOfDay() {

    var timeOfDay = getParameter('timeOfDay');
    return timeOfDay;
}

function getNbrPassengers() {

    var nbrPassengers = getParameter('nbrPassengers');
    nbrPassengers = parseInt(nbrPassengers);
    return nbrPassengers;
}


