﻿  //Google Maps
  
   var latstore, longstore,storeid,typestore
   var myPano;
   //google.load("maps", "2");  
        
        // Call this function when the page has been loaded
        function mapsLoaded(id, latitude, longitude) 
        {
               
                var map = new GMap2(document.getElementById(id));
                map.addControl(new GLargeMapControl());
                map.addControl(new GMapTypeControl());
                map.setCenter(new GLatLng(latitude, longitude), 13);
                 // Create a base icon for all of our markers that specifies the
                // shadow, icon dimensions, etc.
                var baseIcon = new GIcon();
                baseIcon.shadow = BasePath + "images/FlagShadow.png";
                baseIcon.iconSize = new GSize(27, 40);
                baseIcon.shadowSize = new GSize(41, 21);
                baseIcon.iconAnchor = new GPoint(9, 34);
                baseIcon.infoWindowAnchor = new GPoint(9, 2);
                baseIcon.infoShadowAnchor = new GPoint(18, 25);
                
                var icon = new GIcon(baseIcon);
                icon.image = BasePath + "images/pin.aspx?CommunityNum=0&GraphicName=FlagSF.png&MarkerNumbers=false"; //Single Family Icon
                
                //Create our marker based upon lat/long and icon
                var marker = new GMarker(new GLatLng(latitude, longitude), icon);
                map.addOverlay(marker);
        }
    function OpenMapWindow( tableid, id, latitude, longitude, cellnum )
    {
        storeid = tableid;
        if (document.getElementById) { // DOM3 = IE5, NS6
		    if(document.getElementById(tableid).style.display == 'none' || (latitude != latstore && longitude !=longstore) || typestore != "map")
		    {
			    hidedivgrid("birdeye" + cellnum );
			    showdiv( id );
			    showdiv(tableid);
			    mapsLoaded(id, latitude, longitude);
			    latstore = latitude;
                longstore = longitude;
                typestore = "map";
		    }
		    else if( latitude == latstore && longitude == longstore )
		    {
			    hidedivgrid(tableid);
			    storeid = null;
			    latstore = null;
			    longstore = null;
			    typestore = null;
		    }	
	    }
	    else {
		    if (document.layers) { // Netscape 4
			    if(document.tableid.display == 'none' || (latitude != latstore && longitude !=longstore) || typestore != "map")
			    {
				    hidedivgrid("birdeye" + cellnum );
				    showdiv( id );
				    showdiv(tableid);
				    mapsLoaded(id, latitude, longitude);
				    latstore = latitude;
                    longstore = longitude;
                    typestore = "map";
			    }	
		    else if( latitude == latstore && longitude == longstore )
		    {
			    hidedivgrid(tableid);
			    storeid = null;
			    latstore = null;
			    longstore = null;
			    typestore = null;
			    }
		    }
		    else { // IE 4
			    if(document.all.tableid.style.display == 'none'|| (latitude != latstore && longitude !=longstore) || typestore != "map")
			    {
				    hidedivgrid("birdeye" + cellnum );
				    showdiv( id );
				    showdiv(tableid);
				    mapsLoaded(id, latitude, longitude);
				    latstore = latitude;
                    longstore = longitude;
                    typestore = "map";
			    }	
		    else if( latitude == latstore && longitude == longstore )
		    {
			    hidedivgrid(tableid);
			    storeid = null;
			    latstore = null;
			    longstore = null;
			    typestore = null;
			    }
		    }
	    }	
    }
    
    function OpenStreetViewGrid( tableid, panid, latitude, longitude, cellnum )
    {
        storeid = tableid;
        if (document.getElementById) { // DOM3 = IE5, NS6
		    if(document.getElementById(tableid).style.display == 'none' || (latitude != latstore && longitude !=longstore) || typestore != "street")
		    {
			    hidedivgrid("birdeye" + cellnum );
			    showdiv( panid );
			    showdiv(tableid);
			    StartStreetViewGrid(latitude, longitude, panid);
			    latstore = latitude;
                longstore = longitude;
                typestore = "street";
		    }
		    else if( latitude == latstore && longitude == longstore )
		    {
			    myPano.remove();
			    hidedivgrid(tableid);
			    storeid = null;
			    latstore = null;
			    longstore = null;
			    typestore = null;
		    }	
	    }
	    else {
		    if (document.layers) { // Netscape 4
			    if(document.tableid.display == 'none' || (latitude != latstore && longitude !=longstore) || typestore != "map")
			    {
				    hidedivgrid("birdeye" + cellnum );
				    showdiv( panid );
				    showdiv(tableid);
				    StartStreetViewGrid(latitude, longitude, panid);
				    latstore = latitude;
                    longstore = longitude;
                    typestore = "street";
			    }	
		    else if( latitude == latstore && longitude == longstore ) 
		    {
			    myPano.remove();
			    hidedivgrid(tableid);
			    storeid = null;
			    latstore = null;
			    longstore = null;
			    typestore = null;
			    }
		    }
		    else { // IE 4
			    if(document.all.tableid.style.display == 'none' || (latitude != latstore && longitude !=longstore) || typestore != "map")
			    {
				    hidedivgrid("birdeye" + cellnum );
				    showdiv( panid );
				    showdiv(tableid);
				    StartStreetViewGrid(latitude, longitude, panid);
				    latstore = latitude;
                    longstore = longitude;
                    typestore = "street";
			    }	
		    else if(latitude == latstore && longitude == longstore)
		    {
			    myPano.remove();
			    hidedivgrid(tableid);
			    storeid = null;
			    latstore = null;
			    longstore = null;
			    typestore = null;
			    }
		    }
	    }	

    }
    
    function StartStreetViewGrid(latitude, longitude, id)
    {
            community = new GLatLng(latitude,longitude);
            //myPOV = {yaw:370.64659986187695,pitch:0};
            svOpts = {latlng:community };
            myPano = new GStreetviewPanorama(document.getElementById(id), svOpts);
            //myPano.setContainer(document.getElementById(id)); 
            GEvent.addListener(myPano, "error", handleNoFlashStreet);
    }
    
         function handleNoFlashStreet(errorCode) {
        if (errorCode == 603) {
            //document.getElementById(storeid).style.display = "none";
            alert("Error: Flash doesn't appear to be supported by your browser");
            hidedivgrid(storeid);
            latstore = null;
            longstore = null;
            storeid = null;
            typestore = null;
            return;
        }
        if (errorCode == 600 ) {
            //document.getElementById(storeid).style.display = "none";
            alert("We're sorry, there is no available street view map for this community");
            hidedivgrid(storeid);
            latstore = null;
            longstore = null;
            storeid = null;
            typestore = null;
        return;
        }
        }
        
        function handleNoFlashStreet(errorCode) {
        if (errorCode == 603) {
            //document.getElementById(storeid).style.display = "none";
            alert("Error: Flash doesn't appear to be supported by your browser");
            hidedivgrid(storeid);
            latstore = null;
            longstore = null;
            storeid = null;
            typestore = null;
            return;
        }
        if (errorCode == 600 ) {
            //document.getElementById(storeid).style.display = "none";
            alert("We're sorry, there is no available street view map for this community");
            hidedivgrid(storeid);
            latstore = null;
            longstore = null;
            storeid = null;
            typestore = null;
        return;
        }
    }
    
    //Live Maps
    var birdeyemap = null;
    
    function GetBirdEyeMapGrid(tableid, panid, latitude, longitude, cellnum)         
    {
        storeid = tableid;
        if (document.getElementById) { // DOM3 = IE5, NS6
		    if(document.getElementById(tableid).style.display == 'none' || (latitude != latstore && longitude !=longstore) || typestore != "birdeye")
		    {
			    hidedivgrid("contentarea" + cellnum );
			    showdiv( panid );
			    showdiv(tableid);
			    StartBirdEyeView(latitude, longitude, panid);
			    latstore = latitude;
                longstore = longitude;
                typestore = "birdeye";
		    }
		    else if( latitude == latstore && longitude == longstore )
		    {
			    hidedivgrid(tableid);
			    storeid = null;
			    latstore = null;
			    longstore = null;
			    typestore = null;
		    }	
	    }
	    else {
		    if (document.layers) { // Netscape 4
			    if(document.tableid.display == 'none' || (latitude != latstore && longitude !=longstore) || typestore != "birdeye")
			    {
				    hidedivgrid("contentarea" + cellnum );
				    showdiv( panid );
				    showdiv(tableid);
				    StartBirdEyeView(latitude, longitude, panid);
				    latstore = latitude;
                    longstore = longitude;
                    typestore = "birdeye";
			    }	
		    else if( latitude == latstore && longitude == longstore ) 
		    {
			    hidedivgrid(tableid);
			    storeid = null;
			    latstore = null;
			    longstore = null;
			    typestore = null;
			    }
		    }
		    else { // IE 4
			    if(document.all.tableid.style.display == 'none' || (latitude != latstore && longitude !=longstore) || typestore != "birdeye")
			    {
				    hidedivgrid("contentarea" + cellnum );
				    showdiv( panid );
				    showdiv(tableid);
				    StartBirdEyeView(latitude, longitude, panid);
				    latstore = latitude;
                    longstore = longitude;
                    typestore = "birdeye";
			    }	
		    else if(latitude == latstore && longitude == longstore)
		    {
			    hidedivgrid(tableid);
			    storeid = null;
			    latstore = null;
			    longstore = null;
			    typestore = null;
			    }
		    }
	    }	

    }
    
    function StartBirdEyeView( latitude, longitude, id)
    {
            birdeyemap = new VEMap(id); 
            birdeyemap.LoadMap(new VELatLong(latitude, longitude), 10 ,VEMapStyle.BirdseyeHybrid);
            var pinLocation = new VELatLong(latitude, longitude);
            var pushpin = new VEShape(VEShapeType.Pushpin, pinLocation);               
            birdeyemap.AddShape(pushpin);
    }
    
        function hidedivgrid(id) {
	    //safe function to hide an element with a specified id
	    if (document.getElementById) { // DOM3 = IE5, NS6
	        if(myPano != null) 
	        {
	            myPano.remove();
                myPano = null;
                GUnload();	            
	        }
		    document.getElementById(id).style.display = 'none';
	    }
	    else {
		    if (document.layers) { // Netscape 4
			    if(myPano != null)
			    {
			         myPano.remove();
			         myPano = null;
                     GUnload();	
			    }
			    document.id.display = 'none';
		    }
		    else { // IE 4
		        if(myPano != null)
		        {
		            myPano.remove();
		            myPano = null;
                    GUnload();	
		        }
			    document.all.id.style.display = 'none';
		    }
	    }
    }

    function showdiv(id) {
	    //safe function to show an element with a specified id
	    if (document.getElementById) { // DOM3 = IE5, NS6
		    document.getElementById(id).style.display = 'block';
	    }
	    else {
		    if (document.layers) { // Netscape 4
			    document.id.display = 'block';
		    }
		    else { // IE 4
			    document.all.id.style.display = 'block';
		    }
	    }
    }



