﻿String.prototype.trim = function(){return (this.replace(/^[\s\xA0]+/, "").replace(/[\s\xA0]+$/, ""))}
String.prototype.startsWith = function(str) {return (this.match("^"+str)==str)}
String.prototype.endsWith = function(str) {return (this.match(str+"$")==str)}
function CurrencyFormatted(amount)
{
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
}

String.prototype.parseURL = function() {
    return this.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/, function(url) {
        return url.link(url);
    });
};
String.prototype.parseUsername = function() {
    return this.replace(/[@]+[A-Za-z0-9-_]+/, function(u) {
        var username = u.replace("@", "")
        return u.link("http://twitter.com/" + username);
    });
};
String.prototype.parseHashtag = function() {
    return this.replace(/[#]+[A-Za-z0-9-_]+/, function(t) {
        var tag = t.replace("#", "%23")
        return t.link("http://search.twitter.com/search?q=" + tag);
    });
};
String.prototype.linkify_tweet = function() {
    var tweet0 = this.replace(/(http:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+)/g, '<a href="$1" class="linktweet"> $1 </a>');
    var tweet = tweet0.replace(/(^|\s)@(\w+)/g, '$1@<a href="http://www.twitter.com/$2" class="linktweet"> $2 </a>');
    var tweet1 = tweet.replace(/(^|\s)#(\w+)/g, '$1#<a href="http://search.twitter.com/search?q=%23$2" class="linktweet"> $2 </a>');
    
    var longword = /<a.+?>(.+?)<\/a>/gi;

    var result;

    var tweet2 = tweet1;
    while ((result = longword.exec(tweet1)) != null) {
        if (result[1].length > 20)
            tweet2 = tweet2.replace(result[1], result[1].substr(0, 17) + '...');
    }

    return tweet2;
   
};

function testfunction(v) {
    alert(v.substr(0, 2));
    return v.substr(0, 2);
}
