function setupSearchFields(thetype,thelocation,theprice) {
	theform=document.forms[0];

	if (1)	{
		clearMarkers();
		searchProperties(theform,thetype,thelocation,theprice);
	} else {
		if (thetype != '')	{
	//				alert(thetype);
			selectLocation(theform,thetype,thelocation,theprice);
			if(thelocation != '') {
	//				alert(thetype+' '+thelocation);
				selectPriceRange(theform,thetype,thelocation,theprice);
				if(theprice != '') {
	//				alert(thetype+' '+thelocation+' '+theprice);
					searchProperties(theform,thetype,thelocation,theprice);
				}
			}
		}
	}
}
 
 function selectPriceRange(theform,thetype,thelocation,theprice) {
	clearMarkers();
	var refresh=document.getElementById("refreshbutton");refresh.disabled=true;
	var item_span=document.getElementById("propertyprice");
	var item3_span=document.getElementById("propertylist");
	item3_span.innerHTML='';
	item_span.innerHTML='<select name=property_price><option></option></select>';
	var p = '';
	var c = '';
	var v = '';
	if (typeof theform.property_type  !== "undefined") {
		p = theform.property_type.options[theform.property_type.selectedIndex].value;
	}
	if (typeof theform.property_location  !== "undefined") {
		c = theform.property_location.options[theform.property_location.selectedIndex].value;
	}
	if (thetype != '' &&   typeof thetype  !== "undefined") p = thetype;
	if (thelocation != '' &&   typeof thelocation  !== "undefined") c = thelocation;
	if (theprice != '' &&   typeof theprice  !== "undefined") v = theprice;
	if (p != '' && c != '') {
//		alert(p+' '+c);
		item_span.innerHTML = "Loading...";
		if (window.XMLHttpRequest) { 
		http_request = new XMLHttpRequest();
		} else if (window.ActiveXObject) { 
		http_request = new ActiveXObject("Microsoft.XMLHTTP");
		}
		http_request.onreadystatechange = function(){
		if (http_request.readyState == 4) {
			if(http_request.status == 200) {
				item_span.innerHTML = http_request.responseText;
			}else{
				item_span.innerHTML = "There was an error getting price data, please try again!";	
			}
			    // everything is good, the response is received
			} else {
			    // still not ready
			}
		};
//		alert('./results.cfm?p='+p+'&c='+c);
		http_request.open('GET', './results.cfm?p='+p+'&c='+c+'&v='+v, true);

		http_request.send(null);
	} else {
		item_span.innerHTML = "<select name=property_price><option></option></select>";
	}
}
function selectLocation(theform,thetype,thelocation,theprice) {
	clearMarkers();
	var refresh=document.getElementById("refreshbutton");refresh.disabled=true;
	var item_span=document.getElementById("propertylocation");
	var item2_span=document.getElementById("propertyprice");
	var item3_span=document.getElementById("propertylist");
	var v='';
	var p= ''
	item2_span.innerHTML='';
	item3_span.innerHTML='';
	if (typeof theform.property_type  !== "undefined") {
		p = theform.property_type.options[theform.property_type.selectedIndex].value;
	}	
	if (thetype != '' &&   typeof thetype  !== "undefined") p = thetype;
	if (thelocation != '' &&   typeof thelocation  !== "undefined") v = thelocation;
	if (p != '') {
//		alert(p);
		item_span.innerHTML = "Loading...";
		if (window.XMLHttpRequest) { 
		http_request = new XMLHttpRequest();
		} else if (window.ActiveXObject) { 
		http_request = new ActiveXObject("Microsoft.XMLHTTP");
		}
		http_request.onreadystatechange = function(){
		if (http_request.readyState == 4) {
			if(http_request.status == 200) {
				item_span.innerHTML = http_request.responseText;
			}else{
				item_span.innerHTML = "There was an error getting location data, please try again!";	
			}
			    // everything is good, the response is received
			} else {
			    // still not ready
			}
		};
//	alert('./results.cfm?p='+p);
		http_request.open('GET', './results.cfm?p='+p+'&v='+v, true);

		http_request.send(null);
	} else {
		item_span.innerHTML = "<select name=property_location><option></option></select>";
	}
}

function searchProperties(theform,thetype,thelocation,theprice) {
	clearMarkers();
	var item_span=document.getElementById("refreshbutton");
	item_span.disabled=false;

	var item_span=document.getElementById("propertylist");
	var p = '';
	var l = '';
	var c = '';
	if (typeof theform.property_price  !== "undefined") {
		l = theform.property_price.options[theform.property_price.selectedIndex].value
	}	
	if (typeof theform.property_type  !== "undefined") {
		p = theform.property_type.options[theform.property_type.selectedIndex].value;
	}	
	if (typeof theform.property_location  !== "undefined") {
		c = theform.property_location.options[theform.property_location.selectedIndex].value;
	}
	if (thetype != '' &&   typeof thetype  !== "undefined") p = thetype;
	if (thelocation != '' &&   typeof thelocation  !== "undefined") c = thelocation;
	if (theprice != '' &&   typeof theprice  !== "undefined") l = theprice;
	if (p != '' && l != ''  && c != '') {
//		alert(p+' '+c+' '+l);
		item_span.innerHTML = "Loading...";
		if (window.XMLHttpRequest) { 
		http_request = new XMLHttpRequest();
		} else if (window.ActiveXObject) { 
		http_request = new ActiveXObject("Microsoft.XMLHTTP");
		}
		http_request.onreadystatechange = function(){
		if (http_request.readyState == 4) {
			if(http_request.status == 200) {
				item_span.innerHTML = "";
				var the_result=http_request.responseText;
				var col_array=the_result.split("^");
				var part_num=0;


				while (part_num < col_array.length) {
//					alert(col_array[part_num].substring(0,4));
					if (col_array[part_num].substring(0,4) == 'TOT:') {
						item_span.innerHTML = "<table border=0 width=100%><tr><td colspan=2><b>"+col_array[part_num].substring(4)+"</b><br></td></tr>";
					} else if (col_array[part_num].substring(0,4) != 'LOC:') {
						item_span.innerHTML += col_array[part_num];
					} else {
						var col_array2=col_array[part_num].split("|");
						var part_num2=0;
						var i=0;
						var lat=0;
						var lng=0;
						var note="";
						var address="";
						var city="";
						var img="";
						var thedetails="";
						var office="";
						var mlsnumber="";
				var iconid=0;
				var iconimg="";
				while (part_num2 < col_array2.length) {
							var the_string=col_array2[part_num2].replace(/^\s*|\s*$/g,'');
//							alert(the_string);
							if (the_string.substring(0,4) == 'IMG:') {
//								item_span.innerHTML += '<tr><td><img src='+the_string.substring(4)+' width=100></td><td style="font-size:11pt;">';
								img=the_string.substring(4);
							} else if (the_string.substring(0,4) == 'NOT:') {
								note=the_string.substring(4);
							} else if (the_string.substring(0,4) == 'ADR:') {
								address=the_string.substring(4);
							} else if (the_string.substring(0,4) == 'OFF:') {
								office=the_string.substring(4);
							} else if (the_string.substring(0,4) == 'ICN:') {
								iconid=the_string.substring(4);
								if (iconid == 0) iconimg = "mm_20_red.png";
								if (iconid == 1) iconimg = "mm_20_blue.png";
								if (iconid == 2) iconimg = "mm_20_orange.png";
							} else if (the_string.substring(0,4) == 'CTY:') {
								city=the_string.substring(4);
//								item_span.innerHTML +=city+"<br>";
								thedetails+=city+"<br>";
							} else if (the_string.substring(0,4) == 'MLS:') {
								mlsnumber=the_string.substring(4);
								mlsnumber=mlsnumber.replace(/^\s*|\s*$/g,'');
//								item_span.innerHTML +=the_string+"<br>";
								thedetails+=the_string+"<br>";
							} else if (the_string.substring(0,4) == 'LOC:') {
								var col_array3=the_string.substring(4).split(",");
//								alert(the_string.substring(4));
								i=col_array3[0];
								lat=col_array3[1];
								lng=col_array3[2];
//								item_span.innerHTML +="</td></tr>";
							} else {
//								item_span.innerHTML +=the_string+"<br>";
								thedetails+=the_string+"<br>";
							}
							part_num2+=1;
						}	
						if (lat != 0 && lng !=0 && i != 0) {
								layout='<table border=0><tr><td colspan=2 style=font-weight:bold;>'+address+' - '+city+'<hr></td></tr><tr><td valign=top align=left width=150><img src='+img+' width=150></td><td valign=top align=left style=font-size:9pt;>';
								layout += thedetails+'<a href=detail.cfm?MLS='+mlsnumber+' style=font-size:9pt;>More Information</a></td></tr>';
								layout += '<tr><td colspan=2 style=font-size:8pt;>'+office+'</td></tr></table>';
								createLocation(lat,lng,i,layout,iconimg);
						}
						if (i!=0) {
							var letter = String.fromCharCode("A".charCodeAt(0) + parseInt(i)-1);
							theimage = "<img src=http://www.google.com/mapfiles/marker" + letter + ".png>";
							theimage = "<img src=http://labs.google.com/ridefinder/images/"+iconimg+">";
							item_span.innerHTML +='<table border=0 id=theitem'+i+'><tr><td align=left valign=top width=12>'+theimage+'</td><td valign=top align=left width=100><a name=loc'+i+' onclick=\'showMarker('+i+');\'><img src='+img+' width=100 border=2></a></td><td valign=top align=left style=font-size:9pt;>'+thedetails+'</td></tr></table>';
						} else {
							theimage =" ";
							item_span.innerHTML +='<table border=0><tr><td align=left valign=top width=12>'+theimage+'</td><td valign=top align=left width=100><a href=detail.cfm?MLS='+mlsnumber+' ><img src='+img+' width=100 border=1></a></td><td valign=top align=left style=font-size:9pt;>'+thedetails+'</td></tr></table>';
						}
					}
					part_num+=1;
				}			
				item_span.innerHTML += "</table>";
			}else{
				item_span.innerHTML = "There was an error getting location data, please try again!";	
			}
			    // everything is good, the response is received
			} else {
			    // still not ready
			}
		};

//		alert('./results.cfm?p='+p+'&l='+l+'&c='+c);

		http_request.open('GET', './results.cfm?p='+p+'&l='+l+'&c='+c, true);

		http_request.send(null);
	} else {
		item_span.innerHTML = "No Data";
	}
}


