function checkExtension(phoneExt){
	var rePhoneExt = /^\d{4}$/;
	return rePhoneExt.test(phoneExt);
}

function selectByText(oLst, txtToFind){
/*	oLst: SELECT tag
*	txtToFind: Text to Find
*	Returns index of first occurrence of txtToFind within oLst, -1 if not found
*/
	if (oLst){
		for (var i=0; i < oLst.options.length; i++){
			if (oLst.options[i].text.toUpperCase()== txtToFind.toUpperCase()){
				oLst.selectedIndex = i;
				return i;
			}
		}
	}
	return -1;
}

function selectByVal(oLst, valToFind){
/*	oLst: SELECT tag
*	valToFind: Text to Find
*	Returns index of first occurrence of valToFind within oLst, -1 if not found
*/
	if (oLst){
		for (var i=0; i < oLst.options.length; i++){
			if (oLst.options[i].value.toUpperCase()== valToFind.toUpperCase()){
				oLst.selectedIndex = i;
				return i;
			}
		}
	}
	return -1;
}
function isDate(dateValue){
/* validates a date formatted using mm/dd/yyyy. returns the date itself if valid, null otherwise */		
	var reDate = /[^\/]+/g; // match anything that is not '/' 
	var dateArr = dateValue.match(reDate);
	if (dateValue =='')
		return null;
	else if (dateArr.length < 3)
		return null;
	else {
		for (i=0 ; i < dateArr.length ; i++)
		dateArr[i] = Number(dateArr[i]); // remove leading zeroes	
		var oDate = new Date(dateValue);		
		var YEAR = dateArr[2], MONTH = dateArr[0], DAY = dateArr[1];
		if ( YEAR == oDate.getFullYear() && MONTH == oDate.getMonth() + 1 && DAY == oDate.getDate() )
			return dateValue;
		else
			return null;			
	}				
}
		
function DateFromYMD(nYear, nMonth, nDate)
{	/* 	Validates Dates. 
		Returns 	Date constructed from nYear nMonth and ndate if success. 
					Null if nYear, nMonth and nDate are not a valid Date.
	*/
	
	var dDate = new Date();

	dDate.setFullYear(nYear, nMonth, nDate);
	if(dDate.getFullYear() != nYear)
		return null;
	if(dDate.getMonth() != nMonth)
		return null;
	if(dDate.getDate() != nDate)
		return null;
	return dDate;
}

