accentsTidy = function(s) {
	var r=s.toLowerCase();
	// r = r.replace(new RegExp("\\s", 'g'),"");
	// actung fuer vvk hier in latin1, dafuer gibt es suggestion-vvk.js (!)
    r = r.replace(new RegExp(/[àáâãå]/g),"a");
    r = r.replace(new RegExp(/æ/g),"ae");
    r = r.replace(new RegExp(/ç/g),"c");
    r = r.replace(new RegExp(/[èéêë]/g),"e");
    r = r.replace(new RegExp(/[ìíîï]/g),"i");
    r = r.replace(new RegExp(/ñ/g),"n");                
    r = r.replace(new RegExp(/[òóôõ]/g),"o");
    r = r.replace(new RegExp(/œ/g),"oe");
    r = r.replace(new RegExp(/[ùúû]/g),"u");
    r = r.replace(new RegExp(/[ýÿ]/g),"y");
	// r = r.replace(new RegExp("\\W", 'g'),"");
	return r;
}

function lookup(inputString) {
	if(inputString.length == 0) {
		// Hide the suggestion box.
		$("#suggestions").hide();
	} else if (inputString.length > 1) {
		data = '';
		$("#artist").children('option').each(function () {
			//artist = $(this).tml().replace(/['"]/g,'');
			vartist = $(this).html().replace(/["]/g,'');
			sartist = accentsTidy(vartist.replace('&amp;','&'));
			id = $(this).val();
			martist = sartist.replace(accentsTidy(inputString) , "<span class='suggestionMatch'>" + inputString + "</span>");
			if (martist != sartist) {
				data = data + "<li onclick='fill(" + id+ ", 1 )'>" + martist + "</li>";
			}
		});
		if (data) {
			data = "<li disabled='disabled' class='suggestionHeader'>K&uuml;nstler</li>" + data;
		}
		dataTitel = '';
		$("#vtitel").children('option').each(function () {
			vtitel = $(this).html().replace(/["]/g,'');
			stitel = accentsTidy(vtitel.replace('&amp;','&'));
			id = $(this).val();
			mtitel = stitel.replace(accentsTidy(inputString), "<span class='suggestionMatch'>" + inputString + "</span>");
			if (mtitel != stitel) {
				dataTitel = dataTitel + "<li onclick='fill(" + id+ ", -1 )'>" + mtitel + "</li>";
			}
		});
		if (dataTitel) {
			dataTitel = "<li disabled='disabled' class='suggestionHeader'>Veranstaltung</li>" + dataTitel;
			data = data + dataTitel;
		}
		dataStage = '';
		$("#stage").children('option').each(function () {
            vstage = $(this).html().replace(/["]/g,'');
			sstage = accentsTidy(vstage.replace('&amp;','&'));
			id = $(this).val();
            mstage = sstage.replace(accentsTidy(inputString) , "<span class='suggestionMatch'>" + inputString + "</span>");
			if (mstage != sstage) {
				dataStage = dataStage + "<li onclick='fill(" + id+ ", 0 )'>" + mstage + "</li>";
			}
		});
		if (dataStage) {
			dataStage = "<li disabled='disabled' class='suggestionHeader'>Veranstaltungsort</li>" + dataStage;
			data = data + dataStage;
		}
		if (!data) {
			data = "<li>... kein Treffer</li>";
		} 
		if (data) {
			$("#suggestions").show();
			$("#autoSuggestionsList").html(data);
		}
	}
} // lookup

function fill(nr,artist) {
	$("#inputString").val('');
	$("#suggestions").hide();
	if (artist == 1) {
		jumpTo(nr, 'tickerArtist');
	} else if (artist == -1) {
		jumpTo(nr, 'tickerTitel');
	} else {
		jumpTo(nr, 'tickerStage');
	}
}

function blurSuggestion() {
	$("#suggestions").hide();	
	$("#inputString").val('');
}


