﻿$(function() {
    if (!window.console)
    {
        window.console = {};
        window.console.log = function() {}
    }
});

(function(){
  var isFn = function(fn) { return typeof fn == "function"; };
  PClass = function(){};
  PClass.create = function(proto) {
    var k = function(magic) { // call init only if there's no magic cookie
      if (magic != isFn && isFn(this.init)) this.init.apply(this, arguments);
    };
    k.prototype = new this(isFn); // use our private method as magic cookie
    for (key in proto) (function(fn, sfn){ // create a closure
      k.prototype[key] = !isFn(fn) || !isFn(sfn) ? fn : // add _super method
        function() { this._super = sfn; return fn.apply(this, arguments); };
    })(proto[key], k.prototype[key]);
    k.prototype.constructor = k;
    k.extend = this.extend || this.create;
    return k;
  };
})();

(function(){
  CClass = function(){};
  CClass.create = function(constructor) {
    var k = this;
    c = function() {
      this._super = k;
      var pubs = constructor.apply(this, arguments), self = this;
      for (key in pubs) (function(fn, sfn) {
        self[key] = typeof fn != "function" || typeof sfn != "function" ? fn :
          function() { this._super = sfn; return fn.apply(this, arguments); };
      })(pubs[key], self[key]);
    }; 
    c.prototype = new this;
    c.prototype.constructor = c;
    c.extend = this.extend || this.create;
    return c;
  };
})();

//DianaSonis.console = function() {
//  
//  function _log(oldConsole) {
//    if (oldConsole != null)
//        oldConsole.log(arguments);
//  }
//  
//  return {
//    oldConsole: null,
//    log: function() {
//        _log(oldConsole);
//    }
//  };
//    
//};

String.prototype.startsWith = function(val)
{
    // must be a string
    if (typeof(val) != 'string')
        return false;
    
    // length of source must be greater
    if (this.length < val.length)
        return false;
            
    // true for empty source and empty value
    if (this.length == 0 && val == "")
        return true;
    
    var source = this.split('');
    var check = val.split('');
    
    for (var i = 0; i < check.length; i++)
    {
        if (source[i] != check[i])
            return false;
    }
    
    return true;
}

String.prototype.endsWith = function(val)
{
    // must be a string
    if (typeof(val) != 'string')
        return false;
    
    // length of source must be greater
    if (this.length < val.length)
        return false;
            
    // true for empty source and empty value
    if (this.length == 0 && val == "")
        return true;
    
    var source = this.split('');
    var check = val.split('');
    
    for (var i = 0; i < check.length; i++)
    {
        if (source[source.length - i - 1] != check[check.length - i - 1])
            return false;
    }
    
    return true;
}

String.prototype.left = function(count)
{
    if (count <= 0)
        return "";
        
    if (this.length < count)
        return this;
        
    return this.substring(0, count);
}

String.prototype.right = function(count)
{
    if (count <= 0)
        return "";
        
    if (this.length < count)
        return this;
        
    return this.substring(this.length - count);
}

var DS = {};
DS.Utils = {};
DS.Utils.Path = 
{
    Combine: function(path1, path2)
    {
        if (path1.endsWith('/') && path2.startsWith('/'))
            return path1.left(path1.length - 1) + path2;
            
        if (!path1.endsWith('/') && !path2.startsWith('/'))
            return path1 + '/' + path2;
            
        return path1 + path2;
    }
}