﻿


function CreateApRentIcon(  zoom )
{
    if(zoom>16) zoom=16;
    var p_icon = new GIcon();
    p_icon.image = icon_url;
    var size = 26.0*(zoom/16.0)*(zoom/16.0);
    p_icon.iconSize = new GSize(size, size);
    p_icon.iconAnchor = new GPoint(size/2, size/2 );
    p_icon.infoWindowAnchor = new GPoint(size/2, size/2);
    
    p_icon  = G_DEFAULT_ICON;
    return p_icon;
}


var swapper = null;

function SetPhoto(n,fname)
{
    if(fname==null) 
	{
		fname="~/images/mls/place_large.gif";
		
	}
	

    var anchor = document.getElementById("a_ph"+n);
    var imag = document.getElementById("i_ph"+n);
    
    var hwidth = 250;
    var lwidth = 120;
    var hheight = 180;
    var lheight = 80;
    
    var high = siteroot+"image.ashx?type=3&width="+hwidth+"&height="+hheight+"&path="+fname;
    var low =  siteroot+"image.ashx?type=3&width="+lwidth+"&height="+lheight+"&path="+fname;
    var srcres = low;
    if(n==1) 
    {
        srcres = high;
        //
        if( swapper == null)
        {
            swapper = new ImageSwapper( imag.id , low, high );       
        }
        //
    }else 
    {
        if( swapper.DataById (imag.id) == null)
        {
             swapper.AddControl( imag.id , low, high );       
        }
    }
    
    imag.src = srcres;
    anchor.href = "#"; 
    //anchor.href = "image.ashx?path="+fname;
    //anchor.target = "_blank";
}

var ApRentData = new Array();
var ARMapData = new Array();

function LocateOnMap(uid)
{
    var info = ApRentData[uid];
    var mapinfo = ARMapData[uid];
    var Lat=info.getAttribute("Lan");
    var Long=info.getAttribute("Long");
    if(parseInt(Lat)==0) 
    {
        alert("We are sorry, but we don't have this property on map.");
    }else
    {
        map.setCenter(new GLatLng(Lat,Long));
       
        showInfoBalloon( mapinfo.point,mapinfo.title ,mapinfo.text );
    }
}

function FeatureSheet(uid)
{
    swapper = null;
    var info = ApRentData[uid];
    var photo1=info.getAttribute("photo1");
     var photo1id=info.getAttribute("photo1id");
    var photo2=info.getAttribute("photo2");
    var photo3=info.getAttribute("photo3");
    var photo4=info.getAttribute("photo4");
    var photo5=info.getAttribute("photo5");
    var address = info.getAttribute("Address1")+" "+info.getAttribute("Address2");
    var postal = info.getAttribute("Postal");
    var price = info.getAttribute("Price");
    var phone = info.getAttribute("Phone");
    var bedrooms = info.getAttribute("Bedrooms");
    var bathrooms = info.getAttribute("Bathrooms");
    var desription = info.getAttribute("Description");
    var city = info.getAttribute("City");
    
    var uid =  info.getAttribute("uid");
    
    document.getElementById(hnd_mailme).value = uid;
 
    document.getElementById('address').innerHTML = address;
    document.getElementById('postal').innerHTML = postal;
    document.getElementById('price').innerHTML = price;
    document.getElementById('city').innerHTML = city;
    document.getElementById('bedrooms').innerHTML =bedrooms;
    document.getElementById('bathrooms').innerHTML = bathrooms;
    
    if(displaybeds == 0 ) document.getElementById('bedsrow').style.display = "none";
        else document.getElementById('bedsrow').style.display = "";
    
    document.getElementById('ap_description').innerHTML = desription;
    // photos //
    if( photo1id != 0) 
    {
    document.getElementById("photos").style.display = "";
    SetPhoto(1,photo1);
    SetPhoto(2,photo2);
    SetPhoto(3,photo3);
    SetPhoto(4,photo4);
    SetPhoto(5,photo5);
    }else
    {
        document.getElementById("photos").style.display = "none";
    }
    
   var infodiv = document.getElementById('infodiv'); 

   
   document.getElementById('infodiv').style.display = "block";
   
   // document.getElementById('mapdiv').visibility = "hidden";
}

function CloseSheet()
{
   document.getElementById('infodiv').style.display = "none";
 
}

function ShowApRentItems()
{

    var aParams ="";//"?keyword="+keyword;
    map.clearOverlays();

    if(mgr!=null) 
    {
       for(a in mgr) // This is HARD way to delete object //
        {
            mgr[a] = function() {};
        }
        delete mgr;
    }
    mgr = new GMarkerManager(map);  

    var icon = new GIcon();
    if(icon_url!="")
    {
    icon.image = icon_url;
    icon.iconSize = new GSize(26, 26);
    icon.iconAnchor = new GPoint(13, 13);
    icon.infoWindowAnchor = new GPoint(12, 12);
    }else icon = G_DEFAULT_ICON;
    
    GDownloadUrl(items_url+aParams, function(data, responseCode) 
            {
                var bounds = new GLatLngBounds();
                bounds.extend( map.getCenter());
                var xml = GXml.parse(data);
                var markers = xml.documentElement.getElementsByTagName("item");
                  for (var i = 0; i < markers.length; i++) 
                                {
                                    var point = new GLatLng(parseFloat(markers[i].getAttribute("Lan")),
                                                 parseFloat(markers[i].getAttribute("Long")));
                                    bounds.extend(point);
                                    var logo = "";
                                    var logo_img = house_url;
                                    if(markers[i].getAttribute("photo1id")!=0) logo_img = "image.ashx?path="+markers[i].getAttribute("photo1");
                                    
                                    
                                    logo = "<img style='float:left;margin:6px;width:72px;height:72px;border:solid 1px #425095;' src='"+logo_img+"' />";
                                    
                                    var text ="<div style='width:220px;height:80px;font-weight:normal;font-size:14px;'>"+ logo +"<div style='border:solid 1px #425095;margin:5px;float:left;background:#ebedf4;font-size:10px;padding:3px;'>";
                                    if(displaybeds != 0) text+="<b>Beds: </b>"+ markers[i].getAttribute("Bedrooms")+"<br /><b>  Baths: </b>"+ markers[i].getAttribute("Bathrooms")+"<br/>";
                                    text+="<b>"+pricelabel+"</b>:&nbsp;$&nbsp;"+ parseInt( markers[i].getAttribute("Price") )+"</div></div>";
                                    
                                    
                                    var addr = markers[i].getAttribute("Address1")+" "+ markers[i].getAttribute("Address2");
                                    var title = String( addr ).length >25 ? String(addr).substr(0,25)+"...":addr;
                                    
                                    var js = 'FeatureSheet('+markers[i].getAttribute("uid")+');';
                                    text+="<div style='padding-left:100px;'>"+"<a href='#' onclick='"+js+"'>"+"<img border=0 src='images/public/featuresheet.png' />"+"</a></div>"
                                    
                                    ApRentData[parseInt(markers[i].getAttribute("uid"))]=markers[i];
                                    ARMapData[parseInt(markers[i].getAttribute("uid"))] =  { point: point, title:title, text: text};
                                     map.addOverlay(createMarkerBalloon(point,title,text,CreateApRentIcon(12)));
                                    //for(z=11;z<=17;z++)
                                    //{
                                       
                                        //mgr.addMarker( createMarkerBalloon(point,title,text,CreateApRentIcon(z)), z , z );
                                    //}
                                    

                                  }
                                
                                
                                mgr.refresh();

          });
   
}

function OpenMailmeApRent()
{
    var cnt = document.getElementById('EmailMeApRent');
    if( cnt.style.visibility == 'hidden')
    {
        cnt.style.visibility = 'visible';
    }else
    {
        cnt.style.visibility ='hidden';
    }
}

function CloseEmailMe(uid)
{
   

   var cnt = document.getElementById('EmailMe'+uid);
   if( cnt == null ) cnt= document.getElementById('EmailMeApRent');
        cnt.style.visibility ='hidden';
   var childNodes = cnt.getElementsByTagName("span");
   for(var i=0;i<childNodes.length;i++ )
   {
        var child = childNodes[i];
        if( child.style.visibility == 'visible' )
        {
            child.style.visibility = '';
        }
   }
}