
var approot = "/AZVOCA/"
var blninvaliddata = false;
var strvalidatedfield = "";   
var digits = "0123456789";
var lowercaseLetters = "abcdefghijklmnopqrstuvwxyz";
var uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var positivenegative = "+-"
var whitespace = " \t\n\r";
var decimalPointDelimiter = "."
var phoneNumberDelimiters = "()-. ";
var CurrencyDelimiters = "$, ";
var NumberDelimiters = ", ";
var validUSPhoneChars = digits + phoneNumberDelimiters;
var digitsInUSPhoneNumber = 10;
var ZIPCodeDelimiters = "-";
var validZIPCodeChars = digits + ZIPCodeDelimiters;
var digitsInZIPCode1 = 5
var digitsInZIPCode2 = 9

var daysInMonth = Array(12);
daysInMonth[1] = 31;
daysInMonth[2] = 29;
daysInMonth[3] = 31;
daysInMonth[4] = 30;
daysInMonth[5] = 31;
daysInMonth[6] = 30;
daysInMonth[7] = 31;
daysInMonth[8] = 31;
daysInMonth[9] = 30;
daysInMonth[10] = 31;
daysInMonth[11] = 30;
daysInMonth[12] = 31;

var USStateCodeDelimiter = "|";
var USStateCodes = "AL|AK|AS|AZ|AR|CA|CO|CT|DE|DC|FM|FL|GA|GU|HI|ID|IL|IN|IA|KS|KY|LA|ME|MH|MD|MA|MI|MN|MS|MO|MT|NE|NV|NH|NJ|NM|NY|NC|ND|MP|OH|OK|OR|PW|PA|PR|RI|SC|SD|TN|TX|UT|VT|VI|VA|WA|WV|WI|WY|AE|AA|AE|AE|AP";



var defaultEmptyOK = false;

function givefocus()
{
  var blnFound = false;
	  
  if(document.forms.length!=0)
  {
    for(i=0; i<document.forms.length; i++)
    {
      for(j=0; j<document.forms[i].length; j++)
      {
        if((document.forms[i].elements[j].type == "text" && !document.forms[i].elements[j].disabled) || document.forms[i].elements[j].type == "textarea" || document.forms[i].elements[j].type == "password" )
        {
          blnFound = true;
          document.forms[i].elements[j].focus();
          window.scrollTo(0,0);
          break;
        }
      }
	      
      if( blnFound ) break;
    }
  }
}

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

function isWhitespace (s)
{   
	var i;

    if (isEmpty(s)) return true;

    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);

        if (whitespace.indexOf(c) == -1) return false;
    }

    return true;
}

function stripCharsInBag (s, bag)
{   
	var i;
    var returnString = "";

    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }

    return returnString;
}

function stripCharsNotInBag (s, bag)
{   var i;
    var returnString = "";

    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (bag.indexOf(c) != -1) returnString += c;
    }

    return returnString;
}

function stripWhitespace (s)
{   return stripCharsInBag (s, whitespace)
}

function stripInitialWhitespace (s)
{   var i = 0;

    while ((i < s.length) && charInString (s.charAt(i), whitespace))
       i++;
    
    return s.substring (i, s.length);
}

function isLetter (c)
{   return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}

function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}

function isLetterOrDigit (c)
{   return (isLetter(c) || isDigit(c))
}

function isInteger (s)
{   
	var i;

    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);

    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }

    return true;
}

function isSignedInteger (s)
{   if (isEmpty(s)) 
       if (isSignedInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isSignedInteger.arguments[1] == true);

    else {
        var startPos = 0;
        var secondArg = defaultEmptyOK;

        if (isSignedInteger.arguments.length > 1)
            secondArg = isSignedInteger.arguments[1];

        if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
           startPos = 1;    
        return (isInteger(s.substring(startPos, s.length), secondArg))
    }
}

function isPositiveInteger (theField)
{   var secondArg = defaultEmptyOK;
    //s = stripCharsInBag(s, NumberDelimiters)
    var normalizedint = stripCharsInBag(theField, NumberDelimiters);   
    if (isPositiveInteger.arguments.length > 1)
        secondArg = isPositiveInteger.arguments[1];

    return (isSignedInteger(normalizedint, secondArg)
         && ( (isEmpty(normalizedint) && secondArg)  || (parseInt (normalizedint) > 0) ) );
}

function isNonnegativeInteger (theField)
{   var secondArg = defaultEmptyOK;
    var normalizedint = stripCharsInBag(theField, NumberDelimiters);     
    if (isNonnegativeInteger.arguments.length > 1)
        secondArg = isNonnegativeInteger.arguments[1];
    return (isSignedInteger(normalizedint, secondArg)
         && ( (isEmpty(normalizedint) && secondArg)  || (parseInt (normalizedint) >= 0) ) );
}

function RemoveLeadingZeros(value)
{
//alert(value);
//alert(value.length);
var convertedvalue = '';
var endremovezeros = false;
  for (i = 0; i < value.length; i++)
  {
    var c = value.charAt(i);
  //alert(c);
  //alert(convertedvalue);    
    if ((c != 0) && !endremovezeros)
    {
      endremovezeros = true;
      convertedvalue += c;
    }
    else if ((c == 0) && !endremovezeros && value.charAt(i + 1) == '.')
    {
      endremovezeros = true;
      convertedvalue += c;    
    }
    else if ((c == 0) && !endremovezeros && value.length == 1)
    {
      endremovezeros = true;
      convertedvalue += c;    
    }    
    else if (endremovezeros) convertedvalue += c;        
  }
  
  
return(convertedvalue);
}

function isFloat(s)             
{   
	var i;
    var seenDecimalPoint = false;
    var seenSign = false;
    var secondArg = defaultEmptyOK;

    if (isFloat.arguments.length > 1)
        secondArg = isFloat.arguments[1];
        
	if (isEmpty(s) && secondArg)
       return true;
       
    if (s == '.') return false;
                
    for (i = 0; i < s.length; i++)
    {
        var c = s.charAt(i);
                
        if ((c == '.') && !seenDecimalPoint) seenDecimalPoint = true;
        else if ((c == '-' || c == '+') && i == 0) seenSign = true;
        else if (!isDigit(c)) return false;
    }
                
    return true;
}

function isAlphabetic (s)
{   var i;

    if (isEmpty(s)) 
       if (isAlphabetic.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphabetic.arguments[1] == true);

    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);

        if (!isLetter(c))
        return false;
    }

    return true;
}

function isAlphanumeric (s)
{   var i;

    if (isEmpty(s)) 
       if (isAlphanumeric.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphanumeric.arguments[1] == true);

    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);

        if (! (isLetter(c) || isDigit(c) ) )
        return false;
    }

    return true;
}

function reformat (s)
{   var arg;
    var sPos = 0;
    var resultString = "";

    for (var i = 1; i < reformat.arguments.length; i++) {
       arg = reformat.arguments[i];
       if (i % 2 == 1) resultString += arg;
       else {
           resultString += s.substring(sPos, sPos + arg);
           sPos += arg;
       }
    }
    return resultString;
}



function roundtodecimals(original_number, decimalplaces) {
    var value1 = original_number * Math.pow(10, decimalplaces)
    var value2 = Math.round(value1)
    var value3 = value2 / Math.pow(10, decimalplaces)
    return insertzeros(value3, decimalplaces)
}

function insertzeros(rounded_value, decimal_places) {

    // Convert the number to a string
    var value_string = rounded_value.toString()
    
    // Locate the decimal point
    var decimal_location = value_string.indexOf(".")

    // Is there a decimal point?
    if (decimal_location == -1) {
        
        // If no, then all decimal places will be padded with 0s
        decimal_part_length = 0
        
        // If decimal_places is greater than zero, tack on a decimal point
        value_string += decimal_places > 0 ? "." : ""
    }
    else {

        // If yes, then only the extra decimal places will be padded with 0s
        decimal_part_length = value_string.length - decimal_location - 1
    }
    
    // Calculate the number of decimal places that need to be padded with 0s
    var pad_total = decimal_places - decimal_part_length
    
    if (pad_total > 0) {
        
        // Pad the string with 0s
        for (var counter = 1; counter <= pad_total; counter++) 
            value_string += "0"
        }
    return value_string
}

function removenumeralcommas(s)
{
  return stripCharsInBag(s, ",");
}

function removecommasfromfield(field)
{
  field.value = stripCharsInBag(field.value, ",");
  field.focus();
}

function insertnumeralcommas(s)
{
  s = removenumeralcommas(s);
  
    var sPos;
    var start = s.length - 1;
    var resultString = s.charAt(start);
  
	for (sPos = start-1; sPos >= 0; sPos--) 
    {
       if ((start - sPos) % 3 == 0) 
		   resultString = s.charAt(sPos) + ',' + resultString
       else 
           resultString = s.charAt(sPos) + resultString;
    }
    return resultString;
}

function isCurrency (s)
{   if (isEmpty(s)) 
       if (isCurrency.arguments.length == 1) return defaultEmptyOK;
       else return (isCurrency.arguments[1] == true);
    return (isFloat(s))
}


function checkCurrency (theField, emptyOK)
{   if (checkCurrency.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) {
		theField.value = reformatCurrency(0);
		return true;
	}
    else
    {  var normalizedCurrency = stripCharsInBag(theField.value, CurrencyDelimiters)
	   normalizedCurrency = convertParenthesis(normalizedCurrency)
       if (!isCurrency(normalizedCurrency, false)) 
          return false;
       else 
       {
          theField.value = reformatCurrency(normalizedCurrency)
          return true;
       }
    }
}

function reformatCurrency(s)
{
  var length;
  
	var startPos = 0;
	var endPos;
	var currency;
  var currencyfirstcharacter;
  var decimalpointposition;

  // Remove All Not Currency Characters
  currency = stripCharsNotInBag(s, decimalPointDelimiter + digits + positivenegative);
  //alert("Removed NonCurrency characters = " + currency);
  
  length = currency.length;
  currencyfirstcharacter = currency.substring(0,1);  
  //alert("First Character of Currency =" + currencyfirstcharacter);
  
  currency = currency.substring(1,length + 1);
  // Remove all +/- signs that are not the first character
  currency = stripCharsInBag(currency, positivenegative);
  //alert("Removed all negative and positive signs =" + currency);
  
  
  length = currency.length;
  decimalpointposition = currency.indexOf(decimalPointDelimiter);
  
  
  if (decimalpointposition != -1) {
  currency = stripCharsInBag(currency.substring(0,decimalpointposition + 1), decimalPointDelimiter) + "." + stripCharsInBag(currency.substring(decimalpointposition,length + 1), decimalPointDelimiter);
  //alert("Only one decimal point =" + currency);   
  }
  
  currency = currencyfirstcharacter + currency;

  currency = roundtodecimals(currency, 2);
  //alert("Rounded to 2 decimal places =" + currency);
  
  length = currency.length;
  
  if (currency.substring(length - 3, length + 1) == ".00") {
  currency = currency.substring(0, currency.indexOf("."));
  }
 
	if ( (currency.charAt(0) == "-") || (currency.charAt(0) == "+") ) 
		startPos = 1; 
	
	endPos = currency.indexOf(".");
	
	//alert("End Position = " + endPos);
	//alert("Length = " + s.length);

	if (endPos == -1)
	{
	  if (isNaN(s.length))
	  {
	    endPos = 1;  
	  }
	  else
	  {
	    endPos = s.length;
	  }
	}
		
	//alert(startPos + " " + endPos);
	
	if (currency.charAt(0) == "-")
	{   
		return( '-' + insertnumeralcommas(currency.substring(startPos, endPos)) + currency.substring(endPos, s.length));
	  //currency = '-' + insertnumeralcommas(currency.substring(startPos, endPos)) + currency.substring(endPos, s.length);
	}
	else 
	{
		return( insertnumeralcommas(currency.substring(startPos, endPos)) + currency.substring(endPos, currency.length) );
    //currency = insertnumeralcommas(currency.substring(startPos, endPos)) + currency.substring(endPos, currency.length);
  }
    currency = roundtodecimals(currency, 2)
    
    return( currency );
}	

function convertParenthesis(s)
{   
	if (isEmpty(s)) 
       if (convertParenthesis.arguments.length == 1) return defaultEmptyOK;
       else return (convertParenthesis.arguments[1] == true);

    else 
		if ( (s.charAt(0) == "(") && (s.charAt( s.length ) == ")") ) 
 			return ( '-' + s.substring(1, s.length - 1 ) )
		else 
			return( s );
}

function reformatUSPhone (USPhone)
{   return (reformat (USPhone, "(", 3, ") ", 3, "-", 4))
}

function isUSPhoneNumber (s)
{   if (isEmpty(s)) 
       if (isUSPhoneNumber.arguments.length == 1) return defaultEmptyOK;
       else return (isUSPhoneNumber.arguments[1] == true);
    return (isInteger(s) && s.length == digitsInUSPhoneNumber)
}

function checkUSPhone (theField, emptyOK)
{   
	if (checkUSPhone.arguments.length == 1) emptyOK = defaultEmptyOK;
	
	var normalizedPhone = stripCharsInBag(theField.value, phoneNumberDelimiters);
    if ((emptyOK == true) && (isEmpty(normalizedPhone))) return true;
    else
    {  
       if (!isUSPhoneNumber(normalizedPhone, false)) 
          return false;
       else 
       {
          theField.value = reformatUSPhone(normalizedPhone);
          return true;
       }
    }
}

function checkPhoneExt (theField, emptyOK)
{  
  if (checkPhoneExt.arguments.length == 1) emptyOK = defaultEmptyOK;
	var normalizedPhoneExt = stripCharsNotInBag(theField.value, digits);
  theField.value = normalizedPhoneExt;
  return true;

}


function isZIPCode (s)
{  if (isEmpty(s)) 
       if (isZIPCode.arguments.length == 1) return defaultEmptyOK;
       else return (isZIPCode.arguments[1] == true);
   return (isInteger(s) && 
            ((s.length == digitsInZIPCode1) ||
             (s.length == digitsInZIPCode2)))
}

function reformatZIPCode (ZIPString)
{   if (ZIPString.length == 5) return ZIPString;
    else return (reformat (ZIPString, "", 5, "-", 4));
}

function checkZIPCode (theField, emptyOK)
{   
	if (checkZIPCode.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else
    { var normalizedZIP = stripCharsInBag(theField.value, ZIPCodeDelimiters)
      if (!isZIPCode(normalizedZIP, false)) 
         return false;
      else 
      {
         theField.value = reformatZIPCode(normalizedZIP)
         return true;
      }
    }
}

function isEmail (s)
{   if (isEmpty(s)) 
       if (isEmail.arguments.length == 1) return defaultEmptyOK;
       else return (isEmail.arguments[1] == true);
   
    if (isWhitespace(s)) return false;
    
    var i = 1;
    var sLength = s.length;

    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}

function checkEmail (theField, emptyOK)
{   if (checkEmail.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else if (!isEmail(theField.value, false)) 
       return false;
    else return true;
}

function isYear (s)
{   if (isEmpty(s)) 
       if (isYear.arguments.length == 1) return defaultEmptyOK;
       else return (isYear.arguments[1] == true);
    if (!isNonnegativeInteger(s)) return false;
    //if (s > 2100 || s < 1900) return false;
    return (s.length == 4);
    //((s.length == 2) || 
}

function isIntegerInRange (s, a, b)
{   if (isEmpty(s)) 
       if (isIntegerInRange.arguments.length == 1) return defaultEmptyOK;
       else return (isIntegerInRange.arguments[1] == true);

    if (!isInteger(s, false)) return false;

    var num = parseInt (s);
    return ((num >= a) && (num <= b));
}

function isMonth (s)
{   if (isEmpty(s)) 
       if (isMonth.arguments.length == 1) return defaultEmptyOK;
       else return (isMonth.arguments[1] == true);
    return isIntegerInRange (s, 1, 12);
}

function isDay (s)
{   if (isEmpty(s)) 
       if (isDay.arguments.length == 1) return defaultEmptyOK;
       else return (isDay.arguments[1] == true);   
    return isIntegerInRange (s, 1, 31);
}

function daysInFebruary (year)
{
    return (  ((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) ) ) ? 29 : 28 );
}

function isDate (year, month, day)
{
    if (! (isYear(year, false) && isMonth(month, false) && isDay(day, false))) return false;

    var intYear = parseInt(year);
    var intMonth = parseInt(month);
    var intDay = parseInt(day);

    if (intDay > daysInMonth[intMonth]) return false; 

    if ((intMonth == 2) && (intDay > daysInFebruary(intYear))) return false;

    return true;
}

function checkYear (theField, emptyOK)
{   if (checkYear.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    if (!isYear(theField.value, false)) 
       return false;
    else return true;
}


function checkMonth (theField, emptyOK)
{   if (checkMonth.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    if (!isMonth(theField.value, false)) 
       return false;
    else return true;
}


function checkDay (theField, emptyOK)
{   if (checkDay.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    if (!isDay(theField.value, false)) 
       return false;
    else return true;
}

function checkDate (yearField, monthField, dayField, labelString, OKtoOmitDay)
{
    if (checkDate.arguments.length == 4) OKtoOmitDay = false;
    if (!isYear(yearField.value)) return false;
    if (!isMonth(monthField.value)) return false;
    if ( (OKtoOmitDay == true) && isEmpty(dayField.value) ) return true;
    else if (!isDay(dayField.value)) 
       return false;
    if (isDate (yearField.value, monthField.value, dayField.value))
       return true;
    return false;
}

function getRadioButtonValue (radio)
{   for (var i = 0; i < radio.length; i++)
    {   if (radio[i].checked) { break }
    }
    return radio[i].value;
}

function checkFederalID(theField, emptyOK)
{
	if (checkFederalID.arguments.length == 1) defaultEmptyOK = false;
	if ((emptyOK == true) && (isEmpty(theField.value))) return true;

	var strFedID = stripCharsNotInBag(theField.value, digits);

	if (strFedID.length != 9)
		return false;
		
	strFedID = (strFedID.substring(0,2) + "-" + strFedID.substring(2,9));

	theField.value = strFedID;
	
	return true;	
}

function checkValidDate(theField, emptyOK) 
{
	var dateStr = theField.value;
	var datePat = /^(\d{1,2})([\/-])(\d{1,2})\2(\d{4})$/; // requires 4 digit year

	if (checkValidDate.arguments.length == 1) defaultEmptyOK = false;
	if ((emptyOK == true) && (isEmpty(theField.value))) return true;

	var matchArray = dateStr.match(datePat); // is the format ok?
	if (matchArray == null) 
	{
		//alert(dateStr + " Date is not in a valid format.")
		return false;
	}
	month = matchArray[1]; // parse date into variables
	day = matchArray[3];
	year = matchArray[4];
	if (month < 1 || month > 12) 
	{ 
		return false;
	}
	if (day < 1 || day > 31) 
	{
		return false;
	}
	if ((month==4 || month==6 || month==9 || month==11) && day==31) 
	{
		return false;
	}
	if (month == 2) 
	{ 
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day>29 || (day==29 && !isleap)) 
		{
			return false;
		}
	}
	if (year < 1900 || year > 2078) 
	{
	  return false;	
	}

  theField.value = month + '/' + day + '/' + year;	
	return true;
}



function checkTextareaLength(theField, maxSize)
{
	strTextarea = theField.value;
	if (strTextarea.length > maxSize) {
		return false;
	}
	
	return true;
}


var strNonNegIntMsg = 'This field must be a non-negative whole number.  Please reenter it now.';
var strNonNegFloatMsg = 'This field must be a non-negative number.  Please reenter it now.';
var strMoneyErrorMsg = 'This field must be a non-negative whole dollar amount.  Please reenter it now.';
var strNonNegMoneyMsg = 'This field must be a non-negative dollar amount.  Please reenter it now.';

var strValidPhoneMsg = "This field must be a valid phone number with area code.  Please reenter it now.";
var strValidFaxMsg = "This field must be a valid fax number with area code.  Please reenter it now.";
var strValidZipMsg = "This field must be a valid zip code.  Please reenter it now.";
var strValidDateMsg = "This field must be a valid date using the format: mm/dd/yyyy.  Please reenter it now.";
var strValidFedIDMsg = "This field must be a valid Federal ID using the format: 12-1234567.  Please reenter it now."
var strValidCVANumMsg = "This field must be a valid CVA Number using the format: 12345-67V89 or 12345-6V78.  Please reenter it now."



function checkNonNegInt(field)
{
	if (!isNonnegativeInteger(field.value, true))
		alert(strNonNegIntMsg);
}

function checkNonNegFloat(field)
{
	if (!isNonnegativeFloat(field.value, true))
		alert(strNonNegFloatMsg);
}


function isNonnegativeFloat(s)
{
	var secondArg = defaultEmptyOK;

    if (isNonnegativeFloat.arguments.length > 1)
        secondArg = isNonnegativeFloat.arguments[1];
        
    if (isEmpty(s) && secondArg)
       return true;
           
	if (isFloat(s) && parseFloat(s) >= 0)
		return true;
	else return false;
}

function checkNonNegCurrency(field)
{	
	//if (!isNonNegCurrency(field.value, true))
	//	alert(strNonNegMoneyMsg);
	//else 
	field.value = reformatCurrency(unformatCurrency(field.value));
}

function isNonNegCurrency(s)
{
	var secondArg = defaultEmptyOK;
  s = reformatCurrency(unformatCurrency(s));
   
    if (isNonNegCurrency.arguments.length > 1)
        secondArg = isNonNegCurrency.arguments[1];
        
    if (isEmpty(s) && secondArg)
       return true;
       
	if (!isNonnegativeFloat(unformatCurrency(s)))
		return false;
	else return true;
}

function checkNonNegWholeCurrency(field)
{	
	if (!isNonNegWholeCurrency(field.value, true))
		alert(strMoneyErrorMsg);
	else field.value = reformatCurrency(unformatCurrency(field.value));
}

function isNonNegWholeCurrency(s)
{
	var secondArg = defaultEmptyOK;

    if (isNonNegWholeCurrency.arguments.length > 1)
        secondArg = isNonNegWholeCurrency.arguments[1];
        
    if (isEmpty(s) && secondArg)
       return true;
		
	if (!isNonnegativeInteger(unformatCurrency(s)))
		return false;
	else return true;
}

function unformatCurrency(s)
{
  var returnedvalue = "";
  
	returnedvalue = stripCharsInBag(s, CurrencyDelimiters);
	if (returnedvalue == "")
	  returnedvalue = 0;
	
	return returnedvalue;
	
}

function calcTotalLineAmnt(vocaField, localField, totalField)
{
	if (isEmpty(vocaField.value))
		vocaField.value = 0;
	if (isEmpty(localField.value))
		localField.value = 0;
		
	//totalField.value = parseInt(unformatCurrency(vocaField.value)) + parseInt(unformatCurrency(localField.value));
	// modified by seyed on 11/17/00 to the following line
	totalField.value = Math.round(parseFloat(unformatCurrency(vocaField.value)) + parseFloat(unformatCurrency(localField.value)));
	
	if (totalField.value == "NaN")
		totalField.value = "error";
	else totalField.value = reformatCurrency(totalField.value.toString());				
}

function selectField(field)
{
  //field.focus();
	field.select();
}

function noFocus(field, text)
{
  var Errormessage;
  Errormessage = "You may not change this value.\nThe system automatically calculates this value";
  if (isEmpty(text)) {
   //Errormessage = Errormessage + ".";
  }
  else
  { 
  Errormessage = Errormessage + " by " + text;
  alert(Errormessage);
  }
	field.blur();  
  //alert(Errormessage);  
}
function SubmittedReport(field)
{
  var Errormessage;
  Errormessage = "You may not change this value.\nThis report has already been submitted and therefore cannot be edited.";
	field.blur();  
  alert(Errormessage);  

}


function setToZeroIfBlank(field)
{
	if (field.value == "")
		field.value = "0";
}


function isInRange(field, intMax, emptyOK)
{	
	var intFieldValue;

	if ((emptyOK == true) && (isEmpty(field.value))) 
		return true;
	
	intFieldValue = parseInt(field.value);
	if (intFieldValue.toString() == "NaN")
		return false;
		
	if (intFieldValue < 1 || intFieldValue > intMax)
		return false;
	else return true;
}


function validateField(type, field, fieldName, sectionTitle, intMax )
{
  // Following code added 02/26/02 to prevent infinite loop of going from one field with error to another with an error.
  if (blninvaliddata && field != strvalidatedfield)
  {
    return true;
  }

  var errorMsg = "";
  var emptyOK = true;
  var displayError = false;
  if (type=="zipcode")
  {
  field.value = stripWhitespace(field.value + " ");
  }
  
  if( sectionTitle != "" && sectionTitle != null )
  {
    errorMsg = "In section:  " + sectionTitle + "\n\n";
  }

  if( type=="phone" )
  {
    if( !checkUSPhone(field, emptyOK) )
    {
      displayError = true;
      errorMsg += "Please enter a valid phone number for \"" + fieldName + "\"";
      errorMsg += "\nValid format:  (123) 456-7890";
    }
  }
  if( type=="phoneext" )
  {
    if( !checkPhoneExt(field, emptyOK) )
    {
      displayError = true;
      errorMsg += "Please enter a valid telephone extension for \"" + fieldName + "\"";
    }
  }  
  else if( type=="zipcode" )
  {
    if( !checkZIPCode(field, emptyOK) )
    {
      displayError = true;
      errorMsg += "Please enter a valid Zip Code";
      errorMsg += "\nValid formats:  12345 or 12345-6789";
    }
  }
  else if ( type=="numerical" )
  {
    field.value = stripWhitespace(field.value);
    
    if (field.value == "")
    {
      field.value = 0;
    }
    if( !isNonnegativeInteger(field.value, emptyOK) )
    {
      displayError = true;
      errorMsg += "Please enter a valid postive numerical value."
    }  
    else
    {    
      field.value = RemoveLeadingZeros(stripCharsInBag(field.value, NumberDelimiters));
    }
  
  }
  else if ( type=="alphanumeric" )
  {
    field.value = stripWhitespace(field.value);
    
    if (field.value == "")
    {
      field.value = 0;
    }
    if( !isAlphanumeric(field.value, emptyOK) )
    {
      displayError = true;
      errorMsg += "Please enter an Alpha Numeric number."
    }  
    else
    {    
      field.value = RemoveLeadingZeros(stripCharsInBag(field.value, NumberDelimiters));
    }
  
  }   
   
   
    
  else if( type=="date" )
  {
    if( !checkValidDate(field, emptyOK))
    {
      displayError = true;
      errorMsg += "Please enter a valid " + fieldName;
      errorMsg += "\nValid format:  MM/DD/YYYY";
    }  
  }
  else if( type=="federalID" )
  {
    if( !checkFederalID(field, emptyOK) )
    {
      displayError = true;
      errorMsg += "Please enter a valid Federal Employer ID Number";
      errorMsg += "\nValid format:  12-3456789";
    }
  }
  else if( type=="year" )
  {
    if( !checkYear(field, emptyOK) )
    {
      displayError = true;
      errorMsg += "Please enter a valid 4-digit year";
      errorMsg += "\nValid formats:  2004, 2005, etc.";
    }  
  }
  else if( type=="nonNegInt" )
  {
    field.value = stripWhitespace(field.value);
    
    if (field.value == "")
    {
      field.value = 0;
    }
    if( !isNonnegativeInteger(field.value, emptyOK) )
    {
      displayError = true;
      errorMsg += "The field \"" + fieldName + "\" must be a non-negative integer."
      errorMsg += "\nPlease re-enter it now."
    }  
    else
    {    
      field.value = RemoveLeadingZeros(stripCharsInBag(field.value, NumberDelimiters));
    }
  
  }
  else if( type=="nonNegWholeCurrency" )
  {
    if( !isNonNegWholeCurrency(field.value, emptyOK) )
    {
      displayError = true;
      errorMsg += fieldName + " must be a non-negative whole dollar amount."
      errorMsg += "\nPlease re-enter it now."
    }
    else
    {
      field.value = reformatCurrency(unformatCurrency(field.value));
    }
  }
  else if( type=="Currency" )
  {
    if( !isCurrency(unformatCurrency(field.value)) )
    {
      displayError = true;
      errorMsg += fieldName + " must be a dollar amount."
      errorMsg += "\nPlease re-enter it now."
    }
    else
    {
      //alert( reformatCurrency(unformatCurrency(field.value)));
      field.value = reformatCurrency(unformatCurrency(field.value));
    }
  }  
  else if( type=="nonNegCurrency" )
  {
    if( !isNonNegCurrency(field.value, emptyOK) )
    {
      displayError = true;
      errorMsg += fieldName + " must be a non-negative dollar amount."
      errorMsg += "\nPlease re-enter it now."
    }
    else
    {
      //alert( reformatCurrency(unformatCurrency(field.value)));
      field.value = reformatCurrency(unformatCurrency(field.value));
    }
  }
  else if( type=="threedecimalplaces" )
  {
    var lngthreedecimalplaces;
    var decimalpointposition;
    lngthreedecimalplaces = stripCharsNotInBag(field.value, decimalPointDelimiter + digits);
    decimalpointposition = lngthreedecimalplaces.indexOf(decimalPointDelimiter);
  
  
    if (decimalpointposition != -1)
    {
    lngthreedecimalplaces = stripCharsInBag(lngthreedecimalplaces.substring(0,decimalpointposition + 1), decimalPointDelimiter) + "." + stripCharsInBag(lngthreedecimalplaces.substring(decimalpointposition,lngthreedecimalplaces.length + 1), decimalPointDelimiter);       
    }
    //alert("Only one decimal point =" + lngthreedecimalplaces);    
    lngthreedecimalplaces = roundtodecimals(lngthreedecimalplaces, 3);
    
    field.value = lngthreedecimalplaces;
  }
  else if( type=="nonNegFloat" )
  {
    if( !isNonnegativeFloat(field.value, emptyOK) )
    {
      displayError = true;
      errorMsg += fieldName + " must be a non-negative number."
      errorMsg += "\nPlease re-enter it now."
    }
    else
    {
      field.value = reformatCurrency(unformatCurrency(field.value));
    }
  }
  else if( type=="textarea" )
  {
  var intexcesscharacters = 0;
  var excessmessage = "";
 
    if(!checkTextareaLength(field, intMax))
    {
    displayError = true;
    intexcesscharacters = field.value.length - intMax;
      if (intexcesscharacters == 1) 
      {
        excessmessage = intexcesscharacters + " character"; 
      }
      else
      { 
        excessmessage = intexcesscharacters + " characters"; 
      }  
      if(fieldName=="")
      {
        errorMsg += "The text box input exceeds the maximum length of " + intMax + " characters.\nPlease remove " + excessmessage + ".\nNote: Characters include whitespaces."
      }
      else
      {
        errorMsg += "The input for \"" + fieldName + "\" exceeds the maximum length of " + intMax + " characters.\nPlease remove " + excessmessage + ".\nNote: Characters include whitespaces."
      }
    }
  }
  else if( type=="email" )
  {
    if(!isEmail(field.value, emptyOK))
    {
      displayError = true;
      errorMsg += "The field \"" + fieldName + "\" contains an invalid e-mail address."
      errorMsg += "\nPlease re-enter it now."
    }
  }
              
  if( displayError )
  {
    strvalidatedfield = field;
    alert(errorMsg);
    if( type!="textarea" )
    {      
      field.select(); 
    }
    blninvaliddata = true;
    strvalidatedfield = field;  
    field.focus();    
  }
  else
  {
    blninvaliddata = false;
  }
  return true; 
}

function roundToPennies(n)
{
 pennies = n * 100;

 pennies = Math.round(pennies);

 strPennies = "" + pennies;
 len = strPennies.length;

 return strPennies.substring(0, len - 2) + "." + strPennies.substring(len - 2, len);
}

function CheckErrors(URL, ShowMessage)
{

  if (ShowMessage != 1 && ShowMessage != 0)
    ShowMessage = 1;
    
  var ErrorWindow;
	var msg = "\n You need to save your changes before doing error checking!\n\n" +
			  "Click OK to continue with the error checking.\n" + 
			  "Click Cancel to go back and save your changes.\n";
		if (ShowMessage == 1)
		{	  		  
	  if (confirm(msg))
	  {	  	  
      ErrorWindow = window.open(URL, 'Errors', 'scrollbars=yes,width=700, height=500');
      ErrorWindow.focus();
	  }
	  }
	  else
	  {
      ErrorWindow = window.open(URL, 'Errors', 'scrollbars=yes,width=700, height=500');
      ErrorWindow.focus();
	  }

  return;
  
}
function CheckAllErrors(URL)
{	 
  ErrorWindow = window.open(URL, 'Errors', 'scrollbars=yes,width=700, height=500');
  ErrorWindow.focus();
}

function GetHelp(ID,fscID)
{
  var HelpWindow;
  HelpWindow = window.open(approot + 'voca/help.asp?ID=' + ID + '&fscID=' + fscID, 'Help', 'scrollbars,left=0,top=0,resizable');
  HelpWindow.focus();
  
  return;
}

function DisplayInformation()
{
  var InformationWindow;
  InformationWindow = window.open(approot + 'voca/displayinformation.asp', 'Information', 'scrollbars,left=0,top=0,resizable');
  InformationWindow.focus();
  
  return false;
}

function DeleteRecord()
{
  if(confirm("Are you sure you want to delete this record?") == true)
    return true;      
  else
    return false;
}

function DeleteBudget()
{
  if(confirm("Are you sure you want to delete the budget for this record?") == true)
    return true;      
  else
    return false;
}


function DeleteGoalWarning()
{
  if(confirm("WARNING: Deleting the Performance Measure(s) may cause the loss of data submitted in the quarterly Programmatic Report(s). Contact your agency’s VOCA Grant Coordinator if changes are necessary to the Performance Measures. Click the OK button to continue deleting this record. Click the CANCEL button to go back.") == true)
    return DeleteRecord();      
  else
    return false;
}