// JavaScript Document

	var num_requested = 0;
	var num_returned = 0;
	var num_total = 0;
	var zoomed = 0; // set by zoomend, used to not load on zoom
	var zoomSizeChangeLevel = 13;
	var pic_src = "";
	var descrip = "";
	var num_pics = 0;
	var cur_pic = 0;
	var cur_id = 0;
//	array of properties added by onmoveend()
	var props = new Array();
	var load_dyn;
//	are we caching?
	var caching;
//	cached props in order of added
	var prop_cache = new Array();
//	MlsNum is index, value stored is index into prop_cache
	var prop_cache_indices = new Array();
//	selected row in table
	var highlighted_row = -1;
//	MlsNum of currently selected property (clicked in list, centered on map, green pushpin)
	var cur_sel_prop = 0;
//	MlsNum of last selected property
	var last_sel_prop = 0;
//	MlsNum of currently "popped up" prop on map (i.e. mouseover this prop)
	var cur_hover_prop = 0;
//	display_table definition array
	var display_table_def = new Array();

	function preloadImages() {
		if (document.images) {
			close_gif = newImage("http://"+host+"/images/close.gif");
			close_hover_gif = newImage("http://"+host+"/images/close-hover.gif");
		}
	}
	preloadImages();
	
	function newImage(arg) {
		if (document.images) {
			rslt = new Image();
			rslt.src = arg;
			return rslt;
		}
	}

	function fetch_pic(dir){
		document.images["ft_pic"].src = "http://"+host+"/images/loading.gif";
		
		var xmlhttp = create_xmlhttp();
		document.getElementById("working").innerHTML = "<img src=\"http://"+host+"/images/waiting-16.gif\" width=\"16\" height=\"16\" />";
		serverPage = "http://"+host+"/processors/get-pic.asp?id="+cur_id+"&cur_pic="+cur_pic;
	//	document.getElementById("debugging").innerHTML = (vars[0][1]+0) ? serverPage+"\n<br />"+document.getElementById("debugging").innerHTML : "";
		xmlhttp.open("GET", serverPage, true); // asynch param set to false for synch requests, true for asynch
				
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				eval(xmlhttp.responseText);
				document.images["ft_pic"].src = pic_src;
				document.getElementById("working").innerHTML = "<img src=\"http://"+host+"/images/pix.gif\" width=\"16\" height=\"16\" />";
			}
		}
		
		xmlhttp.send(null);
	}

	function do_scroll(dir){
		var mPic = document.images["ft_pic"];
		cur_pic = ((cur_pic + dir) > num_pics) ? 1 : (cur_pic + dir);
		cur_pic = (cur_pic < 1) ? num_pics : cur_pic;
		mPic.onerror = function() {fetch_pic(dir)};
		mPic.src = get_feat_pic_name(cur_id, cur_pic);
		document.getElementById("pic_number").innerHTML = cur_pic + " of " + num_pics;
	}

	function do_left_scroll(){
		do_scroll(-1)
	}
	
	function do_right_scroll(){
		do_scroll(1)
	}
	
	function reset_form(){
		clear_properties();
		var fm = document.map_search_form;
		var num_els = vars.length;
		var eltype = "";
		for (i=0; i<num_els; i++){
		//	if form element exists
			if (eval("fm."+vars[i][0])) {
				eltype = eval("fm."+vars[i][0]+".type");
				if (eltype == "checkbox") {
					eval("fm."+vars[i][0]+".checked = "+vars[i][2]+";");
				} else if (eltype == "select-one") {
					eval("fm."+vars[i][0]+".selectedIndex = set_select_by_value(fm."+vars[i][0]+", '"+vars[i][2]+"', 0);");
				} else {
					eval("fm."+vars[i][0]+".value = "+vars[i][2]+";");
				}
		   }
		}
		do_load_dyn_cb();
	}

	function reset_map(){
		var num_vars = vars.length;
		num_vars -= 5; // skip the last five vars, we don't want them
		for(i=0; i<num_vars; i++){
			DeleteCookie(vars[i][0]);
		}
		reset_form();
		map.setCenter(defaultCenterPoint, default_zoom, G_NORMAL_MAP);		
	}
	
//	give a div an id then pass it in here
	function changeElementText(id, newText) {
		alert(id);
		element = document.getElementById(id);
		element.innerHTML = newText;
	}

	function get_feat_pic_name(mlsnum, num){
		var imgsrc = "http://"+host+"/pics/"+mlsnum+"/"+mlsnum+"_"+num+"_featured.jpg"
		return imgsrc;
	}

//	store type, MlsNum, marker, picture name
//	prop_cache[cache_index] = new Array(props[i][0], props[i][1], rs[cnt], props[i][7], ...);
	function get_picture_name(mlsnum){
		var imgsrc = "http://"+host+"/pics/"+mlsnum+"/"+mlsnum+"_1_small.jpg"
		return imgsrc;
	}
	
	function set_prop_label(mlsnum){
	//	make target property easier to handle
		var tProp = prop_cache[prop_cache_indices[mlsnum]];
		//	address
		var txt = "$"+add_commas(numeric_chars_only(tProp[4]));
		txt += (txt.length) ? ", " : "";

		txt += tProp[5];
		txt += (txt.length) ? ", " : "";
		//	price
		var temp = "";
		switch (tProp[0]) {
			case 'Single Family House':
			case 'Condominium':
			case 'Duplex':
			case 'Half Duplex':
			case 'Townhouse':
			case 'Flat':
			case 'Mobile Home':
				temp += ((temp.length) && (tProp[6].length)) ? "/" : "";
				temp += (tProp[6].length) ? tProp[6] : "";
				temp += (tProp[7].length) ? "/"+tProp[7] : "";
				temp += (tProp[8].length) ? "/"+tProp[8] : "";
				break;
			case 'Residential Lot':
			case 'Commercial Lot':
			case 'Farm':
				temp += ((temp.length) && (tProp[9].length)) ? "/" : "";
				temp += (tProp[9].length) ? tProp[9] : "";
				break;
			case 'Commercial Building':
			case 'Business':
			case 'Multi-Unit':
				break;
		}
		
		
		txt += temp;
		document.getElementById("pano_label").innerHTML = txt;
	//	document.getElementById("pano_label").innerHTML = "<span style=\"font-family: Arial, Helvetica, sans-serif; font-weight:bold; font-size:10px;\">"+txt+"</span>";
	}
	
	function get_popup_text(mlsnum){
	//	make target property easier to handle
		var tProp = prop_cache[prop_cache_indices[mlsnum]];
		//	address
		var txt = tProp[5];
		txt += (txt.length) ? "\n<br />" : "";
		//	price
		var price = "$"+add_commas(numeric_chars_only(tProp[4]));
		var temp = "";
		switch (tProp[0]) {
			case 'Single Family House':
			case 'Condominium':
			case 'Duplex':
			case 'Half Duplex':
			case 'Townhouse':
			case 'Flat':
			case 'Mobile Home':
				temp += ((temp.length) && (tProp[6].length)) ? "/" : "";
				temp += (tProp[6].length) ? tProp[6] : "";
				temp += (tProp[7].length) ? "/"+tProp[7] : "";
				temp += (tProp[8].length) ? "/"+tProp[8] : "";
				break;
			case 'Residential Lot':
			case 'Commercial Lot':
			case 'Farm':
				temp += ((temp.length) && (tProp[9].length)) ? "/" : "";
				temp += (tProp[9].length) ? tProp[9] : "";
				break;
			case 'Commercial Building':
			case 'Business':
			case 'Multi-Unit':
				break;
		}
		
		if (price.length){
			temp = (temp.length) ? price + ", " + temp : price;
		}
		
		txt += temp;
		return txt;
	}

	function open_pseudo_window(mlsnum){
		var el = document.getElementById("pano_container");
		var map_obj = document.getElementById("map_canvas");
		
		var map_left = map_obj.offsetLeft;
		if (map_obj.offsetParent.offsetLeft){
			map_left = map_obj.offsetParent.offsetLeft;
		}
		
		var tmp = findPos(map_obj);
		var map_top = tmp[1];		


		var map_width = map_obj.offsetWidth;
		var map_height = map_obj.offsetHeight;
		var load_width = el.offsetWidth;
		var load_height = el.offsetHeight;
		
		
		var load_left = (map_left + parseInt((map_width - load_width)/2))+"px";
		var load_top = (map_top + parseInt((map_height - load_height)/2))+"px";
		
		el.style.left = load_left;
		el.style.top = load_top;
		
		el.style.visibility = "visible";
		document.getElementById("pano").style.visibility = "visible";
		document.getElementById("pano_label").style.visibility = 'visible';
		document.getElementById("close_box").style.visibility = 'visible';
		
	}

	function open_pano_window(mlsnum){
	//	prop_cache[prop_cache_indices[mlsnum]][2].openInfoWindowHtml("<div name=\"pano\" id=\"pano\" style=\"width: 500px; height: 300px;\"></div>");
/*		var el = document.getElementById("pano_container");
		var map_obj = document.getElementById("map_canvas");
		
		var map_left = map_obj.offsetLeft;
		if (map_obj.offsetParent.offsetLeft){
			map_left = map_obj.offsetParent.offsetLeft;
		}
		
		var tmp = findPos(map_obj);
		var map_top = tmp[1];		


		var map_width = map_obj.offsetWidth;
		var map_height = map_obj.offsetHeight;
		var load_width = el.offsetWidth;
		var load_height = el.offsetHeight;
		
		
		var load_left = (map_left + parseInt((map_width - load_width)/2))+"px";
		var load_top = (map_top + parseInt((map_height - load_height)/2))+"px";
		
		el.style.left = load_left;
		el.style.top = load_top;
		
		el.style.visibility = "visible";
		document.getElementById("pano").style.visibility = "visible";
		document.getElementById("pano_label").style.visibility = 'visible';
		document.getElementById("close_box").style.visibility = 'visible';*/
		
		open_pseudo_window(mlsnum);
		
		set_prop_label(mlsnum);
		
		window.setTimeout("init_pano("+mlsnum+")", 1000);
	}

	function do_marker_click(mlsnum){
		
		open_pseudo_window(mlsnum);
		set_prop_label(mlsnum);
		
		load_prop(mlsnum);
		
/*		var fm = document.map_search_form;
		if (fm.streetview_button.value == "turn street view on"){
		//	streetview is off, do something else
		} else {
		//	streetview is on
			
			window.setTimeout("open_pano_window("+mlsnum+")", 1000);
		
		}*/
		
	}
	
	var num_displayed = 0;
    
	function close_info_window(){
		map.closeInfoWindow();
	}
	
	function close_pano(){
		document.getElementById("pano").style.visibility = 'hidden';
		document.getElementById("pano_label").style.visibility = 'hidden';
		document.getElementById("close_box").style.visibility = 'hidden';
		document.getElementById("pano_container").style.visibility = 'hidden';
	//	document.getElementById("feat_pic").innerHTML = "<img id=\"ft_pic\" src=\"http://"+host+"/images/loading.gif\" height=\"240\" width=\"320\" />";
	//	document.getElementById("ft_pic").src = "http://"+host+"/images/loading.gif";
		document.images["ft_pic"].src = "http://"+host+"/images/loading.gif";
		
		document.getElementById("narrative").innerHTML = "";
		cur_pic = 0;
	}
	
	function load_alt_image() {
		document["popupimg_"+popup[cur_pop][0]].width = "100";
		document["popupimg_"+popup[cur_pop][0]].height = "75";
		document["popupimg_"+popup[cur_pop][0]].src = "http://"+host+"/images/no_pic.gif";
	}
	
	var cur_pop = 0;
	var popup = new Array(
						  new Array("ll", 4, -132),
						  new Array("lr", -152, -120),
						  new Array("ul", 4, 4),
						  new Array("ur", -152, 4));
	
	function findPos(obj) {
		var curleft = curtop = 0;
		if (obj.offsetParent) {
			do {
				curleft += obj.offsetLeft;
				curtop += obj.offsetTop;
			} while (obj = obj.offsetParent);
		}
		return [curleft,curtop];
	}


	function select_popup(){
		var map_obj = document.getElementById("map_canvas");

		var map_left = map_obj.offsetLeft;
		if (map_obj.offsetParent.offsetLeft){
			map_left = map_obj.offsetParent.offsetLeft;
		}
/*		var map_top = map_obj.offsetTop;
		if (map_obj.offsetParent.offsetTop){
			map_top = map_obj.offsetParent.offsetTop;
		}*/
		
		var tmp = findPos(map_obj);
		var map_top = tmp[1];
		
		var right = map_left + map_obj.offsetWidth;
		var bottom = map_top + map_obj.offsetHeight;
		
		var vert = "l";
		var horz = "l";
			
		if (xMousePos+146 > right) {
			horz = "r";
		} else if (xMousePos-146 < map_left) {
			horz = "l";
		}
		
		if (yMousePos-132 < map_top){
			vert = "u";
		} else if (yMousePos+132 > bottom){
			vert = "l";
		}
		
		var sel_pop = 0;
		switch (vert+horz){
			case "ll":
				sel_pop = 0;
				break;
			case "lr":
				sel_pop = 1;
				break;
			case "ul":
				sel_pop = 2;
				break;
			case "ur":
				sel_pop = 3;
				break;
			default:
				sel_pop = 0;
		}
		return sel_pop;
	}
	
	
	
	function get_icon(size, type, status){
		var stat_word = "";
		if (status == 1) {
			stat_word = "_ao";
		} else if (status == 2) {
			stat_word = "_sold";
		}
		return eval(type+stat_word+size+"_icon");
	}

	function get_GMarkerS(type, status, size){
		var icon = null;
	//	var size = (map.getZoom() > zoomSizeChangeLevel) ? "_med" : "_small";
		switch(type){
			case 'Single Family House':
				icon = get_icon(size, "house", status);
				break;
			case 'Flat':
			case 'Condominium':
			case 'Townhouse':
				icon = get_icon(size, "condo", status);
				break;
			case 'Duplex':
				icon = get_icon(size, "duplex", status);
				break;
			case 'Half Duplex':
				icon = get_icon(size, "half_duplex", status);
				break;
			case 'Multi-Unit':
				icon = get_icon(size, "multi_unit", status);
				break;
			case 'Mobile Home':
				icon = get_icon(size, "mobile_home", status);
				break;
			case 'Residential Lot':
			case 'Commercial Lot':
				icon = get_icon(size, "lot", status);
				break;
			case 'Farm':
				icon = get_icon(size, "farm", status);
				break;
			case 'Commercial Building':
			case 'Business':
				icon = get_icon(size, "business", status);
				break;
			default:
				icon = get_icon(size, "house", status);
				break;
		}
		
		return icon;
	}

	function get_GMarker_small(type, status){
		return get_GMarkerS(type, status, "_small");
	}
	
	function get_GMarker_big(type, status){
		return get_GMarkerS(type, status, "_med");
	}
	
	function get_GMarker(type, status){
		var icon = null;
		var size = (map.getZoom() > zoomSizeChangeLevel) ? "_med" : "_small";
		switch(type){
			case 'Single Family House':
				icon = get_icon(size, "house", status);
				break;
			case 'Flat':
			case 'Condominium':
			case 'Townhouse':
				icon = get_icon(size, "condo", status);
				break;
			case 'Duplex':
				icon = get_icon(size, "duplex", status);
				break;
			case 'Half Duplex':
				icon = get_icon(size, "half_duplex", status);
				break;
			case 'Multi-Unit':
				icon = get_icon(size, "multi_unit", status);
				break;
			case 'Mobile Home':
				icon = get_icon(size, "mobile_home", status);
				break;
			case 'Residential Lot':
			case 'Commercial Lot':
				icon = get_icon(size, "lot", status);
				break;
			case 'Farm':
				icon = get_icon(size, "farm", status);
				break;
			case 'Commercial Building':
			case 'Business':
				icon = get_icon(size, "business", status);
				break;
			default:
				icon = get_icon(size, "house", status);
				break;
		}
		
		return icon;
	}

	function get_icon(size, type, status){
		var stat_word = "";
		if (status == 1) {
			stat_word = "_ao";
		} else if (status == 2) {
			stat_word = "_sold";
		}
		return eval(type+stat_word+size+"_icon");
	}

	function fetch_image(type, status){
		var img = "";
		var size = (map.getZoom() > zoomSizeChangeLevel) ? "_med" : "_small";
		var stat_word = "";
		if (status == 1) {
			stat_word = "-ao";
		} else if (status == 2) {
			stat_word = "-sold";
		}
		switch(type){
			case 'Single Family House':
				img = "images/real-estate-map/icons"+size+"/house"+stat_word+".gif";
				break;
			case 'Flat':
			case 'Condominium':
			case 'Townhouse':
				img = "images/real-estate-map/icons"+size+"/condo"+stat_word+".gif";
				break;
			case 'Duplex':
				img = "images/real-estate-map/icons"+size+"/duplex"+stat_word+".gif";
				break;
			case 'Half Duplex':
				img = "images/real-estate-map/icons"+size+"/half-duplex"+stat_word+".gif";
				break;
			case 'Multi-Unit':
				img = "images/real-estate-map/icons"+size+"/multi-unit"+stat_word+".gif";
				break;
			case 'Mobile Home':
				img = "images/real-estate-map/icons"+size+"/mobile-home"+stat_word+".gif";
				break;
			case 'Residential Lot':
			case 'Commercial Lot':
				img = "images/real-estate-map/icons"+size+"/lot"+stat_word+".gif";
				break;
			case 'Farm':
				img = "images/real-estate-map/icons"+size+"/farm"+stat_word+".gif";
				break;
			case 'Commercial Building':
			case 'Business':
				img = "images/real-estate-map/icons"+size+"/business"+stat_word+".gif";
				break;
			default:
				img = "images/real-estate-map/icons"+size+"/house"+stat_word+".gif";
				break;
		}
		
		return img;
	}
	
	function fetch_highlight_image(type){
		var img = "";
		var size = (map.getZoom() > zoomSizeChangeLevel) ? "_med" : "_small";
		switch(type){
			case 'Single Family House':
				img = "images/real-estate-map/icons"+size+"/house-highlight.gif";
				break;
			case 'Flat':
			case 'Condominium':
			case 'Townhouse':
				img = "images/real-estate-map/icons"+size+"/condo-highlight.gif";
				break;
			case 'Duplex':
				img = "images/real-estate-map/icons"+size+"/duplex-highlight.gif";
				break;
			case 'Half Duplex':
				img = "images/real-estate-map/icons"+size+"/half-duplex-highlight.gif";
				break;
			case 'Multi-Unit':
				img = "images/real-estate-map/icons"+size+"/multi-unit-highlight.gif";
				break;
			case 'Mobile Home':
				img = "images/real-estate-map/icons"+size+"/mobile-home-highlight.gif";
				break;
			case 'Residential Lot':
			case 'Commercial Lot':
				img = "images/real-estate-map/icons"+size+"/lot-highlight.gif";
				break;
			case 'Farm':
				img = "images/real-estate-map/icons"+size+"/farm-highlight.gif";
				break;
			case 'Commercial Building':
			case 'Business':
				img = "images/real-estate-map/icons"+size+"/business-highlight.gif";
				break;
		}
		return img;
	}

	function fix_image_size(isrc) {
		var oImg = new Image();
		oImg.src = isrc;
		if (oImg.complete) {
		//	scale image to fit popup
			if ((oImg.width <= 100) &&  (oImg.height <= 75)){
				document["popupimg_"+popup[cur_pop][0]].width = oImg.width;
				document["popupimg_"+popup[cur_pop][0]].height = oImg.height;
			} else {
				if (oImg.width > 100){
					document["popupimg_"+popup[cur_pop][0]].width = 100;
					document["popupimg_"+popup[cur_pop][0]].height = (75*oImg.height)/100;
				}
				if (oImg.height > 75){
					document["popupimg_"+popup[cur_pop][0]].height = 75;
					document["popupimg_"+popup[cur_pop][0]].width = (100*oImg.width)/75;
				}
			}
			
		}
		else {
			window.setTimeout('fix_image_size(document["popupimg_"+popup[cur_pop][0]].src)', 50);
		}
	}
	
	function toggle_more(){
		var mb_el = document.getElementById("more_button");
		var cb_el = document.getElementById("checkbox_atts");
		if (mb_el.value == "more..."){
			cb_el.style.display = "block";
			cb_el.style.width = "360px";
			mb_el.value = "less...";
		} else if (mb_el.value == "less..."){
			cb_el.style.display = "none";
			cb_el.style.width = "0px";
			mb_el.value = "more...";
		}
	}

	function add_props(){
		if (props.length){
		//	create an array to hold all the new points
			var prop_cache_new = new Array();
			var prop_cache_new_indices = new Array();
			var cache_index_new = 0;
			var mrkrs = new Array();
			var mrkrs_big = new Array();
			var num_new = props.length;
			var cnt = 0;
			var zoom_level = map.getZoom();
			for (i=0; i < num_new; i++){
			//	add prop if it's not already in cache
				if (prop_cache_indices[props[i][0]] == undefined){
					var mPt = new GLatLng(props[i][1], props[i][2]);
				//	mrkrs[cnt] = new GMarker(mPt, get_GMarker(props[i][12], props[i][6]));
					mrkrs[cnt] = new GMarker(mPt, get_GMarker_small(props[i][12], props[i][6])); // zoom 13 and below (zoom out lower level)
					mrkrs[cnt].id = props[i][0];
				//	mrkrs[cnt].size = (zoom_level > zoomSizeChangeLevel) ? "med" : "small";
					mrkrs_big[cnt] = new GMarker(mPt, get_GMarker_big(props[i][12], props[i][6])); // zoom 14 and above (zoom in higher level)
					mrkrs_big[cnt].id = props[i][0];
					
					GEvent.addListener(mrkrs[cnt], 'click', function() {
						do_marker_click(this.id);
					});
					
					GEvent.addListener(mrkrs_big[cnt], 'click', function() {
						do_marker_click(this.id);
					});
					
					GEvent.addListener(mrkrs[cnt], 'mouseover', function() {
						cur_hover_prop = this.id;
						cur_pop = select_popup();
						document["popupimg_"+popup[cur_pop][0]].onerror = function() {load_alt_image()};
						document["popupimg_"+popup[cur_pop][0]].src = get_picture_name(this.id);
						
						fix_image_size(document["popupimg_"+popup[cur_pop][0]].src);
												
						var text_el = document.getElementById("popuptxt_"+popup[cur_pop][0]);
						text_el.innerHTML = get_popup_text(this.id);
						text_el.style.width="100px";
						text_el.style.height="21px";
						text_el.style.overflow="hidden";
	
						var el = document.getElementById("prop_tag_"+popup[cur_pop][0]);
						el.style.visibility = 'visible';
						el.style.left = xMousePos+popup[cur_pop][1]+"px";
						el.style.top = yMousePos+popup[cur_pop][2]+"px";

						prop_cache[prop_cache_indices[this.id]][2].setImage(fetch_highlight_image(prop_cache[prop_cache_indices[this.id]][0]));
					});
					
					GEvent.addListener(mrkrs_big[cnt], 'mouseover', function() {
						cur_hover_prop = this.id;
						cur_pop = select_popup();
						document["popupimg_"+popup[cur_pop][0]].onerror = function() {load_alt_image()};
						document["popupimg_"+popup[cur_pop][0]].src = get_picture_name(this.id);
						
						fix_image_size(document["popupimg_"+popup[cur_pop][0]].src);
												
						var text_el = document.getElementById("popuptxt_"+popup[cur_pop][0]);
						text_el.innerHTML = get_popup_text(this.id);
						text_el.style.width="100px";
						text_el.style.height="21px";
						text_el.style.overflow="hidden";
	
						var el = document.getElementById("prop_tag_"+popup[cur_pop][0]);
						el.style.visibility = 'visible';
						el.style.left = xMousePos+popup[cur_pop][1]+"px";
						el.style.top = yMousePos+popup[cur_pop][2]+"px";

						prop_cache[prop_cache_indices[this.id]][11].setImage(fetch_highlight_image(prop_cache[prop_cache_indices[this.id]][0]));
					});
					
					GEvent.addListener(mrkrs[cnt], 'mouseout', function() {
						var el = document.getElementById("prop_tag_"+popup[cur_pop][0]);
						el.style.visibility = 'hidden';
						document["popupimg_"+popup[0][0]].src = "/images/loading.gif";
						document["popupimg_"+popup[1][0]].src = "/images/loading.gif";
						document["popupimg_"+popup[2][0]].src = "/images/loading.gif";
						document["popupimg_"+popup[3][0]].src = "/images/loading.gif";
						cur_hover_prop = 0;
						
						prop_cache[prop_cache_indices[this.id]][2].setImage(fetch_image(prop_cache[prop_cache_indices[this.id]][0], prop_cache[prop_cache_indices[this.id]][10]));
					});
					
					GEvent.addListener(mrkrs_big[cnt], 'mouseout', function() {
						var el = document.getElementById("prop_tag_"+popup[cur_pop][0]);
						el.style.visibility = 'hidden';
						document["popupimg_"+popup[0][0]].src = "/images/loading.gif";
						document["popupimg_"+popup[1][0]].src = "/images/loading.gif";
						document["popupimg_"+popup[2][0]].src = "/images/loading.gif";
						document["popupimg_"+popup[3][0]].src = "/images/loading.gif";
						cur_hover_prop = 0;
						
						prop_cache[prop_cache_indices[this.id]][11].setImage(fetch_image(prop_cache[prop_cache_indices[this.id]][0], prop_cache[prop_cache_indices[this.id]][10]));
					});
					
					cache_index = prop_cache.length;
					
					
			//	store 									type, 			ID, 	marker, 	picture, 	price, 		address, 		beds, 			baths, 		sqft, 		lot size,		status_code, big marker
					prop_cache[cache_index] = new Array(props[i][12], props[i][0], mrkrs[cnt], props[i][7], props[i][4], props[i][3], props[i][7], props[i][8], props[i][9], props[i][11], props[i][6], mrkrs_big[cnt]);
					prop_cache_new[i] = new Array(props[i][12], props[i][0], mrkrs[cnt], props[i][7], props[i][4], props[i][3], props[i][7], props[i][8], props[i][9], props[i][11], props[i][6], mrkrs_big[cnt]);
					

				//	store the index in the cache
					prop_cache_indices[props[i][0]] = cache_index;
					
				//	insert_row(props[i]);
					if (!caching){
						map.addOverlay(mrkrs[cnt]);
						map.addOverlay(mrkrs_big[cnt]);
					}
					
					cnt++;
				} else {
				//	our "new" prop is already in the cache so we need to copy it into the new array that will replace existing
					var index = prop_cache_indices[props[i][0]];
					var num_fields = prop_cache[index].length;
					prop_cache_new[i] = new Array();
					for (j=0; j<num_fields; j++){
						prop_cache_new[i][j] = prop_cache[index][j];
					}
				}
			}
		//	caching, so use markerManager
			if (caching){
			//	mm.addMarkers(mrkrs, 0, 17);
				mm.addMarkers(mrkrs, 0, zoomSizeChangeLevel);
				mm.addMarkers(mrkrs_big, zoomSizeChangeLevel+1, 17);
				mm.refresh();
			}
			mrkrs.splice(0, mrkrs.length);
			mrkrs_big.splice(0, mrkrs_big.length);
			
		//	remove markers not just retrieved
			if (!caching){
			//	first create a temporary MlsNum indexed array holding new markers
				var temp_new_arr = new Array();
			//	next create a temporary array holding old markers to remove
				var temp_del_arr = new Array();
				var num_new = props.length;
				for (i=0; i<num_new; i++){
				//	store marker at MlsNum index
					temp_new_arr[props[i][0]] = props[i][0];
				}
			//	now step through the cache array, 
				var num_old = prop_cache.length;
				var cnt = 0;
				for (i=0; i<num_old; i++){
				//	checking for existance in temp array
					if (temp_new_arr[prop_cache[i][1]] == undefined){
					//	if it's not there, record it to delete later
						temp_del_arr[cnt++] = prop_cache[i][0];
					}
				}
			//	trash temp array
				temp_new_arr.splice(0, temp_new_arr.length);
				
				var num_del = temp_del_arr.length;
				for (i=0; i<num_del; i++){
/*					document.getElementById("debugging").innerHTML = temp_del_arr[i]+"\n<br />"+document.getElementById("debugging").innerHTML;
					document.getElementById("debugging").innerHTML = prop_cache_indices[temp_del_arr[i]]+"\n<br />"+document.getElementById("debugging").innerHTML;
					document.getElementById("debugging").innerHTML = prop_cache[prop_cache_indices[temp_del_arr[i]]][1]+"\n<br />"+document.getElementById("debugging").innerHTML;*/
				//	remove from map
					map.removeOverlay(prop_cache[prop_cache_indices[temp_del_arr[i]]][2]);
				//	remove from table
					remove_row_by_id(prop_cache[prop_cache_indices[temp_del_arr[i]]][1]);
				}
			//	remove from cache
			//	dump the original array	
				prop_cache_indices.splice(0, prop_cache_indices.length);
				prop_cache.splice(0, prop_cache.length);
			//	replace prop_cache_indices and prop_cache with new
				num_new = prop_cache_new.length;
				for (i=0; i<num_new; i++){
					prop_cache_indices[prop_cache_new[i][1]] = i;
					var num_fields = prop_cache_new[i].length;
					prop_cache[i] = new Array();
					for (j=0; j<num_fields; j++){
						prop_cache[i][j] = prop_cache_new[i][j];
					}
				}
			//	trash the temp new array
				prop_cache_new.splice(0, prop_cache_new.length);
			//	trash del array
				temp_del_arr.splice(0, temp_del_arr.length);
			}
//			var table_element = document.getElementById("display_table").getElementsByTagName("tbody")[0];
//			makePretty(table_element,-1,0);
		}
	}
	

	function strip_trailing_zeroes(str){
		while (str.charAt(str.length-1) == '0'){
			str = str.substr(0, str.length-1);
		}
		return str;
	}
	
	
	function prop_details(prop){
		var details = "";
		var tstr = "";
		switch(prop[0]){
			case 'residential':
				if (prop[9].length) {
					details += (details.length) ? ", <b>Beds:</b> "+prop[9] : "<b>Beds:</b> "+prop[9];
				}
				if (prop[10].length) {
					details += (details.length) ? ", <b>Baths:</b> "+prop[10] : "<b>Baths:</b> "+prop[10];
				}
				if (prop[11].length) {
					details += (details.length) ? ", <b>Square Feet:</b> "+prop[11] : "<b>Square Feet:</b> "+prop[11];
				}
				if (prop[12].length) {
					details += (details.length) ? ", <b>Acres:</b> "+strip_trailing_zeroes(prop[12]) : "<b>Acres:</b> "+strip_trailing_zeroes(prop[12]);
				}
				if (prop[20].length) {
					details += (details.length) ? ", <b>Year Built:</b> "+prop[20].substr(0, 4) : "<b>Year Built:</b> "+prop[20].substr(0, 4);
				}
				
				details += (details.length) ? "<br />" : "";
				
				if ((prop[4].length) || (prop[0].length) || (prop[14].length) || (prop[1].length)) {
					if (prop[4].length) {
						tstr += (tstr.length) ? ", <b>Status:</b> "+prop[4] : "<b>Status:</b> "+prop[4];
					}
					if (prop[0].length) {
						tstr += (tstr.length) ? ", <b>Class:</b> "+prop[0] : "<b>Class:</b> "+prop[0];
					}
					if (prop[14].length) {
						tstr += (tstr.length) ? ", <b>Type:</b> "+prop[14] : "<b>Type:</b> "+prop[14];
					}
					if (prop[1].length) {
						tstr += (tstr.length) ? ", <b>MLS#:</b> "+prop[1] : "<b>MLS#:</b> "+prop[1];
					}
					details += tstr+"<br />";
					tstr = "";
				}
			//
				if (
					((prop[16].length) && (prop[16] != 'Call School Board'))
					||
					((prop[17].length) && (prop[17] != 'Call School Board'))
					||
					((prop[18].length) && (prop[18] != 'Call School Board'))
					){
					tstr += (tstr.length) ? ", <b>Elem.:</b> "+prop[16] : "<b>Elem.:</b> "+prop[16];
					tstr += (tstr.length) ? ", <b>Middle:</b> "+prop[17] : "<b>Middle:</b> "+prop[17];
					tstr += (tstr.length) ? ", <b>High:</b> "+prop[18] : "<b>High:</b> "+prop[18];
					tstr = "Schools<br />"+tstr;
					details += tstr+"<br />";
					tstr = "";
				}
				
			//	details = (details.length) ? "<b>"+details+"</b>" : "";
				break;
			case 'commercial/industrial':
				if (prop[9].length) {
					details += (details.length) ? ", <b>SqFt Total:</b> "+prop[9] : "<b>SqFt Total:</b> "+prop[9];
				}
				if (prop[10].length) {
					details += (details.length) ? ", <b>Mnfct SqFt:</b> "+prop[10] : "<b>Mnfct SqFt:</b> "+prop[10];
				}
				if (prop[11].length) {
					details += (details.length) ? ", <b>Office SqFt:</b> "+prop[11] : "<b>Office SqFt:</b> "+prop[11];
				}
				if (prop[12].length) {
					details += (details.length) ? ", <b>Retail SqFt:</b> "+prop[12] : "<b>Retail SqFt:</b> "+prop[12];
				}
				if (prop[13].length) {
					details += (details.length) ? ", <b>Wrhse SqFt:</b> "+prop[13] : "<b>Wrhse SqFt:</b> "+prop[13];
				}
				if (prop[14].length) {
					details += (details.length) ? ", <b>Year Built:</b> "+prop[14].substr(0, 4) : "<b>Year Built:</b> "+prop[14].substr(0, 4);
				}
				
				details += (details.length) ? "<br />" : "";
				
				if ((prop[4].length) || (prop[0].length) || (prop[14].length) || (prop[1].length)) {
					if (prop[4].length) {
						tstr += (tstr.length) ? ", <b>Status:</b> "+prop[4] : "<b>Status:</b> "+prop[4];
					}
					if (prop[0].length) {
						tstr += (tstr.length) ? ", <b>Class:</b> "+prop[0] : "<b>Class:</b> "+prop[0];
					}
					if (prop[14].length) {
						tstr += (tstr.length) ? ", <b>Type:</b> "+prop[14] : "<b>Type:</b> "+prop[14];
					}
					if (prop[1].length) {
						tstr += (tstr.length) ? ", <b>MLS#:</b> "+prop[1] : "<b>MLS#:</b> "+prop[1];
					}
					details += tstr+"<br />";
					tstr = "";
				}
				break;
			case 'commercial land':
				if (prop[9].length) {
					details += (details.length) ? ", <b>Acres:</b> "+strip_trailing_zeroes(prop[9]) : "<b>Acres:</b> "+strip_trailing_zeroes(prop[9]);
				//	alert(strip_trailing_zeroes(prop[9])+" and "+prop[9]);
				}
				if (prop[12].length) {
					details += (details.length) ? ", <b>Lot Dimensions:</b> "+prop[12] : "<b>Lot Dimensions:</b> "+prop[12];
				}
				
				details += (details.length) ? "<br />" : "";
				
				if ((prop[4].length) || (prop[0].length) || (prop[10].length) || (prop[1].length)) {
					if (prop[4].length) {
						tstr += (tstr.length) ? ", <b>Status:</b> "+prop[4] : "<b>Status:</b> "+prop[4];
					}
					if (prop[0].length) {
						tstr += (tstr.length) ? ", <b>Class:</b> "+prop[0] : "<b>Class:</b> "+prop[0];
					}
					if (prop[10].length) {
						tstr += (tstr.length) ? ", <b>Type:</b> "+prop[10] : "<b>Type:</b> "+prop[10];
					}
					if (prop[1].length) {
						tstr += (tstr.length) ? ", <b>MLS#:</b> "+prop[1] : "<b>MLS#:</b> "+prop[1];
					}
					details += tstr+"<br />";
					tstr = "";
				}
				break;
			case 'land':
				
				break;
			case 'multi-family':
				
				break;
			case 'rental':
				
				break;
		}
		return details;
	}

//	
	function load_prop(mlsnum){
		cur_id = mlsnum;
	//	clear previous property
		document.images["ft_pic"].src = "http://"+host+"/images/loading.gif";
		document.getElementById("narrative").innerHTML = "loading...";
		
		var xmlhttp = create_xmlhttp();
		document.getElementById("working").innerHTML = "<img src=\"http://"+host+"/images/waiting-16.gif\" width=\"16\" height=\"16\" />";
		serverPage = "http://"+host+"/processors/get-detail_t.asp?id="+mlsnum;
	//	document.getElementById("debugging").innerHTML = (vars[0][1]+0) ? serverPage+"\n<br />"+document.getElementById("debugging").innerHTML : "";
		xmlhttp.open("GET", serverPage, true); // asynch param set to false for synch requests, true for asynch
		
		pics.splice(0, pics.length);
		
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				eval(xmlhttp.responseText);
			//	document.getElementById("feat_pic").innerHTML = "<img id=\"ft_pic\" src=\""+pic_src+"\" height=\"240\" width=\"320\" />";
			//	document.getElementById("ft_pic").src = pic_src;
				document.images["ft_pic"].src = pic_src;
				document.getElementById("pic_number").innerHTML = cur_pic + " of " + num_pics;
				document.getElementById("narrative").innerHTML = descrip;
				document.getElementById("details_link").innerHTML = "<a href=\"details.asp?ID="+mlsnum+"\">View Details</a>";

				document.getElementById("working").innerHTML = "<img src=\"http://"+host+"/images/pix.gif\" width=\"16\" height=\"16\" />";
			}
		}
		
		xmlhttp.send(null);
	}
	
	function save_vars_to_cookie(){
		var num_vars = vars.length;
		num_vars -= 5; // skip the last five vars, we don't want them
		for(i=0; i<num_vars; i++){
			SetCookie(vars[i][0], vars[i][1], expires);
		}
	}

//	vars is a 2D array that we pass to map loader	
	function fetch_properties(){
	//	document.getElementById("debugging").innerHTML = "fetch_properties()<br />"+document.getElementById("debugging").innerHTML;
		save_vars_to_cookie();
		var xmlhttp = create_xmlhttp();
		document.getElementById("working").innerHTML = "<img src=\"http://"+host+"/images/waiting-16.gif\" width=\"16\" height=\"16\" />";
		
	//	setup server url
	//	serverPage = "http://"+host+"/admin/MLS/processors/map-loader.php?";
		serverPage = "http://"+host+"/processors/map-loader_t.asp?";
		var num_vars = vars.length;
		for(i=0; i<num_vars; i++){
			serverPage += vars[i][0]+"="+vars[i][1]+"&";
		}
		serverPage = serverPage.substr(0, serverPage.length-1); // trim off trailing "&"
		
	//	document.getElementById("debugging").innerHTML = (vars[0][1]+0) ? serverPage+"\n<br />"+document.getElementById("debugging").innerHTML : "";
		xmlhttp.open("GET", serverPage, true); // asynch param set to false for synch requests, true for asynch

		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				var response = xmlhttp.responseText;
			//	document.getElementById("debugging").innerHTML = response+"<br />\n"+document.getElementById("debugging").innerHTML;
				eval(response);
				add_props();
			//	document.getElementById("report").innerHTML = "Num requested: "+num_requested+", num returned: "+num_returned+", num total: "+num_total+", prop_cache: "+prop_cache.length+", mm count: ";
			//	document.getElementById("report").innerHTML += (caching) ? mm.getMarkerCount(0)+"." : ".";
				document.getElementById("num_props").innerHTML = "props: "+num_returned; // num_total
				document.getElementById("working").innerHTML = "<img src=\"http://"+host+"/images/pix.gif\" width=\"16\" height=\"16\" />";
				document.getElementById("loading").style.visibility = 'hidden';
			//	document.getElementById("debugging").innerHTML = "props: "+num_total+"<br />"+document.getElementById("debugging").innerHTML;
			} else if (xmlhttp.readyState == 4) {
				document.getElementById("num_props").innerHTML = "error: "+xmlhttp.statusText;
				document.getElementById("working").innerHTML = "<img src=\"http://"+host+"/images/pix.gif\" width=\"16\" height=\"16\" />";
				document.getElementById("loading").style.visibility = 'hidden';
			//	document.getElementById("debugging").innerHTML = serverPage+"<br />"+document.getElementById("debugging").innerHTML;
			}
		}
		
		xmlhttp.send(null);
	}
	

	function display_loading(){
	//	var rp = "";
		var el = document.getElementById("loading");
		var map_obj = document.getElementById("map_canvas");
		
		var map_left = map_obj.offsetLeft;
		if (map_obj.offsetParent.offsetLeft){
			map_left = map_obj.offsetParent.offsetLeft;
		}
		
		var tmp = findPos(map_obj);
		var map_top = tmp[1];		


		var map_width = map_obj.offsetWidth;
		var map_height = map_obj.offsetHeight;
		var load_width = el.offsetWidth;
		var load_height = el.offsetHeight;
		
		
		var load_left = (map_left + parseInt((map_width - load_width)/2))+"px";
		var load_top = (map_top + parseInt((map_height - load_height)/2))+"px";
		
		el.style.left = load_left;
		el.style.top = load_top;
		
		el.style.visibility = "visible";
	}
	
//	sets up the global vars array
	function setup_bounds_vars(){
		var mapBounds = map.getBounds();
		vars[VAR_UBOUND-3][1] = mapBounds.getNorthEast().lat(); // north
		vars[VAR_UBOUND-2][1] = mapBounds.getSouthWest().lat(); // south
		vars[VAR_UBOUND-1][1] = mapBounds.getNorthEast().lng(); // east
		vars[VAR_UBOUND-0][1] = mapBounds.getSouthWest().lng(); // west
	}
	
	function do_load_props(){
	//	document.getElementById("debugging").innerHTML = "do_load_props()<br />"+document.getElementById("debugging").innerHTML;
		update_vars_values_from_form(true);
		setup_bounds_vars();
		display_loading();
		fetch_properties();
	}
	
	function do_moveend(){
	//	document.getElementById("debugging").innerHTML = "do_moveend()<br />"+document.getElementById("debugging").innerHTML;
	//	document.getElementById("debugging").innerHTML = "load_dyn is "+load_dyn+"<br />"+document.getElementById("debugging").innerHTML;
		if (load_dyn){
		//	we don't want to load on zoomed
			if (!zoomed){
				do_load_props();
			} else {
				zoomed = 0;
			}
		//	document.getElementById("debugging").innerHTML = "do_moveend()<br />" + document.getElementById("debugging").innerHTML;
		}
		SetCookie("lat", map.getCenter().lat(), expires);
		document.map_search_form.lat.value = map.getCenter().lat();
		SetCookie("lon", map.getCenter().lng(), expires); 
		document.map_search_form.lon.value = map.getCenter().lng();
	//	document.getElementById("debugging").innerHTML = "lat: "+GetCookie("lat")+"\n<br />"+"lon: "+GetCookie("lon")+"\n<br />"+document.getElementById("debugging").innerHTML;
	}
	
	function do_zoomed(oldZoom, newZoom){
	//	document.getElementById("zoomD").innerHTML = "zoom: "+newZoom;
		zoomed = (oldZoom > newZoom) ? 0 : 1; // don't search for new props on zoom in!
		if ((oldZoom == zoomSizeChangeLevel) && (oldZoom < newZoom)){
			zoomed = 0;
		//	clear_properties();
		//	document.getElementById("debugging").innerHTML = "oldZoom equals change level<br />" + document.getElementById("debugging").innerHTML;
		}
		if ((newZoom == zoomSizeChangeLevel) && (oldZoom >= newZoom)){
			zoomed = 0;
		//	clear_properties();
		//	document.getElementById("debugging").innerHTML = "newZoom equals change level<br />" + document.getElementById("debugging").innerHTML;
		}
		
	//	document.getElementById("debugging").innerHTML = "zoomed is "+zoomed+"<br />" + document.getElementById("debugging").innerHTML;
	}
	
	function init_pano(mlsnum){
	//	init_pano(prop_cache[prop_cache_indices[mlsnum]][2].getPoint().lat(), prop_cache[prop_cache_indices[mlsnum]][2].getPoint().lng());
	//	var mlsnum = this.id;
		var myPano = new GStreetviewPanorama(document.getElementById("pano"));
		pano_loc = new GLatLng(prop_cache[prop_cache_indices[mlsnum]][2].getPoint().lat(), prop_cache[prop_cache_indices[mlsnum]][2].getPoint().lng());
	//	pano_loc = new GLatLng(lat, lon);
		myPOV = {yaw:180,pitch:10};
		myPano.setLocationAndPOV(pano_loc, myPOV);
		GEvent.addListener(myPano, "error", handleNoFlash);
	}
	
	function handleNoFlash(errorCode) {
	  var FLASH_UNAVAILABLE = 603;
	  if (errorCode == FLASH_UNAVAILABLE) {
		alert("Error: Flash doesn't appear to be supported by your browser");
		return;
	  }
	}
	

	var svOverlay = null;

	function toggle_streetview(){
		var fm = document.map_search_form;
		if (fm.streetview_button.value == "turn street view on"){
			fm.streetview_button.value = "turn street view off";
			map.addOverlay(svOverlay);
		} else {
			fm.streetview_button.value = "turn street view on";
			map.removeOverlay(svOverlay);
		}
	}

//	called by clicking search button
	function do_search(){
	//	document.getElementById("debugging").innerHTML = "do_search()<br />"+document.getElementById("debugging").innerHTML;
	//	get the values from the search form
		update_vars_values_from_form(true);
	//	get the bounds of the map
		setup_bounds_vars();
	//	do the search
		fetch_properties();
	}
	
	var map = null;
	var mm = null;
	var overviewControl = null;
	var initialCenterPoint = new GLatLng(iLat, iLon);
	var defaultCenterPoint = new GLatLng(default_lat, default_lon);
	var initialZoomLevel = iZoom;
	var map_type = GetCookie("map_type");
	map_type = (map_type.length > 0) ? map_type : 'G_NORMAL_MAP';
//	var initialMapType = G_NORMAL_MAP;
	
	function setup_MarkerManager(){
		var mgrOptions = { borderPadding: 20, trackMarkers: false };
		mm = new MarkerManager(map, mgrOptions); // zoom 13 and below (zoom out lower level)
	}

	function currentMapTypeNumber(map){ 
		var type=-1; 
		for (var ix=0;ix<map.getMapTypes().length;ix++) {
			if (map.getMapTypes()[ix]==map.getCurrentMapType())
				type=ix;
		}
		return type;
	}
	
	function initialize() {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map_canvas"));
		
		if ((map_type != 'G_NORMAL_MAP') && (map_type != 'G_SATELLITE_MAP') && (map_type != 'G_HYBRID_MAP') && (map_type != 'G_PHYSICAL_MAP')) {
			map_type = 'G_NORMAL_MAP';
		}
		
	//	document.getElementById("debugging").innerHTML = "map_type: "+map_type+"\n<br />"+document.getElementById("debugging").innerHTML;
		map.setCenter(initialCenterPoint, initialZoomLevel, eval(map_type));
		
		map.addMapType(G_PHYSICAL_MAP);
		
		map.addControl(new GSmallMapControl());
		map.addControl(new GScaleControl());
		map.addControl(new GMenuMapTypeControl());
		overviewControl = new GOverviewMapControl();
		map.addControl(overviewControl);
		
		map.enableScrollWheelZoom();
		

		svOverlay = new GStreetviewOverlay();


		window.setTimeout(setup_MarkerManager, 1000);
	//	window.setTimeout(do_moveend, 1500);
		
		
		GEvent.addListener(map, "moveend", function(){ 
			do_moveend();
		} );
		
		GEvent.addListener(map, "zoomend", function(oldZoomLevel, newZoomLevel){ 
			do_zoomed(oldZoomLevel, newZoomLevel);
			SetCookie("zoom", newZoomLevel, expires);
			document.map_search_form.zoom.value = newZoomLevel;
		} );


		GEvent.addListener(map, 'mousemove', function() {
			var el = document.getElementById("prop_tag_"+popup[cur_pop][0]);
		//	is the popup open?
			if (el.style.visibility == 'visible'){
				var new_pop = select_popup();
				if (cur_pop == new_pop){
				//	we only need to reposition the popup
					el.style.left = xMousePos+popup[cur_pop][1]+"px";
					el.style.top = yMousePos+popup[cur_pop][2]+"px";
					
				} else {
				//	we have a new popup, hide the old one, setup the new one
					el.style.visibility = 'hidden';
					cur_pop = new_pop;
				//	setup new popup
					el = document.getElementById("prop_tag_"+popup[cur_pop][0]);
					document["popupimg_"+popup[cur_pop][0]].onerror = function() {load_alt_image()};
					document["popupimg_"+popup[cur_pop][0]].src = get_picture_name(cur_hover_prop);
					var text_el = document.getElementById("popuptxt_"+popup[cur_pop][0]);
					text_el.innerHTML = get_popup_text(cur_hover_prop);
					text_el.style.width="100px";
					text_el.style.height="21px";
					text_el.style.overflow="hidden";

					el.style.visibility = 'visible';
					el.style.left = xMousePos+popup[cur_pop][1]+"px";
					el.style.top = yMousePos+popup[cur_pop][2]+"px";
				}
			}
		});
		
		GEvent.addListener(map, 'maptypechanged', function() {
			var map_type_name = map.getCurrentMapType().getName();
			var map_type = 'G_NORMAL_MAP';
			switch (map_type_name){
				case 'Map':
					map_type = 'G_NORMAL_MAP';
					break;
				case 'Satellite':
					map_type = 'G_SATELLITE_MAP';
					break;
				case 'Hybrid':
					map_type = 'G_HYBRID_MAP';
					break;
				case 'Terrain':
					map_type = 'G_PHYSICAL_MAP';
					break;
				default:
					map_type = 'G_NORMAL_MAP';
					break;
			}
			SetCookie("map_type", map_type, expires);
			document.map_search_form.map_type.value = map_type;
		//	document.getElementById("debugging").innerHTML = "map_type: "+map_type+"\n<br />"+document.getElementById("debugging").innerHTML;
		});


	//	map.onResize = function(){alert('in onResize');};
	//	do_zoomed();
	//	changeElementText("zoomD", "zoom: "+map.getZoom());
      }
    }

//	vars is a 2D array that we pass to map loader	
	function setup_display_table(){
		var xmlhttp = create_xmlhttp();
		document.getElementById("working").innerHTML = "<img src=\"http://"+host+"/images/waiting-16.gif\" width=\"16\" height=\"16\" />";
		
	//	setup server url
		serverPage = "http://"+host+"/admin/MLS/processors/display-table-loader.php?reclass="+vars[1][1];
		
	//	document.getElementById("debugging").innerHTML = (vars[0][1]+0) ? serverPage+"\n<br />"+document.getElementById("debugging").innerHTML : "";
		xmlhttp.open("GET", serverPage, true); // asynch param set to false for synch requests, true for asynch

		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				var response = xmlhttp.responseText;
				document.getElementById("display_table_div").innerHTML = response;
				document.getElementById("working").innerHTML = "<img src=\"http://"+host+"/images/pix.gif\" width=\"16\" height=\"16\" />";
			}
		}
		
		xmlhttp.send(null);
	}
	
//	transfer map form values to vars array
	function update_vars_values_from_form(ignored){
		var fm = document.map_search_form;
		var num_els = vars.length;
		var instr = "";
		var eltype = "";
		for (i=0; i<num_els; i++){
			eltype = eval("fm."+vars[i][0]+".type");
			if (eltype == "checkbox") {
				instr = "vars["+i+"][1] = (fm."+vars[i][0]+".checked) ? 1 : 0;";
			} else {
				instr = "vars["+i+"][1] = fm."+vars[i][0]+".value;";
			}
			eval(instr);
		//	save to cookie
			SetCookie(vars[i][0], vars[i][1], expires);
		//	document.getElementById("debugging").innerHTML = instr+"<br />"+document.getElementById("debugging").innerHTML;
		}
	}
	
	
	function swap_map_form(){
	//	alert(report_vars());
		rp = "";
	//	store the last reclass form (false)
		update_vars_values_from_form(false);
	//	alert(report_vars());
		
		clear_properties();
		
	//	alert("now onto load_form()");
		load_form();
	//	alert("returned from load_form()");
		
		setup_display_table();
		
	//	if setup_display_table() works asynchronously the following call will fail
	//	because it calls update_vars_values_from_form(true) before the values it reads
	//	are setup!
		
/*		if (document.map_prefs.load_dyn.checked){
			do_search();
		}*/
		
	//	document.getElementById("debugging").innerHTML = "document.map_prefs.load_dyn.checked: "+document.map_prefs.load_dyn.checked+".<br />"+document.getElementById("debugging").innerHTML;

		
	}
	
	function report_vars(){
		var num_vars = vars.length;
		var rp = "";
		for(i=0; i<num_vars; i++){
			rp += vars[i][0]+": "+vars[i][1]+"\n";
		}
		return rp;
	}
	
	function report_forms(){
		var rp = "";
		for (i=0; i<document.forms.length; i++){
			rp += document.forms[i].name + "\n";
			for (j=0; j<document.forms[i].elements.length; j++){
				rp += "\t"+document.forms[i].elements[j].name + "\n";
			}
		}
		rp += "\tliststatus.length: "+document.forms[0].liststatus.length;
		return rp;
	}
	
//	removes properties from the cache, map and table
	function clear_properties(){
	//	remove all the markers from the map
		for (i=0; i<prop_cache.length; i++){
			map.removeOverlay(prop_cache[i][2]);
			map.removeOverlay(prop_cache[i][11]);
		}
		
	//	clear all the markers
		mm.clearMarkers();
	//	destroy current marker manager			
		mm = null;
	//	re-initialize the marker manager
		setup_MarkerManager();
		
	//	remove all markers from cache
		prop_cache.splice(0, prop_cache.length);
	//	remove all points from tracking array
		prop_cache_indices.splice(0, prop_cache_indices.length);
		
	//	document.getElementById("report").innerHTML = "Num requested: 0, num returned: 0, num total: 0, prop_cache: "+prop_cache.length+", mm count: "+mm.getMarkerCount(0)+".";
		document.getElementById("num_props").innerHTML = "props: 0";
	}
	
	function do_cache_props_cb(){
		var cb = document.map_prefs.caching;
		caching = (cb.checked);
	//	first clear
		clear_properties();
	//	next, add properties
		do_moveend();
	}

	function do_load_dyn_cb(){
		load_dyn = document.map_search_form.load_dyn.checked;
	}

	function write_vars(){
		var num_vars = vars.length;
		for(i=0; i<num_vars; i++){
			document.getElementById("debugging").innerHTML = vars[i][0]+"="+vars[i][1]+".<br />"+document.getElementById("debugging").innerHTML;
		}
		
	}

	function write_debugging(str){
		document.getElementById("debugging").innerHTML = str+"<br />"+document.getElementById("debugging").innerHTML;
	}

/*	if (window.attachEvent) {
		window.attachEvent("onresize", function() {this.map.onResize()});
	} else { 
		window.addEventListener("resize", function() {this.map.onResize()}, false);
	}*/
	
	function size_map(){
		var map_obj = document.getElementById("map_canvas");
		map_obj.style.right = pageWidth()+"px";
	}
	
	
// Browser Window Size and Position
// copyright Stephen Chapman, 3rd Jan 2005, 8th Dec 2005
// you may copy these functions but please keep the copyright notice as well
function pageWidth() {return window.innerWidth != null? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;} 
function pageHeight() {return  window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;} 
function posLeft() {return typeof window.pageXOffset != 'undefined' ? window.pageXOffset :document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;} 
function posTop() {return typeof window.pageYOffset != 'undefined' ?  window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;} 
function posRight() {return posLeft()+pageWidth();} function posBottom() {return posTop()+pageHeight();}
                    