﻿function GetSelectedValues(select)
{
    var r = new Array();
    for (var i = 0; i < select.options.length; i++)
        if (select.options[i].selected)
        {
            r[r.length] = select.options[i].value + "|" + select.options[i].text;
        }
    return r;
}

function formatCurrency(num)
{
    num = num.toString().replace(/\$|\,/g, '');
    if (isNaN(num))
        num = "0";
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num * 100 + 0.50000000001);
    cents = num % 100;
    num = Math.floor(num / 100).toString();
    if (cents < 10)
        cents = "0" + cents;

    for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
        num = num.substring(0, num.length - (4 * i + 3)) + ',' + num.substring(num.length - (4 * i + 3));

    return (((sign) ? '' : '-') + num + '.' + cents);
}

function GetPrimarySelectedValue(selectid)
{
    return document.getElementById(selectid).options[document.getElementById(selectid).selectedIndex].value
}

function AppendSeperate(base, toadd, sep)
{
    if(base != "")
        base += sep
    
    base += toadd;
    return  base;
}

function appendCombo(theSel, newText, newValue)
{
    if (theSel.length == 0)
    {
        var newOpt1 = new Option(newText, newValue);
        theSel.options[0] = newOpt1;
        theSel.selectedIndex = 0;
    }
    else if (theSel.selectedIndex != -1)
    {
        var selText = new Array();
        var selValues = new Array();
        var selIsSel = new Array();
        var newCount = -1;
        var newSelected = -1;
        var i;
        for (i = 0; i < theSel.length; i++)
        {
            newCount++;
            selText[newCount] = theSel.options[i].text;
            selValues[newCount] = theSel.options[i].value;
            selIsSel[newCount] = theSel.options[i].selected;

            if (newCount == theSel.selectedIndex)
            {
                newCount++;
                selText[newCount] = newText;
                selValues[newCount] = newValue;
                selIsSel[newCount] = false;
                newSelected = newCount - 1;
            }
        }
        for (i = 0; i <= newCount; i++)
        {
            var newOpt = new Option(selText[i], selValues[i]);
            theSel.options[i] = newOpt;
            theSel.options[i].selected = selIsSel[i];
        }
    }
}
