startList = function() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("useroptions");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
}
window.onload=startList;

function SiteSearch(searchterm) {
    document.siteSearch.searchFor.value = searchterm ;
    searchSite();
}

function searchSite() {
	document.getElementById('searchSubmitDiv').style.display = 'none' ;
	document.getElementById('searchSpinnerDiv').style.display = 'inline' ;
	new Ajax.Updater('searchResults', '/core/sitesearch.php?searchWhat='+document.siteSearch.searchWhat.value+'&searchFor='+document.siteSearch.searchFor.value+'&user='+document.siteSearch.user.value, {asynchronous:true, evalScripts:true});
}

function clearSearch() {
	document.getElementById('searchSubmitDiv').style.display = 'inline' ;
	document.getElementById('searchSpinnerDiv').style.display = 'none' ;
	document.siteSearch.searchFor.value = '' ;
	Effect.BlindUp("searchResults") ;
}

function advancedSearchSelect() {
	if(document.siteSearch.searchWhat.value == "Music") window.location = '/music/search.php'
	else if(document.siteSearch.searchWhat.value == "Forums") window.location = '/forums/search.php'
	else if(document.siteSearch.searchWhat.value == "Artists") window.location = '/artists/search.php'

}

function toggleLogin(val) {
	if(val == 0) {
		document.getElementById('joinBox').style.display = 'none' ;
		document.getElementById('joinText').style.display = 'none' ;
		document.getElementById('loginBox').style.display = 'inline' ;
		document.getElementById('loginText').style.display = 'inline' ;
	} else if (val == 1) {
		document.getElementById('loginBox').style.display = 'none' ;
		document.getElementById('loginText').style.display = 'none' ;
		document.getElementById('joinBox').style.display = 'inline' ;
		document.getElementById('joinText').style.display = 'inline' ;
	}
}

function markUnread() {
	document.selected.action.value = 'unread';
	document.selected.submit() ;
}
function markRead() {
	document.selected.action.value = 'read';
	document.selected.submit() ;
}
function movetoTrash() {
	document.selected.action.value = 'trash';
	document.selected.submit() ;	
}
function permanentlyDelete() {
	if(confirm('Are you sure you want to permanently delete these messages?')) {
		document.selected.action.value = 'delete';
		document.selected.submit() ;	
	}
}
function selectAll(status) {
	for (i = 0; i < document.selected.length; i++) {
		document.selected.elements[i].checked = status;
		if(status == true) {
			document.getElementById("selectlink").innerHTML = "<a href='javascript:selectAll(false);'>Select</a>" ;
		} else {
			document.getElementById("selectlink").innerHTML = "<a href='javascript:selectAll(true);'>Select</a>" ;
		}
	}
}
function selectAllArchive(status) {
	for (i = 0; i < document.selected.length; i++) {
		document.selected.elements[i].checked = status;
		if(status == true) {
			document.getElementById("selectlink").innerHTML = "<a href='javascript:selectAllArchive(false);'>Archive</a>" ;
		} else {
			document.getElementById("selectlink").innerHTML = "<a href='javascript:selectAllArchive(true);'>Archive</a>" ;
		}
	}
}
function send() {
	if(document.send.compose_subject.value.length < 1) { alert('You must enter a subject') ; return false ; } else {	
	if(document.send.compose_text.value.length < 1) { alert('You must enter a message') ; return false ; } else {
	document.send.submit() }}
}
function passwordclear() {
	document.getElementById('newpassword').innerHTML = '<input type="password" name="new_password" size="30" id="newpasswordfield">' ;
	document.getElementById('confirmpassword').innerHTML = '<input type="password" name="new_password_confirm" size="30">' ;
	document.accountpreferences.new_password.focus();
}
function validateAccountPrefs() {
	if(document.accountpreferences.new_email.value.length < 5) { alert('Please enter a valid email address') ; return false ; }
	if(document.accountpreferences.new_password.value == 'Leave blank to keep old password') { document.accountpreferences.new_password.value = '' ; }
	if(document.accountpreferences.new_password.value == 'Leave blank to keep old password') { document.accountpreferences.new_password.value = '' ; }
	if(document.accountpreferences.new_password_confirm.value == 'Leave blank to keep old password') { document.accountpreferences.new_password_confirm.value = '' ; }
	if(document.accountpreferences.new_password.value != '') {
		if(document.accountpreferences.new_password.value.length < 6) { alert('Please enter a password with 6 characters or more') ; return false ; }
	}
	if(document.accountpreferences.new_password.value != document.accountpreferences.new_password_confirm.value) { alert('Your passwords do not match') ; return false ; }
}
function changeURL(newurl) {
	if(newurl != '') {
		document.getElementById('artisticonimg').innerHTML = "<img src='" + newurl + "' alt='icon' width='45' />" ;
		/* document.artisticon.artisticonurl.value = newurl ; */
		document.artisticon.artisticonurlhide.value = newurl ;
	}
}
function changeView(newview) {
	if(newview == 'url') {
		document.getElementById('aiurl').style.display = "block" ;
		document.getElementById('aigallery').style.display = "none" ;
		document.getElementById('aiupload').style.display = "none" ;
	}
	else if(newview == 'gallery') {
		document.getElementById('aiurl').style.display = "none" ;
		document.getElementById('aigallery').style.display = "block" ;
		document.getElementById('aiupload').style.display = "none" ;
	}
	else if(newview == 'upload') {
		document.getElementById('aiurl').style.display = "none" ;
		document.getElementById('aigallery').style.display = "none" ;
		document.getElementById('aiupload').style.display = "block" ;
	}
		document.artisticon.artisticontype.value = newview ;
}
function checkContribution() {
	if(isNaN(document.contribute.contribution.value)) {
		alert("You have entered an invalid character for the amount of your contribution. Please enter a number.") ;
		document.contribute.contribution.value = "0" ;
		return false ;
	} else if(document.contribute.contribution.value < 1) {
		alert("You have entered an invalid amount for your contribution. Please enter an amount greater than $1.") ;
		document.contribute.contribution.value = "0" ;
		return false ;
	}  else { return true ; }
}

var sideTab = 1 ;
var permAuto = "true" ;

function sidebarFocus(tab,auto) {
        sideTab = tab ;
        document.getElementById('sidetab1').style.background = "#FFFFFF" ;
        document.getElementById('sidetab1').style.padding = "4px 0px 0px 0px" ;
        document.getElementById('sidetab2').style.background = "#FFFFFF" ;
        document.getElementById('sidetab2').style.padding = "4px 0px 0px 0px" ;
        document.getElementById('sidetab3').style.background = "#FFFFFF" ;
        document.getElementById('sidetab3').style.padding = "4px 0px 0px 0px" ;
        document.getElementById('sidelink1').style.color = "#192AA1" ;
        document.getElementById('sidelink2').style.color = "#192AA1" ;
        document.getElementById('sidelink3').style.color = "#192AA1" ;
        document.getElementById('sidetab' + tab).style.background = "#354b56" ;
        document.getElementById('sidetab' + tab).style.padding = "4px 1px 0px 0px" ;
        document.getElementById('sidelink'  + tab).style.color = "#FFFFFF" ;
        
    if(tab == 1) {
        document.getElementById('servAdFree').innerHTML = '<a href="/site/adfree/"><img src="/core/images/sidebar-adfree.jpg" border="0" alt="Ad Free" /></a>' ;
    } else if(tab == 2) {
        document.getElementById('servAdFree').innerHTML = '<a href="/site/podcasts/"><img src="/core/images/sidebar-podcasts.jpg" border="0" alt="Artist Podcasts" /></a>' ;
    } else if(tab == 3) {
        document.getElementById('servAdFree').innerHTML = '<a href="/site/albums/"><img src="/core/images/sidebar-albums.jpg" border="0" alt="Artist Albums" /></a>' ;
    }
    if(auto == 'false') permAuto = 'false' ;
    if(auto == 'true' && permAuto == 'true') changeSidebar() ;
}

function changeSidebar() {
    var timeout;
    if(sideTab == 1) { timeout = setTimeout("sidebarFocus(2,'true')",5000) ; }
    else if(sideTab == 2) { timeout = setTimeout("sidebarFocus(3,'true')",5000) ; }
    else if(sideTab == 3) { timeout = setTimeout("sidebarFocus(1,'true')",5000) ; }
    else { alert("error") ; }
}

function showArtistFavorites(uid) {
  document.getElementById('favoritesbox').innerHTML = '<div align="center"><img src="/core/images/spinner.gif" alt="processing" /></div>' ;
  new Ajax.Updater('favoritesbox','/core/artists-inc/ajax-favorites.php', {method:'post', postBody:"uid="+uid,evalScripts:true});
}