// generic textstring functions written by JAS (of CTSI) - please do not steal

function isAlpha(strText) {
	if (isWhiteSpace(strText)) {return false;}	//strText = new String("" + strText);
	var retAlpha = strText.match(/(^[A-Z]+(\.?[\-\' ]?[A-Z]+)*(\.?[\-\' ]?[A-Z]+)*$)/gi); //allows common lastname and city characters as well
	if (!retAlpha) {return false;} else {return true;}
}

function isAlphaNum(strText) {
	if (isWhiteSpace(strText)) {return false;}
	var retAlphaNum = strText.match(/(^[\w\-\'\.\,\#\&\* ]+$)/g); //allows common lastname, address, decimal characters, and search wildcards
	if (!retAlphaNum) {return false;} else {return true;}
}

function isEmpty(strIn) {
	return (strIn==null || strIn=="" || typeof(strIn)=="undefined"); 
}

function isWhiteSpace(strIn) {
	if (isEmpty(strIn)) {return true;}
	var strTest = new String(strIn).replace(/\s/g,"");
	return (strTest=="");
}

function isDateJS(strIn) { 
	//use in combination with formatDateY2K() for handling of leap days and acceptable years
	return ((!isEmpty(strIn)) && (!isNaN(Date.parse(strIn))));
} 	

function isDateLater(strDate1,strDate2) {
	//requires isDateJS() function above
	if (!isDateJS(strDate1) || !isDateJS(strDate2)) {return false;}
	var intDate1 = Date.parse(strDate1);
	var intDate2 = Date.parse(strDate2);
	return (intDate1 > intDate2);
} 

function formatDateY2K(strDate) {  // if valid date passed in, reformats it to MM/DD/YYYY 
	if (!isDateJS(strDate)) {return "";} 	// requires isDateJS() function above
	var d = new Date(strDate), intYear = d.getFullYear();
	if ((intYear<1950 && intYear>=1900) && (strDate.search(/((\s|\/|\-)19\d{2,2})/)==-1))
		{intYear=d.getYear()+2000;} //user typed in year as 0-50
	if (intYear>2199){intYear=2199;}
	if (intYear<1800){intYear=1800;}
	return (d.getMonth()+1) + "/" + d.getDate() + "/" + intYear;
}

function trimJS(strText) { // LTrim() and RTrim()
	if (isEmpty(strText)) {return "";} // handle null & undefined
	return (strText.replace(/^\s+/g,"").replace(/\s+$/g,""));
}

function removeExtraSpaces(strText) { // replace extra whitespaces with a single space
	strText = trimJS(strText);
	return (strText.replace(/\s+/g,' '));
}

function isZip(strZip) {
	var retZip = strZip.match(/(^(\d{5}|\d{5}\-\d{4})$)/g);
	if (!retZip) {return false;} else {return true;}
}

function getRepeatString(strToRepeat,timesToRepeat) {
	var strTmp='';
	for (var i=1; i<=timesToRepeat; i++) {strTmp += strToRepeat;}
	return strTmp;
}