// abandoned as not currently required!

function browse_server()
{
	popup('/assets/admin/js/file_manager/index.html?Type=Images&Standalone=attachment_url');
}

function popup( url, width, height )
{
	width = width || '80%' ;
	height = height || '70%' ;

	if ( typeof width == 'string' && width.length > 1 && width.substr( width.length - 1, 1 ) == '%' )
		width = parseInt( window.screen.width * parseInt( width ) / 100 ) ;

	if ( typeof height == 'string' && height.length > 1 && height.substr( height.length - 1, 1 ) == '%' )
		height = parseInt( window.screen.height * parseInt( height ) / 100 ) ;

	if ( width < 200 )
		width = 200 ;

	if ( height < 200 )
		height = 200 ;

	var top = parseInt( ( window.screen.height - height ) / 2 ) ;
	var left = parseInt( ( window.screen.width  - width ) / 2 ) ;

	var options = 'location=no,menubar=no,toolbar=no,dependent=yes,minimizable=no,modal=yes,alwaysRaised=yes,resizable=yes' +
		',width='  + width +
		',height=' + height +
		',top='  + top +
		',left=' + left ;

	var popupWindow = window.open( url, 'FileBrowse', options, true ) ;

	// Blocked by a popup blocker.
	if ( !popupWindow )
		return false ;

	try
	{
		popupWindow.moveTo( left, top ) ;
		popupWindow.resizeTo( width, height ) ;
		popupWindow.focus() ;
		popupWindow.location.href = this._BuildUrl() ;
	}
	catch (e)
	{
		popupWindow = window.open( url, 'FileBrowse', options, true ) ;
	}

	return true ;
}


function BrowseServer( startupPath, functionData )
{
	// You can use the "CKFinder" class to render CKFinder in a page:
	var finder = new CKFinder() ;

	// The path for the installation of CKFinder (default = "/ckfinder/").
	finder.BasePath = '/assets/admin/ckfinder/' ;

	//Startup path in a form: "Type:/path/to/directory/"
	finder.StartupPath = startupPath ;

	// Name of a function which is called when a file is selected in CKFinder.
	finder.SelectFunction = SetFileField ;

	// Additional data to be passed to the SelectFunction in a second argument.
	// We'll use this feature to pass the Id of a field that will be updated.
	finder.SelectFunctionData = functionData ;

	// Name of a function which is called when a thumbnail is selected in CKFinder.
	finder.SelectThumbnailFunction = ShowThumbnails ;

	// Launch CKFinder
	finder.Popup() ;
}

// This is a sample function which is called when a file is selected in CKFinder.
function SetFileField( fileUrl, data )
{
	document.getElementById( data["selectFunctionData"] ).value = fileUrl ;
}

// This is a sample function which is called when a thumbnail is selected in CKFinder.
function ShowThumbnails( fileUrl, data )
{
	var sFileName = decodeURIComponent( fileUrl.replace( /^.*[\/\\]/g, '' ) ) ;
	document.getElementById( 'thumbnails' ).innerHTML +=
			'<div class="thumb">' +
				'<img src="' + fileUrl + '" />' +
				'<div class="caption">' +
					'<a href="' + data["fileUrl"] + '" target="_blank">' + sFileName + '</a> (' + data["fileSize"] + 'KB)' +
				'</div>' +
			'</div>' ;

	document.getElementById( 'preview' ).style.display = "";
	// It is not required to return any value.
	// When false is returned, CKFinder will not close automatically.
	return false;
}
