﻿
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-z0-9!#/`~%=+\-]([a-z0-9!#/`~%=+\-_\.]*)@([a-z0-9!#/`~%=+\-_\.]*)([.][a-z0-9!#/`~%=+\-]{3})$)|(^[a-z0-9!#/`~%=+\-]([a-z0-9!#/`~%=+\-_\.]*)@([a-z0-9!#/`~%=+\-_\.]*)(\.[a-z0-9!#/`~%=+\-]{3})(\.[a-z0-9!#/`~%=+\-]{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.
	*************************************************/
	// JKF - 20101123 - Made matches more permissive
    var objRegExp = /^([\(]{1}[0-9]{3}[\)]{1}[\.| |\-]{0,1}|^[0-9]{3}[\.|\-| ]?)?[0-9]{3}(\.|\-| )?[0-9]{4}$/;

	//check for valid us phone 
	return objRegExp.test(strValue);
}
