﻿var loading = '<div style="text-align:center; margin-top:10px"><img src="/images/loader.gif"><br />数据加载中...</div>';

function autoSuggest(textId, divId, type){
	options = {
		parameters		: 'type='+type,
		method			: 'get',
		frequency		: 0.3,
		updateElement	: function(item){$(textId).value = item.down().innerHTML;}
	};
	new Ajax.MyAutocompleter(textId, divId, '/suggestions.asp', options);
}

function showCalendar(fieldId, btnId, initDate){
	var tmpDate = new Date();
	var arg = arguments[3];
	$(fieldId).value = Calendar.printDate(initDate,'%Y-%m-%d');
	new Calendar({
		inputField: fieldId,
		dateFormat: '%Y-%m-%d',
		trigger: btnId,
		bottomBar: false,
		min: Calendar.dateToInt(tmpDate),
		max: Calendar.dateToInt(DateAdd('y', 2, tmpDate)),
		onSelect: function() {
			this.hide();
			if($(arg)) $(arg).value = Calendar.printDate(DateAdd('d', 3, Calendar.intToDate(this.selection.get())),'%Y-%m-%d');																								
		}
	});
}

Ajax.MyAutocompleter = Class.create(Ajax.Autocompleter, {
	initialize: function($super, element, update, url, options){
		$super(element, update, url, options);
		//Event.observe(this.element, 'focus', this.onFocusHandler.bindAsEventListener(this));
	},
	onFocusHandler: function(e){
		var element = Event.element(e);
		element.focus();
		element.select();
		var q = this.options.parameters.split('=')[1];
		var tmpArr = (q == 'gj_hotel') ? cityList2 : cityList1 
		var choices = '';
		for(var i = 0; i < tmpArr.length; i++){
			choices += '<li><span style="float:left">'+tmpArr[i][0]+'</span><strong style="float:right; text-align:right">'+tmpArr[i][1]+'</strong></li>';
		}
		choices = '<ul>' + choices + '</ul>';
		this.setDefault(choices);
	},
	setDefault: function(choices){
		this.changed = false;
		this.hasFocus = true;
		setTimeout(this.updateChoices(choices), 50);
	}
		//Event.observe(this.element, 'keyup', this.onKeyPressHandler.bindAsEventListener(this));
/*	onKeyPressHandler: function(e){
		var element = Event.element(e);
		if(element.value.strip() == '') this.setDefault('');
	},*/
});
