var SearchEngine = {
	
	init: function() {
		var sorting = $('sorting');
		var pagination = $('pagination');		

		SearchEngine.changeMenu('USERNAME');
		
		Event.observe('search-types', 'change', function(event){
			var element = Event.element(event);
			var option = $A(element.options).find(function(n){
				if (n.selected) {
					return true;
				}
			});
			SearchEngine.changeMenu(option.value);
		});
	},
	
	changeMenu: function(type) {
		var menu = $('menu_busqueda_usuario');
		var html = '';
		menu.innerHTML = '';
		
		switch (type) {
			case 'USERNAME':
				html += "<input type='text' class='texto' name='keywords' />";
				new Insertion.Bottom(menu, html);
				break;
			case 'RESIDENCE':
				html += "<div style='position:relative'>";
				html += "<input type='text' class='texto ac_field' id='InputField' autocomplete='off' name='keywords'/>";
				html += "<script type='text/javascript'>var options = {script:'/users/autocomplete_residence/15?', varname:'input', json:true, minchars:3, delay:200, minWidth:300, maxWidth:300, hOffset:0, setWidth:true, shownoresults:false, maxresults:15, truehighlights:true}; InputField=new AutoCompleteDB('InputField', options);</script>";
				html += "</div>";
				new Insertion.Bottom(menu, html);
				break;
			case 'CURRENT_CITY':
				html += "<div style='position:relative'>";
				html += "<input type='text' class='texto ac_field' id='InputField' autocomplete='off' name='keywords'/>";
				html += "<script type='text/javascript'>var options = {script:'/users/autocomplete_residence/15?', varname:'input', json:true, minchars:3, delay:200, minWidth:300, maxWidth:300, hOffset:0, setWidth:true, shownoresults:false, maxresults:15, truehighlights:true}; InputField=new AutoCompleteDB('InputField', options);</script>";
				html += "</div>";
				new Insertion.Bottom(menu, html);
				break;
			case 'VISITED_COUNTRY':
				html += "<div style='position:relative'>";
				html += "<input type='text' class='texto ac_field' id='InputField' autocomplete='off' name='keywords'/>";
				html += "<script type='text/javascript'>var options = {script:'/users/autocomplete_country/?', varname:'input', json:true, minchars:3, delay:200, minWidth:300, maxWidth:300,  hOffset:0, setWidth:true, shownoresults:false, maxresults:15, truehighlights:true}; InputField=new AutoCompleteDB('InputField', options);</script>";
				html += "</div>";
				new Insertion.Bottom(menu, html);
				break;
			case 'TRAVEL_CITY':
				html += "<div style='position:relative'>";
				html += "<input type='text' class='texto ac_field' id='InputField' autocomplete='off' name='keywords'/>";
				html += "<script type='text/javascript'>var options = {script:'/users/autocomplete_residence/15?', varname:'input', json:true, minchars:3, delay:200, minWidth:300, maxWidth:300, hOffset:0, setWidth:true, shownoresults:false, maxresults:15, truehighlights:true}; InputField=new AutoCompleteDB('InputField', options);</script>";
				html += "</div>";				
				html += "<div id='date_picker'>";
				html += "<div style='z-index: 10; top: 100px;'>";
				html += "	<input type='text' id='ArrivalDate' readonly='readonly' style='cursor: pointer;' value='' class='formeditpeke' name='arrival_date'/>";
				html += "	<img align='absmiddle' alt='date' style='cursor: pointer;' id='imageArrivalDate' src='/img/date.png'/>";
				html += "	<script type='text/javascript'>var dpck = new DatePicker({relative: 'ArrivalDate', language: '" + Dictionary.language + "', topOffset: 20, leftOffset: 0, relativePosition: true, zIndex  : '100', cellClickCallback: Prototype.emptyFunction}); dpck.load();</script>";
				html += "</div>";
				html += "<div style='z-index: 10; top: 100px;'>";
				html += "	<input type='text' id='DepartureDate' readonly='readonly' style='cursor: pointer;' value='' class='formeditpeke' name='departure_date'/>";
				html += "	<img align='absmiddle' alt='date' style='cursor: pointer;' id='imageDepartureDate' src='/img/date.png'/>";
				html += "	<script type='text/javascript'>var dpck = new DatePicker({relative: 'DepartureDate', language: '" + Dictionary.language + "', topOffset: 20, leftOffset: 0, relativePosition: true, zIndex  : '100', cellClickCallback: Prototype.emptyFunction}); dpck.load();</script>";
				html += "</div>";
				html += "</div>";
				new Insertion.Bottom(menu, html);
				break;				
		}
	}
}