﻿var map = null;
    var geocoder = null;
    var add = "1600 Amphitheatre Pky, Mountain View, CA";﻿
     var icon = new GIcon();  
$(document).ready(function(){
    if(document.getElementById("map")!=null)
    {
           
        initialize();
        
        
     }

});

function initialize() {
            if (GBrowserIsCompatible()) {
                map = new GMap2(document.getElementById("map"));
                geocoder = new GClientGeocoder();
		
	              map.setCenter(new GLatLng(40, -100), 3);			
         
                map.enableDoubleClickZoom();
        		map.enableScrollWheelZoom();	
        		map.addControl(new GSmallMapControl());
                
                if(typeof (pname) == 'undefined') 
	             {		
	               //alert("undefined");			
                 }
                 else{
                    for(var i = 0; i < pname.length ; i++)
		              {
		               var address = pname[i][0]+","+ pname[i][1] +","+pname[i][2]+","+pname[i][3];
		               var storename = pname[i][4];
                       showAddress(address,storename);
                     }
                     if(typeof (code) != 'undefined') 
      	             {	
      	                Zoom(code);
      	             }
                 }
                
            }
        }

    function showAddress(address,storename) {       
                                        
                                                                           
                                        geocoder.getLocations(address,
					                       function(response){
					                        if(!response || response.Status.code != 200)
					                        {
                                               // alert(response.Status.code);
                                            }
                                            else
                                            {
                                            place = response.Placemark[0];
                                            point = new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]);
					                        map.setFocus(point);
					                        var marker = new GMarker(point);
					                        
					                        GEvent.addListener(marker, "click", function() {
					                           marker.openInfoWindowHtml("<table width=200 border=0><tr><td  nowrap><strong>Store Name: </strong></td><td>" + storename +"</tr><tr><td><strong>Address: </strong></td><td>"+address+"</td></tr></table>");
					                        });
					                        map.addOverlay(marker);			
						                        }
						                        }
						                        );
                                         
                                   }
   function getpoint(address){

var point = new GLatLng('42.356679','-88.001852');
 map.setCenter(point,3);
                                         
   }
   
 function Zoom(address) {   
     
     
                                if (geocoder) {
                                                    geocoder.getLatLng(
                                                  address,
                                                  function(point) {
                                                                      if (!point) {
                                                                          alert(address + " not found");
                                                                          } 
                                                                     else {
                                                                          map.setCenter(point, 11);
                                                                       
                                                                          }
                                                                   }
                                                                 );
                                                
                                                }
                                                
                             }
    