
/* utility javascript functions */
 
function OpenCertDetails()
{
thewindow =window.open('https://www.thawte.com/cgi/server/certdetails.exe?code=GBFLAS6', 'anew',config='height=400,width=450,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,directories=no,status=yes');
}


function openWin(strFile, strName, intWidth, intHeight)
{
    var strProperties = 'toolbar=no,width=' + Math.round(intWidth) + ',height=' + Math.round(intHeight) + ',left=30,top=150,' + 'status=no,scrollbars=yes,resizable=yes,menubar=no';
    tmpWin = window.open(strFile,strName,strProperties);
    tmpWin.focus();
}

function appendHTTP(url)
{
    // appends http:// to url is not already present
    var re = /^http:\/\//i;
    if (!url.match(re))
    {
        url = "http://" + url;
    }
    return url;
}

function getRandomNumber(low, high)
{

    // desc: generates random no between low and high
    // arguments: low(integer), high(integer)
    // returns: number

    var i;

    if (low >= high){
        return null;
    }
    else{
        i = Math.random();
        return Math.round(low + ((high - low) * i));
    }
}

function roundOff(value, precision)
{
    value = "" + value;
    precision = parseInt(precision);

    var whole = "" + Math.round(value * Math.pow(10, precision));

    var decPoint = whole.length - precision;

    if (decPoint != 0)
    {
            result = whole.substring(0, decPoint);
            result += ".";
            result += whole.substring(decPoint, whole.length);
    }
    else
    {
            result = whole;
    }
    return result;
}

function addCommas(number)
{
    // adds commas to numbers eg 1,000,000
    number = '' + number;
    if (number.length > 3)
    {
        var mod = number.length % 3;
        var output = (mod > 0 ? (number.substring(0,mod)) : '');

        for (i=0 ; i < Math.floor(number.length / 3); i++)
        {
            if ((mod == 0) && (i == 0))
            {
                output += number.substring(mod+ 3 * i, mod + 3 * i + 3);
            }
            else
            {
                output += ',' + number.substring(mod + 3 * i, mod + 3 * i + 3);
            }
        }

        return (output);
    }
    else
    {
        return number;
    }
}

function removeCommas(number)
{
    number = number.toString();
    return number.replace(",", "");
}

/*
 * removes leading and trailing whitespace
 * from a string
 */
function trim(input)
{
    return input.replace(/(^\s)|(\s$)/g,"");
}

/*
 * removes leading whitespace from a string
 */
function ltrim(input)
{
    return input.replace(/(^\s)/g,"");
}

/*
 * removes  trailing whitespace from a string
 */
function rtrim(input)
{
    return input.replace(/(\s$)/g,"");
}

/*
 * generates a simple random password
 */
function generatePassword(maxlength)
{
    var chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    var password = "";
    for (var i = 0; i < maxlength; i++)
    {
        password += chars.charAt(chars.length * Math.random());
    }
    return password;
}