function categoryUpdate(cat)
{
	var album = document.getElementById('album_pick');
	album.options.length=0;
	
	var cid = cat.value;
	
	albums = categories[cid]['albums'];
	
	for (aid in albums)
	{
		album.options[album.options.length] = new Option(albums[aid], aid);
	}
	album.options[album.options.length] = new Option('New...', 'N');
	
	if (album.options.length == 1)
		albumUpdate(album);
}

function albumUpdate(album)
{
	if (album.value == 'N')
	{
		var i = album.options.length;
		var newalbum = prompt('Enter a name for the new album','');
		if (!newalbum)
			return false;
		album.options[i-1] = new Option(newalbum,'--'+newalbum);
		album.options[i] = new Option('New Album...', 'N');
		album.selectedIndex = i-1;
	}
	return true;
}

function ImageUploader_UploadFileCountChange()
{
	var iu = getImageUploader("ImageUploader1");
	
	var uploadFileCount = iu.getUploadFileCount();
	
	if (uploadFileCount == 0)
		document.getElementById('UploadButton').disabled = true;
	else
		document.getElementById('UploadButton').disabled = false;
	
}

function ImageUploader_AfterUpload(html)
{
	if (html == 'failed')
	{
		alert("Sorry, there was an error processing the uploads\n\n"+
			  "Please try again later");
		return;
	}
	
	if (html == 'bad album')
	{
		alert("You have not entered an album name");
		return;
	}
	
	document.open();
    document.write(html);
	document.close();
}



function UploadButton_click()
{
	if (!albumUpdate(document.getElementById('album_pick')))
	{
		alert('You have not entered an album name');
		return false;
	}
	
	var iu = getImageUploader("ImageUploader1");
	iu.Send();
}
