﻿// Opens up a new windows at the specified address, using the parameters set fo the help page.
function OpenHelpWindow(targetPage)
{
	var helpWindow = window.open(targetPage, 'Helps', 'width=600, height=554, resizable=0, toolbar=yes, toolbar=0');
	if (helpWindow)
	{
		helpWindow.focus();
	}
}

//Preloads an image at the specified path.
function PreLoadImage(imagePath) {
    if (document.images) {
        preloadedImage = new Image();
        preloadedImage.src = imagePath;
    }
}

//Change the src of the specified element to the specified path.
function ChangeImage(element, imagePath) {
    if (document.images) {
        element.src = imagePath;
	}
}

//Adds a thousands seperator to the specified number. If the value is not a number, the value will be returned unchanged.
function AddThousandsSeperatorToNumber(number) {
	if (isNaN(number))
		return number;
   	number += '';
   	x = number.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;
}

//Performs a click event on the specified object.
function DoClick(obj) {
    try {
        var evt = document.createEvent('MouseEvents');
        evt.initMouseEvent('click', false, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
        obj.dispatchEvent(evt);
    }
    catch (e) {
        obj.click();
    }
}

//Checks if last key press was on the enter key, and calls the specified function.
function CatchEnter(delegateFunction, evnt) {
    var e = evnt || window.event;
    if (e.keyCode == 13) {
        e.cancelBubble = true;
        e.returnValue = false;
        if (e.preventDefault)
            e.preventDefault();
        delegateFunction();
    }
    return false;
}

//Opens up a new windows at the specified address, using the parameters set fo the quickstats page.
function OpenQuickStatsWindow(targetPage) {
    var quickStatsWindow = window.open(targetPage, 'QuickStats', 'width=800, height=565, location=yes, scrollbars=yes, resizable=yes');
    if (quickStatsWindow) {
        quickStatsWindow.focus();
    }
}
