/* $Id: fileswap.js,v 2.2 2006/05/09 18:02:59 ray Exp $ */
function Lighten(obj) { obj.style.MozOpacity='0.9'; }
function Darken(obj)  { obj.style.MozOpacity='0.5'; }

function init() {
	if (window.Event) { document.captureEvents(Event.MOUSEMOVE); }

	document.onmousemove = getXY;
}

function ShowThumb(id,thumb) {
	var obj = document.getElementById(id);
	var path = '?cmd=thumb&width=100&filename='+thumb;
	var image = new Image();
	image.src = path;
	obj.style.top=posY+15;
	obj.style.left=posX+15;
	obj.style.border='2px outset #406294';
	obj.innerHTML='<img src="'+path+'"/>';
	obj.style.display='block';
	obj.style.visibility='visible';
}

function HideThumb(id) {
	var obj = document.getElementById(id);
	obj.style.visibility='hidden';
	obj.style.display='none';
	obj.innerHTML='';
}

var posX =0;
var posY =0;
window.onload = init;

function getXY(e) {
	posX = (window.Event) ? e.pageX : event.clientX;
	posY = (window.Event) ? e.pageY : event.clientY;
}

function toggleFields(off,on) {
	document.getElementById(off).style.visibility = "hidden";
	document.getElementById(off).style.display = "none";
	document.getElementById(on).style.visibility = "visible";
	document.getElementById(on).style.display = "block";
}

function toggleOnOff(obj) {
	if (document.getElementById(obj).style.visibility == 'hidden') {
		document.getElementById(obj).style.visibility = "visible";
		document.getElementById(obj).style.display = "block";
	}
	else {
		document.getElementById(obj).style.visibility = "hidden";
		document.getElementById(obj).style.display = "none";
	}
}

function renameFile(file, old, value) {
	if (value == '') {
		alert("Value must not be empty.  Please specify a value.");
		return FALSE;
	}
	if (old != value && confirm("Are you sure you want to change this field to '" + value + "'?")) {
		window.location="?cmd=rename&filename="+file+"&new="+value;
	}
}

function setDescription(file, old, value) {
	if (old != value) {
		window.location="?cmd=chdesc&filename="+file+"&desc="+value;
	}
}

function deleteFile(file) {
	if (confirm("Are you sure you want to delete '"+file+"'?")) {
		window.location="?cmd=rm&filename="+escape(file);
	}
}

var childWindow;
var childWindowStatus;

function popupWindow(url,name,width,height) {
	if (childWindow) childWindow.focus();
	else childWindow = window.open(
		url,
		name,
		'width='+width+',height='+height+
		',resizable=yes,scrollbars=yes,toolbar=no,location=no,status=no,menubar=no,copyhistory=no,directories=no'
	
	);
	if (typeof(childWindow) == 'undefined') {
		alert("This site requires use of popups.  If you have popups disabled, enable them for this site.");
		return null;
	}
	else {
		childWindowStatus = 1;
		setTimeout('popupMonitor()', 500);
		return childWindow;
	}
}

function popupMonitor() {
	if (childWindowStatus == 1 && !childWindow.closed) {
		childWindowStatus = 2;
	}
	else if (childWindowStatus == 2 && childWindow.closed) {
		childWindowStatus = 0;
		location.reload();
	}

	if (childWindowStatus > 0) {
		// childWindow.focus(); // make sure the window is in focus
		setTimeout("popupMonitor()", 500);
	}
	
}

function goCopyBrowser(file) {
	var copybrowser = popupWindow('?cmd=move&filename='+file, 'MoveBrowser', 300, 400);
}

function goResetPassword(user) {
	var resetbrowser = popupWindow('?cmd=admin&action=chpass&user='+user, 'PasswordReset', 400, 200);
}

function goCreateUser() {
	var createbrowser = popupWindow('?cmd=admin&action=add', 'CreateUser', 400, 200);
}

function goUploadBrowser(dir) {
	var uploadbrowser = popupWindow("?cmd=put&dir="+dir, 'UploadBrowser', 500, 350);
}

function windowClose() {
	window.setTimeout('window.close()', 100);
}

function reloadOpener() {
	window.opener.location.reload();
}

/* $Log: fileswap.js,v $
/* Revision 2.2  2006/05/09 18:02:59  ray
/* Fixed file deleting issue with files containing & characters.
/* Modified popup monitor.
/*
/* Revision 2.1  2005/05/31 13:07:53  ray
/* Now includes radupload capability and several other small fixes.
/* */
