
function OpenActionWindow( href, name, height, width ) {
	
	wndHeight = 0;
	wndWidth = 0;
	
	/* Make correction for window size */
	if ( navigator.appName == 'Netscape' ) {
		wndHeight = height;
		wndWidth = width;
	} else {
		wndHeight = height + 30;
		wndWidth = width + 10;
	}
	
	/* Set options */
	options = 'dependent=yes,height='+wndHeight+',width='+wndWidth+',menubar=no,resizable=no,toolbar=no,titlebar=no';
	/* Create window */
	chldWin = window.open( href, name, options );
	/* Test if parent has been registered */
	if (!chldWin.opener) {
		/* Register parent */
		chldWin.opener = self;
	}
	/* Focus window */
	chldWin.focus();
	
}

function Action_ViewFile() {
	
	/* Hide menu first */
	//doHideContextmenu();
	
	/* Process action selection */
	for( index = 0; index < selectedItems.length; index++ ) {
		/* Get item */
		actionItem = selectedItems[ index ]; 
		path = files[ actionItem ];

		/* Update display */
		classNameHide = 'fileView_item';
		fileView_setClassForRow( actionItem, classNameHide );

		/* Open new window and open file */
		href='actions/viewFile.php?file='+path;
		OpenActionWindow( href, 'viewFile'+index, 430, 600 );
	}
	
	/* Clean selection */
	selectedItems.length = 0;
	
}

function Action_EditFile() {
	
	/* Hide menu first */
	doHideContextmenu();
	
	/* Process action selection */
	for( index = 0; index < selectedItems.length; index++ ) {
		/* Get item */
		actionItem = selectedItems[ index ];
		path = files[ actionItem ];

		/* Update display */
		classNameHide = 'fileView_item';
		fileView_setClassForRow( actionItem, classNameHide );

		/* Open new window and open file */
		href='actions/editFile.php?file='+path;
		OpenActionWindow( href, 'editFile'+index, 430, 600 );
	}
	
	/* Clean selection */
	selectedItems.length = 0;
	
}

function Action_RefreshFile() {
	location.reload();
}

function Action_DownloadFile() {
	
	/* Hide menu first */
	//doHideContextmenu();
	
	/* Process action selection */
	href_param = '';
	for( index = 0; index < selectedItems.length; index++ ) {
		/* Get item */
		actionItem = selectedItems[ index ];
		path = files[ actionItem ];

		/* Update display */
		classNameHide = 'fileView_item';
		fileView_setClassForRow( actionItem, classNameHide );
		
		/* Update URL */
		href_param = href_param + '&file' + index + '=' + path; 
	}
	/* Open new window and open file */
	
	href='actions/downloadFile.php?listcount='+selectedItems.length+href_param;

	/* Set new href */
	top.actionFrame.location.replace( href );
	
	/* Clean selection */
	selectedItems.length = 0;
	
}

function Action_RenameFile() {
	
	/* Hide menu first */
	doHideContextmenu();
	
	/* Check count of messages */
	if (selectedItems.length > 1 ) {
		/* Send error message */
		alert('Cannot rename multiple files. Rename files one by one');
		
		/* Exit */
		return;
	} 

	filename = files[ selectedItems[ 0 ] ];
	oldName = filenames[ selectedItems[ 0 ] ];
	question = 'Give new name for file';
	/* Ask new name */
	newNameOfFile = prompt( question, oldName );
		
	if ((newNameOfFile != '') & (typeof(newNameOfFile) == 'string')) {

		/* Do action in special frame */
		href="actions/renameFile.php?new="+newNameOfFile+"&old="+filename;
		
		/* Set new href */
		top.actionFrame.location.replace( href );
	
	} else {
		alert('Action has been canceled');
	}
	
	/* Clean selection */
	selectedItems.length = 0;
	
}


function Action_DeleteFile() {
	
	/* Hide menu first */
	doHideContextmenu();
	
	question = '';
	/* Create question */
	if (selectedItems.length > 1 ) {
		/* Multiple selection */
		question = 'Are you sure you want to remove all '+selectedItems.length+' files?';
	} else {
		question = "Are you sure you want to remove '"+filenames[selectedItems[0]]+"'?";
	}

	/* Ask question */	
	if ( confirm( question ) ) {
		/* Delete files */
		
		/* Set parameter */
		param = '';
		
		/* Add each file */
		for ( index = 0; index < selectedItems.length; index++ ) {
			/* Get item */
			actionItem = selectedItems[ index ];
			path = files[ actionItem ];
			
			/* Update display */
			classNameHide = 'fileView_item';
			fileView_setClassForRow( actionItem, classNameHide );
			
			/* Update params */
			param = param+"&file"+index+"="+path;
		}
		
		/* Do action in special frame */
		href='actions/deleteFile.php?filecount='+selectedItems.length+param;
		
		/* Set new href */
		top.actionFrame.location.replace( href );
		
		
		
	} else {
		alert('Action has been canceled');	
	}
	
	/* Clean selection */
	selectedItems.length = 0;
	
}

function Action_NewFile( dir ) {

	question = 'Give name of file to create';
	nameOfFile = prompt( question, "" );
	
	if ((nameOfFile != '') & (typeof(nameOfFile) == 'string')) {
		
		/* Do action in special frame */
		href="actions/newFile.php?name="+nameOfFile+"&dir="+dir;
		
		/* Set new href */
		top.actionFrame.location.replace( href );
		
	} else {
		alert('Action has been canceled');
	}

}

function Action_UploadFiles( dir ) {
	
	/* Open new window and open file */
	href='actions/uploadFile.php?dir='+dir;
	OpenActionWindow( href, 'uploadFile', 200, 600 );
}


/* Variable for directory actions */
var action_activeDir = '';
var action_activeDirName = '';

function Action_NewFolder( sourceDir ) {

	question = 'Give name of directory to create';
	nameOfDir = prompt( question, "" );
	
	if ((nameOfDir != '') & (typeof(nameOfDir) == 'string')) {
		
		/* Do action in special frame */
		href="actions/newDirectory.php?name="+nameOfDir+"&dir="+sourceDir;
		
		/* Set new href */
		top.actionFrame.location.replace( href );
		
	} else {
		alert('Action has been canceled');
	}

}

function Action_RenameFolder( dir, dirname ) {

	/* Do rootdirectory check */
	if (dirname == '\\') {
		/* Is root directory */
		
		/* Give error message */
		alert("Cannot rename root directory");
		
		/* Return */
		return;
	}

	question = 'Give new name for directory';
	newNameOfDir = prompt( question, dirname );
	
	if ((newNameOfDir != '') & (typeof(newNameOfDir) == 'string')) {

		/* Do action in special frame */
		href="actions/renameDirectory.php?new="+newNameOfDir+"&old="+dirname+"&dir="+dir;
		
		/* Set new href */
		top.actionFrame.location.replace( href );
	
	} else {
		alert('Action has been canceled');
	}

}

function Action_RefreshFolder() {
	location.reload();
}

function Action_DownloadFolder( dir ) {	
	/* Do action in special frame */
	href='actions/downloadDirectory.php?dir='+dir;

	/* Set new href */
	top.actionFrame.location.replace( href );
}

function Action_DeleteFolder( dir ) {

	/* Do rootdirectory check */
	if (dir == '\\') {
		/* Is root directory */
		
		/* Give error message */
		alert("Cannot delete root directory");
		
		/* Return */
		return;
	}
	
	/* Create question */
	question = "Are you sure you want to delete '"+dir+"' and all its subdirectories";
	
	if ( confirm( question ) ) {

		/* Do action in special frame */
		href="actions/deleteDirectory.php?dir="+dir;
		
		/* Set new href */
		top.actionFrame.location.replace( href );
	
	} else {
		alert('Action has been canceled');	
	}

}