// Author:	renjin
// Author Blog: http://renjin.blogspot.com/
// Date: May 23, 2008
if (typeof(String.prototype.format) == 'undefined') {
    String.prototype.format = function() {        
        
        var result = this;

        for(var i=0; i<arguments.length; i++)
        {
            var regex = new RegExp('\\{' + i.toString() + '\\}','gm');
            result = result.replace(regex, arguments[i]);            
        }
        
        return result;   
    };
}

if (typeof(addTo) == 'undefined') {
    var addTo = function(site, title, url) {    
        title = encodeURIComponent(title);
        url = encodeURIComponent(url);  
        var via = encodeURIComponent(typeof(document.referrer) == 'string' ? document.referrer : '');  
        var desc = '';
        if (window.getSelection) desc = window.getSelection();
        else if(document.getSelection) desc = document.getSelection();
        else if(document.selection) desc = document.selection.createRange().text;
        desc = encodeURIComponent(desc);
    
        var fullUrl = '';
    
        switch(site) {
            case 'HemiDemi':
                fullUrl = 'http://www.hemidemi.com/user_bookmark/new?title=' + title + '&url=' + url + '&description=' + desc + '&via=' + via;
                break;
            case 'MyShare':
                fullUrl = 'http://myshare.url.com.tw/index.php?func=newurl&from=mysharepop&url=' + url + '&desc=' + title + '&contents=' + desc;
                break;
            case 'udn':
                fullUrl = 'http://bookmark.udn.com/add?f_URL=' + url + '&f_TITLE=' + title;
                break;
            case 'funP':
                fullUrl = 'http://funp.com/push/submit/?via=tools&url=' + url + '&title=' + title;
                break;
            case 'Baidu':
                fullUrl = 'http://cang.baidu.com/do/add?iu=' + url + '&it=' + title + '&dc=' + desc;
                break;
            case 'del.icio.us':
                fullUrl = 'http://del.icio.us/post?title=' + title + '&url=' + url + '&notes=' + desc;
                break;
            case 'reddit':
                fullUrl = 'http://reddit.com/submit?url=' + url + '&title=' + title;
                break;
            case 'Furl':
                fullUrl = 'http://www.furl.net/storeIt.jsp?t=' + title + '&u=' + url + '&r='+ via +'&c=' + desc + '&p=1';
                break;
            case 'Digg':
                fullUrl = 'http://digg.com/submit?phase=2&url=' + url + '&title=' + title + '&bodytext=' + desc;
                break;
            case 'Google Bookmarks':
                fullUrl = 'http://www.google.com/bookmarks/mark?op=add&bkmk=' + url + '&title=' + title + '&annotation=' + desc;
                break;
            case 'Yahoo MyWeb':
                fullUrl = 'http://tw.myweb2.search.yahoo.com/myresults/bookmarklet?t=' + title + '&u=' + url + '&d=' + desc + '&&ei=UTF-8';
                break;
            case 'Technorati':
                fullUrl = 'http://technorati.com/faves?add=' + url + '&title=' + title;
                break;    
            case 'dotnetkicks':
                fullUrl = 'http://www.dotnetkicks.com/kick/?url=' + url + '&title=' + title;
                break;
            default:
                return;
        }      
        
        self.location = fullUrl;                      
    };    
}

(function() {
var title = (typeof(_bookmarkTitle) == 'string' ? _bookmarkTitle : window.document.title);
var url = (typeof(_bookmarkUrl) == 'string' ? _bookmarkUrl:window.location.href);  
var formatString = '<a href="javascript:addTo(&quot;{0}&quot;,&quot;' + title + '&quot;,&quot;' + url + '&quot;)"><img src="{1}" alt="{0}" class="social-button"/></a>';

document.write(formatString.format('HemiDemi', 'http://hcuff424.myweb.hinet.net/bookmark/hemidemi.gif'));
document.write(formatString.format('MyShare', 'http://hcuff424.myweb.hinet.net/bookmark/myshare.jpg'));                        
document.write(formatString.format('udn', 'http://hcuff424.myweb.hinet.net/bookmark/udn.png'));
document.write(formatString.format('funP', 'http://hcuff424.myweb.hinet.net/bookmark/funp.png'));
document.write(formatString.format('Baidu', 'http://hcuff424.myweb.hinet.net/bookmark/baidu.gif'));
document.write(formatString.format('del.icio.us', 'http://hcuff424.myweb.hinet.net/bookmark/delicious.jpg'));
document.write(formatString.format('reddit', 'http://hcuff424.myweb.hinet.net/bookmark/reddit.gif'));
document.write(formatString.format('Furl', 'http://hcuff424.myweb.hinet.net/bookmark/furl.jpg'));
document.write(formatString.format('Digg', 'http://hcuff424.myweb.hinet.net/bookmark/digg.png'));
document.write(formatString.format('Google Bookmarks', 'http://hcuff424.myweb.hinet.net/bookmark/google.jpg'));
document.write(formatString.format('Yahoo MyWeb', 'http://hcuff424.myweb.hinet.net/bookmark/yahoo.gif'));
document.write(formatString.format('Technorati', 'http://hcuff424.myweb.hinet.net/bookmark/technorati.jpg'));
})();


