var PattDict = new Object();
PattDict.postalCodeUS = /^\d{5}(-?\d{4})?$/;
PattDict.currencyUSD = /^\$?\d{1,3}(,?\d{3})*\.\d{2}$/;
PattDict.time12 = /^((0{0,1}\d)|(1[0-2])):[0-5]\d$/;
PattDict.time24 = /^(([0-1]{0,1}\d)|(2[0-4])):[0-5]\d$/;
PattDict.emailStd = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
PattDict.notEmpty = /.+/;
PattDict.dateMDY = /^[0-1]?\d(\/|-|\.)[0-3]?\d(\/|-|\.)(\d{2}|\d{4})$/;
PattDict.numberNoDec = /^\d+$/;

// just validate the value
function valueValidate(theVal, thePat){
	if(PattDict[thePat]) {
		var testPat = PattDict[thePat]; // select the validating regular expr
		return  testPat.test(theVal); // run it on value of elArr[i]
	}
}

// validate the value of the object
function objValidate(theObj, thePat) {
	return valueValidate(theObj.value, thePat);
}

// If the object validation fails it focues to the object
function objValidateFocus(theObj, thePat) {
	if(!objValidate(theObj,thePat))
	{
		theObj.focus();
		return false;
	}
	return true;
}

function isEmail(str) {
	// are regular expressions supported?
	var supported = 0;
	if (window.RegExp) {
		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr)) supported = 1;
	}
	if (!supported) 
		return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	return (!r1.test(str) && r2.test(str));
}

// Returns index of checked radio button in radio set,
// or -1 if no radio buttons are checked
// See this page for more good functions
// http://www.breakingpar.com/bkp/home.nsf/Doc?OpenNavigator&U=CA99375CC06FB52687256AFB0013E5E9
function getCheckedRadioButton(radioSet)
{ 
	if (radioSet[0]) {
		for (var i=0; i<radioSet.length; i++)
		{
			if (radioSet[i].checked)
			{
				return i;
			}
		}
	}
	else
	{
		if (radioSet.checked)
		{
			return 0;
		}
	}
	return -1;
}

// Usage with FORM SUBMIT: onClick="return confirmDelete()"
// Usage with FORM BUTTON: onClick="if(confirmDelete()) {document.frmItem.submit();}"
function confirmDelete()
{
	var agree = confirm("Are you sure you want to delete this item?");
	if (agree)
	{
		return true;
	}
	else
	{
		return false;
	}
}
