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/viewcatalog?id=" + parseInt(categoryId);
}

function showImage(photoId) {
    showDialog("/servlet/viewcatalogphoto?photoId="+parseInt(photoId) + "&show_add_to_cart_button=true",640,480);
}

function showImage1(photoId) {
    showDialog("/servlet/viewcatalogphoto?photoId="+parseInt(photoId), 640, 480);
}


function showOrderImage(photoId) {
	var height = 480;
	var width = 640;
	var link = "/servlet/vieworderphoto?photoId="+parseInt(photoId);
	var photo = window.open(link,"photo","height="+height+",width="+width+",status=no,toolbar=no,menubar=no,location=no, scrollbars=yes, resizable=yes");
	if (photo) photo.focus();
}


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/addcatalogcategory?parentId="+parseInt(selectedId),500,300);
}
function edit_category(){
	if (selectedId == null) {
		alert('Please, select a category.');
		return;
	}
    showDialog("/servlet/editcatalogcategory?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 Catalog. 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/deletecatalogcategory?id="+parseInt(selectedId);
    }
}
function upload_photo(){
	if (selectedId == null) {
		alert('Please, select a category.');
		return;
	}
	showDialog("/servlet/uploadcatalogphoto?categoryId="+parseInt(selectedId),600,450);
}
function replace_photo(){
	if (selectedPhotoId == null) {
		alert('Please, select a category.');
		return;
	}
	showDialog("/servlet/replacecatalogphoto?photoId=" + parseInt(selectedPhotoId),600,700);
}
function edit_photo_description(){
	if (selectedPhotoId == null) {
		alert('Please, select a category.');
		return;
	}
	showDialog("/servlet/editcatalogphotodescription?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 Catalog. There will not be an undo function. Are you absolutely sure you want to delete the image?")){
		document.location.href="/servlet/deletecatalogphoto?id=" + parseInt(selectedId) + "&photoId=" + parseInt(selectedPhotoId);
	}
}

function viewDescription(photoId) {
    showDialog("/servlet/viewcatalogdescription?id=" + parseInt(photoId),500,300);
}