/**
 * 
Open Source License
------------------------------------------------------------------------------------------
Generic Table Editor is licensed under the terms of the Open Source GPL 3.0 license. 

http://www.gnu.org/licenses/gpl.html

Generic Table Editor is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Foobar is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Foobar.  If not, see <http://www.gnu.org/licenses/>.

--

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

 * 
 * Generic Table Editor
 *
 * @author Bernhard Woehrlin
 * @copyright (c) 2008-2009, IT.CappuccinoNet.com
 * @date 2009-09-01 16:27:36
 * @version 1.3
 *
 */



/**
 * ########################################################
 *  Default Parameter
 * ########################################################
 */
Ext.namespace(
  'APPL'              // main namespace
  ,'APPL.MSG'         // message strings
  ,'APPL.ux'          // component user extensions (ux)
  ,'APPL.ux.layout'
  ,'APPL.ux.comp'  
);


// container for our data
APPL.DATA = '';
APPL.DATA_URL = 'app.php';
APPL.CONFIG = null;
APPL.CONFIG_URL ='appconfig.php';
APPL.SHOW_GIRD02 = true;
APPL.SHOW_CHART01 = true;
APPL.SHOW_CHART02 = true;

/**
 * ########################################################
 *  Utility classes
 * ########################################################
 */

/**
 * Initialize the Logger
 */
// Wrapper around Firebug Console, so we output just in case of console
// NOTE: i.e. IE does not have a Console
var FB = function(){
};

// DEBUG LEVEL
FB.LOG = 0;
FB.DEBUG = 1;
FB.INFO = 2;
FB.ERROR = 3;

if (location.hostname === 'localhost') {
  FB.o = true;
  FB.l = 0; // add log level ID for console output
}
else
  if (location.hostname == 'sub.cappuccinonet.com') {
    FB.o = true;
    FB.l = 0; // add log level ID for console output
  }
  else {
    FB.o = true;
    //FB.o = false; //globally disable debugging output
    FB.l = 3; // add log level ID for console output
  }

FB.log = function(msg, level, x){

  if (!FB.o) {
    return true;
  }

  if (!window.console) {
    return true;
  }
  else {
    switch (level) {
      case (FB.LOG):
        if (FB.l <= 0) {
          window.console.log('LOG: ' + msg);
        //window.console.debug(msg); // won't work on Safari
        }
        break;
      case (FB.DEBUG):
        if (FB.l <= 1) {
          window.console.log('DEBUG: ' + msg);
        //window.console.debug(msg); // won't work on Safari
        }
        break;
      case (FB.INFO):
        if (FB.l <= 2) {
          window.console.log('INFO: ' + msg);
        //window.console.info(msg); // won't work on Safari
        }
        break;
      case (FB.ERROR):
        if (FB.l <= 3) {
          window.console.log('ERROR: ' + msg);
        //window.console.error(msg); // won't work on Safari
        }
        break;
      default:
        if (FB.l <= 0) {
          window.console.log('LOG: ' + msg);
        //window.console.debug(msg); // won't work on Safari
        }
        break;
    }
  }
};



/**
 *
 * Extension to get a EU money formatter.
 *
 * @author: Thomas Stachl
 * @email: thomas@stachl.me
 *
 */
Ext.util.Format.euMoney = function (v) {
    v = (Math.round((v-0)*100))/100;
    v = (v == Math.floor(v)) ? v + ".00" : ((v*10 == Math.floor(v*10)) ? v + "0" : v);
    v = String(v);
    var ps = v.split('.');
    var whole = ps[0];
    var sub = ps[1] ? ','+ ps[1] : ',00';
    var r = /(\d+)(\d{3})/;
    while (r.test(whole)) {
        whole = whole.replace(r, '$1' + '.' + '$2');
    }
    v = whole + sub;
    if(v.charAt(0) == '-'){
        return '-' + v.substr(1) + ' &euro;';
    }
    return v + " &euro;";
};


