// Norton Lot Bank - JavaScript Document



function showRecentSearches(){
     var thirdFade = new Spry.Effect.Fade('xrecent', {duration: 500, from: 0, to: 100, toggle:false});
     thirdFade.start();
     
     //var item = document.getElementById('xrecent');
     //item.onmouseover = hideRecentSearches;
}


function hideRecentSearches(e){


     if (!e) var e = window.event;
	var tg = (window.event) ? e.srcElement : e.target;
	if (tg.nodeName != 'DIV') return;
	var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
	while (reltg != tg && reltg.nodeName != 'BODY')
		reltg= reltg.parentNode
	if (reltg== tg) return;

     toggleOff('xrecent');

     //var thirdFade = new Spry.Effect.Fade('xrecent', {duration: 500, from: 100, to: 0, toggle:true});
     //thirdFade.start();
     
     //alert('fade out');
     
     //var item = document.getElementById('xrecent');
     //item.onmouseover = null;
}

function toggleOff(id){
     var item = document.getElementById(id);
     
     if(item)
          item.style.display = 'none';
}

function showAdvOptions(){
     var advFade = new Spry.Effect.Fade('xadv', {duration: 500, from: 0, to: 100, toggle:false});
     advFade.start();
     
     //var item = document.getElementById('xrecent');
     //item.onmouseover = hideRecentSearches;
}



function showXBubble(e, show_id ){
     //alert(document.getElementById(show_id));
     
      
     
     var eventcnt = document.getElementById(show_id);
     
     document.getElementById("btcnt").innerHTML = eventcnt.innerHTML;
     
     BLocate(e);
     
      document.getElementById("btci").style.display='block';
    
}

function hideXBubble(e){
     //var d=document.getElementById("btc");
     //if(d.childNodes.length>0) d.removeChild(d.firstChild);
     document.getElementById("btci").style.display='none';
}

function BLocate(e, col){

//alert(e);
     var posx=0,posy=0;
     
     if(e==null) e=window.event;
     
     if(e.pageX || e.pageY){
     
         posx=e.pageX; posy=e.pageY;
         
     }else if(e.clientX || e.clientY){
     
          if(document.documentElement.scrollTop){
               posx=e.clientX+document.documentElement.scrollLeft;
               posy=e.clientY+document.documentElement.scrollTop;
          } else {
               posx=e.clientX+document.body.scrollLeft;
               posy=e.clientY+document.body.scrollTop;
          }
     }
     
     //alert(posy +' '+ posx);
     //document.getElementById("btci").style.top=(posy+8)+"px";
     //document.getElementById("btci").style.left=(posx-20)+"px";
	 document.getElementById("btci").style.top=(posy-120)+"px";
	 
	 if( col==2 || col ==3 )
	 	xleft = (posx-380)+"px";
	 else
	 	xleft = (posx+40)+"px";
		
     document.getElementById("btci").style.left=xleft;
	 
}





/* ////////////////////////////////////////////// */
/* ////////////////////////////////////////////// */
// MAP FUNCTIONS //////////////////////////////// //
/* ////////////////////////////////////////////// */
/* ////////////////////////////////////////////// */


    function addLatLonMarkerList(lat, lon, label_html, loc_type, lot_id ){
    
          point = new GLatLng( lat, lon );
  
          //var label_txt = '<b>'+address_title+'<'+'/b><br />'+ address; // + '<br>'+ lat +'<br>'+lon;
          marker = createMarker( point, label_html, loc_type, lot_id );
          
          markers[lot_id] = marker;
          
          map.addOverlay(marker);
    
    }



    function addLatLonMarker(lat, lon, address, address_title, loc_type ){
    
          point = new GLatLng( lat, lon );
  
          var label_txt = '<b>'+address_title+'<'+'/b><br />'+ address; // + '<br>'+ lat +'<br>'+lon;
          marker = createMarker(point, label_txt, loc_type);
            
          map.addOverlay(marker);
    
    }
    
    function addAddressMarker(address, address_title, loc_type){
        //geocoder.getLocations(address, addAddressToMap);

        geocoder.getLocations(address, 
        
          function addAddressToMap2(response) {
               //map.clearOverlays();
               if (!response || response.Status.code != 200) {
                    //alert("Sorry, we were unable to geocode that address: "+address_title);
               } else {
                    place = response.Placemark[0];
                    point = new GLatLng(place.Point.coordinates[1],
                                      place.Point.coordinates[0]);
                                      
                    var lat = place.Point.coordinates[1];
                    var lon = place.Point.coordinates[0];
                    
                    var label_txt = '<b>'+address_title+'<'+'/b><br />'+place.address + '<br>'+ lat +'<br>'+lon;
                    marker = createMarker(point, label_txt, loc_type);
                    
                    map.addOverlay(marker);
               
               
               }
          }
        
        
        );
        
    }

    // addAddressToMap() is called when the geocoder returns an
    // answer.  It adds a marker to the map with an open info window
    // showing the nicely formatted version of the address and the country code.
    function addAddressToMap(response) {
      //map.clearOverlays();
      if (!response || response.Status.code != 200) {
        alert("Sorry, we were unable to geocode that address");
      } else {
        place = response.Placemark[0];
        point = new GLatLng(place.Point.coordinates[1],
                            place.Point.coordinates[0]);

       var label_txt = place.address + '<br>';
       marker = createMarker(point, label_txt );
       
       map.addOverlay(marker);

          
      }
    }
    
     // Creates a marker whose info window displays the letter corresponding
     // to the given index.
     function createMarker(point, label, loc_type, lot_id ) {
       
       var xxIcon = new GIcon(G_DEFAULT_ICON);
       
       if(loc_type=='safestart') { 
          xxIcon.image = "http://www.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png";
          xxIcon.iconSize = new GSize(32,32);
          xxIcon.iconAnchor  = new GPoint(15,32);
       }

       
       markerOptions = { icon:xxIcon };
       var marker = new GMarker(point, markerOptions);
     
       GEvent.addListener(marker, "click", function() {
         var html = $('#vr_'+lot_id+' div.vpop').html();
         marker.openInfoWindowHtml( html );
         highlightRow(lot_id);
       });
       
       return marker;
}


    // showLocation() is called when you click on the Search button
    // in the form.  It geocodes the address entered into the form
    // and adds a marker to the map at that location.
    function showLocation() {
      var address = document.forms[0].q.value;
      geocoder.getLocations(address, addAddressToMap);
    }

   // findLocation() is used to enter the sample addresses into the form.
    function findLocation(address) {
      document.forms[0].q.value = address;
      showLocation();
    }




