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})$/;

// 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 focuses 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));
}

// If the object validation fails it focuses to the object
function objValidateDropdownFocus(theObj, thePat) {
	if(!objValidate(getDropdownSelected(theObj),thePat))
	{
		theObj.focus();
		return false;
	}
	return true;
}


// Returns index of dropdown selected from index,
function getDropdownSelected(dropDown) {
   selectionValue=dropDown.options[dropDown.selectedIndex];
   return selectionValue;
}


// Returns index of checked radio button in radio set,
// or -1 if no radio buttons are checked
function getCheckedRadioButton(radioSet)
  { 
  for (var i=0; i<radioSet.length; i++)
    if (radioSet[i].checked)
      return i;
  return -1;
  }
