
// Return a reference to a named ID.
function GetByName(name) {
	if (document.layers) // Netscape layers
		return document.layers[name];
	else if (document.getElementById) // DOM; IE5, NS6, Mozilla, Opera
		return document.getElementById(name);
	else if (document.all) // Proprietary DOM; IE4
		return document.all[name];
	else if (document[name]) // Netscape alternative
		return document[name];
	else return false;
}

// Show or hide a block element by ID.
function ShowElement(ref, show) {
	if (OldBrowser || !ref) return;
	if (ref.style) // DOM & proprietary DOM
		ref.style.visibility = show ? 'visible' : 'hidden';
	else if (ref.visibility) // Netscape
		ref.visibility = show ? 'show' : 'hide';
}

// Alter the display style of a div.
function SetDisplayStyle(ref, kind) {
	if (!ref) return;
	if (ref.style) ref = ref.style;
	ref.display = kind;
}

// Helper functions for showing/hiding divs.
function HideDiv(name)
	{ SetDisplayStyle(GetByName(name), 'none'); }
function ShowDiv(name)
	{ SetDisplayStyle(GetByName(name), 'block'); }

// Change one image into another.
function SetImage(name, new_img_url) {
	ref = GetByName(name);
	if (!ref) return;
	ref.src = new_img_url;
}

function GetEventButton(event) {
	var e = event;
	if (!event) e = window.event;
	if (event.which) return event.which;
	else if (event.button) return event.button;
	else return 1;
}

// Switch to a full-size image.
function ShowFull(event, image) {
	if (GetEventButton(event) < 2) {
		ShowDiv('full');
		HideDiv('small');
		SetImage('fullimg', image);
	}
}

// Switch to a small-size image.
function ShowSmall(event) {
	if (GetEventButton(event) < 2) {
		ShowDiv('small');
		HideDiv('full');
	}
}

// Switch to displaying an animation.
function ShowAni(event, name) {
	if (GetEventButton(event) < 2) {
		ShowDiv('full');
		HideDiv('small');
		frames['fullani'].location.href = "view.php?img=" + name + "&mode=raw";
	}
}

// Ask the user if they really want to delete this image;
// and if they answer yes, actually do the deletion.
function AskDelete(title, name) {
	var agree = confirm("Are you sure you want to delete this artwork?\n\n"
		+ "        \"" + title + "\"\n\n"
		+ "Warning: You cannot undo this action!\n");

	if (agree)
		window.location = "delete.php?img=" + name;
}

