////////////////////////////////////////////////////////////////////////////////
//                        Misc. Functions v1.00                               //
//                                                                            //
//This file containe 3 simple javascript functions that may become usefull.   //
//     The first one, MoneyFormat, will take a str, and turn it into a        //
//properaly listed dollar amount. It will make sure the number has 2 decimals //
//and digit grouping, thousand marker.                                        //
//                                                                            //
//     The second one, isNum, is used by the MoneyFormat to determine if the  //
//string only has numeric digits.                                             //
//                                                                            //
//     The second one, screenpop, is used to popup a window.                  //
//                                                                            //
//      This Page, Script, and/or Associated Scripts are copyrighted 2002     //
//                      Derek Mantey, Hyper                                   //
//      Distribution of this file is not permitted without the writen consent //
//of Derek Mantey or Hyper.                                                   //
////////////////////////////////////////////////////////////////////////////////
function MoneyFormat(str)
{
    isMoneyFormatAmount = 0.00;
    isMoneyFormatString = "0.00";


    str = new String("" + str); // force string
    for (var i=0; i<str.length;i++)
    {
        var ch = str.charAt(i);
        if (!isNum(ch) && ch!='.' && ch != ',' && ch !='-') return false;
    }


    var sign = 1;
    var signChar = '';

    if (str.length > 1)
    {
        signChar = str.substring(0,1);
        if (signChar == '-' || signChar == '+' )
        {
            if (signChar == '-') sign = -1;
            str = str.substring(1);
        }
        else signChar = '';
    }

    var decimalPoint = '.';
    var thDelim = ',';

    test1 = str.split(decimalPoint);
    if (test1.length == 2)
    { // Decimals found
        if (test1[1].length > 2)
        {   // more than 2 decimals
            if (test1[1].charAt(2) > 5)
            {
                temp = new String("");
                temp += parseInt(test1[1].charAt(0));
                temp += parseInt(test1[1].charAt(1)) + 1;
                test1[1] = new String(temp);
            }
            else
            {
                temp = new String("");
                temp += test1[1].charAt(0);
                temp += test1[1].charAt(1);
                test1[1] = new String(temp);
            }
        }

        if (isNum(test1[1]) && test1[1].length < 2)
        {
            test1[1] = new String(test1[1]+"0");
        }
    }
    else test1[1] = "00"; // force decimals

    if (test1[0] == '') test1[0] = 0;

    if(test1[0].length > 3)
    {
        var setmax = Math.round((test1[0].length + 1)/3) - 1;
        var set = 0;
        var test2 = new Array();

        for(var i=test1[0].length; i>0; i-=3)
        {
            if (i-3 < 0) test2[setmax - set] = test1[0].substring(0, i);
            else test2[setmax - set] = test1[0].substring(i-3, i);
            set++;
        }
        test1[0] = test2.join();
    }

    isMoneyFormatAmount = (parseInt(test1[0]) + parseFloat('.'+test1[1]))*sign;
    isMoneyFormatString = new String(signChar+test1[0] +'.'+test1[1]);
    return isMoneyFormatString;
}

function isNum(str)
{
    if(!str) return false;
    for(var i=0; i<str.length; i++)
    {
        var ch=str.charAt(i);
        if ("0123456789".indexOf(ch) ==-1) return false;
    }
    return true;
}

function screenpop(url)
{
    link = window.open(url,"screenpop","toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=1,width=350,height=350");
}