//String.prototype.trim = function() {
//	return this.replace(/(^\s*)|(\s*$)/g, "");
//} 
Object.extend(Object.prototype, {
	isString : function() { return (typeof(this)=="string" || this instanceof String);},//added by ping:  || this instanceof String
	isSimpleXmlNode: function() {return this._$_;},
	listProps: function() {
		var  result = "[";
		if (this.isString()){return this.toString;}
		for (var property in this) {
			//alert(property);
			if (typeof(this[property])=="function") {continue;}
			result +=property + ":\"" + this[property] + "\"\r\n";
		}
		return result+"]";
	},
	listFuns : function () {
		var result = "";
		for (var property in this) {
			if (typeof(this[property])!="function") {continue;}
			result +=  "function:" + property + "\r\n";
		}
		return result;
	},
		
	isNumber:function() {
		return (new RegExp(/^[0-9]+$/).test(this));
	},
	isPositiveInteger:function(){
		return (new RegExp(/^[1-9]\d*$/).test(this));
	}
});
Object.extend(String.prototype, {
	trim:function(){
		return this.replace(/(^\s*)|(\s*$)|\r|\n/g, "");
	},
	
	trans:function() {
		return this.replace(/&lt;/g, '<').replace(/&gt;/g,'>').replace(/&quot;/g, '"');
	},
	
	replaceAll:function(os, ns) {
		return this.replace(new RegExp(os,"gm"),ns);
	},
	
	skipChar:function(ch) {
		if (!this || this.length===0) {return '';}
		if (this.charAt(0)===ch) {return this.substring(1).skipChar(ch);}
		return this;
	},

	// check if Valid email/password ...
	isValidPwd:function() {
		return (new RegExp(/^([_]|[a-zA-Z0-9]){6,32}$/).test(this)); 
	},

	isValidMail:function(){ 
		return(new RegExp(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/).test(this.trim()));
	},
	
	isSpaces:function() {
		for(var i=0; i<this.length; i+=1) {
			var ch = this.charAt(i);
			if (ch!=' '&& ch!="\n" && ch!="\t" && ch!="\r") {return false;}
		}
		return true;		
	},
	
	isPhone:function() {
		return (new RegExp(/(^([0-9]{3,4}[-])?\d{3,8}(-\d{1,6})?$)|(^\([0-9]{3,4}\)\d{3,8}(\(\d{1,6}\))?$)|(^\d{3,8}$)/).test(this));
	},
	
	isCreditCard:function(){
		if(this.isNumber && this.length == 16){return true;}
		return false;
	},
	isURL:function(){
		return (new RegExp(/^[a-zA-z]+:\/\/(\w+(-\w+)*)(\.(\w+(-\w+)*))*(\?\S*)?$/).test(this)); 
	}

});


function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num)) {num = "0";}
	
	var sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	var cents = num%100;
	num = Math.floor(num/100).toString();
	
	if(cents<10) {cents = "0" + cents;}
	
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++){
		num = num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3));
	}

	return (((sign)?'':'-') + '$' + num + '.' + cents);
}

function formatPercent(num){
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num)) {num = "0";}
	
	var sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	var cents = num%100;
	num = Math.floor(num/100).toString();
	
	if(cents<10) {cents = "0" + cents;}
	
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++){
		num = num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3));
	}

	return (((sign)?'':'-') + num + '.' + cents + '%');
}