function setFontById(vv){
    document.getElementById('article').style.fontSize = vv;
}

function setStyleById(i, p, v) {
    var n = document.getElementById(i);
    n.style[p] = v;
}

var StoryURL=location.href;
var StoryTitle=document.title;

function sharePop(url, width, height, name) {
    testwindow= window.open(url, name, "location=1,status=1,scrollbars=1,resizable=1,width=" + width + ",height=" + height);
}

function shareBusinessExchange() {
    sharePop('http://bx.businessweek.com/api/add-article-to-bx.tn?url='+encodeURIComponent(StoryURL), 850, 500, 'BusinessExchangePopup');
}

function shareTwitter() {
    sharePop('http://twitter.com/home?status='+encodeURIComponent(StoryURL), 850, 500, 'twitterPopup');
}

function shareDelicious() {
    sharePop('http://del.icio.us/post?v=2&url='+encodeURIComponent(StoryURL)+'&title='+encodeURIComponent(HeadLine)+'&bodytext=' + encodeURIComponent(summary) + '&tags=news', 850, 500, 'deliciousPopup');
}

function shareDigg() {
    sharePop('http://digg.com/submit?url='+encodeURIComponent(StoryURL)+'&title='+encodeURIComponent(HeadLine)+'&bodytext=' + encodeURIComponent(summary) + '&topic=business_finance', 850, 500, 'diggPopup');
}

function shareFacebook() {
    sharePop('http://www.facebook.com/sharer.php?u='+encodeURIComponent(StoryURL)+'&t='+encodeURIComponent(HeadLine), 850, 500, 'facebookPopup');
}

function shareLinkedIn() {
    sharePop('http://www.linkedin.com/shareArticle?mini=true&url='+encodeURIComponent(StoryURL)+'&title='+encodeURIComponent(HeadLine)+'&summary=' + encodeURIComponent(summary) + '&source=Bloomberg.com', 850, 500, 'linkedinPopup');
}

function shareNewsvine() {
    sharePop('http://www.newsvine.com/_wine/save?popoff=1&h='+encodeURIComponent(HeadLine)+'&t=world-news&u='+encodeURIComponent(StoryURL)+'&e=', 850, 445, 'newsvinePopup');
}

function shareProp() {
    sharePop('http://www.propeller.com/submit/?T='+encodeURIComponent(HeadLine)+'&U='+encodeURIComponent(StoryURL)+'&D=' + encodeURIComponent(summary) + '&tag=news', 850, 540, 'propPopup');
}

function shareYahoo() {
    sharePop('http://buzz.yahoo.com/buzz?targetUrl=' + encodeURIComponent(StoryURL) + '&headline=' + encodeURIComponent(HeadLine) + '&summary=' + encodeURIComponent(summary), 980, 540, 'yahooPopup');
}


var arrShareLinks = new Array(
    "Twitter",
    "javascript:shareTwitter();",
    "BusinessExcange",
    "javascript:shareBusinessExchange();",
    "Delicious",
    "javascript:shareDelicious();",
    "Digg",
    "javascript:shareDigg();",
    "Facebook",
    "javascript:shareFacebook();",
    "LinkedIn",
    "javascript:shareLinkedIn();",
    "Yahoo!",
    "javascript:shareYahoo();"
);

var shareOverlayFocus = false;
var shareInterval;

function trimTools(strText) {
    return strText.replace(/\\./,"").replace("!","").replace(" ","");
}

function parseShareName(strWord) {
    if (strWord == "Delicious")
        strWord = "Del.icio.us";
    return strWord;
}

function tryShareOverlay() {
    if (!document.getElementById("shareContainer")) {
        var shareDiv = document.createElement("div");
        shareDiv.id = "shareContainer";
        shareDiv.className = "hidden";
        var objShareDiv = document.getElementById("atools").insertBefore(shareDiv, document.getElementById("autilities"));
    }
    if (document.getElementById("shareContainer").innerHTML == '') {
        showShareOverlay();
    } else {
        hideShareOverlay();
    }
}

function putShareLinks(id) {
    var cloz="";
    if (id == "shr_v" || id == "shr_t") { cloz = '<li id="shareclose"><div class="sharecloseoff"><a href="javascript:togShareLinks(\''+ id + '\');">Close</a></li>'
    var sharHTML = '<ul class="' + id + '" style="padding: 0px;">' +
            //'<li class="d9"><a href="javascript:shareTwitter();">Twitter</a></li>' +
            '<li class="d1"><a href="javascript:shareDelicious();">Delicious</a></li>' +
            '<li class="d2"><a href="javascript:shareDigg();">Digg</a></li>' +
            //'<li class="d3"><a href="javascript:shareFacebook();">Facebook</a></li>' +
            '<li class="d4"><a href="javascript:shareLinkedIn();">LinkedIn</a></li>' +
            '<li class="d5"><a href="javascript:shareNewsvine();">Newsvine</a></li>' +
            //'<li class="d6"><a href="javascript:shareProp();">Propeller</a></li>' +
            '<li class="d7"><a href="javascript:shareYahoo();">Yahoo! Buzz</a></li>' + cloz +
            '</ul>';
            }

            if (id == "shr_h") {
    var sharHTML = '<ul class="' + id + '">' +
            //'<li class="d9" style="width:auto;margin: 2px 0 0 5px;"><a href="javascript:shareTwitter();">Twitter</a></li>' +
            '<li class="d1" style="width:auto;margin: 2px 0 0 5px;"><a href="javascript:shareDelicious();">Delicious</a></li>' +
            '<li class="d2" style="width:auto;margin: 2px 0 0 5px;"><a href="javascript:shareDigg();">Digg</a></li>' +
            //'<li class="d3" style="width:auto;margin: 2px 0 0 5px;"><a href="javascript:shareFacebook();">Facebook</a></li>' +
            '<li class="d4" style="width:auto;margin: 2px 0 0 5px;"><a href="javascript:shareLinkedIn();">LinkedIn</a></li>' +
            '<li class="d5" style="width:auto;margin: 2px 0 0 5px;"><a href="javascript:shareNewsvine();">Newsvine</a></li>' +
            //'<li class="d6" style="width:auto;margin: 2px 0 0 5px;"><a href="javascript:shareProp();">Propeller</a></li>' +
            '<li class="d7" style="width:auto;margin: 2px 0 0 5px;"><a href="javascript:shareYahoo();">Yahoo! Buzz</a></li>' +
            '</ul>';
            }



    var el=(document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? document.layers[id]: null;
    if (el) {
        el.innerHTML=sharHTML;
    }
}


function togShareLinks(id) {
    var el=(document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? document.layers[id]: null;
    if (el) {
        if (el.style.visibility == "hidden") {
            el.style.visibility="visible";
            putShareLinks(id);
        }else{
            el.style.visibility="hidden";
        }
    }
}


function showShareOverlay() {
    var strShareOverlay = '<div id="shareTab"></div>';
    strShareOverlay += '<div id="shareShadow"><div id="shareContents">';
    for (i=0; i<arrShareLinks.length; i++) {
        if ((i%2) == 0) {
            strShareOverlay += '<div class="shareTool">';
            strShareOverlay += '<a id="' + trimTools(arrShareLinks[i]).toLowerCase() + 'Link" href="' + arrShareLinks[i+1] + '">' + parseShareName(arrShareLinks[i]) + '</a>';
            strShareOverlay += '</div>';
        }
    }
    strShareOverlay += '<div id="shareWhat"><a href="javascript:sharePop('+"'/tools/share', 540, 600, 'sharePopup'"+');">(what is this?)</a></div>';
    strShareOverlay += '</div></div>';
    strShareOverlay += '<div id="shareCloseButton"><a href="javascript:hideShareOverlay();"></a></div>';
    if (document.getElementById) {
        var intShareX = document.getElementById("shareLink").offsetLeft - 6;
        var intShareY = document.getElementById("shareLink").offsetTop + document.getElementById("shareLink").offsetHeight - 2;
        document.getElementById("shareContainer").innerHTML = strShareOverlay;
        document.getElementById("shareContainer").className = "";
        document.getElementById("shareContainer").style.cssText = "position:absolute; top:" + intShareY + "px; left:" + intShareX + "px;";
    }
}

function hideShareOverlay() {
    if (document.getElementById) {
        document.getElementById("shareContainer").innerHTML = "";
        document.getElementById("shareContainer").className = "hidden";
        document.getElementById("shareContainer").style.cssText = "";
        shareOverlayFocus = false;
    }
}
