function socialShare(social, url) {
    if (typeof(url) != 'undefined') {
        // Check if URL is relative. If so, append protocol and host
        if (url.substring(0, 1) == '/')
            url = location.protocol + '//' + location.host + url;
        var encUrl = encodeURIComponent(url);
    }
    else
        var encUrl = encodeURIComponent(location.href);
    console.log(encUrl);
    var title = encodeURIComponent(document.title);
    switch (social) {
        case 'facebook':
            var shareUrl = 'http://www.facebook.com/share.php?u=' + encUrl + '&t=' + title;
            var popup = 'toolbar=0,status=0,width=965,height=565';
            break;
        case 'nettby':
            if (document.getElementsByTagName('meta')) {
                var metas = document.getElementsByTagName('meta');
                for (var i = 0; i < metas.length; i++) {
                    if (metas[i].name == 'description')
                        var description = encodeURIComponent(metas[i].content);
                }
            }
            var shareUrl = 'http://www.nettby.no/user/edit_link.php?name=' + title + '&url=' + encUrl + '&description=' + ((description) ? description : title);
            var popup = 'scrollbars=no,width=450,height=430';
            break;
        case 'custom':
            var shareUrl = decodeURIComponent(encUrl);
            var popup = 'toolbar=0,status=0,width=965,height=565';
            break;
        default:
            return false;
    }
    window.open(shareUrl, social, popup);
    return false;
}
