		
	// global variables	

var searchForm = function(){
	var pm = {}; // Public Members
	pm.prev_location = '';
	pm.stored = [];
	return pm;

}();

		
function expand(el){
	if (!el.nodeName){
		el = document.getElementById(el);
	}
	
	if (el.nodeName == "INPUT"){
		var output_option = document.getElementById(el.id.replace('advanced_search','output'));
		if (el.checked){
			addClass(el,"active");
			removeClass($("#"+el.id+"_content"),"hide");
			if (output_option){
				removeClass(output_option,"hide");
			}
		}else{
			removeClass(el,"active");
			addClass($("#"+el.id+"_content"),"hide");
			if (output_option){
				addClass(output_option,"hide");
			}
		}
		updateLabelClass(el,el.checked,'active');
	}
	if (el.nodeName == "A"){
		toggleClass(el.id,"active");
		toggleClass(el.id+"_content","hide");
	}
}

function updateLabelClass(el,active,class_name){
	var labels = el.parentNode.getElementsByTagName("label");
	for (var i=0; i<labels.length; i++){
		if (labels[i].getAttribute("for") == el.id){
			if (active){
				addClass(labels[i],class_name);
			}else{
				removeClass(labels[i],class_name);
			}				
		}
	}
	
}

function set_prop_type(id){

	var container = document.getElementById(id);
	var inputs = container.getElementsByTagName("INPUT");
	
	var arr = [];
	
	for (var i=0; i<inputs.length; i++){
		if ((inputs[i].type == 'checkbox' || inputs[i].type == 'radio') && inputs[i].checked){
			arr.push(inputs[i].value);
		}
	}
	
	var nodes = [];
	var container = document.getElementById('advanced_search');
	
	
	
	if (document.getElementsByClassName){
		// Native implementation of getElementsByClassName
		nodes = container.getElementsByClassName('conditional_type');
	}else{
		nodes = getElementsByClass('conditional_type',container);
	}
	

	var divs = nodes;

	for (var j = 0; j<divs.length; j++){

			var hide = true;

			for (var i=0; i<arr.length; i++){
				//var m = arr[i].split('_');
				//for (var k = 0; k<m.length; k++){
					if (hasClass(divs[j],arr[i])){
						hide = false;
					}
				//}						
			}
			if (hide){
				addClass(divs[j],'hide');
			}else{
				removeClass(divs[j],'hide');
			}
	}
		
}





function ui_set_type(r,search_type, app, rid){
	
	for (var i=0; i<r.form[r.name].length; i++){
		var l = document.getElementById(r.form[r.name][i].id+"_container");
		if (r.form[r.name][i].checked){
			addClass(l,'current');
		}else{
			removeClass(l,'current');
		}		
	}
	
	var form_url = "/mason/UI/components/search_form.html?search_type="+search_type+"&app="+app+"&ajaxload=1";
	
	if (rid){
		form_url += "&rid="+rid;	
	}
	
	if (r.form.location.value != r.form.location.defaultValue || hasClass(r.form.location,"focus")){
		form_url += "&location=" + r.form.location.value;
	}

	var s = new AjaxService();
	s.setURL(form_url);
	var form_container = document.getElementById("simple_search");
	s.setDelegate(function(r){
		form_container.innerHTML = r;
		form_container.style.width = "auto";
		form_container.style.height = "auto";
		
		set_field_value("search_token");
		set_field_value("location");

		
	});
	s.callService();
	
	form_container.style.height = form_container.offsetHeight + "px";
	form_container.style.width = form_container.offsetWidth + "px";
	form_container.innerHTML = "<div class=\"loading\">Loading " + search_type + " search</div>";

	close_error_message();
	
	clear_stored_field_value("search_token");
	clear_stored_field_value("location");
	
}
	
// Disable hidden input fields
// as in css display=none not as in html input type=hidden
// *****************************************************************************************
	
function ft_disable_hidden(id){

	ft_disable_in_hidden(id);
	
	var partial = document.getElementById('advanced_search_display_only');
	if (partial){
		var el = document.getElementById(id);
		var acive_fields;
		if (document.getElementsByClassName){
			acive_fields = el.getElementsByClassName('display_mode_off');
		}else{
			acive_fields = getElementsByClass('display_mode_off',el);
		}
		
		for (var i=0; i<acive_fields.length; i++){
			ft_set_disabled(acive_fields[i],true);	
		}
	}
}

function ft_disable_in_hidden(id){
	
	//*********************************************
	// disable all input elements that are
	// 1. children of el if el has class hide
	// 2. children of element with classes criteria_expandee+hide
	//*********************************************
	
	var el = document.getElementById(id);
	
	if (!el){
		return;
	}
	
	if (hasClass(el,"hide")){
		ft_set_disabled(el,true);
		return;
	}
	
	var criteria_expandees = [];
		
	if (document.getElementsByClassName){
		criteria_expandees = el.getElementsByClassName('criteria_expandee');
	}else{
		criteria_expandees = getElementsByClass('criteria_expandee',el);
	}

	for (var i=0; i<criteria_expandees.length; i++){
		if (hasClass(criteria_expandees[i],'hide')){
			ft_disable_in_hidden(criteria_expandees[i].id)
		}	
	}
}

function ft_set_disabled(el,disabled){
	if (!el.nodeName){
		el = document.getElementById(el);
	}
	
	if (el){
		
		var field_types = ["INPUT","SELECT","TEXTAREA"];
		for (var i=0; i<field_types.length; i++){
			var form_fields = el.getElementsByTagName(field_types[i]);
			for (var j=0; j<form_fields.length; j++){
				if (!hasClass(form_fields[j], "passthrough")) {
					form_fields[j].disabled = disabled;
				}
			}
		}
	}
}
	
	
// Some generic form and dom helper functions
// *****************************************************************************************
	
function fs_singular_check(el){
	
	//*********************************************
	// el is a checkbox in a fieldset
	// fs_singular_check will cause all other
	// checkboxes in the fieldset to be un-checked
	//*********************************************
	
	var container = get_closest_ancestor(el,"FIELDSET");
	
	if (container){
		var inputs = container.getElementsByTagName("INPUT");
		for (var i=0; i<inputs.length; i++){
			if (inputs[i].type == 'checkbox' && inputs[i] != el){
				inputs[i].checked = false;
			}
		}
	}
}

function fs_expand(el){
	
	//*********************************************
	// el is a checkbox in a fieldset
	// fs_expand will expand or collapse
	// section with id = fieldset.id + '_content'
	// if any of the checkboxes in fieldset are checked
	//*********************************************
	
	var container = get_closest_ancestor(el,"FIELDSET");
	
	
	if (container){
		var content = document.getElementById(container.id + '_content');
		if (content){
			var show = false;
			var inputs = container.getElementsByTagName("INPUT");
			for (var i=0; i<inputs.length; i++){
				if (inputs[i].type == 'checkbox' && inputs[i].checked){
					show = true;
				}
			}
			if (show){
				removeClass(content,'hide');
			}else{
				addClass(content,'hide');
			}
		}
	}
}

function get_closest_ancestor(el,tag_name){
	
	//*********************************************
	// find and return el's closest ancestor 
	// with tagName == tag_name
	//*********************************************
	
	var ancestor = el.parentNode;
	while (ancestor.tagName != tag_name){
		ancestor = ancestor.parentNode;
		if (ancestor.tagName == "BODY"){
			return;	
		}
	}
	return ancestor;
}
	
	
function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}
		
		
		
		
// Section for function dealing with displaying and hiding advanced search options
// *****************************************************************************************
		
		
	function load_criteria_from_location(rid,app,qstring,callback) {
		
		// if location value has changed (check defaultValue first, global vaiable or hidden field next),
		// load script which calls function with locale corresponding to the current location value
		// if they are different, load advanced form using ajax
		
		var current_location = document.getElementById('location').value;
		var default_location = document.getElementById('location').defaultValue;
		
		if (searchForm.prev_location == ""){
			searchForm.prev_location = default_location;
		}

		if (current_location.toLowerCase() == searchForm.prev_location.toLowerCase() && searchForm.prev_location.toLowerCase() != "ambiguous"){
			remove_advanced_loader_and_display_advanced_options()
			return;
		}
		searchForm.prev_location = current_location;
		
		var location = document.getElementById('location').value;
		
		var search_token;
		if (document.getElementById('search_token')){
			search_token = document.getElementById('search_token').value;
		}
		
		var args = [];
		args.push('callback=load_additional_criteria');
		args.push('callback_advanced_criteria='+callback);
		args.push('location='+location);
		args.push('search_token='+search_token);
		args.push('rid='+rid);
		args.push('app='+app);
		args.push(qstring);		
		
		include_script('/mason/UI/location.js?'+args.join('&')+'&seed='+Math.floor(Math.random()*100000),'criteriaLocation');
	}
	
	function load_additional_criteria(location,qstring,callback){
		var app_locale = document.getElementById('app_locale');
		if (app_locale){
			if (app_locale.value.toLowerCase() == location.toLowerCase()){
				remove_advanced_loader_and_display_advanced_options()
				return;
			}
		}
		
		var url = "/mason/UI/components/advanced_search.html?app_locale=" + location + "&" + qstring + "&ajaxload=1";
		//window.open(url);
		
		var service = new AjaxService();
		service.setDelegate(function(r){
			document.getElementById('advanced_search_content').innerHTML = r;
			if (callback) eval(callback+"()");
			remove_advanced_loader_and_display_advanced_options();
		});
		service.setURL(url);
		service._execScript = true;
		service.callService();
	}
	
	function load_advanced_loader(location){
		var loading_el = document.getElementById('advanced_search_loader');
		var advanced_search = document.getElementById('advanced_search');
		if (!loading_el){
			loading_el = document.createElement('DIV');
			loading_el.id = "advanced_search_loader";
			advanced_search.appendChild(loading_el,advanced_search);
		}
		
		loading_el.innerHTML = "Loading advanced search options for <b>" + location + "</b>...";
		removeClass($('#advanced_search_loader'),'hide');
		addClass($('#advanced_search_content'),'hide');
		addClass($('#advanced_search_control'),'hide');
	}
	
	function remove_advanced_loader_and_display_advanced_options(){
		removeClass($('#advanced_search_content'),'hide');
		addClass($('#advanced_search_loader'),'hide');
	}
	
	function set_location_state(){
		// store value of location field when it receives focus
		// used by check_location_state to determine if a keyup or mouseup
		// event precedes an actual change to the field value
		searchForm.location_at_focus = document.getElementById('location').value;
		close_disambiguator();
		
	}
	
	function check_location_state() {
		
		if (document.getElementById('location').value != searchForm.location_at_focus){
			close_advanced(false);
			close_error_message();
			close_disambiguator();
		}
		
	}
	
	function open_advanced(show,rid,app,qstring,callback){
		addClass($('#advanced_search'),'active');
		show_advanced(show,rid,app,qstring,callback);
		addClass($('#advanced_search_control'),'hide');
	}
	
	function close_advanced(show,rid){
		
		var full = document.getElementById('advanced_search_edit');
		var partial = document.getElementById('advanced_search_display_only');
		
		if (full || partial){
			if (full){
				full.id = '';	
			}
			if (partial){
				partial.id = '';	
			}	
		}
		removeClass($('#advanced_search'),'active');
		show_advanced(show,rid);
		removeClass($('#advanced_search_control'),'hide');
	}
	function expand_advanced(show,rid,app,qstring){
		var partial = document.getElementById('advanced_search_display_only');
		if (partial){
			partial.id = 'advanced_search_edit';
			addClass($('#advanced_search_control'),'hide');
			return;	
		}
		
		addClass($('#advanced_search'),'active');
		show_advanced(show,rid,app,qstring);
		addClass($('#advanced_search_control'),'hide');
	}
	function collapse_advanced(show,rid){
		var full = document.getElementById('advanced_search_edit');
		if (full){
			full.id = 'advanced_search_display_only';
			removeClass($('#advanced_search_control'),'hide');
			return;	
		}
		removeClass($('#advanced_search'),'active');
		show_advanced(show,rid);
		removeClass($('#advanced_search_control'),'hide');
		
	}
	
	function reset_advanced(rid){

	}
	
	
	function show_advanced(show,rid,app,qstring,callback){
		
		var search_token = document.getElementById('search_token');
		var loc_el = document.getElementById('location');
		var btn = document.getElementById("search_submit_button");
		var adv = document.getElementById("advanced_search_content");
		var cur = document.getElementById("current_search_criteria");

		if (show){
			if (loc_el.value && (hasClass(loc_el,'set') || loc_el.value != loc_el.defaultValue )){
				// the location field has a value
				// display appropriate advanced search section
				addClass($('#advanced_search_toggle'),'hide');
				load_advanced_loader(loc_el.value)
				load_criteria_from_location(rid,app,qstring,callback);
				ft_set_disabled('advanced_search',false);
				addClass(cur,'hide');
			}else{
				// the location field does not have a value
				// display error message
				ss_set_error_message("To optimize search for your area, please enter <b>City, State</b> or <b>Zip</b> or <b>NYC Borough</b> before opening advanced search options");
				loc_el.focus();
			}
		}else{
			addClass($('#advanced_search_content'),'hide');
			removeClass($('#advanced_search_control'),'hide');
			ft_set_disabled('advanced_search',true);
			removeClass(cur,'hide');
		}
	}
	
	function edit_crit(id){
		document.getElementById("c_"+id).className = "display_mode_english_off";
		document.getElementById("h_"+id).className = "display_mode_edit_on";	
	}
	
	
// Section for error messages
// *****************************************************************************************
	
	function close_error_message(){
		// Close error message

		var err_el = document.getElementById('search_error');
		if (err_el && err_el.className != "hide") {
			addClass($('#search_error'),'hide');
			removeClass($('#advanced_search_control'),'hide');
			removeClass($('#advanced_search'),'hide');
		}
	}
	
	function ss_set_error_message(txt){

		var err_el = document.getElementById('search_error');
		var inp_el = document.getElementById('search_error_input');
		var arr_el = document.getElementById('search_error_arrow');
		if (!err_el && txt){
			err_el = document.createElement('DIV');
			err_el.id = 'search_error';
			
			
			arr_el = document.createElement('IMG');
			arr_el.id = 'search_error_arrow';
			arr_el.src = '/img/jk/error_arr_up.gif';
			arr_el.style.position = "absolute"

			err_el.appendChild(arr_el);
			
			inp_el = document.createElement('P');
			inp_el.id = 'search_error_input';
			err_el.appendChild(inp_el);
			
			var sim_el = document.getElementById('simple_search');
			sim_el.parentNode.insertBefore(err_el,sim_el.nextSibling);
			
			err_el.onclick = function(){ close_error_message() };
		}
		
		if (err_el){
			if (txt){
				arr_el.style.top = "-10px";
				var el_search_token = document.getElementById("search_token");
				var el_location = document.getElementById("location");
				var w = 0;
				if (el_search_token){
					w += el_search_token.offsetWidth;
				}
				if (el_location){
					w += el_location.offsetWidth;
				}
				arr_el.style.left = el_search_token ? el_search_token.offsetWidth + "px" : 0;
				
				err_el.style.position = "relative";
				err_el.style.border = "1px solid #b3c0cc";
				err_el.style.background = "#eef4f9";
				err_el.style.padding = "8px";
				err_el.style.margin = "10px 0";
				err_el.style.width = (w-16)+"px";
				inp_el.innerHTML = txt;
				removeClass(err_el,'hide');
				addClass(document.getElementById("advanced_search_toggle"),"hide");
				addClass($('#advanced_search'),'hide');
			}else{
				close_error_message();
			}
		}
		
		
	}
	
	
// Disambiguate Location

function disambiguate_location(location, locations, callback_obj){
	

	var location_field = document.getElementById('location');
	
	addClass($('#advanced_search_loader'),'hide');

	var disambiguator = document.getElementById('disambiguator');
	if (!disambiguator){
		disambiguator = document.createElement('DIV');
		disambiguator.id = 'disambiguator';
		location_field.parentNode.insertBefore(disambiguator,location_field.nextSibling);
		var field_width = location_field.offsetWidth;
		if (field_width < 200){
			disambiguator.style.width = field_width-18+"px";
		}
		
	}
	addClass($('#advanced_search_control'),'hide');
	disambiguator.innerHTML = '';
	var p = document.createElement('P');
	p.innerHTML = "Oops, I found more than one <b>" + location + "</b>:";
	var ul = document.createElement('UL');
	for (var i=0; i<locations.length; i++){
		var this_location = locations[i]
		var li = document.createElement('LI');
		var a = document.createElement('A');
		a.innerHTML = locations[i];
		a.href = "#";
		a.i = i;
		if (callback_obj){
			if (callback_obj.type == "submit"){
				a.onclick = function(){
					document.getElementById('location').value = locations[this.i];
					close_disambiguator()
					disambiguator.innerHTML = '';
					searchForm.prev_location = "ambiguous";
					submit_search_form(document.getElementById(callback_obj.form_id),searchForm.prev_location,callback_obj.callback,false);
					return false;	
				}
			}	
		}else{
			a.onclick = function(){
				document.getElementById('location').value = locations[this.i];
				close_disambiguator()
				disambiguator.innerHTML = '';
				searchForm.prev_location = "ambiguous";
				return false;	
			}
		}
		li.appendChild(a);
		ul.appendChild(li);	
	}	
	disambiguator.appendChild(p);
	disambiguator.appendChild(ul);
	removeClass(disambiguator,'hide');

	
}

function close_disambiguator(){
	addClass($('#disambiguator'),'hide');
	addClass($('#advanced_search_content'),'hide');
	removeClass($('#advanced_search_control'),'hide');
}
	
	
// Section for submitting the form
// *****************************************************************************************

function submit_search_form(form, locale, callback, locale_updated){
	
	//***********************************************
	// script to run before submitting form
	// The purpose of this script is to set the location cookie
	// and then 
	//    A. call a callback function
	//    B. submit the form
	//    C. both
	//
	// First we determine if the location cookie needs to be set
	// If it does need to be set, we load an external js file
	// that sets the cookie and calls this function again, 
	// this time with the locale_updated argument set to true
	//***********************************************
	
	// Make sure required location field is set
	if (check_required_location(form.location)){
	
		// If default field value always matches location cookie on page load
		// we should be able to check form.location.value != form.location.defaultValue to
		// determine if we even need to set the cookie
	
		if (typeof locale_updated == 'undefined' || !locale_updated){	// Check if location cookie has already been updated

			// Location cookie has not been updated yet.
			// This has to be done server side, so we include a new js file to take care of it
			// Note, this file should not be cachable, so add a random seed to querystring
			
			var url = '/mason/UI/components/set_locale.js?callback='+callback+'&form_id='+form.id+'&location='+form.location.value+'&seed='+Math.floor(Math.random()*100000);
			
			include_script(url,'setLocale');
			
			// Set prev_location so callback function has something to compare to
			searchForm.prev_location = locale;
			
			// Do not preceed.
			// This function will be called again when set_locale.js is loaded and location cookie set
			return false;	
		}
		
		// Location cookie corresponds to form.location.value
		// so we can proceed with submitting the form
	
		// Disable all fields that are hidden from view (css display=none, not input type=hidden)
		ft_disable_hidden('advanced_search');
	
		if (callback){	// check if we have a callback function
			//Create the function call from function name and args.
			var funcCall = callback + "('" + locale + "','" + $(form).serialize() + "');";

			var return_value = eval(funcCall);
			
			if (return_value){
				// Our callback function returned true
				// which means we now need to submit the form
				form.submit();
			}
		}else{
			// No callback function, so simply submit the form
			form.submit();
		}
	}
	return false;
}

function check_required_location(el){
	
	//*********************************************
	// Form can only be submitted if there is a valid value
	// in the location field
	//*********************************************

	if(el.value == ""){
		ss_set_error_message("Please enter <b>City, State</b> or <b>Zip</b> or <b>NYC Borough</b> to search");
		el.focus();
		return false;
	}
	return true;
}

// Map callback function

function js_search_pois_on_map(location,qstring){
	if (location != searchForm.prev_location) {
		// location has changed, so let's reload page
		document.location.href="?ui=0&variant=lefty&"+qstring;
	}else{
		// location is the same, so place point(s) on current map
		document.getElementById('map-search-results').innerHTML = "";
		var url = "/mason/UI/maps_search.js?"+qstring+"&map_name=map&ajax_loaded=1&v=0.1&seed="+Math.floor(Math.random()*100000);
		
		
		//window.open(url);
		if (include_script(url,'mapsSearch')){
			map.loadingPOI("search results");
		}
	}
}

function js_search_load_results_page(rid, page){
	if (document.getElementById('map-search-results')){
	var url = "/mason/Maps/search/search.html?rid="+rid+"&results_only=1&page="+page;
	var service = new AjaxService();
	service.setDelegate(function(r){
		document.getElementById('map-search-results').innerHTML = r;
	});
	service.setURL(url);
	service.callService();
	document.getElementById('map-search-results').innerHTML = "loading results";
	map.setCurrentPOIPage(page);
	map.loadOverlays();
	map.setAutoPanZoomPOI(-1);
	map.autoPanZoomPOI();
}else{
	//alert("not available...");
}
	
}


function load_case(id,url){
	var service = new AjaxService();
	var container = document.getElementById(id);

	service.setDelegate(function(r){
		document.getElementById(id).innerHTML = r;
	});
	service.setURL(url);
	service.callService();
	container.innerHTML = "loading data";
}

// 



// building class selector
// this is locale specific and will be available through a popup
// populated based on what is in the location field
// Will probably be expanded to other search criteria

function init_building_class_selector(link){
	
	include_script('/includes/tree.js','tree');
	
	var id = link.id;
	var content_id = id+"_content";
	var location = document.getElementById('location').value;
	
	var content_container = document.getElementById(content_id);
	
	if (hasClass(content_container, 'hide')){
	
	
	document.getElementById(content_id).innerHTML = "loading building class selector for " + location;
	
	var args = [];
	args.push('callback=load_building_class_selector');
	args.push('location='+location);
	args.push('id='+id);	
	
	include_script('/mason/UI/location.js?'+args.join('&')+'&seed='+Math.floor(Math.random()*100000),'building_class_loader');
		removeClass(content_container, 'hide');
		document.getElementById(id).innerHTML = link.innerHTML.replace("Load","Hide");
	}else{
		addClass(content_container, 'hide');
		document.getElementById(id).innerHTML = link.innerHTML.replace("Hide","Load");
	}
}

function load_building_class_selector(locale,qstring){
	var id;
	var location;
	if (qstring){
		var pairs = qstring.split("&");
		for (var i=0; i<pairs.length; i++){
			p = pairs[i].split("=");
			if (p[0] == "id"){
				id = p[1];
			}
			if (p[0] == "location"){
				location = p[1];
			}
		}
	}
	var url = "/mason/UI/building_classes.html?loc=" + locale + "&location=" + location;
	var service = new AjaxService();
	service.setDelegate(function(r){
		document.getElementById(id+"_content").innerHTML = r;
	});
	service.setURL(url);
	service.callService();
	
}



function adjust_style_types() {
	var search_type;

	if (document.forms && document.forms.search){
		for (var i=0; i < document.forms.search.search_type.length; i++){
			if (document.forms.search.search_type[i].checked && !document.forms.search.search_type[i].defaultChecked){
				search_type = document.forms.search.search_type[i].value;
			}
		}
	
		if (search_type){
			searchForm.stored["search_token"] = get_stored_field_value("search_token");
			searchForm.stored["location"] = get_stored_field_value("location");
			
			var radio = document.getElementById("search_type_radio_" + search_type);
			if (radio) {
				radio.click();
			}
		}
	}
}

function set_field_value(field_name){
	if (searchForm.stored[field_name] && searchForm.stored[field_name].length>0){
		var f = document.getElementById(field_name);
		f.value = searchForm.stored[field_name];
		searchForm.stored[field_name] = "";
	}
}

function set_stored_field_value(field_name,val){
	var f = document.getElementById("stored_field_values");
	if (f){
		var s = [];
		var exists = false;
		var pairs = f.value.split(";");
		for (var i=0; i<pairs.length; i++){
			p = pairs[i].split("=");
			if (p[0] == field_name){
				exists = true
				s.push(p[0]+"="+val);
			}else{
				s.push(pairs[i]);
			}
		}
		if (!exists){
			s.push(field_name+"="+val);
		}
		f.value = s.join(";");
	}	
}

function clear_stored_field_value(field_name){
	var f = document.getElementById("stored_field_values");
	if (f){
		var s = [];
		var pairs = f.value.split(";");
		for (var i=0; i<pairs.length; i++){
			p = pairs[i].split("=");
			if (p[0] != field_name){
				s.push(pairs[i]);
			}
		}
		f.value = s.join(";");
	}
}

function get_stored_field_value(field_name){
	var f = document.getElementById("stored_field_values");
	if (f){
		var pairs = f.value.split(";");
		for (var i=0; i<pairs.length; i++){
			p = pairs[i].split("=");
			if (p[0] == field_name){
				return p[1];
			}
		}
	}
	return '';
}

_UTIL_addDOMLoadEvent(adjust_style_types);





// other functions etc that probably don't belong in this file...

	function toggleList(toggle,width){
		var container = document.getElementById("properties_on_map");
		var available_width = container.offsetWidth - toggle.offsetWidth;
		if (hasClass(toggle,"show_list")){
			$("#tdlist").show();
			properties.resizeInlineMap(width,480);
			document.getElementById("tdmap").style.width = width+"px";
			removeClass(toggle,"show_list");
		}else{
			$("#tdlist").hide();
			properties.resizeInlineMap(available_width,480);
			document.getElementById("tdmap").style.width = available_width+"px";
			addClass(toggle,"show_list");
		}
		toggle.blur();
	}
