/* The Following set of Data is for XP Box Server MS4W */
//var absPath = "http://cyberswiftgis.servehttp.com:7070/indiapollutionmap/";
//var baseUrlForMapServerCall = "http://cyberswiftgis.servehttp.com:88/cgi-bin/mapserv.exe?";
//var baseUrlForMapServerData = "map=/MS4W/ms4w/project_data/160_ipm/";

/* The Following set of Data is for Production Server MS4W */
//var absPath = "http://test.indiapollutionmap.org/";
//var absPath = "http://184.168.119.199/indiapollutionmap/";
//var baseUrlForMapServerCall = "http://184.168.119.199:23180/cgi-bin/mapserv.exe?";
//var baseUrlForMapServerData = "map=/DATA/PROJECT/160_IPM/MAP/";


//var absPath = "http://10.60.64.76:8080/pollutionmapdesign/";
//var absPath = "http://localhost:8080/pollutionmapdesign/";
//var baseUrlForMapServerCall = 'http://10.60.64.76/fcgi-bin/mapserv.exe?';
//var baseUrlForMapServerData = 'map=E:/Prabus Files/Pollution Map/project_data/160_IndiaPollutionMap/ms4w_data/';
//live
var absPath = "http://www.indiapollutionmap.org/";
//var absPath = "http://184.168.119.199/indiapollutionmap/";
var baseUrlForMapServerCall = "http://184.168.119.199:23180/cgi-bin/mapserv.exe?";
var baseUrlForMapServerData = "map=/DATA/PROJECT/160_IPM/MAP/";


function CS_Map(targetObj, centerLat, centerLong, zoomLvl)
{
   //alert("Called....2");
   var id = null;
   var map = null;
   if (map == null)
   {
      map = new GMap2(targetObj);

      map.setCenter(new GLatLng(centerLat, centerLong), zoomLvl);
      map.addControl(new GScaleControl()); // Adding Scale Control
      map.addControl(new GLargeMapControl3D()); // Adding Navigation Control
      map.addControl(new GMapTypeControl()); // Adding MapType Control Map, Satelite, Hybrid
      //map.addControl(new GZoomControl()); // Adding Rectangle zoom control
      //map.setMapType(G_SATELLITE_3D_MAP);
      map.setMapType(G_NORMAL_MAP); // Setting Normal Control
      //map.setMapType(G_HYBRID_MAP);  //Setting Hybrid Control
      map.enableScrollWheelZoom(); //Enable mouse wheel zoom
   //map.enableGoogleBar();
   }

   this.setCenter = function(centerLat, centerLong, zoomLvl)
   {
      map.setCenter(new GLatLng(centerLat, centerLong), zoomLvl);
   }
   this.setCenterFromBoundbox = function(boundbox)
   {
      map.setCenter(boundbox.getCenter(),map.getBoundsZoomLevel(boundbox));
   }

   this.getBounds = function()
   {
      return map.getBounds();
   }

   this.addOverlay = function(item)
   {
      map.addOverlay(item);
   }

   this.removeOverlay = function(item)
   {
      map.removeOverlay(item);
   }

   this.getMap = function()
   {
      return map;
   }
	
   this.getLocation = function(locationString)
   {
      //alert("Called 2");
      var geocoder = new GClientGeocoder();
      geocoder.getLatLng(locationString,
         function(point)
         {
            if (!point)
            {
               alert("'"+locationString+"' - not found");
            }
            else
            {
               try
               {
                  map.setCenter(point,11);
               }
               catch(e)
               {
                  alert(e);
               }
            }
         });
   }
	
   this.registerLayerPopupEvent = function(_id)
   {
      id = _id;
      var _map = this.getMap();
		
      GEvent.addListener(_map,"click",function(overlay, latlng)
      {
         //alert(selectLayerName+"_#_"+zoomLavel+"_#_"+year+"_#_"+id+"_/_"+latlng);
         if(!overlay &&  selectLayerName)
         {
            initializeLayerInfowindowContent(_map, document.getElementById('"+id+"_infowindowdiv'),selectLayerName,zoomLavel,year,latlng);
         }
      //_map.openInfoWindowHtml(latlng,html);
      });
   }
}

function CS_TwingMapOperation(map1, map2)
{
   var dragStart1;
   var dragEnd1;
   var dragging1;
   var zoomStart1;
   var zoomEnd1;
   var zooming1;

   var zoomStart2;
   var zoomEnd2;
   var zooming2;
   var dragStart2;
   var dragEnd2;
   var dragging2;
	
	
   this.linkMaps = function()
   {
      map2.setCenterFromBoundbox(map1.getBounds());
		
      // Attaching Right map with Left map
      dragStart1 = GEvent.addListener(map1.getMap(),"dragstart",function()
      {
         map2.setCenterFromBoundbox(map1.getBounds());
      });
      dragEnd1 = GEvent.addListener(map1.getMap(),"dragend",function()
      {
         map2.setCenterFromBoundbox(map1.getBounds());
      });
      dragging1 = GEvent.addListener(map1.getMap(),"drag",function()
      {
         map2.setCenterFromBoundbox(map1.getBounds());
      });
		
      zoomStart1 = GEvent.addListener(map1.getMap(),"zoomstart",function()
      {
         map2.setCenterFromBoundbox(map1.getBounds());
      });
      zoomEnd1 = GEvent.addListener(map1.getMap(),"zoomend",function()
      {
         map2.setCenterFromBoundbox(map1.getBounds());
      });
      zooming1 = GEvent.addListener(map1.getMap(),"zooming",function()
      {
         map2.setCenterFromBoundbox(map1.getBounds());
      });
		
      // Attaching Left map with Right map
      dragStart2 = GEvent.addListener(map2.getMap(),"dragstart",function()
      {
         map1.setCenterFromBoundbox(map2.getBounds());
      });
      dragEnd2 = GEvent.addListener(map2.getMap(),"dragend",function()
      {
         map1.setCenterFromBoundbox(map2.getBounds());
      });
      dragging2 = GEvent.addListener(map2.getMap(),"drag",function()
      {
         map1.setCenterFromBoundbox(map2.getBounds());
      });
		
      zoomStart2 = GEvent.addListener(map2.getMap(),"zoomstart",function()
      {
         map1.setCenterFromBoundbox(map2.getBounds());
      });
      zoomEnd2 = GEvent.addListener(map2.getMap(),"zoomend",function()
      {
         map1.setCenterFromBoundbox(map2.getBounds());
      });
      zooming2 = GEvent.addListener(map2.getMap(),"zooming",function()
      {
         map1.setCenterFromBoundbox(map2.getBounds());
      });
   }
	
   this.unlinkMaps = function()
   {
      GEvent.removeListener(dragStart1);
      GEvent.removeListener(dragEnd1);
      GEvent.removeListener(dragging1);
      GEvent.removeListener(zoomStart1);
      GEvent.removeListener(zoomEnd1);
      GEvent.removeListener(zooming1);
		
      GEvent.removeListener(dragStart2);
      GEvent.removeListener(dragEnd2);
      GEvent.removeListener(dragging2);
      GEvent.removeListener(zoomStart2);
      GEvent.removeListener(zoomEnd2);
      GEvent.removeListener(zooming2);
   }
}

/*
 http://cyberswiftgis.servehttp.com:88/cgi-bin/mapserv.exe?map=/ms4w/ms4w/Apache/htdocs/polution/state.map&layers=state&mode=tile&tilemode=gmap&tile=
 http://localhost:5480/cgi-bin/mapserv.exe?map=/ms4w/project_data/indianPollutionMap/state_cancer_data.map&layers=state_cancer_data&mode=tile&tilemode=VE&tile=123
 */

function CS_BoundaryForHome(map)
{
   var stateLayer = null;
   //if (GBrowserIsCompatible()) {
   //}
   this.showLayer = function(tLavel)
   {
      //var urlTemplate = 'http://intel2dual:87/cgi-bin/mapserv.exe?';
      var urlTemplate = baseUrlForMapServerCall;
      urlTemplate += baseUrlForMapServerData+'state.map&';
      urlTemplate += 'layers=home_boundary&';
      urlTemplate += 'mode=tile&';
      urlTemplate += 'tilemode=gmap&';
      urlTemplate += 'tile={X}+{Y}+{Z}';
		
      //alert(urlTemplate);
		
      var tileLayer = new GTileLayer(null,0,18,{
         tileUrlTemplate:urlTemplate,
         isPng:true,
         opacity:tLavel
      });
      stateLayer = new GTileLayerOverlay(tileLayer);
      map.addOverlay(stateLayer);
   }
   this.hideLayer = function(map)
   {
      map.removeOverlay(stateLayer);
   }
}

function CS_LayerState(map)
{
   var statePopulationLayer = null;
   var itr,len;

   this.showLayer = function(map,legendsParam,tLavel)
   {
      //var urlTemplate = 'http://intel2dual:87/cgi-bin/mapserv.exe?';
      var urlTemplate = baseUrlForMapServerCall;
      urlTemplate += baseUrlForMapServerData+'state.map&';
      urlTemplate += 'layers=state&';
      urlTemplate += 'mode=tile&';
      urlTemplate += 'tilemode=gmap&';
      urlTemplate += 'tile={X}+{Y}+{Z}';
		
      for(itr = 0; itr<6 ; itr++){
         try
         {
            urlTemplate += '&V'+(itr+1)+'='+legendsParam[itr];
         }
         catch(e)
         {
            urlTemplate += '&V'+(itr+1)+'=-1';
            alert(itr+" - "+e);
         }
      }
		
      //alert(urlTemplate);
		
      var tileLayer = new GTileLayer(null,0,18,{
         tileUrlTemplate:urlTemplate,
         isPng:true,
         opacity:tLavel
      });
      statePopulationLayer = new GTileLayerOverlay(tileLayer);
      map.addOverlay(statePopulationLayer);
   }
   this.hideLayer = function(map)
   {
      map.removeOverlay(statePopulationLayer);
   }
}

function CS_LayerDistrictTotalPopulation(map)
{
   var districtTotalPopulation = null;
   var itr,len;
	
   this.showLayer = function(map,legendsParam,tLavel)
   {
      //var urlTemplate = 'http://intel2dual:87/cgi-bin/mapserv.exe?';
      var urlTemplate = baseUrlForMapServerCall;
      urlTemplate += baseUrlForMapServerData+'district.map&';
      urlTemplate += 'layers=district_pop&';
      urlTemplate += 'mode=tile&';
      urlTemplate += 'tilemode=gmap&';
      urlTemplate += 'tile={X}+{Y}+{Z}';
		
      for(itr = 0; itr<6 ; itr++)
      {
         try
         {
            urlTemplate += '&V'+(itr+1)+'='+legendsParam[itr];
         }
         catch(e)
         {
            urlTemplate += '&V'+(itr+1)+'=-1';
            alert(itr+" - "+e);
         }
      }
		
      var tileLayer = new GTileLayer(null,0,18,{
         tileUrlTemplate:urlTemplate,
         isPng:true,
         opacity:tLavel
      });
      districtTotalPopulation = new GTileLayerOverlay(tileLayer);
      map.addOverlay(districtTotalPopulation);
   }
   this.hideLayer = function(map)
   {
      map.removeOverlay(districtTotalPopulation);
   }
}

function CS_LayerDistrictFertilizerConsumption()
{
   //alert("Called Level 2");
   var districtTotalPopulation = null;
   var itr,len;
	
   this.showLayer = function(map,legendsParam,tLavel)
   {
      //var urlTemplate = 'http://intel2dual:87/cgi-bin/mapserv.exe?';
      var urlTemplate = baseUrlForMapServerCall;
      urlTemplate += baseUrlForMapServerData+'district.map&';
      urlTemplate += 'layers=fert_consump&';
      urlTemplate += 'mode=tile&';
      urlTemplate += 'tilemode=gmap&';
      urlTemplate += 'tile={X}+{Y}+{Z}';
      for(itr = 0; itr<6 ; itr++)
      {
         try
         {
            urlTemplate += '&V'+(itr+1)+'='+legendsParam[itr];
         }
         catch(e)
         {
            urlTemplate += '&V'+(itr+1)+'=-1';
            alert(itr+" - "+e);
         }
      }
      //document.getElementById('test_div').innerHTML = urlTemplate;
      var tileLayer = new GTileLayer(null,0,18,{
         tileUrlTemplate:urlTemplate,
         isPng:true,
         opacity:tLavel
      });
      districtTotalPopulation = new GTileLayerOverlay(tileLayer);
      map.addOverlay(districtTotalPopulation);
   }
   this.hideLayer = function(map)
   {
      map.removeOverlay(districtTotalPopulation);
   }
}

function CS_LayerDistrictFertilizerConsumption05_06()
{
   //alert("Called Level 2");
   var districtTotalPopulation = null;
   var itr,len;
	
   this.showLayer = function(map,legendsParam,tLavel)
   {
      //var urlTemplate = 'http://intel2dual:87/cgi-bin/mapserv.exe?';
      var urlTemplate = baseUrlForMapServerCall;
      urlTemplate += baseUrlForMapServerData+'district.map&';
      urlTemplate += 'layers=fert_consump05_06&';
      urlTemplate += 'mode=tile&';
      urlTemplate += 'tilemode=gmap&';
      urlTemplate += 'tile={X}+{Y}+{Z}';
		
      for(itr = 0; itr<6 ; itr++)
      {
         try
         {
            urlTemplate += '&V'+(itr+1)+'='+legendsParam[itr];
         }
         catch(e)
         {
            urlTemplate += '&V'+(itr+1)+'=-1';
            alert(itr+" - "+e);
         }
      }
      //document.getElementById('test_div').innerHTML = urlTemplate;
      var tileLayer = new GTileLayer(null,0,18,{
         tileUrlTemplate:urlTemplate,
         isPng:true,
         opacity:tLavel
      });
      districtTotalPopulation = new GTileLayerOverlay(tileLayer);
      map.addOverlay(districtTotalPopulation);
   }
   this.hideLayer = function(map)
   {
      map.removeOverlay(districtTotalPopulation);
   }
}

function CS_LayerStateFertilizerPesticide()
{
   //alert("Called Level 2");
   var stateFertilizerPesticide = null;
   var itr,len;
   /*
	 * Shayamal Mondal
	 * +91-9362126275
	 * */
   this.showLayer = function(map,legendsParam,tLavel)
   {
      //var urlTemplate = 'http://intel2dual:87/cgi-bin/mapserv.exe?';
      //var urlTemplate = 'http://souravb/cgi-bin/mapserv.exe?';
      //urlTemplate += 'map=/ms4w/project_data/indianPollutionMap/state_pesticide_consmp.map&';
		
      var urlTemplate = baseUrlForMapServerCall;
      urlTemplate += baseUrlForMapServerData+'state.map&';
      urlTemplate += 'layers=state_tot_pesticide_consumption&';
      urlTemplate += 'mode=tile&';
      urlTemplate += 'tilemode=gmap&';
      urlTemplate += 'tile={X}+{Y}+{Z}';
		
      for(itr = 0; itr<6 ; itr++)
      {
         try
         {
            urlTemplate += '&V'+(itr+1)+'='+legendsParam[itr];
         }
         catch(e)
         {
            urlTemplate += '&V'+(itr+1)+'=-1';
            alert(itr+" - "+e);
         }
      }
		
      var tileLayer = new GTileLayer(null,0,18,{
         tileUrlTemplate:urlTemplate,
         isPng:true,
         opacity:tLavel
      });
      stateFertilizerPesticide = new GTileLayerOverlay(tileLayer);
      map.addOverlay(stateFertilizerPesticide);
   }
   this.hideLayer = function(map)
   {
      map.removeOverlay(stateFertilizerPesticide);
   }
}

function CS_LayerDistrictVehicle()
{
   //alert("Called CS_LayerDistrictVehicle");
   var districtTotalPopulation = null;
   var itr,len;
   //if (GBrowserIsCompatible()) {
   //}
   this.showLayer = function(map,legendsParam,tLavel)
   {
      //var urlTemplate = 'http://intel2dual:87/cgi-bin/mapserv.exe?';
      var urlTemplate = baseUrlForMapServerCall;
      urlTemplate += baseUrlForMapServerData+'district.map&';
      urlTemplate += 'layers=dist_veh&';
      urlTemplate += 'mode=tile&';
      urlTemplate += 'tilemode=gmap&';
      urlTemplate += 'tile={X}+{Y}+{Z}';
		
      for(itr = 0; itr<6 ; itr++)
      {
         try
         {
            urlTemplate += '&V'+(itr+1)+'='+legendsParam[itr];
         }
         catch(e)
         {
            urlTemplate += '&V'+(itr+1)+'=-1';
            alert(itr+" - "+e);
         }
      }
		
      var tileLayer = new GTileLayer(null,0,18,{
         tileUrlTemplate:urlTemplate,
         isPng:true,
         opacity:tLavel
      });
      districtTotalPopulation = new GTileLayerOverlay(tileLayer);
      map.addOverlay(districtTotalPopulation);
   }
   this.hideLayer = function(map)
   {
      map.removeOverlay(districtTotalPopulation);
   }
}

function CS_LayerDistrictTotalNoOfIndustries()
{
   //alert("Called CS_LayerDistrictVehicle");
   var districtTotalPopulation = null;
   var itr,len;
   //if (GBrowserIsCompatible()) {
   //}
   this.showLayer = function(map,legendsParam,tLavel)
   {
      //var urlTemplate = 'http://intel2dual:87/cgi-bin/mapserv.exe?';
      var urlTemplate = baseUrlForMapServerCall;
      urlTemplate += baseUrlForMapServerData+'district.map&';
      urlTemplate += 'layers=district_totn_ind&';
      urlTemplate += 'mode=tile&';
      urlTemplate += 'tilemode=gmap&';
      urlTemplate += 'tile={X}+{Y}+{Z}';
		
      for(itr = 0; itr<6 ; itr++)
      {
         try
         {
            urlTemplate += '&V'+(itr+1)+'='+legendsParam[itr];
         }
         catch(e)
         {
            urlTemplate += '&V'+(itr+1)+'=-1';
            alert(itr+" - "+e);
         }
      }
		
      var tileLayer = new GTileLayer(null,0,18,{
         tileUrlTemplate:urlTemplate,
         isPng:true,
         opacity:tLavel
      });
      districtTotalPopulation = new GTileLayerOverlay(tileLayer);
      map.addOverlay(districtTotalPopulation);
   }
   this.hideLayer = function(map)
   {
      map.removeOverlay(districtTotalPopulation);
   }
}

function CS_LayerStateTotalRespiratoryDisorder()
{
   //alert("Called CS_LayerDistrictVehicle");
   var stateTotalResDis = null;
   var itr,len;
   //if (GBrowserIsCompatible()) {
   //}
   this.showLayer = function(map,legendsParam,tLavel)
   {
      //var urlTemplate = 'http://intel2dual:87/cgi-bin/mapserv.exe?';
      //var urlTemplate = 'http://cyberswiftgis.servehttp.com:88/cgi-bin/mapserv.exe?';
      var urlTemplate = baseUrlForMapServerCall;
      urlTemplate += baseUrlForMapServerData+'state.map&';
      urlTemplate += 'layers=state_tot_case&';
      urlTemplate += 'mode=tile&';
      urlTemplate += 'tilemode=gmap&';
      urlTemplate += 'tile={X}+{Y}+{Z}';
		
      for(itr = 0; itr<6 ; itr++)
      {
         try
         {
            urlTemplate += '&V'+(itr+1)+'='+legendsParam[itr];
         }
         catch(e)
         {
            urlTemplate += '&V'+(itr+1)+'=-1';
            alert(itr+" - "+e);
         }
      }
		
      var tileLayer = new GTileLayer(null,0,18,{
         tileUrlTemplate:urlTemplate,
         isPng:true,
         opacity:tLavel
      });
      stateTotalResDis = new GTileLayerOverlay(tileLayer);
      map.addOverlay(stateTotalResDis);
   }
   this.hideLayer = function(map)
   {
      map.removeOverlay(stateTotalResDis);
   }
}

function CS_LayerStateTotalTBPatient(map)
{
   var stateTotalTBPatient = null;
   var itr,len;
	
   this.showLayer = function(map,legendsParam,tLavel)
   {
      //var urlTemplate = 'http://intel2dual:87/cgi-bin/mapserv.exe?';
      var urlTemplate = baseUrlForMapServerCall;
      urlTemplate += baseUrlForMapServerData+'state.map&';
      urlTemplate += 'layers=state_tot_tb_case&';
      urlTemplate += 'mode=tile&';
      urlTemplate += 'tilemode=gmap&';
      urlTemplate += 'tile={X}+{Y}+{Z}';
		
      for(itr = 0; itr<6 ; itr++)
      {
         try
         {
            urlTemplate += '&V'+(itr+1)+'='+legendsParam[itr];
         }
         catch(e)
         {
            urlTemplate += '&V'+(itr+1)+'=-1';
            alert(itr+" - "+e);
         }
      }
		
      var tileLayer = new GTileLayer(null,0,18,{
         tileUrlTemplate:urlTemplate,
         isPng:true,
         opacity:tLavel
      });
      stateTotalTBPatient = new GTileLayerOverlay(tileLayer);
      map.addOverlay(stateTotalTBPatient);
   }
   this.hideLayer = function(map)
   {
      map.removeOverlay(stateTotalTBPatient);
   }
}

function CS_LayerStateTotalCancerRecord(map)
{
   var stateTotalTBPatient = null;
   var itr,len;
	
   this.showLayer = function(map,legendsParam,tLavel)
   {
      var urlTemplate = baseUrlForMapServerCall;
      urlTemplate += baseUrlForMapServerData+'state.map&';
      urlTemplate += 'layers=state_cancer_data&';
      urlTemplate += 'mode=tile&';
      urlTemplate += 'tilemode=gmap&';
      urlTemplate += 'tile={X}+{Y}+{Z}';
		
      for(itr = 0; itr<6 ; itr++)
      {
         try
         {
            urlTemplate += '&V'+(itr+1)+'='+legendsParam[itr];
         }
         catch(e)
         {
            urlTemplate += '&V'+(itr+1)+'=-1';
            alert(itr+" - "+e);
         }
      }
		
      //alert(urlTemplate);
		
      var tileLayer = new GTileLayer(null,0,18,{
         tileUrlTemplate:urlTemplate,
         isPng:true,
         opacity:tLavel
      });
      stateTotalTBPatient = new GTileLayerOverlay(tileLayer);
      map.addOverlay(stateTotalTBPatient);
   }
   this.hideLayer = function(map)
   {
      map.removeOverlay(stateTotalTBPatient);
   }
}

function CS_LayerStateWasteWater(map)
{
   var stateTotalWasteWater = null;
   var itr,len;
	
   this.showLayer = function(map,legendsParam,tLavel)
   {
      var urlTemplate = baseUrlForMapServerCall;
      urlTemplate += baseUrlForMapServerData+'state.map&';
      urlTemplate += 'layers=state_waste_water&';
      urlTemplate += 'mode=tile&';
      urlTemplate += 'tilemode=gmap&';
      urlTemplate += 'tile={X}+{Y}+{Z}';
		
      for(itr = 0; itr<6 ; itr++)
      {
         try
         {
            urlTemplate += '&V'+(itr+1)+'='+legendsParam[itr];
         }
         catch(e)
         {
            urlTemplate += '&V'+(itr+1)+'=-1';
            alert(itr+" - "+e);
         }
      }
		
      //alert(urlTemplate);
		
      var tileLayer = new GTileLayer(null,0,18,{
         tileUrlTemplate:urlTemplate,
         isPng:true,
         opacity:tLavel
      });
      stateTotalWasteWater = new GTileLayerOverlay(tileLayer);
      map.addOverlay(stateTotalWasteWater);
   }
   this.hideLayer = function(map)
   {
      map.removeOverlay(stateTotalWasteWater);
   }
}

function CS_Shape(lbl, gLatLng, property)
{
   var label = lbl;
   var polygon = null;

   /*
	 * property[0] = '#CCFFCC'; // Color code of Polygon border property[1] = 1; //
	 * Border Thickness property[2] = .6; // Border Opacity property[3] =
	 * '#CCFFCC'; // Polygon background color property[4] = .4, // Polygon
	 * background opacity
	 */
   polygon = new GPolygon(gLatLng, // Array of GLatLong
      property[0], // Color code of Polygon border
      property[1], // Border Thickness
      property[2], // Border Opacity
      property[3], // Polygon background colour
      property[4], // Polygon background opacity
      false);

   this.drawShape = function(map)
   {
      // alert(polygon.isHidden());
      if (polygon.isHidden())
      {
         polygon.show();
      }
      else
      {
         map.addOverlay(polygon);
      }
   }

   this.removeShape = function(map)
   {
      map.removeOverlay(polygon);
   }

   this.hideShape = function(map)
   {
      polygon.hide();
   }
}

function CS_PollutionAirRest(map,markerDetails)
{
   var addedToMapFlag = false;

   var markerCluster = null;
   var markers = [];
   var cIcon = null;

   var tmpTime = null;
	
   if(map != null && markerDetails != null)
   {
      tmpTime = new Date().getTime();
		
      try
      {
         len = markerDetails.length;

         markers = new Array();
         var i,len;
         for(i=0; i<len ;i++)
         {
				
            cIcon = new GIcon(G_DEFAULT_ICON);
            cIcon.image = markerDetails[i][2];
            cIcon.shadow = "";
            cIcon.iconSize = new GSize(9, 16);
            cIcon.iconAnchor = new GPoint(4, 16);
				
            var tempMarker =  createMarker(markerDetails[i][0],{
               icon :cIcon,
               title :markerDetails[i][1]
               },markerDetails[i][3]);
            markers.push(tempMarker);
         }
      //alert("Headquarter Layer Time : ["+tmpTime+"] : "+(new Date().getTime()-tmpTime));
      }
      catch(e)
      {
         alert(e);
      }
   }
   else
   {
   //alert("Headquarter Marker Layer Null");
   }
	
   function createMarker(point,markerOptions,html)
   {
      var marker = new GMarker(point,markerOptions);
      GEvent.addListener(marker,"click",function()
      {         
         marker.openInfoWindowHtml(html);
      });
      return marker;
   }
	
   this.showClusterMarkers = function(map)
   {
      markerCluster = new MarkerClusterer(map.getMap(), markers);
      markerCluster.getAllMarkersBound(map.getMap(), markers);
   }
	
   this.removeClusterMarkers = function(map)
   {
      markerCluster.clearMarkers();
   }
}

function CS_MarkersPollutionWater(map,markerDetails)
{
   var addedToMapFlag = false;

   var markerCluster = null;
   var markers = [];
   var cIcon = null;

   var tmpTime = null;
	
   if(map != null && markerDetails != null)
   {
      tmpTime = new Date().getTime();
				
      try
      {
         len = markerDetails.length;

         markers = new Array();
         var i,len;
         for(i=0; i<len ;i++)
         {
				
            cIcon = new GIcon(G_DEFAULT_ICON);
            cIcon.image = markerDetails[i][2];
            cIcon.shadow = "";
            cIcon.iconSize = new GSize(9, 16);
            cIcon.iconAnchor = new GPoint(4, 16);
				
            var tempMarker =  createMarker(markerDetails[i][0],{
               icon :cIcon,
               title :markerDetails[i][1]
               },markerDetails[i][3]);
            markers.push(tempMarker);
         }
      //alert("Headquarter Layer Time : ["+tmpTime+"] : "+(new Date().getTime()-tmpTime));
      }
      catch(e)
      {
         alert(e);
      }
   }
   else
   {
   //alert("Headquarter Marker Layer Null");
   }
	
   function createMarker(point,markerOptions,html)
   {
      var marker = new GMarker(point,markerOptions);
      GEvent.addListener(marker,"click",function()
      {
         marker.openInfoWindowHtml(html);
      });
      return marker;
   }
	
   this.showClusterMarkers = function(map)
   {
      markerCluster = new MarkerClusterer(map.getMap(), markers);
      markerCluster.getAllMarkersBound(map.getMap(), markers);
   }
	
   this.removeClusterMarkers = function(map)
   {
      markerCluster.clearMarkers();
   }
}

function CS_MarkersWasteWater(map,markerDetails)
{
   var addedToMapFlag = false;

   var markerCluster = null;
   var markers = [];
   var cIcon = null;

   var tmpTime = null;
	
   if(map != null && markerDetails != null)
   {
      tmpTime = new Date().getTime();
				
      try
      {
         len = markerDetails.length;

         markers = new Array();
         var i,len;
         for(i=0; i<len ;i++)
         {
				
            cIcon = new GIcon(G_DEFAULT_ICON);
            cIcon.image = markerDetails[i][2];
            cIcon.shadow = "";
            cIcon.iconSize = new GSize(9, 16);
            cIcon.iconAnchor = new GPoint(4, 16);
				
            var tempMarker =  createMarker(markerDetails[i][0],{
               icon :cIcon,
               title :markerDetails[i][1]
               },markerDetails[i][3]);
            markers.push(tempMarker);
         }
      //alert("Headquarter Layer Time : ["+tmpTime+"] : "+(new Date().getTime()-tmpTime));
      }
      catch(e)
      {
         alert(e);
      }
   }
   else
   {
   //alert("Headquarter Marker Layer Null");
   }
	
   function createMarker(point,markerOptions,html)
   {
      var marker = new GMarker(point,markerOptions);
      GEvent.addListener(marker,"click",function()
      {
         marker.openInfoWindowHtml(html);
      });
      return marker;
   }
	
   this.showClusterMarkers = function(map)
   {
      markerCluster = new MarkerClusterer(map.getMap(), markers);
      markerCluster.getAllMarkersBound(map.getMap(), markers);
   }
	
   this.removeClusterMarkers = function(map)
   {
      markerCluster.clearMarkers();
   }
}

function CS_MarkersHeadQuarters(map,markerDetails)
{
   var addedToMapFlag = false;

   var markerCluster = null;
   var markers = [];
   var cIcon = null;

   var tmpTime = null;
	
   if(map != null && markerDetails != null)
   {
      tmpTime = new Date().getTime();
		
      len = markerDetails.length;

      markers = new Array();
      try
      {
         var i,len;
         for(i=0; i<len ;i++)
         {
				
            cIcon = new GIcon(G_DEFAULT_ICON);
            cIcon.image = markerDetails[i][2];
            cIcon.shadow = "";
            cIcon.iconSize = new GSize(9, 16);
            cIcon.iconAnchor = new GPoint(4, 16);
				
            var tempMarker =  createMarker(markerDetails[i][0],{
               icon :cIcon,
               title :markerDetails[i][1]
               },markerDetails[i][3]);
            markers.push(tempMarker);
         }
      //alert("Headquarter Layer Time : ["+tmpTime+"] : "+(new Date().getTime()-tmpTime));
      }
      catch(e)
      {
         alert(e);
      }
   }
   else
   {
   //alert("Headquarter Marker Layer Null");
   }
	
   function createMarker(point,markerOptions,html)
   {
      var marker = new GMarker(point,markerOptions);
      GEvent.addListener(marker,"click",function()
      {
         marker.openInfoWindowHtml(html);
      });
      return marker;
   }
	
   this.showClusterMarkers = function(map)
   {
      markerCluster = new MarkerClusterer(map.getMap(), markers);
   }
	
   this.removeClusterMarkers = function(map)
   {
      markerCluster.clearMarkers();
   }
}

function CS_GGWNitrateMarkers(map,markerDetails)
{
   var addedToMapFlag = false;

   //var gLatLng = null;
   //var details = null;
   var markerCluster = null;
   var markers = [];
   var cIcon = null;
   //var htmlText = null;
	
   //var tempMarker = null;
   var tmpTime = null;
	
   if(map != null && markerDetails != null)
   {
      tmpTime = new Date().getTime();
      len = markerDetails.length;

      markers = new Array();
      try
      {
         var i,len;
         for(i=0; i<len ;i++)
         {
            //tempMarker = null;
            var gLatLng = markerDetails[i][0];
            var details = markerDetails[i][1];
				
            cIcon = new GIcon(G_DEFAULT_ICON);
            cIcon.image = details[4];
            cIcon.shadow = "";
            cIcon.iconSize = new GSize(9, 16);
            cIcon.iconAnchor = new GPoint(4, 16);
				
            var htmlText = '<table width="200px" border="0" cellspacing="2" cellpadding="0" class="infoWindow">'+
            '<tr><td width="40%" class="label">Location:</td>'+
            '<td width="60%">'+details[0]+'</td>'+
            '</tr><tr><td class="label">State:</td>'+
            '<td>'+details[1]+'</td>'+
            '</tr><tr><td class="label">District:</td>'+
            '<td>'+details[2]+'</td>'+
            '</tr><tr><td class="label">Nitrate:</td>'+
            '<td>'+details[3]+'</td>'+
            '</tr></table>';
				
            var tempMarker =  createMarker(gLatLng,{
               icon :cIcon,
               title :details[3]
               },htmlText);
            markers.push(tempMarker);
         //map.addOverlay(tempMarker);
         }
      //alert("Layer Processing Time : ["+tmpTime+"] : "+(new Date().getTime()-tmpTime));
      }
      catch(e)
      {
         alert(e);
      }
   }
   else
   {
   //alert("Map or Marker Layer Null");
   }
	
   function createMarker(point,markerOptions,html)
   {
      var marker = new GMarker(point,markerOptions);
      GEvent.addListener(marker,"click",function()
      {
         marker.openInfoWindowHtml(html);
      });
      return marker;
   }
	
   this.showClusterMarkers = function(map)
   {
      markerCluster = new MarkerClusterer(map.getMap(), markers);
      markerCluster.getAllMarkersBound(map.getMap(), markers);
   }
	
   this.showMarker = function(map)
   {
      //alert("Called 2a");
      var iS,lenS;
      if(markers != null)
      {
         lenS = markers.length;
         for(iS = 0 ; iS<lenS ; iS++)
         {
            //map.addOverlay(markers[iS]);
            markers[iS].show();
         }
      }
   }

   this.removeClusterMarkers = function(map)
   {
      markerCluster.clearMarkers();
   }
	
   this.hideMarker = function()
   {
      //alert("Called 2b");
      var iH,lenH;
      if(markers != null)
      {
         lenH = markers.length;
         for(iH = 0 ; iH<lenH ; iH++)
         {
            //map.removeOverlay(markers[iH]);
            markers[iH].hide();
         }
      }
   }
}

function CS_GGWArsenicMarkers(map,markerDetails)
{
   var addedToMapFlag = false;

   //var gLatLng = null;
   //var details = null;
   var markerCluster = null;
   var markers = [];
   var cIcon = null;
   //var htmlText = null;
	
   //var tempMarker = null;
   var tmpTime = null;
	
   if(map != null && markerDetails != null)
   {
      tmpTime = new Date().getTime();
      len = markerDetails.length;

      markers = new Array();
      try
      {
         var i,len;
         for(i=0; i<len ;i++)
         {
            //tempMarker = null;
            var gLatLng = markerDetails[i][0];
            var details = markerDetails[i][1];
								
            cIcon = new GIcon(G_DEFAULT_ICON);
            cIcon.image = details[4];
            cIcon.shadow = "";
            cIcon.iconSize = new GSize(9, 16);
            cIcon.iconAnchor = new GPoint(4, 16);
				
            var htmlText = '<table width="200px" border="0" cellspacing="2" cellpadding="0" class="infoWindow">'+
            '<tr><td width="40%" class="label">Location:</td>'+
            '<td width="60%">'+details[0]+'</td>'+
            '</tr><tr><td class="label">State:</td>'+
            '<td>'+details[1]+'</td>'+
            '</tr><tr><td class="label">District:</td>'+
            '<td>'+details[2]+'</td>'+
            '</tr><tr><td class="label">Arsenic:</td>'+
            '<td>'+((details[3]!= '0.0')?details[3]:"Below Detectable Level")+'</td>'+
            '</tr></table>';
				
            var tempMarker =  createMarker(gLatLng,{
               icon :cIcon,
               title :details[3]
               },htmlText);
            markers.push(tempMarker);
         //map.addOverlay(tempMarker);
         }
      //alert("Layer Processing Time : ["+tmpTime+"] : "+(new Date().getTime()-tmpTime));
      }
      catch(e)
      {
         alert(e);
      }
   }
   else
   {
   //alert("Map or Marker Layer Null");
   }
	
   function createMarker(point,markerOptions,html)
   {
      var marker = new GMarker(point,markerOptions);
      GEvent.addListener(marker,"click",function()
      {
         marker.openInfoWindowHtml(html);
      });
      return marker;
   }
	
   this.showClusterMarkers = function(map)
   {
      markerCluster = new MarkerClusterer(map.getMap(), markers);
      markerCluster.getAllMarkersBound(map.getMap(), markers);
   }
	
   this.showMarker = function(map)
   {
      //alert("Called 2a");
      var iS,lenS;
      if(markers != null)
      {
         lenS = markers.length;
         for(iS = 0 ; iS<lenS ; iS++)
         {
            //map.addOverlay(markers[iS]);
            markers[iS].show();
         }
      }
   }

   this.removeClusterMarkers = function(map)
   {
      markerCluster.clearMarkers();
   }
	
   this.hideMarker = function()
   {
      //alert("Called 2b");
      var iH,lenH;
      if(markers != null)
      {
         lenH = markers.length;
         for(iH = 0 ; iH<lenH ; iH++)
         {
            //map.removeOverlay(markers[iH]);
            markers[iH].hide();
         }
      }
   }
}

function CS_Legends(minm,maxm,divId,className,label,type)
{
	
   var legStrStart = '<div id="'+divId+'"><ul class="'+className+'"><li class="header">'+label+'</li>';
   var legStrEnd = '</ul><div style="height:1px; clear:both"></div></div>';
	
   var colourParams = ['255,108,118','254,189,75','254,247,46','39,251,114','108,111,205','10,10,10'];
   var legendIcons = ["images/map/mrkr_green.gif",
   "images/map/mrkr_blue.gif",
   "images/map/mrkr_violet.gif",
   "images/map/mrkr_orange.gif",
   "images/map/mrkr_red.gif"];
	
   var squeareLegendIcons = ["images/map/sqr_mrkr/mrkr_sqr_green.gif",
   "images/map/sqr_mrkr/mrkr_sqr_blue.gif",
   "images/map/sqr_mrkr/mrkr_sqr_violet.gif",
   "images/map/sqr_mrkr/mrkr_sqr_orange.gif",
   "images/map/sqr_mrkr/mrkr_sqr_red.gif"];
	
   var v1;
   var v2;
   var v3;
   var v4;
   var v5;
   var v6;
	
   this.isInitialized = function()
   {
      if(v1 != null && v2 != null && v1 != '' && v2 != '')
      {
         return true;
      }
      else
      {
         return false;
      }
   }
	
   this.defaultInitialize = function(divitions)
   {
      var i;
      if(divitions <= 5)
      {
         v1 = minm;
         for(i=2 ; i <= divitions ; i++)
         {
            eval("v"+i+"="+(parseInt(minm)+parseInt((maxm-minm)/(divitions))*(i-1)));
         }
         eval("v"+(divitions+1)+" = maxm");
      }
      else
      {
         this.defaultInitialize(5);
      }
   }
	
   this.getLegendStringMarker = function(divId,styleClass)
   {
      var legendString = legStrStart;
		
      if((v1 != null && v1 != '') && (v2 != null && v2 != ''))
      {
         legendString += '<li style="padding-left:10px"><img src="'+absPath+legendIcons[0]
         +'" border="0" style="float:left" /><div style="float:left; border:none; position:static">&nbsp;&nbsp;'
         +v1+' - '+v2+'</div></li>';
      }
      if((v2 != null && v2 != '') && (v3 != null && v3 != ''))
      {
         legendString += '<li style="padding-left:10px"><img src="'+absPath+legendIcons[1]
         +'" border="0" style="float:left" /><div style="float:left; border:none; position:static">&nbsp;&nbsp;'
         +v2+' - '+v3+'</div></li>';
      }
      if((v3 != null && v3 != '') && (v4 != null && v4 != ''))
      {
         legendString += '<li style="padding-left:10px"><img src="'+absPath+legendIcons[2]
         +'" border="0" style="float:left" /><div style="float:left; border:none; position:static">&nbsp;&nbsp;'
         +v3+' - '+v4+'</div></li>';
      }
      if((v4 != null && v4 != '') && (v5 != null && v5 != ''))
      {
         legendString += '<li style="padding-left:10px"><img src="'+absPath+legendIcons[3]
         +'" border="0" style="float:left" /><div style="float:left; border:none; position:static">&nbsp;&nbsp;'
         +v4+' - '+v5+'</div></li>';
      }
      if((v5 != null && v5 != '') && (v6 != null && v6 != ''))
      {
         legendString += '<li style="padding-left:10px"><img src="'+absPath+legendIcons[4]
         +'" border="0" style="float:left" /><div style="float:left; border:none; position:static">&nbsp;&nbsp;'
         +v5+' - '+v6+'</div></li>';
      }
      //legendString += '<li style="padding-left:10px"><img src='+legendIcons[5]+'" border="0" /><div style="float:left; border:none; position:static">&nbsp;&nbsp;No Data</div></li>';
		
      //legendString += '<li style="text-align:right"><a href="javascript:openDynamicThemeLightBox(\''+minm+'\',\''+maxm+'\',\''+label+'\',\''+type+'\')">Change Legend Intervals</a></li>';
      legendString += legStrEnd;
		
      return legendString;
   }
   
   this.getLegendStringMarkerSqueare = function(divId,styleClass)
   {
      var legendString = legStrStart;
		
      if((v1 != null && v1 != '') && (v2 != null && v2 != ''))
      {
         legendString += '<li style="padding-left:10px"><img src="'+absPath+squeareLegendIcons[0]+'" border="0" style="float:left" /><div style="float:left; border:none; position:static">&nbsp;&nbsp;'+v1+' - '+v2+'</div></li>';
      }
      if((v2 != null && v2 != '') && (v3 != null && v3 != ''))
      {
         legendString += '<li style="padding-left:10px"><img src="'+absPath+squeareLegendIcons[1]+'" border="0" style="float:left" /><div style="float:left; border:none; position:static">&nbsp;&nbsp;'+v2+' - '+v3+'</div></li>';
      }
      if((v3 != null && v3 != '') && (v4 != null && v4 != ''))
      {
         legendString += '<li style="padding-left:10px"><img src="'+absPath+squeareLegendIcons[2]+'" border="0" style="float:left" /><div style="float:left; border:none; position:static">&nbsp;&nbsp;'+v3+' - '+v4+'</div></li>';
      }
      if((v4 != null && v4 != '') && (v5 != null && v5 != ''))
      {
         legendString += '<li style="padding-left:10px"><img src="'+absPath+squeareLegendIcons[3]+'" border="0" style="float:left" /><div style="float:left; border:none; position:static">&nbsp;&nbsp;'+v4+' - '+v5+'</div></li>';
      }
      if((v5 != null && v5 != '') && (v6 != null && v6 != ''))
      {
         legendString += '<li style="padding-left:10px"><img src="'+absPath+squeareLegendIcons[4]+'" border="0" style="float:left" /><div style="float:left; border:none; position:static">&nbsp;&nbsp;'+v5+' - '+v6+'</div></li>';
      }
      //legendString += '<li style="padding-left:10px"><img src='+squeareLegendIcons[5]+'" border="0" /><div style="float:left; border:none; position:static">&nbsp;&nbsp;No Data</div></li>';
		
      //legendString += '<li style="text-align:right"><a href="javascript:openDynamicThemeLightBox(\''+minm+'\',\''+maxm+'\',\''+label+'\',\''+type+'\')">Change Legend Intervals</a></li>';
      legendString += legStrEnd;
		
      return legendString;
   }

   this.getMarkerIcon = function(value)
   {
      if(value >= v1 && value < v2)
      {
         return absPath+legendIcons[0];
      }
      else if(value >= v2 && value < v3)
      {
         return absPath+legendIcons[1];
      }
      else if(value >= v3 && value < v4)
      {
         return absPath+legendIcons[2];
      }
      else if(value >= v4 && value < v5)
      {
         return absPath+legendIcons[3];
      }
      else if(value >= v5 && value <= v6)
      {
         return absPath+legendIcons[4];
      }
      else
      {
         return "";
      }
   }
   this.getSquareMarkerIcon = function(value)
   {
      if(value >= v1 && value < v2)
      {
         return absPath+squeareLegendIcons[0];
      }
      else if(value >= v2 && value < v3)
      {
         return absPath+squeareLegendIcons[1];
      }
      else if(value >= v3 && value < v4)
      {
         return absPath+squeareLegendIcons[2];
      }
      else if(value >= v4 && value < v5)
      {
         return absPath+squeareLegendIcons[3];
      }
      else if(value >= v5 && value <= v6)
      {
         return absPath+squeareLegendIcons[4];
      }
      else
      {
         return "";
      }
   }

   this.getLegendString = function(divId,styleClass)
   {
      var legendString = legStrStart;
		
      if((v1 != null && v1 != '') && (v2 != null && v2 != ''))
      {
         legendString += '<li style="padding-left:10px"><div style="width:14px; height:14px; float:left; background:rgb('
         +  colourParams[0]+')" ></div><div style="float:left; border:none; position:static">&nbsp;&nbsp;'
         +v1+' - '+v2+'</div></li>';
      }

      if((v2 != null && v2 != '') && (v3 != null && v3 != ''))
      {
         legendString += '<li style="padding-left:10px"><div style="width:14px; height:14px; float:left; background:rgb('
         +colourParams[1]+')" ></div><div style="float:left; border:none; position:static">&nbsp;&nbsp;'
         +v2+' - '+v3+'</div></li>';
      }

      if((v3 != null && v3 != '') && (v4 != null && v4 != ''))
      {
         legendString += '<li style="padding-left:10px"><div style="width:14px; height:14px; float:left; background:rgb('
         +colourParams[2]+')" ></div><div style="float:left; border:none; position:static">&nbsp;&nbsp;'
         +v3+' - '+v4+'</div></li>';
      }

      if((v4 != null && v4 != '') && (v5 != null && v5 != ''))
      {
         legendString += '<li style="padding-left:10px"><div style="width:14px; height:14px; float:left; background:rgb('
         +colourParams[3]+')" ></div><div style="float:left; border:none; position:static">&nbsp;&nbsp;'
         +v4+' - '+v5+'</div></li>';
      }

      if((v5 != null && v5 != '') && (v6 != null && v6 != ''))
      {
         legendString += '<li style="padding-left:10px"><div style="width:14px; height:14px; float:left; background:rgb('
         +colourParams[4]+')" ></div><div style="float:left; border:none; position:static">&nbsp;&nbsp;'
         +v5+' - '+v6+'</div></li>';
      }
      
      legendString += '<li style="padding-left:10px"><div style="width:14px; height:14px; float:left; background:rgb('
      +colourParams[5]+')" ></div><div style="float:left; border:none; position:static">&nbsp;&nbsp;No Data</div></li>';
		
      legendString += '<li style="text-align:right"><a href="javascript:openDynamicThemeLightBox(\''+minm+'\',\''
      +maxm+'\',\''+label+'\',\''+type+'\')">Change Legend Intervals</a></li>';
      legendString += legStrEnd;
		
      return legendString;
   }
	
   this.getLegendArray = function()
   {
      var legendParamsArray = [];
      if(v1 != null && v1 != '')
      {
         legendParamsArray.push(v1);
      }

      if(v2 != null && v2 != '')
      {
         legendParamsArray.push(v2);
      }

      if(v3 != null && v3 != '')
      {
         legendParamsArray.push(v3);
      }

      if(v4 != null && v4 != '')
      {
         legendParamsArray.push(v4);
      }

      if(v5 != null && v5 != '')
      {
         legendParamsArray.push(v5);
      }

      if(v6 != null && v6 != '')
      {
         legendParamsArray.push(v6);
      }
		
      return legendParamsArray;
   }
	
   this.setV1 = function(v1f)
   {
      v1 = v1f;
   }

   this.getV1 = function()
   {
      return v1;
   }
	
   this.setV2 = function(v2f)
   {
      v2 = v2f;
   }

   this.getV2 = function()
   {
      return v2;
   }
	
   this.setV3 = function(v3f)
   {
      v3 = v3f;
   }

   this.getV3 = function()
   {
      return v3;
   }
	
   this.setV4 = function(v4f)
   {
      v4 = v4f;
   }

   this.getV4 = function()
   {
      return v4;
   }
	
   this.setV5 = function(v5f)
   {
      v5 = v5f;
   }

   this.getV5 = function()
   {
      return v5;
   }
	
   this.setV6 = function(v6f)
   {
      v6 = v6f;
   }

   this.getV6 = function()
   {
      return v6;
   }
}

function getCircle(center, radius, numPoints)
{
   poly = [];
   var lat = center.lat();
   var lng = center.lng();
   var d2r = Math.PI / 180; // degrees to radians
   var r2d = 180 / Math.PI; // radians to degrees
   var Clat = (radius / 3963) * r2d; // using 3963 as earth's radius
   var Clng = Clat / Math.cos(lat * d2r);

   // Add each point in the circle
   for ( var i = 0; i < numPoints; i++)
   {
      var theta = Math.PI * (i / (numPoints / 2));
      Cx = lng + (Clng * Math.cos(theta));
      Cy = lat + (Clat * Math.sin(theta));
      poly.push(new GLatLng(Cy, Cx));
   }
   // Add the first point to complete the circle
   poly.push(poly[0]);

   return poly;
}

function createLandMarkMarker(point, title, icon_url)
{
   var icon = new GIcon();
   icon.image = icon_url;
//   icon.iconSize = new GSize(32, 32);
   icon.iconAnchor = new GPoint(15, 32);
   icon.infoWindowAnchor = new GPoint(15, 1);
   var marker = new GMarker(point, {title: title, icon: icon});
   return marker;
}

function createAreaInfoPolygon(map, points, infoText)
{
   var poly = new GPolygon(points, "#000000", 2, 0, "#FFFFFF" ,0);
   poly.tooltip = infoText;
   if(infoText)
   {      
      GEvent.addListener(poly, "mouseover", function()
      {
         showTooltip(map, poly, poly.getBounds().getCenter());
      });
      GEvent.addListener(poly,"mouseout", function()
      {
         tooltip.style.display="none";
      });
   }
   return poly;
}

function showTooltip(map, object, latLng)
{
   tooltip.innerHTML = object.tooltip;
	var point = map.getCurrentMapType().getProjection().fromLatLngToPixel(map.fromDivPixelToLatLng(new GPoint(0,0),true),map.getZoom());
	var offset = map.getCurrentMapType().getProjection().fromLatLngToPixel(latLng, map.getZoom());
//	var anchor = marker.getIcon().iconAnchor;
//	var width = marker.getIcon().iconSize.width;
	var height = tooltip.clientHeight;
//	var pos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(offset.x - point.x - anchor.x + width, offset.y - point.y -anchor.y -height));
	var pos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(offset.x - point.x, offset.y - point.y - height));
//	pos.apply(tooltip);
	tooltip.style.display="";
}


