//----------------------------------------------------------------
// Tooltip scripts
//----------------------------------------------------------------

var IE = false;

if( navigator.appName.indexOf('Microsoft') != -1 ) IE = true;

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;

var tempX = 0
var tempY = 0

//----------------------------------------------------------------
// Function to retrieve the mouse x, y
//----------------------------------------------------------------

function getMouseXY(e) {
	
	if (IE) { // grab the x-y pos.s if browser is IE
		tempX = event.clientX + document.body.scrollLeft
		tempY = event.clientY + document.body.scrollTop
	} else {  // grab the x-y pos.s if browser is NS
		tempX = e.pageX
		tempY = e.pageY
	}  
  // catch possible negative values in NS4
	if (tempX < 0){tempX = 0}
	if (tempY < 0){tempY = 0}
	
	return true;
}


//----------------------------------------------------------------
// Show the menu for file/dir
//----------------------------------------------------------------

function showmenu(id, full_path, path, is_dir) {
	ff = document.getElementById(id);
	ff.style.left = tempX + 8 + 'px';
	ff.style.top = tempY + 'px';
	
	if( is_dir == 1 ) {
	// build the menu for dir type
		html = '<table style="width:100%" cellpadding="3">' + "\n" + 
		"<tr>\n" + '<td align="left"><a href="?act=adminCP&amp;mod=fileman&amp;path=' + escape(full_path) + '">Open Directory</a></td>' + "</tr>\n" +
		"<tr>\n" + '<td align="left"><a href="?act=adminCP&amp;mod=fileman&amp;cut=' + escape(full_path) + '">Cut</a></td>' + "</tr>\n" +
		"<tr>\n" + '<td align="left"><a href="?act=adminCP&amp;mod=fileman&amp;del=' + escape(full_path) + 
		'" onclick="return confirmdel()">Delete Directory</a></td>' + "</tr>\n" +
		"<tr>\n" + '<td align="left"><a href="javascript:void();" onclick="renameFileDir(\'' + escape(path) + '\', \'' +
		escape(full_path) + '\')">Rename</a></td>' + "</tr>\n" +
		"</tr>\n" + '</table>';
	}
	else {
		html = '<table style="width:100%" cellpadding="3">' + "\n" + 
		"<tr>\n" + '<td align="left"><a href="?act=adminCP&amp;mod=fileman&amp;get=' + escape(full_path) + '">Download File</a></td>' +  "</tr>\n" + 
		"<tr>\n" + '<td align="left"><a href="?act=adminCP&amp;mod=fileman&amp;cut=' + escape(full_path) + '">Cut</a></td>' + "</tr>\n" +
		"<tr>\n" + '<td align="left"><a href="?act=adminCP&amp;mod=fileman&amp;cpy=' + escape(full_path) + '">Copy</a></td>' + "</tr>\n" +
		"<tr>\n" + '<td align="left"><a href="?act=adminCP&amp;mod=fileman&amp;del=' + escape(full_path) + '">Delete</a></td>' + "</tr>\n" +
		"<tr>\n" + '<td align="left"><a href="javascript:void();" onclick="renameFileDir(\'' + escape(path) + '\', \'' +
		escape(full_path) + '\')">Rename</a></td>' + "</tr>\n" +
		'</table>'
	}
	
	ff.innerHTML = html;
	
	ff.style.visibility = 'visible';

	return true;

}


//----------------------------------------------------------------
// Show tooltip like the one in windows
//----------------------------------------------------------------

function showTooltip(id, info) {

	ff = document.getElementById(id);
	ff.style.left = tempX + 'px';
	ff.style.top = tempY + 16 + 'px';
	ff.innerHTML = info;
	ff.style.visibility = 'visible';
	
	return true;
}


//----------------------------------------------------------------
// Self explain, hide layers
//----------------------------------------------------------------

function hide(id) {
	ff = document.getElementById(id);
	
	ff.style.visibility = 'hidden';
	
	return true;
}


//----------------------------------------------------------------
// Confirm message to delete dir
//----------------------------------------------------------------

function confirmdel() {

	ans = confirm('Delete directory and all it\'s content?');
	return ans;
}


//----------------------------------------------------------------
// Get new name for the file/dir renaming function
//----------------------------------------------------------------

function renameFileDir(path, oldname) {
	
	oldname = unescape(oldname);
	
	// Get the basename of the path if contain '/' char
	if( oldname.indexOf('/') != -1 ) {
		name = oldname.substring(oldname.lastIndexOf('/') + 1, oldname.length);
	}
	else {
		name = oldname;	
	}
	newname = prompt("Enter the new name.", name);
	
	newname = trim(newname);
	
	if( newname && newname != null ) {
		window.location = '?act=adminCP&mod=fileman&path=' + path + '&ren=' + escape(name) + '&to=' + escape(newname);
	}
}