﻿// JScript File

var geocoder;
var map;
var point;
var comAddress;
   
function loadEarth(mapdiv) {
    
    comAddress = "";
    document.getElementById("map").style.display = "none";  
    
  // if (GBrowserIsCompatible()) {                                    

		 // Create new geocoding object
		 geocoder = new GClientGeocoder();
		 
		 if (country != '')
		    comAddress = country;
		    
		 if (postcode != '')
		    comAddress = comAddress  +  ", " + postcode;
		    
		 if (state != '')
		    comAddress = comAddress  +  ", " + state;
		 
		 if (city != '')
		    comAddress = comAddress  +  ", " + city;
		    
		 if (address != '')
		    comAddress = comAddress  +  ", " + address;
		    
		    
		
		 
		
 
	     // Retrieve location information, pass it to addToMap()  			     
	     geocoder.getLocations(comAddress, addToMap);	  
		 
   //   }

}

// This function adds the point to the map	
function addToMap(response)
{	        
  if (response.Status.code == 200) {
  
     document.getElementById("map").style.display = "block";  
     // Create new map object
      map = new GMap2(document.getElementById("divMap"));
      map.setUIToDefault();
      
      // Retrieve the object
      place = response.Placemark[0];

      // Retrieve the latitude and longitude
      point = new GLatLng(place.Point.coordinates[1],
					      place.Point.coordinates[0]);

        
      // Center the map on this point
      map.setCenter(point, 13);

      // Create a marker
      marker = new GMarker(point);

     GEvent.addListener(marker, "mouseover", function() {
               
     marker.openInfoWindowHtml(Text1);});
              
     GEvent.addListener(marker, "mouseout", function() {
              
     marker.closeInfoWindow();});

     map.addOverlay(marker);
    
 }
 else
 {   
    var cityLevel;
    cityLevel = '';
        if (country != '')
		    cityLevel = country;
		    
		 if (postcode != '')
		    cityLevel = cityLevel  +  ", " + postcode;
		    
		 if (state != '')
		    cityLevel = cityLevel  +  ", " + state;
		 
		 if (city != '')
		    cityLevel = cityLevel  +  ", " + city;	    
	
    geocoder.getLocations(cityLevel, addToMapCity);                                   
 }
 
 
}


// This function adds the point to the map	
function addToMapCity(response)
{	        
  if (response.Status.code == 200) {
  
     document.getElementById("map").style.display = "block";  
     // Create new map object
      map = new GMap2(document.getElementById("divMap"));
      map.setUIToDefault();

      // Retrieve the object
      place = response.Placemark[0];

      // Retrieve the latitude and longitude
      point = new GLatLng(place.Point.coordinates[1],
					      place.Point.coordinates[0]);

        
      // Center the map on this point
     map.setCenter(point, 10);

      // Create a marker
      marker = new GMarker(point);

     GEvent.addListener(marker, "mouseover", function() {
               
     marker.openInfoWindowHtml(Text1);});
              
     GEvent.addListener(marker, "mouseout", function() {
              
     marker.closeInfoWindow();});

     map.addOverlay(marker);
    
 }
 else
 {   
    var stateLevel;    
    stateLevel = '';
        if (country != '')
		    stateLevel = country;
		    
		 if (postcode != '')
		    stateLevel = stateLevel  +  ", " + postcode;
		    
		 if (state != '')
		    stateLevel = stateLevel  +  ", " + state;
		 
		
    
    geocoder.getLocations(stateLevel, addToMapCountry);                
 }
 
 
}



// This function adds the point to the map	
function addToMapState(response)
{	        
  if (response.Status.code == 200) {
  
     document.getElementById("map").style.display = "block";  
     // Create new map object
      map = new GMap2(document.getElementById("divMap"));
      map.setUIToDefault();

      // Retrieve the object
      place = response.Placemark[0];

      // Retrieve the latitude and longitude
      point = new GLatLng(place.Point.coordinates[1],
					      place.Point.coordinates[0]);

        
      // Center the map on this point
     map.setCenter(point, 10);

      // Create a marker
      marker = new GMarker(point);

     GEvent.addListener(marker, "mouseover", function() {
               
     marker.openInfoWindowHtml(Text1);});
              
     GEvent.addListener(marker, "mouseout", function() {
              
     marker.closeInfoWindow();});

     map.addOverlay(marker);
    
 }
 else
 {       
    var stateLevel;    
    postCodeLevel = '';
        if (country != '')
		    postCodeLevel = country;
		    
		 if (postcode != '')
		    postCodeLevel = postCodeLevel  +  ", " + postcode;
		    
	
    
    geocoder.getLocations(stateLevel, addToMapPostCode);                                      
 }
 
 
}


// This function adds the point to the map	
function addToMapPostCode(response)
{	        
  if (response.Status.code == 200) {
  
     document.getElementById("map").style.display = "block";  
     // Create new map object
      map = new GMap2(document.getElementById("divMap"));
      map.setUIToDefault();

      // Retrieve the object
      place = response.Placemark[0];

      // Retrieve the latitude and longitude
      point = new GLatLng(place.Point.coordinates[1],
					      place.Point.coordinates[0]);

        
      // Center the map on this point
      map.setCenter(point, 10);

      // Create a marker
      marker = new GMarker(point);

     GEvent.addListener(marker, "mouseover", function() {
               
     marker.openInfoWindowHtml(Text1);});
              
     GEvent.addListener(marker, "mouseout", function() {
              
     marker.closeInfoWindow();});

     map.addOverlay(marker);
    
 }
 else
 {   
    geocoder.getLocations(country, addToMapCountry);                                 
    
 }
 
 
}


// This function adds the point to the map	
function addToMapCountry(response)
{	        
  if (response.Status.code == 200) {
  
     document.getElementById("map").style.display = "block";  
     // Create new map object
      map = new GMap2(document.getElementById("divMap"));
      map.setUIToDefault();

      // Retrieve the object
      place = response.Placemark[0];

      // Retrieve the latitude and longitude
      point = new GLatLng(place.Point.coordinates[1],
					      place.Point.coordinates[0]);

        
      // Center the map on this point
      map.setCenter(point, 10);

      // Create a marker
      marker = new GMarker(point);

     GEvent.addListener(marker, "mouseover", function() {
               
     marker.openInfoWindowHtml(Text1);});
              
     GEvent.addListener(marker, "mouseout", function() {
              
     marker.closeInfoWindow();});

     map.addOverlay(marker);
    
 }
 else
 {   
    document.getElementById("map").style.display = "none";                               
    
 }
 
 
}