<!--
// Strip spaces from a string
function StripSpaces(aString) {
var newString=""
for (var i=0; i<aString.length; i++) {
   if (aString.charAt(i)!=" ") { newString+=aString.charAt(i) }
   }
return newString;
}

//Edit a text string to double the apostrophe for SQL inserts
//Some people have names like O'Connor
function DoubleApostrophe(inString) {
newString = inString
pos = inString.indexOf("'")
len = inString.length
if (pos > -1 && len > 1) {
   newString = inString.substring(0,pos) + "'" + inString.substring(pos,inString.length)
	}
if (newString == "'") {
	newString = " "
	}	
return newString
}

// Version 1/29/97 --- Remove formatting characters
function StripFormatting(aField) {
var newstring=""
for (var i = 0; i < aField.length; i++) {
   var onechar = aField.charAt(i)
   if (onechar != '(' &&
       onechar != ')' &&
       onechar != '$' &&
       onechar != '-' &&
       onechar != '"' &&
       onechar != ',') {
          newstring+=onechar
       }
   }
return newstring
}

// Validate an Integer Number
function IsNumeric(InputVal) {
inputstr = "" + InputVal
if (inputstr.length == 0) { return false }
for (var i = 0; i < inputstr.length; i++) {
   var onechar = inputstr.charAt(i)
   if (onechar >= "0" && onechar <= "9") {
      continue }
   else {
      return false }
   }
return true
}

// Validate a Name, Allow only A-Z, space, -
function IsName(InputVal) {
	var validstring = "ABCDEFGHIJKLMNOPQRSTUVWXYZ -'";
	var inputstr = "" + InputVal
	if (inputstr.length == 0) { return false }
	inputstr = inputstr.toUpperCase();
	for (var i = 0; i < inputstr.length; i++) {
	   var onechar = inputstr.charAt(i);
	   if (validstring.indexOf(onechar) >= 0) {
	      continue;
	   }
       else {
		return false;
	   }
    }
    return true;
}

// Version 4/19/97 --- Validate a Numeric 0.00 String
function IsCurrency(aString) {
var newstring=""
var dotcount=0
var decimalcount=0
for (var i = 0; i < aString.length; i++) {
   var onechar = aString.charAt(i)
   if (onechar >= "0" && onechar <= "9") {
      if (dotcount==1) decimalcount+=1
      if (decimalcount > 2) return false
      continue
      }
   if (onechar == "$" && i == 0) {
      continue
      }
   if (onechar == "." && dotcount <= 1) {
      dotcount+=1
      continue
      }
   return false
   }
return true
}

// Version 1/29/97 --- Format a Currency String
// Allow user input of several different currency formats including 0.00, .00, 0.0, 0,000 etc.
// Make sure IsCurrency() and StripFormatting() are called if the user has changed data
function FormatCurrency(aString) {
var newstring="$"
var decimalcount=0
var havedot=false
for (var i = 0; i < aString.length; i++) {
   var onechar = aString.charAt(i)
   if (i==0 && onechar==".") {
      newstring+="0" }
   if (havedot) {
      decimalcount+=1 }
   if (onechar == ".") {
      havedot=true }
   newstring+=onechar
   }
if (newstring.length == 1) {
   newstring+="0" }
if (havedot) {
   if (decimalcount == 0) {
      newstring+="00" }
   if (decimalcount == 1) {
      newstring+="0" }
   }
else {
   newstring+=".00" }

var oldlength=newstring.length
if (oldlength>7) {
   newstring=newstring.substring(0,oldlength-6) + "," + newstring.substring(oldlength-6,oldlength)
   }

return newstring
}

// Version 3/29/99 --- Validate a Numeric 000.00000 String
function IsRate(aString, DecMax) {
var newstring=""
var dotcount=0
var decimalcount=0
 for (var i = 0; i < aString.length; i++) {
   var onechar = aString.charAt(i)
   if (onechar >= "0" && onechar <= "9") {
      if (dotcount==1) decimalcount+=1
      if (decimalcount > DecMax) return false;
      continue;
   }
   if (onechar == "." && dotcount <= 1) {
      dotcount+=1;
      continue;
   }
   return false;
 }
return true;
}

// Version 1/14/99 --- Check for string containing alphas without spaces
function IsAlpha(InputVal) {
	if (StripSpaces(StripFormatting(InputVal)) == "") return false;

	var validstring = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var inputstr = "" + InputVal
	if (inputstr.length == 0) { return false }
	inputstr = inputstr.toUpperCase();
	for (var i = 0; i < inputstr.length; i++) {
	   var onechar = inputstr.charAt(i);
	   if (validstring.indexOf(onechar) >= 0) {
	      continue;
	   }
       else {
		return false;
	   }
    }
    return true;
}
// Version 1/14/99 --- Check for string containing alphas with spaces allowed
function IsAlphaS(InputVal) {
	if (StripFormatting(InputVal) == "") return false;

	var validstring = "ABCDEFGHIJKLMNOPQRSTUVWXYZ ";
	var inputstr = "" + InputVal
	if (inputstr.length == 0) { return false }
	inputstr = inputstr.toUpperCase();
	for (var i = 0; i < inputstr.length; i++) {
	   var onechar = inputstr.charAt(i);
	   if (validstring.indexOf(onechar) >= 0) {
	      continue;
	   }
       else {
		return false;
	   }
    }
    return true;
}

// Version 1/14/99 --- Check for string containing alphanumerics without spaces
function IsAlphaNumeric(InputVal) {
	if (StripSpaces(StripFormatting(InputVal)) == "") return false;

	var validstring = "ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890.,";
	var inputstr = "" + InputVal
	if (inputstr.length == 0) { return false }
	inputstr = inputstr.toUpperCase();
	for (var i = 0; i < inputstr.length; i++) {
	   var onechar = inputstr.charAt(i);
	   if (validstring.indexOf(onechar) >= 0) {
	      continue;
	   }
       else {
		return false;
	   }
    }
    return true;
}

// Version 1/14/99 --- Check for string containing alphanumerics with spaces allowed
function IsAlphaNumericS(InputVal) {
	if (StripFormatting(InputVal) == "") return false;

	var validstring = "ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890., ";
	var inputstr = "" + InputVal
	if (inputstr.length == 0) { return false }
	inputstr = inputstr.toUpperCase();
	for (var i = 0; i < inputstr.length; i++) {
	   var onechar = inputstr.charAt(i);
	   if (validstring.indexOf(onechar) >= 0) {
	      continue;
	   }
       else {
		return false;
	   }
    }
    return true;
}

// Version 1/14/99 --- Check for string containing alphanumerics without spaces and an @ sign
function IsEmail(InputVal) {
	var atfound = false;
	
	if (StripSpaces(StripFormatting(InputVal)) == "") return false;

	var validstring = "ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890.#!$-_~*<>@";
	var inputstr = "" + InputVal
	if (inputstr.length == 0) { return false }
	inputstr = inputstr.toUpperCase();
	for (var i = 0; i < inputstr.length; i++) {
	   var onechar = inputstr.charAt(i);
	   if (validstring.indexOf(onechar) >= 0) {
	      if (onechar == '@') atfound = true;
	      continue;
	   }
       else {
		return false;
	   }
    }
	if (!atfound) return false;
	
    return true;
}

// Version 1/29/97 --- Format a Social Security Number
function FormatSSN(aString) {
var newstring=""
for (var i = 0; i < aString.length; i++) {
   var onechar = aString.charAt(i)
   if (IsNumeric(onechar)) {
      if (newstring.length == 3) {
         newstring+="-"
         }
      if (newstring.length == 6) {
         newstring+="-"
         }
      newstring+=onechar
      }
   }
return newstring
}
/*
	dmonth: String - Month in number format (MM)
	dday:	String - Day in number format (DD)
	dyear:	String - Year in number format (YYYY)
*/
function ValidDate(dmonth, dday, dyear)
{
	if (dmonth == '02') {
		if(((dyear%4)==0) && (((dyear%100)!=0) || ((dyear%400)==0))){
		   lastFebDay = 29; // Leap year...
		} else {
		   lastFebDay = 28; // Not leap year
		}
		if (dday > lastFebDay) return false;	
	}
	if (dmonth == '04' || dmonth == '06' || dmonth == '09' || dmonth == '11') {
		if (dday == '31') return false;
	}
	return true;
}
function CZeroPad(instring)
{
	if (instring == "") return "00";
	if (instring.length < 2) return "0" + instring;
	return instring;
}
// Input Date in MM/DD/YYYY Format
function CMonthAbbrev (theDate)
{
var SMonth = "";
var Month = "";
var MonthAbv = -1;

SMonth = theDate.substring(0,2);
Month = (SMonth.charAt(0) == '0') ? SMonth.charAt(1) : SMonth;

  if (Month == 1)
      MonthAbv = "JAN";
  else if (Month == 2)
      MonthAbv = "FEB";
  else if (Month == 3)
      MonthAbv = "MAR";
  else if (Month == 4)
      MonthAbv = "APR";
  else if (Month == 5)
      MonthAbv = "MAY";
  else if (Month == 6)
      MonthAbv = "JUN";
  else if (Month == 7)
      MonthAbv = "JUL";
  else if (Month == 8)
      MonthAbv = "AUG";
  else if (Month == 9)
      MonthAbv = "SEP";
  else if (Month == 10)
      MonthAbv = "OCT";
  else if (Month == 11)
      MonthAbv = "NOV";
  else if (Month == 12)
      MonthAbv = "DEC";

  return MonthAbv;
}
function Ck_Empty(ThisItem)
{
    if (ThisItem.value == "") {
        alert("This field must contain a value");
		ThisItem.focus();
		return false;
	}
	return true;
}
function Ck_EmptySelect(ThisItem)
{
    if (ThisItem.selectedIndex == 0) {
        alert("This field must contain a value");
		ThisItem.focus();
		return false;
	}
	return true;
}
function Ck_Alpha(ThisItem)
{
	if (ThisItem.value == "") return true;
	if (!IsAlpha(ThisItem.value)) {
       alert("This field must contain only alpha characters");
	   ThisItem.select(); ThisItem.focus(); 
	   return false;
	}
	return true;
}
function Ck_AlphaS(ThisItem)
{
	if (ThisItem.value == "") return true;
	if (!IsAlphaS(ThisItem.value)) {
       alert("This field must contain only alpha characters");
	   ThisItem.select(); ThisItem.focus(); 
	   return false;
	}
	return true;
}
function Ck_EmptyAlpha(ThisItem)
{
    if (ThisItem.value == "") {
        alert("This field must contain a value");
		ThisItem.focus();
		return false;
	}
	if (!IsAlpha(ThisItem.value)) {
       alert("This field must contain only alpha characters");
	   ThisItem.select(); ThisItem.focus(); 
	   return false;
	}
	return true;
}
function Ck_EmptyAlphaS(ThisItem)
{
    if (ThisItem.value == "") {
        alert("This field must contain a value");
		ThisItem.focus();
		return false;
	}
	if (!IsAlphaS(ThisItem.value)) {
       alert("This field must contain only alpha characters");
	   ThisItem.select(); ThisItem.focus(); 
	   return false;
	}
	return true;
}
function Ck_AlphaNumeric(ThisItem)
{
	if (ThisItem.value == "") return true;
	if (!IsAlphaNumeric(ThisItem.value)) {
       alert("This field must contain only alphanumeric characters");
	   ThisItem.select(); ThisItem.focus(); 
	   return false;
	}
	return true;
}
function Ck_AlphaNumericS(ThisItem)
{
	if (ThisItem.value == "") return true;
	if (!IsAlphaNumericS(ThisItem.value)) {
       alert("This field must contain only alphanumeric characters");
	   ThisItem.select(); ThisItem.focus(); 
	   return false;
	}
	return true;
}
function Ck_EmptyAlphaNumeric(ThisItem)
{
	if (ThisItem.value == "") {
        alert("This field must contain a value");
		ThisItem.focus();
		return false;
	}
	if (!IsAlphaNumeric(ThisItem.value)) {
       alert("This field must contain only alphanumeric characters");
	   ThisItem.select(); ThisItem.focus(); 
	   return false;
	}
	return true;
}
function Ck_EmptyAlphaNumericS(ThisItem)
{
    if (ThisItem.value == "") {
        alert("This field must contain a value");
		ThisItem.focus();
		return false;
	}
	if (!IsAlphaNumericS(ThisItem.value)) {
       alert("This field must contain only alphanumeric characters");
	   ThisItem.select(); ThisItem.focus(); 
	   return false;
	}
	return true;
}
function Ck_Numeric(ThisItem)
{
	if (ThisItem.value == "") return true;
	if (!IsNumeric(ThisItem.value))	{
       alert("This field must contain only numeric characters");
	   ThisItem.focus(); ThisItem.select();
	   return false;
	}
	return true;
}
function Ck_EmptyNumeric(ThisItem)
{
    if (ThisItem.value == "") {
        alert("This field must contain a value");
		ThisItem.focus();
		return false;
	}
	if (!IsNumeric(ThisItem.value))	{
       alert("This field must contain only numeric characters");
	   ThisItem.select(); ThisItem.focus(); 
	   return false;
	}
	return true;
}
function Ck_Currency(ThisItem)
{
	if (ThisItem.value == "") return true;
	if (!IsCurrency(ThisItem.value))	{
       alert("This field must contain only numeric characters with no more than 2 decimal places");
	   ThisItem.focus(); ThisItem.select();
	   return false;
	}
	return true;
}
function Ck_EmptyCurrency(ThisItem)
{
    if (ThisItem.value == "") {
        alert("This field must contain a value");
		ThisItem.focus();
		return false;
	}
	if (!IsCurrency(ThisItem.value))	{
       alert("This field must contain only numeric characters with no more than 2 decimal places");
	   ThisItem.select(); ThisItem.focus(); 
	   return false;
	}
	return true;
}
function Ck_Rate(ThisItem, DecMax)
{
	if (ThisItem.value == "") return true;
	if (!IsRate(ThisItem.value, DecMax))	{
       alert("This field must contain only numeric characters with no more than " + DecMax + " decimal places");
	   ThisItem.focus(); ThisItem.select();
	   return false;
	}
	return true;
}
function Ck_EmptyRate(ThisItem, DecMax)
{
    if (ThisItem.value == "") {
        alert("This field must contain a value");
		ThisItem.focus();
		return false;
	}
	if (!IsRate(ThisItem.value, DecMax))	{
       alert("This field must contain only numeric characters with no more than " + DecMax + " decimal places");
	   ThisItem.select(); ThisItem.focus(); 
	   return false;
	}
	return true;
}
function Ck_Email(ThisItem)
{
	if (ThisItem.value == "") return true;
	if (!IsEmail(ThisItem.value))	{
       alert("This field must contain only alphanumeric characters (some special) and an @ sign");
	   ThisItem.focus(); ThisItem.select();
	   return false;
	}
	return true;
}
function Ck_EmptyEmail(ThisItem)
{
    if (ThisItem.value == "") {
        alert("This field must contain a value");
		ThisItem.focus();
		return false;
	}
	if (!IsEmail(ThisItem.value))	{
       alert("This field must contain only alphanumeric characters (some special) and an @ sign");
	   ThisItem.select(); ThisItem.focus(); 
	   return false;
	}
	return true;
}
function ConvertUpper(ThisItem)
{
	//	Convert upper case
	ThisItem.value = ThisItem.value.toUpperCase();
}
function FillSpace(ThisItem, MaxLen)
{
	var i = 0;
	var nstring = "";
	
	nstring = ThisItem.value;
	
	if (nstring.length >= MaxLen) return;

	for (i=nstring.length; i<MaxLen; i++) {
		nstring = nstring + ' ';
	}

	ThisItem.value = nstring;
}
function Ck_category(ThisItem)
{
	if (!Ck_Numeric(ThisItem)) return false;
	return true;
}
function Ck_start_yr(ThisItem)
{
	if (!Ck_EmptySelect(document.FORM1.start_dy)) return false;
	if (!Ck_EmptySelect(document.FORM1.start_mon)) return false;
	if (!Ck_Numeric(ThisItem)) return false;
	
	if (ThisItem.value.length < 4) {
	   alert("This field must be at least 4 characters long");
	   ThisItem.focus(); ThisItem.select();
	   return false;
	}
	dindex = document.FORM1.start_dy.selectedIndex;
	mindex = document.FORM1.start_mon.selectedIndex;

	if (!ValidDate(document.FORM1.start_mon.options[mindex].value,
		document.FORM1.start_dy.options[dindex].value,
		ThisItem.value)) {

		alert("Invalid Date Entered !!!");
		document.FORM1.start_dy.focus();
		return false;
	}
	return true;
}
function Ck_stop_yr(ThisItem)
{
	if (!Ck_EmptySelect(document.FORM1.stop_dy)) return false;
	if (!Ck_EmptySelect(document.FORM1.stop_mon)) return false;
	if (!Ck_Numeric(ThisItem)) return false;

	if (ThisItem.value.length < 4) {
	   alert("This field must be at least 4 characters long");
	   ThisItem.focus(); ThisItem.select();
	   return false;
	}
	dindex = document.FORM1.stop_dy.selectedIndex;
	mindex = document.FORM1.stop_mon.selectedIndex;

	if (!ValidDate(document.FORM1.stop_mon.options[mindex].value,
		document.FORM1.stop_dy.options[dindex].value,
		ThisItem.value)) {

		alert("Invalid Date Entered !!!");
		document.FORM1.stop_dy.focus(); 
		return false;
	}

	EffCkDate = document.FORM1.start_yr.value  + CZeroPad(document.FORM1.start_mon_index.value)
		+ CZeroPad(document.FORM1.start_dy.value);

	StopCkDate = document.FORM1.stop_yr.value
		+ CZeroPad(document.FORM1.stop_mon.options[mindex].value)
		+ CZeroPad(document.FORM1.stop_dy.options[dindex].value);

	if (StopCkDate <= EffCkDate) {
		alert("Stop Date Must be greater than Effective Date !!!");
		document.FORM1.stop_dy.focus(); 
		return false;
	}

	return true;
}
function CYesNoText(bnum)
{
	var btext = ""
	
	if (bnum == 0) btext = "No";
	else btext = "Yes";
	
	return btext;
}
//-->


