// JavaScript Document
	// global stuff and global (ick) variables
	
	var baseIcon = new GIcon();
    baseIcon.shadow = "/images/shadow.png";
    baseIcon.iconSize = new GSize(12, 12);
    baseIcon.shadowSize = new GSize(12, 12);
    baseIcon.iconAnchor = new GPoint(5, 7);
    baseIcon.infoWindowAnchor = new GPoint(5, 7);
    baseIcon.infoShadowAnchor = new GPoint(0, 12);
	var bounds = new GLatLngBounds();
      var gicons = [];
      var icon = new GIcon();
      gicons["None"] = new GIcon( baseIcon, "/images/open.png");
      gicons["WEP"] = new GIcon( baseIcon, "/images/wep.png");
      gicons["Wpa"] = new GIcon( baseIcon, "/images/wpa.png");

	  var mappoints=[];
      var gmarkers = [];
      // global arrays to hold copies of the markers and html used by the side_bar
    //var gmarkers = [];
      var htmls = [];
      var html = "";
      var markIndex = 0;
      var htmlloc="";
      var markerloc = null;
      var hpmap;
	// This function (resizeMap) wasoriginaly  written by John Resig
//  and taken from example found at http://ejohn.org/blog/one-week-of-google-maps-2/
// it was hacked up to work under gmap API v 2 which has reversed the map zoom order! and changed a few function names

function resizeMap( mymap, points ) {
  var minLong = 999;
  var minLat = 999;
  var maxLong = -999;
  var maxLat = -999;
  
  // Get the current map width/height
  var size = mymap.getBounds();
  var NE= size.getNorthEast();
 var SW= size.getSouthWest();

  var baseWidth = NE.lng()- SW.lng();
  var baseHeight =  NE.lat()-SW.lat();
  
  // Figure out the elemental unit (depends on the size of the map)
  // You will need to re-run resizeMap() if the size of the map changes.
  if ( mymap.getZoom() > 0 ) {
    baseWidth *= Math.pow( 2,17-mymap.getZoom() );
    baseHeight *= Math.pow( 2, 17-mymap.getZoom() );
  }

  // Find the max/min points
  for ( var i = 0; i < points.length; i++ ) {
    if ( points[i].x < minLong ) minLong = points[i].x;
    if ( points[i].x > maxLong ) maxLong = points[i].x;
    if ( points[i].y < minLat ) minLat = points[i].y;
    if ( points[i].y > maxLat ) maxLat = points[i].y;
  }

  // Find the optimal Width Zoom
  var wZoom = 0;
  var w = Math.abs( maxLong - minLong );
  for ( var i = 0; i < 17; i++ ) {
    if ( baseWidth < w ) break;
    baseWidth /= 2;
    wZoom = i;
  }

  // Find the optimal Height Zoom
  var hZoom = 0;
  var h = Math.abs( maxLat - minLat );
  for ( var i = 0; i < 17; i++ ) {
    if ( baseHeight < h ) break;
    baseHeight /= 2;
    hZoom = i;
  }
  
  // Reposition
  oldZoom=wZoom > hZoom ? wZoom : hZoom;
  
	mymap.setCenter(new GLatLng( ( minLat + maxLat ) / 2 , ( minLong + maxLong ) / 2), 17-oldZoom   );

}


// Creates a marker at the given point with the given number label
function createMarker(point, $info, $enc) {
  	if($enc == "None")
	{
		var marker = new GMarker(point,gicons["None"]);
  	}
	else if($enc == "WEP")
	{
		var marker = new GMarker(point,gicons["WEP"]);
		}
	else
	{
		var marker = new GMarker(point,gicons["Wpa"]);
	}

	GEvent.addListener(marker, "click", function() {
    	marker.openInfoWindowHtml($info);
  	});

	gmarkers[i] = marker;
	i++;
  	return marker;
	}

    function load() {
      if (GBrowserIsCompatible()) {
		 //alert("Inside load");
		 //alert(final_pts_arr.length);
		
		//map.addControl(new GMapTypeControl());
		
		
			hpmap = new GMap2(document.getElementById("map"));
			// set a center then update it later
			hpmap.setCenter(new GLatLng(23.84, 91.277778), 10);
			//getMarkers(final_pts_arr, hpmap);
			
			
			hpmap.addControl(new GLargeMapControl());
			//map.addControl(new GSmallMapControl());
			hpmap.addControl(new GMapTypeControl());
			hpmap.addControl(new GScaleControl ());
			hpmap.addControl(new GOverviewMapControl ());
			
										 
		}
	}
	
	
	// This function picks up the side_bar click and opens the corresponding info window
	    function myclick(i) 
	    {
	      
		  hpmap.clearOverlays();
		  document.getElementById('map').scrollIntoView();
		   if (i == 0) //Amarpur
		  {

				var point = new GLatLng(23.524722, 91.6575);
				//hpmap.setCenter(point, 12);	
				var marker = new GMarker(point);  
				var htmlInfo = '<table>';
				htmlInfo = htmlInfo+'<tr><td width=300><b>AMARPUR</b></td></tr>';
				
				htmlInfo = htmlInfo+'<tr><td width=300>Bamboo Handicrafts Cluster</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>Core Product: Bamboo Blinds &amp; Loom based Mats</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>No of Artisans: 150</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>Percentage of Women: 80%</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>Percentage of Minority: 80% SC</td></tr>';
					
				htmlInfo = htmlInfo+'</table>';
				//hpmap.panTo(point);
				hpmap.addOverlay(marker);
				
				marker.openInfoWindowHtml(htmlInfo);
				GEvent.addListener(marker, "click", function() {
    				marker.openInfoWindowHtml(htmlInfo);
  				});
		  }
		  
		  if (i == 1) //Baikhura
		  {

				var point = new GLatLng(23.2723, 91.5333);
				//hpmap.setCenter(point, 12);	
				var marker = new GMarker(point);  
				var htmlInfo = '<table>';
				htmlInfo = htmlInfo+'<tr><td width=300><b>BAIKHURA</b></td></tr>';
				
				htmlInfo = htmlInfo+'<tr><td width=300>Sheetal Pati Cluster</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>Core Product: Sheetal Pati Mats &amp; Accessories</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>No of Artisans: 250</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>Percentage of Women: 95%</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>Percentage of Minority: 50% OBC</td></tr>';
					
				htmlInfo = htmlInfo+'</table>';
				//hpmap.panTo(point);
				hpmap.addOverlay(marker);
				
				marker.openInfoWindowHtml(htmlInfo);
				GEvent.addListener(marker, "click", function() {
    				marker.openInfoWindowHtml(htmlInfo);
  				});
		  }
			
		  if (i == 2) //CHARILAM
		  {

				var point = new GLatLng(23.636667, 91.312222);
				//hpmap.setCenter(point, 12);	
				var marker = new GMarker(point);  
				var htmlInfo = '<table>';
				htmlInfo = htmlInfo+'<tr><td width=300><b>CHARILAM</b></td></tr>';
				
				htmlInfo = htmlInfo+'<tr><td width=300>Bamboo Handicrafts Cluster</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>Core Product: Bamboo Baskets &amp; Decorative Mats</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>No of Artisans: 2500</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>Percentage of Women: 80%</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>Percentage of Minority: 80% SC</td></tr>';
					
				htmlInfo = htmlInfo+'</table>';
				//hpmap.panTo(point);
				hpmap.addOverlay(marker);
				
				marker.openInfoWindowHtml(htmlInfo);
				GEvent.addListener(marker, "click", function() {
    				marker.openInfoWindowHtml(htmlInfo);
  				});
			
 }
 if (i == 3) //Nalchar
		  {

				var point = new GLatLng(23.4881, 91.33);
				//hpmap.setCenter(point, 12);	
				var marker = new GMarker(point);  
				var htmlInfo = '<table>';
				htmlInfo = htmlInfo+'<tr><td width=300><b>NALCHAR</b></td></tr>';
				
				htmlInfo = htmlInfo+'<tr><td width=300>Bamboo Handicrafts &amp; Polished Incense Sticks Cluster</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>Core Product: Bamboo Baskets &amp; Loom based fine mats</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>No of Artisans: 2000</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>Percentage of Women: 75%</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>Percentage of Minority: 70% SC</td></tr>';
					
				htmlInfo = htmlInfo+'</table>';
				//hpmap.panTo(point);
				hpmap.addOverlay(marker);
				
				marker.openInfoWindowHtml(htmlInfo);
				GEvent.addListener(marker, "click", function() {
    				marker.openInfoWindowHtml(htmlInfo);
  				});
			
 }
 if (i == 4) //Katlamara
		  {

				var point = new GLatLng(23.976389, 91.277222);
				//hpmap.setCenter(point, 12);	
				var marker = new GMarker(point);  
				var htmlInfo = '<table>';
				htmlInfo = htmlInfo+'<tr><td width=300><b>KATLAMARA</b></td></tr>';
				
				htmlInfo = htmlInfo+'<tr><td width=300>Bamboo Furniture Cluster</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>Core Product: Bamboo Baskets &amp; Decorative mats</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>No of Artisans: 200</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>Percentage of Women: 25%</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>Percentage of Minority: 80% ST</td></tr>';
					
				htmlInfo = htmlInfo+'</table>';
				//hpmap.panTo(point);
				hpmap.addOverlay(marker);
				
				marker.openInfoWindowHtml(htmlInfo);
				GEvent.addListener(marker, "click", function() {
    				marker.openInfoWindowHtml(htmlInfo);
  				});
			
 }
 
 if (i == 5) //Panisagar
		  {

				var point = new GLatLng(24.266389, 92.154444);
				//hpmap.setCenter(point, 12);	
				var marker = new GMarker(point);  
				var htmlInfo = '<table>';
				htmlInfo = htmlInfo+'<tr><td width=300><b>PANISAGAR</b></td></tr>';
				
				htmlInfo = htmlInfo+'<tr><td width=300>Bamboo Handicrafts &amp; Cane Furniture</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>Core Product: Bamboo Baskets &amp; Decorative mats</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>No of Artisans: 300</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>Percentage of Women: 90%</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>Percentage of Minority: 45% SC</td></tr>';
					
				htmlInfo = htmlInfo+'</table>';
				//hpmap.panTo(point);
				hpmap.addOverlay(marker);
				
				marker.openInfoWindowHtml(htmlInfo);
				GEvent.addListener(marker, "click", function() {
    				marker.openInfoWindowHtml(htmlInfo);
  				});
			
 }
 if (i == 6) //JOGINDRANAGAR
		  {

				var point = new GLatLng(23.819444, 91.303333);
				//hpmap.setCenter(point, 12);	
				var marker = new GMarker(point);  
				var htmlInfo = '<table>';
				htmlInfo = htmlInfo+'<tr><td width=300><b>JOGENDRANAGAR</b></td></tr>';
				
				htmlInfo = htmlInfo+'<tr><td width=300>Bamboo Handicrafts Cluster</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>Core Product: Bamboo  Blinds, decorative products &amp; bamboo place mats</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>No of Artisans: 2000</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>Percentage of Women: 95%</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>Percentage of Minority: 70% SC</td></tr>';
					
				htmlInfo = htmlInfo+'</table>';
				//hpmap.panTo(point);
				hpmap.addOverlay(marker);
				
				marker.openInfoWindowHtml(htmlInfo);
				GEvent.addListener(marker, "click", function() {
    				marker.openInfoWindowHtml(htmlInfo);
  				});
			
 }
 
  if (i == 7) //Mohanpur
		  {

				var point = new GLatLng(23.846900, 91.380200);
				//hpmap.setCenter(point, 12);	
				var marker = new GMarker(point);  
				var htmlInfo = '<table>';
				htmlInfo = htmlInfo+'<tr><td width=300><b>MOHANPUR</b></td></tr>';
				
				htmlInfo = htmlInfo+'<tr><td width=300>Bamboo Handicrafts Cluster</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>Core Product: Bamboo Loom mats &amp; Bamboo woven mats</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>No of Artisans: 500</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>Percentage of Women: 80%</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>Percentage of Minority: 60% SC</td></tr>';
					
				htmlInfo = htmlInfo+'</table>';
				//hpmap.panTo(point);
				hpmap.addOverlay(marker);
				
				marker.openInfoWindowHtml(htmlInfo);
				GEvent.addListener(marker, "click", function() {
    				marker.openInfoWindowHtml(htmlInfo);
  				});
			
 }

if (i == 8) //Agartala
		  {

				var point = new GLatLng(23.84, 91.277778);
				//hpmap.setCenter(point, 12);	
				var marker = new GMarker(point);  
				var htmlInfo = '<table>';
				htmlInfo = htmlInfo+'<tr><td width=300><b>AGARTALA</b></td></tr>';
				
				htmlInfo = htmlInfo+'<tr><td width=300>Bamboo Handicrafts Cluster</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>Core Product: Bamboo decoration wall panels, partitions, crockery</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>No of Artisans: 500</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>Percentage of Women: 50%</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>Percentage of Minority: 60% SC</td></tr>';
					
				htmlInfo = htmlInfo+'</table>';
				//hpmap.panTo(point);
				hpmap.addOverlay(marker);
				
				marker.openInfoWindowHtml(htmlInfo);
				GEvent.addListener(marker, "click", function() {
    				marker.openInfoWindowHtml(htmlInfo);
  				});
			
 }

if (i == 9) //Kamalpur
		  {

				var point = new GLatLng(24.195833, 91.830278);
				//hpmap.setCenter(point, 12);	
				var marker = new GMarker(point);  
				var htmlInfo = '<table>';
				htmlInfo = htmlInfo+'<tr><td width=300><b>KAMALPUR</b></td></tr>';
				
				htmlInfo = htmlInfo+'<tr><td width=300>Bamboo Mats Cluster</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>Core Product: Bamboo Mats</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>No of Artisans: 1000</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>Percentage of Women: 20%</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>Percentage of Minority: 70% SC</td></tr>';
					
				htmlInfo = htmlInfo+'</table>';
				//hpmap.panTo(point);
				hpmap.addOverlay(marker);
				
				marker.openInfoWindowHtml(htmlInfo);
				GEvent.addListener(marker, "click", function() {
    				marker.openInfoWindowHtml(htmlInfo);
  				});
			
 }
 
 if (i == 10) //Salema
		  {

				var point = new GLatLng(24.007778, 91.834167);
				//hpmap.setCenter(point, 12);	
				var marker = new GMarker(point);  
				var htmlInfo = '<table>';
				htmlInfo = htmlInfo+'<tr><td width=300><b>SALEMA</b></td></tr>';
				
				htmlInfo = htmlInfo+'<tr><td width=300>Bamboo Mats Cluster</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>Core Product: Bamboo Mats</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>No of Artisans: 1500</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>Percentage of Women: 20%</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>Percentage of Minority: 80% ST</td></tr>';
					
				htmlInfo = htmlInfo+'</table>';
				//hpmap.panTo(point);
				hpmap.addOverlay(marker);
				
				marker.openInfoWindowHtml(htmlInfo);
				GEvent.addListener(marker, "click", function() {
    				marker.openInfoWindowHtml(htmlInfo);
  				});
			
 }
 
  if (i == 11) //Jirania
		  {

				var point = new GLatLng(23.8268, 91.4468);
				//hpmap.setCenter(point, 12);	
				var marker = new GMarker(point);  
				var htmlInfo = '<table>';
				htmlInfo = htmlInfo+'<tr><td width=300><b>JIRANIA</b></td></tr>';
				
				htmlInfo = htmlInfo+'<tr><td width=300>Bamboo Handicrafts Cluster</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>Core Product: Bamboo Table mats</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>No of Artisans: 1000</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>Percentage of Women: 80%</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>Percentage of Minority: 80% SC</td></tr>';
					
				htmlInfo = htmlInfo+'</table>';
				//hpmap.panTo(point);
				hpmap.addOverlay(marker);
				
				marker.openInfoWindowHtml(htmlInfo);
				GEvent.addListener(marker, "click", function() {
    				marker.openInfoWindowHtml(htmlInfo);
  				});
			
 }


if (i == 12) //Shankhela
		  {

				var point = new GLatLng(24.0634, 91.3177);
				//hpmap.setCenter(point, 12);	
				var marker = new GMarker(point);  
				var htmlInfo = '<table>';
				htmlInfo = htmlInfo+'<tr><td width=300><b>SHANKHELA</b></td></tr>';
				
				htmlInfo = htmlInfo+'<tr><td width=300>Rolled Bamboo Furniture Cluster</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>Core Product: Bamboo Furniture</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>No of Artisans: 150</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>Percentage of Women: 25%</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>Percentage of Minority: 100% ST</td></tr>';
					
				htmlInfo = htmlInfo+'</table>';
				//hpmap.panTo(point);
				hpmap.addOverlay(marker);
				
				marker.openInfoWindowHtml(htmlInfo);
				GEvent.addListener(marker, "click", function() {
    				marker.openInfoWindowHtml(htmlInfo);
  				});
			
 }

if (i == 13) //Ganganagar
		  {

				var point = new GLatLng(23.8469, 91.8608);
				//hpmap.setCenter(point, 12);	
				var marker = new GMarker(point);  
				var htmlInfo = '<table>';
				htmlInfo = htmlInfo+'<tr><td width=300><b>GANGANAGAR</b></td></tr>';
				
				htmlInfo = htmlInfo+'<tr><td width=300>Bamboo Resource</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>Core Product: Bamboo Plantation & Management</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>No of Artisans: 1000</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>Percentage of Women: 50%</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>Percentage of Minority: 100% ST</td></tr>';
					
				htmlInfo = htmlInfo+'</table>';
				//hpmap.panTo(point);
				hpmap.addOverlay(marker);
				
				marker.openInfoWindowHtml(htmlInfo);
				GEvent.addListener(marker, "click", function() {
    				marker.openInfoWindowHtml(htmlInfo);
  				});
			
 }


if (i == 14) //Gandacherra
		  {

				var point = new GLatLng(23.8054, 91.8388);
				//hpmap.setCenter(point, 12);	
				var marker = new GMarker(point);  
				var htmlInfo = '<table>';
				htmlInfo = htmlInfo+'<tr><td width=300><b>GANDACHERRA</b></td></tr>';
				
				htmlInfo = htmlInfo+'<tr><td width=300>Bamboo Mats Cluster</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>Core Product: Bamboo Mats</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>No of Artisans: 2500</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>Percentage of Women: 80%</td></tr>';
				htmlInfo = htmlInfo+'<tr><td width=300>Percentage of Minority: 80% SC</td></tr>';
					
				htmlInfo = htmlInfo+'</table>';
				//hpmap.panTo(point);
				hpmap.addOverlay(marker);
				
				marker.openInfoWindowHtml(htmlInfo);
				GEvent.addListener(marker, "click", function() {
    				marker.openInfoWindowHtml(htmlInfo);
  				});
			
 }



		  
	    }
	
	
	// This function picks up the side_bar click and opens the corresponding info window
	    function locclick() 
	    {
	      markerloc.openInfoWindowHtml(htmlloc);
	    }
	
	
	function loadforlocation(lat, lng, locname, pincdval, addrval, websiteval, phonenbrval, fax, email, comments) 
	{
	      if (GBrowserIsCompatible()) {
			//alert("Name:"+locname);
			var map = new GMap2(document.getElementById("map"));
			//map.addControl(new GMapTypeControl());
			map.addControl(new GLargeMapControl());
			map.addControl(new GMapTypeControl());
			map.addControl(new GScaleControl ());
			map.addControl(new GOverviewMapControl ());
			var point = new GLatLng(lat, lng);
			// set a center then update it later
			map.setCenter(point, 16);
			map.addOverlay(createMarkerForLocation(point, locname, pincdval, addrval, websiteval, phonenbrval, fax, email, comments));
			return map;
			}
	}
	
	
	
	function createMarkerForLocation(point, locname, pincdval, addrval, websiteval, phonenbrval, fax, email, comments) 
	{  
		var marker = new GMarker(point);  
		var htmlInfo = '<table>'
		if(locname.length > 0)
		{
			htmlInfo = htmlInfo+'<tr>'+'<td width=300>'+'<b>'+locname+'</b>'+'</td>'+'</tr>';
		}
		if(addrval.length > 0)
		{
			htmlInfo = htmlInfo+'<tr>'+'<td width=300>'+addrval+'</td>'+'</tr>';
		}
		
		if(pincdval.length > 0)
		{
			htmlInfo = htmlInfo+'<tr>'+'<td width=300>'+pincdval+'</td>'+'</tr>';
		}
		
		if(phonenbrval.length > 0)
		{
			htmlInfo = htmlInfo+'<tr>'+'<td width=300>'+'Tel: '+phonenbrval+'</td>'+'</tr>';
		}
		if(fax.length > 0)
		{
			htmlInfo = htmlInfo+'<tr>'+'<td width=300>'+'Fax: '+fax+'</td>'+'</tr>';
		}
		
		if(websiteval.length > 0)
		{
			htmlInfo = htmlInfo+'<tr>'+'<td width=300>'+'<a href="'+websiteval+'" target="_blank"/>'+websiteval+'</td>'+'</tr>';
		}
		
		if(email.length > 0)
		{
			htmlInfo = htmlInfo+'<tr>'+'<td width=300>'+'<a href="mailto:'+email+'"/>'+'Email: '+email+'</td>'+'</tr>';
			
		}
		
		htmlInfo = htmlInfo+'</table>';
		
		
		GEvent.addListener(marker, "click", function() 
		{    
			
				marker.openInfoWindowHtml(htmlInfo);
			
		});
		
		htmlloc=htmlInfo; 
		markerloc=marker;
		return marker;
	}
	
	
	function createMarkerForLocationAll(point, nameest, address, pincode, urllink, fone, fax, email, comments, catdisplay, icon) 
	{  
		var marker = new GMarker(point, icon);  
		
		
		var htmlInfo = '<table>'
		if(nameest.length > 0)
		{
			htmlInfo = htmlInfo+'<tr>'+'<td width=300>'+'<b>'+nameest+'</b>'+'</td>'+'</tr>';
		}
		if(address.length > 0)
		{
			htmlInfo = htmlInfo+'<tr>'+'<td width=300>'+address+'</td>'+'</tr>';
		}
		
		if(pincode.length > 0)
		{
			htmlInfo = htmlInfo+'<tr>'+'<td width=300>'+pincode+'</td>'+'</tr>';
		}
		
		if(catdisplay.length > 0)
		{
			htmlInfo = htmlInfo+'<tr>'+'<td width=300>'+"<font size=2 style='font-style: italic; color: blue;'><b>Category: </font></b>"+catdisplay+'</td>'+'</tr>';
			
		}
		
		if(fone.length > 0)
		{
			htmlInfo = htmlInfo+'<tr>'+'<td width=300>'+'Tel: '+fone+'</td>'+'</tr>';
		}
		if(fax.length > 0)
		{
			htmlInfo = htmlInfo+'<tr>'+'<td width=300>'+'Fax: '+fax+'</td>'+'</tr>';
		}
		
		if(urllink.length > 0)
		{
			htmlInfo = htmlInfo+'<tr>'+'<td width=300>'+'<a href="'+urllink+'" target="_blank"/>'+urllink+'</td>'+'</tr>';
		}
		
		if(email.length > 0)
		{
			htmlInfo = htmlInfo+'<tr>'+'<td width=300>'+'<a href="mailto:'+email+'"/>'+'Email: '+email+'</td>'+'</tr>';
			
		}
		
		htmlInfo = htmlInfo+'</table>';
		
		
		
		
		
		
		
		
		GEvent.addListener(marker, "click", function() 
		{    
			
				marker.openInfoWindowHtml(htmlInfo);
			
		});
		
			html=htmlInfo;
			/*
			if((fone.length > 0) && (urllink.length > 0))
			{
				
				html = '<table>'+'<tr>'+'<td width=200>'+'<b>'+nameest+'</b>'+'</td>'+'</tr>'+'<tr>'+'<td width=250>'+address+'</td>'+'</tr>'+'<tr>'+'<td width=100>'+pincode+'</td>'+'</tr>'+'<tr>'+'<td width=100>'+fone+'</td>'+'</tr>'+'<tr>'+'<td width=100>'+'<a href="'+urllink+'" target="_blank"/>'+"Web Site"+'</td>'+'</tr>'+'</table>';
				htmls[markIndex]=html;
			}
			if((fone.length == 0) && (urllink.length > 0))
			{
				html = '<table>'+'<tr>'+'<td width=200>'+'<b>'+nameest+'</b>'+'</td>'+'</tr>'+'<tr>'+'<td width=250>'+address+'</td>'+'</tr>'+'<tr>'+'<td width=100>'+pincode+'</td>'+'</tr>'+'<tr>'+'<td width=100>'+'<a href="'+urllink+'" target="_blank"/>'+"Web Site"+'</td>'+'</tr>'+'</table>';
				htmls[markIndex]=html;
			}
			if((fone.length > 0) && (urllink.length == 0))
			{
				html = '<table>'+'<tr>'+'<td width=200>'+'<b>'+nameest+'</b>'+'</td>'+'</tr>'+'<tr>'+'<td width=250>'+address+'</td>'+'</tr>'+'<tr>'+'<td width=100>'+pincode+'</td>'+'</tr>'+'<tr>'+'<td width=100>'+fone+'</td>'+'</tr>'+'</table>';
				htmls[markIndex]=html;
			}
			if((fone.length == 0) && (urllink.length == 0))
			{
				html = '<table>'+'<tr>'+'<td width=200>'+'<b>'+nameest+'</b>'+'</td>'+'</tr>'+'<tr>'+'<td width=250>'+address+'</td>'+'</tr>'+'<tr>'+'<td width=100>'+pincode+'</td>'+'</tr>'+'</table>';
				htmls[markIndex]=html;
			}*/
			
		
		
		gmarkers[markIndex] = marker;
		htmls[markIndex]=html;
		//alert(gmarkers[markIndex]);
		//htmls[markIndex] = html;
		//alert(gmarkers[markIndex]);
		markIndex++; 
		 
		  
		
		return marker;
	}
	
	
	
	
	
	
	function getMarkers(final_pts_arr, hpmap)
	{
		alert("inside getmarkers");
		hpmap.setCenter(new GLatLng(final_pts_arr[0]['lat'],final_pts_arr[0]['lng']), 12);					
		for (var i=0; i < final_pts_arr.length; i++)
		{
			
			
			var point = new GLatLng(final_pts_arr[i]['lat'],final_pts_arr[i]['lng']);
			var nameest = final_pts_arr[i]['name'];
			
			
			
			icon.image = "http://www.magnifyindia.com/testenv/images/magbang_marker_v3.png";
			 icon.shadow = "http://www.magnifyindia.com/testenv/images/shadow-magbang_marker_v3.png";
			icon.iconSize = new GSize(20.0, 31.0);
			 icon.shadowSize = new GSize(36.0, 31.0);

			//icon.shadow = "http://www.magnifyindia.com/testenv/myredmaptest/images/shadow-love.png";
			//icon.shadowSize = new GSize(35, 25);
			//icon.iconSize = new GSize(20.0, 30.0);
			    //icon.shadowSize = new GSize(36.0, 30.0);
			    icon.iconAnchor = new GPoint(11, 30);
			    icon.infoWindowAnchor = new GPoint(10.0, 15.0);

			//var marker = createMarkerForLocationAll(point, nameest, address, pincode, category, urllink, fone, fax, email, comments, icon);
			var marker = new GMarker(point, icon); 
			
			//markers[i] = new GMarker(new GLatLng(locations[i].getAttribute("lat"),locations[i].getAttribute("lng")));
			//alert(locations[i].getAttribute("lat"));
			// Add attributes to the marker so we can poll them later.                                               
			// When clicked, an overlay will have these properties.                                                  
			//markers[i].infowindow = "This is "+locations[i].getAttribute("name");                                    
			                                                                                                         
			// Useful things to store on a marker (Not needed for this example, could be removed)                    
			// Tells you what index in the markers[] array an overlay is                                             
			//markers[i].markerindex = i;                                                                              
			// Store the location_id of the location the marker represents.                                          
			// Very useful to know the true id of a marker, you could then make                                      
			// AJAX calls to the database to update the information if you had it's location_id                      
			                                                                                                         
			hpmap.addOverlay(marker);
			//detailField = detailField + "Name:"+locations[i].getAttribute("name")+"\n";                                                                              
						 
		}
			
			
			
	}
	
	
	
	
	
	
	function getMarkers(estname, forwhat, onwhichrd,areazip, map)
	{                                                                                                                                           
	    //alert("estname:"+estname);
	    var urlstr="http://www.magnifyindia.com/testenv/scripts/getInitMapData.php?estname="+estname+"&forwhat="+forwhat+"&onwhichrd="+onwhichrd+"&areazip="+areazip;                                                                                                                       
	    var request;  // The variable that makes Ajax possible!
		
		try{
			// Opera 8.0+, Firefox, Safari
			request = new XMLHttpRequest();
		} catch (e){
			// Internet Explorer Browsers
			try{
				request = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try{
					request = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e){
					// Something went wrong
					alert("Your browser broke!");
					return false;
				}
			}
		}
	
	    request.open("GET", urlstr , true);	// request XML from PHP with AJAX call 
	    //alert("urlstr"+urlstr)
	    request.onreadystatechange = function () 
	    {                                                                                                   
			if (request.readyState == 4) 
			{                                                                                                   
				//alert("request="+urlstr);
				//alert("request.status="+request.status+".");
				//alert("request.responseXML="+request.responseXML+".");
				//alert("request.responseText="+request.responseText+".");
				//alert("request.statusText="+request.statusText+"."); 
				//var xmlDoc = request.responseXML; 
				//alert("response"+request.responseText); 
				//var testStr = "&";
				//alert("testStr:"+testStr);
				//var testEncoded = Utf8.encode(testStr);
				//var testEncoded = Utf8.encode(request.responseText);
				//alert("testEncoded:"+testEncoded);
				var xmlDoc = GXml.parse(request.responseText);
				
				//alert("xmlDoc:"+xmlDoc); 
				//locations = xmlDoc.documentElement.getElementsByTagName("location");  
				//var xmlDoc = request.responseText;
				locations = xmlDoc.documentElement.getElementsByTagName("location");
				//alert("locations:"+locations);
				//alert("locations.length:"+locations.length);
				//var detailField = "";
				//markers = [];                                                                                                            
					/*
					// creates a <table> element and a <tbody> element
				        var tbl     = document.createElement("table");
				        //tbl.style.backgroundColor = "maroon";
				        var tblBody = document.createElement("tbody");
					
					if (locations.length){
					for (var i = 0; i < locations.length; i++) 
					{
						// creates a table row
            					var row = document.createElement("tr");
            					row.style.backgroundColor = "silver";
            					//for (var j = 0; j < 3; j++) 
            					//{
					                // Create a <td> element and a text node, make the text
					                // node the contents of the <td>, and put the <td> at
					                // the end of the table row
					                var cell1 = document.createElement("td");
					                var cellText1 = document.createTextNode(locations[i].getAttribute("name"));
					                cell1.setAttribute("href","http://www.yahoo.com");
					                cell1.href = "http://www.yahoo.com";
					                cell1.setAttribute("href","http://www.yahoo.com");
					                cell1.appendChild(cellText1);
					                //cellText1.setAttribute("href","http://www.magnifyindia.com/testenv/scripts/newsearch.php?q=test");
					                row.appendChild(cell1);
					                
					                var cell2 = document.createElement("td");
					                var cellText2 = document.createTextNode(locations[i].getAttribute("lat"));
					                cell2.appendChild(cellText2);
					                row.appendChild(cell2);
					                
					                var cell3 = document.createElement("td");
					                var cellText3 = document.createTextNode(locations[i].getAttribute("lng"));
					                cell3.appendChild(cellText3);
					                row.appendChild(cell3);
					                
            					//}
            					// add the row to the end of the table body
            					tblBody.appendChild(row);
            					
            					
					}
					// put the <tbody> in the <table>
				        tbl.appendChild(tblBody);
				        // appends <table> into <body>
					document.getElementById("resultsSec").appendChild(tbl);
				}*/
					
					if (locations.length){
					
						map.setCenter(new GLatLng(locations[0].getAttribute("lat"), locations[0].getAttribute("lng")), 12);					
						//alert("locations.length"+locations.length);
					for (var i = 0; i < locations.length; i++) 
					{ // cycle thru locations                                             
						//markers[i] = new GMarker(new GLatLng(xmlDoc.getElementsByTagName("lat")[i].childNodes[i].nodeValue,xmlDoc.getElementsByTagName("lng")[i].childNodes[i].nodeValue), icon);
						
						var point = new GLatLng(locations[i].getAttribute("lat"),locations[i].getAttribute("lng"));
						var nameest = Base64.decode(locations[i].getAttribute("name"));
						var address = Base64.decode(locations[i].getAttribute("address"));
						var pincode = locations[i].getAttribute("zip");
						var category = locations[i].getAttribute("category");
						var urllink = locations[i].getAttribute("url");
						var fone = locations[i].getAttribute("fone");
						var fax = locations[i].getAttribute("fax");
						var email = locations[i].getAttribute("email");
						var comments = locations[i].getAttribute("comments");
						
						
						icon.image = "http://www.magnifyindia.com/testenv/images/magbang_marker_v3.png";
						 icon.shadow = "http://www.magnifyindia.com/testenv/images/shadow-magbang_marker_v3.png";
						icon.iconSize = new GSize(20.0, 31.0);
   						 icon.shadowSize = new GSize(36.0, 31.0);

						//icon.shadow = "http://www.magnifyindia.com/testenv/myredmaptest/images/shadow-love.png";
						//icon.shadowSize = new GSize(35, 25);
						//icon.iconSize = new GSize(20.0, 30.0);
						    //icon.shadowSize = new GSize(36.0, 30.0);
						    icon.iconAnchor = new GPoint(11, 30);
						    icon.infoWindowAnchor = new GPoint(10.0, 15.0);

						var marker = createMarkerForLocationAll(point, nameest, address, pincode, category, urllink, fone, fax, email, comments, icon);
						
						
						//markers[i] = new GMarker(new GLatLng(locations[i].getAttribute("lat"),locations[i].getAttribute("lng")));
						//alert(locations[i].getAttribute("lat"));
						// Add attributes to the marker so we can poll them later.                                               
						// When clicked, an overlay will have these properties.                                                  
						//markers[i].infowindow = "This is "+locations[i].getAttribute("name");                                    
						                                                                                                         
						// Useful things to store on a marker (Not needed for this example, could be removed)                    
						// Tells you what index in the markers[] array an overlay is                                             
						//markers[i].markerindex = i;                                                                              
						// Store the location_id of the location the marker represents.                                          
						// Very useful to know the true id of a marker, you could then make                                      
						// AJAX calls to the database to update the information if you had it's location_id                      
						                                                                                                         
						map.addOverlay(marker);
						//detailField = detailField + "Name:"+locations[i].getAttribute("name")+"\n";                                                                              
						


						 
					}
					//document.getElementById("resultsSec").appendChild(menuTable);
			}                
		}                                                                                                                                        
		                                                                                                                
	}
	request.send(null);  
}
	
/**
*
*  Base64 encode / decode
*  http://www.webtoolkit.info/
*
**/

var Base64 = {

	// private property
	_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

	// public method for encoding
	encode : function (input) {
		var output = "";
		var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
		var i = 0;

		input = Base64._utf8_encode(input);

		while (i < input.length) {

			chr1 = input.charCodeAt(i++);
			chr2 = input.charCodeAt(i++);
			chr3 = input.charCodeAt(i++);

			enc1 = chr1 >> 2;
			enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
			enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
			enc4 = chr3 & 63;

			if (isNaN(chr2)) {
				enc3 = enc4 = 64;
			} else if (isNaN(chr3)) {
				enc4 = 64;
			}

			output = output +
			this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
			this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);

		}

		return output;
	},

	// public method for decoding
	decode : function (input) {
		var output = "";
		var chr1, chr2, chr3;
		var enc1, enc2, enc3, enc4;
		var i = 0;

		input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

		while (i < input.length) {

			enc1 = this._keyStr.indexOf(input.charAt(i++));
			enc2 = this._keyStr.indexOf(input.charAt(i++));
			enc3 = this._keyStr.indexOf(input.charAt(i++));
			enc4 = this._keyStr.indexOf(input.charAt(i++));

			chr1 = (enc1 << 2) | (enc2 >> 4);
			chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
			chr3 = ((enc3 & 3) << 6) | enc4;

			output = output + String.fromCharCode(chr1);

			if (enc3 != 64) {
				output = output + String.fromCharCode(chr2);
			}
			if (enc4 != 64) {
				output = output + String.fromCharCode(chr3);
			}

		}

		output = Base64._utf8_decode(output);

		return output;

	},

	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";

		for (var n = 0; n < string.length; n++) {

			var c = string.charCodeAt(n);

			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}

		}

		return utftext;
	},

	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;

		while ( i < utftext.length ) {

			c = utftext.charCodeAt(i);

			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}

		}

		return string;
	}

}
	
function StringBuffer() { 
   	this.buffer = []; 
 	} 

 StringBuffer.prototype.append = function append(string) { 
   this.buffer.push(string); 
   return this; 
 }; 

 StringBuffer.prototype.toString = function toString() { 
   return this.buffer.join(""); 
 };
	
	
	

	function gotomarker(map,index)
	{
		map.panTo(mappoints[index]);
    		GEvent.trigger(gmarkers[index],'click');
		window.scrollTo(0,0);

	}

function encode(str)
  {
    var sbuf = new StringBuffer();
    
    //return sbuf.toString();
  }
function fitMap( map, markerPoints ) {
   //alert("inside fitmap");
   var bounds = new GLatLngBounds();
   //alert(markerPoints.length);
   for (var i=0; i< markerPoints.length; i++) {
      bounds.extend(markerPoints[i]);
   }

   map.setZoom(map.getBoundsZoomLevel(bounds));
   map.setCenter(bounds.getCenter());
}

	