var demo_path = '/';
var go;
function get_id()
{
	var select_list_field = document.getElementById('limba1');
	var select_list_selected_index = select_list_field.selectedIndex;

	var text = select_list_field.options[select_list_selected_index].text;
	var value = select_list_field.value;
return (value);
}
function get_id_limba2()
{
	var select_list_field = document.getElementById('limba2');
	var select_list_selected_index = select_list_field.selectedIndex;

	var text = select_list_field.options[select_list_selected_index].text;
	var value = select_list_field.value;
return (value);
}
window.addEvent('domready', function() {
	// You can skip the following two lines of code. We need them to make sure demos
	// are runnable on MooTools demos web page.
	if (!window.demo_path) window.demo_path = '';
	
	// --
	//We can use one Request object many times.
	/*var inputWord = $('txt_search');
	// Our instance for the element with id "demo-word"
	go = new Autocompleter.Request.JSON(inputWord, demo_path+'autocomplete.php', {
		'indicatorClass': 'autocompleter-loading'
	});*/

	
	var inputWord = $('txt_search');
	 
	// Our instance for the element with id "demo-word2"
	new Autocompleter.Request.HTML(inputWord, demo_path+'autocomplete.php', {
		'indicatorClass': 'autocompleter-loading',
		/*'postData': {
			'extended': '1' // send additional POST data, check the PHP code
		},*/
		'injectChoice': function(choice) {
			// choice is one <li> element
			var text = choice.getFirst();
			// the first element in this <li> is the <span> with the text
			var value = text.innerHTML;
			// inputValue saves value of the element for later selection
			choice.inputValue = value;
			// overrides the html with the marked query value (wrapped in a <span>)
			text.set('html', this.markQueryValue(value));
			// add the mouse events to the <li> element
			this.addChoiceEvents(choice);
		}
	});

	
	
	$('limba1').addEvent('change', function() {
		
		
		$('limba2').disabled=true;
		$('txt_search').disabled=true;
		$('btn_submit').disabled=true;
		$('limba2').set('text', 'Se incarca...');
		var value = get_id();
		
		if(value!=0){
		var req = new Request.HTML({url:demo_path+'limba2.php?id='+value, 
			onSuccess: function(html) {
				//Clear the text currently inside the results div.
				$('limba2').set('text', '');
				//Inject the new DOM elements into the results div.
				$('limba2').adopt(html);
				$('limba2').disabled=false;
				$('txt_search').disabled=false;
				$('btn_submit').disabled=false;
			},
			//Our request will most likely succeed, but just in case, we'll add an
			//onFailure method which will let the user know what happened.
			onFailure: function() {
				$('limba2').set('text', 'The request failed.');
				alert('Eroare cand am incercat sa comunic cu serverul!');
			}
		});
		}else{
			$('limba2').disabled=true;
			$('txt_search').disabled=true;
			$('btn_submit').disabled=true;
		};
		//$('limba2').set('text', value);
		req.send();
	});
	
$('limba2').addEvent('change', function() {
		
		
		
		var value = get_id_limba2();
		
		if(value!=0){
		var req = new Request.HTML({url:demo_path+'limba2.php?id_dictionar_detalii='+value, 
			onSuccess: function(html) {
				//Clear the text currently inside the results div.
			},
			//Our request will most likely succeed, but just in case, we'll add an
			//onFailure method which will let the user know what happened.
			onFailure: function() {
				$('limba2').set('text', 'The request failed.');
				alert('Eroare cand am incercat sa comunic cu serverul!');
			}
		});
		}
		//$('limba2').set('text', value);
		req.send();
	});

});
