$(document).ready(function() {
	var controlWidth = 295;
	if (document.location.href.indexOf("find-rental.htm") != -1) {
		// find-a-rental page
		controlWidth = 405;
	} else if (document.location.href.indexOf("deals.htm") != -1) {
		// find-a-rental page
		controlWidth = 316;
	} else if (document.location.href.indexOf(".htm") == -1) {
		// home page
		controlWidth = 255;
	} else {
		// default
		controlWidth = 295;
	}
	$("#search").autocomplete("/search/autocomplete.htm", {
		delay: 100,
		minChars: 3, 
		max: 9,
		highlight: false,
		cacheLength: 10,
		matchSubset: false,
		width: controlWidth
	}).result(function() {
		var node = this;
		while (node.nodeName.toLowerCase() != "form")
			node = node.parentNode;
		// call submit after delay to allow all the chained events to finish execution
		window.setTimeout(function() {
			// call form's onSubmit() function if one exists since calling form.submit()
			// will NOT fire the onSubmit event
			if (node.onSubmit)
				node.onSubmit();
			
			//node.submit(); //commenting out to disable auto submit with wrong availability date fields
		}, 1);
		return true;
	});
});

