﻿function doHourglass()
{
    document.body.style.cursor = 'wait';
}

function formatTimeTextboxes(sString)
{
    while (sString.substring(0, 1) == ' ')
    {
        sString = sString.substring(1, sString.length);
    }
    
    while (sString.substring(sString.length - 1, sString.length) == ' ')
    {
        sString = sString.substring(0, sString.length - 1);
    }
    
    if (sString.length == 1)
    {
        sString = "0" + sString;
    }
    
    return sString;
}

function limitKeyPress(evnt)
{
    if (((evnt.keyCode > 47) && (evnt.keyCode < 58)) || (evnt.keyCode == 46))
    {
        return true;
    }
    else
    {
        return false;
    }
}

function roundDecimals(valueToRound, numDecs)
{
    var num = Math.round(Math.pow(10, parseInt(numDecs)) * parseFloat(valueToRound)) / Math.pow(10, parseInt(numDecs));
    if (isNaN(num))
    {
        num = "";
    }

    return num;
}

var openedResizableWindow = null;
function openResizableWindow(windowName, windowHeight, windowWidth, windowLocation)
{
    //Remove special characters from name
    name = name.replace(/\/|\-|\./gi, "");

    //Remove whitespaces from name
    var whitespace = new RegExp("\\s", "g");
    name = name.replace(whitespace, "_");

    //If it is already open
    if (openedResizableWindow && !openedResizableWindow.closed && openedResizableWindow.location)
    {
        openedResizableWindow.location.href = windowLocation;
    }
    else
    {
        openedResizableWindow = window.open(windowLocation, windowName, "location=no, scrollbars=yes, resizable=yes, toolbar=no, menubar=no, width=" + windowWidth + ", height=" + windowHeight);
        if (!openedResizableWindow.opener)
        {
            openedResizableWindow.opener = self;
        }
    }

    //If my main window has focus - set it to the popup
    if (window.focus)
    {
        openedResizableWindow.focus()
    }
}
