/* LISTINGS MAPPING FOR HOMES.Z57.COM
   IF YOU EDIT THIS ALSO EDIT THE WEBSITE FILE AS WELL
*/

  fileManagerURL = 'http://root.z57.com/filemanager/uploads/';

  function createYahooMarker(geopoint, info) { 
    var myImage = new YImage(listingIcon,new YSize(listingIconWidth,listingIconHeight),new YCoordPoint(listingIconWidth-4,listingIconHeight-4)); 
    var marker = new YMarker(geopoint,myImage);
    marker.addAutoExpand("<div style='width:100px;height:60px;'><center><b>Click on the icon for property information.</b></center></div>");
    YEvent.Capture(marker,EventsList.MouseClick, function() { marker.openSmartWindow(info) }); 
    return marker; 
  }
  var myFilter = function (dataSet, row, rowNumber)
  {
  	var minPrice=0;
	var maxPrice=0;
	switch(parseInt(document.forms[0]["price"].value)){
		case 1:
			minPrice=0;
			maxPrice=100000;
			break;
		case 2:
                        minPrice=100000;
                        maxPrice=200000;
                        break;
		case 3:
                        minPrice=200000;
                        maxPrice=300000;
                        break;
		case 4:
                        minPrice=300000;
                        maxPrice=400000;
                        break;
		case 5:
                        minPrice=400000;
                        maxPrice=500000;
                        break;
		case 6:
                        minPrice=500000;
                        maxPrice=750000;
                        break;	
		case 7:
                        minPrice=750000;
                        maxPrice=1000000;
                        break;	
		case 8:
                        minPrice=1000000;
                        maxPrice=1000000000;
                        break;	
	}
	if (document.forms[0]["price"].value != "" && ( row["pricesort"] == "" || parseInt(row["pricesort"]) < minPrice || parseInt(row["pricesort"]) > maxPrice)) {
		hideMarker(row);
		return null;
	}
	else if (document.forms[0]["city"].value != "" && row["city"] != document.forms[0]["city"].value) {
		hideMarker(row);
		return null;
	}
	else if (document.forms[0]["state"].value != "" && row["state"] != document.forms[0]["state"].value) {
		hideMarker(row);
		return null;
	}	
	else if (document.forms[0]["type"].value != "" && row["type"] != document.forms[0]["type"].value) {
		hideMarker(row);
		return null;
	}	
	else if (document.forms[0]["bed"].value != "" && ((document.forms[0]["bed"].value != "4" && row["bedrooms"] != document.forms[0]["bed"].value) || (document.forms[0]["bed"].value == "4" && parseFloat(row["bedrooms"]) < 4) || row["bedrooms"] == "")) {
		hideMarker(row);
		return null;
	}
	else if (document.forms[0]["bath"].value != "" && ((document.forms[0]["bath"].value != "3" && row["bathrooms"] != document.forms[0]["bath"].value) || (document.forms[0]["bath"].value == "3" && parseFloat(row["bathrooms"]) < 3))) {
		hideMarker(row);
		return null;
	}	
	showMarker(row);	
	return row;
  }
  var initFilter = function(dataSet, row, rowNumber) 
  {
	plot(row, rowNumber);
	return row;
  }
  var destructiveFilter = function(dataSet, row, rowNumber)
  {
    if (document.forms[0]["listing"].value != "" && row["lid"] != document.forms[0]["listing"].value) {
       return null;
    }    
    
    if (document.forms[0]["agent"].value != "" && row["agent"] != document.forms[0]["agent"].value) {
		return null;
	}  	
	if (document.forms[0]["office"].value != "" && row["office"] != document.forms[0]["office"].value) {
		return null;
	}  	
	if (document.forms[0]["category"].value != "" && row["category"] != document.forms[0]["category"].value) {
		return null;
	}
    if (document.forms[0]["featured"].value != "" && row["featured"] != document.forms[0]["featured"].value) {
        return null;
    }
    if (document.forms[0]["openhouse"].value != "" && row["openhouse"] != document.forms[0]["openhouse"].value) {
        return null;
    }                                          	
	if (document.forms[0]["no_import"].value == "T" && row["imported"] == "T") {
        return null;
    }
	return row;
  }
  function plot(row, rowNumber)
  {
	if (row["lat"] != "" && row["lon"] != "")
	{
		markerArray[row["ds_RowID"]] = createYahooMarker(new YGeoPoint(row["lat"],row["lon"]),makeSmartWindow(row["lid"],row["ltitle"],fileManagerURL+row["image"],row["height"],row["width"],row["price"],row["address1"],row["city"],row["state"],row["zip"],row["bedrooms"],row["bathrooms"],theRID));
		markerArray[row["ds_RowID"]].setSmartWindowColor(infoWindowBorderColor);
        map.addOverlay(markerArray[row["ds_RowID"]]);
        if (centerMapOnFirst == "0") {
        	map.drawZoomAndCenter(markerArray[row["ds_RowID"]].YGeoPoint, defaultZoom);
        	centerMapOnFirst = 1;
        }
	}
  }
  function showMarker(row)
  {
	if (typeof(markerArray[row["ds_RowID"]]) != "undefined") {
        markerArray[row["ds_RowID"]].unhide();
        if (centerMapOnFirst == "0") {
        	map.drawZoomAndCenter(markerArray[row["ds_RowID"]].YGeoPoint, defaultZoom);
        	centerMapOnFirst = 1;
        }		
	}
  }
  function hideMarker(row)
  {
	if (typeof(markerArray[row["ds_RowID"]]) != "undefined") {
		markerArray[row["ds_RowID"]].hide();
	}
  }
  function makeSmartWindow(listingid,title,photo,photoHeight,photoWidth,price,address,city,state,zip,bed,bath,rid)
  {
	smartWindow = "<div style='width: 200px;'>";
	smartWindow += "<b>"+title+"</b><br />";
	smartWindow += "<b>Address:</b><br />"+address+"<br />"+city+", "+state+" "+zip;
	smartWindow += "<hr>"
	if (photo != "")
		smartWindow += "<img src='"+photo+"' height='"+photoHeight+"' width='"+photoWidth+"'>";	
	if (price != "")
		smartWindow += "<br /><b>Price:</b> "+price;
	if (bed != "")
		smartWindow += "<br /><b>Bedrooms:</b> "+bed;
	if (bath != "")
		smartWindow += "<br /><b>Bathrooms:</b> "+bath;
	smartWindow += "<br /><a href='"+city+"-"+state+"~"+rid+"~~"+listingid+".cfm'><img src='http://images.z57websites.com/realestate/ae/mapping/images/btn-sm-more_details.gif' width='90' height='18' border='0' /></a> ";
	/* smartWindow += "<a href='/exec/clients.real_estate.ae_forms.main?TEMPLATE=listing_schedule&RID="+theRID+"&LID="+listingid+"'><img src='http://images.z57websites.com/realestate/ae/mapping/images/btn-sm-schedule_showing.gif' width='98' height='18' border='0' /></a>"; */
	smartWindow += "</div>";
	return smartWindow;
  }
  var initFilterObserver = new Object;
  initFilterObserver.onPostLoad = function(dataSet, data)
  {
	if (initRan == 0) {
		initRan = 1;
		dsListings.filter(null);
	}
  }  
  function getQueryVariable(variable) {
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i=0;i<vars.length;i++) {
      var pair = vars[i].split("=");
      if (pair[0] == variable) {
        return pair[1];
      }
    } 
    return 0;
  }  
