/* Object object 
Object.prototype.clone = function() {
	function o() {}
	o.prototype = this;
	return new o();
}*/

/* Math Object */
Math.multipleOf = function(v, m, t) {
	switch(t) {
		case 1 : return Math.ceil(v/m)*m;
		case -1 : return Math.floor(v/m)*m;
		default : return Math.round(v/m)*m;
	}
}
Math.roundTo = function(v, s) {
	s = (!s || s <= 0) ? 1 : s;
	var p10 = Math.pow(10,s);
	return Math.round(v*p10)/p10;
}

/* String Object */
String.prototype.cleanSQL = function(typ) {
	var tStr = this.replace(/^\s*|\s*$/,"");
	if(!tStr || tStr.length == 0) { return ""; }
	if(tStr.toLowerCase() == "null") {
		return "";
	} else {
		switch(typ) {
		case "I" :
		case "D" :
			return Number(tStr);
		default :
			tStr = tStr.replace(/--|==|;/g," ").replace(/\'/g,"''");
			return tStr;
		}
	}
};
if( !("").trim ) {
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/gi, "");
};
}
String.prototype.translate = function(_a,_b) {
	var a = (typeof _a == "string") ? _a : "";
	var b = (typeof _b == "string") ? _b : "";
	var str = this;
	for(var i=0; i<Math.min(a.length, b.length); i++) {
		str = str.replace(a.charAt(i), b.charAt(i)); 
	}
	return str;
};

/* Date object */
Date.prototype.toXML = 
Date.prototype.toJSON = function (key) {
	function f(n) {
		// Format integers to have at least two digits.
		 return (!n || n == "") ? "00" : (n < 10) ? '0' + n : n;
	}

	return this.getFullYear() + '-' +
		f(this.getMonth() + 1) + '-' +
		f(this.getDate()) + 'T' +
		f(this.getHours()) + ':' +
		f(this.getMinutes()) + ':' +
		f(this.getSeconds()) + 'Z';
};
Date.prototype.toMySQLString = function() {
	function f(n) {
		// Format integers to have at least two digits.
		 return (!n || n == "") ? "00" : (n < 10) ? '0' + n : n;
	}
	return f(this.getFullYear()) + "-" + f(this.getMonth()+1) + "-" + f(this.getDate()) + " " + f(this.getHours()) + ":" + f(this.getMinutes()) + ":" + f(this.getSeconds()); 
};

/* RegExp Object */
RegExp.prototype.toXML = 
RegExp.prototype.toJSON = function(key) {
	return this.toString().replace(/\\/gi, "\\\\").replace(/"/g,"\\\"");
};

/* Array */	
Array.prototype.contains = function(value) {
	for(var i=0; i<this.length; i++) {
		if(this[i] == value) { return true; }
	}
	return false;
};
Array.prototype.indexOf = function(value) {
	for(var i=0; i<this.length; i++) {
		if(this[i] == value) { return i; }
	}
	return -1;
};

Array.prototype.toXML = function(key) {
	return this.toString();
};