﻿//Listing Details
var listingPhotoViewer = null;

function displayResidentialDetails(listing,index,source)
{
    //Images & Courtesy Message
    var courtesyMessge = "Listing Courtesy of " + listing.ListingBrokerName;
    if (listingPhotoViewer == null)
    {
        listingPhotoViewer = $create(OeS.PhotoViewer,{thumbnailWidth:110,mainImageWidth:330,cssClassValue:'photoViewer',thumbnailCssClass:'photoViewerThumbnails'},null,null,$get("listingImages"));
        
    }
    listingPhotoViewer.show(listing.Images,courtesyMessge);
    
    //List Status
    if (listing.ListStatus == 'CONTG' || listing.ListStatus == 'contg')
    {
        $get("ListStatus").innerHTML = "CONTINGENT";
    }
    else
	{
		$get("ListStatus").innerHTML = "";
	}
	
    //Set Listing Summary    
    if (listing.InternetAddress) {
	    $get("Street1").innerHTML = listing.Street1;
	    $get("CityStateZip").innerHTML = listing.City + ', ' + listing.State + ' ' + listing.ZipCode;
	}
	else {
	    $get("Street1").innerHTML = "";
	    $get("CityStateZip").innerHTML = "";
	}
	
    $get("ListPrice").innerHTML = '$' + String.format('{0:c0}',listing.ListPrice).substr(1);
    $get("MLSNumber").innerHTML = "MLS #" + listing.MLSNumber;   
    
    //Set At a Glance
    $get("Neighborhood").innerHTML = listing.Subdivision;
    $get("YearBuiltAtAGlance").innerHTML = listing.YearBuilt;
    $get("BedroomsAtAGlance").innerHTML = listing.Beds;
    $get("BathsAtAGlance").innerHTML = '<em>full/half</em>&nbsp;&nbsp;' + listing.BathsFull + '/' + listing.BathsHalf;
    $get("SqFeetAtAGlance").innerHTML = String.format('{0:c0}',listing.SqFtTotal).substr(1)
    
    //More Details:
    $get("MLSArea").innerHTML = listing.MLSArea;
    $get("TotalRooms").innerHTML = listing.RoomCount;
    $get("Bedrooms").innerHTML = listing.Beds;
    $get("FullBaths").innerHTML = listing.BathsFull;
    $get("HalfBaths").innerHTML = listing.BathsHalf;
    $get("TotalSqFt").innerHTML = String.format('{0:c0}',listing.SqFtTotal).substr(1);
    $get("UnfinishedSqFt").innerHTML = String.format('{0:c0}',listing.SqFtTotalUnheated).substr(1);
    $get("Style").innerHTML = listing.Style;
    $get("Roof").innerHTML = listing.Roof;
    $get("DiningRoom").innerHTML = listing.Dining;
    $get("FirePlace").innerHTML = listing.Fireplace;
    $get("BasementDisplay").innerHTML = listing.Basement;
    $get("WasherDryerLocation").innerHTML = listing.WasherDryer;
    $get("LotDescription").innerHTML = listing.LotDescription;
    $get("Flooring").innerHTML = listing.Floors;
    $get("YearBuilt").innerHTML = listing.YearBuilt;
    $get("AcresDisplay").innerHTML = listing.Acres;
    $get("WaterSewer").innerHTML = listing.WaterSewer;
    $get("ParkingDisplay").innerHTML = listing.Parking;
    
    //Remarks
    $get("listingRemarks").innerHTML = listing.AgentComments;
    
    
    //Rooms
    var roomDetails = $get("roomDetails");
    if (roomDetails!=null)
    {            
        var row;
        var cell;
        //Delete any previous listing rooms
        while(roomDetails.rows.length > 1)
        {
            roomDetails.deleteRow(1);
        }
        for(var i=0;i < listing.Rooms.length;i++)
        {
            row = roomDetails.insertRow(roomDetails.rows.length);
            cell = document.createElement('th');
            cell.innerHTML = listing.Rooms[i].Name;
            row.appendChild(cell);
            
            cell = row.insertCell(row.cells.length);
            cell.innerHTML = listing.Rooms[i].Dimensions;
            cell.style.textAlign='center';
            
            cell = row.insertCell(row.cells.length);
            cell.innerHTML = listing.Rooms[i].Level;
        }
    }
    
    //Schools
    $get("ElementarySchools").innerHTML = listing.ElementarySchools
    $get("MiddleSchools").innerHTML = listing.MiddleSchools;
    $get("HighSchools").innerHTML = listing.HighSchools;
    
    //Action Links
    var actionLinks = '';
    actionLinks += '<a href="#" onclick="AddToFavorites(\''+source+ '\',\''+listing.MLSNumber+'\', \'listingDialog\');return false;" title="Add this listing to your Favorites">save</a>&nbsp;';
    actionLinks += '<a href="#" onclick="requestMoreInfo('+index+',\''+source+'\');return false;">request info</a>&nbsp;';
    actionLinks += '<a href="#" onclick="printDetails(\'Residential\');return false;">print</a>&nbsp;'    
    actionLinks += '<a href="#" onclick="showResidentialDetails('+index+',\'photos\',\''+source+'\');return false;">enlarge photos</a>&nbsp;';
    if (listing.VirtualTour != "")
    {
        actionLinks += '<a href="http://'+listing.VirtualTour+'" target="_blank">tour</a>&nbsp;';
    }
	
	if (listing.InternetAddress) {
        actionLinks += '<a href="#" onclick="showResidentialDetails(' + index + ',\'map\',\'' + source + '\');return false;">map</a>';
    }
	
    $get("listingActionContainer").innerHTML = actionLinks;

}


function displayCommunityDetails(community,index)
{
    //Container
    var communityDetailContainer = $get("commmunityDetailContainer");
    if (communityDetailContainer != null)
    {
        if (community.Ranking >0)
        {
            communityDetailContainer.className = "communityDetailsFeatured";            
        }
        else
        {
            communityDetailContainer.className = "communityDetailsNormal";
        }
    }
    
    //Title
    var communityTitle = $get("communityTitle");
    if (communityTitle != null)
    {
        communityTitle.innerHTML = community.CommunityName + ", " + community.City;
        if (community.Ranking > 0)
        {
            communityTitle.className = "communityFeaturedTitle"
        } else {
            communityTitle.className = "";
        }
    }
    //Photo or Logo
    var communityPhoto = $get("communityPhoto")
    if (communityPhoto != null)
    {
        communityPhoto.style.display = "inline";
        if (community.Photos.length > 0)
        {
            communityPhoto.src = community.Photos[0] + "?size=300";   
        }
        else if(community.Logo != "")
        {
            communityPhoto.src = community.Logo;
        }
        else
        {
            communityPhoto.style.display = "none";
        }
    }
    
    //Description
    var communityDescription = $get("communityDescription");
    if (communityDescription != null)
    {
        communityDescription.innerHTML = community.FullDescription;
    }    

    
    //Footer
    var footer = $get("communityDetailFooter");
    if (footer != null)
    {       
        var summaryItem = '';
        summaryItem += '<a href="#" onclick="AddToFavorites(\'Community\',\''+community.CommunityId+'\', \'commmunityDetailContainer\');return false;" title="Add this Community to your Favorites">save</a>&nbsp;';
        summaryItem += '<a href="#" onclick="requestMoreInfo('+ index + ',\'Community\');toggleInfoBox();return false;">request info</a>&nbsp;';        
        summaryItem += '<a href="#" onclick="printDetails(\'Community\');return false;">print</a>&nbsp;'    
        if (community.Photos.length > 0)
        {
            //summaryItem += ' / ';
            summaryItem += '<a href="#" onclick="showCommunityDetails('+ index + ',\'photos\');return false;">photos</a>';
        }
        if (community.AvailableHomes > 0)
        {
            summaryItem += '&nbsp;';
            summaryItem += '<a href="#" onclick="showCommunityDetails(' + index + ',\'homes\');return false;">'+ community.AvailableHomes + ' available homes</a>';
        }
        if (community.Latitude != 0 && community.Longitude != 0)
        {
            summaryItem += '&nbsp;';
            summaryItem += '<a href="#" onclick="showCommunityDetails('+ index + ',\'map\');return false;">map</a>';
        }
        
        footer.innerHTML = summaryItem;
    }
    
    //Website Link
    var communityWebsite = $get("communityWebsite");
    if (community.Ranking >= 4 && community.Website != '')
    {        
        if (communityWebsite != null)
        {
            communityWebsite.innerHTML = '<a href="http://'+community.Website+'" target="_blank" onclick="TrackPageView(BuildNeighborhoodPageViewByIndex('+index+',\'click_through\'))">'+community.Website+'</a>';
        }
    } else {
        if (communityWebsite != null)
        {
            communityWebsite.innerHTML = "";
        }
    }
    
    
   
   
    
}


// Notify ScriptManager that this is the end of the script.
if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();