var currentRowID = "";
var currentType = "";


function hiLiteRow(myRowID) {
	if (currentRowID != myRowID) {
		document.getElementById(myRowID).className = 'over';
	}
}

function loLiteRow(myRowID) {
	if (currentRowID != myRowID) {
		document.getElementById(myRowID).className = 'normal';
	}
}

function selectRow(myRowID, myType) {
	rows = document.getElementById("fileListTable").getElementsByTagName("TR");
    for (var i = 0; i < rows.length; i++)  {
      rows[i].className = 'normal';
    } 
	if (currentRowID != myRowID) {
		currentRowID = myRowID;
		currentType = myType;
		try {
			document.getElementById("deleteButton").style.visibility = "visible";
		} catch(err){};
		if (currentType == "file") {
			document.getElementById("downloadButton").style.visibility = "visible";
			try {
				document.getElementById("moveFolderButton").style.visibility = "hidden";
				document.getElementById("moveButton").style.visibility = "visible";
			} catch(err){};
			if (archiveable) {
				document.getElementById("archiveButton").style.visibility = "visible";
			}
		} else {
			document.getElementById("moveFolderButton").style.visibility = "visible";
			document.getElementById("downloadButton").style.visibility = "hidden";
			document.getElementById("archiveButton").style.visibility = "hidden";
			try {
				document.getElementById("moveButton").style.visibility = "hidden";
			} catch(err){};
		}		
		document.getElementById(myRowID).className = 'selected';
	} else {
		currentRowID = '';
		currentType = '';
		try {
			document.getElementById("deleteButton").style.visibility = "hidden";
		} catch(err){};
		document.getElementById("downloadButton").style.visibility = "hidden";
		document.getElementById("archiveButton").style.visibility = "hidden";
		try {
			document.getElementById("moveButton").style.visibility = "hidden";
			document.getElementById("moveFolderButton").style.visibility = "hidden";
		} catch(err){};
		document.getElementById(myRowID).className = 'normal';
	}
}

function selectRowUser(myRowID) {
	rows = document.getElementById("fileListTable").getElementsByTagName("TR");
    for (var i = 0; i < rows.length; i++)  {
      rows[i].className = 'normal';
    } 
	if (currentRowID != myRowID) {
		currentRowID = myRowID;
		document.getElementById("deleteUserButton").style.visibility = "visible";
		document.getElementById(myRowID).className = 'selected';
	} else {
		currentRowID = '';
		currentType = '';
		document.getElementById("deleteUserButton").style.visibility = "hidden";
		document.getElementById(myRowID).className = 'normal';
	}
}

function openFolder(folderID) {
	document.location.href='index.php?folder_id=' + folderID;
}

function downloadFile() {
	document.location.href='download.php?fileID=' + currentRowID;
}

function openFile(fileID) {
	document.location.href='download.php?fileID=' + fileID;
}

function deleteItem() {
	if (currentRowID != '') {
		if (confirm("Delete this item?  This action cannot be undone.")) {
			if (currentType == "folder") {
				document.location.href='deleteFolder.php?folderID=' + currentRowID;
			} else {
				document.location.href='deleteFile.php?fileID=' + currentRowID;
			}
		}
	} else {
		alert("Nothing selected.");
	}
}

function moveFile() {
	tb_show(null, "moveFile.php?fileID=" + currentRowID + "&KeepThis=true&TB_iframe=true&height=600&width=600&modal=true", false)
}

function moveFolder() {
	tb_show(null, "moveFolder.php?folderID=" + currentRowID + "&KeepThis=true&TB_iframe=true&height=600&width=600&modal=true", false)
}

function archiveFile(flag) {
	if (flag) {
		theMsg = "Archive this file?";
	} else {
		theMsg = "Unarchive this file?";
	}
	if (currentRowID != '') {
		if (confirm(theMsg)) {
			document.location.href='archiveFile.php?fileID=' + currentRowID;
		}
	} else {
		alert("Nothing selected.");
	}
}

function deleteUser() {
	if (currentRowID != '') {
		if (confirm("Delete this user?  This action cannot be undone.")) {
			document.location.href='deleteUser.php?deleteUserID=' + currentRowID;
		}
	} else {
		alert("Nothing selected.");
	}
}

function updateUser(userID) {
	tb_show(null, "updateUser.php?updateUserID=" + userID + "&KeepThis=true&TB_iframe=true&height=600&width=400&modal=true", false)
}

function doSearch() {
	document.cookie = "searchString=" + document.getElementById("searchString").value + ";";
	document.location.href = "users.php";
	return false;
}
