
function refinesearchsetup() {

	// make sure users can only check one box at a time
	// similar to radio button functionality, but cohesive with this design
	$('.location-boxes').click(function() {
		// $(':checkbox[name='+ $(this).attr('name') +']').attr('checked',false);
		// $(this).attr('checked',true);

		var selectedCommunity = "";
		var count = 0;
		$("#commID").val("");
		$('.location-boxes').each(function() {
			if ($(this).attr('checked') == true) {
				selectedVillage = $(this).attr('name');
				selectedVillage = selectedVillage.replace("location-", "");
				count = count + 1;
				
				if ($("#commID").val() != "") {
					$("#commID").val($("#commID").val() + "," + $(this).val());
				} else {
					$("#commID").val($(this).val());
				}				
			}
		});	
		
		if (count == 1) {
			// each checkbox value is the name of the community, i.e. Las Olas = las-olas, which is page "villages-las-olas.html"			
			$("#listings-form").attr('action','villages-' + selectedVillage + '.html');
		} else {
			// if there is more than one selected, forward them to the 
			$("#listings-form").attr('action','villages.html');
		}
	});
	
	$('#refinesearchbtn').click(function() {
		if (jQuery.url.attr("file") == $("#listings-form").attr('action')) {
			$("#resultsWrapper").html('<p style="margin-left:320px;"><img src="images/ajax-loader.gif" /><p>');
			setTimeout( function()
			{
				resetHeight($(".content-cols"));
				ListMarbellaProducts($("#commID").val(),"true");
				
			}, 500);
			
			return false;
		}
	});
	
	//empty list of community IDs stored in the hidden field initially if parameters are passed to the page
	if (jQuery.url.param("x") != undefined) {
		$("#commID").val("");
	}
	
      	// if parameters passed, then set form to reflect selections	
	$('#listings-form :input').each(function() {		
	
		// setup checkboxes
		
		// check to see if this villages page was click directly, or we were sent here by the form
		if (jQuery.url.param("x") != undefined) {
					
			if ($(this).attr('type') == 'checkbox') {
				if (jQuery.url.param($(this).attr('name')) != undefined) {
					$(this).attr("checked", true);

					if ($("#commID").val() != "") {
						$("#commID").val($("#commID").val() + "," + $(this).val());
					} else {
						$("#commID").val($(this).val());
					}
				} else {
					$(this).attr("checked", false);
				}
			}

			// setup select boxes
			if ($(this).attr('type') == 'select-one') {
				if (jQuery.url.param($(this).attr('name')) != undefined) {
					paramName = $(this).attr('name');
					$('#' + $(this).attr('name') + " :option").each(function() {
						if ($(this).val() == jQuery.url.param(paramName)) {
							$(this).attr("selected", true);
						}
					});
				}
			}
		}
	});
	
	//alert($("#commID").val());
	
	
} 
