﻿// JScript File
function formatKSeperator(nStr) {
    nStr += '';
    x = nStr.split('.');
    x1 = x[0];
    x2 = x.length > 1 ? '.' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1)) {
        x1 = x1.replace(rgx, '$1' + ',' + '$2');
    }
    return x1 + x2;
}

function formatPPDNumber(nStr) {
    if (nStr <= 0) return "";
    return formatKSeperator(nStr);
}
/*****************************************************************************
* To know whether a check box is checked base on the id.
*****************************************************************************/
function isChecked(p_id)
{
    var ret = false;
    var chk = document.getElementById(p_id);
    if (chk != null)
    {
        ret = chk.checked;
    }
    return ret;
}

/*****************************************************************************
* Check, uncheck all Stock Symbol filter check boxes.
*****************************************************************************/
function setAllCheckBoxes(p_sChkName, p_checked) {
    if (p_sChkName != null) {
        var arrChk = document.getElementsByName(p_sChkName);
        for (i = 0; i < arrChk.length; i++) {
            arrChk[i].checked = p_checked;
        }
    }
}


/*****************************************************************************
* Check, and set value for value attribute of the button specified by id
*****************************************************************************/
function setBtnValue(p_id, p_value)
{
    var btn = document.getElementById(p_id);
    if (btn != null)
    {
        btn.value = p_value;
    }
}

/*****************************************************************************
* 
*****************************************************************************/
function setWidthByTdOffsetWidth(p_id)
{
    var td = document.getElementById(p_id);
    if (td != null)
    {
        return (" width='" + td.offsetWidth + "px' ");
    }
    else
    {
        return "";
    }
}

function UpdatePutthroughLangguage() {
    var objElement = document.getElementById("bPutthrough");
    if (objElement != null) {
        objElement.innerHTML = langTxt.Txt_PutthroughAd;
    }
}

function addToFavorites(urlAddress, pageName) {
    if (window.sidebar) { // Firefox
        window.sidebar.addPanel(pageName, urlAddress, "");
    } else if (window.external) { // IE
        window.external.AddFavorite(urlAddress, pageName);
    } else {
        return true;
    }
}
