/**
 * Additional utilities for chat
 *
 * @author Vendelev Artiom
 * @class
 */
function eChatUtils() {
  var self = this;

  self.cookie = new eCookie();
  self.evt    = new eChatUtilsEvent();
  self.elem   = new eChatUtilsElement();
  
  var unicId = 0;
  
/////////////////////////////////

  /**
   * Definition object's type
   *
   * @param {Object} obj Object
   * @return {String} Type name
   */
  this.getType = function(obj) {
    var type = typeof(obj);
    if (type == 'object') {
      if (obj) {
        if(!obj.nodeType) {
          type = (obj.window && obj == obj.window);
          if (!type) {
            type = Object.prototype.toString.apply(obj);
            type = type.substring(8,type.length-1);
          } else type = 'window';
        } else type = 'element';//obj.nodeName;
      } else type = 'null';
    }
    return type.toLowerCase();
  }
  
  /**
   * Convert object to JSON string
   *
   * @param {Object} obj Object
   * @return {String} JSON string
   */
  this.toJSON = function(obj) {
    var ii, tmp = [], res = [];
    switch (self.getType(obj)) {
      case 'object':
        res[res.length] = '{';
        for (ii in obj) tmp[tmp.length] = ['"', ii, '":', arguments.callee(obj[ii])].join('')
        res[res.length] = tmp.join(',');
        res[res.length] = '}';
        break;
      case 'array':
        res[res.length] = '[';
        for (ii=0; ii/g,  '>'
             ).replace(/');
	}
  
  /**
   * Unescape special HTML chars
   *
   * @param {String} str String
   * @return {String}
   */
  this.unescapeHtml = function(str) {
    str = str || '';
    return str.replace(/
/g, '\n' ).replace(/>/g, '>' ).replace(/</g, '<' ).replace(/&/g, '&'); }; /** * Escape special HTML chars for JSON string * * @param {String} str * @return {String} */ this.escapeString = function(str) { return str.replace(/([\"\\])/g, '\\$1' ).replace(/[\f]/g, "\\f" ).replace(/[\b]/g, "\\b" ).replace(/[\n]/g, "\\n" ).replace(/[\t]/g, "\\t" ).replace(/[\r]/g, "\\r"); } this.ajax = function(obj) { var method = obj.method || "GET"; var url = obj.url || ''; var data = obj.data || {}; var success = obj.success || function(){}; jQuery.ajax({ type: method, url: url + ((url.indexOf("?")>-1)?"&":"?") + 'xml=1', //dataType: 'html', data: data, success: success }); } this.unicId = function() { unicId++; return ((new Date())-0)+'-'+unicId; } }