<!--
//*************** ISEMPTY ***************//
function isEmpty(s)
{   
	return ((s == null) || (s.length == 0));
}
//*************** ISWHITESPACE ***************//
function isWhitespace (s)
{
	var i;
	if (isEmpty(s)) return true;
	for (i = 0; i < s.length; i++)
	{
		// Check that current character isn't whitespace.
		var c = s.charAt(i);
		if (c != ' ') return false;
	}
	return true;
}
//*************** LTRIM ***************//
function lTrim(s){
	if(s.length==0){return s;}
	else{
		for (var i=0; i<s.length; i++){
			if (s.charAt(i) != ' ') return(s.slice(i));
		}
	}
	return s;
}	
//*************** RTRIM ***************//
function rTrim(s){
	if(s.length==0){return s;}
	else{
		for (var i=s.length-1; i>=0; i--){
			if (s.charAt(i) != ' ') return(s.slice(0,i+1));
		}
	}		 
	return s;	
}
//*************** TRIM ***************//
function trim(s){
	if(isWhitespace(s)){return s;}

	else{
		return(rTrim(lTrim(s)));
	}
}
//*************** ISNUM ***************//
function isNum(strIn)  // See also IsNaN()
{
	var strValue = trim(strIn);
	// Is the value numeric (decimal or whole number and No negatives)?
	if (strValue == ""){ 
		return false;}
	else
	{
		for (i=0; i<strValue.length; i++) 
		{
			if ((strValue.charAt(i) < "0") || (strValue.charAt(i) > "9"))
				{if  (strValue.charAt(i) != "."){
					return false;}}
		}
	}
	return true;
}
//*************** ISWHOLENUM ***************//
function isWholeNum(strIn)
{
        var strValue = trim(strIn);
	// Is the value a whole number (no decimals or negatives)?
	if (strValue == ""){ 
		return false;}
	else
	{
		for (i=0; i<strValue.length; i++) 
		{
			if ((strValue.charAt(i) < "0") || (strValue.charAt(i) > "9"))
				{return false;}
		}
	}
	return true;
}
//*************** ISZIP ***************//
function isZip(strZip){
	strZip=trim(strZip);
	if(strZip==""){return true;}
	if(strZip=="00000"){return false;}
	if(strZip.length!=5&&strZip.length!=10){return false;}
	if(strZip.length==5){
		if(!isWholeNum(strZip)){return false;}
	}
	if(strZip.length==10){
		if(strZip.indexOf('-')!=5){return false;}
		var firstfive=strZip.slice(0,5);
		if(!isWholeNum(firstfive)){return false;}
		var lastfour=strZip.slice(6);
		if(!isWholeNum(lastfour)){ return false;}
	}
	return true;
}
//*************** ISDATE ***************//
function isDate(strDate)
///////////////////////////////////////////////////////////////////
//  Check to see if isDate2 below will work instead of this one first.
///////////////////////////////////////////////////////////////////
{
	strDate = trim(strDate);
	if (strDate==""){return true;}
	if (strDate.length<6||strDate.length> 10){return false;}
	if(strDate.indexOf(" ")!=-1){return false;}
	if(strDate.indexOf("-")==-1&&strDate.indexOf("/")==-1){return false;}
	if(strDate.indexOf("-")!=-1&&strDate.indexOf("/")!=-1){return false;}
	if(strDate.indexOf("-")!=-1){
		var isHyphen=true;
	}
	else{
		var isHyphen=false;
	}
	var pos = 0;
	var oldPos = -1;
	if(isHyphen){
		pos = strDate.indexOf("-");
	}
	else{
		pos = strDate.indexOf("/");
	}
	if(pos!=1&&pos!=2){return false;}
	nMonth =  strDate.substring(oldPos + 1,pos);
	if(!isWholeNum(nMonth)){return false;}
	nMonth =  parseInt(nMonth,10);
	if ( (nMonth > 12) || (nMonth < 1)){ return false;}
	oldPos = pos;
	if(isHyphen){
		pos = strDate.indexOf("-", oldPos + 1);
	}
	else{
		pos = strDate.indexOf("/", oldPos + 1);
	}
	if(pos!=3&&pos!=4&&pos!=5){ return false;}
	nDay   = strDate.substring(oldPos + 1,pos);
	if(!isWholeNum(nDay)){return false;}
	nDay   = parseInt(nDay,10);
	oldPos = pos;
	if(isHyphen){
		pos = strDate.indexOf("-", oldPos + 1);
	}
	else{
		pos = strDate.indexOf("/", oldPos + 1);
	}
	if(pos != -1){ return false;}
	nYear   = strDate.substring(oldPos + 1, strDate.length);
	if(!isWholeNum(nYear)){return false;}
	if(nYear.length!=2&&nYear.length!=4){return false;}
	if(nYear.length==2){
		if(parseInt(nYear.charAt(0),10)<3){nYear='20'+nYear;}
		if(parseInt(nYear.charAt(0),10)>=3){nYear='19'+nYear;}
	}
	nYear=parseInt(nYear,10);
	if ((nYear < 0) ){ return false;}
	// for SQL server Gregorian calendar limitation
	if ((nYear < 1900) || (nYear > 2078)){ return false;}
	switch(nMonth){
		case 1:
		case 3:
		case 5:
		case 7:
		case 8:
		case 10:
		case 12:
			if ( (nDay > 31) || (nDay < 1)){
				return false;
			}
			break;
		case 2:
			if ((nYear%4)==0){ // leap year
				if ((nDay > 29) || (nDay < 1)){
					return false;
				}
			}
			else{  // non-leap year
				if ( (nDay > 28) || (nDay < 1)){
					return false;
				}
			}
			break;
		case 4:
		case 6:
		case 9:
		case 11:
			if ((nDay > 30) || (nDay < 1)){
				return false;
			}
			break;
	}
	return true;
}
//*************** ISEMAIL ***************//
function isEmail(strEmail)
{
	strEmail = trim(strEmail);
	if (strEmail == "") {return true;}
	invalidChars = " /:,;'";
	for (i=0; i<invalidChars.length; i++){
		badChar = invalidChars.charAt(i);
		if (strEmail.indexOf(badChar,0) != -1){ return false;}
	}
	atPos = strEmail.indexOf("@",1);
	if (atPos == -1){ return false;}
	// should not be more than one @ symbol
	if (strEmail.indexOf("@",atPos+1) != -1){ return false;}
	// at least one . after the @
	dotPos = strEmail.indexOf(".",atPos);
	if (dotPos == -1){ return false;}
	return true;
}
//*************** ISCITY ***************//
function isCity(str){
	// check if city  str is pure alphabet chars and no numbers
	//isCity not check '()., while isChar checks it
	str = trim(str);
 	if (str=="") return true;
	invalidChars = ";:\"=|/?><+-*&^_%$#@!~\\{}[]`1234567890";
	for (i=0; i<invalidChars.length; i++){
		badChar = invalidChars.charAt(i);
		if (str.indexOf(badChar,0) != -1){ return false;}
	}
	return true;
}
//*************** ISCHAR ***************//
function isChar(str){
	// check if str is pure alphabet chars and no numbers
	str = trim(str);
	invalidChars = ";:'\"=|/?><.,+-*&()^_%$#@!~\\{}[]`1234567890";
	for (i=0; i<invalidChars.length; i++){
		badChar = invalidChars.charAt(i);
		if (str.indexOf(badChar,0) != -1){ return false;}
	}
	return true;
}
//*************** ISYEAR ***************//
function isYear(strYear){
	strYear= trim(strYear);
	if(strYear==''){return true;}	
	return (strYear.length == 4 && isWholeNum(strYear) && (strYear.charAt(0)=="1"||strYear.charAt(0)=="2"));
}
//*************** ISDEA ***************//
function isDEA(strDEA,doctorLastName){
	if(strDEA==''){return true;}
	//if(doctorLastName==''){return true;}
	strDEA= trim(strDEA);
	doctorLastName=trim(doctorLastName);
	var doctorLastNameInit=doctorLastName.charAt(0);
	doctorLastNameInit = doctorLastNameInit.toUpperCase();
	strDEA= strDEA.toUpperCase();

	//Validate against DEA format	
	if(strDEA.length!=9){return false;}
	if(!isChar(strDEA.charAt(0))){return false;}
	if(!isChar(strDEA.charAt(1))){return false;}
	if(!isWholeNum(strDEA.charAt(2))){return false;}
	if(!isWholeNum(strDEA.charAt(3))){return false;}
	if(!isWholeNum(strDEA.charAt(4))){return false;}
	if(!isWholeNum(strDEA.charAt(5))){return false;}
	if(!isWholeNum(strDEA.charAt(6))){return false;}
	if(!isWholeNum(strDEA.charAt(7))){return false;}
	if(!isWholeNum(strDEA.charAt(8))){return false;}

	//Validate against DEA formula
	if(strDEA.charAt(0)!="A"){if(strDEA.charAt(0)!="B"){if(strDEA.charAt(0)!="M"){return false;}}}
	//if(strDEA.charAt(1)!=doctorLastNameInit){return false;}
	var a;
	a=parseInt(strDEA.charAt(3))+parseInt(strDEA.charAt(5))+parseInt(strDEA.charAt(7));
	var b;
	b=parseInt(strDEA.charAt(2))+parseInt(strDEA.charAt(4))+parseInt(strDEA.charAt(6));
	var d;
	d=parseInt(strDEA.charAt(8));
	var c;
	c=(2*a)+b;
	if(c % 10 != d){return false;}
	return true;
}
//*************** ISFIVEFOURTWO ***************//
function isFiveFourTwo(str){
	if(str==''){return true;}
	str= trim(str);
	//Validate against 5-4-2 format	
	if(str.length!=13 && str.length!=11){return false;}
	if(str.length==13){
		if(!isWholeNum(str.charAt(0))){return false;}
		if(!isWholeNum(str.charAt(1))){return false;}
		if(!isWholeNum(str.charAt(2))){return false;}
		if(!isWholeNum(str.charAt(3))){return false;}
		if(!isWholeNum(str.charAt(4))){return false;}
		if(str.charAt(5)!="-"){return false;}
		if(!isWholeNum(str.charAt(6))){return false;}
		if(!isWholeNum(str.charAt(7))){return false;}
		if(!isWholeNum(str.charAt(8))){return false;}
		if(!isWholeNum(str.charAt(9))){return false;}
		if(str.charAt(10)!="-"){return false;}
		if(!isWholeNum(str.charAt(11))){return false;}
		if(!isWholeNum(str.charAt(12))){return false;}
	}
	if(str.length==11){
		if(!isWholeNum(str.charAt(0))){return false;}
		if(!isWholeNum(str.charAt(1))){return false;}
		if(!isWholeNum(str.charAt(2))){return false;}
		if(!isWholeNum(str.charAt(3))){return false;}
		if(!isWholeNum(str.charAt(4))){return false;}
		if(!isWholeNum(str.charAt(5))){return false;}
		if(!isWholeNum(str.charAt(6))){return false;}
		if(!isWholeNum(str.charAt(7))){return false;}
		if(!isWholeNum(str.charAt(8))){return false;}
		if(!isWholeNum(str.charAt(9))){return false;}
		if(!isWholeNum(str.charAt(10))){return false;}
	}
	return true;
}
//*************** ISURL ***************//
function isURL(strURL){
	if(strURL==''){return true;}	
	strURL=trim(strURL);
	if (strURL.indexOf("http://http://") != -1) {return false;}
	if (strURL.indexOf("https://https://") != -1) {return false;}
	if (strURL.indexOf("https://http://") != -1) {return false;}
	if (strURL.indexOf("http://https://") != -1) {return false;}
	if (strURL.indexOf(".") == -1) {return false;}
	if (strURL.indexOf("..") != -1) {return false;}
	if (strURL.indexOf("...") != -1) {return false;}
	if (strURL.indexOf("@") != -1) {return false;}
	if (strURL.indexOf(" ") != -1) {return false;}
	if (strURL.charAt(0)==".") {return false;}
	if (strURL.charAt(strURL.length-1)=='.') {return false;}
	{return true;}
}
//*************** SETSELECT ***************//
function setSelect(oList, vValue, criteria)  {
	if (vValue == "") { return true;}
	for (nIndex=0; nIndex < oList.options.length; nIndex++){
		var opt = oList.options[nIndex];
		if (criteria=="value"){
			if (opt.value == vValue){
				oList.selectedIndex = opt.index;
				break;
			}
		}
		if (criteria=="text"){
			if (opt.text == vValue){
				oList.selectedIndex = opt.index;
				break;
			}
		}
	}
	return true;
}
//*************** FIELDCLEAR ***************//
function fieldclear(frm){
	for(var i=0;i<frm.elements.length;i++){
		if(frm.elements[i].type=="text"||frm.elements[i].type=="textarea"||frm.elements[i].type=="password"){
			frm.elements[i].value="";
		}
		else if(frm.elements[i].type=="select-one"){
			frm.elements[i].selectedIndex=0;
		}
		else if(frm.elements[i].type=="select-multiple"){
			frm.elements[i].selectedIndex=-1;
		}
		else if(frm.elements[i].type=="checkbox"){
			frm.elements[i].checked=false;
		}
	}
}
//*************** CONVERTDATE ***************//
function convertDate(strdate){
	//this function converts date string formatted like '1/1/00' 
	//to a date string formatted like '01/01/2000'

	if(trim(strdate)==''){return strdate;}
	if(strdate.indexOf('/')==-1||strdate.indexOf('/')==0){return strdate;}
	var stryear,strmonth,strday
	var pos1 = strdate.indexOf('/');
	strmonth= strdate.slice(0,pos1);
	if(strmonth.length>2||parseInt(strmonth)>12||!isWholeNum(strmonth)||parseInt(strmonth)==0){return '';}
	var pos2 = strdate.indexOf('/',pos1+1);
	strday=strdate.slice(pos1+1,pos2);
	if(strday.length>2||parseInt(strday)>31||!isWholeNum(strday)||parseInt(strday)==0){return '';}
	stryear=strdate.slice(pos2+1);
	if((stryear.length!=2&&stryear.length!=4)||!isWholeNum(stryear)){return '';}
	if(strmonth.length==1){strmonth='0'+strmonth;}
	if(strday.length==1){strday='0'+strday;}
	if(stryear.length==2){
		if(parseInt(stryear.charAt(0))<7){stryear='20'+stryear;}
		if(parseInt(stryear.charAt(0))>=7){stryear='19'+stryear;}
	}
	return strmonth+'/'+strday+'/'+stryear;
}
//*************** COMPAREDATE ***************//
function compareDate(strdatefrom,strdateto){
	var stryearfrom,strmonthfrom,strdayfrom
	var stryearto,strmonthto,strdayto
	if(strdatefrom.indexOf("-")!=-1){
		var isHyphenfrom=true;
	}
	else{
		var isHyphenfrom=false;
	}
	if(strdateto.indexOf("-")!=-1){
		var isHyphento=true;
	}
	else{
		var isHyphento=false;
	}
	if(isHyphenfrom){
		var pos1from = strdatefrom.indexOf('-');
		strmonthfrom= parseInt(strdatefrom.slice(0,pos1from),10);
		var pos2from = strdatefrom.indexOf('-',pos1from+1);
		strdayfrom=parseInt(strdatefrom.slice(pos1from+1,pos2from),10);
		stryearfrom=strdatefrom.slice(pos2from+1);
	}
	if(!isHyphenfrom){
		var pos1from = strdatefrom.indexOf('/');
		strmonthfrom= parseInt(strdatefrom.slice(0,pos1from),10);
		var pos2from = strdatefrom.indexOf('/',pos1from+1);
		strdayfrom=parseInt(strdatefrom.slice(pos1from+1,pos2from),10);
		stryearfrom=strdatefrom.slice(pos2from+1);
	}
	if(isHyphento){
		var pos1to = strdateto.indexOf('-');
		strmonthto= parseInt(strdateto.slice(0,pos1to),10);
		var pos2to = strdateto.indexOf('-',pos1to+1);
		strdayto=parseInt(strdateto.slice(pos1to+1,pos2to),10);
		stryearto=strdateto.slice(pos2to+1);
	}
	if(!isHyphento){
		var pos1to = strdateto.indexOf('/');
		strmonthto= parseInt(strdateto.slice(0,pos1to),10);
		var pos2to = strdateto.indexOf('/',pos1to+1);
		strdayto=parseInt(strdateto.slice(pos1to+1,pos2to),10);
		stryearto=strdateto.slice(pos2to+1);
	}
	if(stryearfrom.length==2){
		if(parseInt(stryearfrom.charAt(0),10)<3){stryearfrom='20'+stryearfrom;}
		if(parseInt(stryearfrom.charAt(0),10)>=3){stryearfrom='19'+stryearfrom;}
	}
	stryearfrom=parseInt(stryearfrom,10);
	if(stryearto.length==2){
		if(parseInt(stryearto.charAt(0),10)<3){stryearto='20'+stryearto;}
		if(parseInt(stryearto.charAt(0),10)>=3){stryearto='19'+stryearto;}
	}
	stryearto=parseInt(stryearto,10);
	var thedatefrom = new Date(stryearfrom,strmonthfrom-1,strdayfrom);
	var thedateto = new Date(stryearto,strmonthto-1,strdayto);
	var from=thedatefrom.valueOf();
	var to=thedateto.valueOf();
	if(from>to){return false;}
	return true;
}
function checkDate(objCaller){
// ----------------------------------------------------------------------------
//	CHECKDATE -- This function is new to validation.js as of v1.1
//-----------------------------------------------------------------------------
//	Description:
//		makes a call to formatDate - returns false and pops up error
//		if can't be converted to date-type format.
//	Input:
//		objCaller	- object reference of the item we are checking
//	Output:
//		- sends the properly formated string to objCallers value 
//		- returns false if the string can not be formatted correctly
//		  (sends false to avoid form submit in formValidate page function)
//	Author:
//		Mitch Wagner - 11/06/00
// Modified:
//		Bill Seling - 11/08/00 to be used as checkDate from checkPhone
//		Mitch Wagner - 12/20/02 updated to return true (still sets textbox value as well)
// ----------------------------------------------------------------------------
	var strToCheck = objCaller.value
	
	//only do this if it's not empty
	if(strToCheck){
		var strReturn = formatDate(strToCheck);
		var errorMessage = ' Invalid date format or invalid date:\n Dates need to be input as mm/dd/yyyy'
	
		// display message if false was returned
		// otherwise throw the formatted version back to the text box
		if(strReturn){
			objCaller.value = strReturn;
			return(true);
		}
		else{
			alert(errorMessage);
			objCaller.focus();
			objCaller.select();
			// if being called from within an event, set returnValue false - to avoid IE5 bug.
			if(event){event.returnValue = false;}
			return(false);
		}
	}
}
function formatDate(strToFormat){
// ----------------------------------------------------------------------------
//	 FORMATDATE -- This function is new to validation.js as of v1.1
//-----------------------------------------------------------------------------
//	Description:
//		makes a call to:
//			- padDate: returns values of mm dd yyyy
//			- stripChar: returns value of mmddyyyy stripped of special characters
//           named below in arrChar.
//			- checkMinLength: verifies length of a string
//			- insertChar: Inserts characters to format date, i.e. mm/dd/yyyy
//			- isDate2: returns True/False determining if the date passed is a real date.
//	Input:
//		strToFormat	- value of textbox containing a date value
//	Output:
//		- sends the properly formated string mm/dd/yyyy to objCallers value 
//		- returns false if the string can not be formatted correctly
//		  (sends false to avoid form submit in formValidate page function)
//	Author:
//		Mitch Wagner - 11/06/00
// Modified:
//		Bill Seling - 11/08/00 for checking for valid dates.
// ----------------------------------------------------------------------------
	var intDateLen = 8
	var returnString = ''
	// Date type characters to strip out: 
	// need to preceed special characters with double wack
	arrChar = new Array('\\/', '-', ' ', '\\.');
	var paddedString = padDate(strToFormat, arrChar);
	var cleanString = stripChar(paddedString, arrChar);
	//make sure they entered numbers
	if(isNaN(cleanString)){
		return(false);
	}
	//check if it has min amount of characters needed and return length
	var intcleanStringLen = checkMinLength(cleanString,intDateLen)
	// if we have 8 digits - format it
	if(intcleanStringLen==intDateLen){
		// insert slashes
		returnString = insertChar(cleanString, '/', 4);
		returnString = insertChar(returnString, '/', 2);
		
		// we've formatted it so now, verify it is a real date
		if(isDate2(returnString)){
			// valid date, return it
			return(returnString);
		}
		else{
			// not a valid date, return false
			return(false);
		}
	}
	else{
		return(false);
	}
}
function padDate(strToPad, arrChar){
// ----------------------------------------------------------------------------
//	 PADDATE -- This function is new to validation.js as of v1.1
//-----------------------------------------------------------------------------
//	Description:
//		Adds zero before one character months and/or days. Helps work with
//		dates that come in a m/d/yy format.
//	Input:
//		Support for the following input:
//			MMDDYY, MMDDYYYY, MM/DD/YY, MM/DD/YYYY, M/D/YY, M/D/YYYY
//			any delimiter besides slash can be sent in array
//	Output:
//		- sends back input string with mm dd yyyy formatted dates.
//	Author:
//		Mitch Wagner - 11/06/00
// ----------------------------------------------------------------------------

	var strTempPad = strToPad;
	for (i = 0; i < arrChar.length; i++){
		var strTmpChar = arrChar[i]
		// if the length of arrChar is greater than 1 it's sent as a special
		// character so use only the character on the right
		if(strTmpChar.length > 1){
			strTmpChar=strTmpChar.charAt(strTmpChar.length - 1)
		}
		// get the location of this arrchar character
		// grab the last character of arrChar (support for special characters in  array)
		intCharLoc1 = strTempPad.indexOf(strTmpChar);
		if(intCharLoc1==1){
			strTempPad = insertChar(strTempPad, '0', 0);
		}
		intCharLoc2 = strTempPad.lastIndexOf(strTmpChar)
		if(intCharLoc2==4){
			strTempPad = insertChar(strTempPad, '0', 3);	
			if(strTempPad.length==8){
				//support for m/d/yy - insert 20 into the year
				strTempPad = insertChar(strTempPad, '20', 6);
			}
		}
		else{
			if(intCharLoc2==5 && strTempPad.length==8){
				//support for mm/dd/yy and m/dd/yy - insert 20 into the  year
				strTempPad = insertChar(strTempPad, '20', 6);
			}
		}
	}
	if(strTempPad.length==6){
		//support for mmddyy - insert 20 into the year
		strTempPad = insertChar(strTempPad, '20', 4);
	}
	return(strTempPad);
}
function isDate2 (strDate) {
// ----------------------------------------------------------------------------
//	 ISDATE2 -- This function is new to validation.js as of v1.1
//-----------------------------------------------------------------------------
//	Description:
//		Determines if a date is valid or not. This does a "minor" check for
//    a leap year. This function may replace isDate from SaltMine. Some
//    work will need to be done to determine if it's possible. Meanwhile, try
//    to use this one.
//	Input:
//		strDate	- Date value in mm/dd/yyyy format.
//	Output:
//		- sends true if date is a valid date 
//		- returns false if the date is not valid
//	Author:
//		Mitch Wagner - 11/06/00
// ----------------------------------------------------------------------------

	var nMonth =  strDate.substring(0, 2);
	nMonth =  parseInt(nMonth,10);
	if ( (nMonth > 12) || (nMonth < 1)){ return false;}

	var nDay   = strDate.substring(3, 5);
	nDay   = parseInt(nDay,10);
	if(nDay < 1){return false;}
		
	var nYear   = strDate.substr(6);
	nYear=parseInt(nYear,10);
	if ((nYear < 0) ){ return false;}

	 // for SQL server Gregorian calendar limitation
	if ((nYear < 1900) || (nYear > 2078)){ return false;}

	switch(nMonth){
		case 1:
		case 3:
		case 5:
		case 7:
		case 8:
		case 10:
		case 12:
			if (nDay > 31){return false;}
			break;
		case 2:
			if ((nYear%4)==0){ // leap year
				if (nDay > 29){return false;}
			}
			else{			// non-leap year
				if (nDay > 28){return false;}
			}
			break;
		case 4: // all these are 30 day months
		case 6: // work is filtered down to case 11...
		case 9:
		case 11:
			if (nDay > 30){return false;}
			break;
	}
	return true;
}
//*************** ALLSPACESORBLANK ***************//
function AllSpacesOrBlank(strIn){
	/*	Check to see if a string is nothing but spaces or blank.
		Especialy used to check to see if nothing was
		really entered in a text box except a space or two
	*/
	if((strIn == "")||(strIn == null)){return true;}
	var strLength = strIn.length;
	var loopCT;
	var blnReturn = false;
	for(loopCT = 0;loopCT < strLength;loopCT++){
		if(strIn.charCodeAt(loopCT) == 32){
			blnReturn = true;
		}
		else{
			blnReturn = false;
			break;
		}		
	}
	return blnReturn;
}
//*************** CHKTEXT ***************//
function chkText(strIn,intType) {
	//  checks for "undefined" or otherwise undesirable values and returns the appropriate value for the Type specified
	if (typeof(strIn) == 'undefined' || strIn == 'undefined' || strIn == '') {
		var bNothing = true;
	}
	switch(intType) {
		case 0: // accepts negatives and decimals
			if (bNothing == true || isNaN(strIn)) {return '0';}
			break;
		case 1: // negative numbers returned as zero
			if (bNothing == true || isNaN(strIn) || (!isNaN(strIn) && eval(strIn) < 0)) 
			{return '0';}
			break;
		default: // undefined values are returned as an empty string
			if (bNothing == true) {return '';}
			break;
	}
	return strIn;						
}
//*************** CURRENCY ***************//
function currency(anynum) {
   //-- Returns passed number as string in $xxx,xxx.xx format.
   anynum=eval(anynum)
   workNum=Math.abs((Math.round(anynum*100)/100));
   workStr=""+workNum
   if (workStr.indexOf(".")==-1){workStr+=".00"}
   dStr=workStr.substr(0,workStr.indexOf("."));dNum=dStr-0
   pStr=workStr.substr(workStr.indexOf("."))
   while (pStr.length<3){pStr+="0"}

   //--- Adds comma in thousands place.
   if (dNum>=1000) {
      dLen=dStr.length
      dStr=parseInt(""+(dNum/1000))+","+dStr.substring(dLen-3,dLen)
   }

   //-- Adds comma in millions place.
   if (dNum>=1000000) {
      dLen=dStr.length
      dStr=parseInt(""+(dNum/1000000))+","+dStr.substring(dLen-7,dLen)
   }
   retval = dStr + pStr 
   //-- Put numbers in parentheses if negative.
   if (anynum<0) {retval="("+retval+")"}
   return "$"+retval
}
//*************** MASK ***************//
function mask(frmField, dataType){
	//This function will accept a form field and a datatype and then format that field based
	//on Type (date, zip, phone) and length.
	
	switch (dataType){
		case "date":
			//First, we strip out possible seperators
			cleanedString = frmField.value;
			cleanedString = cleanedString.replace(/[\/]/g, "");
			cleanedString = cleanedString.replace(/-/g, "");
			if(!isNaN(cleanedString)){ //Make sure no other invalid characters are present
			
				switch (cleanedString.length){
				//Check the various lengths of possible dates for best way to format
					case 4:
						month = cleanedString.substring(0,1) //grab first digit for month
						day = cleanedString.substring(1,2)   //grab second digit for day
						year = cleanedString.substring(2,4)  //grab last two digits for year
						frmField.value = month + "/" + day + "/" + year //Replace old value with new formatted one.
					break;
					case 5:
					//Possibly either X/XX/XX or XX/X/XX. Will check first two digits and make assumptions.
						if(cleanedString.substring(0,1)=="0"){//First digit is zero, we know it's the month
							month = cleanedString.substring(0,2) //grab first two digits for month
							day = cleanedString.substring(2,3)   //grab third digit for day
							year = cleanedString.substring(3,5)  //grab last two digits for year
							frmField.value = month + "/" + day + "/" + year //Replace old value with new formatted one.
						}
						else{
							if(cleanedString.substring(0,1)=="1" && (cleanedString.substring(1,2)=="0" || cleanedString.substring(1,2)=="1" || cleanedString.substring(1,2)=="2")){
								//checking for double digit months.
								month = cleanedString.substring(0,2) //grab first two digits for month
								day = cleanedString.substring(2,3)   //grab third digit for day
								year = cleanedString.substring(3,5)  //grab last two digits for year
								frmField.value = month + "/" + day + "/" + year //Replace old value with new formatted one.
							}
							else{ //First two digits cannot be month
								month = cleanedString.substring(0,1) //grab first digit for month
								day = cleanedString.substring(1,3)   //grab third digit for day
								year = cleanedString.substring(3,5)  //grab last two digits for year
								frmField.value = month + "/" + day + "/" + year //Replace old value with new formatted one.
							}
						}
					break;
					case 6:
						month = cleanedString.substring(0,2) //grab first two digits for month
						day = cleanedString.substring(2,4)   //grab second two digits for day
						year = cleanedString.substring(4,6)  //grab last two digits for year
						frmField.value = month + "/" + day + "/" + year //Replace old value with new formatted one.
					break;
					case 8:
						month = cleanedString.substring(0,2) //grab first two digits for month
						day = cleanedString.substring(2,4)   //grab second two digits for day
						year = cleanedString.substring(4,8)  //grab last four digits for year
						frmField.value = month + "/" + day + "/" + year //Replace old value with new formatted one.
					break;
					default:
					break;
				}//end embedded switch
			} //end if	
		break; //end case date
		case "zip":
			cleanedString = frmField.value
			cleanedString = cleanedString.replace(/-/g, ""); //Pick out possible seperator
			if(!isNaN(cleanedString)){
				if(cleanedString.length == 9){
					frmField.value = cleanedString.substring(0,5) + "-" + cleanedString.substring(5,9)
				}
			}
		break;
		case "phone":
			cleanedString = frmField.value;
			cleanedString = cleanedString.replace(/-/g, "");
			cleanedString = cleanedString.replace(/\(/g, "");
			cleanedString = cleanedString.replace(/\)/g, "");
			cleanedString = cleanedString.replace(/\s/g, "");
			if(!isNaN(cleanedString)){		
				switch (cleanedString.length){
					case 7:
						areaCode = "";
						prefix = cleanedString.substring(0,3);
						number = cleanedString.substring(3,7);
						frmField.value = "(" + areaCode + ") " + prefix + "-" + number
					break;
					case 10:
						areaCode = cleanedString.substring(0,3);
						prefix = cleanedString.substring(3,6);
						number = cleanedString.substring(6,10);
						frmField.value = "(" + areaCode + ") " + prefix + "-" + number
					break;	
				}
			}				
		break;
		case "money": //Was going to flesh this out and replace the currency function. No real need. Not that bored. wtr.
			cleanedString = frmField.value;
			cleanedString = cleanedString.replace(/$/g, "");

			if(!isNaN(cleanedString)){
			
			}
		break;
		default:
		break;
	}
}
function stripChar(strToStrip, arrChar){
// ----------------------------------------------------------------------------
//	STRIPCHAR
//-----------------------------------------------------------------------------
//	Description:
//		strips out every instance of the characters sent in the arrChar array
//	Input:
//		strToStrip - string that needs to be cleaned.
//		arrChar - array of characters to clean out of string.
// 				if you need to clean out special characters
//				preceed your character with double wack \\
//				example:  '\\(' for left parens, etc
//	Output:
//		returnString -  return strToStrip string without arrChars
//	Author:
//		Mitch Wagner - 11/06/00
// ----------------------------------------------------------------------------

	var returnString = strToStrip;
	var reString;
	// loop through the arrChar array
	for (i = 0; i < arrChar.length; i++){
		// create regular expression string (global, case insensitive)
		reString = eval('/' + arrChar[i] + '/gi');
		// clean out the string
		returnString = returnString.replace(reString, "");
	}
	return(returnString);
}
function insertChar(strToInsertInto, strChar, intCharPos){
// ----------------------------------------------------------------------------
//	INSERTCHAR
//-----------------------------------------------------------------------------
//	Description:
//		inserts a character or string into a certain position of a string
//	Input:
//		strToInsertInto	- string to insert the character(s) into.
//		strChar			- character(s) to insert.
//		intCharPos		- Position you want the character(s) inserted at.
//	Output:
//		returnString -  returns strToInsertInto with strChar inserted
//						at the intCharPos position.
//	Notes:
//						If intCharPos is equal to 6, strChar will be inserted
//						after the 6th character of the string
//	Author:
//		Mitch Wagner - 11/06/00
// ----------------------------------------------------------------------------

	// split the string at the position sent
	var strLeft = strToInsertInto.substring(0, intCharPos);
	var strRight = strToInsertInto.substr(intCharPos);
	// then put back together with the strChar in between
	var returnString = strLeft + strChar + strRight;
	return(returnString);
}
function checkMinLength(strToCheck, intMinLen, strErrorMsg){
//-----------------------------------------------------------------------------
//	CHECKMINLENGTH
//-----------------------------------------------------------------------------
//	Description:
//		used to verify length of a string.
//	Input:
//		strToCheck		- string to check length on.
//		intMinLen		- Min length that strToCheck should be.
//		strErrorMsg		- Error Message to display, (optional)
//	Output:
//		- returns the length of the string if it was not less than intMinLen
//		- returns false if the string is less than intMinLen
//	Author:
//		Mitch Wagner - 11/06/00
//	NOTES:
//  		adding another parameter to display error message -Choudary 12/04/02
//		fixed issue with all format functions giving undefined error
//-----------------------------------------------------------------------------
	var intStrLen = strToCheck.length;
	if(intStrLen < intMinLen){
		if(strErrorMsg)
			alert(strErrorMsg);
		return(false);
	}
	else{
		return(intStrLen);
	}
}

function checkMaxLength(strToCheck, intMaxLen, strErrorMsg){
//-----------------------------------------------------------------------------
//	CHECKMAXLENGTH
//-----------------------------------------------------------------------------
//	Description:
//		used to verify Maximum length of a string.
//	Input:
//		strToCheck		- string to check length on.
//		intMaxLen		- Maximum length that strToCheck should be.
//		strErrorMsg		- Error Message to display, (optional)
//	Output:
//		When u call KeyDown Event:
//			- returns False   if length of the string is equal to Maximum Length
//			- returns True    if length of the string is less than Maximum Length
//		Other than Keydown Event:
//			- returns True    if length of the string is greater than Maximum Length
//			- returns False   if length of the string is less than Maximum Length
//	Author:
//		Padmanaban Ekambaram - 01/29/01
//  Last Change :
//				Enable to work all special keys even when it reaches maximum length
//				-- Paddy
//-----------------------------------------------------------------------------
	var intStrLen = strToCheck.length;
	var intErrorLen = strErrorMsg;
	
	
	// Enabling Delete, Backspace and Tab, Caps, Num Lock, ctrl, shift, alter, Functional keys, home, end, arrows, 
	//	scroll lock, prints screen, pause,page up and page down keys
	if ((window.event.keyCode == 8) || (window.event.keyCode == 9) || 
		(window.event.keyCode == 144) || (window.event.keyCode == 145) || 
		(window.event.keyCode == 27) || 
		((window.event.keyCode >= 12) && (window.event.keyCode <= 20)) ||
		((window.event.keyCode >= 33) && (window.event.keyCode <= 46)) ||
		((window.event.keyCode >= 91) && (window.event.keyCode <= 93)) ||
		((window.event.keyCode >= 112) && (window.event.keyCode <= 123)) ){
		return(true);
	}
	else{
			// Only for KeyDown event. i.e. when user entery times validation
		if (window.event.type == 'keydown')
		{
			// Error Message is Optional parameter, if user didnt pass Error Message then
			// it will display default Error Message.
			if (checkMaxLength.arguments.length < 3){
				var strErrorMsg = 'This Field Maximum Size is ' + intMaxLen + ' Character(s)';
			}
			if (intErrorLen == 0){
				strErrorMsg = 'This Field Maximum Size is ' + intMaxLen + ' Character(s)';
			}

			if(intStrLen == intMaxLen){
				alert(strErrorMsg);
				return(false);
			}
			else{
				return(true);
			}
		}
		else{				// Normal other Function calls and other event time
			if(intStrLen > intMaxLen){
				return(true);
			}
			else{
				return(false);
			}		
		}
	}
}

function checkPhone(objCaller){
// ----------------------------------------------------------------------------
//	CHECKPHONE
//-----------------------------------------------------------------------------
//	Description:
//		makes a call to formatphone - returns false and pops up error
//		if can't be converted to phone type format.
//	Input:
//		objCaller	- object reference of the item we are checking
//	Output:
//		- sends the properly formated string to objCallers value 
//		- returns false if the string can not be formatted correctly
//		  (sends false to avoid form submit in formValidate page function)
//	Author:
//		Mitch Wagner - 11/06/00
// ----------------------------------------------------------------------------
	var strToCheck = objCaller.value
	
	//only do this if it's not empty
	if(strToCheck){
		var strReturn = formatPhone(strToCheck);
		var errorMessage = 'Invalid Phone/Fax format. Phone/Fax numbers\nneed to be input in 10 digit format.\nExample: 555-555-5555'
	
		// display message if false was returned
		// otherwise throw the formatted version back to the text box
		if(strReturn){
			objCaller.value = strReturn;
		}
		else{
			alert(errorMessage);
			objCaller.focus();
			objCaller.select();
			// if being called from within an event, set returnValue false - to avoid IE5 bug.
			if(event){event.returnValue = false;}
			return(false);
		}
	}
}
function formatPhone(strToFormat){
// ----------------------------------------------------------------------------
//	FORMATPHONE
//-----------------------------------------------------------------------------
//	Description:
//		specialized function for formatting phone numbers
//		for phone related input formatting
//	Input:
//		strToFormat		- string to format into phone type format.
//	Output:
//		- returns the properly formatted string (if able to format)
//		- returns false if the string can not be formatted correctly
//	Author:
//		Mitch Wagner - 11/06/00
// ----------------------------------------------------------------------------

	var intPhoneLen = 10
	var returnString = ''
	// Phone type characters: 
	// call the stripChar function to strip out ( ) - space period and comma. 
	// need to preceed special characters with a wack
	arrChar = new Array('\\(','\\)','-',' ','\\.','\\,');
	var cleanString = stripChar(strToFormat, arrChar);

	//make sure they entered numbers
	if(isNaN(cleanString)){
		return(false);
	}
	//check if it has 10 characters
	if(checkMinLength(cleanString, intPhoneLen)==intPhoneLen){
		// insert a dash after the 6th character
		returnString = insertChar(cleanString, '-', 6);
		returnString = insertChar(returnString, ')', 3);
		returnString = insertChar(returnString, '(', 0);
		return(returnString);
	}
	else{
		return(false);
	}
}

function LillyformatPhone(strToFormat){
// ----------------------------------------------------------------------------
//	FORMATPHONE
//-----------------------------------------------------------------------------
//	Description:
//		specialized function for formatting phone numbers
//		for phone related input formatting
//	Input:
//		strToFormat		- string to format into phone type format.
//	Output:
//		- returns the properly formatted string (if able to format)
//		- returns false if the string can not be formatted correctly
//		(Added this function to put space after parenthesis-- Lilly connect requirement)
//	Author:
//		Choudary Rayala - 09/20/02 
// ----------------------------------------------------------------------------

	var intPhoneLen = 10
	var returnString = ''
	// Phone type characters: 
	// call the stripChar function to strip out ( ) - space period and comma. 
	// need to preceed special characters with a wack
	arrChar = new Array('\\(','\\)','-',' ','\\.','\\,');
	var cleanString = stripChar(strToFormat, arrChar);

	//make sure they entered numbers
	if(isNaN(cleanString)){
		return(false);
	}
	//check if it has 10 characters
	if(checkMinLength(cleanString, intPhoneLen)==intPhoneLen){
		// insert a dash after the 6th character
		returnString = insertChar(cleanString, '-', 6);
		returnString = insertChar(returnString, ') ', 3);
		returnString = insertChar(returnString, '(', 0);
		return(returnString);
	}
	else{
		return(false);
	}
}

// ----------------------------------------------------------------------------
//	CHECKEMPTYSPACE -- This function is new to validation.js as of v1.2
//-----------------------------------------------------------------------------
//	Description:
//		used to verify whether the string contains any empty spaces.
//	Input:
//		strToCheck		- string to check empty spaces on.
//		invalid 		- Empty space
//	Output:
//		- returns True if the string contains empty space
//		- returns false if the string does not contains space
//	Author:
//		Choudary Rayala - 01/26/01
// ----------------------------------------------------------------------------

function checkEmptySpace(strToCheck, invalid){
	var intStrLen = strToCheck.indexOf(invalid);
	if (intStrLen > -1){
		return(true);
	}
	else {
		return(false);
	}
 }

//-----------------------------------------------------------------------------
function checkPassword(objCaller){
// ----------------------------------------------------------------------------
//	CHECKPASSWORD -- This function is new to validation.js as of v1.1
//-----------------------------------------------------------------------------
//	Description:
//		makes a call to checkMinLength - returns false if the user does not
//		meet minimum length.
//	Input:
//		objCaller	- object reference of the item we are checking
//	Output:
//		- sends back True if length is OK 
//		- returns False if password length is too short
//	Author:
//		Bill Seling - 11/10/00
// ----------------------------------------------------------------------------
	
	var strToCheck = objCaller.value
	//only do this if it's not empty
	
	if(strToCheck){
	
		//Start changes by Choudary for finding Empty spaces //
		
		var invalid = " ";
		//will be true if has space in string
		var bContainsSpace = checkEmptySpace(strToCheck, invalid);
		var errorMessage = 'Spaces are not allowed in the Password field.\n Please try again.'
		if(bContainsSpace){
			alert(errorMessage);
			objCaller.focus();
			objCaller.select();
			// if being called from within an event, set returnValue false - to avoid IE5 bug.
			if(event){event.returnValue = false;}
			return(false);
		}

		//Added by Jack S. Lin for finding Double Quote characters //
		invalid = '"';
		errorMessage = 'Double quotes are not allowed in the Password field.\n Please try again.'

		//will be true if has double quote in string
		var bContainsDoubleQuote = checkEmptySpace(strToCheck, invalid);
		if(bContainsDoubleQuote){
			alert(errorMessage);
			objCaller.focus();
			objCaller.select();
			// if being called from within an event, set returnValue false - to avoid IE5 bug.
			if(event){event.returnValue = false;}
			return(false);
		}


			var intMinLength = 6  //Sets the minimum length allowed for a password
			var strReturn = checkMinLength(strToCheck, intMinLength);
			var errorMessage = 'Passwords must be at least 6 characters in length.\n Please try again.'
		
		// display message if False is returned and place box into focus,
		// otherwise return True back to calling function
		
		if(strReturn){
			return(true);
		}
		else{
			alert(errorMessage);
			objCaller.focus();
			objCaller.select();
	// if being called from within an event, set returnValue false - to avoid IE5 bug.
			if(event){event.returnValue = false;}
			return(false);
		}
	}
}

function checkUserName(objCaller){
// ----------------------------------------------------------------------------
//	CHECKUSERNAME -- This function is new to validation.js as of v1.1
//-----------------------------------------------------------------------------
//	Description:
//		makes a call to checkMinLength - returns false if the user does not
//		meet minimum length.
//	Input:
//		objCaller	- object reference of the item we are checking
//	Output:
//		- sends back True if length is OK 
//		- returns False if username length is too short
//	Author:
//		Bill Seling - 11/10/00
// ----------------------------------------------------------------------------
	var strToCheck = objCaller.value
	//only do this if it's not empty
	
	if(strToCheck){

		//Start Changes by Choudary for finding Empty spaces //
		
		var invalid = " ";
		//will be true if has space in string
		var bContainsSpace = checkEmptySpace(strToCheck, invalid);
		var errorMessage = 'Spaces are not allowed in the User Name field.\n Please try again.'
		if(bContainsSpace){
			alert(errorMessage);
			objCaller.focus();
			objCaller.select();
			// if being called from within an event, set returnValue false - to avoid IE5 bug.
			if(event){event.returnValue = false;}
			return(false);
		}

		var intMinLength = 6  //Sets the minimum length allowed for a username
		var strReturn = checkMinLength(strToCheck, intMinLength);
		var errorMessage = 'User Names must be at least 6 characters in length.\n Please try again.'
			
		// display message if False is returned and place box into focus,
		// otherwise return True back to calling function
		
	if(strReturn){
			return(true);
		}
	else{
			alert(errorMessage);
			objCaller.focus();
			objCaller.select();
			// if being called from within an event, set returnValue false - to avoid IE5 bug.
			if(event){event.returnValue = false;}
			return(false);
		}
	}
}

function checkNumeric(objCaller,numType){
// ----------------------------------------------------------------------------
//	CHECKNUMERIC -- This function is new to validation.js as of v1.1
//-----------------------------------------------------------------------------
//	Description:
//		checks whether the value of 'objCaller' can be converted to a number.
//		It sends back the formatted version if it can, error message if not
//	Input:
//		objCaller	- object reference of the item we are checking
//		numType		- type of number to format
//			[cur] - format with comma(s) and two decimal
//			[dec] - currently same as currency (comma and decimal)
//			[num] - format with comma(s) only
//	Output:
//		- sends back the correctly formatted version to ObjCaller.value
//		- pops up a message and returns false if can't be properly formatted
//	Author:
//		Mitch Wagner - 11/17/00
// ----------------------------------------------------------------------------
	var strToCheck = objCaller.value
	//only do this if it's not empty
	if(strToCheck){
		//strToCheck = StripChar()
		//var temper = anyfield.value.replace(/[$,]/g, "");
		var strReturn = formatNumeric(strToCheck,numType);
		var errorMessage = 'Only numeric data is accepted in this field.\nPlease try again.'
		// display message if False is returned and place box into focus,
		// otherwise return true back to caller
		if(strReturn){
			objCaller.value = strReturn;
			return(true);
		}
		else{
			alert(errorMessage);
			objCaller.focus();
			objCaller.select();
			// if being called from within an event, set returnValue false - to avoid IE5 bug.
			if(event){event.returnValue = false;}
			return(false);
		}
	}
}
function formatNumeric(strToFormat,numType){
// ----------------------------------------------------------------------------
//	FORMATNUMERIC
//-----------------------------------------------------------------------------
//	Description:
//		specialized function for formatting numbers
//		for numeric related input formatting
//		note: This function is called by checkNumeric
//	Input:
//		strToFormat	- string/number to format into phone type format.
//		numType	- type of number to format
//			[cur] format with comma(s) and two decimal
//			[dec] currently same as currency (comma and decimal)
//			[num] format with comma(s) only
//	Output:
//		- returns the properly formatted string (if able to format)
//		- returns false if the string can not be formatted correctly
//	Author:
//		Mitch Wagner - 11/17/00
// ----------------------------------------------------------------------------

	// Numeric type characters: 
	// call the stripChar function to strip out [-] [space] [comma] and [dollar]. 
	// need to preceed special characters with a double wack
	arrChar = new Array('-',' ','\\,','\\$');
	var cleanString = stripChar(strToFormat, arrChar);

	//make sure they entered numbers
	if(isNaN(cleanString)){return(false);}

	var anynum = parseFloat(cleanString);
    anynum=eval(anynum)
	switch(numType){
		case 'dec':
			// decimal support
			workNum=Math.abs((Math.round(anynum*100)/100));
			// handle as string
			workStr=""+workNum;
			// if not decimal yet, then tack on .00
			if (workStr.indexOf(".")==-1){workStr+=".00"}
			// get the numbers on the left of the decimal point
			dStr=workStr.substr(0,workStr.indexOf("."));
			// get the numbers on the right of the decimal point (along with decimal)
			pStr=workStr.substr(workStr.indexOf("."));
			// if only decimal and one character, tack on a zero
			if(pStr.length==2){pStr=pStr+='0'}
			break;
		case 'num':
			// standard number support (comma only)
			workNum=anynum-0;
			// handle as string
			workStr=""+workNum;
			// used to support comma placement below
			if (workStr.indexOf(".")==-1){
				// no decimal in the value
				dStr=workStr
			}
			else{
				// we have a decimal in the value
				dStr=workStr.substr(0,workStr.indexOf("."));
			}
			pStr=""
			break;
		case 'cur':
			// currency support
			workNum=Math.abs((Math.round(anynum*100)/100));
			// handle as string
			workStr=""+workNum;
			// if not decimal yet, then tack on .00
			if (workStr.indexOf(".")==-1){workStr+=".00"}
			// get the numbers on the left of the decimal point
			dStr=workStr.substr(0,workStr.indexOf("."));
			// get the numbers on the right of the decimal point (along with decimal)
			pStr=workStr.substr(workStr.indexOf("."));			
			// if only decimal and one character, tack on a zero
			if(pStr.length==2){pStr=pStr+='0'}
			break;
		default:
			// if no type was sent we default to standard number (comma only)
			workNum=anynum-0;
			// handle as string
			workStr=""+workNum;
			if (workStr.indexOf(".")==-1){
				// no decimal in the value
				dStr=workStr
			}
			else{
				// we have a decimal in the value so grab from the left of it
				// to strip off decimal
				dStr=workStr.substr(0,workStr.indexOf("."));
			}
			pStr=""
			break;
	}
	
	// handle as number
	dNum=dStr-0 
	
	//--- Adds comma in thousands place.
	if (dNum>=1000){
		dLen=dStr.length;
		dStr=parseInt(""+(dNum/1000))+","+dStr.substring(dLen-3,dLen);
	}
	//-- Adds comma in millions place.
	if (dNum>=1000000){
	   dLen=dStr.length;
	   dStr=parseInt(""+(dNum/1000000))+","+dStr.substring(dLen-7,dLen);
	}
	//-- Adds comma in 100 millionth place.
	if (dNum>=1000000000){
	   dLen=dStr.length;
	   dStr=parseInt(""+(dNum/1000000000))+","+dStr.substring(dLen-11,dLen);
	}
	retval = dStr + pStr;
	return(retval);
}

function formatNumeric1(strToFormat,numType){
// ----------------------------------------------------------------------------
//	FORMATNUMERIC1 -- Duplicating the above function and not putting Comma's.
//-----------------------------------------------------------------------------
//	Description:
//		specialized function for formatting numbers
//		for numeric related input formatting
//		note: This function is called by checkNumeric
//	Input:
//		strToFormat	- string/number to format into phone type format.
//		numType	- type of number to format
//			[cur] format with comma(s) and two decimal
//			[dec] currently same as currency (comma and decimal)
//			[num] format with comma(s) only
//	Output:
//		- returns the properly formatted string (if able to format)
//		- returns false if the string can not be formatted correctly
//	Author:
//		Mitch Wagner - 11/17/00
// ----------------------------------------------------------------------------

	// Numeric type characters: 
	// call the stripChar function to strip out [-] [space] [comma] and [dollar]. 
	// need to preceed special characters with a double wack
	arrChar = new Array('-',' ','\\,','\\$');
	var cleanString = stripChar(strToFormat, arrChar);

	//make sure they entered numbers
	if(isNaN(cleanString)){return(false);}

	var anynum = parseFloat(cleanString);
    anynum=eval(anynum)
	switch(numType){
		case 'dec':
			// decimal support
			workNum=Math.abs((Math.round(anynum*100)/100));
			// handle as string
			workStr=""+workNum;
			// if not decimal yet, then tack on .00
			if (workStr.indexOf(".")==-1){workStr+=".00"}
			// get the numbers on the left of the decimal point
			dStr=workStr.substr(0,workStr.indexOf("."));
			// get the numbers on the right of the decimal point (along with decimal)
			pStr=workStr.substr(workStr.indexOf("."));
			// if only decimal and one character, tack on a zero
			if(pStr.length==2){pStr=pStr+='0'}
			break;
		case 'num':
			// standard number support (comma only)
			workNum=anynum-0;
			// handle as string
			workStr=""+workNum;
			// used to support comma placement below
			if (workStr.indexOf(".")==-1){
				// no decimal in the value
				dStr=workStr
			}
			else{
				// we have a decimal in the value
				dStr=workStr.substr(0,workStr.indexOf("."));
			}
			pStr=""
			break;
		case 'cur':
			// currency support
			workNum=Math.abs((Math.round(anynum*100)/100));
			// handle as string
			workStr=""+workNum;
			// if not decimal yet, then tack on .00
			if (workStr.indexOf(".")==-1){workStr+=".00"}
			// get the numbers on the left of the decimal point
			dStr=workStr.substr(0,workStr.indexOf("."));
			// get the numbers on the right of the decimal point (along with decimal)
			pStr=workStr.substr(workStr.indexOf("."));			
			// if only decimal and one character, tack on a zero
			if(pStr.length==2){pStr=pStr+='0'}
			break;
		default:
			// if no type was sent we default to standard number (comma only)
			workNum=anynum-0;
			// handle as string
			workStr=""+workNum;
			if (workStr.indexOf(".")==-1){
				// no decimal in the value
				dStr=workStr
			}
			else{
				// we have a decimal in the value so grab from the left of it
				// to strip off decimal
				dStr=workStr.substr(0,workStr.indexOf("."));
			}
			pStr=""
			break;
	}
	
	// handle as number
	dNum=dStr-0 
		
	retval = dStr + pStr;
	return(retval);
}

function checkNumericRange(objCaller,min,max){
// ----------------------------------------------------------------------------
//	CHECKNUMERICRANGE -- This function is new to validation.js as of v1.2
//-----------------------------------------------------------------------------
//	Description:
//		checks whether the value of objCaller is more than min and less than max.
//		It sends back the true if it is within the range, error message if not
//	Input:
//		objCaller	- object reference of the item we are checking
//		min			- minimum range
//		max			- miximum range
//	Output:
//		- sends back true if within range
//		- pops up a message and returns false if its not within the range
//	Author:
//		Mitch Wagner - 04/06/01
// ----------------------------------------------------------------------------
	var numToCheck = objCaller.value
	
	//only do this if it's not empty
	if(numToCheck){
		var bInRange=false;
		
		//if within the range set to true
		if(numToCheck>=min&&numToCheck<=max){bInRange = true;}
	
		if(bInRange){
			return(true);
		}
		else{
			var errorMessage = 'Please enter a numeric value between ' + min + ' and ' + max +' .'
			alert(errorMessage);
			objCaller.focus();
			objCaller.select();
			// if being called from within an event, set returnValue false - to avoid IE5 bug.
			if(event){event.returnValue = false;}
			return(false);
		}
	}
}

function checkNumericRange1(objCaller,min,max,errorMessage){
// ----------------------------------------------------------------------------
//	CHECKNUMERICRANGE1 -- This function is duplicating the above function except 
//						  passing errorMessage
//-----------------------------------------------------------------------------
//	Description:
//		checks whether the value of objCaller is more than min and less than max.
//		It sends back the true if it is within the range, error message if not
//	Input:
//		objCaller	- object reference of the item we are checking
//		min			- minimum range
//		max			- maximum range
//		errorMessage - message to display if the value is not within the range
//	Output:
//		- sends back true if within range
//		- pops up a message and returns false if its not within the range
//	Author:
//		Choudary Rayala - 08/09/01
// ----------------------------------------------------------------------------
	var numToCheck = objCaller.value
	
	//only do this if it's not empty
	if(numToCheck){
		var bInRange=false;
		
		//if within the range set to true
		if(numToCheck>=min&&numToCheck<=max){bInRange = true;}
	
		if(bInRange){
			return(true);
		}
		else{
			alert(errorMessage);
			objCaller.focus();
			objCaller.select();
			// if being called from within an event, set returnValue false - to avoid IE5 bug.
			if(event){event.returnValue = false;}
			return(false);
		}
	}
}

function checkInvalidChar(str){
// ----------------------------------------------------------------------------
//	checkInvalidChar -- This function is new to validation.js as of v1.2
//-----------------------------------------------------------------------------
//	Description:
//		checks whether the value of str contains any invalid characters.
//		It sends back the true if it doesn't have any invalid characters. 
//	Input:
//		str 		- string reference of the item we are checking
//	Output:
//		- sends back true if it doesn't have any invalid characters
//		- pops up a message and returns false if it contains any invalid characters
//	Author:
//		Choudary Rayala - 04/12/01
// ----------------------------------------------------------------------------
//*************** ISCHAR ***************//

	// check if str is pure alphabet chars and numbers, no invalid characters.
	str = trim(str);
	invalidChars = ";:'\"=|/?><.,+-*&()^_%$#@!~\\{}[]`";
	for (i=0; i<invalidChars.length; i++){
		badChar = invalidChars.charAt(i);
		if (str.indexOf(badChar,0) != -1){ return false;}
	}
	return true;
}

function checkNumericInvalidChar(str){
// ----------------------------------------------------------------------------
//	checkNumeric and InvalidChar -- This function is new to validation.js as of v2.1
//-----------------------------------------------------------------------------
//	Description:
//		checks whether the value of str contains any numerics and invalid characters.
//		It sends back the true if it doesn't have any numerics and invalid characters. 
//	Input:
//		str 		- string reference of the item we are checking
//	Output:
//		- sends back true if it doesn't have any Numerics and invalid characters
//		- pops up a message and returns false if it contains any numerics and invalid characters
//	Author:
//		Choudary Rayala - 07/31/01
//  Modified:
//		Bill Seling - 11/13/02 -- Removed check for apostrophe (now allowed).
// ----------------------------------------------------------------------------

	// check if str is pure alphabet chars and no numbers and invalid characters.
	str = trim(str);
	invalidChars = ";:\"=|/?><+*&()^_%$#@!~\\{}[]`1234567890";
	for (i=0; i<invalidChars.length; i++){
		badChar = invalidChars.charAt(i);
		if (str.indexOf(badChar,0) != -1){ return false;}
	}
	return true;
}

function getSecurityChars(){
// ----------------------------------------------------------------------------
//	cleanSecurityChars -- This function is new to validation.js as of v2.1
//-----------------------------------------------------------------------------
// since invalid security characters are needed in more than one place I setup 
// this call so that we only need to change or add to this list here.
// (use backslash to preceed special characters - like double quote)
//-----------------------------------------------------------------------------
	var securityChars = "<>'%;\"\)\(&+";
	return securityChars
}

function checkSecurityChars(str){
// ----------------------------------------------------------------------------
//	checkSecurityChars -- This function is new to validation.js as of v2.1
//-----------------------------------------------------------------------------
//	Description:
//		checks whether the value of str contains any characters that can cause 
//		security issues.
//		It sends back the true if it doesn't have any offending characters. 
//	Input:
//		str - string reference of the item we are checking
//	Output:
//		- sends back true if it doesn't have any offending characters
//		- returns false if it contains offending characters
//	Author:
//		Mitchell Wagner - 08/16/01
// ----------------------------------------------------------------------------
// check if str has any security related characters that may be used to violate integrity

	str = trim(str);
	var securityChars = getSecurityChars()
	for (i=0; i<securityChars.length; i++){
		badChar = securityChars.charAt(i);
		if(str.indexOf(badChar,0)!= -1){return false;}
	}
	return true;
}

function cleanSecurityChars(str){
// ----------------------------------------------------------------------------
//	cleanSecurityChars -- This function is new to validation.js as of v2.1
//-----------------------------------------------------------------------------
//	Description:
//		cleans out any characters that can cause security issues.
//		It sends back the string cleansed of the offending characters
//	Input:
//		str - string reference of the item we are checking
//	Output:
//		- sends back the string - cleansed of the offending characters
//	Author:
//		Mitchell Wagner - 08/16/01
// ----------------------------------------------------------------------------

	var cleanedString = str;
	var securityChars = getSecurityChars()
	for (i=0; i<securityChars.length; i++){
		var badChar = securityChars.charAt(i);
		if(str.indexOf(badChar,0)!= -1){
			var intCharCode = badChar.charCodeAt(0)//get character set ascii code number
			if(intCharCode < 47){ // if special character append backslash(s).
				badChar = '\\' + badChar;
			}
			var reString = eval('/' + badChar + '/g');
			cleanedString = cleanedString.replace(reString, "");
		}
	}
	return cleanedString;	
}
