﻿var oVECompsMap = null;
var oVECompsMap_PropCompsLayer = null;
var oPanel = null;
var oIPanel = null;
var Source = null;
var Site = null;
var iSysID = 0;
var Address = null;
var PostalCode = null;
var oDrivingDir = null;
var isPrinting = false;
var PropMapData = null;
var oOutput = null;
var N = 0;
var Start = 0;
var CurrentPage = 0;

function Initialize() {
    GoogleAnalytics()
    // If we aren't in a prop search situation replace the "Back to Map" with a Return button
    if (parent.CurrentTab) {
        $get("btnBack").src = $get("btnBack").src.replace("Return", "ReturnToMap");
        if ($get("butSave2ShoppingCart")) $get("butSave2ShoppingCart").style.display = "block";
    }
    isPrinting = (0 < $get("hPrinting").value.length);
    Source = $get("hSiteCode").value;
    Site = $get("hSiteCode").value;
    iSysID = parseInt($get("hSysID").value, 10);
    oDrivingDir = new DrivingDir();
    DataClear();
    Resize();
    Compute();
    setTimeout("ShowZoomedInPropMap()", 500);
    if (!isPrinting) GetAuxPhotos();
		    
    // No suggested props for MIBOR or Agent Search Links
    if ((Site!="INR") && (parent.PropListData)) GetSuggestedProps();
    if ((Site=="INR") && (!isPrinting)) 
    {
			$get('chkContactAnAgent').checked=true;
    	ToggleView('chkContactAnAgent', 'divContactAnAgent'); // Agent Info Open by default
    }
     
    if ($get("CMA"))
    {         
			if (Site == 'DFW') $get("CMA").style.display = "none";
			if (Site == 'INR') $get("CMA").style.display = "none";
		}
		
    // If this is a print window, do some reformatting
    if (isPrinting) {
        
        ToggleView('chkLoanCalc', 'divLoanCalc'); // Calculator on;
        ToggleView('chkContactAnAgent', 'divContactAnAgent'); // Agent Info
        $get("tblContactForm").style.display = "none";
        $get("Send2Friend").style.display = "none";
        $get("tblContactAnAgent").style.display = "none";
				
        var oWin = window.opener;
        if (oWin) {	
            
            if (oWin.document.getElementById("bShowDir").checked) {
                $get("tblDrivingDirections").style.display = "none";
                $get("divDirections").innerText = oWin.document.getElementById("divDirections").innerText;
            } else {
                $get("DrivingDirections").style.display = "none";
            }

            if (oWin.document.getElementById("chkLoanCalc").checked) {
                $get("tblLoanCalc").style.display = "none";
            } else {
                $get("LoanCalc").style.display = "none";
            }

        } else {
            $get("DrivingDirections").style.display = "none";
            $get("LoanCalc").style.display = "none";
        }
        if ($get("hSiteCode").value == 'INR') {
					//Setup print flyer
	        //Copy existing tables into the print flyer tables in the arranged order
					var feattable = document.getElementById("tblFeatureList1");
					document.getElementById("printFeatureList1").appendChild(feattable);
			    
					var printheader = $get("hPrintHeader").value;
					
					var headertable = document.getElementById("PropDetailHdr");
					document.getElementById("printHeader").appendChild(headertable);
			    
					var detailstable1 = document.getElementById("tblFeatureList1");
					document.getElementById("printFeatureList1").appendChild(detailstable1);
			    
					var detailstable2 = document.getElementById("tblFeatureList2");
					document.getElementById("printFeatureList2").appendChild(detailstable2);
					
					var detailstable3 = document.getElementById("tblFeatureList3");
					document.getElementById("printFeatureList3").appendChild(detailstable3);
					
					var detailstable4 = document.getElementById("tblFeatureList4");
					document.getElementById("printFeatureList4").appendChild(detailstable4);
					
					var remarkstable = document.getElementById("agentRemarks");
					document.getElementById("printAgentRemarks").appendChild(remarkstable);
			    
					var agentstable = document.getElementById("agentInformation");
					document.getElementById("printAgentContact").appendChild(agentstable);
			    
					var copyrighttable = document.getElementById("copyright");
					document.getElementById("printCopyrightInfo").appendChild(copyrighttable);
			    
					$get("propPhoto").src = $get("hPrimaryPhotoURL").value;
					
					//Turn off the display of the normal page elements
					//$get("propPhotos").style.display = "none";
					$get("TestTable").style.display = "none";
					$get("AgentComments").style.display = "none";
					$get("PropertyFeatures").style.display = "none";
					$get("divPropCompsMap").style.display = "none";
					$get("divPropCompsMapSpacer").height = "0";
					$get("DrivingDirections").style.display = "none";
					$get("ContactAnAgent").style.display = "none";
					$get("Send2Friend").style.display = "none";
					$get("LoanCalc").style.display = "none";
					$get("divPropSuggest").style.display = "none";
					$get("copyright").style.display = "none";
					//$get("MIBORHdr").style.display = "none"; - hiding this makes it not print
					$get("divPrintReport").style.display = "block";
        }
        if ($get("hSiteCode").value == 'MFR') {
            if (oWin.document.getElementById("chkPropComps").checked) {
                $get("tblAVM").style.display = "none";
                $get("divPropComps").style.display = "block";
                divPropCompsTable.innerHTML = oWin.document.getElementById("divPropCompsTable").innerHTML;
            } else {
                $get("CMA").style.display = "none";
            }
        }
       Print2();
    } else setTimeout("SlideShow()",3000); // slideshow unless we are printing
    
    //Get data and length for the prev-next buttons
    PropMapData = parent.PropListData;
    
    var ddlPg = $get("PageNum")
    var NPages=0;
    if (!PropMapData) ddlPg = null;
    else  NPages = PropMapData.length 
    
    if (ddlPg) {
        while (ddlPg.options.length) ddlPg.remove(0);
        for (var i = 1; i <= NPages; i++) {
            ddlPg.options.add(new Option(i,i));
        }
        if (ddlPg.options.length > 0) {
            ddlPg.options[Math.min(ddlPg.options.length, Math.max(0, CurrentPage))].selected = true;
        } else { CurrentPage = 0; }
        if (parent.SelectedProp) $get("ckSelect").checked=parent.SelectedProp[CurrentPage];
    }
    
    //Find property on mini-map
    if ((Site == "HHI") || (Site == "INR")){
    var Lat = parseFloat($get("hLatitude").value);
    var Lon = parseFloat($get("hLongitude").value);
    var Title = $get("hAddress").value;
    if (parent.FindOnMapSearch) {
        parent.FindOnMapSearch(Lat, Lon, Title); // HHI & MIBOR Style
    }
    }
    
    window.onresize = Resize;
}

var SlideNum = 0;
var isSlideShowRunning = true;

function SlideShow() {
    if (isSlideShowRunning) {
        // change Image
        var oImg = $get("Photo" + SlideNum);
        if (!oImg) oImg = $get("PhotoXH" + SlideNum);
        if (!oImg) oImg = $get("PhotoXV" + SlideNum);
        
        if ((!oImg) || (0 < oImg.src.indexOf("NoPhoto"))) 
        {
            SlideNum = 0;
				} else {
					SwitchPhoto ($get("PhotoX"),oImg);
					SlideNum++;
				}
    }
    setTimeout("SlideShow()", 5000);
}

function SwitchPhoto (oPhoto, oImg)
{
    if (!oPhoto) return;
    var NumFilters = 4
		var id = Math.floor(NumFilters * Math.random());
		var canFilter = oPhoto.filters && oPhoto.filters(id)
		if (canFilter) oPhoto.filters(id).Apply();
		oPhoto.src = oImg.src;
		if (canFilter) oPhoto.filters(id).Play();
}


function DataClear() {
    CurrentPage = parseInt($get("hN").value);
}

function Next(Dir) {
    CurrentPage = Math.min(Math.max(0, CurrentPage+Dir), PropMapData.length-1);
    var Prop = new PropInfo(PropMapData, CurrentPage); //PropMapData has a zero-based index
    var SysID = Prop.SysID;
    Source = Prop.Source;
    ShowPropDetail(CurrentPage, Source, SysID);
    if ((Site == "HHI") || (Site == "INR")) {  //Find property on mini-map (redundant??)
       var Lat = parseFloat($get("hLatitude").value);
       if (parent.FindOnMapSearch) parent.FindOnMapSearch(Prop.Lat, Prop.Lon, Prop.Address); // HHI & MIBOR Style
    }
}

function Move(pg) {
    if (pg < 0) return;
    CurrentPage = pg;
    setTimeout("Next(0)", 1000);
}

function Resize() {
    // If the user resizes the window this will resize all the layers

    var Height = Math.max(200, GetScreenHeight());
    var Width = Math.max(200, GetScreenWidth());
    var Edge = Math.max(300, Width - 35);

    oPanel = $get("divDetailsPanel");
    if (oPanel) {

        switch (Site) {
     
            //Style B (HHI) Sites have a smaller height value 
            case "HHI":
            case "INR":
                oPanel.style.width = (Width) + "px";
                oPanel.style.height = (Height - 20) + "px";
                break;
                
            default: // Default Style
                oPanel.style.height = (Height - 35) + "px";
				oPanel.style.width = Width + "px";
				break;
        }
    }


		// Resize Aux Photo Display so their are 6 per line on the bottom and 6 per column on the right
    var oPhoto = $get("PhotoX");
		if (oPhoto){
			var H1 = Height-75;
			var W1 = Math.min(Width-25, 520);
			
 			oPhoto.height = Math.round(Math.min(H1, W1 / 1.3));
			oPhoto.width = Math.round(Math.min(W1, H1 * 1.3));
			var tnW = Math.max(10,Math.round(oPhoto.width / 6.0)-4);
      var tnH = Math.max(10,Math.round(oPhoto.height / 6.0)-4);
      for (var i=0; i<20; i++)
      {
				var oTNv = $get("PhotoXV" + i);
				var oTNh = $get("PhotoXH" + i);
				if (oTNv) { oTNv.style.height = tnH + "px" ; oTNv.style.width=tnW + "px" ;}
				if (oTNh) { oTNh.style.width = tnW + "px" ;	oTNh.style.height=tnH + "px" ;}			
			}
			FitPhotoX(Width-25,oPhoto.width, tnW);
		}

    //$get("divBackground").style.width = Edge+"px";
    $get("divPropCompsMap").style.width = Edge + "px";
    $get("divIDXCourtesy").style.width = Edge + "px";
    var NumPhotos = parseInt($get("NumPhotos").value,10);


    // Narrow screen, make single column
    if (Edge < 600) {
        var oOverflow = $get("tdOverflow");
        var oFeatureList2 = $get("tblFeatureList2");
        var oFeatureList3 = $get("tblFeatureList3");
        var oFeatureList4 = $get("tblFeatureList4");
        if (oOverflow && oFeatureList2) {
            oOverflow.innerHTML = oFeatureList2.outerHTML + oFeatureList3.outerHTML + oFeatureList4.outerHTML;
            oFeatureList2.outerHTML = "";
            oFeatureList3.outerHTML = "";
            oFeatureList4.outerHTML = "";
            $get("tdDivider").style.display = "none";
        } // else already a narrow screen
    }
}

function FitPhotoX(ScreenWidth,MainPhotoWidth,ThumbnailWidth)
{
	// Arrange thubnails to maximize usage of horizontal space
	
	// 1) if room for first columns of photos on the right, then delete them from the bottom
	// else remove all photos from the right.
	if (ScreenWidth > MainPhotoWidth + ThumbnailWidth + 3)
	{
		for (var i=0; i<6; i++)	HidePhotoX("H",i);
	} else {
		for (var i=0; i<18; i++) HidePhotoX("V",i);
		return;
	}
			
	// 2) if room for second  columns of photos on the right, then delete them from the bottom
	// else remove second & third column from the right.
	if (ScreenWidth > MainPhotoWidth + 2 * (ThumbnailWidth + 3))
	{
		for (var i=6; i<12; i++)	HidePhotoX("H",i);
	} else {
		for (var i=6; i<18; i++) HidePhotoX("V",i);
		return;
	}
	
	// 3) If room for third colum of photos on rihjt, then delete same photos from the bottom
	// else remove third photo row from right	
	if (ScreenWidth > MainPhotoWidth + 3 * (ThumbnailWidth + 3))
	{
		for (var i=12; i<18; i++)	HidePhotoX("H",i);
	} else {
		for (var i=12; i<18; i++) HidePhotoX("V",i);
		return;
	}
}

function HidePhotoX(Type,N)
{
	var oPhoto = $get("PhotoX" + Type + N)
	if (!oPhoto) return;
	oPhoto.style.display="none";
}

function ShowPhoto(evt) {
    var oIng = null;
    var eType = null;

    if (window.event) {
        oImg = window.event.srcElement;
        eType = window.event.type;
    } else {
        oImg = evt.target;
        eType = evt.type;
    }

    switch (eType) {
        case "mouseover":
        case "click":
            var oPhoto = $get("Photo"); if (oPhoto) oPhoto.src = oImg.src;
            var oPhoto = $get("PhotoX"); if (oPhoto) oPhoto.src = oImg.src;
            SlideNum = parseInt(oImg.id.substr(5));
            isSlideShowRunning = false;
            break;
        case "mouseout":
            isSlideShowRunning = true;
            break;
        default:
    }
}

function ShowZoomedInPropMap() {

    var Title = "Subject Property";

    var Lat = parseFloat($get("hLatitude").value); //if (isNaN(Lat)) Lat=40;
    var Lon = parseFloat($get("hLongitude").value); //if (isNaN(Lon)) Lon=-80;
    var oDrivDir = $get("DrivingDirections");
    // If we don't have coordinates don't show the map
    if ((isNaN(Lat)) || (isNaN(Lon))) {
        $get("divPropCompsMap").style.display = "none";
        $get("divPropCompsMapSpacer").style.display="none";
        if (oDrivingDir) { $get("DrivingDirections").style.display = "none"; }
        return;
    }

    var Point = new VELatLong(Lat, Lon);

    if (!oVECompsMap) {
        oVECompsMap = new VEMap('divPropCompsMap');
        oVECompsMap.LoadMap(Point, 17, "s", false, 1, true);
        //oVECompsMap_ParcelLayerSpec = new VETileSourceSpecification("ParcelLayer", "../ParcelTile.aspx?style=%1&tilenum=%4");
        //oVECompsMap_ParcelLayerSpec.MaxZoomLevel = 19; // Closest to the earth you can get with GPL WMS "turned on"
        //oVECompsMap_ParcelLayerSpec.MinZoomLevel = 17; // Farthest away from the earth you can go before GPL WMS will "turn off"
        //if (parent.ShowParcels)oVECompsMap.AddTileLayer(oVECompsMap_ParcelLayerSpec, true);
        pOptions = new VEPrintOptions(true);
        oVECompsMap.SetPrintOptions(pOptions);
    }

    //Format map to the proper style
    switch (Site) {
        case "MFR":
            if (oVECompsMap.Style == VEMapStyle.Shaded) return; // Map already reset;

            if (oVECompsMap) {
                oVECompsMap.SetCenterAndZoom(Point, 17);
                oVECompsMap.SetMapStyle(VEMapStyle.Shaded);
            }
            break;
        case "HHI":
        case "INR":
            if (oVECompsMap.Style == VEMapStyle.Hybrid) return; // Map already reset;
            oVECompsMap.SetCenterAndZoom(Point, 17);
            oVECompsMap.SetMapStyle(VEMapStyle.Hybrid);

            break;
        default:
    }

    if (oVECompsMap_PropCompsLayer) oVECompsMap_PropCompsLayer.DeleteAllShapes();
    if (!oVECompsMap_PropCompsLayer) {
        oVECompsMap_PropCompsLayer = new VEShapeLayer();
        oVECompsMap.AddShapeLayer(oVECompsMap_PropCompsLayer);
    }

    var PushPin = new VEShape(VEShapeType.Pushpin, Point)
    PushPin.SetCustomIcon("<img src='../Icons/Pin_Big_Red.gif' />");
    PushPin.SetTitle("<div><B>" + Title + "</B></div>");
    if ($get("Photo")) PushPin.SetDescription("<div><img src='" + $get("Photo").src + "' alt='Click icon for more property info' width='100'></div>")
    oVECompsMap_PropCompsLayer.AddShape(PushPin);

    // add parcel boundaries
    if ("Y" == $get("hShowParcels").value) {
        var Addr = $get("hAddress").value
        var Zip = $get("hZipcode").value
        MyAjaxService.GetParcelInfo(Lat, Lon, Addr, Zip, GetParcelCallBack, FailedCallback);
    }

}

// Display parcel boundaries
function GetParcelCallBack(e) {
    //alert("Show shape:" + e.isValid)
    if (!e.isValid) {
        if (parent.DisplayStatus) parent.DisplayStatus("No Parcel Boundaries");
        return;
    }
    var veLatLon = [];

    var Geometry = e.Geometry.replace("MULTIPOLYGON", "")
    Geometry = Geometry.replace(/\)/g, "");
    Geometry = Geometry.replace(/\(/g, "");
    Geometry = Geometry.split(",");

    for (var i = 0; i < Geometry.length; i++) {
        var point = Geometry[i].split(" ");
        if (point.length > 1) {
            var Lat = parseFloat(point[1]);
            var Lon = parseFloat(point[0]);
            if ((!isNaN(Lat)) && (!isNaN(Lon))) veLatLon.push(new VELatLong(Lat, Lon));
        }
    }

    if (veLatLon.length > 0) {
        shape = new VEShape(VEShapeType.Polygon, veLatLon);
        shape.SetLineWidth(2);
        shape.SetLineColor(new VEColor(255, 0, 0, .8));
        shape.SetFillColor(new VEColor(255, 0, 0, .15));
        shape.HideIcon();
        oVECompsMap_PropCompsLayer.AddShape(shape);
    }
    oVECompsMap.SetZoomLevel(19);
    oVECompsMap.SetMapStyle(VEMapStyle.Hybrid);

}


function UpdateNotesCallBack(Msg) {
    $get("tdFavoriteMsg").innerText = Msg;

}

function UpdateNotes() {
    var VisitorID = $get("hEncryptedVisitorID").value
    var NewText = $get("txtNotes").value;
    var SysPropertyID = $get("hSysID").value
    var Source = $get("hSiteCode").value
    MyAjaxService.UpdateNotes(VisitorID, Source, SysPropertyID, NewText, UpdateNotesCallBack, FailedCallback)
}

function ToggleView(ImgID, DivID) {
    var oImg = $get(ImgID);
    if ("_Up.gif" == oImg.src.substr(oImg.src.length - 7)) {
        $get(DivID).style.display = "none";
        oImg.src = oImg.src.substr(0, oImg.src.length - 7) + "_Dn.gif";
        if (DivID == "divPropComps") ShowZoomedInPropMap();
        return;
    }
    $get(DivID).style.display = "block";
    oImg.src = oImg.src.substr(0, oImg.src.length - 7) + "_Up.gif";
    var VisitorID = $get("hEncryptedVisitorID").value;
    var Lat = parseFloat($get("hLatitude").value); if (isNaN(Lat)) Lat = 40;
    var Lon = parseFloat($get("hLongitude").value); if (isNaN(Lon)) Lon = -80;

    switch (DivID) {
        case "divCommunity":
            GeoNamesService.FindNearbyWikipedia(Lat, Lon, WikiCallBack, FailedCallback)
            GeoNamesService.FindNearbyWeather(Lat, Lon, WeatherCallBack, FailedCallback)
            break;

        case "divPropComps":

            var PropType = $get("hPropTypeCode").value;
            var Beds = parseInt($get("hBeds").value, 10); if (isNaN(Beds)) Beds = 0;
            var BathsF = parseInt($get("hBathsF").value, 10); if (isNaN(BathsF)) BathsF = 0;
            var BathsP = parseInt($get("hBathsP").value, 10); if (isNaN(BathsP)) BathsP = 0;
            var Lot = parseFloat($get("hLotSize").value); if (isNaN(Lot)) Lot = 0;
            var SqFt = parseInt($get("hSqFt").value, 10); if (isNaN(SqFt)) SqFt = 0;
            var MLNum = $get("MLNumber").innerText;
            var LPrice = parseInt($get("hListPrice").value, 10); if (isNaN(LPrice)) LPrice = 0;
            var HOAFeeMo = parseInt($get("hHOAFee").value, 10); if (isNaN(HOAFeeMo)) HOAFeeMo = 0;
            var TaxesMo = parseInt($get("hTaxes").value, 10); if (isNaN(TaxesMo)) TaxesMo = 0;
            var AssessedValue = parseInt($get("hAssessed").value, 10); if (isNaN(AssessedValue)) AssessedValue = 0;
            var DOM = parseInt($get("hDOM").value, 10); if (isNaN(DOM)) DOM = 0;

            var YrBuilt = parseInt($get("hYrBuilt").value, 10); if (isNaN(YrBuilt)) YrBuilt = 0;
            var GarageSpaces = parseInt($get("hGarageSpaces").value, 10); if (isNaN(GarageSpaces)) GarageSpaces = 0;
            var Neighborhood = $get("hNeighborhood").value;
            var ZipCode = $get("hZipcode").value;
            var City = $get("hCity").value;
            var County = $get("hCounty").value;
            var PoolType = $get("hPoolType").value;

            $get("divPropCompsTable").innerText = "Loading...Please wait."

            var NumComps = Math.round(GetScreenWidth() / 155) - 1
            NumComps = 12;
            var CompPropStatus = "S"
            MyAjaxService.GetCompGrid(NumComps, CompPropStatus,
				MLNum, Lat, Lon, PropType, Neighborhood, ZipCode, City, County, Beds, BathsF, BathsP, SqFt,
				Math.round(Lot * 100.0), YrBuilt, LPrice, HOAFeeMo, TaxesMo, AssessedValue, GarageSpaces, PoolType, DOM,
				this.CompsCallBack, FailedCallback);

            break;


        case "divLoanCalc": Compute(); break;

        case "divContactAnAgent": break;
        case "divSend2Friend": break; // nothing to do.

        default: alert("Missing ToggleView handler: " + DivID); break;
    }
}

function CompsCallBack(CompProp) {

    var N = CompProp.N;
    var Tbl = new Sys.StringBuilder("<table width='100%' cellspacing='0' cellpadding='2' border='1' id='CompGrid'>");

    Tbl.append("<tr><td valign='bottom'><b><i>Market<br>Comparison</i></b></td>");
    Tbl.append("<td><img src='" + $get("PhotoX").src + "' width='100'/></td>");

    for (i = 1; i < N; i++) {
        var URL = "http://" + CompProp.PhotoPaths[i];
        if (!CompProp.PhotoPaths[i]) URL = "../Icons/NoPhoto_147.jpg"
        Tbl.append("<td><img src='" + URL + "' width='100'/></td>");
    }
    Tbl.append("</tr>");

    Tbl.append("<tr><td valign='bottom'>Property</td><td align='center' class='SubjHighlight'>Subject</td>");
    for (i = 1; i < N; i++) Tbl.append("<td align='center'>" + i + "</td>");
    Tbl.append("</tr>");

    var City = "" + CompProp.City;
    Tbl.append(AddRow(N, "Rank", CompProp.Rank));
    Tbl.append(AddRow(N, "MLNumber", CompProp.MLNumber));
    Tbl.append(AddRow(N, "City", City.substr(0, Math.min(20, City.length))));
    Tbl.append(AddRow(N, "Bedrooms", CompProp.Bedrooms));
    Tbl.append(AddRow(N, "Full Baths", CompProp.BathsFull));
    Tbl.append(AddRow(N, "Partial Baths", CompProp.BathsPartial));
    Tbl.append(AddRow(N, "Size (SqFt)", CompProp.SqFt));
    Tbl.append(AddRow(N, "Garage", CompProp.GarageSpaces));
    Tbl.append(AddRow(N, "Acres", CompProp.LotAcres));
    Tbl.append(AddRow(N, "Year Built", CompProp.YrBuilt));
    Tbl.append(AddRow(N, "HOA", CompProp.HOAFeeMo));
    Tbl.append(AddRow(N, "Taxes", CompProp.TaxesAnn));
    Tbl.append(AddRow(N, "Tax Value", CompProp.AssessedValue));
    Tbl.append(AddRow(N, "Price", CompProp.Price));
    if ($get("hSiteCode").value == "LAS") Tbl.append(AddRow(N, "Price/SqFt", CompProp.PriceSqFt));
    Tbl.append(AddRow(N, "Date Sold", CompProp.ClosedDate));
    Tbl.append("<tr><td valign='bottom'>Include?</td>");
    for (i = 0; i < N; i++) {
        Tbl.append("<td align='center' ");
        if (0 == i) Tbl.append("class='SubjHighlight' ");
        Tbl.append("><input type='checkbox' checked='checked' id='Incl" + i + "' ");
        Tbl.append("AssessedValue='" + CompProp.iAssessedValue + "' ");
        Tbl.append("Price='" + CompProp.iPrice[i] + "' ");
        Tbl.append("SqFt='" + CompProp.iSqFt[i] + "' ");
        Tbl.append("DOM='" + CompProp.DOM[i] + "' onclick='fnRecalc()' ");

        if (i == 0) Tbl.append("disabled=1");
        Tbl.append("></td>");
    }
    Tbl.append("</tr>");
    Tbl.append("<tr><td valign='top' class='SubjHighlight'><b>Price<br>Analysis</b></td>")
    Tbl.append("<td valign='top'>based on <span id='NumComps'>?</span> selected properties</td>");
    Tbl.append("<td colspan='" + N + "' id='EstSP'></td></tr>");
    Tbl.append("</table>");

    $get("divPropCompsTable").innerHTML = Tbl.toString();
    fnRecalc();

    for (var i = 1; i < N; i++) {
        var Point = new VELatLong(CompProp.Latitude[i], CompProp.Longitude[i]);
        var PushPin = new VEShape(VEShapeType.Pushpin, Point);
        PushPin.SetTitle("Comp #" + i);
        PushPin.SetCustomIcon("<img src='../Icons/Pin_blue.gif' />");
        var PhotoURL = "http://" + CompProp.PhotoPaths[i];
        if (!CompProp.PhotoPaths[i]) PhotoURL = "../Icons/NoPhoto_147.jpg"
        PushPin.SetDescription("<div><img src='" + PhotoURL + "' alt='Click icon for more property info' width='100'></div>")
        oVECompsMap_PropCompsLayer.AddShape(PushPin);
    }

    // Adjust the map view so all property is visible
    rect = oVECompsMap_PropCompsLayer.GetBoundingRectangle();
    oVECompsMap.SetMapView(rect);
    oVECompsMap.SetMapStyle(VEMapStyle.Shaded);
    oVECompsMap.ZoomOut();
}

function fnRecalc() {
    var Price = 0;
    var nPrice = 0;
    var n = 0;
    var Answ = "";
    var DOM = 0;
    var nDOM = 0;
    var SubjSqFt = GetAttr($get("Incl0"), "SqFt");
    var SubjAssessedValue = GetAttr($get("Incl0"), "AssessedValue");
    //var PriceLow = 100000000;
    //var PriceHigh = 0;
    var n = 0;
    var PriceSum = 0;
    var Prices = new Array();
    var PricePerSqFtSum = 0;
    var nPricePerSqFt = 0;
    var PricePerAssSum = 0;
    var nPricePerAssess = 0;

    for (i = 1; i < 50; i++) {
        var oCtrl = $get("Incl" + i);
        if (oCtrl && oCtrl.checked) {
            var a_val = GetAttr(oCtrl, "AssessedValue");
            var p_val = GetAttr(oCtrl, "Price");
            var s_val = GetAttr(oCtrl, "SqFt");
            if (p_val > 100) {
                Prices.push(p_val);
                PriceSum += p_val;
                n++;
            }
            if ((s_val > 0) && (SubjSqFt > 0)) {
                PricePerSqFtSum += p_val / s_val;
                nPricePerSqFt++;
            }

            if ((a_val > 0) && (SubjAssessedValue > 0)) {
                PricesPerAssSum += p_val / a_val;
                nPricePerAssess++;
            }
        }
    }
    Prices = Prices.sort(numOrdA);

    Answ = "<table>"
    if (n > 0) {
        Answ += "<tr><td align=right>Price Range:</td><td>$" + Math.round(Prices[0] / 1000) + "K</td><td align='center'>&nbsp;to&nbsp;</td><td>$" + Math.round(Prices[Prices.length - 1] / 1000) + "K</td></tr>";
        Answ += "<tr><td align=right>Average Price:</td><td>$" + Math.round(.001 * PriceSum / n) + "K</td><td>&nbsp;Median:</td><td>$" + Math.round(.001 * (Prices[Math.ceil(n / 2) - 1] + Prices[Math.ceil((n + 1) / 2) - 1]) / 2.0) + "K</td></tr>"

    }

    Answ += "</td></tr></table>";

    $get("EstSP").innerHTML = Answ;
    $get("NumComps").innerText = n;
}

function AddRow(N, Title, oProp) {
    var isData = false;
    var HTML = new Sys.StringBuilder("<tr><td>" + Title + "</td>");
    HTML.append("<td align='center' class='SubjHighlight'>");
    if (oProp[0]) { HTML.append(oProp[0]); isData = true; }
    else HTML.append("&nbsp;");
    HTML.append("</td>");

    for (i = 1; i < N; i++) {
        HTML.append("<td align='center'>");
        if (oProp[i]) { HTML.append(oProp[i]); isData = true; }
        else HTML.append("&nbsp;");
        HTML.append("</td>");
    }
    HTML.append("</tr>");
    if (!isData) return ""; // Skip this row, nothing there
    return HTML.toString();
}

function PopupGoogleMap() {
    var URL = "http://maps.google.com/maps?z=19&layer=tc&t=h&btnG=New+Address&cbp=1,0,1,0,0&cbll="
    URL += "&cbll=" + $get("D_Lat").value
    URL += "," + $get("D_Lon").value
    URL += "&q=" + escape(Address + "," + PostalCode + " USA")

    window.open(URL, "Map", "menubar=no,statusbar=no")
}

function PopupNeighborhoodBrowser() {
    var URL = "http://www.onboardnavigator.com/webcontent/OBWC_results.aspx?&AID=537-692f83792537&Datatype=4&Searchtype=2"
    URL += "&State=" //+ State;
    URL += "&Zip=" + PostalCode;
    URL += "&Address=" + Address;
    URL += "&City="// + City;
    window.open(URL, "Info", "menubar=no,statusbar=no")
    //	GeoNamesService.PostalCodeLookup(PostalCode, LinksCallBack, FailedCallback);

}

function MarkVisitor(Type) {

    var VisitorID = $get("hEncryptedVisitorID").value;
    var Source = $get("hSiteCode").value;
    var SysPropID = $get("hSysID").value;
    MyAjaxService.AddFavorite(VisitorID, Source, SysPropID, Type, DoNothing, FailedCallback);
}

function PopupRealQuest() {
    var URL = "http://csvaluemap.facorelogic.com/ValueMap.aspx?licenseCode=10bc72a40f6446a4ba70081d2bd0ea42"
    URL += "&StreetAddress=" + escape($get('Address').innerText);
    URL += "&CityStateZip=" + $get('hZipCode').value;
    window.open(URL, "Info", "menubar=no,statusbar=no")

}

// FUNCTION:  restrictNumeric
// REMARKS:   Called when the "onchange" event fires. This could have been done per 
//            keystroke but Netscape does not support "onkeypress" for input controls.
// IN:        bAllowDecimals - boolean, true allows periods to be entered, false will only allow numbers.
// RETURN:    none.
function restrictNumeric(bAllowDecimals, objInput) {
    // Loop through the string and remove any non numeric characters or decimals if flagged so.
    var sValue = objInput.value;
    var iLength = sValue.length;
    var iCharCode = null;
    var sNewString = "";
    for (var i = 0; i < iLength; i++) {
        iCharCode = sValue.charCodeAt(i);
        if ((iCharCode == 46 && bAllowDecimals) || (iCharCode >= 48 && iCharCode <= 57) || iCharCode == 8 || iCharCode == 9 || iCharCode == 127) {
            sNewString += sValue.charAt(i);
        }
    }

    // Display the newly formatted string.
    objInput.value = sNewString;
}
function ShowInquiry() {
		if (!$get("chkContactAnAgent").checked)
		{
			$get("chkContactAnAgent").checked = true;
			ToggleView('chkContactAnAgent', 'divContactAnAgent')
		}
    $get("divContactAnAgent").scrollIntoView(false);
    MarkVisitor("I");
}


function CancelInquiry() {
    $get("chkContactAnAgent").checked = false;
    ToggleView('chkContactAnAgent', 'divContactAnAgent')
}

function ShowSend2Friend() {
    $get("chkSend2Friend").checked = true;
    ToggleView('chkSend2Friend', 'divSend2Friend')
    $get("divSend2Friend").scrollIntoView(false);
}



function ShowMap() {
		//Reset top page navigation elements
		CurrentPage = 0;
		$get("hN").value = '0';
    
    if (parent.HideDetailFrame) {parent.HideDetailFrame(); return; }
    
    if (document.referrer.indexOf("PropSummary.aspx") > 0) {
        window.history.go(-1); // For agent web page usage ... site was framed, got back to propsummary rather than home page
    } 
    else {
    
			var Site = $get("hSiteCode").value;
			switch(Site)
			{
				case "INR": document.location.href = "../HomePageMibor.aspx"; break;
				default: document.location.href = "../HomePage" + Site + ".aspx"; break;
			}
    }
}

function AddLead() {

    if ($get("subject").value.length > 0) return; // Abort if a bot has filled in this hidden field.
    $get("tdStatus").innerText = "Preparing email...";

    var ToEmailAddr = $get("LAEmail").value;
    var FromEmailAddr = $get("txtEmail").value;
    var Subj = "Info Request from " + document.domain;
    var Msg = $get("txtFirstName").value + " " + $get("txtLastName").value + "<br>";
    Msg += Glue("", $get("txtHomeStreet").value, "<br>");
    Msg += Glue("", $get("txtHomeCity").value, ", ") + $get("txtHomeState").value + " " + $get("txtHomeZip").value + "<br>";
    Msg += Glue("<a href='mailto:", $get("txtEmail").value, "'>" + $get("txtEmail").value + "</a><br>");
    Msg += Glue("Home Phone: ", $get("txtHomePhone").value, "<br>");

    Msg += Glue("Working with agent: ", $get("txtMyAgent").value, "<br>")
    Msg += Glue("Comment: ", $get("taComments").value, "<br>")

    Msg += "<hr>The website visitor above was viewing ML# " + $get("MLNumber").innerText
    Msg += "<br>Address: <a href='" + document.location.href + "'>" + $get("hAddress").value + "</a>"
    Msg += "<br>when they sent this inquiry."

    if ($get("chkSearchInfo").checked) {
        Msg += "<br>Their search criteria at the time was:<br>"
        if (parent.SrchType) Msg += Glue("SrchType=", parent.SrchType, "<br>");
        if (parent.PropType) Msg += Glue("PropType=", parent.PropType, "<br>");
        if (parent.Beds) Msg += GlueNum("Bedrooms >=", parent.Beds, "<br>");
        if (parent.Baths) Msg += GlueNum("Baths >=", parent.Baths, "<br>");
        if (parent.MinPrice) Msg += GlueNum("Price >=", parent.MinPrice, "<br>");
        if (parent.MaxPrice) Msg += GlueNum("Price <", parent.MaxPrice, "<br>");
        if (parent.SqFt) Msg += GlueNum("SqFt >=", parent.SqFt, "<br>");
        if (parent.Acre) Msg += GlueNum("Lot size (Acres) >=", parent.Acre, "<br>");
        if (parent.YrBuilt) Msg += GlueNum("Year Built after ", parent.YrBuilt, "<br>");
        if (parent.Pool) Msg += Glue("Pool=", parent.Pool, "<br>");
        if (parent.County) Msg += Glue("County=", parent.County, "<br>");
        if (parent.OpenHouse) Msg += Glue("OpenHouse=", parent.OpenHouse, "<br>");
        if (parent.Garage) Msg += GlueNum("Garage=", parent.Garage, "<br>");
        if (parent.Area) Msg += Glue("Area=", parent.Area, "<br>");
        if (parent.Priority) Msg += Glue("Priority is ", parent.Priority, "<br>");
        //Msg += "Click to view <a href='http://" + document.domain + "/ProspectView.aspx?id=" + $get("hEncryptedVisitorID").value + "'>User's Map</a><br>"
    }
    Msg += "<br><br><b>Please reply immediately.</b><br>Thank you."


    var VisitorID = $get("hEncryptedVisitorID").value;
    var Source = $get("hSiteCode").value;
    var SysPropID = $get("hSysID").value;
    var SiteCode = $get("hSiteCode").value;

    //Lookup CCEmail to send to the MLS (stored in the SiteInfo table)
    //var ccemail = DB.GetValue("SELECT CCEmail FROM SiteInfo WHERE " + Utils.AddString("SiteMLSCode",Source));

    //LAS wants a call to their GLVAR website to track email leads, passing variables in the URL
    //Make a request to a page they specify passing the agent code and some activity code:
    //Ex: http://www.glvar.com/WebsiteTracking.asp?activity=LeadGen&Agentid=12345

    // Some slimeball offices want the leads to go to them instead of the listing agents (XA)
    // Others just want an email copy of lead (CC)
    // Some agents don't want mail at all MLXPro Only (MX)
    switch ($get("hOfficeSpecialAction").value) {
        case "XA":
            ToEmailAddr = $get("hOfficeEmail").value;
            MyAjaxService.SendLeadEmail(VisitorID, Source, SysPropID, "E", ToEmailAddr, FromEmailAddr, Subj, Msg, LeadCallback, FailedCallback)
            return; // no MLXPro Leads allowed

        case "CC":
            ToEmailAddr += ";" + $get("hOfficeEmail").value;
            MyAjaxService.SendLeadEmail(VisitorID, Source, SysPropID, "E", ToEmailAddr, FromEmailAddr, Subj, Msg, LeadCallback, FailedCallback)
            break;

        case "MX": break; // No email, just PRO

        default:
            MyAjaxService.SendLeadEmail(VisitorID, Source, SysPropID, "E", ToEmailAddr, FromEmailAddr, Subj, Msg, LeadCallback, FailedCallback)
    }

    // Send to MLX Pro if available	
    var url = $get("MLXProLeadURL").value

    var data = "listingID=" //+ $get("listingID").value
    data += "&selectedListingIDs=" + $get("selectedListingIDs").value
    data += "&radInterest=" + $get("radInterest").value
    data += "&selCriteriaBedrooms=" + $get("selCriteriaBedrooms").value
    data += "&selCriteriaBathrooms=" + $get("selCriteriaBathrooms").value
    data += "&txtCriteriaPriceMin=" + $get("txtCriteriaPriceMin").value
    data += "&txtCriteriaPriceMax=" + $get("txtCriteriaPriceMax").value
    data += "&txtCriteriaKeyFeatures="; // + $get("txtCriteriaKeyFeatures").value

    data += "&txtFirstName=" + $get("txtFirstName").value
    data += "&txtLastName=" + $get("txtLastName").value
    data += "&subject=" + $get("subject").value
    data += "&txtStreetAddress=" + $get("txtHomeStreet").value
    data += "&txtCity=" + $get("txtHomeStreet").value
    data += "&txtState=" + $get("txtHomeState").value
    data += "&txtZip=" + $get("txtHomeZip").value
    data += "&txtEmailAddress=" + $get("txtEmail").value
    data += "&txtHomePhone=" + $get("txtHomePhone").value
    data += "&txtWorkPhone="
    data += "&txtCellPhone="
    data += "&selContactMethod=Email"
    data += "&taComments=" + $get("taComments").value.replace(/\n/g, " ");

    // No callback, messages added to errorlog
    if (url.length != 0) MyAjaxService.SendLead2MLX(url, data, MLXLeadCallback, FailedCallback);

}

function MLXLeadCallback(Msg) {
    //alert(Msg);
}

function LeadCallback(Msg) {
    $get("tdStatus").innerText = Msg;
    alert(Msg);
}

function Print() {
    var whnd = window.open(self.location.href + "&prt=1", "printwindow", "width=800,height=500;");
}

function Print2() {
    //print now that we are in the popup print window	

    window.print();
    setTimeout("window.close()", 500);
}

function Send2Friend() {
    var ToEmailAddr = $get("emailto").value
    if (0 == ToEmailAddr.length) {
        alert("Please enter an email address");
        return;
    }
    $get("btnSend2Friend").disabled = false;
    var FromEmailAddr = $get("EmailFrom").value
    if (0 == FromEmailAddr.length) return;
    RememberChanges($get("EmailFrom"), 'EmailAddr');
    createCookie("VisitorEmail", FromEmailAddr, 60); // Keep track of this person.

    var url = document.location.href;

    var Subj = "Property Recommendation from " + document.domain + " (" + $get("hAddress").value + ")";
    var Msg = $get("EmailMessage").value
    Msg += "<br>--" + $get("MyFirstName").value + " " + $get("MyLastName").value + "<br>";
    Msg += "<br><a href='" + url + "'><img alt='Click for Details' src='" + $get("PhotoX").src + "'></a>"
    Msg += "<br>Address: <a href='" + url + "'>" + $get("hAddress").value + "</a>"
    Msg += Glue("<br>City: ", $get("hCity").value, "");
    Msg += Glue("<br>County: ", $get("hCounty").value, "");
    Msg += Glue("<br>Neighborhood: ", $get("hNeighborhood").value, "");
    Msg += "<br>Price: $" + CommaFmt($get("hListPrice").value)
    Msg += "<br>Bedrooms: " + $get("hBeds").value
    Msg += "<br>Bathrooms: " + $get("hBathsF").value + " Full" + GlueNum(", ", $get("hBathsP").value, " Partial");
    Msg += GlueNum("<br>Living Area: ", $get("hSqFt").value, " sqft");
    Msg += GlueNum("<br>Lot: ", $get("hLotSize").value, " acres");
    Msg += GlueNum("<br>Year Built: ", $get("hYrBuilt").value, "");
    Msg += GlueNum("<br>Garage: ", $get("hGarageSpaces").value, " spaces");
    Msg += Glue("<br>Pool: ", $get("hPoolType").value, "");

    Msg += "<br><br>URL:<a href='" + url + "'>" + url + "</a>"

    var VisitorID = $get("hEncryptedVisitorID").value;
    var Source = $get("hSiteCode").value;
    var SysPropID = $get("hSysID").value;

    MyAjaxService.SendLeadEmail(VisitorID, Source, SysPropID, "S", ToEmailAddr, FromEmailAddr, Subj, Msg, Send2FriendCallback, FailedCallback)
}

function Send2FriendCallback(Msg) {
    if ($get("btnSend2Friend")) {
        $get("btnSend2Friend").disabled = false;
    }
    alert(Msg);
}

function getFormValues(obj) {
    var queryStr = "";
    for (i = 0; i < obj.elements.length; i++) {
        var VarName = "&" + obj.elements[i].name + "="
        if (obj.elements[i].name.length == 0) continue;
        if (VarName.substr(1, 2) == "__") continue;
        switch (obj.elements[i].type) {
            case "text":
            case "submit":
            case "button":
            case "textarea":
            case "hidden": queryStr += VarName + obj.elements[i].value.replace(/\n/g, " "); break;

            case "radio":
            case "checkbox": if (obj.elements[i].checked) queryStr += VarName + obj.elements[i].value; break;

            case "select-one":
                var sel = obj.elements[i];
                queryStr += VarName + sel.options[sel.selectedIndex].value;
                break;
            default: alert("Missing getFormValues Handler for " + obj.elements[i].type);
        }
    }
    queryStr = queryStr.substr(1, (queryStr.length - 1));
    return queryStr;
}

function WikiCallBack(e) {
    var Data = Sys.Serialization.JavaScriptSerializer.deserialize(e, true);
    var HTML = new Sys.StringBuilder("");
    if ((e != null) && (Data.geonames != null)) {
        for (var i = 0; i < Data.geonames.length; i++) {
            HTML.append("<p><big><a href='http://" + Data.geonames[i].wikipediaUrl + "' target='_new'>")
            HTML.append(Data.geonames[i].title + "</a></big>&nbsp;" + Data.geonames[i].summary + "</P>")
        }
    } else {
        HTML.append("No results found")
    }
    $get("tdWiki").innerHTML = HTML.toString()
    $get("tabExternalLink").innerHTML = "";
}

function WeatherCallBack(e) {
    var Data = Sys.Serialization.JavaScriptSerializer.deserialize(e, true);
    var HTML = new Sys.StringBuilder("");
    if ((e != null) && (Data.weatherObservation != null)) {
        HTML.append("Observation Station: " + Data.weatherObservation.stationName);
        HTML.append("<br>Time of Observation: " + Data.weatherObservation.datetime);
        HTML.append("<br>Obervation Elevation: " + Data.weatherObservation.elevation);
        HTML.append("<br>Weather Conditions: " + Data.weatherObservation.weatherCondition);
        HTML.append("<br>Clouds: " + Data.weatherObservation.clouds);
        HTML.append("<br>Temperature: " + Data.weatherObservation.temperature);
        HTML.append("<br>Wind Speed: " + Data.weatherObservation.windSpeed);
        HTML.append("<br>Wind Direction: " + Data.weatherObservation.windDirection);
        HTML.append("<br>Dew Point: " + Data.weatherObservation.dewPoint);
        HTML.append("<br>Humidity: " + Data.weatherObservation.humidity);
    } else {
        HTML.append("No results found");
    }
    $get("tdWeather").innerHTML = HTML.toString()
}

function HelpSwitch() {
    $get('tdHelp').style.display = 'block';
    $get('linkClick').innerText = "";
}

function GetInput(FldName) {
    var oCtrl = $get(FldName)
    if (!oCtrl) alert(FldName + " is not an object");
    return MakeInt(oCtrl.value.replace(/\,/g, ""));
}

function Compute() {
	if (!$get("divLoanCalc")) return;
    var Price = GetInput("SalesPrice");
    var DownPay = GetInput("DownPay");
    var Taxes = GetInput("Taxes");
    var Insurance = GetInput("Insurance");
    var HOA = GetInput("HOA")
    var Taxes = GetInput("Taxes")
    var Mortgage = Price - DownPay;
    var Closing = GetInput("Closing")
    if (Closing == 0) Closing = .03 * Price;
    var Cash = DownPay + Closing
    var IR = $get("Rate")[$get("Rate").selectedIndex].value / 1200.
    var Pay = Math.round(Mortgage * ((IR * Math.pow(1 + IR, 30 * 12)) / ((Math.pow(1 + IR, 30 * 12)) - 1)));

    $get("SalesPrice").value = CommaFmt(Price);
    $get("DownPay").value = CommaFmt(DownPay);
    $get("Mortgage").value = CommaFmt(Mortgage);
    $get("Closing").value = CommaFmt(Closing);
    $get("Cash").value = CommaFmt(Cash);
    $get("Pay").value = CommaFmt(Pay);
    $get("Taxes").value = CommaFmt(Taxes);
    $get("Insurance").value = CommaFmt(Insurance);
    $get("HOA").value = CommaFmt(HOA);
    $get("MoTotal").value = CommaFmt(Math.round(Pay + Insurance + HOA + Taxes));
    $get("Income").value = CommaFmt(Math.round((12 * (Pay + Taxes + Insurance)) / .28));
}

function GetAuxPhotos() {
    var Source = $get("hSiteCode").value;
    var SysID = $get("hSysID").value;
    MyAjaxService.GetAuxPhotos(Source, SysID, GetAuxPhotosCallBack, FailedCallback);
}

function GetAuxPhotosCallBack(ImgList) {
    // Show photo list
    for (var i = 0; i < ImgList.length; i++) {
        var oPhotoH = $get("Photo" + i);
        var oPhotoV = $get("PhotoB" + i);
        var oPhotoXH = $get("PhotoXH" + i);
				var oPhotoXV = $get("PhotoXV" + i);
        if (oPhotoH) {oPhotoH.src = "http://" + ImgList[i]; oPhotoH.style.display = "block";}
        if (oPhotoV) {oPhotoV.src = "http://" + ImgList[i]; oPhotoV.style.display = "block";}
        if (oPhotoXH) {oPhotoXH.src = "http://" + ImgList[i]; oPhotoXH.style.display = "block";}
        if (oPhotoXV) {oPhotoXV.src = "http://" + ImgList[i]; oPhotoXV.style.display = "block";}
   }
    $get("NumPhotos").value = ImgList.length;
    Resize();
}

function GetSuggestedProps() {
		if (!$get("divPropSuggest")) return;

    var NumComps = 5;
    var CompPropStatus = "A";
    var MLNum = $get("hMLNum").value;
    var Lat = parseFloat($get("hLatitude").value); if (isNaN(Lat)) Lat = 40;
    var Lon = parseFloat($get("hLongitude").value); if (isNaN(Lon)) Lon = -80;
    var PropType = $get("hPropTypeCode").value;
    var Neighborhood = $get("hNeighborhood").value;
    var ZipCode = $get("hZipcode").value;
    var City = $get("hCity").value;
    var County = $get("hCounty").value;
    var Beds = parseInt($get("hBeds").value, 10); if (isNaN(Beds)) Beds = 0;
    var BathsF = parseInt($get("hBathsF").value, 10); if (isNaN(BathsF)) BathsF = 0;
    var BathsP = parseInt($get("hBathsP").value, 10); if (isNaN(BathsP)) BathsP = 0;
    var SqFt = parseInt($get("hSqFt").value, 10); if (isNaN(SqFt)) SqFt = 0;
    var Lot = Math.round($get("hLotSize").value);
    var YrBuilt = parseInt($get("hYrBuilt").value, 10); if (isNaN(YrBuilt)) YrBuilt = 0;
    var LPrice = parseInt($get("hListPrice").value, 10); if (isNaN(LPrice)) LPrice = 0;
    var HOAFeeMo = parseInt($get("hHOAFee").value, 10); if (isNaN(HOAFeeMo)) HOAFeeMo = 0;
    var TaxesMo = parseInt($get("hTaxes").value, 10); if (isNaN(TaxesMo)) TaxesMo = 0;
    var AssessedValue = parseInt($get("hAssessed").value, 10); if (isNaN(AssessedValue)) AssessedValue = 0;
    var GarageSpaces = parseInt($get("hGarageSpaces").value, 10); if (isNaN(GarageSpaces)) GarageSpaces = 0;
    var PoolType = $get("hPoolType").value;
    var DOM = parseInt($get("hDOM").value, 10); if (isNaN(DOM)) DOM = 0;
    MyAjaxService.GetCompGrid(NumComps, CompPropStatus,
				MLNum, Lat, Lon, PropType, Neighborhood, ZipCode, City, County, Beds, BathsF, BathsP, SqFt,
				Lot, YrBuilt, LPrice, HOAFeeMo, TaxesMo, AssessedValue, GarageSpaces, PoolType, DOM,
				this.PropsSuggestedCallBack, FailedCallback);

}

function PropsSuggestedCallBack(CompProp) {

    var Source = $get("hSiteCode").value
	
    var N = CompProp.N;
    var Tbl = new Sys.StringBuilder("<p class=\"suggestedPropsHeaderBold\">Below are comparable properties that you might be interested in viewing.</p>");
    Tbl.append("<table width=\"95%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
    Tbl.append("<tr>");
    //Repeats price columns
    for (i = 1; i < N; i++) {

        Tbl.append("<td width=\"100\" class=\"suggestedPropsPrice\">$" + CommaFmt(CompProp.iPrice[i]) + "</td>");
    }
    Tbl.append("</tr>");
    Tbl.append("<tr>");
    //Repeats photo columns
    for (j = 1; j < N; j++) {
        var URL = "http://" + CompProp.PhotoPaths[j];
        //var DetailURL = "javascript:void(0);";
        var DetailURL = "Javascript:ShowPropDetail(" + j + ",'" + Source + "','" + CompProp.SysPropID[j] + "')";
        if (!CompProp.PhotoPaths[j]) URL = "../Icons/NoPhoto_147.jpg";
        Tbl.append("<td width=\"100\"><a href=\"" + DetailURL + "\" class=\"suggestedPropsLink\"><img src='" + URL + "' alt='" + CompProp.Address[j] + "' width='100' height='75' hspace='0' vspace='2' border='0' align='left' /></a></td>");
    }
    Tbl.append("</tr>");
    Tbl.append("<tr>");
    for (k = 1; k < N; k++) {
        //var DetailURL = "javascript:void(0);";
        var DetailURL = "Javascript:ShowPropDetail(" + k + ",'" + Source + "','" + CompProp.SysPropID[k] + "')";
        Tbl.append("<td width=\"100\" valign=\"top\"><a href=\"" + DetailURL + "\" class=\"suggestedPropsLink\">" + CompProp.Address[k] + "</a></td>");
    }
    Tbl.append("</tr>");
    Tbl.append("</table>");

    $get("divPropSuggest").innerHTML = Tbl.toString();

    //Display suggested properties block
    $get("divPropSuggest").style.display = "block";
}

function ShowPropDetail(N, Source, SysID) {
    switch (Site) {
        case "HHI":
            var URL = FullURL("SiteContent/PropDetail_B.aspx?N=" + N + "&S=" + Source + "&Id=" + SysID);
            break;
        case "INR":
        default:
            var URL = FullURL("SiteContent/PropDetail.aspx?N=" + N + "&S=" + Source + "&Id=" + SysID);
            break;
    }
    if (parent.ShowDetailFrame) {parent.ShowDetailFrame(URL);}
    else
        document.location.href = URL;
}

function DoNothing() {

}

function SetSelection(){
	parent.SelectedProp[CurrentPage]=$get("ckSelect").checked;
	
}
