<!-- //<![CDATA[var mapviewer, searcher, loading, markers, search, pre_search;var order_by_fields, order_by_order, return_fields, submitbtn;var funcRef = resultsLoaded;// Including the 'client_id' ensures that clicking on a result logs it as such within the reports:var rfs = ['client_id', 'name', 'street', 'town','pc', 'lat', 'lon'];function onLoad() {    mapviewer = new MultimapViewer( document.getElementById( 'mapviewer' ) );  mapviewer.goToPosition( new MMLocation( new MMLatLon( 54.400, -2.800 ),6) );    		    // Add an Event Handler to show info boxes when the markers are clicked    //mapviewer.addEventHandler( 'click', defaultClick );    order_by_fields = document.getElementById( 'order_by_fields' );      order_by_order = document.getElementById( 'order_by_order' );      submitbtn = document.getElementById( 'submitbtn' );     loading = document.getElementById( 'loading' );    loadingStatus( false );}function openInfoBox( type, target) {    if( target.infoBoxOpened() ) {        target.closeInfoBox();    }    else {        target.openInfoBox( );    }}function loadingStatus ( bool ) {    // If we're loading values we want to disable the form elements    // and display a spinning icon to show activity    order_by_fields.disabled = bool;      order_by_order.disabled = bool;      submitbtn.disabled = bool;    loading.style.display = bool ? 'block' : 'none';}function createMarker(location, display_name, num) {    // Creates marker    var marker = mapviewer.createMarker(location, {'text' : num});    marker.setInfoBoxContent('<p>' + display_name + '<' + '/p>');    return marker;}  function initSearch () {    cleanUp();    searcher = new MMSearchRequester( funcRef );    search = new MMSearch();     search.return_fields = rfs;    search.radius_units = 'miles';    search.route_modes  = 'walking,driving';     search.address = new MMAddress({ qs : 'EC4A 2DY' });// Activate the next line of code if you wish to configure the API to use data// from one of your existing 'classic' Multimap services (such as XML Storefinder), // as described in the topic "Integration with Classic Multimap XML Products".  // When doing so, please replace "[api_key]" with the appropriate service client name:// search.data_source = 'mm.clients.[api_key]'          search.order_by_fields = order_by_fields.value;    search.order_by_order = order_by_order.value;            loadingStatus( true );    searcher.search( search );}  function cleanUp () {    // Clean up the HTML containers    var message = document.getElementById('message');    while (message.firstChild) {        message.removeChild(message.firstChild);    }    message.style.display = 'none';    var record_list = document.getElementById('recordListDiv');    while (record_list.firstChild) {        record_list.removeChild(record_list.firstChild);    }                mapviewer.removeAllOverlays();      markers = new Array(); }        function resultsLoaded ( ) {    // Process search results    var container = document.getElementById('recordListDiv');    loadingStatus( false );    if ( searcher.error_code ) {        var err =  '';        if ( searcher.error_explanation ) {            err =  searcher.error_explanation;        } else {            err =  'Your request failed. Error code: ' + searcher.error_code;        }        alert( err );        return;    }     var results_returned = 1;        //  Create table and table header         var el = document.createElement ( 'table' );    el.id = 'recordList';    var tbody = document.createElement ( 'tbody' );    el.appendChild ( tbody );         var  start_index_value = 1;    if  (search.start_index && Number (search.start_index) > 0 ) {        start_index_value = Number (search.start_index);    }      var tr_first = document.createElement ( 'tr' );    var ths = [         document.createTextNode ( '#' ),          document.createTextNode ( 'Result' ),         document.createTextNode ( 'Straight line distance (km/mi)' ),         document.createTextNode ( 'Driving distance (km/mi)' ),         document.createTextNode ( 'Driving duration (dd:hh:mm)' ),         document.createTextNode ( 'Walking distance (km/mi)' ),         document.createTextNode ( 'Walking duration (dd:hh:mm)' )    ];     for ( i  = 0; i < ths.length; i++) {        var th = document.createElement ( 'th' );         th.appendChild( ths [ i ] );        tr_first.appendChild ( th );    }     tbody.appendChild ( tr_first );         // for each record set    for ( var count=0, l = searcher.record_sets.length; count < l; count++ ) {                // for each record        if ( searcher.record_sets[count].error ) {            var err =  '';            if ( searcher.record_sets[count].error.error_explanation ) {                err =  searcher.record_sets[count].error.error_explanation;            } else {                err =  'Your request failed. Error code: ' + searcher.record_sets[count].error.error_code;            }            alert( err );            return;          }         if ( searcher.record_sets[count].records ) {                       for (var record_count = 0, rl = searcher.record_sets[count].records.length; record_count < rl; record_count++ ) {                var record = searcher.record_sets[count].records[record_count];                                  var tr = handleRecord(record, start_index_value + record_count);                 tbody.appendChild ( tr );            }                    } else {                    var total = searcher.record_sets[count].totalRecordCount;             el = document.createElement ('p');            if ( total  > 0) {                el.appendChild ( document.createTextNode( 'Total results found: ' + total ) );            } else {                el.appendChild ( document.createTextNode( 'No results returned' ) );             }              results_returned = 0;        }            }    container.appendChild( el );                        if ( results_returned == 1 ) {        mapviewer.goToPosition ( mapviewer.getAutoScaleLocation( markers ) );      }          }function handleRecord ( record, num ) {    // Handle single record from search result set    var marker_text = '<h1>Result #' + num + '<' + '/h1>';        marker_text += '<p>';      for ( i = 0, j=0; i < rfs.length; i++ ) {        if ( record[rfs[i]] ) {            if ( j > 0) marker_text += ', ';            marker_text += record[rfs[i]];            j++;        }    }    marker_text += '<' + '/p>';        var distance = '';      if ( record.distance ) {        distance = 'Straight line distance (km/mi): ' + record.distance.km + '/' + record.distance.miles;        marker_text += '<p>' + distance.replace(/ /g, ' ') + '<' + '/p>';    }        var driving_distance = '';      if ( record.driving_distance ) {        driving_distance =  'Driving distance (km/mi), duration (dd:hh:mm) : ' + record.driving_distance.km + '/' + record.driving_distance.miles ;        driving_distance += ', ' + formatInt ( record.driving_duration.days, 2) + ':'+ formatInt ( record.driving_duration.hours, 2)  + ':'+ formatInt ( record.driving_duration.minutes, 2);        marker_text += '<p>' + driving_distance.replace(/ /g, ' ') + '<' + '/p>';    }    var walking_distance = '';      if ( record.walking_distance ) {        walking_distance =  'Walking distance (km/mi), duration (dd:hh:mm) : ' + record.walking_distance.km + '/' + record.walking_distance.miles;        walking_distance += ', ' + formatInt ( record.walking_duration.days, 2) + ':'+ formatInt ( record.walking_duration.hours, 2)  + ':'+ formatInt ( record.walking_duration.minutes, 2);        marker_text += '<p>' + walking_distance.replace(/ /g, ' ') + '<' + '/p>';    }        if ( record.point ) {        var marker = createMarker( record.point, marker_text, num);        markers.push(marker);    }         var anchor = document.createElement ( 'a' );    anchor.href = '#';    anchor.record_id = record.id;    anchor.appendChild(document.createTextNode ( record.name ));    anchor.onclick = function () { openInfoBox ( 'click', marker ); return false; };       var tr = document.createElement ( 'tr' );    var tds = [         document.createTextNode ( num ),          anchor,           document.createTextNode ( record.distance.km  + '/'+ record.distance.miles ),           document.createTextNode ( record.driving_distance.km  + '/'+ record.driving_distance.miles ),          document.createTextNode ( formatInt ( record.driving_duration.days, 2) + ':'+ formatInt ( record.driving_duration.hours, 2)  + ':'+ formatInt ( record.driving_duration.minutes, 2)  ),           document.createTextNode ( record.walking_distance.km  + '/'+ record.walking_distance.miles ),          document.createTextNode ( formatInt ( record.walking_duration.days, 2)  + ':'+ formatInt ( record.walking_duration.hours, 2)  + ':'+ formatInt ( record.walking_duration.minutes, 2)  )    ];     for ( i  = 0; i < tds.length; i++) {        var td = document.createElement ( 'td' );         td.appendChild( tds [ i ] );        tr.appendChild ( td );    }     return tr;}function formatInt ( num, min_width ) {   // Format Integer to specified width (adding leading zeros)   var str = num.toString ();   while ( str.length < min_width ) {        str = '0' + str;   }    return str;}  MMAttachEvent( window, 'load', onLoad );//]]> // -->