   /***
     This java script used to show google map.
	 Map initialize on home page.
	*/
	var commcity;
	function trim(stringToTrim) 
	{
		return stringToTrim.replace(/^\s+|\s+$/g,"");
	}
	
	function initialize(mapdata,maptype,communityid) 
	{
		
		
		var list = new Array() ;
	    var address;
		var dbcountry ='dbcountry';
		var dbcommunity ='dbcommunity';
		var communityname;
	    list = eval("("+mapdata+")");
		
		var zoomlevel = 3;
		if (GBrowserIsCompatible()) 
		{
				
			map = new GMap2(document.getElementById("map_canvas"));
			map.setCenter(new GLatLng(37.09024, -95.712891),3);
			map.addControl(new GSmallMapControl());  // Add control on google map
			map.addControl(new GMapTypeControl());   // Add control on google map
			geocoder     = new GClientGeocoder();
			point        = new GLatLng(37.09024, -95.712891);
			marker       = createInfoMarker(point,city);  //  user for create marker
				
		}
		
		if(maptype=='1' && communityid < 1)
		{
		    clearShapes();
		    for(var counter=0; counter < list.length ; counter++)
			{
				address = list[counter];
				var code='var geocoder_'+counter+'= new GClientGeocoder();if (geocoder_'+counter+'){geocoder_'+counter+'.getLatLng("'+address+'",function(point) {if (point) {marker['+counter+'] = createInfoMarkerHome(point,"'+address+'",'+counter+','+dbcountry+');map.addOverlay(marker['+counter+']);}});}';
				eval(code);
			
			}
		}
		else if(maptype=='2' || communityid > 0)
		{
			for(var counter=0; counter < list.length ; counter++)
			{
				clearShapes();
				address = list[counter][2]+' '+list[counter][4]+' '+list[counter][5]+' '+list[counter][6];
			    //alert(address);
				communityname = list[counter][8]+','+list[counter][7];
				//dbcity ='dbcity'+' '+list[counter][4];
				commcity = list[counter][4];
				var code='var geocoder_'+counter+'= new GClientGeocoder();if (geocoder_'+counter+'){geocoder_'+counter+'.getLatLng("'+address+'",function(point) {if (point) {map.setCenter(point,9);marker['+counter+'] = createInfoMarkerHome(point,"'+address+'","'+counter+'","'+dbcommunity+'","'+communityname+'");map.addOverlay(marker['+counter+']);}});}';
				eval(code);
			
			}
		}
	}
	
	 /***
	  Used to create marker.
	*/
	
   	function createInfoMarker(point, address) 
	{
		var tooltipmsg = address;
		//var mapURL   = document.getElementById('mapurl').value; 
      //  var webURL   = document.getElementById('weburl').value;
		baseIcon = new GIcon(G_DEFAULT_ICON);
				
	baseIcon.image = mapURL+'/mapicon.png';
		   
		markerOptions = {icon:baseIcon,title:tooltipmsg};
	    marker    = new GMarker(point,markerOptions);
		
		GEvent.addListener(marker, "click",
		function() {
			 var result = address.split(' ');
			 var len = result.length;
			 if(len ==1)
			 {
				 clearShapes();
				 callState();
				 document.getElementById('country').value = result[0];
				 getStateHome('3');
			 }
		});

	    return marker;
    }
	
	function createInfoMarkerHome(point, address,index,dummy,communtiymsg) 
	{
		//var mapURL   = document.getElementById('mapurl').value; 
      //  var webURL   = document.getElementById('weburl').value;
		var tooltipmsg = address;
		//var tempdummy = trim(dummy).split(' ');
		//dummy =  tempdummy[0];
		
		if(communtiymsg)
		{
			var communityres = communtiymsg.split(',');
			tooltipmsg = communityres[0]+', '+tooltipmsg ;
			communityId = communityres[1];
		}
		
		baseIcon = new GIcon(G_DEFAULT_ICON);
		/*baseIcon.image = mapURL+'/mapicon_home.png';*/		
		/*
    baseIcon.image = mapURL+'/google-icons/home.png';
        baseIcon.iconSize = new GSize(20, 20); 
				baseIcon.shadow = '';
        baseIcon.shadowSize = new GSize(0, 0);
    */
				
		markerOptions = {icon:baseIcon,title:tooltipmsg};
	    marker[index]    = new GMarker(point,markerOptions);
		
		GEvent.addListener(marker[index], "click",
		function() {
			
			 var result = trim(address).split(' ');
			
			 var len = result.length;
					
			 if(len == 1)
			 {
				 clearShapes();
				 document.getElementById('state').value = "";
				 document.getElementById('city').value = "";
				 document.getElementById('country').value = result[0];
				 callState();
				 getStateHome('3');
			 }
			
			 if(len == 2  )
			 {
				 clearShapes();
				 document.getElementById('city').value = "";
				 document.getElementById('country').value = result[0];
				 document.getElementById('state').value = result[1];
				 callCity();
				 getCityHome('5');
				 
			 }
			 
			 if(dummy =='dbcity')
			 {
								
				 if(commcity)
				 { 
				     clearShapes();
					 document.getElementById('city').value = commcity ;				
					 document.getElementById('country').value = result[0];
					 document.getElementById('state').value = result[1];
					 callCommunity();
					 getCommunity('9');
					
				 }
				 else
				 {
					
					 if(len == 3 || len == 4 )
					 {
						 clearShapes();
						 if(len==3)
						 {
							document.getElementById('city').value = result[2];
							
						 }
						 if(len==4)
						 {
							document.getElementById('city').value = result[2]+' '+result[3];
							
						 }
						 document.getElementById('country').value = result[0];
						 document.getElementById('state').value = result[1];
						 callCommunity();
						 getCommunity('9');
					 }
				 }
				 
			 }
			 
			 if(dummy =='dbcommunity')
			 {
				clearShapes();
				if(len >= 3 || len > 4 )
				{
					 var res = tooltipmsg.split(',');
					 moveToCommunityNew(res[0]);
				}
			 }
		});

	    return marker[index];
    }

    
  
   /***
	 Map initialize on community page.
   */
  
  //function showcommunity(communityaddress,useraddress)
  function showcommunity(communityaddress)
  {
		if (GBrowserIsCompatible())
		{
			map = new GMap2(document.getElementById("map_canvas"));
			map.addControl(new GSmallMapControl());
			map.addControl(new GMapTypeControl());
			geocoder     = new GClientGeocoder();
			communityAddress(communityaddress);
			//userAddress(useraddress);
		}
  }
  
  /***
	 This function show the community marker .
  */
  
  function communityAddress(communityaddress)
  {
	
	
	if (geocoder) 
	{
		geocoder.getLatLng(
		  communityaddress,
		  function(point) {
			map.setCenter(point,11);
			marker = createInfoMarker(point, communityaddress);  //  user for create marker
			var point    = marker.getLatLng();
			var center   = point;
			radius       = 1.609344*communityradius;
			createCircle = drawCricleSearch(radius, center);
		  }
		);
	  }
  }
  
    /***
	 This function show the community user .
  */
  
  
  function userAddress(useraddress)
  {
	var list = new Array() ;
	var address;
	list = eval("("+useraddress+")");
	if(list )
	{
		var len = list.length;
		for(var counter=0 ; counter < len ; counter++)
		{
			address = list[counter][2]+' '+list[counter][4]+' '+list[counter][5]+' '+list[counter][6];
			
			//username=list[counter][11];
			username="<div style='font-size:10px;'><b>Name</b> : "+list[counter][11]+" <br/> <b>Address</b> : ";
			if(list[counter][2])
			{
				username+=list[counter][2];
			}
			username+="<br/>"+list[counter][4]+" "+list[counter][5]+" "+list[counter][6];			
			username+=" </div>";
			
	
			var code='var geocoder_'+counter+'= new GClientGeocoder();if (geocoder_'+counter+'){geocoder_'+counter+'.getLatLng("'+address+'",function(point) {if (point) {marker['+counter+'] = createInfoMarkerCommunity(point,"'+address+'","'+username+'",'+counter+');map.addOverlay(marker['+counter+']);}});}';
			eval(code);
		}
	}
  }
  
function createInfoMarkerCommunity(point,address, username,i)
{
	//var mapURL   = document.getElementById('mapurl').value; 
   // var webURL   = document.getElementById('weburl').value;
	var tooltipmsg = username+', '+address;
	baseIcon = new GIcon(G_DEFAULT_ICON);
	//baseIcon.image = mapURL+'/mapicon.png';
  
  baseIcon.image = mapURL+'/google-icons/person.png';
        baseIcon.iconSize = new GSize(20, 20); 
					baseIcon.shadow = '';
        baseIcon.shadowSize = new GSize(0, 0);
  		
	markerOptions = {icon:baseIcon};
	marker[i]    = new GMarker(point,markerOptions);	
	GEvent.addListener(marker[i], "click", function() {
	var msg =username;											 
	map.openInfoWindow(point,msg);
	});
	
	return marker[i];
}
  
  
	
	 /***
	 This function used to draw the circle around community member .
  	*/
  
	function drawCricleSearch(radius,center) // draw a circle
	{
		var latOffset = 0.01;
		var lonOffset = 0.01;
		var latConv   = center.distanceFrom(new GLatLng(center.lat()+0.1,center.lng()))/100;
		var lngConv   = center.distanceFrom(new GLatLng(center.lat(),center.lng()+0.1))/100;
		// nodes = number of points to create circle polygon
		var nodes = 40;
		//Loop
		var points = [];
		var step = parseInt(360/nodes)||10;
		for(var i=0; i<=360; i+=step)
		{
			var pint = new GLatLng(center.lat() + (radius/latConv * Math.cos(i* Math.PI/180)), center.lng() + (radius/lngConv * Math.sin(i *Math.PI/180)));
			// push pints into points array
			points.push(pint);
		}
		var polygon = new GPolygon(points, "#f33f33", 1, 1, "#ff0033",0.1);
		map.addOverlay(polygon);
		return polygon;
	}
	
	
	function getStateHome(zoomlevel)
	{
		
        var mapflag   = document.getElementById('mapflag').value;
		if(mapflag==1)
		{
			clearShapes();
			
		}
		zoomlevel = 3;
		var dbstate = 'dbstate';
		var	communityname ="";
		
		country = document.getElementById('country').value;
		
		if(country=='-')
		{
			$.ajax(
			{
			type: "GET",
			url: webURL+'/community/getMapCountry',
			data:'',
			success:function(msg)
			{
				var list = new Array();
				var address;
				var dbcountry ='dbcountry';
				list = eval("("+msg+")");
				if(list!="")
				{
					for(var counter=0 ; counter < list.length ; counter++)
					{
						address = list[counter];
			var code='var geocoder_'+counter+'= new GClientGeocoder();if (geocoder_'+counter+'){geocoder_'+counter+'.getLatLng("'+address+'",function(point) {if (point) {map.setCenter(point,'+zoomlevel+');marker['+counter+'] = createInfoMarkerHome(point,"'+address+'",'+counter+','+dbcountry+');map.addOverlay(marker['+counter+']);}});}';
			eval(code);
					}
				}
			}
			});
		}
		else
		{
			$.ajax(
			{
			type: "GET",
			url: webURL+'/community/getState/'+country,
			data:'',
			success:function(msg)
			{
				var list = new Array();
				var address;
				
				list = eval("("+msg+")");
				if(list!="")
				{
					for(var counter=0 ; counter < list.length ; counter++)
					{
						clearShapes();
						address = country+' '+list[counter];
						//alert(address);
						var code='var geocoder_'+counter+'= new GClientGeocoder();if (geocoder_'+counter+'){geocoder_'+counter+'.getLatLng("'+address+'",function(point) {if (point) {map.setCenter(point,'+zoomlevel+');marker['+counter+'] = createInfoMarkerHome(point,"'+address+'",'+counter+','+dbstate+',"'+communityname+'");map.addOverlay(marker['+counter+']);}});}';
						eval(code);
					}
				}
				else
				{
					address = country;
					if (geocoder) 
					{
						geocoder.getLatLng(
						  address,
						  function(point) {
							if (!point) {
							 // alert(address + " not found");
							} else {
								clearShapes();
								map.setCenter(point,3);
								marker[0] = createInfoMarkerHome(point, address,0,dbstate,communityname);  //  user for create marker
								map.addOverlay(marker[0]);
							}
						  }
						);
					 }
				}
			}
			});
		}
	}
	
	
	function getCityHome(zoomlevel)
	{
		//var webURL   = document.getElementById('weburl').value;

		zoomlevel = 5;
		clearShapes();
		country = document.getElementById('country').value;
		state = document.getElementById('state').value;
		if(country!='-' && state=='-')
		{
			
			$.ajax(
			{
			type: "GET",
			url: webURL+'/community/getState/'+country,
			data:'',
			success:function(msg)
			{
				var list = new Array();
				var address;
				var dbstate ='dbstate';
				list = eval("("+msg+")");
				if(list!="")
				{
					for(var counter=0 ; counter < list.length ; counter++)
					{
						clearShapes();
						address = country+' '+list[counter];
						var code='var geocoder_'+counter+'= new GClientGeocoder();if (geocoder_'+counter+'){geocoder_'+counter+'.getLatLng("'+address+'",function(point) {if (point) {map.setCenter(point,3);marker['+counter+'] = createInfoMarkerHome(point,"'+address+'",'+counter+','+dbstate+');map.addOverlay(marker['+counter+']);}});}';
						eval(code);
					}
				}
			}
			});
		}
		else
		{
			$.ajax(
			{
			type: "GET",
			url: webURL+'/community/getCity/'+country+'/'+state,
			data:'',
			success:function(msg)
			{
				var list = new Array();
				var address;
				var dbcity='dbcity';
				var communityname ="";
				list = eval("("+msg+")");
				if(list!="")
				{
					for(var counter=0 ; counter < list.length ; counter++)
					{
						clearShapes();
						address = country+' '+state+' '+list[counter];
							
						var code='var geocoder_'+counter+'= new GClientGeocoder();if (geocoder_'+counter+'){geocoder_'+counter+'.getLatLng("'+address+'",function(point) {if (point) {map.setCenter(point,'+zoomlevel+');marker['+counter+'] = createInfoMarkerHome(point,"'+address+'",'+counter+','+dbcity+',"'+communityname+'");map.addOverlay(marker['+counter+']);}});}';
						eval(code);
					}
				}
				else
				{
					address = country;
					if (geocoder) 
					{
						geocoder.getLatLng(
						  address,
						  function(point) {
							if (!point) {
							 // alert(address + " not found");
							} else {
								clearShapes();
								map.setCenter(point,3);
								marker[0] = createInfoMarkerHome(point, address,0,dbcity, communityname);  //  user for create marker
								map.addOverlay(marker[0]);
							}
						  }
						);
					 }
				}
			}
			});
		}
	}
	
	
	/***
	 This function get all  the community and show on google map .
  */
	
  function getCommunity(zoomlevel)
  	{
		//var webURL   = document.getElementById('weburl').value;
		zoomlevel = 9;
		clearShapes();
		country = document.getElementById('country').value;
		state = document.getElementById('state').value;
		city = document.getElementById('city').value;
		if(city=='-')
		{
			
			$.ajax(
			{
			type: "GET",
			url: webURL+'/community/getCity/'+country+'/'+state,
			data:'',
			success:function(msg)
			{
				var list = new Array();
				var address;
				var dbcity='dbcity';
				var communityname ="";
				list = eval("("+msg+")");
				if(list!="")
				{
					for(var counter=0 ; counter < list.length ; counter++)
					{
						clearShapes();
						address = country+' '+state+' '+list[counter];
							
						var code='var geocoder_'+counter+'= new GClientGeocoder();if (geocoder_'+counter+'){geocoder_'+counter+'.getLatLng("'+address+'",function(point) {if (point) {map.setCenter(point,5);marker['+counter+'] = createInfoMarkerHome(point,"'+address+'",'+counter+','+dbcity+');map.addOverlay(marker['+counter+']);}});}';
						eval(code);
					}
				}
				else
				{
					address = country;
					if (geocoder) 
					{
						geocoder.getLatLng(
						  address,
						  function(point) {
							if (!point) {
							 // alert(address + " not found");
							} else {
								clearShapes();
								map.setCenter(point,3);
								marker[0] = createInfoMarkerHome(point, address,0,dbcity, communityname);  //  user for create marker
								map.addOverlay(marker[0]);
							}
						  }
						);
					 }
				}
			}
			});
		
		}
		else
		{
			$.ajax(
			{
			type: "GET",
			url: webURL+'/community/getCommunity/'+city,
			data:'',
			success:function(msg)
			{
				var list = new Array();
				var address;
				var dbcommunity ='dbcommunity';
				var communityname ="" ;
				list = eval("("+msg+")");
				if(list.length > 0)
				{
					for(var counter=0 ; counter < list.length ; counter++)
					{
						clearShapes();
						communityId = list[counter][0];
						communityname = list[counter][1]+','+list[counter][0];
						address = list[counter][2]+' '+list[counter][4]+' '+list[counter][5]+' '+list[counter][6];
						var code='var geocoder_'+counter+'= new GClientGeocoder();if (geocoder_'+counter+'){geocoder_'+counter+'.getLatLng("'+address+'",function(point) {if (point) {map.setCenter(point,'+zoomlevel+');marker['+counter+'] = createInfoMarkerHome(point,"'+address+'",'+counter+',"'+dbcommunity+'","'+communityname+'");map.addOverlay(marker['+counter+']);}});}';
						eval(code);
					}
				}
				else
				{
					address = country+' '+state;
					if (geocoder) 
					{
						geocoder.getLatLng(
						  address,
						  function(point) {
							if (!point) {
							 // alert(address + " not found");
							} else {
								clearShapes();
								var dbcity ='dbcity';
								map.setCenter(point,5);
								marker[0] = createInfoMarkerHome(point, address,0,dbcity,communityname);  //  user for create marker
								map.addOverlay(marker[0]);
							}
						  }
						);
					 }
				}
			}
			});
		}
	}
	
	
	function clearShapes()
	{
	 try {
		map.clearOverlays();
		}
		catch(err) {}
	}
	
