if( typeof( AdmeaDossier ) == 'undefined' ) AdmeaDossier = {};

AdmeaDossier.Documentation = function()
{
	// Private variables
	var _popup = null;
	var _docurl = 'DocumentationInterface.ashx?doc=';

	// Public
	return {

		init : function()
		{
		},
		
		getDocument : function( docid )
		{
			if( !_popup )
				popupHelp();
			
			Ext.get( 'help_content' ).dom.style.cursor = 'wait';

			Ext.Ajax.request({
				url: _docurl + docid,
				success: function( response, options )
				{
					Ext.DomHelper.overwrite( 'help_content', response.responseText );
					
					Ext.get( 'help_content' ).dom.style.cursor = 'auto';
					/*
					var obj = _popup.findById( 'help_content' );

					if( obj )
						 Ext.DomHelper.overwrite( obj, response.responseText );
					*/
					// obj.innerHTML = response.responseText;
				}
			});
		},
		
		focusTopic : function( topic )
		{
			if( Ext )
			{
				Ext.get( topic ).scrollIntoView( 'help_content', false );
				
				return false;
			}
			else
				return true;
		},
		
		popupHelp : function( docid )
		{
			if( !_popup )
			{
	    		_popup = new Ext.Window( {
	    			id: 'HelpWindow',
	    			visible: true,
	    			// contentEl: 'adminpanel',
	    			title: '\\o/ ~Help!',
	    			width: 920,
	    			height: 450,
	    			modal: true,
	    			closeAction: 'hide',
	    			resizable: true,
	    			// autoHeight: true,
	    			layout: 'fit',
	    			items:
	    				new Ext.BoxComponent( {
							id: 'help_content',
							autoEl: { tag: 'div' } // , id: 'help_placeholder' }
						} )
	    		} );
    		}

    		_popup.show( 'toolBtnHelp' );
    		
    		this.getDocument( ( docid ? docid : '' ) );
		}
	};
}();

// Global methods

getDocument = AdmeaDossier.Documentation.getDocument;
focusTopic = AdmeaDossier.Documentation.focusTopic;
