$(document).ready(function(){
	
	/*
	 * autocomplete: location
	 *
	 */
	$("#location").autocomplete("/manage/lookup_location", {
		width: 370,
		selectFirst: false,
		max: 40,
		minChars: 2,
		extraParams: {use_guid:1}
		/*
		// if using /assets/js/jquery.autocomplete.alt-full.js
		onItemSelect: function(li){
			alert( $(li).html() );			
		}
		*/		
	}).result(function(event, data, formatted){
		
		var loc_id = 0;
		if (data) {
			var loc_label = data[0];
			var loc_id		= data[1];
		}
		$('input#locations_guid').attr( 'title', loc_label ).val(loc_id);
	});
		
	/*
	 * implement spinboxes, datepickers, masked inputs, multiselects
	 *
	 */
	$("input.datepicker").datePicker( {clickInput: true, verticalOffset: 24} );
	
	/*
	 * clear out the locations guid if the user entered something new
	 *
	 */
	$('form#searchBasic').submit(function(){		
		var loc_orig = $('input#locations_guid').attr( 'title' );
		var loc_now  = $('input#location').val();		
		//alert('was = ' + loc_orig);
		//alert('now = ' + loc_now);
		if (loc_orig != loc_now) {
			$('input#locations_guid').val( '' );
			//alert('cleared guid');
		}
		return true;
	});
	
});