function deleteSubGallery()
{
	if (confirm("Are you sure you wish to permanently delete all photos in this sub gallery? This action is not undoable."))
	{
		document.forms[0].elements['action'].value = "delete_sub";
		document.forms[0].submit();
	}
	
	return;
}

function deleteMainGallery()
{
	if (confirm("Are you sure you wish to permanently delete all photos and sub galleries in this main gallery? This action is not undoable."))
	{
		document.forms[0].elements['action'].value = "delete_main";
		document.forms[0].submit();
	}
	
	return;
}


function setPic(picName)
{
	document.getElementById('displayPic').src = picName;
}

function deleteSelected()
{
	if (confirm('Are you sure you wish to delete the selected pictures'))
	{
		document.forms[0].submit();
	}
}

function updatePhotoInfo(picId)
{
	
	document.forms[0].elements['action'].value = "update";
	document.forms[0].elements['pic_id'].value = picId;
	document.forms[0].submit();
}

function createGallery(kind)
{
	var f = document.forms[0];
	if (kind == "sub")
	{
		var mainGalleryId = f['newMainGallery'].options[f['newMainGallery'].options.selectedIndex].value;
		window.open('pg_create_gallery.php?kind=sub&location=show&main_gallery_id=' + mainGalleryId, 'createGallery', 'toolbar=0, location=0, status=0, scrollbars=autos, width=900, height=800');
	}
	else
	{
		window.open('pg_create_gallery.php?kind=main&location=show', 'createGallery', 'toolbar=0, location=0, status=0, scrollbars=autos, width=900, height=800');
	}
}

function deleteEmptyGallery(kind, galleryId)
{
	var f = document.forms[0];
	if (confirm("Are you sure you want to delete this gallery along with any photos contained within?"))
	{
		if (kind == "sub")
		{
			f.elements['action'].value = "delete_sub";
			f.submit();
		}
	}
}

function updateSubGalleries(curIndex, mainGallery, subGallery)
{
	alert("Updating Subgalleries");
	var f = document.forms[0];
	var c = 0;
	var curMainGalleryId = f[mainGallery].options[curIndex].value;
	
	f[subGallery].options.length = 0;
	
	for (a=0; a<userGalleries.length; a++)
	{
		if (userGalleries[a][0] == curMainGalleryId)
		{
			f[subGallery].options[c] = new Option (userGalleries[a][2], userGalleries[a][1]);
			c++;	
		}
	}
	
	//If there are no sub galleries, make that known
	if (c == 0)
	{
		f[subGallery].options[0] = new Option ('No sub galleries defined', 0);
		f[subGallery].disabled = true;
		f['viewGalleryBtn'].disabled = true;
	}
	else
	{
		f[subGallery].disabled = false;
		f['viewGalleryBtn'].disabled = false;
	}
}

function showCart()
{
	window.open('pg_show_cart.php', 'ShoppingCart', 'location=0,status=0,scrollbars=1, resizable=1');
}

function checkout()
{
	window.open ('pg_view_cart.php', 'ShoppingCart', 'location=0,status=0,scrollbars=1,resizable=1,width=820 height=850');
}

function email(picId)
{
	window.open('pg_email.php?pic_id=' + picId, 'EmailPhoto', 'location=0,status=0,scrollbars=1, resizable=1, width=620 height=800');
}