/*
share functions
ssaux, pfagan 03/2007
*/

// Build an URL for the share service passed in the function argument

function sfgate_share(service) {
    // Get href and title
    // PDS URL correction, remove when going live
    var url = location.href;
    url = url.replace(/^http:\/\/[a-z]+\.u\./i,'http://www.');
    encodedurl = encodeURIComponent(url);
    var encodedtitle = encodeURIComponent(document.title);

    var serviceUrl = null;
    if (service == 'delicious') {
        serviceURL = 'http://del.icio.us/post?v=4&noui&jump=close'
            + '&url='      + encodedurl
            + '&title='    + encodedtitle;
    } else if (service == 'digg') {
        serviceURL = 'http://digg.com/submit?phase=2'
            + '&url='      + encodedurl
            + '&title='    + encodedtitle;
    } else if (service == 'fark') {
        serviceURL = 'http://www.fark.com/cgi/fark/submit.pl'
            + '?new_url='     + encodedurl
            + '&new_comment=' + encodedtitle;
    } else if (service == 'google') {
        serviceURL = 'http://www.google.com/bookmarks/mark?op=add'
            + '&bkmk='       + encodedurl
            + '&title='      + encodedtitle
            + '&labels='     + ''
            + '&annotation=' + '';
    } else if (service == 'newsvine') {
        serviceURL = 'http://www.newsvine.com/_tools/seed&save'
            + '?u='      + encodedurl;
    } else if (service == 'reddit') {
        serviceURL = 'http://reddit.com/submit'
            + '?url='      + encodedurl
            + '&title='    + encodedtitle;
    } else if (service == 'slashdot') {
        serviceURL = 'http://slashdot.org/bookmark.pl'
            + '?url='   + encodedurl
            + '&title=' + encodedtitle;
    } else if (service == 'technorati') {
        serviceURL = 'http://technorati.com/faves?sub=favthis'
            + '&add=' + encodedurl;
    }
    if ( serviceURL != null ) {
        var theNewWin = window.open(serviceURL,'sfgateshare','width=900,height=640,resizable=yes,toolbar=no,location=no,scrollbars=yes');
        if ( typeof theNewWin != "undefined" &&
             theNewWin != null ) {
            theNewWin.focus();
        }
    }
    // remove the layer.
    document.getElementById('sharepop1').style.display='none';
    document.getElementById('sharepop1mask').style.display='none';
}

