var ds = 'ms_search_stark';
var max_results = "500";

var open_div = "";

function getMap(envelope) {

	if (okToSend) {
  		http = getHTTPObject();

  		if ((http != null) ) {
			okToSend = false;
	    	var axl = getMapRequest(envelope);
   	 
    		http.open("POST", url, true);
	    	http.onreadystatechange = printResponse;
	    	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	    	showLayer('loading');
	    	http.send(axl);
		}
	}
}

function createQueryString()
{
        var retVal = "minx=" + minx + "&miny=" + miny + "&maxx=" + maxx + "&maxy=" + maxy;

        var myvars = new Array('lp_low', 'lp_high', 'beds_low', 'baths_low', 'p_type');

        for (var i = 0; i < myvars.length; i++) {
                retVal = retVal + "&" + myvars[i] + "=" + getElmById(myvars[i]).value;
        }


        retVal += "&zoom=true&scale=" + scale;


        if (document.getElementById('jl').checked) {
                retVal += "&jl=true";
        }
        if (document.getElementById('wf').checked) {
                retVal += "&wf=true";
        }
        if (document.getElementById('oh').checked) {
                retVal += "&oh=true";
        }
        return escape(retVal);
}

function buildPoiWhere() {
        var w = "";
        var cats = "";

        var inputs = document.getElementsByTagName('input');

        for(var i=0; i<inputs.length; i++){
                var type = inputs[i].type;
                var id = inputs[i].id;
                var name = inputs[i].name;
                if (type == 'checkbox' && id.indexOf('POI_') == 0) {
                        if (inputs[i].checked) {
                                if (cats.length == 0) {
                                        cats += "'" + name + "'";
                                } else {
                                        cats += ",'" + name + "'";
                                }
                        }
                }
        }

        if (cats.length > 0) {
                w = " AND tp_category IN (" + cats + ")";
        }

        return w;
}

function getMapRequest(env)
{
        var lp_low = document.getElementById('lp_low').value;
        var lp_high = document.getElementById('lp_high').value;
        var beds_low = document.getElementById('beds_low').value;
        var baths_low = document.getElementById('baths_low').value;
        var p_type = document.getElementById('p_type').value;
        var wf = document.getElementById('wf').checked ? "true" : "";
        var jl = document.getElementById('jl').checked ? "true" : "";
        var oh = document.getElementById('oh').checked ? "true" : "";

       	var w = ' AND lp_Listing_Price >= ' + lp_low + ' AND lp_Listing_Price <= ' + lp_high + ' AND lp_No_Bedrooms >= ' + beds_low + '  AND lp_No_Bathrooms >= ' + baths_low;

        if (p_type.length > 0) {
                w += " AND lp_tp_Improvement = '" + escape(p_type) + "'";
        }
        if (wf.length > 0) {
                w += " AND lp_fg_WaterAccess = 'Y'";
        }

        if (oh.length > 0) {
                w += " AND lp_ind_OpenHouse = 'Y'";
        }

        if (jl.length > 0) {
                w += " AND lp_Listing_Date > DATE_ADD(NOW(), INTERVAL -7 DAY)";
        }

        w += " ORDER BY " + order_by + " " + up_down;

	var w_poi = buildPoiWhere();

        var fl = "cd_MLS,lp_MLS_Number,FORMAT(lp_Listing_Price, 0) as lp_Listing_Price_Display,FLOOR(lp_Listing_Price) AS lp_Listing_Price,lp_ListingCity,lp_ListingAddr1,lp_No_Bedrooms,lp_No_Bathrooms,lp_res_Lat,lp_res_Long,lp_Photo_URL,lp_PhotoDesc_1,lp_ind_OpenHouse,lp_ds_OpenHouseTime,cd_Company,PanoramaDesc16";

        var axl = 'SITE=' + site + '&INC_OFFICES=&minx=' + minx + '&maxy=' + maxy + '&maxx=' + maxx + '&miny=' + miny + '&cache=' + cache + '&width=' + width + '&height=' + height + '&INC_LISTINGS=y&DS=' + ds + '&MAX_RESULTS=' + max_results + '&FL=' + fl + "&scale=" + scale + '&zoom=' + fixedzoom + "&CACHE_ORIGIN_X=" + cache_origin_x + "&CACHE_ORIGIN_Y=" + cache_origin_y + "&SRCH_WHERE=" + w + "&INC_POI=" + (w_poi.length > 0 ? "true" : "") + "&POI_WHERE=" + w_poi;

        axl += '&US_TILES=true'

        return axl;
}

function printResponse(){

if (http.readyState == 4) {
    if (http.status == 200) {

      isWorking = false;
      
      	var result = http.responseText;

	var xmlDoc = getXMLDoc();
	
      	var tiles = xmlDoc.getElementsByTagName("TILES")[0].getElementsByTagName("TILE");
        scale = xmlDoc.getElementsByTagName("TILES").item(0).getAttribute("scale");

        resolution = xmlDoc.getElementsByTagName("TILES").item(0).getAttribute("resolution");

	positionMileSlider();

        var env = xmlDoc.getElementsByTagName("ENVELOPE").item(0);

        minx = parseFloat(env.getAttribute("minx"));
        miny = parseFloat(env.getAttribute("miny"));
        maxx = parseFloat(env.getAttribute("maxx"));
        maxy = parseFloat(env.getAttribute("maxy"));

        clearImageMap();

        placeTiles(tiles);

        fixedzoom = "";

        document.getElementById('propcount').innerHTML = 'Property Count: ' + xmlDoc.getElementsByTagName("PROPERTIES").item(0).getAttribute("count");

        var props = xmlDoc.getElementsByTagName("PROPERTY");
        var offices = xmlDoc.getElementsByTagName("OFFICE");
	var pois = xmlDoc.getElementsByTagName("POI");

        processPropertyRecs(props, xmlDoc.getElementsByTagName("PROPERTIES").item(0).getAttribute("count"));
        processOfficeRecs(offices);
	if (props.length > 0) {
	processPoiRecs(pois);
	}

	var saveSearch = getElmById('saveSearch');
		var p_div = getElmById('poi_div');

        if (props.length > 0) {
		p_div.style.visibility = 'visible';
		display_stats(props);
        	createSummary(props);
		saveSearch.innerHTML = createSaveLink();
		saveSearch.style.visibility = 'visible';
     	} else {
		p_div.style.visibility = 'hidden';
		document.getElementById('POI_SCHOOL').checked = false;
		document.getElementById('POI_LIBRARY').checked = false;
		clearStats();	
        	clearSummary();
		saveSearch.style.visibility = 'hidden';
        }


	hideLayer('loading');
    }
 
   okToSend = true;
  } 
}

function processPoiRecs(props)
{


        for (var i = 0; i < props.length; i++) {
                var x = parseInt(props[i].getAttribute('x'));
                var y = parseInt(props[i].getAttribute('y'));

                var x1 = x;
                var y1 = y;

                var icon_type = "";

                if (x > (width / 2)) {
                        if (y > (height / 2)) {
                                icon_type = "BR";
                                x = x - icon_w;
                                y = y - icon_h;
                        } else {                                
				icon_type = "TR";
                                x = x - icon_w + 6;
                                y = y + 4;
                        }
                } else {
                        if (y > (height / 2)) {
                               icon_type = "BL";                                
				y = y - icon_h;
                                x = x + 5;
                        } else {
                                icon_type = "TL";
                                x = x + 5;
                                y = y + 3;                        
			}
		}

                var cd_key = cleanString(props[i].getAttribute('cd_key'));
                var myDiv = document.createElement('DIV');                
		myDiv.id = "POI_" + cd_key;
                myDiv.style.position='absolute';
                myDiv.style.visibility='hidden';
                myDiv.style.left =x + 'px';
                myDiv.style.top = y + 'px';
                myDiv.style.width = '206px';
                myDiv.style.height= '237px';

		myDiv.style.zIndex=2;

                var tmp_balloon = '<div class="balloon_' + icon_type + '">';
                tmp_balloon += '<div class="inner_balloon_poi">';

                tmp_balloon += '<div class="close_icon"><a href="javascript:hideAll();"><img border="0" src="images/close_icon.gif" style="width:17px;"></a></div><br>';
                if (cleanString(props[i].getAttribute('ds_image')).indexOf('<img') > -1) {
                        tmp_balloon += cleanString(props[i].getAttribute('ds_image'));
                } else if (cleanString(props[i].getAttribute('ds_image')).length > 0) {
                        tmp_balloon += '<img src="http://mapping.redata.com/plots/poi/' + site + '/poi/'  + cleanString(props[i].getAttribute('ds_image')) + '" with="150" height="117"><br>';
                }

                if (cleanString(props[i].getAttribute('ds_display')).length > 0) {
                        tmp_balloon += '<table><tr><td align="left">' + cleanString(props[i].getAttribute('ds_display')) + '</td></tr></table>';
                } else {
                        tmp_balloon += cleanString(props[i].getAttribute('ds_text1')) + '<br>';
                        tmp_balloon += cleanString(props[i].getAttribute('ds_text2')) + '<br>';
                        tmp_balloon += cleanString(props[i].getAttribute('ds_text3')) + '<br>';
                }

                tmp_balloon += '</div>';

                tmp_balloon += '</div>';

                myDiv.innerHTML = tmp_balloon;

                mapContainer.appendChild(myDiv);

                var area = document.createElement('DIV');
                area.id = cd_key;

                area.innerHTML = '<img src="images/' + cleanString(props[i].getAttribute('ds_icon')) + '" border="0">';

                area.style.left=x1 + 'px';
                area.style.top=y1 + 'px';
                area.style.position='absolute';
                area.style.zIndex=1;
                area.onmouseover = function() {
			hideAll();
                        document.getElementById('POI_' + this.id).style.visibility = 'visible';
                        open_div = document.getElementById('POI_' + this.id);
                        document.onmousemove = checkPosition;

                }

                mapContainer.appendChild(area);

        }
}

function processOfficeRecs(offices)
{


        var queryString = createQueryString();

	for (var i = 0; i < offices.length; i++) 
	{
		var x = parseInt(offices[i].getAttribute('x'));
		var y = parseInt(offices[i].getAttribute('y'));
  	
		var x1 = x;
                var y1 = y;

		var icon_type = "";

                if (x > (width / 2)) {
                	if (y > (height / 2)) {
				icon_type = "BR";
				x = x - icon_w;
				y = y - icon_h; 
			} else {
				icon_type = "TR";
				x = x - icon_w + 6;
				y = y + 4;
			}				
		} else {
                	if (y > (height / 2)) {
				icon_type = "BL";
				y = y - icon_h;
				x = x + 5;
			} else {
				icon_type = "TL";
				x = x + 5;
				y = y + 3;
			}
                }

                var myDiv = document.createElement('DIV');
                myDiv.id = "OFFICE_" + i;
                myDiv.style.position='absolute';
                myDiv.style.visibility='hidden';
                myDiv.style.left =x + 'px';
                myDiv.style.top = y + 'px';
                myDiv.style.width = '206px';
                myDiv.style.height= '237px';
                myDiv.style.zIndex=2;

                var photo_string = "";

                if (offices[i].getAttribute('O_DFLT_PHOTO_URL').length > 0) {
                        photo_string = '<a href="' + root_url + cleanString(offices[i].getAttribute('O_WWWSITE')) + '" target="_parent"><img src="' + root_url + cleanString(offices[i].getAttribute('O_DFLT_PHOTO_URL')) + '" width="150" height="117" border="0"></a>';

                } 

		var balloon = '<div class="balloon_' + icon_type + '">';
		balloon += '<div class="inner_balloon">';
		balloon += '<div class="close_icon"><a href="javascript:hideAll();"><img border="0" src="images/close_icon.gif" style="width:17px;"></a></div>';
		balloon += photo_string;
		balloon += '<div class="address">' + cleanString(offices[i].getAttribute('O_NM_OFFICE')) + '</div>';
		balloon += cleanString(offices[i].getAttribute('O_ADDRESS_01')) + '<br />';
		balloon += '<a href="' + root_url + cleanString(offices[i].getAttribute('O_WWWSITE')) + '&mapvars=' + queryString + '%26s_layer%3DmyOffice' + i + '" target="_parent">More Details</a>';
		balloon += '</div>';
		balloon += '</div>';
		balloon += '</div>';

		if (offices[i].getAttribute("O_WWWSITE").length > 0) {

			myDiv.innerHTML = balloon;

                	mapContainer.appendChild(myDiv);
                        
	                var area = document.createElement('DIV');
        	        area.id = i;
                	area.innerHTML = '<img src="http://www.starkhomes.com/icon-office.gif" width="16" height="16" border="0">';
	                area.style.left=x1 + 'px';
        	        area.style.top=y1 + 'px';
                	area.style.position='absolute';
	                area.style.zIndex=1;
        	        area.onmouseover = function() {
				hideAll();
                        	document.getElementById('OFFICE_' + this.id).style.visibility = 'visible';
                        	open_div = document.getElementById('OFFICE_' + this.id);
                        	document.onmousemove = checkPosition;
                	}
                
                mapContainer.appendChild(area); 
		
		}
                
        }       
}
	
function processPropertyRecs(props, numProps)
{

	var props_list = "";

	var queryString = createQueryString();
	
	for (var i = 0; i < props.length; i++) {
		var x = parseInt(props[i].getAttribute('x'));
		var y = parseInt(props[i].getAttribute('y'));
	
		if (props_list.length == 0) {
			props_list = props[i].getAttribute("cd_MLS");
		} else {
			props_list = props_list +  "," + props[i].getAttribute("cd_MLS");
		}
	
		var x1 = x - 8;
		var y1 = y - 8;

                var icon_type = "";

                if (x > (width / 2)) {
                        if (y > (height / 2)) {
                                icon_type = "BR";
                                x = x - icon_w;
                                y = y - icon_h;
                        } else {
                                icon_type = "TR";
                                x = x - icon_w + 6;
                                y = y + 4;
                        }
                } else {
                        if (y > (height / 2)) {
                                icon_type = "BL";
                                y = y - icon_h;
                                x = x;
                        } else {
                                icon_type = "TL";
                                x = x;
                                y = y;
                        }
                }

		var myDiv = document.createElement('DIV');
		myDiv.id = "LISTING_" + i;
		myDiv.style.position='absolute';
		myDiv.style.visibility='hidden';
		if (s_layer == props[i].getAttribute('cd_MLS')) {
			myDiv.style.visibility = 'visible';
			s_layer = '';
		}

		myDiv.style.left =x + 'px';
		myDiv.style.top = y + 'px';
		myDiv.style.width = '206px';
		myDiv.style.height= '237px';
		myDiv.style.zIndex=2;

		var photo_string = "";

                if (props[i].getAttribute('lp_Photo_URL').length > 0) {
                        if (pres_agent.length > 0) {
                                photo_string = '<a href="' + root_url + '/vp/ListingServlet?cd_MLS=' + props[i].getAttribute('cd_MLS') + '&SITE=' + site + '&ScreenID=AGENT_LISTING_DETAIL&pres_agent=' + pres_agent + '&mapvars=' + queryString + '%26s_layer%3D' + props[i].getAttribute('cd_MLS') +'" target="_parent"><img src="http://' + cleanString(props[i].getAttribute('lp_Photo_URL')) + props[i].getAttribute('lp_MLS_Number') + 'at.jpg" width="150" height="117" border="0"></a>'; 
                        } else {
                                photo_string = '<a href="' + root_url + '/vp/ListingServlet?cd_MLS=' + props[i].getAttribute('cd_MLS') + '&SITE=' + site + '&ScreenID=LISTING_DETAIL_P&mapvars=' + queryString + '%26s_layer%3D' + props[i].getAttribute('cd_MLS') +'" target="_parent"><img src="http://' + cleanString(props[i].getAttribute('lp_Photo_URL')) + props[i].getAttribute('lp_MLS_Number') + 'at.jpg" width="150" height="117" border="0"></a>';
                        }
                }
                
                var balloon = '<div class="balloon_' + icon_type + '">';
                balloon += '<div class="inner_balloon">';
                if (props[i].getAttribute('lp_ind_OpenHouse') == 'Y') {
                        if (pres_agent.length > 0) {
                                balloon += '<div style="font-size:9px;font-face:Arial"><a href="' + root_url + '/vp/ListingServlet?cd_MLS=' + props[i].getAttribute('cd_MLS') + '&SITE=' + site + '&ScreenID=AGENT_LISTING_DETAIL&pres_agent=' + pres_agent + '&mapvars=' + queryString + '%26s_layer%3D' + props[i].getAttribute('cd_MLS')  + '" target="_parent">Open:' + cleanString(props[i].getAttribute('lp_ds_OpenHouseDay')) + ' ' + cleanString(props[i].getAttribute('lp_ds_OpenHouseTime')) + '</a></div>';
                        } else {
                                balloon += '<div style="font-size:9px;font-face:Arial"><a href="' + root_url + '/vp/ListingServlet?cd_MLS=' + props[i].getAttribute('cd_MLS') + '&SITE=' + site + '&ScreenID=LISTING_DETAIL_P&mapvars=' + queryString + '%26s_layer%3D' + props[i].getAttribute('cd_MLS')  + '" target="_parent">Open:' + cleanString(props[i].getAttribute('lp_ds_OpenHouseDay')) + ' ' + cleanString(props[i].getAttribute('lp_ds_OpenHouseTime')) + '</a></div>';                             
                        }       
                }       
                
		if (cleanString(props[i].getAttribute('PanoramaDesc16')).length > 0) {
			balloon += "<table cellpadding=\"0\" cellspacing=\"0\" width=\"150\"><tr><td align=\"left\"><a href=\"#\" onClick=\"getStreetView('" + props[i].getAttribute('lp_MLS_Number') + "'); return true;\"><img src=\"images/streetview.gif\" style=\"width:20px\" border=\"0\"></td><td align=\"right\"><a href=\"javascript:hideAll();\"><img border=\"0\" src=\"images/close_icon.gif\" style=\"width:15px\"></a></td></tr></table>";
		} else {
			balloon += "<table cellspacing=\"0\" cellpadding=\"0\"><tr><td align=\"right\"><a href=\"javascript:hideAll();\"><img border=\"0\" src=\"images/close_icon.gif\" style=\"width:15px\"></a></td></tr></table>";
		}

                balloon += photo_string;
                balloon += '<div class="address">' + cleanString(props[i].getAttribute('lp_ListingAddr1')) + '</div>';
                balloon += '$' + cleanString(props[i].getAttribute('lp_Listing_Price_Display')) + '<br />';  
                balloon += props[i].getAttribute('lp_No_Bedrooms') + ' Beds ' + props[i].getAttribute('lp_No_Bathrooms') + ' Baths<br>';
                if (pres_agent.length > 0) {
                        balloon += '<a href="' + root_url + '/vp/ListingServlet?cd_MLS=' + props[i].getAttribute('cd_MLS') + '&SITE=' + site + '&ScreenID=AGENT_LISTING_DETAIL&pres_agent=' + pres_agent + '&mapvars=' + queryString + '%26s_layer%3D' + props[i].getAttribute('cd_MLS') + '" target="_parent">More Details</a>';
                } else {
                        balloon += '<a href="' + root_url + '/vp/ListingServlet?cd_MLS=' + props[i].getAttribute('cd_MLS') + '&SITE=' + site + '&ScreenID=LISTING_DETAIL_P&mapvars=' + queryString + '%26s_layer%3D' + props[i].getAttribute('cd_MLS') + '" target="_parent">More Details</a>';                
		}                
		balloon += '</div>';
		balloon += '</div>';
                balloon += '</div>';

                myDiv.innerHTML = balloon;

		mapContainer.appendChild(myDiv);
	
		var area = document.createElement('DIV');
		area.id = i;
	
		if (props.length < 250) {
	  		area.innerHTML = '<img src="images/House-Image.gif" border="0">';
		} else {
	  		area.innerHTML = '<img src="images/House-Image.gif" height="8" border="0">';
		}
	
		area.style.left=x1 + 'px';
		area.style.top=y1 + 'px';
		area.style.position='absolute';
		area.style.zIndex=1;
		area.onmouseover = function() {
			hideAll();
                        document.getElementById('LISTING_' + this.id).style.visibility = 'visible';
                        open_div = document.getElementById('LISTING_' + this.id);
                        document.onmousemove = checkPosition;

		}

		mapContainer.appendChild(area);
	
	}

         var theform = getElmById("theForm");


        if (props.length > 0)
        {

                var cd_MLS_sum = getElmById("cd_MLS_sum");
                var numPages = getElmById("numPages");
                var numFound = getElmById("numFound");
                var searchCriteria = getElmById("searchCriteria");
                var mapvars = getElmById("mapvars");

                mapvars.value = unescape(createQueryString());
                theform.style.visibility = 'visible';
                cd_MLS_sum.value = props_list;
                numFound.value = props.length;
                numPages.value = Math.ceil(parseFloat(props.length / 10));

        } else {
                theform.style.visibility = 'hidden';
        }

}

function getStreetView(str) {

var sv = document.getElementById('streetview');
sv.style.visibility = 'visible'; 

sv.style.width = width + 'px';
sv.style.left= '0px';
if (isSafari) {
	sv.style.top = '0px';
	sv.style.height= height+ 'px';
} else {
	sv.style.top = '0px';
	sv.style.height = height + 'px';
}
sv.innerHTML = '<table width="' + width + '" bgcolor="white"><tr><td><a href="#" onClick="closeStreetView()"><img src="images/close_icon.gif" border="0"></a><br><br></td></tr>' +
'<tr><td align="center"><OBJECT CLASSID="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" WIDTH="440" HEIGHT="320" CODEBASE="http://www.apple.com/qtactivex/qtplugin.cab">' +
'<param name="controller" value="true">' + 
'<param name="src" value="http://www.redata.com/100005/61/vr/' + str + 'px.mov">' +
'<EMBED SRC="http://www.redata.com/100005/61/vr/' + str + 'px.mov" width="440" height="320" controller="true" ALIGN="BOTTOM" PLUGINSPACE="http://www.apple.com/quicktime/download">' +
'</OBJECT></td></tr><tr><td><img src="images/pixel.gif" height="100"></td></tr></table>';

}

function closeStreetView() {
	var sv = document.getElementById('streetview');
	sv.innerHTML = '';
	sv.visibility = 'hidden';
	sv.style.width = '0px';
	sv.style.height = '0px';

}

function postSaveSearch()
{

        if (okToSend) {
                http = getHTTPObject();

                if ((http != null) ) {
                        okToSend = false;
                        var dat = getSaveData();

                        http.open("POST", save_url, true);
                        http.onreadystatechange = saveResponse;
                        http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                        showLayer('loading');
                        http.send(dat);
                        hideLayer('loading');
                }
        }

        okToSend = true;
}

function saveResponse() {

        if (http.readyState == 4) {
                if (http.status == 200) {
                        isWorking = false;

                        var result = http.responseText;
                        var xmlDoc = getXMLDoc();

                        var retVal = xmlDoc.getElementsByTagName("RESPONSE").item(0).getAttribute("returnCode");

                        var ss = getElmById("saveSearch");
                        if (retVal == 'true') {
                                ss.innerHTML = '<font color="red">Search Successfully Saved</font>';
                        } else {
                                ss.innerHTML = '<font color="red">There was a problem saving your search</font>';
                        }
                }
        }
}

function getSaveData()
{
        var dat = 'SITE=' + site + '&cd_Contact=' + cookieid + '&sql=';

        var sql = "SELECT Listing.cd_MLS FROM ListingPublic,Listing WHERE ListingPublic.cd_MLS = Listing.cd_MLS " + buildWhere()  + ' AND lp_res_Lat > ' + miny + ' AND lp_res_Lat < ' + maxy + ' AND lp_res_Long > ' + minx + ' AND lp_res_Long < ' + maxx;

        dat += sql + '&criteria=' + buildCriteria() + '&fg_1=Y';

        return dat;    
}

function buildWhere()
{

        var lp_low = document.getElementById('lp_low').value;
        var lp_high = document.getElementById('lp_high').value;
        var beds_low = document.getElementById('beds_low').value;
        var baths_low = document.getElementById('baths_low').value;
        var p_type = document.getElementById('p_type').value;

        var w = ' AND lp_Listing_Price >= ' + lp_low + ' AND lp_Listing_Price <= ' + lp_high + ' AND lp_No_Bedrooms >= ' + beds_low + '  AND lp_No_Bathrooms >= ' + baths_low;

        if (p_type.length > 0) {
                w += " AND lp_tp_Improvement = '" + escape(p_type) + "'";
        }


        if (document.getElementById('wf').checked) {
                w += " AND lp_fg_WaterAccess = 'Y'";
        }

        if (document.getElementById('oh').checked) {
                w += " AND lp_ind_OpenHouse = 'Y'";
        }

        if (document.getElementById('jl').checked) {
                w += " AND lp_Listing_Date > DATE_ADD(NOW(), INTERVAL -14 DAY)";
        }

        return w;
}

function buildCriteria()
{
        var lp_low = document.getElementById('lp_low').value;
        var lp_high = document.getElementById('lp_high').value;
        var beds_low = document.getElementById('beds_low').value;
        var baths_low = document.getElementById('baths_low').value;
        var p_type = document.getElementById('p_type').value;

        var c = "Latitude greater than " + miny + " Latitude less than " + maxy + "<br>";

        c += "AND Longitude greater than " + minx + " Longitude less than " + maxx + "<br>";

        if (lp_low.length > 0) {
                c += "Listing Price greater than " + lp_low + "<BR>";
        }

        if (lp_high.length > 0) {
                c += "Listing Price less than " + lp_high + "<BR>";
        }

        if (beds_low.length > 0) {
                c += "Bedrooms greater than " + beds_low + "<BR>";
        }

        if (baths_low.length > 0) {
                c += "Bathrooms greater than " + baths_low + "<BR>";
        }

        if (p_type.length > 0) {
		if (p_type == '3') {
                	c += "Property Type equals Single Family<BR>";
		} else if (p_type == '1') {
                	c += "Property Type equals Condominiums<BR>";
		} else if (p_type == '14') {
                	c += "Property Type equals Commercial<BR>";
		} else if (p_type == '2') {
                	c += "Property Type equals Sites or Lots<BR>";
		} else if (p_type == '7') {
                	c += "Property Type equals Farms and Farmettes<BR>";
		} else if (p_type == '8') {
                	c += "Property Type equals Multi Family<BR>";
		}	
        }

        if (document.getElementById('wf').checked) {
                c += "Water frontage/access equals true<BR>";
        }
	
	if (document.getElementById('jl').checked) {
		c += "Just listed equals true<br>";
	}

	if (document.getElementById('oh').checked) {
		c += "Open House equals true<br>";
	}

        return c;
}

function createSaveLink()
{
        var link = "";

        if (cookieid.length > 0)
        {
                link = '<a href="javascript:postSaveSearch()">Save This Search</a>';
        }
        else
        {
                link = '<a href="' + root_url + '/vp/LoginServlet2?ScreenID=VOW_LOGIN&SITE=' + site + '&DFLT_PAGE=VOW_HOME&next_url=/vp/jsps/' + site + '/MAPSEARCH_PROXY.jsp?' + createQueryString() + '" target="_parent">Login To Save Searches</a>';
        }

        return link;

}


