/*    var map;

    var geocoder;

    var address;

    var city, cityLatitude, cityLongitude;

    

    function initialize(latitude, longitude)

    {  

        map = new GMap2(document.getElementById("map_canvas")); 
		
		map.setMapType(G_NORMAL_MAP);

        map.setCenter(new GLatLng(parseFloat(latitude),parseFloat(longitude)), 13);  

        map.addControl(new GLargeMapControl);   

        

        //document.getElementById('').style.backgroundImage=

    }

    

    function findLatLong(zipcode,display,phone)

    {

        //city = document.getElementById('txtCity').value;

		city = zipcode;

        geocoder = new GClientGeocoder();

        geocoder.getLatLng(city, function(point) 

                                    {  

                                        if (point == null)

                                        {   

                                            //alert('No point found');

                                        } 

                                        else

                                        {  

                                            cityLatitude = point.lat();   

                                            cityLongitude = point.lng(); 

                                            //alert(point.lat() + ',' + point.lng());                                             

                                            findInputCity(point, cityLatitude, cityLongitude,display,phone);                                                                                   

                                        }

                                    }

                                );     

    }

    

    

    function findInputCity(point, latitude, longitude,display,phone)

    {       

        var geocoder2 = new GClientGeocoder(); 

        

        map = new GMap2(document.getElementById("map_canvas"));
		
		map.setMapType(G_NORMAL_MAP);

        map.setCenter(new GLatLng(parseFloat(latitude),parseFloat(longitude)), 13);  

        map.addControl(new GLargeMapControl); 
		
		

          

        //var point = new GPoint(latitude, longitude)

        geocoder2.getLocations(point, function(response)

        {            

            map.clearOverlays();  

            if (!response || response.Status.code != 200) 

            {    

                //alert("Status Code:" + response.Status.code);  

            } 

            else

            {    

                place = response.Placemark[0];    

                point = new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]);    

                marker = new GMarker(point);    

                map.addOverlay(marker);    

                var InfoWindowHtml = '<img src="images/logoIcon.jpg"><br>' +
				       '<b>Address : </b>' + display + '&nbsp;&nbsp;&nbsp;<br>' +        

                       '<b>Telephone : </b>' + phone + '<br>' +        

                       '<b>Country code : </b> ' + place.AddressDetails.Country.CountryNameCode

                marker.openInfoWindowHtml(InfoWindowHtml);

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

                       

                       address = null;

                       var countryName = place.AddressDetails.Country.CountryNameCode;

                       switch(countryName)

                       {

                            case 'AD': //Andorra

                                address = place.address.match(new RegExp(/[Aa][Dd][1-7][0]{2}/)); 

                                break;

                                

                            case 'DE': // Germany

                            case 'EE': // Estonia                                

                            case 'ES': // Spain

                            case 'FI': // Finland

                            case 'FR': // France

                            case 'GR': // Greece

                            case 'IT': // Italy

                            case 'LT': // Lithuania

                            case 'SE': // Sweden

                                address = place.address.match(new RegExp(/[0-9]{5}/)); 

                                break; 

                                   

                            case 'AT': // Austria  

                            case 'BE': // Belgium

                            case 'CH': // Switzerland 

                            case 'DK': // Denmark   

                            case 'HU': // Hungary 

                            case 'LV': // Latvia                  

                            case 'NL': // Netherlands

                            case 'NO': // Norway

                            case 'PT': // Portugal

                            case 'SI': // Slovania

                                address = place.address.match(new RegExp(/[0-9]{4}/)); 

                                break;

                                

                            case 'CZ': // Czech Republic

                                address = place.address.match(new RegExp(/[0-9]{3}\s[0-9]{2}/)); 

                                break;

                                

                            case 'BG': // Bulgaria

                            case 'BY': // Belarus

                            case 'CY': // Cyprus

                            case 'GB': // United Kingdom 

                            case 'HR': // Croatia

                            case 'IE': // Ireland

                            case 'IL': // Israel

                            case 'IS': // Iceland

                            case 'LU': // Luxembourg

                            case 'MT': // Malta

                            case 'PL': // Poland

                            case 'RO': // Romania

                            case 'SK': // Slovakia

                            case 'TR': // Turkey

                                address = '-1' ;

                                break;

                            

                       }    

                       

                       //alert('INPUT CITY : ' + city + '\nOUTPUT POSTCODE :  ' + address + '\nOUTPUT COUNTRY CODE :  ' + countryName);                         

            }                             

        } );                

    }   */
	
	var map;
    var gdir;
    var geocoder = null;
    var addressMarker;
    var address;
    var city, cityLatitude, cityLongitude;



    /*function initialize() {
      if (GBrowserIsCompatible()) {      
        map = new GMap2(document.getElementById("map_canvas"));
		//for point
		map.setCenter(new GLatLng(37.4419, -122.1419), 13);
		// Add 10 markers to the map at random locations
        var bounds = map.getBounds();
        var southWest = bounds.getSouthWest();
        var northEast = bounds.getNorthEast();
        var lngSpan = northEast.lng() - southWest.lng();
        var latSpan = northEast.lat() - southWest.lat();
        for (var i = 0; i < 1; i++) {
          var latlng = new GLatLng(southWest.lat() + latSpan * Math.random(),
                                  southWest.lng() + lngSpan * Math.random());
          map.addOverlay(new GMarker(latlng));
        }
        // end
		
		//for direction

        gdir = new GDirections(map, document.getElementById("directions"));
        GEvent.addListener(gdir, "load", onGDirectionsLoad);
        GEvent.addListener(gdir, "error", handleErrors);

        //setDirections("San Francisco", "Mountain View", "en_US");
      }
    }*/
	function initialize(latitude, longitude)

    {  

        map = new GMap2(document.getElementById("map_canvas")); 
		
		map.setMapType(G_NORMAL_MAP);

        map.setCenter(new GLatLng(parseFloat(latitude),parseFloat(longitude)), 13);  

        map.addControl(new GLargeMapControl);   
		
		gdir = new GDirections(map, document.getElementById("directions"));
        GEvent.addListener(gdir, "load", onGDirectionsLoad);
        GEvent.addListener(gdir, "error", handleErrors);

        

        //document.getElementById('').style.backgroundImage=

    }

    

    function findLatLong(zipcode,display,phone)

    {

        //city = document.getElementById('txtCity').value;

		city = zipcode;

        geocoder = new GClientGeocoder();

        geocoder.getLatLng(city, function(point) 

                                    {  

                                        if (point == null)

                                        {   

                                            //alert('No point found');

                                        } 

                                        else

                                        {  
                                            
											
                                            cityLatitude = point.lat();   

                                            cityLongitude = point.lng(); 

                                            //alert(point.lat() + ',' + point.lng());                                             

                                            findInputCity(point, cityLatitude, cityLongitude,display,phone);                                                                                   

                                        }

                                    }

                                );     

    }

    function func(){
	   document.getElementById("tab").style.display = 'block';
	   document.getElementById("tspan").style.display = 'none';
	}

    

    function findInputCity(point, latitude, longitude,display,phone)

    {       

        var geocoder2 = new GClientGeocoder(); 

        

        map = new GMap2(document.getElementById("map_canvas"));
		
		map.setMapType(G_NORMAL_MAP);

        map.setCenter(new GLatLng(parseFloat(latitude),parseFloat(longitude)), 13);  

        //map.addControl(new GLargeMapControl); 
		
		gdir = new GDirections(map, document.getElementById("directions"));
        GEvent.addListener(gdir, "load", onGDirectionsLoad);
        GEvent.addListener(gdir, "error", handleErrors);
		
		

          

        //var point = new GPoint(latitude, longitude)

        geocoder2.getLocations(point, function(response)

        {            

            map.clearOverlays();  

            if (!response || response.Status.code != 200) 

            {    

                //alert("Status Code:" + response.Status.code);  

            } 

            else

            {    

                place = response.Placemark[0];    

                //point = new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]); 
				
				if(phone=='702-893-9999'){
				point = new GPoint('-115.070950', '36.074866');
				} else {
				point = new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]); 	
				}


                marker = new GMarker(point);    

                map.addOverlay(marker);    

                var InfoWindowHtml = '<img src="images/logoIcon.jpg"><br>' +
				       '<b>Address : </b>' + display + '&nbsp;&nbsp;&nbsp;<br>' +        

                       '<b>Telephone : </b>' + phone + '<br>' +    
					   
					   '<span id="tspan"><a href="#" onclick="func();return false;">Driving Directions</a><br></span>' +        

                       '<b>Country code : </b> ' + place.AddressDetails.Country.CountryNameCode

                marker.openInfoWindowHtml(InfoWindowHtml);
				
				//setDirections("8565 W Sahara Ave #112 Las Vegas, NV 89117", "8565 W Sahara Ave #112 Las Vegas, NV 89117", "en_US");

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

                       

                       address = null;

                       var countryName = place.AddressDetails.Country.CountryNameCode;

                       switch(countryName)

                       {

                            case 'AD': //Andorra

                                address = place.address.match(new RegExp(/[Aa][Dd][1-7][0]{2}/)); 

                                break;

                                

                            case 'DE': // Germany

                            case 'EE': // Estonia                                

                            case 'ES': // Spain

                            case 'FI': // Finland

                            case 'FR': // France

                            case 'GR': // Greece

                            case 'IT': // Italy

                            case 'LT': // Lithuania

                            case 'SE': // Sweden

                                address = place.address.match(new RegExp(/[0-9]{5}/)); 

                                break; 

                                   

                            case 'AT': // Austria  

                            case 'BE': // Belgium

                            case 'CH': // Switzerland 

                            case 'DK': // Denmark   

                            case 'HU': // Hungary 

                            case 'LV': // Latvia                  

                            case 'NL': // Netherlands

                            case 'NO': // Norway

                            case 'PT': // Portugal

                            case 'SI': // Slovania

                                address = place.address.match(new RegExp(/[0-9]{4}/)); 

                                break;

                                

                            case 'CZ': // Czech Republic

                                address = place.address.match(new RegExp(/[0-9]{3}\s[0-9]{2}/)); 

                                break;

                                

                            case 'BG': // Bulgaria

                            case 'BY': // Belarus

                            case 'CY': // Cyprus

                            case 'GB': // United Kingdom 

                            case 'HR': // Croatia

                            case 'IE': // Ireland

                            case 'IL': // Israel

                            case 'IS': // Iceland

                            case 'LU': // Luxembourg

                            case 'MT': // Malta

                            case 'PL': // Poland

                            case 'RO': // Romania

                            case 'SK': // Slovakia

                            case 'TR': // Turkey

                                address = '-1' ;

                                break;

                            


                       }    

                       

                       //alert('INPUT CITY : ' + city + '\nOUTPUT POSTCODE :  ' + address + '\nOUTPUT COUNTRY CODE :  ' + countryName);                         

            }                             

        } );                

    }   
    
    function setDirections(fromAddress, toAddress, locale) {
	  if(fromAddress==''){
		  alert("Please enter from address/zipcode.");
		  return false;
	  } else {
	  document.getElementById("directions").style.display = 'block';
	  document.getElementById("tspan").style.display = 'none';
	  document.getElementById("map_canvas").style.width = '380px';
      gdir.load("from: " + fromAddress + " to: " + toAddress,
                { "locale": locale });
	  }
    }

    function handleErrors(){
	   if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	     alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);
	   else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
	     alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
	   
	   else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
	     alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);

	//   else if (gdir.getStatus().code == G_UNAVAILABLE_ADDRESS)  <--- Doc bug... this is either not defined, or Doc is wrong
	//     alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + gdir.getStatus().code);
	     
	   else if (gdir.getStatus().code == G_GEO_BAD_KEY)
	     alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);

	   else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
	     alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
	    
	   else alert("An unknown error occurred.");
	   
	}

	function onGDirectionsLoad(){ 
      // Use this function to access information about the latest load()
      // results.

      // e.g.
      // document.getElementById("getStatus").innerHTML = gdir.getStatus().code;
	  // and yada yada yada...
	}
