function GetChecked(name)
{
	var result = "";
	var inputs = document.getElementsByTagName("INPUT");
	for (var i = 0; i < inputs.length; i++)
	{
		var input = inputs.item(i);
		if (input.type == "checkbox" && input.name == name && input.checked)
		{
			if (result == "")
				result = input.value;
			else
				result += "|" + input.value;
		}
	}
	return result;
}

function SetCheck(name, check)
{
	var inputs = document.getElementsByTagName("INPUT");
	for (var i = 0; i < inputs.length; i++)
	{
		var input = inputs.item(i);
		if (input.type == "checkbox" && input.name == name)
			input.checked = check;
	}
}

function ReverseCheck(name)
{
	var inputs = document.getElementsByTagName("INPUT");
	for (var i = 0; i < inputs.length; i++)
	{
		var input = inputs.item(i);
		if (input.type == "checkbox" && input.name == name)
			input.checked = !input.checked;
	}
}

function Play(name, url)
{
	var id = GetChecked(name);
	if (id == "")
		return;
		
	window.open(url + "?ID=" + id, "_blank");
}

function AddLyric(id, url)
{
	window.open(url + "?ID=" + id, null, "width=500,height=400,menubar=no,toolbar=no,location=no,scrollbars=no,status=no,modal=yes");
}

function OnSearch(form, searchMusic, searchAlbum, searchStar, searchLyric)
{
	if (document.getElementById("SearchMusic").checked)
	{
		if (window.location.href.toLowerCase().lastIndexOf(searchMusic) != -1)
			window.location.href = searchMusic + "?q=" + escape(form.q.value);
		else
			window.open(searchMusic + "?q=" + escape(form.q.value), "_blank");
	}
	else if (document.getElementById("SearchAlbum").checked)
	{
		if (window.location.href.toLowerCase().lastIndexOf(searchAlbum) != -1)
			window.location.href = searchAlbum + "?q=" + escape(form.q.value);
		else
			window.open(searchAlbum + "?q=" + escape(form.q.value), "_blank");
	}
	else if (document.getElementById("SearchStar").checked)
	{
		if (window.location.href.toLowerCase().lastIndexOf(searchStar) != -1)
			window.location.href = searchStar + "?q=" + escape(form.q.value);
		else
			window.open(searchStar + "?q=" + escape(form.q.value), "_blank");
	}
	else if (document.getElementById("SearchLyric").checked)
	{
		if (window.location.href.toLowerCase().lastIndexOf(searchLyric) != -1)
			window.location.href = searchLyric + "?q=" + escape(form.q.value);
		else
			window.open(searchLyric + "?q=" + escape(form.q.value), "_blank");
	}
	
	return false;
}