//<![CDATA[
var CallMap = false;
function loadDealerMapResults(glat, glong) {
  if (document.getElementById("dlrMap").style.display == 'none') {
    document.getElementById("ViewMap").className = "current";
    document.getElementById("dlrMap").style.display = 'block';
    document.getElementById("MapForm").style.display = 'block';
  } else {
    document.getElementById("ViewMap").className = "";
    document.getElementById("dlrMap").style.display = 'none';
    document.getElementById("MapForm").style.display = 'none';
  }
  if (!CallMap) {
    CallMap = true;
    loadDealerMap(glat, glong);
  }
}
function loadMultiDealerMapResults(glat, glong, id) {
  if (document.getElementById("dlrMap"+id).style.display == 'none') {
    document.getElementById("ViewMap"+id).className = "current";
    document.getElementById("dlrMap"+id).style.display = 'block';
    document.getElementById("MapForm"+id).style.display = 'block';
  } else {
    document.getElementById("ViewMap"+id).className = "";
    document.getElementById("dlrMap"+id).style.display = 'none';
    document.getElementById("MapForm"+id).style.display = 'none';
  }
  if (!CallMap) {
    CallMap = true;
    loadMultiDealerMap(glat, glong, id);
  }
}
function loadDoubleDealerMapResults(glat, glong, id) {
  if (id == '1') {
    document.getElementById("dlrMap2").style.display = 'none';
    document.getElementById("MapForm2").style.display = 'none';
    document.getElementById("ViewMap2").className = "";
  }
  else {
    document.getElementById("dlrMap1").style.display = 'none';
    document.getElementById("MapForm1").style.display = 'none';
    document.getElementById("ViewMap1").className = "";
  }

  if (document.getElementById("dlrMap"+id).style.display == 'none') {
    document.getElementById("ViewMap"+id).className = "current";
    document.getElementById("dlrMap"+id).style.display = 'block';
    document.getElementById("MapForm"+id).style.display = 'block';
  } else {
    document.getElementById("ViewMap"+id).className = "";
    document.getElementById("dlrMap"+id).style.display = 'none';
    document.getElementById("MapForm"+id).style.display = 'none';
  }
    CallMap = true;
    loadMultiDealerMap(glat, glong, id);
  
}
function createMarker(point,html) {
  var marker = new GMarker(point);

  GEvent.addListener(marker, "click", function() {
    marker.openInfoWindowHtml(html);
  });
  return marker;
}

function loadDealerMap(glat, glong) {
  var map_options =
  {
    zoom: 13,
    center: new google.maps.LatLng(glat, glong),
    mapTypeId: google.maps.MapTypeId.ROADMAP
  }
  var map = new google.maps.Map(document.getElementById("dlrMap"), map_options);
  var point = new google.maps.LatLng(glat, glong);
  var marker = new google.maps.Marker(
  {
    position: point,
    map: map
  });

}
function loadDealerExpMap(glat, glong,dealer,string,postcode) {
  var string = Base64.decode(string);

  var map_options =
  {
    zoom: 13,
    center: new google.maps.LatLng(glat, glong),
    mapTypeId: google.maps.MapTypeId.ROADMAP
  }
  var map = new google.maps.Map(document.getElementById("dlrMap"), map_options);
  var point = new google.maps.LatLng(glat, glong);
  var marker = new google.maps.Marker(
  {
    position: point,
    map: map
  });
  var html = '<b>'+dealer+'</b><br /><br />'+string+'<br />'+postcode+'<br />'+
			      '<form method="GET" action="http://maps.google.com/maps" target="_blank" style="padding:0;background:none">'+
   		              'Start Address&nbsp;&nbsp;&nbsp;<input name="saddr" value="" style="width: 9em;">'+
		              '&nbsp;&nbsp;&nbsp;'+
		              '<input value="Get Directions" type="submit">'+
		              '<input name="daddr" value="'+postcode+'" type="hidden">'+
		              '<input name="hl" value="en" type="hidden">'+
		              '</form>';  
  var infowindow = new google.maps.InfoWindow(
  {
    content: html
  });

  infowindow.open(map, marker);
}

function loadMultiDealerMap(glat, glong, id) {
  var map_options =
  {
    zoom: 13,
    center: new google.maps.LatLng(glat, glong),
    mapTypeId: google.maps.MapTypeId.ROADMAP
  }
  var map = new google.maps.Map(document.getElementById("dlrMap"+id), map_options);
  var point = new google.maps.LatLng(glat, glong);
  var marker = new google.maps.Marker(
  {
    position: point,
    map: map
  });
}
//]]>
