


////////////////////////////////////////////////////////////
//
//  class CPsAppMgr
//
//  general application support
//


function CPsAppMgr()
{


    ////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////

    ////////////////////////////////////////////////////////////
    //
    //  ctor
    //

    CPsAppMgr.prototype._construct =
	function()
	{
	    this._debugInit();
	};


    ////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////


    ////////////////////////////////////////////////////////////
    //
    //  debug support
    //

    ////////////////////////////////////////////////////////////
    //
    //  _debugInit()
    //

    CPsAppMgr.prototype._debugInit =
	function()
	{
	    var nLevel = this.searchGETVars('_debug');
	    if (!nLevel)
	    {
		return;
	    }
	    nLevel = parseInt(nLevel);

	    for (var i=0; i<=nLevel; i++)
	    {
		this._arrDebugLevels[i] = true;
	    }
	};


    ////////////////////////////////////////////////////////////
    //
    //  isDebugLevel(nLevel)
    //

    CPsAppMgr.prototype.isDebugLevel =
	function(nLevel)
	{
	    return this._arrDebugLevels[nLevel];
	};


    ////////////////////////////////////////////////////////////
    //
    //  debugAlert(nLevel, ...)
    //
    //  pop up an alert message if we are in debug level nLevel
    //

    CPsAppMgr.prototype.debugAlert =
	function(nLevel)
	{
	    if (arguments.length <= 1)
	    {
		return;
	    }
	    if (!this.isDebugLevel(nLevel))
	    {
		return;
	    }

	    var arrArgs = new Array();
	    for (var i=1; i<arguments.length; i++)
	    {
		arrArgs[i-1] = arguments[i];
	    }
	    alert(CPsText.sprintf.apply(CPsText, arrArgs));
	};


    ////////////////////////////////////////////////////////////
    //
    //  debugGLog(nLevel, ...)
    //
    //  writes a message to GLog window if we are in debug level nLevel
    //

    CPsAppMgr.prototype.debugGLog =
	function(nLevel)
	{
	    if (arguments.length <= 1)
	    {
		return;
	    }
	    if (!this.isDebugLevel(nLevel))
	    {
		return;
	    }

	    var arrArgs = new Array();
	    for (var i=1; i<arguments.length; i++)
	    {
		arrArgs[i-1] = arguments[i];
	    }
	    GLog.write(CPsText.sprintf.apply(CPsText, arrArgs));
	};


    ////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////


    ////////////////////////////////////////////////////////////
    //
    //  support for GET vars
    //

    ////////////////////////////////////////////////////////////
    //
    //  searchGETVars(szVar)
    //

    CPsAppMgr.prototype.searchGETVars =
	function(szVar)
	{
	    var szGETVars = window.location.search.substring(1);
	    if (!szGETVars)
	    {
		return '';
	    }

	    var arrGETVars = szGETVars.split('&');
	    for (var i=0; i<arrGETVars.length; i++)
	    {
		var arrPair = arrGETVars[i].split('=');
		if (arrPair[0] == szVar)
		{
		    return arrPair[1];
		}
	    } 

	    return '';
	};



    ////////////////////////////////////////////////////////////
    //
    //  private methods
    //



    ////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////


    ////////////////////////////////////////////////////////////
    //
    //  public attributes
    //


    ////////////////////////////////////////////////////////////
    //
    //  private attributes
    //

    this._arrDebugLevels = new Array();



    ////////////////////////////////////////////////////////////
    //
    //  init'ing (ctor) code
    //

    this._construct();



}


var gPsAppMgr = new CPsAppMgr();



