var STD = function() {

  return {
    globalVar: [],
    nothing: function () {
      /*
      This is used as a fake callback when you want to do an async call but don't care for the result.
      */
      return null;
    },
    listPropertyNames: function (obj) {
      var names = "";
      for(var i in obj)
      names += i + "=" + obj[i] + ", ";
      return names;
    },
    createToken : function ( length ) {
      //Generate random 32 byte ID
      chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890';

      out_text = '';
      for (a = 0; a < length; a++ ) {

        curr_char = chars[Math.floor(Math.random() * chars.length)];

        out_text += curr_char;
      }

      return out_text;

    },
    generateId : function ( ) {
      //Generate random 32 byte ID
      chars = 'abcdefghijklmnopqrstuvwxyz1234567890';

      out_text = '';
      for (a = 0; a < 32; a++ ) {

        curr_char = chars[Math.floor(Math.random() * chars.length)];

        out_text += curr_char;
      }

      return out_text;

    },
    destroy: function (el) {

      if (typeof el == 'string')
      el = document.getElementById(el);

      el.parentNode.removeChild(el);

    },
    setTimeout: function ( fn, timeout, uid ) {

      var timer_id = 'timer-' + uid;

      STD.clearTimer(uid);

      var newTimer = setTimeout(fn, timeout);

      STD.setGlobal(timer_id, newTimer);

    },
    setHashData: function (data_array) {
      hash_data = data_array.join('/');
      window.location.hash = hash_data;
    },
    getHashData: function () {
      if (window.location.hash.length)
      return window.location.hash.substr(1).split('/');
      else
      return null;

    },
    clearTimer: function ( uid ) {

      var timer_id = 'timer-' + uid;

      oldtimer = STD.getGlobal(timer_id);

      if (typeof oldtimer != 'undefined')
      clearTimeout(oldtimer);

    },
    setGlobal: function ( var_name, value, only_new ) {

      if (only_new == true && typeof this.globalVar[var_name] != 'undefined')
      return false;

      this.globalVar[var_name] = value;

      return true;
    },
    getGlobal: function (var_name) {
      return this.globalVar[var_name];
    },
    unsetGlobal: function (var_name) {
      if (typeof this.globalVar[var_name] != 'undefined')
      delete this.globalVar[var_name];

      return;
    },
    gmtOffset: function () {
      var d = new Date()
      return - d.getTimezoneOffset() * 60;
    },

    numberFormat: function (num)
    {
      num += '';
      x = num.split('.');
      x1 = x[0];
      x2 = x.length > 1 ? '.' + x[1] : '';
      var rgx = /(\d+)(\d{3})/;
      while (rgx.test(x1)) {
        x1 = x1.replace(rgx, '$1' + ',' + '$2');
      }
      return x1 + x2;
    },
    // returns a custom(specific) date format
    getDate: function(timestamp) {
      var d = new Date(timestamp);
      var day    = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][d.getDay()];
      var month  = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][d.getMonth()];
      var year   = d.getFullYear();
      var hour   = (d.getHours() - ((d.getHours() > 12) ? 12 : 0));
      var min    = "0" + d.getMinutes();
      var time   = hour + ":" +  (min.length > 2 ? min.substr(1) : min);

      return day + ", " + month + " " + d.getDate() + ", " + year + " " + time;
    },
    getParam: function ( varName ) {
      var qsParm = new Array();
      var query = window.location.search.substring(1);

      var parms = query.split('&');

      for (var i=0; i<parms.length; i++) {
        var pos = parms[i].indexOf('=');

        if (pos > 0) {
          var key = parms[i].substring(0,pos);
          var val = parms[i].substring(pos+1);
          qsParm[key] = val;
        }
      }

      if (typeof qsParm[varName] == 'undefined')
      return null;
      else
      return qsParm[varName];
    },
    serializeFormObj: function(form) {
      var params = {};
      $.each($(form).serializeArray(), function() {
        if (this.value)
        params[this.name] = this.value;
      });
      return params;
    },
    evalJSON: function(s) {
      return window['eval']("(" + s +  ")");
    }
  }

} ();

