﻿
function getEl(elementId)
{
	return document.getElementById(elementId);
}

function gub(msg)
{
	alert(msg);
}

// returns with format $0.00
function formatMoney(num)
{
	if (isNaN(num)) return num;

	if (num === '' || num == null) return num;

	return "$" + parseFloat(num).toFixed(2);
}

function hide(elementId)
{
	getEl(elementId).style.display = "none";
}

function show(elementId)
{
	getEl(elementId).style.display = "block";
}

function showInline(elementId)
{
	getEl(elementId).style.display = "inline";
}

function setClass(elementId, className)
{
	getEl(elementId).className = className;
}

// rgbToHex snagged from StackOverflow
function rgbToHex(rgbString)
{
	var parts = rgbString.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
	delete (parts[0]);

	for (var i = 1; i <= 3; ++i)
	{
		parts[i] = parseInt(parts[i]).toString(16);
		if (parts[i].length == 1) parts[i] = '0' + parts[i];
	}
	var hexString = parts.join('');
	return hexString;
}

function validateEmail(strValue)
{
	/************************************************
	DESCRIPTION: Validates that a string contains a
	valid email pattern.

	PARAMETERS:
	strValue - String to be tested for validity

	RETURNS:
	True if valid, otherwise false.

	REMARKS: Accounts for email with country appended
	does not validate that email contains valid URL
	type (.com, .gov, etc.) or valid country suffix.
	*************************************************/
	var objRegExp = /(^[a-z]([a-z_\.]*)@([a-z_\.]*)([.][a-z]{3})$)|(^[a-z]([a-z_\.]*)@([a-z_\.]*)(\.[a-z]{3})(\.[a-z]{2})*$)/i;

	//check for valid email
	return objRegExp.test(strValue);
}

function validateUSPhone(strValue)
{
	/************************************************
	DESCRIPTION: Validates that a string contains valid
	US phone pattern.
	Ex. (999) 999-9999 or (999)999-9999

	PARAMETERS:
	strValue - String to be tested for validity

	RETURNS:
	True if valid, otherwise false.
	*************************************************/
	var objRegExp = /^\([1-9]\d{2}\)\s?\d{3}\-\d{4}$/;

	//check for valid us phone with or without space between
	//area code
	return objRegExp.test(strValue);
}