   //<![CDATA[
      var map;
      var geocoder;

      function load() {
        if (GBrowserIsCompatible()) {
          geocoder = new GClientGeocoder();
	    map = new GMap2(document.getElementById('map'));
          map.addControl(new GSmallMapControl());
          map.addControl(new GMapTypeControl());
	    map.setCenter(new GLatLng(40.7042, -73.9178), 13);
	  }
      } //end  of func

	function searchArray(excludeType, input){
	  if (excludeType=='fieldname'){
	    var fieldArray=new Array('Name','Location','TradeName');
	  }else if (excludeType=='field'){
	    var fieldArray=new Array('Boro','lat','lng','EntityType','AddressBldg','AddressStreetName','AddressCity','AddressState','AddressZipCode','AddressLocation','Address','City','Zip',
               'BORO_DECODE','FacilityLevelName_Decode','total_results','Month','Year','Borough','X_Coordinate', 'Y_Coordinate');
	  }else if (excludeType=='plot_x') {
	    var fieldArray=new Array('');
	  }else if (excludeType=='plot_xlabel') {
	    var fieldArray=new Array('District');
	  }else if (excludeType=='plot_y') {
	    var fieldArray=new Array('Total_Diversion');
	  }else if (excludeType=='plot_ylabel') {
	    var fieldArray=new Array('');
	  }else if (excludeType=='report') {
	    var fieldArray=new Array('diversion');
	  }
	  for (var f=0; f<fieldArray.length; f++){
	    if (fieldArray[f]==input) { return true;}
	  }
	  return false;
	} //end  of func

          function searchLocations() {
        var facilityleveltype = document.getElementById('facilityleveltype').value;
        var borough = document.getElementById('borough').value;
        var address = document.getElementById('address').value;
	  var radius = document.getElementById('radius').value; 
	  var graphdate= document.getElementById('graphdate').value; 


	//only when the min search fields are set before the search
	if(facilityleveltype.substring(0,2) =='r_' && (borough == '' || graphdate=='')){
		alert('Please select what you want to search for, Borough and Date'); 
	}else if (facilityleveltype =='' || (borough == '' && address=='')){
		alert('At the minimum, please select what you want to search for \nand either by Borough OR by Address'); 
  	}else {
	  document.getElementById('sidebar').innerHTML = '';
        document.getElementById("loading").style.visibility="visible";

        if (borough == ''){   //use location
     	    geocoder.getLatLng(address, function(latlng) {
          if (!latlng) {
            alert(address + ' not found');
          } else {
            searchLocationsNear(address,latlng,facilityleveltype,'',1,radius,'N');
          }
          });
        }else { //use borough
		if (facilityleveltype.substring(0,2)=='r_') facilityleveltype=facilityleveltype.substring(2);

	  	if (searchArray('report', facilityleveltype)==true){ //show the report
			var report_date= graphdate.replace('/','');

		 	var graph_filename= facilityleveltype + '_' + borough + '_' + report_date + '_tbl.png';

			//check if file exist using javascript if not then state so****************
		 	var report_html= '<center><img src="graphs/'+ graph_filename + '" border=0 /></center>';
			document.getElementById('sidebar').style.width="800px"; 
		      document.getElementById('map').style.display = "none";
			document.getElementById('sidebar').innerHTML=report_html;
		}else {
          		searchLocationsNear('','',facilityleveltype,borough,1,0,'N');
		}
        }
  }
        document.getElementById("loading").style.visibility="hidden";

      } //end  of func

      function searchLocationsNear(address,center,facilityleveltype,borough,page,radius,skiplog) {
        var showmap = document.getElementById('showmap').checked;
        var prev = (page - 1);
        var next = (page + 1);
        var max_results = 20;
        var from = ((page * max_results) - max_results); 

	  if (borough != '') { 
	    var searchUrl = 'phpsqlsearch_genxml.php?facilityleveltype='+ facilityleveltype + '&borough=' + borough + '&from=' + from + '&showmap=' + showmap + '&skiplog=' + skiplog;
//alert(showmap + ' ' + searchUrl); 
	  }else {
    	   if (typeof(center) =="string") //will be string when sent by pagination
	   {
		//remove the () on the point received
		center_fix=center;
  		center_fix=center_fix.substr(1);
  		center_fix = center_fix.substring(0,center.length-1);
  		var CenterArray = center_fix.split(",");

          	var searchUrl = 'phpsqlsearch_genxml.php?address='+ address + '&facilityleveltype='+ facilityleveltype + '&lat=' + CenterArray[0] + '&lng=' + CenterArray[1] + '&radius=' + radius + '&from=' + from + '&showmap=' + showmap + '&skiplog=' + skiplog; 
	   }else {
          	var searchUrl = 'phpsqlsearch_genxml.php?address='+ address + '&facilityleveltype='+ facilityleveltype + '&lat=' + center.lat() + '&lng=' + center.lng() + '&radius=' + radius + '&from=' + from + '&showmap=' + showmap + '&skiplog=' + skiplog; 
	   }
	  }
	  if (showmap == true)
	  {
	    document.getElementById('map').style.display = "block";
	    document.getElementById('sidebar').style.width="400px";
	    
 	    load();

	    GDownloadUrl(searchUrl, function(data) {
          var xml = GXml.parse(data);
          var markers = xml.documentElement.getElementsByTagName('marker');
          map.clearOverlays();

	    var sidebar = document.getElementById('sidebar');
          sidebar.innerHTML = '';
          if (markers.length == 0) {
            sidebar.innerHTML = '<span class="noresult">No results found.</span>';
            //map.setCenter(new GLatLng(40, -100), 4);
		map.setCenter(new GLatLng(40.7042, -73.9178), 13);
            return;
          }


	    /*** set the pagination ****/
	    total_results = markers[0].getAttribute('total_results');
	    total_pages = Math.ceil(total_results / max_results); 
	    pagination = ''; 

	    /* Create a PREV link if there is one */ 
	    if (page > 1) 
	    { 
	  	pagination += '<span class="pagination"><a href="javascript:void(0);" onclick="javascript:searchLocationsNear(\'' + address + '\',\'' + center + '\',\'' + facilityleveltype + '\',\'' + borough + '\',' + prev + ',' + radius + ',\'Y\')">Previous</a> ' + '&nbsp;&nbsp;</span>';  
	    } 
	    /* Loop through the total pages */ 
	    for(i = 1; i <= total_pages; i++) 
	    { 
	  	if((page) == i) 
	   	{ 
	    	  pagination += '<span class="pagination">' +  i + '&nbsp;&nbsp;</span>'; 
	  	} 
	  	else 
	  	{ 
	    	  pagination += '<span class="pagination"><a href="javascript:void(0);" onclick="javascript:searchLocationsNear(\''+ address + '\',\'' + center + '\',\'' + facilityleveltype + '\',\'' + borough + '\',' + i + ',' + radius+ ',\'Y\')">' + i + '</a>' + '&nbsp;&nbsp;</span>'; 
	  	} 
	    } 
	    /* Print NEXT link if there is one */ 
	    if(page < total_pages) 
	    { 
	  	pagination += '<span class="pagination"><a href="javascript:void(0);" onclick="javascript:searchLocationsNear(\'' + address + '\',\'' + center + '\',\'' + facilityleveltype + '\',\'' + borough + '\',' + next + ',' + radius + ',\'Y\')">Next</a>' + '&nbsp;&nbsp;</span>'; 
	    } 


          var bounds = new GLatLngBounds();


	    if (borough =='') {
	    	address=document.getElementById('address').value;
		radius=document.getElementById('radius').value;
	      html_head= '<span class="labelHeader1">' + markers[0].getAttribute('FacilityLevelName_Decode') + ' within ' +  Math.round(radius*100)/100 + ' miles of Address: ' + address + '<br><br></span>';
	    } else {
   		html_head= '<span class="labelHeader1">' + markers[0].getAttribute('FacilityLevelName_Decode') + ' In ' +  markers[0].getAttribute('BORO_DECODE') + '<br><br></span>';
	    }

	    sidebar.innerHTML = html_head;

	    for (var i = 0; i < markers.length; i++) {
	      var name = markers[i].getAttribute('Name');
            var address = markers[i].getAttribute('Location');
            var distance = parseFloat(markers[i].getAttribute('distance'));
            var point = new GLatLng(parseFloat(markers[i].getAttribute('lat')),
                                 parseFloat(markers[i].getAttribute('lng')));

            var marker = createMarker(point, name, address);
            map.addOverlay(marker);

         	var sidebarEntry = createSidebarEntry(i,markers, marker, name, address);
         	sidebar.appendChild(sidebarEntry);
            bounds.extend(point);
	    }
	    var div_pg = document.createElement('div');
	    div_pg.innerHTML = pagination;
	    sidebar.appendChild(div_pg);

          map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
          });
	  }else { //if without map

	    	document.getElementById('map').style.display = "none";
	    	document.getElementById('sidebar').style.width="800px"; 

	    if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
	    	xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
	    } else {
	    	xmlDoc = document.implementation.createDocument("","",null);
	    }
//alert(searchUrl); 
    	    xmlDoc.async = false; 
	    xmlDoc.load(searchUrl);

	    var markers = xmlDoc.documentElement.getElementsByTagName('marker');

	    var sidebar = document.getElementById('sidebar');
          sidebar.innerHTML = '';
          if (markers.length == 0) {
            sidebar.innerHTML = '<span class="noresult">No results found.</span>';
            return;
          }

	    /*** set the pagination ****/
	    total_results = markers[0].getAttribute('total_results');
	    total_pages = Math.ceil(total_results / max_results); 
	    pagination = ''; 

	    /* Create a PREV link if there is one */ 
	    if (page > 1) 
	    { 
	  	pagination += '<span class="pagination"><a href="javascript:void(0);" onclick="javascript:searchLocationsNear(\'' + address + '\',\'' + center + '\',\'' + facilityleveltype + '\',\'' + borough + '\',' + prev + ',' + radius + ',\'Y\')">Previous</a> ' + '&nbsp;&nbsp;</span>'; 
	    } 
	    /* Loop through the total pages */ 
	    for(i = 1; i <= total_pages; i++) 
	    { 
	  	if((page) == i) 
	   	{ 
	    	  pagination += '<span class="pagination">' + i + '&nbsp;&nbsp;</span>'; 
	  	} 
	  	else 
	  	{ 
	    	  pagination += '<span class="pagination"><a href="javascript:void(0);" onclick="javascript:searchLocationsNear(\''+ address + '\',\'' + center + '\',\'' + facilityleveltype + '\',\'' + borough + '\',' + i + ',' + radius+ ',\'Y\')">' + i + '</a>' + '&nbsp;&nbsp;</span>'; 
	  	} 
	    } 
	    /* Print NEXT link if there is one */ 
	    if(page < total_pages) 
	    { 
	  	pagination += '<span class="pagination"><a href="javascript:void(0);" onclick="javascript:searchLocationsNear(\'' + address + '\',\'' + center + '\',\'' + facilityleveltype + '\',\'' + borough + '\',' + next + ',' + radius + ',\'Y\')">Next</a>' + '&nbsp;&nbsp;</span>'; 
	    } 


	    if (borough =='') {
	    	address=document.getElementById('address').value;
		radius=document.getElementById('radius').value;
	      html_head= '<span class="labelHeader1">' + markers[0].getAttribute('FacilityLevelName_Decode') + ' within ' +  Math.round(radius*100)/100 + ' miles of Address: ' + address + '<br><br></span>';
	    } else {
   		html_head= '<span class="labelHeader1">' + markers[0].getAttribute('FacilityLevelName_Decode') + ' In ' +  markers[0].getAttribute('BORO_DECODE') + '<br><br></span>';
	    }

	    //html_head= '<span class="labelHeader1">' + markers[0].getAttribute('FacilityLevelName_Decode') + ' In ' +  markers[0].getAttribute('BORO_DECODE') + '<br><br></span>';
	    sidebar.innerHTML = html_head;
	    for (var i = 0; i < markers.length; i++) {
		var x=markers[i].attributes;
      	var div = document.createElement('div');
		var html='';
		var fieldlabel='';
		var fieldvalue='';
	      for (var y = 0; y < x.length; y++) {
	        //if (excludefield.indexOf(x[y].name) == -1){
		  if (searchArray('field',x[y].name) == false){  
		    fieldlabel=(searchArray('fieldname',x[y].name)== true ? '' : '<b>' + x[y].name + ':&nbsp;</b>'); 
		    fieldlabel=fieldlabel.replace('_',' ');	
                fieldvalue=(x[y].name == 'Name' ? '<span class="labelHeader">' + x[y].value + '</span>' : fieldvalue=(x[y].name == 'Distance' ? Math.round(x[y].value*100)/100 + ' miles' : x[y].value));
		    //fieldvalue=(x[y].name == 'Distance' ? Math.round(x[y].value*100)/100 + ' miles' : x[y].value);  
		    if (fieldvalue !=''){ 
		      html = html + fieldlabel + fieldvalue + "<br>";
		    }
		  }
		}
		html = html + "<br><br>";
      	div.innerHTML = html;
            sidebar.appendChild(div);
	    }
          var div_pg = document.createElement('div');
	    div_pg.innerHTML = pagination;
	    sidebar.appendChild(div_pg);
	  }  
      }  //end  of func  


	var GMapSidebar_html = "";
     // arrays to hold copies of the markers and html used by the GMapSidebar
      // because the function closure trick doesnt work there
      var gmarkers = [];
      var htmls = [];
      var i = 0;
      // arrays to hold variants of the info window html with get direction forms open
      var to_htmls = [];
      var from_htmls = [];
	var nearby_htmls = [];
	var init_htmls = [];
var browser=CheckBrowser();


      function createMarker(point, name, address) {
        var marker = new GMarker(point);
        var html = '<div style="width:200px"><b>' + name + '</b> <br/>' + address + '<br>';

if (browser == 'IE6') { //if ie6 need a return false
	  init_htmls[i]= html + '<br><a href="javascript:void(0);" onclick="streetviewLoad(\'' + point + '\'); return false;">street view<a><br>' +
		'Directions: <a href="javascript:void(0);" onclick="tohere('+i+')">To here</a> - <a href="javascript:void(0);"  onclick="fromhere('+i+')">From here</a>'
		+ '<br><a href="javascript:void(0);" onclick="nearby('+i+')">search nearby</a>';


    	  html = html + '<br><a href="javascript:void(0);" onclick="javascript:streetviewLoad(\'' + point + '\');return false;">street view<a><br>';
} else {
	  init_htmls[i]= html + '<br><a href="javascript:void(0);" onclick="streetviewLoad(\'' + point + '\')">street view<a><br>' +
		'Directions: <a href="javascript:void(0);" onclick="tohere('+i+')">To here</a> - <a href="javascript:void(0);"  onclick="fromhere('+i+')">From here</a>'
		+ '<br><a href="javascript:void(0);" onclick="nearby('+i+')">search nearby</a>';


    	  html = html + '<br><a href="javascript:void(0);" onclick="javascript:streetviewLoad(\'' + point + '\');">street view<a><br>';


} //end of chk browser

    	  //To be used only for tohere and from here so the nearby inactive version is available 
    	  html_n=html + '<a href="javascript:void(0);" onclick="nearby('+i+')">search nearby</a>';

        // The info window version with the "to here" form open
        to_htmls[i] = html_n + '<br><br>Directions: <b>To here</b> - <a href="javascript:void(0);" onclick="fromhere(' + i + ')">From here</a>' +
           '<br>Start address:<form action="http://maps.google.com/maps" method="get" target="maps_ref">' +
           '<input type="text" SIZE=30 MAXLENGTH=40 name="saddr" id="saddr" value="" /><br>' +
           '<INPUT value="Get Directions" TYPE="SUBMIT">' +
           '<input type="hidden" name="daddr" value="' + address + 
                  "(" + name + ")" + 
           '"/>' + '<br><a href="javascript:void(0);" onclick="back(' + i + ')"><< Back </a>';
        // The info window version with the "to here" form open
        from_htmls[i] = html_n + '<br><br>Directions: <a href="javascript:void(0);" onclick="tohere(' + i + ')">To here</a> - <b>From here</b>' +
           '<br>End address:<form action="http://maps.google.com/maps" method="get"" target="maps_ref">' +
           '<input type="text" SIZE=30 MAXLENGTH=40 name="daddr" id="daddr" value="" /><br>' +
           '<INPUT value="Get Directions" TYPE="SUBMIT">' +
           '<input type="hidden" name="saddr" value="' + address + 
                  "(" + name + ")" + 
           '"/>' + '<br><a href="javascript:void(0);" onclick="back(' + i + ')"><< Back </a>';

        // The inactive version of the direction info
        html = html + 'Directions: <a href="javascript:void(0);" onclick="tohere('+i+')">To here</a> - <a href="javascript:void(0);"  onclick="fromhere('+i+')">From here</a>';
	  

        // The info window version with the search nearby form open
        nearby_htmls[i] = html + '<br><br>Search Nearby: e.g. "pizza"<br>' +
           '<form action="http://maps.google.com/maps" method="get"" target="maps_ref">' +
           '<input type="text" SIZE=20 MAXLENGTH=80 name="q" id="q" value="" />' +
           '<INPUT value="Go" TYPE="SUBMIT">' +
           '<input type="hidden" name="near" value="' + name + ' at ' + address + 
		'@' + point.lat() + ',' + point.lng() + 
           '"/>' + '<br><a href="javascript:void(0);" onclick="back(' + i + ')"><< Back </a>';

        // The inactive version of the nearby info
        html = html + '<br><a href="javascript:void(0);" onclick="nearby('+i+')">search nearby</a>';

        GEvent.addListener(marker, 'click', function() {	   
          marker.openInfoWindowHtml(html);  
      });

        // save the info we need to use later for the GMapSidebar
        gmarkers[i] = marker;
        htmls[i] = html;
        // add a line to the GMapSidebar html
       // GMapSidebar_html += '<a href="javascript:myclick(' + i + ')">' + name + '</a><br>';
        i++;

        return marker;
      } //end  of func

      // functions that open the directions forms
      function tohere(i) {
        gmarkers[i].openInfoWindowHtml(to_htmls[i]);
      }
      function fromhere(i) {
        gmarkers[i].openInfoWindowHtml(from_htmls[i]);
      }


	// functions that open the search nearby forms
      function nearby(i) {
        gmarkers[i].openInfoWindowHtml(nearby_htmls[i]);
      }

	// functions that back to inactive
      function back(i) {
        gmarkers[i].openInfoWindowHtml(init_htmls[i]);
      }

      function streetviewLoad(point){
                  document.getElementById("loading").style.visibility="visible";

	  //remove the () on the point received
	  point=point.substr(1);
	  point = point.substring(0,point.length-1);

	  var allOptionsArray = point.split(",");

    	  var streetpoints = new GLatLng(allOptionsArray[0], allOptionsArray[1]);  
    	  panoramaOptions = {latlng:streetpoints}; 
 
  	  mypano=new GStreetviewPanorama(document.getElementById("map2"), panoramaOptions);

 	  GEvent.addListener(mypano,"error",handleNoFlash);

	  //hide the previous map
  	  document.getElementById("map").style.display="none";

  	  //show the streetview 
	  document.getElementById('map2').innerHTML='';
  	  document.getElementById('map2').style.display="block";
  	  document.getElementById('closebutton').style.display="block";
        document.getElementById("loading").style.visibility="hidden";


      } //end  of func

	function handleNoFlash(errorCode) { 
  	  if (errorCode == 603) { 
    		alert("Error: Flash doesn't appear to be supported by your browser"); 
    	   	return; 
  	  } 
	} //end  of func  

	function closestreetview(){
  	  //close streetview
  	  document.getElementById("map2").style.display="none";
  	  document.getElementById("closebutton").style.display="none";

  	  //open the map
  	  document.getElementById("map").style.display="block";

	} //end  of func

	function zoomhere(){
  	  var z = map.getCurrentMapType().getMaximumResolution();
	  if (z > (map.getZoom() + 2)){
  	    map.setZoom((z + map.getZoom())/2);
	  }
	}  //end  of func

    	function createSidebarEntry(i,markers,marker, name, address) {
            //var excludefieldname="Name,Location";
		//var excludefield="Boro,lat,lng,EntityType,AddressBldg,AddressStreetName,AddressCity,AddressState,AddressZipCode,AddressLocation";
		var x=markers[i].attributes;
      	var div = document.createElement('div');
		var html='';
		var fieldlabel='';
		var fieldvalue='';

	      for (var y = 0; y < x.length; y++) {
		  if (searchArray('field',x[y].name) == false){  
		    fieldlabel=(searchArray('fieldname',x[y].name)== true ? '' : '<b>' + x[y].name + ':&nbsp;</b>'); 
		    fieldlabel=fieldlabel.replace('_',' ');	
                fieldvalue=(x[y].name == 'Name' ? '<span class="labelHeader">' + x[y].value + '</span>' : fieldvalue=(x[y].name == 'Distance' ? Math.round(x[y].value*100)/100 + ' miles' : x[y].value));  
		    //fieldvalue=(x[y].name == 'Distance' ? Math.round(x[y].value*100)/100 + ' miles' : x[y].value);  
		    if (fieldvalue !=''){ 
			html = html + fieldlabel + fieldvalue + "<br>";
		    }
		  }
		}


      	div.innerHTML = html + '<br>';
      	div.style.cursor = 'pointer';
      	div.style.marginBottom = '5px'; 

      	GEvent.addDomListener(div, 'click', function() {
        	GEvent.trigger(marker, 'click');
      	});
      	GEvent.addDomListener(div, 'mouseover', function() {
        	div.style.backgroundColor = '#A8FF9E';
      	});
      	GEvent.addDomListener(div, 'mouseout', function() {
        	div.style.backgroundColor = '#F3FFCE'; /*'#fff';*/
      	});
      	return div;
    	} //end  of func



    function popup(filename,title){
               document.getElementById("loading").style.visibility="visible";

	var isIE = (navigator.appName=="Microsoft Internet Explorer");
	if(isIE) {
	  oRequest = new ActiveXObject("Msxml2.XMLHTTP");
	  oRequest = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
	  oRequest = new XMLHttpRequest();
	}

               var sURL  = "http://www.lookintonyc.com/" + filename;
		  //var sURL  = "http://sonlaptop02/lookintonyc/" + filename;
	oRequest.open("GET",sURL,false);
	oRequest.setRequestHeader("User-Agent",navigator.userAgent);
	oRequest.send(null)

	if (oRequest.status==200) {
	  document.getElementById("popup_content").innerHTML= oRequest.responseText;
	  document.getElementById("popup_title").innerHTML= title;

	  document.getElementById("popup_bg").style.visibility="visible";
	  document.getElementById("popup_content").style.visibility="visible";
	  document.getElementById("popup_closebutton").style.visibility="visible";

	 //hide drop down due to IE problem showing ontop of div
	  document.getElementById("facilityleveltype").style.visibility="hidden";
	  document.getElementById("borough").style.visibility="hidden";
	  document.getElementById("radius").style.visibility="hidden";
	} 
	else alert("An Error has occured!");
                document.getElementById("loading").style.visibility="hidden";
    } //end  of func

    function closepopup(){
	document.getElementById("popup_bg").style.visibility="hidden";
	document.getElementById("popup_content").style.visibility="hidden";
	document.getElementById("popup_closebutton").style.visibility="hidden";

          //show drop down due to IE problem showing ontop of div    
	  document.getElementById("facilityleveltype").style.visibility="visible";
	  document.getElementById("borough").style.visibility="visible";
	  document.getElementById("radius").style.visibility="visible";

    } //end  of func
  
    function hideloading(){
                document.getElementById("loading").style.visibility="hidden";
    }

   //]]>
