function go(toelement) {
	if(toelement.options[toelement.selectedIndex].value.length>0){
		location = toelement.options[toelement.selectedIndex].value;
	}
}

function searchToggle(songID) {
	if ((document.getElementById("name_" + songID).bgColor).toUpperCase() == "#FFFFFF" || document.getElementById("name_" + songID).bgColor == "") {
		document.getElementById("name_" + songID).bgColor = "#FF8E1F";
		document.getElementById("length_" + songID).bgColor = "#FF8E1F";
		document.getElementById("artist_" + songID).bgColor = "#FF8E1F";
		document.getElementById("name_span_" + songID).className = "search_text_white";
		document.getElementById("length_span_" + songID).className = "search_text_white";
		document.getElementById("artist_span_" + songID).className = "search_text_white";
		document.getElementById("details_" + songID).style.display = "block";
		document.getElementById("info_" + songID).src = "images/btn_info2_over.gif";
	} else {
		document.getElementById("name_" + songID).bgColor = "#FFFFFF";
		document.getElementById("length_" + songID).bgColor = "#FFFFFF";
		document.getElementById("artist_" + songID).bgColor = "#FFFFFF";
		document.getElementById("name_span_" + songID).className = "search_text_black";
		document.getElementById("length_span_" + songID).className = "search_text_grey";
		document.getElementById("artist_span_" + songID).className = "search_text_grey";
		document.getElementById("details_" + songID).style.display = "none";
		document.getElementById("info_" + songID).src = "images/btn_info2.gif";
	}
}

function infoRollOver(tmpID) {
	if ((document.getElementById("name_" + tmpID).bgColor).toUpperCase() == "#FFFFFF" || document.getElementById("name_" + tmpID).bgColor == "") {

			document.getElementById("info_" + tmpID).src = (document.getElementById("info_" + tmpID).src).replace(".gif", "_over.gif");

	}
}

function infoRollOut(tmpID) {
	if ((document.getElementById("name_" + tmpID).bgColor).toUpperCase() == "#FFFFFF" || document.getElementById("name_" + tmpID).bgColor == "") {

			document.getElementById("info_" + tmpID).src = (document.getElementById("info_" + tmpID).src).replace("_over.gif", ".gif");	

	}
}

function rollOver(tmpID) {
	if ((document.getElementById(tmpID).src).indexOf("_over.gif") == -1) {
		document.getElementById(tmpID).src = (document.getElementById(tmpID).src).replace(".gif", "_over.gif");
	} else {
		document.getElementById(tmpID).src = (document.getElementById(tmpID).src).replace("_over.gif", ".gif");	
	}
}

function searchKeyword() {
	if (document.getElementById("q").value == "") {
		alert ("Please enter a keyword.");
		return false;
	} else {
		document.getElementById("search").submit();
	}
}

function searchFilter() {
	if (document.getElementById("moods").value == "" && document.getElementById("cat").value == "" && document.getElementById("beats").value == "" && document.getElementById("length").value == "" && document.getElementById("tempo").value == "" && document.getElementById("inst").value == "") {
		alert ("Please select filters.");
	} else {
		document.getElementById("filter").submit();
	}
}

function checkAll(fmobj) {
  for (var i=0;i<fmobj.elements.length;i++) {
    var e = fmobj.elements[i];
    if ( (e.name != 'allbox') && (e.type=='checkbox') && (!e.disabled) ) {
      e.checked = fmobj.allbox.checked;
    }
  }
}

function showHide(toShow, toHide) {
	document.getElementById(toHide).style.display = "none";	
	document.getElementById(toHide).style.position = "absolute";
	document.getElementById(toShow).style.display = "block";
	document.getElementById(toShow).style.position = "relative";
}

var globalFormObj;
var globalPlaylistID;

function doAction(selectObj, formObj, actionType, actionString) {
	var checks = 0;
	
	if (actionType == "addtoplaylistdropdown") {
		document.getElementById("pldropdown").style.display = "block";
		return;
	}
	
	for (var i=0;i<formObj.elements.length;i++) {
		var e = formObj.elements[i];
		if ( (e.name != 'allbox') && (e.type=='checkbox') && (!e.disabled) ) {
			if (e.checked) {
				checks++;	
			}
		}
	}
	
	if (checks == 0 && actionType.indexOf("license_tracks&licensepl=yes") == -1) {
		alert ("Please select at least one item.");
		selectObj.selectedIndex = 0;
		return;
	}
	
	if (actionType.indexOf("license_tracks") != -1 || actionType.indexOf("song_dl") != -1 || actionType.indexOf("admin_mark_tickers") != -1 || actionType.indexOf("admin_mark_playlists") != -1) {
		selectObj.selectedIndex = 0;
		formObj.action = '?action=' + actionType + actionString;
		formObj.submit();
	} else if (actionType != "") {
		selectObj.selectedIndex = 0;
		formObj.action = '?action=' + actionType + actionString;
		//formObj.submit();
		globalFormObj = formObj;
	}
	
	if (actionType == "delplaylistitem") {
		openPopup("html/popup_delete_track.html", 400, 200);
	}
	
	if (actionType == "admin_delticker" || actionType == "admin_deluser" || actionType == "admin_delsong" || actionType == "delplaylist" || actionType == "admin_delfrompl") {
		openPopup("html/popup_delete.html", 400, 200);
	}
}

function doAction2(formObj, actionType, actionString) {
	var checks = 0;
	
	if (actionType != "") {
		formObj.action = '?action=' + actionType + actionString;
		//formObj.submit();
		globalFormObj = formObj;
	}
	
	if (actionType == "admin_delticker" || actionType == "admin_deluser" || actionType == "admin_delsong" || actionType == "delplaylist" || actionType == "admin_delfrompl" || actionType == "admin_delcat" || actionType == "admin_delsubcat") {
		openPopup("html/popup_delete.html", 400, 200);
	}
}

function doDeletePlaylist(playlistID) {
	globalPlaylistID = playlistID;
	openPopup("html/popup_delete_playlist.html", 400, 200);
}

function openPopup(popupFile, popupWidth, popupHeight) {
    var leftPos = (screen.width - popupWidth) / 2;
    var topPos = (screen.height - popupHeight) / 2;

	winObj = window.open(popupFile,"popup",'scrollbars=1,width=' + popupWidth + ',height=' + popupHeight + ',top=' + topPos + ',left=' + leftPos);
	if(!winObj.opener){ winObj.opener = this.window; }
	winObj.focus();
}

function globalFormSubmit(popupObj) {
	popupObj.close();
	globalFormObj.submit();	
}

function globalDeletePlaylist(popupObj) {
	popupObj.close();
	location.href = "../?action=delplaylist&playlist=" + globalPlaylistID;
}

function validateForm(tmpForm, requiredFields){
	var validated = true;
	var requiredSplit = requiredFields.split(",");
	for (x=0; x<requiredSplit.length; x++) {
		if (eval(tmpForm + "." + requiredSplit[x] + ".value") == "") {
			alert(requiredSplit[x] + " is a required field.");
			eval(tmpForm + "." + requiredSplit[x] + ".focus()");
			validated = false;
			break;
		}
	}
	
	if (requiredFields.indexOf("accept") != -1 && validated == true) {
		if (eval(tmpForm + ".accept.checked") == false) {
			alert("You must agree to the terms.");
			eval(tmpForm + ".accept.focus()");
			validated = false;
		}
	}
	
	if (validated) {
		eval(tmpForm + ".submit()");
		return true;
	}
}

function goFrame(url) {
	window.document.cookie = "url=" + url;
	location.href = "./?action=main";
}
