MarkerFields = {
    'Location' : {
        'customInsert' : function( record, id ) {
            var html;
            html = '<div class="MMinfoboxaddress">';
            html += '<img  src="/i/elogo.png" style="float:left;margin:0 1em 1em 0"/>';
              if (Callbacks.start) {
        				html += '<div ><span  class="MMrecordName" >' + record['companyname'] + '<br /></span><br clear="left"/>';
              }			 else {	
         				html += '<div ><span  class="MMrecordName" >' + record['companyname'] + '<br /><span style="font-weight:normal">('+record['distance'].miles+' miles away)</span></span><br clear="left"/>'; 
            }
         			if (record['address1']) {
            	html += record['address1'] + '<br />';
          	}            
            if (record['address2']) {
            	html += record['address2'] + '<br />';
          	}
           	if (record['town']) {
            	html += record['town'] + '<br />';
          	}
            html += record['pc'] + '<br /><br /><span class="tel"><strong>Phone:</strong> ' + record.telephone + '</span><br />';
            if (record['fax']) {
           	 html += '<span class="fax"><strong>Fax:</strong> ' + record['fax'] + '</span><br />';
          	}
            if (record['email']) {
           	 html += '<span class="email"><strong>E-mail:</strong><a href="mailto:'+record['email']+'" title="Mail us">Click to E-Mail</a></span><br />';
          	}     
            if (record['web']) {     
            	html += '<span class="web"><strong>Web:</strong><a href="http://' + record['web'] + '" title="Visit our Web Site"  target="_blank" >Click to Visit Website</a></span><br />';
  					}

           	html += '<div class="links">';
           	html += '<a href="#" onclick="GetDirectionsFromInfoBox( this, ' + ( id - 1 ) + ' ); return false;">Get Driving Directions</a>';
      
            html += '<form class="directions" action="" method="post" style="display: none">';
            html += '<label for="infoboxDir2' + id + '">';
           	html += 'From ';
            html += ' <input class="text" type="text" value="" id="infoboxDir2' + id + '" />';
            html += '</label>';
            html += '<input type="image" src="/i/go_button.png" class="submit" />';
            html += '</form>';
            if (record['companyname']) {
            	record['companyname_clean'] = record['companyname'].replace(" ","_");
            	record['companyname_clean'] = escape(record['companyname_clean']);      
         	   html += '<a href="/ecu-remapping-evolutionchips-installers/?'+record['companyname_clean']+'.htm" class="gotoloc">View more details >></a>';
          }
            html += '</div>';
            html += '</div>';
            return html;
        }
    }
}
MarkerFields2 = {
    'Location' : {
        'customInsert' : function( record, id ) {
            var html;
            html = '<div class="MMinfoboxaddress">';
            html += '<img  src="/i/elogo.png" />';
            html += '<div><span class="MMrecordName">' + record['companyname'] + '</span><br />';
    
          	if (record['address1']) {
            	html += record['address1'] + '<br />';
          	}            
            if (record['address2']) {
            	html += record['address2'] + '<br />';
          	}
           	if (record['town']) {
            	html += record['town'] + '<br />';
          	}
            html += record['pc'] + '<br /><br /><span class="tel"><strong>Phone:</strong> ' + record.telephone + '</span><br />';
   
          	
          	
           if (record['fax']) {
           	 html += '<span class="fax"><strong>Fax:</strong> ' + record['fax'] + '</span><br />';
          	}
            if (record['email']) {
           	 html += '<span class="email"><strong>E-mail:</strong><a href="mailto:'+record['email']+'" title="Mail us">Click to E-Mail</a></span><br />';
          	}     
            if (record['web']) {     
            	html += '<span class="web"><strong>Web:</strong><a target="_blank" href=\'http://' + record['web'] + '\'" title="Visit our Web Site"  target="_blank" >Click to Visit Website</a></span><br />';
  					}
  	
           	html += '<div class="links">';
           	html += '<a href="#" onclick="GetDirectionsFromInfoBox( this, ' + ( id - 1 ) + ' ); return false;">Get Driving Directions</a>';
      
            html += '<form class="directions" action="" method="post" style="display: none">';
            html += '<label for="infoboxDir' + id + '">';
           	html += 'From ';
            html += ' <input class="text" type="text" value="" id="infoboxDir' + id + '" />';
            html += '</label>';
            html += '<input type="image" src="/i/go_button.png" class="submit" />';
            html += '</form>';
           html += '</div>';
            html += '</div>';
            return html;
        }
    }
}
HtmlFields = {
    'name' : { 'element' : 'div', 'fieldname' : 'companyname' },
    'address1' : { 'element' : 'span', 'fieldname' : 'address1' },
    'address2' : { 'element' : 'span', 'fieldname' : 'address2' },
    'town' : { 'element' : 'span', 'fieldname' : 'town' },
    'postcode' : { 'element' : 'span', 'fieldname' : 'pc' },
    'Email' : { 'element' : 'span', 'fieldname' : 'email' },
    'Web' : { 'element' : 'span', 'fieldname' : 'web' },
    'phone' : { 'element' : 'span', 'fieldname' : 'telephone' },
    'fax' : { 'element' : 'span', 'fieldname' : 'fax' },
    'customInsert' : function() {
        return '<div class="MMresultid"><span class="MMresultidspan">' + arguments[1] + '</span></div>';
    },
    'customInsert2' : function() {
        return '<span class="MMresultdist">' + arguments[0]['distance'].miles + 'miles away</span>';
    },
     'emailInsert' : function() {
        return '<span class="MMresultemail"><strong>E-mail:</strong><a class="straight" href="mailto:' + arguments[0]['email'] + '">mail</a></span>';
    },  
     'nameInsert' : function() {
        return '<span class="MMresultcompanyname">' + arguments[0]['companyname'] + '</span>';
    }, 
    'linkInsert' : function() {
        return '<span class="MMresultlink"><strong>Web:</strong><a class="straight" href="http://' + arguments[0]['web'] + '"  target="_blank" >link</a></span><br clear="left"/>';
    },  

    'customOnclick' : function( id ) {
        var record, marker;
        record = Callbacks.records[id];
        marker = Callbacks.markers[id];
        marker.openInfoBox();
        UpdateRouting( id );
    },
    '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].companyname.toLowerCase();
    todirections.value = name;
    todirections.point = point;
}

GetDirectionsFromInfoBox = function( o, id ) {
    var form = o.parentNode.getElementsByTagName( 'form' )[0];
    if ( form.style.display == 'none' ) {
        form.style.display = 'block';
        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 ) );
}


