MarkerFields = {
    'Location' : {
        'customInsert' : function( record, id ) {
            var html;
            html = '<div class="MMinfoboxaddress">';
            html += '<img style="margin-bottom: 10px;" src="i/slablogo.png" />';
            html += '<div><span class="MMrecordName">' + record['name'].toLowerCase() + '</span><br />';
            html += record['street'] + '<br />' + record['town'] + '<br />' + record['pc'] + '<br /><br /><span class="tel"><strong>Phone:</strong> ' + record.telephone + '</span>';
            html += '<br /><span class="tel"><strong>Web:</strong> <a href="http://' + record['url'].toLowerCase() + '" target="_blank">' + record['url'] + '</a></span>';
            html += '<br /><span class="tel"><strong>Email:</strong> <a href="mailto:' + record['email'].toLowerCase() + '">' + record['email'] + '</span></div>';
            html += '<div class="links">';
            html += '<a href="#" onclick="ZoomToLocation( ' + ( id - (Page.storeSearch.iIndex - 1) - 1 ) + ' ); return false;">Go to this location</a>';
            html += '<a href="#" onclick="GetDirectionsFromInfoBox( this, ' + ( id - 1  ) + ' ); return false;">Get directions</a>';
            html += '<form class="directions" action="" method="post" style="display: none">';
            html += '<label for="infoboxDir' + id + '">';
            html += '<font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>From - insert your postcode or town</strong></font><br/>';
            html += '<input class="text" type="text" value="" id="infoboxDir' + id + '" />';
            html += '</label>';
            html += '<input type="submit" id="searchButton" value="Search" />';
            html += '</form>';
            html += '<a href="#" onclick="CreateMobileIframe( ' + record.id + ' ); return false;">Send to mobile</a>';
            html += '</div>';
            html += '</div>';
            return html;
        }
    },
    'Cases' : {
        'customInsert' : function() {
            var record = arguments[0];
            html = '<span class="tel"><strong>Case Types:</strong><br/>';
            if (record.criminal == 'Yes') html += 'Criminal<br/>';
            if (record.childrens == 'Yes') html += 'Children\'s hearings and appeals<br/>';
            if (record.civil == 'Yes') html += 'Civil<br/><br/>';
            html += '<strong>Civil Case Types:</strong><br/>';
            if (record.benefitstaxcredits == 'Yes') html += 'Benefits and tax credits<br/>';
            if (record.compensation == 'Yes') html += 'Compensation and damages<br/>';
            if (record.complaints == 'Yes') html += 'Complaints against professions<br/>';
            if (record.consumer == 'Yes') html += 'Consumer problems<br/>';
            if (record.death == 'Yes') html += 'Death related matters<br/>';
            if (record.debt == 'Yes') html += 'Debt, money and tax<br/>';
            if (record.discrimination == 'Yes') html += 'Discrimination & human rights<br/>';
            if (record.education == 'Yes') html += 'Education<br/>';
            if (record.employment == 'Yes') html += 'Employment<br/>';
            if (record.family1 == 'Yes') html += 'Family - divorce & separation<br/>';
            if (record.family2 == 'Yes') html += 'Family - contact & children<br/>';
            if (record.family3 == 'Yes') html += 'Family - domestic violence<br/>';
            if (record.housing == 'Yes') html += 'Housing & homelessness<br/>';
            if (record.immigration == 'Yes') html += 'Immigration, asylum & nationality<br/>';
            if (record.medical == 'Yes') html += 'Medical negligence<br/>';
            if (record.mental == 'Yes') html += 'Mental health & adults with incapacity<br/>';
            html += '</span>';
            if (record.specialisms) html += '<br/><strong>Specialisms:</strong><br/>' + record.specialisms;
            return html;
        }
    },
    'Hours' : {
        'customInsert' : function() {
            var record = arguments[0];
            html = '<span class="tel"><strong>Opening Times:</strong><br/><br/>';
            if (record.opening1) html += 'Weekdays: ' + record.opening1 + '<br/>';
            if (record.opening2) html += record.opening2 + '<br/>';
            html += '</span>';
            return html;
        }
    },
    'Access' : {
        'customInsert' : function() {
            var record = arguments[0];
            html = '<span class="tel"><strong>Accessibility Details:</strong><br/><br/>';
            if (record.accessibility == 'y' || record.accessibility == 'yes' || record.accessibility == 'Y' || record.accessibility == 'YES') html += 'Office is accessible to people with disabilities<br/><br/>';
            if (record.accessibilityinfo) html += record.accessibilityinfo + '<br/>';
            html += '</span>';
            return html;
        }
    }
}

HtmlFields = {
    'street' : { 'element' : 'span', 'fieldname' : 'street' },
    'town' : { 'element' : 'span', 'fieldname' : 'town' },
    'postcode' : { 'element' : 'span', 'fieldname' : 'pc' },
    'phone' : { 'element' : 'span', 'fieldname' : 'telephone' },
    'customInsert' : function() {
        return '<div class="MMresultid"><span class="MMresultidspan">' + arguments[1] + '</span>' + '<p class="MMresultname">' + arguments[2] + '</p></div>';
    },
    'customOnclick' : function( id ) {
        var record, marker;
        record = Callbacks.records[id - (Page.storeSearch.iIndex - 1)];
        marker = Callbacks.markers[id - (Page.storeSearch.iIndex - 1)];
        marker.openInfoBox();
        UpdateRouting( id - (Page.storeSearch.iIndex - 1) );
    },
    'addOnClick' : true
}

RoutingFields = {
    'customInsert' : function( step, id ) {
        var road, instruction, element, marker;
        if ( step.road_name && step.road_number ) {
            road = ' ' + step.road_name + ' ( ' + step.road_number + ' ) ';
        } else if ( step.road_name ) {
            road = ' ' + step.road_name + ' ';
        } else if ( step.road_number ) {
            road = ' ' + step.road_number + ' ';
        }
        element = '<span><strong>' + id + '.&nbsp;</strong>' + step.instruction;
        if ( road ) {
            element += road + 'for <strong>' + step.distance.miles + '</strong> miles</span>';
        } else {
            element += '</span>';
        }
        var icon = MM_DEFAULT_ICON.copy();
        icon.cssClass = 'MMMarker MMRouteMarker';
        marker = Page.map.createMarker( step.start_point, { text: id, icon: icon } );
        marker.setInfoBoxContent( element );
        routeMarkers.push( marker );
        return element;
    },
    'addOnClick' : true,
    'customOnclick' : function( id ) {
        window.routeMarkers[id].openInfoBox();
    }
}

UpdateRouting = function( id ) {
    var name, todirections = document.getElementById( 'directions_to' ), point;
    point = Callbacks.records[id].point;
    name = Callbacks.records[id].name.toLowerCase();
    todirections.value = name;
    todirections.point = point;
    var fromlocation = document.getElementById( 'locationsearch' );
    var fromdirections = document.getElementById( 'directions_from' );
    fromdirections.value = fromlocation.value;
}
GetDirectionsFromInfoBox = function( o, id ) {
    var form = o.parentNode.getElementsByTagName( 'form' )[0];
    if ( form.style.display == 'none' ) {
        form.style.display = 'block';
        var infoboxDir = 'infoboxDir' + (id + 1);
        var fromlocation = document.getElementById( 'locationsearch' );
        var infoboxfrom = document.getElementById( infoboxDir );
        infoboxfrom.value = fromlocation.value;
        var directions_from = document.getElementById( 'directions_from' );
        form.onsubmit = function() {
            directions_from.value = this.getElementsByTagName( 'input' )[0].value;
            directions_from.form.onsubmit();
            return false;
        }
    } else {
        form.style.display = 'none';
        form.onsubmit = function() {
            return false;
        }
    }
}

ZoomToLocation = function( id ) {
    Page.map.goToPosition( new MMLocation( Callbacks.records[id].point, 17 ) );
}

CreateMobileIframe = function( id ) {
    var iframe, link, div = document.createElement( 'div' );
    link = 'http://clients.multimap.com/clients/content.cgi?client=scotaid_mob_en&page=mm2m_submit&url=';
    link += escape( 'http://clients.multimap.com/clients/browse.cgi?client=scotaid_mob_en&f_id=' + id );
    iframe = '<iframe src="' + link + '" class="MMmobileIframe" frameborder="0" width="100%" height="100%"></iframe>';
    div.innerHTML = iframe;
    return DisamHandler.populateDisam( div );
}
