String.prototype.hasWord = function(cls) {
  var exp = new RegExp("(^| )" + cls + "\W*");
  return (exp.test(this)) ? true : false;
}

String.prototype.addWord = function(cls) {
  if (this.hasWord(cls)) {
    return this;
  }

  if (this.length > 0) {
    cls = ' ' + cls;
  }
    
  return this + cls;
}

String.prototype.deleteWord = function(cls) {
  if (!this.hasWord(cls)) {
    return this;
  }
  
  var exp = new RegExp("(^| )" + cls + "\W*");
  return this.replace(exp, "");
}

String.prototype.trim = function() {
  return this.replace(/^[\s]+|[\s]+$/g, '');
}

String.prototype.clean = function(sep) {
  var exp = new RegExp("[" + sep + "]+", 'g');
  return this.replace(/[  ]+/, sep);
}

String.prototype.explode = function(sep) {
  var str = this.clean(sep).trim();

  return str.split(sep);
}

Array.prototype.implode = function (sep) {
  var str = '';
  for (var n = 0; n < this.length; n++) {
    str += (n) ? sep + this[n] : this[n];
  }
  return str;
}

Array.prototype.exists = function (value) {
  for (var n = 0; n < this.length; n++) {
    if (this[n] === value) {
      return true;
    }
  }
  return false;
};

Array.prototype.merge = function (arr) {
  for (var n = 0; n < arr.length; n++) {
    if (!this.exists(arr[n])) {
      this[this.length] = arr[n];
    }
  }
}

function createCookie(name, value, days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
		var expires = ";expires = " + date.toGMTString();
	}
	else {
		var expires = "";
	}
	document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');

	for(var i = 0; i < ca.length; i++) {
		var c = ca[i];
		while (c.charAt(0) == ' ') {
			c = c.substring(1, c.length);
		}
		if (c.indexOf(nameEQ) == 0) {
			return c.substring(nameEQ.length, c.length);
		}
  }
  return null;
}

function eraseCookie(name) {
	createCookie(name, "", -1);
}
