var playing_string = '> ';
var playing_animation_string = ' ...';
var playing_animation_position = 0;
var playing_animation = 0;
var global_playing_index = '-1';
var global_playing_item_oldstring = '';
var player_wnd_url = '';
var player_wnd_name = 'SpiritofReggaePlayer';
var player_wnd_params = 'width=470, height=365, left=0, location=no, menubar=no, resizable=yes, scrollbars=no, statusbar=no, toolbar=no, top=0';

/* Genutzt vom Player-Fenster*/

function do_playing_animation() {

	var artist = opener.document.getElementById('artist');
	var playing_index = opener.document.getElementById('playing_index').getAttribute('value');
	var playing_item_oldstring = opener.document.getElementById('playing_item_oldstring').getAttribute('value');

	if (playing_index > 0) {

		if (playing_index != global_playing_index) {
			stop(artist.options[global_playing_index], artist);
              	start_playing_animation();
		}
		else {
			playing_animation_position = playing_animation_position % (playing_animation_string.length) + 1;
			artist.options[playing_index].firstChild.data = playing_string + playing_item_oldstring + playing_animation_string.substr(0, playing_animation_position);
			global_playing_index = playing_index;
			global_playing_item_oldstring = playing_item_oldstring;
		}
	}
	else
		if (playing_index == -1) {//Seite wurde neu geladen
			opener.document.getElementById('playing_index').setAttribute('value', global_playing_index);
			opener.document.getElementById('playing_item_oldstring').setAttribute('value', global_playing_item_oldstring);
			artist.selectedIndex = global_playing_index;
			//alert(global_playing_index + ' ' + artist.selectedIndex);
		}
          else {		//Seite sagt: Stop!
			stop(artist.options[global_playing_index], artist);
               window.close();
          }
}

function start_playing_animation() {

	var artist = opener.document.getElementById('artist');
	global_playing_index = opener.document.getElementById('playing_index').getAttribute('value');
	var playing = artist.options[global_playing_index];
	global_playing_item_oldstring = playing.firstChild.data;

	opener.document.getElementById('playing_item_oldstring').setAttribute('value', playing.firstChild.data);
	playing.firstChild.data = playing_string + playing.firstChild.data;
	playing_animation_position = 0;
	playing_animation = setInterval("do_playing_animation()", 500);
}

function stop() {

	var artist = opener.document.getElementById('artist');

	clearInterval(playing_animation);
	artist.options[global_playing_index].firstChild.data = global_playing_item_oldstring;
}

/*--------------------------*/

function opener_play(obj, artist) {

	var artist = document.getElementById('artist');
	var playing_index = artist.selectedIndex;
	document.getElementById('playing_index').setAttribute('value', playing_index);
	window.open(player_wnd_url + obj.getAttribute('value'), player_wnd_name, player_wnd_params);
}

function opener_stop(obj, artist) {

	var artist = document.getElementById('artist');
	var playing_index = document.getElementById('playing_index').getAttribute('value');

	document.getElementById('playing_index').setAttribute('value', '0');
}

function play_stop() {

	var artist = document.getElementById('artist');
	var playing_index = document.getElementById('playing_index').getAttribute('value');
	var obj = artist.options[artist.selectedIndex];

//	alert(playing_index);

	if ((0 < playing_index) && (artist.options[playing_index].getAttribute('value') == obj.getAttribute('value')))
		opener_stop(obj, artist);
	else {
		opener_play(obj, artist);
	}
}

function enable_disable(obj) {

	if (obj.checked) {
		document.getElementById('name').removeAttribute('disabled');
		document.getElementById('strasse').removeAttribute('disabled');
		staat = document.getElementById('staat');
		staat_lang = document.getElementById('staat_lang');
		staat.removeAttribute('disabled');

		if ('anderer' == staat.options[staat.selectedIndex].text) {

			staat_lang.removeAttribute('disabled');
			staat_lang.value = '';
		}

		document.getElementById('plz').removeAttribute('disabled');
		document.getElementById('ort').removeAttribute('disabled');
	}
	else {
		document.getElementById('name').setAttribute('disabled', 'disabled');
		document.getElementById('strasse').setAttribute('disabled', 'disabled');
		document.getElementById('staat').setAttribute('disabled', 'disabled');
		document.getElementById('staat_lang').setAttribute('disabled', 'disabled');
		document.getElementById('plz').setAttribute('disabled', 'disabled');
		document.getElementById('ort').setAttribute('disabled', 'disabled');
	}
}

function set_staat_lang() {

	staat = document.getElementById('staat');
	staat_lang = document.getElementById('staat_lang');

	if ('anderer' == staat.options[staat.selectedIndex].text) {

		staat_lang.removeAttribute('disabled');
		staat_lang.value = '';
	}
	else {
		staat_lang.setAttribute('disabled', 'disabled');
		staat_lang.value = staat.options[staat.selectedIndex].text;
	}
}
