﻿// JScript File
//FileName: SearchGMap.js
//Author  : Intelligaia Technologies Pvt. Ltd.
//Purpose : to plot the pushpins on the map
//----------Revision History----------
//Originated: 02-August-2008

var map; //hold the object of gmap api
var geocoder; //store new instance of a geocoder that talks directly to Google servers.
var RecordID = 0;
var MarkerID =0;
var side_bar_html = "";
var letteredIcon="";
var divMarkers=[];
var gMarker=0;
// Create a base icon for all of our markers that specifies the
// shadow, icon dimensions, etc.
var baseIcon="";

   
//mark locations on the gmap    
function markLocation(count)
{     
  
   
     
        if(document.getElementById("address"))
        { 
            
            var address = document.getElementById("address").innerHTML; //get the address from list
            geocoder.getLocations(document.getElementById("address").innerHTML, LocationPoints);
  geocoder = new GClientGeocoder(); 
            var value=findLocation(address,document.getElementById("name").innerHTML );//find location on google map          
           
          
       }
    
    
}
function Icon()
{
    baseIcon = new GIcon();    
    baseIcon.shadow = "http://www.signup4chess.com/images/gmapTipShadow.png";
    baseIcon.iconSize = new GSize(20, 34);
    baseIcon.shadowSize = new GSize(37, 34);
    baseIcon.iconAnchor = new GPoint(9, 34);
    baseIcon.infoWindowAnchor = new GPoint(9, 2);
    baseIcon.infoShadowAnchor = new GPoint(18, 25);
    
}


function initialize(control,a)
{
//GUnload();
  if (GBrowserIsCompatible() ) {
  RecordID=0;
  MarkerID=0;
  gMarker=0;
  Icon();
  map = new GMap2(document.getElementById("map_canvas")); //initilize API
  map.addControl(new GLargeMapControl());
  map.addControl(new GMapTypeControl());
  geocoder = new GClientGeocoder(); //Creates a new instance of a geocoder that talks directly to Google servers
 //Creates a new instance of a geocoder that talks directly to Google servers.
 // var count=0;
  //if(document.getElementById("CountLocations"))
  //  count = document.getElementById("CountLocations").innerHTML;
 // else
  //  count=2;
 
   markLocation(1);    //mark locations on the gmap    
  }
}

function LocationPoints(response)
{

    place = response.Placemark[0]; //get place   
    point = new GLatLng(place.Point.coordinates[1],
                        place.Point.coordinates[0]);//get location
                      
    //var zoomLevel=getZoomLevel();
 
    map.setCenter(point,(16));
   
}

function getZoomLevel()
{
    var  ZoomLevel=12;
    if(document.getElementById('Radius').innerHTML=="100 miles")
        ZoomLevel=6;
    else if(document.getElementById('Radius').innerHTML=="50 miles")
        ZoomLevel=7;
    else if(document.getElementById('Radius').innerHTML=="25 miles")
        ZoomLevel=8;
    else if(document.getElementById('Radius').innerHTML=="15 miles")
        ZoomLevel=9;
    else if(document.getElementById('Radius').innerHTML=="10 miles")
        ZoomLevel=10;
        
    return ZoomLevel;
}
//// addAddressToMap() is called when the geocoder returns an
//// answer.  It adds a marker to the map with an open info window
//// showing the nicely formatted version of the address and the country code.
//function addAddressToMap(response)
//{      
//  if (!response || response.Status.code != 200)
//  {
//    //RecordID++;
//  } 
//  else
//  {
//    place = response.Placemark[0]; //get place
//   
//    point = new GLatLng(place.Point.coordinates[1],
//                        place.Point.coordinates[0]);//get location
//  
//     
//        var blueIcon = new GIcon(G_DEFAULT_ICON);
//        // Set up our GMarkerOptions object
//	    markerOptions = { icon:blueIcon };
//    	
//	    var markerFinal=createMarker(point,place.address, place.address);
//	  
//	    map.addOverlay(markerFinal); //mark location  
//        
//  
//   
//  }
//}

  function createMarker(point,name,html) {

  // Create a lettered icon for this point using our icon class
     
      letteredIcon = new GIcon(baseIcon);
      letteredIcon.image = "http://www.signup4chess.com/images/gmapTip.png";
     
    
      // Set up our GMarkerOptions object
      markerOptions = { icon:letteredIcon };
      
 
        var marker = new GMarker(point,markerOptions);
        GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(html);
        });
      
             
       
        MarkerID++;
        RecordID++;
        
             
        return marker;
      }


     
 
     
      
////find and mark the location on Gemp
// function addOneAddressToMap(response)
// {
//      
//      if (!response || response.Status.code != 200)
//      {
//        alert("Sorry, we are unable to locate the address");
//      }
//      else
//      {
//      
//        map.setCenter(new GLatLng(0, 0), 1);
//      
//        place = response.Placemark[0];
//        point = new GLatLng(place.Point.coordinates[1],
//                            place.Point.coordinates[0]);
//        map.addOverlay(new GMarker(point));
//        var blueIcon = new GIcon(G_DEFAULT_ICON);
//        // Set up our GMarkerOptions object
//		markerOptions = { icon:blueIcon };
//        var marker = new GMarker(point);
//        GEvent.addListener(marker, "click", function() {
//            marker.openInfoWindowHtml("<b>Session</b> <br/> "+place.address);});
//       
//        map.addOverlay(marker);       
//        marker.openInfoWindowHtml(place.address);
//      }
//    }
      

// findLocation() is used to enter the sample addresses into the form.
//function findLocationOld(address) {
 // geocoder.getLocations(address, addAddressToMap);
//}

function findLocation(address, InfoToDisplay) 
{
   
      if (geocoder) 
      {
        
        geocoder.getLatLng(
          address,
          function(point) 
          {
            
            
            if (!point) 
            {                         
              RecordID++;
                         
            } 
            else 
            {       
              
               var markerFinal=createMarker(point,InfoToDisplay, InfoToDisplay);	
                
	           map.addOverlay(markerFinal); //mark location  
	             markerFinal.openInfoWindowHtml(InfoToDisplay);
            }
          }
        );
        
      }
      else
      {
         alert('geo not found'); 
      }
     return true;
   }
function ShowLocation(address) {

    geocoder.getLocations(address, addOneAddressToMap);
}

  

