
	soundManager.debugMode = false;
	soundManager.url = 'swf/'

	function keyPressHandler(event)
	{
		if (event.keyCode == 13)
		{
			if (event.target.id.search(/^adm_pl_/) != -1)
				return false;
		}
	}

	function mp3_reset_button(id, file)
	{
		a_element = document.getElementById(id);
		a_element.setAttribute('class', 'link mp3_button_play');
		a_element.onclick = function onclick(event) { mp3_play(id, file); }
	}

	function mp3_play(id, file)
	{
		soundManager.stopAll();
		a_element = document.getElementById(id);
		a_element.setAttribute('class', 'link mp3_button_stop');
		a_element.onclick = function onclick(event) { mp3_stop(id, file); }
		soundManager.play(id, file);
		soundManager.play(id, { onstop: function () { mp3_reset_button(id, file); } } );
		soundManager.play(id, { onfinish: function () { mp3_reset_button(id, file); } } );
	}

	function mp3_stop(id, file)
	{
		soundManager.stop(id);
		mp3_reset_button(id, file);
	}

	function vote(tid, weight, hash)
	{
		if (weight == 'positive')
			spanid = hash + "_pos_span";
		else
			spanid = hash + "_neg_span";

		req = new XMLHttpRequest();

		req.onreadystatechange = function() {
			if (req.readyState == 4 && req.status == 200)
			{
				span_element = document.getElementById(spanid);
				span_element.innerHTML = parseInt(span_element.innerHTML) + 1;

				img_element = document.getElementById(hash + "_pos_img");
				img_element.src = "images/no-like17.png";
				img_element.onclick = "";
				img_element.setAttribute('class', 'vote_button');

				img_element = document.getElementById(hash + "_neg_img");
				img_element.src = "images/no-dislike17.png";
				img_element.onclick = "";
				img_element.setAttribute('class', 'vote_button');				

				alert("Vielen Dank für Deine Stimme!");
			}
			else if (req.readyState == 4 && req.status == 403)
			{
				alert("Du hast bereits für diesen Titel abgestimmt.");
			}
		}

		query = ("?tid=" + tid + "&weight=" + weight); 
		req.open("GET", "tools/vote.php" + query, true);
		req.send();
	}

	function show(id)
	{
		elements = document.getElementsByTagName('div');
		for (i in elements)
		{
			if (elements[i].className == "window")
				elements[i].style.display = (elements[i].id == id) ? "block" : "none";
		}

		element = document.getElementById(id);
		if (element.innerHTML != '') return;

		req = new XMLHttpRequest();

		req.onreadystatechange = function() {
			if (req.readyState == 4 && req.status == 200)
				element.innerHTML = req.responseText;
		}

		filename = "menu_" + id + ".php";
		req.open("GET", filename, true);
		req.send();
	}

	function load_playlist(id, target)
	{
		element = document.getElementById(target);

		req = new XMLHttpRequest();

		req.onreadystatechange = function() {
			if (req.readyState == 4 && req.status == 200)
				element.innerHTML = req.responseText;
		}

		query = (id == -1) ? "" : ("?id=" + id); 
		req.open("GET", "tools/playlist.php" + query, true);
		req.send();
	}

	function toggle_element(id)
	{
		element = document.getElementById(id);
		element.style.display = (element.style.display == "none") ? "" : "none";
	}

	function resetForm()
	{
		elements = document.getElementsByTagName('div');
		for (i = 0; i < elements.length; i++)
		{
			if (elements[i].className.match(/^adm_pl_[a-z]+_item$/))
			{
				elements[i].parentNode.removeChild(elements[i]);
				i--;
			}
		}

		element = document.getElementById('adm_pl_before_item_count');
		if (element != null) element.parentNode.removeChild(element);
		element = document.getElementById('adm_pl_halftime_item_count');
		if (element != null) element.parentNode.removeChild(element);
		element = document.getElementById('adm_pl_after_item_count');
		if (element != null) element.parentNode.removeChild(element);
	}

	function plus(id)
	{
		element = document.getElementById(id);

		item_count = document.getElementById(id + '_item_count');
		if (item_count == null)
		{
			index = 0;
			item_count = document.createElement('span');
			item_count.style.display = "none";
			item_count.setAttribute('id', id + '_item_count');
			item_count.innerHTML = index + 1;
			element.appendChild(item_count);
		}
		else
		{
			index = item_count.innerHTML;
			item_count.innerHTML = (index - 1) + 2;
		}

		div_element = document.createElement('div');
		div_element.setAttribute('class', id + '_item');
		div_element.setAttribute('name', id + '_item_' + index);

		nat_select_element = document.createElement('select');
		nat_select_element.setAttribute('id', id + '_nationality_' + index);
		nat_select_element.setAttribute('name', id + '_nationality_' + index);

		select_template = document.getElementById('nationality_template');
		options = select_template.options
		for (i = 0; i < options.length; i++)
		{
			nat_option_element = document.createElement('option');
			nat_option_element.setAttribute('name', options.item(i).value);
			nat_option_element.setAttribute('value', options.item(i).value);
			nat_option_element.innerHTML = options.item(i).innerHTML;
			nat_select_element.appendChild(nat_option_element);
			if (options.item(i).value == 'de') nat_select_element.selectedIndex = nat_option_element.index;
		}

		div_element.appendChild(nat_select_element);

		artist_element = document.createElement('input');
		artist_element.setAttribute('id', id + "_artist_" + index);
		artist_element.setAttribute('name', id + "_artist_" + index);
		artist_element.setAttribute('value', '');
		artist_element.setAttribute('size', 22);
		div_element.appendChild(artist_element);
		initDropDown(artist_element);

		title_element = document.createElement('input');
		title_element.setAttribute('id', id + "_title_" + index);
		title_element.setAttribute('name', id + "_title_" + index);
		title_element.setAttribute('value', '');
		title_element.setAttribute('size', 22);
		div_element.appendChild(title_element);
		initDropDown(title_element);

		mp3input_element = document.createElement('input');
		mp3input_element.setAttribute('type', 'file');
		mp3input_element.setAttribute('id', id + "_mp3_" + index);
		mp3input_element.setAttribute('name', id + "_mp3_" + index);
		mp3input_element.setAttribute('size', 5);
		div_element.appendChild(mp3input_element);

		info_element = document.createElement('span');
		info_element.setAttribute('id', id + "_info_" + index);
		info_element.setAttribute('class', 'admin_entry_info');
		info_element.style.display = "none";
		div_element.appendChild(info_element);

		element.appendChild(div_element);
	}

