/* $Header: /var/lib/cvs/ldb/www/ldb.js,v 1.4 2006/06/26 22:03:57 tim Exp $ */


function LDB_XMLHttpPost(strURL, strSubmit, strResultFunc)
{ var xmlHttpReq = false;

  // Mozilla/Safari
  if (window.XMLHttpRequest)
	{ xmlHttpReq = new XMLHttpRequest();
	}
  // IE
  else if (window.ActiveXObject)
	{ try
		{ xmlHttpReq = new ActiveXObject('Msxml2.XMLHTTP');
		}
	  catch (e)
		{ try
			{ xmlHttpReq = new ActiveXObject('Microsoft.XMLHTTP');
			}
		  catch (e)
			{}
		}
	}

  if (! xmlHttpReq)
	{ alert('Ihr Web-Browser unterstützt diese Funktion leider nicht (XMLHttpRequest). ' +
		'Wir empfehlen Mozilla Firefox oder Internet Explorer 6.');
	  return;
	}

  xmlHttpReq.open('POST', strURL, true);

  xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  xmlHttpReq.onreadystatechange = function()
	{ if (xmlHttpReq.readyState == 4)
		{ eval(strResultFunc + '(xmlHttpReq.responseText);');
		}
	}

  xmlHttpReq.send(strSubmit);
}


function LDB_AddSongToActiveSonglist(song_id)
{ LDB_XMLHttpPost(
	LDB_WWW + 'active_songlist',
	'add_song=' + escape(song_id),
	'LDB_RepaintSonglist_Callback'
	);
}


function LDB_RemoveSongFromActiveSonglist(song_id)
{ LDB_XMLHttpPost(
	LDB_WWW + 'active_songlist',
	'remove_song=' + escape(song_id),
	'LDB_RepaintSonglist_Callback'
	);
}


function LDB_SwitchActiveSonglist(songlist_id)
{ LDB_XMLHttpPost(
	LDB_WWW + 'active_songlist',
	'songlist=' + escape(songlist_id),
	'LDB_RepaintSonglist_Callback'
	);
}


function LDB_RepaintSonglist_Callback(str)
{ document.getElementById('active_songlist_div').innerHTML = str;
}


function LDB_SwitchHistoryMode(mode)
{ LDB_XMLHttpPost(
	LDB_WWW + 'history',
	'mode=' + escape(mode),
	'LDB_RepaintHistory_Callback'
	);
}


function LDB_RepaintHistory_Callback(str)
{ document.getElementById('history_div').innerHTML = str;
}


function LDB_DisplaySonglistPopup()
{ LDB_XMLHttpPost(
	LDB_WWW + 'songlist_popup',
	'mode=display_popup',
	'LDB_RepaintSonglistPopup_Callback'
	);
}


function LDB_RepaintSonglistPopup_Callback(str)
{ document.getElementById('songlist_popup_div').innerHTML = str;
}


function LDB_SonglistPopupChanged(newvalue)
{ if (newvalue.length > 0)
	LDB_SwitchActiveSonglist(newvalue);
}


function LDB_Songlist_RemoveSong(song_id)
{ LDB_Songlist_SubmitAction('remove_song', song_id);
}


function LDB_Songlist_MoveSongUp(song_id)
{ LDB_Songlist_SubmitAction('up', song_id);
}


function LDB_Songlist_MoveSongDown(song_id)
{ LDB_Songlist_SubmitAction('down', song_id);
}


function LDB_Songlist_SubmitAction(action_str, song_id)
{ var frm = document.forms[ 'songlist_action' ];

  frm.elements[ 'action[what]'    ].value = action_str;
  frm.elements[ 'action[song_id]' ].value = song_id;

  frm.submit();
}
