//-------perform new search

function sendWithGet(_url){
	window.location.href = _url;
}

	//perform new search
	function search() {
		document.frmSearch.page.value = 1;
		_phrase = document.frmSearch.phrase.value;
		
		//if (_phrase.length > 0 && _phrase.length < 4 ) {
		//	window.alert('Cannot search for words less 4 characters.');
		//} else {
			document.frmSearch.submit();
		//}
	}
	
	//trun pages forward and backward
	function nextPage(_page) {
		if (_page <= 0) 
			_newpage = 1;
		else
			_newpage = _page;
		
		document.frmSearch.page.value=_newpage;
		document.frmSearch.submit();
	}

	//reset form and clear all fields
	function clearForm() {
		document.frmSearch.phrase.value = '';
		document.frmSearch.title.value = '';
		document.frmSearch.author.value = '';
		document.frmSearch.publisher.value = '';
	}
	
	function changeEnabledElements() {
		//alert('Code Language:' + document.frmSearch.code_language.value + ';');
		//alert('Type:' + document.frmSearch.type[0].checked);
		cur_selection = document.frmSearch.code_language.value;
		//check language 
		if (cur_selection == -1) {
			//disable input text fields
			document.frmSearch.phrase.disabled = true;
			//set empty value to disabled input text fields
			document.frmSearch.phrase.value = '';
		} else {
			document.frmSearch.phrase.disabled = false;
		}//end language
		
	}

	//print index for titles or authors
	function titleIndex() {
		
		document.frmFullIndexTitle.code_language.value = document.frmSearch.code_language.value;
		
		document.frmFullIndexTitle.submit();
	}

	function authorIndex() {
		document.frmFullIndexAuthors.code_language.value = document.frmSearch.code_language.value;
		document.frmFullIndexAuthors.submit();
		
	}
	
	function publisherIndex() {
		document.frmFullIndexPublisher.code_language.value = document.frmSearch.code_language.value;
		document.frmFullIndexPublisher.submit();
		
	}
//----- RICERCA

jQuery(document).ready(function(){
$("#l").change(function() {
	   //myalt = "suggest_title.php?code_language=" + this.value;
	   //$('#title').attr('alt', myalt );

	   //title
		$(".suggest").each(function(){
			var _alt = this.alt;
			//alert(_alt);
			var p = _alt.indexOf("=");
			_alt = _alt.substring(0,p+1) + $('#l').val();
		//	alert(_alt);
			
			var _options = $(this).metadata();
			if(_alt.length > 0){
				$(this).autocomplete(_alt, _options);
			}
		});
		//authors
		$(".suggest1").each(function(){
			var _alt = this.alt;
			var p = _alt.indexOf("=");
			_alt = _alt.substring(0,p+1) + $('#l').val();
			//alert(_alt);
			var _options = $(this).metadata();
			if(_alt.length > 0){
				$(this).autocomplete(_alt, _options);
			}
		});
		
		//publisher
		$(".suggest2").each(function(){
			var _alt = this.alt;
			var _options = $(this).metadata();
			var p = _alt.indexOf("=");
			_alt = _alt.substring(0,p+1) + $('#l').val();
			//alert(_alt);
			if(_alt.length > 0){
				$(this).autocomplete(_alt, _options);
			}
		});
	   
	});
	
$('#divshow').click(function(){
	
	if( $('#divshow').hasClass('dclose')) {
		$('#divshow').removeClass('dclose');
		$('#divshow').addClass('dopen');
		$('#screen-box').slideDown("slow");	
		$('#divshow').html('&nbsp;');
		$('#phrase').focus();
	}
	else {
		$('#divshow').removeClass('dopen');	
		$('#divshow').addClass('dclose');
		$('#screen-box').slideUp(600);	
	}

		return false;

	});	


$('#divhide').click(function(){
	$('#screen-box').slideUp(600);
	$('#divshow').html('More Options');
	return false;
	});	

$('#btFormReset').click(function(){
	$('#title').val('');
	$('#phrase').val('');
	$('#author').val('');
	$('#l').val('-1');
	$('#publisher').val('');
	return false;
});	

$('.selected').click(function() {
	var phrase = $(this).html();
	var lang = $('#l').val();
	window.open('http://www.logosdictionary.eu/index.php?phrase=' + phrase + '&from=' + lang + '&newsearch=1');
	
});


});
