  var directionsService = new google.maps.DirectionsService();
 var map;var adUnit ;
 var xaddress;
 google.load('search', '1');
var tax = [
  ['浦和',35.861787, 139.647217,1],
  ['川口', 35.836742, 139.722061,2],
  ['大宮', 35.931317, 139.626617,3],
  ['朝霞', 35.825608, 139.589539,4],
  ['越谷', 35.894613, 139.782486,5],
  ['川越', 35.909630, 139.520187,6],
  ['上尾', 36.008006, 139.588165,7],
  ['春日部', 35.981896, 139.747467,8],
  ['西川口', 35.835628, 139.704895,9],
  ['熊谷', 36.150074, 139.379425,10],
  ['所沢', 35.800342, 139.471135,11],
  ['東松山', 36.037995, 139.404144,12],
  ['行田', 36.151182, 139.461823,13],
  ['秩父', 35.985785, 139.078674,14],
  ['本庄', 36.234304, 139.188538,15]
  
 ]; 
  function initialize() {
    directionsDisplay = new google.maps.DirectionsRenderer();
    geocoder = new google.maps.Geocoder();
    var saitama = new google.maps.LatLng(35.986896, 139.5043953);
    var myOptions = {
      zoom:10,
      mapTypeId: google.maps.MapTypeId.ROADMAP,
      center: saitama,
      region: "ja"
       }
    map = new google.maps.Map(document.getElementById("mapCanvas"), myOptions);
         var adUnitDiv = document.createElement('div');
     var ad_options = {
     format: google.maps.adsense.AdFormat.BANNER,
     position: google.maps.ControlPosition.BOTTOM,
     map: map,
     visible: true,
     publisherId: 'ca-pub-9367831331894417'
   };
adUnit = new google.maps.adsense.AdUnit(adUnitDiv, ad_options);


directionsDisplay.setMap(map);
    directionsDisplay.setPanel(document.getElementById("directionsPanel"));

    setMarkers(map, tax); 



}
function setMarkers(map, locations) {
     var gYellowIcon =new google.maps.MarkerImage(
      "http://labs.google.com/ridefinder/images/mm_20_yellow.png",
      new google.maps.Size(12, 20),
      new google.maps.Point(0, 0),
      new google.maps.Point(6, 20));
   for (var i = 0; i < locations.length; i++) {
     var beach = locations[i];
     var myLatLng = new google.maps.LatLng(beach[1], beach[2]);
     var marker = new google.maps.Marker({
         position: myLatLng,
         map: map,
         icon: gYellowIcon,
         title: beach[0],
         zIndex: beach[3] 
        });  
  
	 }
}



  function calcRoute() {
    var start = document.getElementById("start").value;

    var end = document.getElementById("end").value;
    var request = {
        origin:start, 
        destination:end,
        travelMode: google.maps.DirectionsTravelMode.DRIVING
    };
    directionsService.route(request, function(response, status) {
      if (status == google.maps.DirectionsStatus.OK) {
        directionsDisplay.setDirections(response);
      }
    });
  }
   function codeAddress(zaddress) {
     var  address = zaddress;
       if (geocoder) {
        geocoder.geocode(
        { 'address': address}, function(results, status) {
       if (status == google.maps.GeocoderStatus.OK) {
           map.setCenter(results[0].geometry.location);
	   map.setZoom(10); 
           var contentString =  '<p style="font-size:11px">マーカをクリックして<br>詳細地図を見てみよう！</p>';
  	   var infowindow = new google.maps.InfoWindow({
		content: contentString
		});
           var marker = new google.maps.Marker({
                 map: map,
                 position: results[0].geometry.location
                 }); 
//	    window.location.hash = 'top';

	 infowindow.open(map,marker);
           google.maps.event.addListener(
                marker, 'click', function() {
		map.setCenter(results[0].geometry.location);
                map.setZoom(14);
                }		); 
	 

     }    else {
           alert("Geocode was not successful for the following reason: " + status + address);
               }
             });
         } 
window.location.hash = 'top';

      }
 function end_chenge(qaddress){
      document.getElementById("end").value = qaddress;
//	 alert(qaddress);

    }

    // showLocation() is called when you click on the Search button
    // in the form.  It geocodes the address entered into the form
    // and adds a marker to the map at that location.
    function showLocation(yaddress) {
      initialize();
      xaddress = '埼玉県' + yaddress;
      param_adr = yaddress;
 end_chenge(xaddress);

      codeAddress(xaddress); window.location.hash = 'top';

    }

   // findLocation() is used to enter the sample addresses into the form.
    function findLocation(address) {
      document.forms[0].q.value = address;
      showLocation();
    }
