var selectedPhotoId;

function selectPhotoActions(){
	if (selectedPhotoActions){
		for(var i=0; i < selectedPhotoActions.length; i++){
			var obj = document.getElementById(selectedPhotoActions[i]);
			if (obj){
				obj.className = 'action';
			}
		}
	}
}

function selectTreeItem(id, newStyle, oldStyle) {
    if (selectedId!=null){
		document.getElementById(selectedId).className = oldStyle;
	}
	selectedId = id;
	if (!document.getElementById(selectedId)) return;

	document.getElementById(selectedId).className = newStyle;

    selectActions();
}

function selectimg(idim){
	if (selectedPhotoId != null) {
		document.getElementById(selectedPhotoId).className = "imglink";
	}
	selectedPhotoId = idim;
	document.getElementById(selectedPhotoId).className = "imgselectlink";

	selectPhotoActions();
}

function goToCategory(categoryId) {
    document.location.href="/servlet/viewphotocategory?id=" + parseInt(categoryId);
}

function showImage(photoId) {
    showDialog("/servlet/viewphoto?photoId="+parseInt(photoId),640,480);
}


function view_photo_album(){
	alert('View Photo Album');
}
function view_category(){
	alert('View Category');
}
function view_photo(){
	alert('View Photo');
}
function add_category(){
	if (selectedId == null) {
		alert('Please, select a category.');
		return;
	}
    showDialog("/servlet/addcategory?parentId="+parseInt(selectedId),500,300);
}
function edit_category(){
	if (selectedId == null) {
		alert('Please, select a category.');
		return;
	}
    showDialog("/servlet/editcategory?id="+parseInt(selectedId),500,300);
}
function delete_category(){
	if (selectedId == null) {
		alert('Please, select a category.');
		return;
	}
	if (parseInt(selectedId) < 100){
		alert('You can\'t delete this catagory!');
		return;
	}
	if (confirm("This will permanently delete this category from the Art Gallery. If the category has any subcategories, they will be deleted as well. There will not be an undo function. Are you absolutely sure you want to delete the category?")) {
        document.location.href="/servlet/deletecategory?id="+parseInt(selectedId);
    }
}
function upload_photo(){
	if (selectedId == null) {
		alert('Please, select a category.');
		return;
	}
	showDialog("/servlet/uploadphoto?categoryId="+parseInt(selectedId),600,450);
}
function replace_photo(){
	if (selectedPhotoId == null) {
		alert('Please, select a category.');
		return;
	}
	showDialog("/servlet/replacephoto?photoId=" + parseInt(selectedPhotoId),600,700);
}
function edit_photo_description(){
	if (selectedPhotoId == null) {
		alert('Please, select a category.');
		return;
	}
	showDialog("/servlet/editphotodescription?photoId=" + parseInt(selectedPhotoId),550,430);
}
function delete_photo(){
    if (selectedPhotoId == null) {
		alert('Please, select a category.');
		return;
	}
	if (confirm("This will permanently delete this image from the Art Gallery. There will not be an undo function. Are you absolutely sure you want to delete the image?")){
		document.location.href="/servlet/deletephoto?id=" + parseInt(selectedId) + "&photoId=" + parseInt(selectedPhotoId);
	}
}

function viewDescription(photoId) {
    showDialog("/servlet/viewdescription?id=" + parseInt(photoId),500,300);
}