﻿// get pin details
var pinDetails3D;     
var pinLat;
var pinLon;
var pinIDPlotted;
var targetPin;
var pinImgSource;
var pinImgPlotted;
// pin detail variables for indexed pins.... (function used CustomIconSpecification)
var pinHTML;
var pinDiscription;
var pinTitle;
var pinType;


   
function getPinDetails(details)
{
    var commaIndex = details.indexOf(',');
    pinDetails3D = details; 
    mlsCompanyID = details.substring(0, commaIndex);
    details = details.substring(commaIndex+1, details.length);
    commaIndex = details.indexOf(',');
    mlsNumber = details.substring(0, commaIndex);
    details = details.substring(commaIndex+1, details.length);
    commaIndex = details.indexOf(',');
    pinLat = details.substring(0, commaIndex);
    details = details.substring(commaIndex+1, details.length);
    commaIndex = details.indexOf(',');
    pinLon = details.substring(0, commaIndex);
    details = details.substring(commaIndex+1, details.length);
    commaIndex = details.indexOf(',');
    pinIDPlotted = details.substring(0, commaIndex);
    pinImgSource = details.substring(commaIndex+1, details.length);
}
// pin details for Map View
function getPinDetailsMapView(details)
{
    var commaIndex = details.indexOf(',');
    pinDetails3D = details; 
    mlsCompanyID = details.substring(0, commaIndex);
    details = details.substring(commaIndex+1, details.length);
    commaIndex = details.indexOf(',');
    mlsNumber = details.substring(0, commaIndex);
    details = details.substring(commaIndex+1, details.length);
    commaIndex = details.indexOf(',');
    pinLat = details.substring(0, commaIndex);
    details = details.substring(commaIndex+1, details.length);
    commaIndex = details.indexOf(',');
    pinLon = details.substring(0, commaIndex);
    details = details.substring(commaIndex+1, details.length);
    commaIndex = details.indexOf(',');
    pinIDPlotted = details.substring(commaIndex+1, details.length);
}

// pin details for Indexed pin ex- what's nearBy
function getPinDetailsIndexed(pinObj)
{
    pinLat = pinObj.Latitude;
    pinLon = pinObj.Longitude;
    pinHTML = pinObj._customIcon;
    pinDiscription = pinObj.GetDescription();
    pinTitle = pinObj.GetTitle();
}


var pinInfoArray = new Array();
function CollectPinInfo(pinID, type, latitude, longitude)
{
    this.pinID = pinID;
    this.type = type;
    this.latitude = latitude;
    this.longitude = longitude;
}

// Main entry function
// This function is only being used when only one SinglePin is present on map. Rest of pins should be indexed pins
function SearchResults_Pin(id,description,type,latitude,longitude)
{
   var poly01 = new VEShape(VEShapeType.Pushpin, new VELatLong(latitude,longitude));
   if(type == "POI")
   {
    var detail = "<div style=\"height:20px; width:20px;text-align:center;vertical-align:middle\" class=\"Pushpin_POI Pushpin_POI\">"+id+"</div>";
    poly01.SetTitle(id.toString());
   }
    
   if(type == "SinglePin")
   {
    var detail = "<div style=\"height:14px; width:15px;\" class=\"Pushpin_Small Pushpin_SinglePin\"></div>";
    poly01.SetTitle(type);
   }
   
   if(type == "MyPlaces")
   {
   var detail = "<div style=\"background-image:url(http://images.longandfoster.com/Images/Map-Icons/my_places-23.gif);height:20px;width:23px;padding-top:4px\">&nbsp;&nbsp;";
   detail = detail + "<b><font color=\"White\">" + id + "</font></b>";
   poly01.SetTitle(type);
   }
   if(type == "IndexedListing")
   {
    var detail = "<div style=\"height:20px; width:20px;text-align:center;vertical-align:middle\" class=\"Pushpin_POI Pushpin_POI\">"+id+"</div>";
    poly01.SetTitle(id.toString());
   }
   
   var collectPinInfoObj = new CollectPinInfo(id, type, latitude, longitude);
   pinInfoArray.push(collectPinInfoObj);
    poly01.SetCustomIcon(detail);
    poly01.SetDescription(description);
    
    map.AddShape(poly01);
   // map.AttachEvent("onmouseover", PinHoverIndexed);
}
function attachInitialEvents()
{
      map.AttachEvent("onmouseover", PinHoverIndexed);
      map.AttachEvent("onmousedown",attachPinHoverOutEvent);
      map.AttachEvent("onmousewheel",attachPinHoverOutEvent);
      if(document.getElementById('MSVE_navAction_tinyZoomBar_plus'))
      {
      document.getElementById('MSVE_navAction_tinyZoomBar_plus').onmousedown = attachPinHoverOutEvent;
      document.getElementById('MSVE_navAction_tinyZoomBar_minus').onmousedown = attachPinHoverOutEvent;
      }
}

function attachPinHoverOutEvent(e)
{
if(document.getElementById('PinControlDiv') != null)
    {
    pinHoverOutIndexed();
    }
}
function PinHoverIndexed(e)
    { 
      if(document.getElementById('PinControlDiv') != null)
        {
        pinHoverOutIndexed();
        }
        if(e.elementID)
        {
        var pin= map.GetShapeByID(e.elementID);
        getPinDetailsIndexed(pin);
        if(pinTitle == "MyPlaces")
        showPopupMyPlaces(pin);
        if(pinTitle == "Start" || pinTitle == "End" || pinTitle.indexOf('Step') != -1)
        showPopupMyTrips(pin);
        else
        addDivControlIndexed(pin);
        }
    }
   // function for handling pushpin popup in myPlaces
   function showPopupMyPlaces(pinObj)
   {
   map.DeleteShape(pinObj);
   var poly01 = new VEShape(VEShapeType.Pushpin, new VELatLong(pinLat,pinLon ));
    poly01.SetCustomIcon(pinHTML);
    poly01.SetDescription(pinDiscription);
    poly01.SetTitle(pinTitle);
    map.AddShape(poly01);
   ShowPopup(pinDiscription);
   }
 function showPopupMyTrips(pinObj)
   {
   map.DeleteShape(pinObj);
   var instructionNo;
   var poly01 = new VEShape(VEShapeType.Pushpin, new VELatLong(pinLat,pinLon ));
    poly01.SetCustomIcon(pinHTML);
    poly01.SetDescription(pinDiscription);
    poly01.SetTitle(pinTitle);
    map.AddShape(poly01);
    if(pinTitle == "Start")
    instructionNo = 0;
    else if(pinTitle == "End")
    instructionNo = directionPoints.length - 1;
    else
    instructionNo = parseInt(pinTitle.substring(5, pinTitle.length));
    var content = GetInstructionPopup(instructionNo);
    ShowPopup(content);
   }
     
  function addDivControlIndexed(pin)
    {
        var el = document.createElement("div");
        var pixel = map.LatLongToPixel(new VELatLong(pin.Latitude,pin.Longitude ));
        var x=pixel.x - 13;
	    var y=pixel.y - 10;
	    el.id = "PinControlDiv";
	    el.style.top = y+'px'; 
        el.style.left = x+'px';
        
        if(pinTitle == "SinglePin")
            {
            el.className = 'Pushpin_Small Pushpin_SinglePin_On';
            el.style.height = '14px';
            el.style.width = '15px';
            }
            else if(pinTitle == "SinglePin_Clicked")
            {
            el.className = 'Pushpin_Small Pushpin_PushPinClicked_ON';
            el.style.height = '14px';
            el.style.width = '15px';
            }
        else
	        {
	        el.className = 'Pushpin_POI Pushpin_POI_ON';
	        el.innerHTML = pinTitle;
	        el.style.height = '20px';
            el.style.width = '20px';
            el.style.textAlign = 'center';
	        }
	    el.onmouseout = pinHoverOutIndexed;
        el.onclick = getContentForPushpinIndexed;
        map.DeleteShape(pin);
        map.AddControl(el);
	    map.AttachEvent("onmouseover", PinHoverIndexed);
    }

function pinHoverOutIndexed(e)
 {
    RemoveMyControlIndexed();
    var poly01 = new VEShape(VEShapeType.Pushpin, new VELatLong(pinLat,pinLon ));
	    poly01.SetCustomIcon(pinHTML);
	    poly01.SetDescription(pinDiscription);
	    poly01.SetTitle(pinTitle);
	    map.AddShape(poly01);
        map.AttachEvent("onmouseover", PinHoverIndexed);
    
 }

function RemoveMyControlIndexed()
 {
    while(document.getElementById("PinControlDiv") != null )
    {
    var mycontrol = document.getElementById("PinControlDiv");
    if (mycontrol!=null) mycontrol.parentNode.removeChild(mycontrol);
    mycontrol = null;
    }
 }

function getContentForPushpinIndexed(e)
{
    var inc = 0;
    var currentPinType;
    var poly01;
    if(pinTitle == "SinglePin")
        {
            poly01 = new VEShape(VEShapeType.Pushpin, new VELatLong(pinLat,pinLon ));
	        var detail = "<div id=\"SinglePin_dtls\" style=\"height:14px; width:15px;\" class=\"Pushpin_Small Pushpin_PushPinClicked\"></div>";
	        poly01.SetCustomIcon(detail);
	        RemoveMyControlIndexed();
	        map.AddShape(poly01);
	        poly01.SetDescription(pinDiscription);
	        poly01.SetTitle("SinglePin_Clicked");
            
            while(pinInfoArray[inc].pinID != pinTitle)
            inc++;
            pinInfoArray[inc].pinID = currentPinType = "SinglePin_Clicked"; // update record in pin collection
        }
        else
        {
            while(pinInfoArray[inc].pinID != pinTitle)
            inc++;   
            currentPinType = pinInfoArray[inc].type;
        }
    //if high-slide container is present on the page.. and clickedPin is a listing, only then show the listing details on High-slide
    if(document.getElementById('highslideContainer') != null && (currentPinType.indexOf('SinglePin') != -1 || currentPinType == 'IndexedListing'))
        {
            document.getElementById('highslideContainer').innerHTML=pinDiscription;
            hs.height = 430;
            if(pinTitle == "SinglePin")
            {
                var pObj = document.getElementById('SinglePin_dtls');
                hs.htmlExpand(pObj,{contentId:'listingContent_SinglePin'});
            }
            else if(pinTitle == "SinglePin_Clicked")
            hs.htmlExpand(this,{contentId:'listingContent_SinglePin'});
            else
            hs.htmlExpand(this,{contentId:'listingContent_'+pinTitle}); // indexed pin listings. ex; on property brochure
        }
    else
       ShowPopup(pinDiscription);
}

var mapPopup;
var popupZIndex=200;
var color="default";
var defaultSimplePopupWidth = 190;
var defaultAnimatedPopupWidth = 350;
GetPopupBodyHeight=function()
{
    var e=document.getElementById("searchPopup_body").getElementsByTagName("table");
    var bh=0;
    if(e!=null&&e.length>0)
    {
	    for(var i=0;i<e.length;i++)
	    {
		    bh+=e[i].offsetHeight;
	    }
    }
    return bh;
	
}

function findPosX(obj) 
{
    var curleft = 0;
    if (obj.offsetParent) {
        while (1) {
            curleft+=obj.offsetLeft;
            if (!obj.offsetParent) {
                break;
            }
            obj=obj.offsetParent;
        }
    } else if (obj.x) {
        curleft+=obj.x;
    }
    return curleft;
}
function findPosY(obj)
{
    var curtop = 0;
    if (obj.offsetParent) {
        while (1) {
            curtop+=obj.offsetTop;
            if (!obj.offsetParent) {
                break;
            }
            obj=obj.offsetParent;
        }
    } else if (obj.y) {
        curtop+=obj.y;
    }
    return curtop;
}

function ShowPopup(body,entity)
{
    if(!mapPopup)
    {	
	    mapPopup=new VE_PanelCustom("searchPopup",5,80,190,0,color,popupZIndex,"","","");
	    var p=mapPopup;
	    p.SetFooterSize(0);
	    p.SetToolbarSize(0);		
    }
    var p=mapPopup;
    var width;
    var mapdiv = document.getElementById("myMap");
    var posX = findPosX(mapdiv);
    var posY = findPosY(mapdiv);
    var w=mapdiv.offsetWidth+posX;
    var pixel=new Object();
    var x,y;
    if(entity)
        pixel=map.LatLongToPixel(new VELatLong(entity.Latitude,entity.Longitude));
       
   else
        pixel=map.LatLongToPixel(new VELatLong(pinLat,pinLon));
             
    x = pixel.x + 8+posX;
    y = pixel.y - 11+posY;
    
    if(width==null)
    {
	    width=defaultSimplePopupWidth;
	}
    if(x>w-eval(width))
    {
        x-=eval(width)+17;
    }	
    p.SetColor(color);
    p.SetTitle("");
    p.SetBody(body);
    p.SetFooter("");
    p.SetFooterSize(20);
    p.Show();
    p.height=GetPopupBodyHeight()+p.toolbarHeight+p.footerHeight+30;
    if(p.height > 200) p.height = 200;
     
    if(y>posY+mapdiv.offsetHeight-120)
    {
        y-=p.height-20;
    }
    p.SetPosition(x,y,180,80);
    p.Resize();
    if(map.GetMapMode() == 2)
      {
         addPopupFrame3D(p);
      }
}

function ShowPopupAnimation(body)
{
    if(!mapPopup)
    {	
	    mapPopup=new VE_PanelCustom("searchPopup",5,80,195,0,color,popupZIndex,"","","");
	    var p=mapPopup;
	    p.SetFooterSize(0);
	}
    var p=mapPopup;
    var width;
    var mapdiv = document.getElementById("myMap");
    var posX = findPosX(mapdiv);
    var posY = findPosY(mapdiv);
    var w=mapdiv.offsetWidth+posX;
    pixel=map.LatLongToPixel(new VELatLong(pinLat,pinLon));
             
    var x = pixel.x + 8+posX;
    var y = pixel.y - 11+posY;
//    var x=window.event.x + 8+posX;
//    var y=window.event.y - 11+posY;
    p.SetColor(color);
    p.SetBody(body);
    p.height=GetPopupBodyHeight()+p.toolbarHeight+p.footerHeight+30;
    p.Show(); 
    if(width==null)
    {
	    width=defaultAnimatedPopupWidth;
	}
   
var w=mapdiv.offsetWidth+posX;
var h=mapdiv.offsetHeight+posY;
var imageObj = document.getElementById('imgSummPushPin'); 
if(imageObj)
{   //animation case added here 
    
    var pHeight = 250;   
    if(x>w-eval(width))
    {
	    x-=eval(width)+30;
    }
    if(y>h-eval(pHeight))
    {
	    y-=eval(pHeight)+15;
    }
}	
else
{
    //normal case
    width=190;
    VE_SearchManager.popup.width=width;
    if(x>w-eval(width))
    {
	    x-=eval(width)+17;
    }
    if(p.height > 200) p.height = 200;
    var y=pixel.y-11+posY; 
    if(y>posY+mapdiv.offsetHeight-120)
    {
	    y-=p.height-20;
    }
}
    p.SetPosition(x,y,180,80);
    p.Resize();
    // new code for animation
        document.getElementById('searchPopup').style.height='';
	    document.getElementById('searchPopup').style.width='';	
	    document.getElementById('searchPopup_body').style.width='';	
	    document.getElementById('searchPopup_body').style.height='';	
	    var imageObj = document.getElementById('imgSummPushPin');
	    // frame added for animated popup
	    addPopupFrame3DAnimation(imageObj,x,y,p.height,width);
        // end
        if(imageObj)
        {
            imageObj.setAttribute('width','7'); 			
            imageObj.setAttribute('height','5');
            //new code for animation
            document.getElementById('searchPopup_cb').style.display='none'; 
            document.getElementById('pushPopUp').style.width='';
            document.getElementById('pushPopUp').style.height=''; 
            //end
	        showAnimation();		
	    }
}

function showAnimation()
{        
    var imageObj = document.getElementById('imgSummPushPin');
    var animatedIframe = document.getElementById('myShimPopup');    
    var wi = imageObj.width;
    var ht = imageObj.height; 
    if(wi < 275)
    {       
        wi=wi+20;
        ht=ht+11;                      
        imageObj.setAttribute('width',wi);             
        imageObj.setAttribute('height',ht);
        animatedIframe.height = ht;
        animatedIframe.width = wi;             
        ti = setTimeout("showAnimation()",60);  
    }
    else
        {
            clearTimeout(ti);
            var popupDiv = document.getElementById('pushPopUp');
            imageObj.setAttribute('width','284');             
            imageObj.setAttribute('height','189');
            popupDiv.style.width='350px';
            document.getElementById('searchPopup_cb').style.display='block';
            document.getElementById('searchPopup_cb').style.marginLeft='310px';
            document.getElementById('remarksListing').style.display='block';
            var browserName = navigator.userAgent;
            if(browserName.indexOf('MSIE')!=-1)
            {
                document.getElementById('remarksListing').style.marginTop='25px';
            }
            document.getElementById('headText').style.display='block'; 
            document.getElementById('detProp').style.display='block';
            animatedIframe.width = popupDiv.offsetWidth + 20 +'px';  
            animatedIframe.height = popupDiv.offsetHeight + 25 +'px';;
        }
}

function GetEntityReference(e)
{
    var returnValues=new Array();
    if(!e)  
    {
	    e=window.event;
    }
    var t=GetTarget(e);
    if(!t)
    {
	    return;
    }
    var id=t.id;
    var a=id.indexOf('_');
    var b=id.lastIndexOf('_');
    returnValues[0]=id.substr(a+1,b-a-1);
    returnValues[1]=id.substr(b+1,id.length-b);
    return(returnValues);
}

function GetTarget(e)
{
	if(!e)var e=window.event;
	if(!e)return;
	var eventTarget;
	if(e.srcElement)eventTarget=e.srcElement;
	else if(e.target)eventTarget=e.target;
	if(!eventTarget)return;
	if(eventTarget.nodeType==3)eventTarget=targ.parentNode;
	return eventTarget;
	
}

// correctly handle PNG transparency in Win IE 5.5 or higher.
var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

function fixPNG(myImage) 
{
    if ((version >= 5.5) && (document.body.filters)) 
    {
       var imgID = (myImage.id) ? "id='" + myImage.id + "' " : ""
	   var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : ""
	   var imgTitle = (myImage.title) ? 
		             "title='" + myImage.title  + "' " : "title='" + myImage.alt + "' "
	   var imgStyle = "display:inline-block;" + myImage.style.cssText
	   var strNewHTML = "<span " + imgID + imgClass + imgTitle
                  + " style=\"" + "width:" + myImage.width 
                  + "px; height:" + myImage.height 
                  + "px;" + imgStyle + ";"
                  + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
                  + "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>"
	   myImage.outerHTML = strNewHTML	  
    }
}
// Functions For Mapview Search Results 
   var map=null; 
   var mlsNumber;
   var mlsCompanyID;
   
   function GetMapView()
     {
        map = new VEMap('myMap');
	    map.LoadMap();
	    if(navigator.userAgent.indexOf('Safari') != -1)
        document.getElementById("myMap").childNodes[0].style.cursor = "default";
	    map.HideDashboard();
        PageDisplayMapView();
     }
 
   function PageDisplayMapView()
    {
        var hiddenText = document.getElementById(g_control_prefix_mapView +'evalCodeHiddenField');
        eval(hiddenText.value);
    }
  
    function PinHoverMapView(x, y, title, details)
    { 
        var e=window.event;
        if (e!=null)
        var t=GetTarget(e);
        if(!t)
        {
            return;
        }
        if(t.src.indexOf('nearby') != -1)
        t.src = 'http://images.longandfoster.com/Images/Map-Icons/single-nearby-16-on.gif';
        else 
        t.src = 'http://images.longandfoster.com/Images/Map-Icons/single-family-16-on.gif';
                
        t.onmouseout = pinHoverOutMapView;
        getPinDetailsMapView(details);
        t.onclick = getContentForPushpinMapView;
     }
     
     function pinHoverOutMapView(e)
     {
        var t=GetTarget(e);
	    if(!t)
	    {
		    return;
		}
		if(t.src.indexOf('nearby') != -1)
        t.src = 'http://images.longandfoster.com/Images/Map-Icons/single-nearby-16.gif';
        else 
        t.src = 'http://images.longandfoster.com/Images/Map-Icons/single-family-16.gif';
     }


