//**********************************************************************************************
//** function setFormFieldError( ppi_fieldToSetToError, pci_errorMessage ) {

//** function createDaysArray(n) {
//** function isInteger(s){
//** function daysInFebruary (year){
//** function stripCharsInBag(s, bag){
//** function checkDateString  ( ppi_fieldDatePtr ){

//** function ReadUStime(pti_fieldTimeField) {

//** function checkFieldRegExpString( ppi_fieldFieldPtr, pci_fieldType, pci_additionalFieldParameter ) {
//** function validateFormFilename( ppi_formFieldToValidate ){
//** function validateFormEmail( ppi_formEmailFieldToValidate ){
//** function validateFormPhone(  ppi_formPhoneFieldToValidate ){
//** function validateFormzip(  ppi_formFieldToValidate ){
//** function validateFormInteger(  ppi_formFieldToValidate ){
//** function validateFormDecimal(  ppi_formFieldToValidate ){
//** function validateFormNbrRange( ppi_formFieldToValidate, pii_lowRange, pii_hiRange ){
//** function validateFormLength( ppi_formFieldToValidate, pii_formLengthMinMax ){

//** function processRequiredFormattingFieldEdits()
//**********************************************************************************************


//**********************************************************************************************
//* FUNCTION: set or clear an error message next to a field
//* ppi_fieldToSetToError: a pointer to the error division that contains the error text. This will be either set visible or invisible.
//* pci_errorMessage     : an error message to display.
//*                             If the message populated, the division is made visible
//*                             If the message empty, the division hidden.
//**********************************************************************************************
//* example: setFormFieldError( "fieldvalue13", "Valid format is mm/dd/yy")
//* example: setFormFieldError( "fieldvalue13", "")
//**********************************************************************************************
function setFormFieldError( ppi_fieldToSetToError, pci_errorMessage ) {

    var lc_fieldToSetToError     = ppi_fieldToSetToError.name.replace("value","error")
    var lc_fieldIconToSetToError = ppi_fieldToSetToError.name.replace("value","erroricon")

    var lp_fieldPtr     = getObject(lc_fieldToSetToError)
    var lp_fieldIconPtr = getObject(lc_fieldIconToSetToError)


//lp_fieldPtr.innerHTML = 'hello';
//alert( "innerHTML=" + lp_fieldPtr.innerHTML );
//alert( "ppi_fieldToSetToError=" + ppi_fieldToSetToError.id );

    //* If the incoming message is blank, then hide the error message as this indicates there is no error
    if ( (pci_errorMessage=="") || (pci_errorMessage==null) ) {
        hideObject( lc_fieldToSetToError )
        //changeObjVis( lc_fieldToSetToError, "hidden");

        ppi_fieldToSetToError.style.backgroundColor='#ffffff'
        ppi_fieldToSetToError.style.border='2px #ffffff inset'
        lp_fieldPtr.innerHTML=""

        //* Only change the image back to an info gif if it is an error gif
        if (( lp_fieldIconPtr ) && ( lp_fieldIconPtr.src ))
            if ( lp_fieldIconPtr.src.indexOf("icon.exclamationpoint.gif") > 0 ) {
                lp_fieldIconPtr.src="images/icon.info.gif"
            }
    }
    else {
        showObject( lc_fieldToSetToError )
        //changeObjVis( lc_fieldToSetToError, "visible");

        //alert( ppi_fieldToSetToError.currentStyle.backgroundColor );
        //alert( ppi_fieldToSetToError.currentStyle.borderTopColor + "/" + ppi_fieldToSetToError.currentStyle.borderLeftColor + "/" + ppi_fieldToSetToError.currentStyle.borderBottomColor + "/" + ppi_fieldToSetToError.currentStyle.borderRightColor );
        //alert( ppi_fieldToSetToError.currentStyle.borderTopWidth + "/" + ppi_fieldToSetToError.currentStyle.borderLeftWidth + "/" + ppi_fieldToSetToError.currentStyle.borderBottomWidth + "/" + ppi_fieldToSetToError.currentStyle.borderRightWidth );
        //alert( ppi_fieldToSetToError.currentStyle.borderTopStyle + "/" + ppi_fieldToSetToError.currentStyle.borderLeftStyle + "/" + ppi_fieldToSetToError.currentStyle.borderBottomStyle + "/" + ppi_fieldToSetToError.currentStyle.borderRightStyle );
        ppi_fieldToSetToError.style.border='2px red solid'
        ppi_fieldToSetToError.style.backgroundColor='#f9e3ad'
        lp_fieldPtr.innerHTML="<span style='color:red;font-size:8px;text-transform:uppercase;'>" + pci_errorMessage + "</span>"

        //* Only change the image to an error gif if it is an info gif
        if (( lp_fieldIconPtr ) && ( lp_fieldIconPtr.src ))
            if ( lp_fieldIconPtr.src.indexOf("icon.info.gif") > 0 ) {
                lp_fieldIconPtr.src="images/icon.exclamationpoint.gif"
            }
    }

  //this.src="images/icon.exclamationpoint.gif";
  //var lp_errfld=document.all? document.all[lc_fieldToSetToError] : document.getElementById? document.getElementById(lc_fieldToSetToError): "";
  //changeObjVis( lp_errfld, "visible");
  //lp_errfld.innerHTML="<span style=color:red;font-size:8px;text-transform:uppercase;>" + pci_errorMessage + " </span>"


}

//**********************************************************************************************
//**********************************************************************************************
//**********************************************************************************************
/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

//**********************************************************************************************
//* DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
//**********************************************************************************************
//*****************************************************************************
//** FUNCTION: Determines whether a string contains only integers
//** ppi_Number: The ID of the object to verify
//** Note     : Function was extrapolated from bugbook.com
//*****************************************************************************
function isInteger(ppi_Number){
        var i;
    for (i = 0; i < ppi_Number.length; i++){
        // Check that current character is number.
        var c = ppi_Number.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}


//**********************************************************************************************
//* Numeric validation script. Courtesy of http://www.codetoad.com/javascript/isnumeric.asp
//**********************************************************************************************
//*****************************************************************************
//** FUNCTION: Determines whether a string contains only digits or decimals
//** sText    : The number to validate
//*****************************************************************************
//*****************************************************************************
function IsNumeric(sText)

{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;


   for (i = 0; i < sText.length && IsNumber == true; i++)
      {
      Char = sText.charAt(i);
      if (ValidChars.indexOf(Char) == -1)
         {
         IsNumber = false;
         }
      }
   return IsNumber;

   }


//*****************************************************************************
//* Function will remove all charactersToRemove from stringToBeStripped
//*****************************************************************************
function stripCharsInBag(pci_stringToBeStripped, pci_charactersToRemove){
    var i;

    var returnString = "";

    // Search through string's characters one by one.
    // If character is not in pci_charactersToRemove, append to returnString.

    for (i = 0; i < pci_stringToBeStripped.length; i++){

        var c = pci_stringToBeStripped.charAt(i);
        if (pci_charactersToRemove.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

//*****************************************************************************
function daysInFebruary (year){
        // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

//*****************************************************************************
function createDaysArray(n) {
        for (var i = 1; i <= n; i++) {
                this[i] = 31
                if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
                if (i==2) {this[i] = 29}
   }
   return this
}

//*****************************************************************************
function checkDateString(ppi_fieldDatePtr){

        //Trim all spaces all ends of value in case user entered just spaces
        ppi_fieldDatePtr.value=trimAll(ppi_fieldDatePtr.value);
        var dtStr       = ppi_fieldDatePtr.value
        var daysInMonth = createDaysArray(12)
        var pos1        = dtStr.indexOf(dtCh)
        var pos2        = dtStr.indexOf(dtCh,pos1+1)
        var strMonth    = dtStr.substring(0,pos1)
        var strDay      = dtStr.substring(pos1+1,pos2)
        var strYear     = dtStr.substring(pos2+1)
        var strYr       = ""
        var month       = 0
        var day         = 0
        var year        = 0


        //alert(ppi_fieldDatePtr.name.replace("value","name"));
//alert("date1=" + ppi_fieldDatePtr.value );
        var lc_FldName  = getObject(ppi_fieldDatePtr.name.replace("value","name"))
            lc_FldName  = lc_FldName.value

        var lc_errMsg   = ""

        //* Only check the field format if the field is populated
        if ( dtStr.length > 0 ) {

            strYr           = strYear
            if (strDay.charAt(0)  =="0" && strDay.length  >1) strDay=strDay.substring(1)
            if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
            for (var i = 1; i <= 3; i++) {
                    if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
            }

            month = parseInt(strMonth)
            day   = parseInt(strDay)
            year  = parseInt(strYr)
            if (pos1==-1 || pos2==-1){
                    lc_errMsg   = "Edit 1: Field '" + lc_FldName + "' date format should be: mm/dd/yyyy"
            }
            if (strMonth.length<1 || month<1 || month>12){
                    lc_errMsg   = "Edit 2: Please enter a valid month in Field '" + lc_FldName + "'"
            }
            if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
                    lc_errMsg   = "Edit 3: Please enter a valid day in Field '" + lc_FldName + "'"
            }
            if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
                    lc_errMsg   = "Edit 4: Please enter a valid 4 digit year between "+minYear+" and "+maxYear + " in Field '" + lc_FldName + "'"
            }
            if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
                    lc_errMsg   = "Edit 5: Please enter a valid date in Field '" + lc_FldName + "'"
            }
        }


        if ( lc_errMsg.length == 0 ) {
            setFormFieldError( ppi_fieldDatePtr )

            //Pad the month and day with leading zeros
            if ( month ) month = "000" + month;
            if (  day  )  day  = "000" +  day ;
            if ( month&&day )
                ppi_fieldDatePtr.value = month.substr(month.length-2,2) + "/" + day.substr(day.length-2,2) + "/" + year;
//alert("date2=" + ppi_fieldDatePtr.value );

            return true
        }
        else
        {
            setFormFieldError( ppi_fieldDatePtr, "Format is 'mm/dd/yyyy'")
//alert(lc_errMsg.length + ":" + ppi_fieldDatePtr.value )
            //alert( lc_errMsg )
            return false
        }

}

//*****************************************************************************
function validateFormDate( ppi_formDateFieldToValidate ){
        //var dt=document.frmSample.txtDate

//alert(getObject(ppi_formDateFieldToValidate.name.replace("value","name")).value);

        //Trim all spaces from the ends of the value in case user entered some leading/trailing spaces
        ppi_formDateFieldToValidate.value = trimAll(ppi_formDateFieldToValidate.value);

        if (checkDateString(ppi_formDateFieldToValidate)==false){
                ppi_formDateFieldToValidate.focus()
                return false
        }
    return true
 }



//**********************************************************************************************
//* DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
//**********************************************************************************************


//**********************************************************************************************
//** FUNCTION will accept a field ptr and process a regular expression to verify the format of the field
//**    ppi_fieldFieldPt              : Field Pointer to the field that contains the value to verify
//**    pci_fieldType                 : Type of edit to perform on the field (e.g., email, phone, zip, time)
//**    pci_additionalFieldParameter  : Additional data needed to process the format for the field (e.g., for length, it would be minmax)
//**********************************************************************************************
//** Good Regexp Reference - http://www.devshed.com/c/a/JavaScript/Understanding-the-JavaScript-RegExp-Object/3/
//** + = 1 or more occurrences
//** * = 0 or more occurrences
//** ? = 0 or 1 occurrences
//**********************************************************************************************
//** checkFieldRegExpString( fieldPtr, "email"   )
//** checkFieldRegExpString( fieldPtr, "phone"   )
//** checkFieldRegExpString( fieldPtr, "zip"     )
//** checkFieldRegExpString( fieldPtr, "time"    )
//** checkFieldRegExpString( fieldPtr, "integer" )
//**********************************************************************************************
function checkFieldRegExpString( ppi_fieldFieldPtr, pci_fieldType, pci_additionalFieldParameter ) {

    var regExpr
    var lc_fieldFormat

    if (!((ppi_fieldFieldPtr.value==null)||(ppi_fieldFieldPtr.value.length==0)))
    {

        //Get the object ID annd value
        var lc_FldName  = getObject(ppi_fieldFieldPtr.name.replace("value","name"))
            lc_FldName  = lc_FldName.value

        var lc_fieldStringValue = ppi_fieldFieldPtr.value

        //Determine the type of edit to fire
        switch( pci_fieldType )
        {
            case 'filename':
                        {
                            //                    AlphaNumeric_- as the first character then optional AlphaNumeric_-.  (no spaces allowed)
                            regExpr        = /^([0-9a-z\_\-]+[0-9a-z\_\-\.]*)$/;
                            //                                  space/./-
                            lc_fieldFormat = "Alpha, Nbr, .-_ only"
                            break;
                        }

            case 'phone':
                        {
                            //                  Match 3 digits OR (Match 3 digits)             3 digits               Any four digits
                            regExpr        = /^([1-9][0-9][0-9]|\([1-9][0-9][0-9]\))[\s\.\-]?[1-9][0-9][0-9][\s\.\-]?\d{4}$/;
                            //                                                      space/./-               space/./-
                            lc_fieldFormat = "999.999.9999"
                            break;
                        }

            case 'email':
                        {
                            //                 Alpha     Alpha Alpha     Alpha   Alpha23
                            regExpr        = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
                            //                      ./-       @      ./-        .
                            lc_fieldFormat = "x@y.zzz"
                            break;
                        }

            case 'time':
                        {
                            //                   10-12  OR  0-9     opt ":0-59"       AM/PM
                            regExpr        = /^([1][0-2]|[0]?[0-9])(\:[0-5][0-9])?\s?[AP]M$/;
                            lc_fieldFormat = "hh:mm am/pm"
                            break;
                        }

            case 'zip':
                        {
                            //                 5 digs (optional - and 4 digs)
                            regExpr        = /^\d{5}(\-?\d{4})?$/;
                            lc_fieldFormat = "99999-9999"
                            break;
                        }

            case 'integer':
                        {
                            //                 any number of digits up to max length
                            regExpr        = /^\-?([0-9])*\.?(\.[0-9]*)?$/;
                            lc_fieldFormat = "Integer Only"
                            break;
                        }

            case 'decimal':
                        {
                            //                 any number of digits up to max length with one optional decimal point and optional two decimal places
                            regExpr        = /^\-?([0-9])*(\.\d{2})?$/;
                            lc_fieldFormat = "999,999.99"
                            break;
                        }

            case 'mandatory':
                        {
                            //                 at least one character
                            regExpr        = /^\w+$/;
                            lc_fieldFormat = "Field is required"
                            break;
                        }

            case 'nbrrange':
                        {
                            //Get low and high parameters from the additionalFieldParameter in the form of "rangeLow|rangeHigh"
                            li_rangeLow = parseInt(pci_additionalFieldParameter.substring(0,pci_additionalFieldParameter.indexOf("|")))
                            li_rangeHi  = parseInt(pci_additionalFieldParameter.replace(li_rangeLow+"|",""))
//alert(pci_additionalFieldParameter + "/" + pci_additionalFieldParameter.indexOf("|") + "/" + pci_additionalFieldParameter.substring(0,1) + "/" + li_rangeLow + "/" + li_rangeHi)

                            //If Garbage is provided for low or high ranges, then default to 1-500
                            li_rangeLow = (isNaN(li_rangeLow))?1  :li_rangeLow;
                            li_rangeHi  = (isNaN(li_rangeHi ))?500:li_rangeHi;

                            if (( lc_fieldStringValue < li_rangeLow ) || ( lc_fieldStringValue > li_rangeHi )) {
                                //                 Cause regedit to fail regardless
                                regExpr        = /^errorerrorerror/;
                                lc_fieldFormat = "Number between " + li_rangeLow + " to " + li_rangeHi
                            }
                            else {
                                regExpr        = /^\-?([0-9])+$/;
                                lc_fieldFormat = "Numeric Only"
                            }
                            break;
                        }
            default:
                        {
                            alert( "Invalid field edit type: " + pci_fieldType );
                        }
        }

//alert( "lc_fieldFormat=" + lc_fieldFormat );


        //Verify the regular expression set by the SELECT statement
        if (regExpr.test(lc_fieldStringValue)) {
//alert(21+"|"+lc_fieldStringValue);
            setFormFieldError( ppi_fieldFieldPtr )
            return true
        }
        else {
//alert(3);
            setFormFieldError( ppi_fieldFieldPtr, "Format is '" + lc_fieldFormat + "'")
            //alert( "Field '" + lc_FldName + "' format is: " + lc_fieldFormat )
            return false
        }
    }
    else
    {
        setFormFieldError( ppi_fieldFieldPtr )
        return true
    }
}
//**********************************************************************************************

function validateFormFilename( ppi_formFieldToValidate ){

//alert(ppi_formFieldToValidate.id);

      if (!(ppi_formFieldToValidate.id=='undefined'))
      {
          //Trim all spaces from the ends of the value in case user entered just spaces
          ppi_formFieldToValidate.value = trimAll(ppi_formFieldToValidate.value.toLowerCase());

          if (checkFieldRegExpString( ppi_formFieldToValidate, "filename" )==false)
          {
//alert(2);
                  ppi_formFieldToValidate.focus()
                  return false
          }
      }
      return true;
 }


//**********************************************************************************************

function validateFormEmail( ppi_formFieldToValidate ){

//alert(ppi_formFieldToValidate.id);

    //if (!((ppi_formFieldToValidate.value==null)||(ppi_formFieldToValidate.value=="")))
      if (!(ppi_formFieldToValidate.id=='undefined'))
      {
          //Trim all spaces from the ends of the value in case user entered just spaces
          ppi_formFieldToValidate.value = trimAll(ppi_formFieldToValidate.value.toLowerCase());

          if (checkFieldRegExpString( ppi_formFieldToValidate, "email" )==false)
          {
//alert(2);
                  ppi_formFieldToValidate.focus()
                  return false
          }
      }
      return true;
 }


//**********************************************************************************************
function validateFormPhone( ppi_formFieldToValidate ){

      //if ((ppi_formFieldToValidate.value==null)||(ppi_formFieldToValidate.value=="")){
      //        alert("Please Enter your Phone Number")
      //        ppi_formFieldToValidate.focus()
      //        return false
      //}
        if (checkFieldRegExpString( ppi_formFieldToValidate, "phone" )==false) {
                ppi_formFieldToValidate.focus()
                return false
        }

        //* If there is a value, then reformat it with correct phone format
        if (!((ppi_formFieldToValidate.value==null)||(ppi_formFieldToValidate.value=="")))
        {
            //* Strip all non-numeric characters from the string
            ppi_formFieldToValidate.value = stripCharsInBag( ppi_formFieldToValidate.value, "- ().")

            //* Reformat the string of numbers with "(999) 999-9999" format
            ppi_formFieldToValidate.value = "(" + ppi_formFieldToValidate.value.substring(0,3) + ") " + ppi_formFieldToValidate.value.substring(3,6) + "-" + ppi_formFieldToValidate.value.substring(6,10)
        }
        return true
 }


//**********************************************************************************************
function validateFormZip( ppi_formFieldToValidate ){

      //if ((ppi_formFieldToValidate.value==null)||(ppi_formFieldToValidate.value=="")){
      //        alert("Please Enter your Zip Code")
      //        ppi_formFieldToValidate.focus()
      //        return false
      //}
        if (checkFieldRegExpString( ppi_formFieldToValidate, "zip" )==false) {
                ppi_formFieldToValidate.focus()
                return false
        }
        return true
 }


//**********************************************************************************************
function validateFormTime( ppi_formFieldToValidate ){

      //if ((ppi_formFieldToValidate.value==null)||(ppi_formFieldToValidate.value=="")){
      //        alert("Please Enter the time")
      //        ppi_formFieldToValidate.focus()
      //        return false
      //}

        //Trim all spaces from the ends of the value in case user entered just spaces
        ppi_formFieldToValidate.value = trimAll(ppi_formFieldToValidate.value.toUpperCase());

        if (checkFieldRegExpString( ppi_formFieldToValidate, "time" )==false) {
                ppi_formFieldToValidate.focus()
                return false
        }


        return true
 }

//**********************************************************************************************
//* ppi_formFieldToValidate - Pointer to the form field to validate
function validateFormInteger( ppi_formFieldToValidate ){

        //Trim all spaces from the ends of the value in case user entered just spaces
        ppi_formFieldToValidate.value = trimAll(ppi_formFieldToValidate.value.toUpperCase());

        //* Strip all non-numeric characters from the string
        ppi_formFieldToValidate.value = stripCharsInBag( ppi_formFieldToValidate.value, ", ()")

        if (checkFieldRegExpString( ppi_formFieldToValidate, "integer" )==false) {
                ppi_formFieldToValidate.focus()
                return false
        }

        //* Strip out any decimal fragments if a value was provided
        if (ppi_formFieldToValidate.value.length>0)
            ppi_formFieldToValidate.value = parseInt(ppi_formFieldToValidate.value);

        return true
 }

//**********************************************************************************************
//* ppi_formFieldToValidate - Pointer to the form field to validate
//* pii_lowRange            - Low end number to validate number is equal to or greater
//* pii_hiRange             - high end number to validate number is equal to or less

function validateFormNbrRange( ppi_formFieldToValidate, pii_lowRange, pii_hiRange ){

        //Trim all spaces from the ends of the value in case user entered just spaces
        ppi_formFieldToValidate.value = trimAll(ppi_formFieldToValidate.value.toUpperCase());

        //* Strip all non-numeric characters from the string
        ppi_formFieldToValidate.value = stripCharsInBag( ppi_formFieldToValidate.value, ", ()")

        if (checkFieldRegExpString( ppi_formFieldToValidate, "nbrrange", pii_lowRange+"|"+pii_hiRange )==false) {
                ppi_formFieldToValidate.focus()
                return false
        }

        return true
 }

//**********************************************************************************************
function validateFormDecimal( ppi_formFieldToValidate ){

        //Trim all spaces from the ends of the value in case user entered just spaces
        ppi_formFieldToValidate.value = trimAll(ppi_formFieldToValidate.value.toUpperCase());

        //* Strip all non-numeric characters from the string
        ppi_formFieldToValidate.value = stripCharsInBag( ppi_formFieldToValidate.value, ", ()")
//alert(ppi_formFieldToValidate.value.indexOf('.'));
        if (checkFieldRegExpString( ppi_formFieldToValidate, "decimal" )==false) {
                ppi_formFieldToValidate.focus()
                return false
        }

        //* If there isn't a decimal point in the field, then reformat it with a decimal point.
        if ( ppi_formFieldToValidate.value.indexOf('.') == -1 ) {
            ppi_formFieldToValidate.value = ppi_formFieldToValidate.value + '.00'
        }

        return true
 }

//**********************************************************************************************
function validateFormMandatory( ppi_formFieldToValidate ){
        if ( ppi_formFieldToValidate.type=="checkbox" ) {
            if (!ppi_formFieldToValidate.checked) {
                    setFormFieldError( ppi_formFieldToValidate, "Field is mandatory")
                    ppi_formFieldToValidate.focus()
                    return false
            }
        }
        //If the type is a drop down, then make sure they didn't select "0", which equals "none", as the value
        else if ( ppi_formFieldToValidate.type=="select-one" ) {
//alert("type=" + ppi_formFieldToValidate.type + "/" + ppi_formFieldToValidate.value);
            if (ppi_formFieldToValidate.value==0) {
                    setFormFieldError( ppi_formFieldToValidate, "Field is mandatory")
                    ppi_formFieldToValidate.focus()
                    return false
            }
        }
        else
        {
            //Trim all spaces from the ends of the value in case user entered just spaces
//alert("type=" + ppi_formFieldToValidate.type);
            ppi_formFieldToValidate.value = trimAll(ppi_formFieldToValidate.value);
            if (ppi_formFieldToValidate.value.length==0) {
                    setFormFieldError( ppi_formFieldToValidate, "Field is mandatory")
                    ppi_formFieldToValidate.focus()
                    return false
            }
        }

        setFormFieldError( ppi_formFieldToValidate, "");

        return true
 }

//**********************************************************************************************
function validateFormLength( ppi_formFieldToValidate, pci_formFieldLengthMinMax ){

var ppi_formFieldToValidate = ppi_formFieldToValidate

var li_minLength = pci_formFieldLengthMinMax.substring(1,2)*1
var li_maxLength = pci_formFieldLengthMinMax.substring(2,3)*1
var lc_errMsg    = "Field Length must be <br>between " + li_minLength + " and " + li_maxLength + " characters"

        //Trim all spaces from the ends of the value in case user entered just spaces
        ppi_formFieldToValidate.value = trimAll(ppi_formFieldToValidate.value);

//alert(ppi_formFieldToValidate.value.length);
        if ( ( ppi_formFieldToValidate.value.length >= li_minLength) && ( ppi_formFieldToValidate.value.length <= li_maxLength))
        {
//alert('success' + ppi_formFieldToValidate.value.length + ":" + li_minLength + ":" + li_maxLength )

            setFormFieldError( ppi_formFieldToValidate )
            return true
        }
        else
        {

//alert('failure' + ppi_formFieldToValidate.value.length + ":" + li_minLength + ":" + li_maxLength )
            setFormFieldError( ppi_formFieldToValidate, lc_errMsg )
            return false
        }
 }


//**********************************************************************************************
//* FUNCTION: Look at each form input field and determine if it has been defined as a required field or
//* has a specific edit associated with it like EMAIL, Phone, Zip, etc.  If it is required or has a specific
//* edit, then validate the contents and flag if in error.
//* ppi_fieldToSetToError: a pointer to the error division that contains the error text. This will be either set visible or invisible.

//* The intention is that any screen with a form should have a function called "processFieldEdits" with localized form edits and will call
//* this function for all global required and formatting errors and then display the error text returned to the user.

//* RETURNS: For any errors found, the generated error text will be returned which should be displayed to the user to explain the errors.
//*          If there are no errors, it will return an empty string.
//**********************************************************************************************
//* example: processRequiredFormattingFieldEdits()
//**********************************************************************************************
function processRequiredFormattingFieldEdits()
{
var lb_noErrorFound = false
var li_i, li_j, li_errorCountReq=0, li_errorCountFormat=0
var lc_errorText = ""
var lp_errorField
var li_fieldErrorLevel


        //*****************************************************************
        // Go through each row and each field in the row
        //*****************************************************************
        li_errorCountReq    = 0;
        li_errorCountFormat = 0;
        for ( li_j=1; li_j <= getObject('CountSQLRows').value ; li_j++ )
        {
            // For each column in the row
            for ( li_i=1; li_i <= getObject('rowColumnsR' + li_j ).value; li_i++ )
            {

                 lp_errorField = getObject( 'fieldreqR' + li_j + '_' + li_i )
//alert( li_j +'/' + li_i +':'+lp_errorField.value);

                 li_fieldErrorLevel = 0

                 if ( lp_errorField )  // If field exists
                     //*****************************************************************
                     // If field in row is required, set to error.
                     //*****************************************************************
                     if ( getObject( 'fieldreqR' + li_j + '_' + li_i ).value == 'True' )
                     {
//alert(getObject( 'fieldnameR' + li_j + '_' + li_i ).value + "/" + getObject( 'fieldreqR' + li_j + '_' + li_i ).value + "/" + getObject( 'fieldvalueR' + li_j + '_' + li_i ).value);

                         //* If field type is 202 and not a drop down, it is a text field and we need to validate field length to determine if user has provided a value
                         //* If field type is 202      and a dropdown, we need to validate 'value'      to determine if user has selected a value
                         //* If field type is  11,   it is a checkbox, we need to validate 'checked'    to determine if user has provided a value
                         if  (!validateFormMandatory( getObject( 'fieldvalueR' + li_j + '_' + li_i )))
                         {
//alert( getObject( 'fieldnameR' + li_j + '_' + li_i).value + ': is required');
                             li_errorCountReq++;
                             li_fieldErrorLevel = 10;
                         }
                         else
                         {
                             li_fieldErrorLevel = 1;
                         }

                     }
//alert( li_fieldErrorLevel  )
                     //*****************************************************************
                     // If there was no error earlier, and the edit for the field is NOT 'none', refire the edit
                     //*****************************************************************

//if (li_j==2) alert( 'fieldeditR' + li_j + '_' + li_i + '=' + getObject( 'fieldeditR' + li_j + '_' + li_i ).value);

                     if ( ( li_fieldErrorLevel <10 ) && ( getObject( 'fieldeditR' + li_j + '_' + li_i ).value != 'NONE' ) )
                     {

                         lp_fieldPtr = getObject( 'fieldvalueR' + li_j + '_' + li_i )
//alert("lp_fieldPtr=" + lp_fieldPtr.name );
                         switch ( getObject( 'fieldeditR' + li_j + '_' + li_i ).value )
                         {
                             case 'EMAIL':
                                 {
                                     if (!validateFormEmail( lp_fieldPtr ))
                                     {
                                       li_fieldErrorLevel = 10;
                                       li_errorCountFormat++;
                                     }
                                     break;
                                 }
                             case 'PHONE':
                                 {
                                     if (!validateFormPhone( lp_fieldPtr ))
                                     {
                                       li_fieldErrorLevel = 10;
                                       li_errorCountFormat++;
                                     }
                                     break;
                                 }
                             case 'ZIP':
                                 {
                                     if (!validateFormZip( lp_fieldPtr ))
                                     {
                                       li_fieldErrorLevel = 10;
                                       li_errorCountFormat++;
                                     }
                                     break;
                                 }
                             case 'TIME':
                                 {
                                     if (!validateFormTime( lp_fieldPtr ))
                                     {
                                       li_fieldErrorLevel = 10;
                                       li_errorCountFormat++;
                                     }
                                     break;
                                 }
                             case 'DATE':
                                 {
                                     if (!validateFormDate( lp_fieldPtr ))
                                     {
                                       li_fieldErrorLevel = 10;
                                       li_errorCountFormat++;
                                     }
                                     break;
                                 }
                             case 'INTEGER':
                                 {
                                     if (!validateFormInteger( lp_fieldPtr ))
                                     {
                                       li_fieldErrorLevel = 10;
                                       li_errorCountFormat++;
                                     }
                                     break;
                                 }
                             case 'DECIMAL':
                                 {
                                     if (!validateFormDecimal( lp_fieldPtr ))
                                     {
                                       li_fieldErrorLevel = 10;
                                       li_errorCountFormat++;
                                     }
                                     break;
                                 }
                             case 'LENGTH12':
                                 {
                                     if (!validateFormLength( lp_fieldPtr, ' 12 ' ))
                                     {
                                       li_fieldErrorLevel = 10;
                                       li_errorCountFormat++;
                                     }
                                     break;
                                 }
                             case 'LENGTH39':
                                 {
                                     if (!validateFormLength( lp_fieldPtr, ' 39 ' ))
                                     {
                                       li_fieldErrorLevel = 10;
                                       li_errorCountFormat++;
                                     }
                                     break;
                                 }
                  ////       case 'CUSTOM':
                  ////           {
                  ////               // This doesn't work currently. Need to figure out how to call the javascript
                  ////               // associated with the field rather than recreating all the individual calls above
                  ////
alert( "lp_fieldPtr.name=" + lp_fieldPtr.name )
                  ////               //validateFormEmail( lp_fieldPtr );
                  ////               break;
                  ////           }
                             default:
                                 {
                                     break;
                                 }
                         }
                     }

               if ( li_fieldErrorLevel == 1 )
                   setFormFieldError( getObject( 'fieldvalueR' + li_j + '_' + li_i), '' );
            }

        }
        if (li_errorCountReq    > 0 ) lc_errorText += '\n\r - There are ' + li_errorCountReq    + ' mandatory field(s) requiring completion';
        if (li_errorCountFormat > 0 ) lc_errorText += '\n\r - There are ' + li_errorCountFormat + ' field(s) with format errors';
        //*****************************************************************


    //* expectation is that the function that calls this function will display the error text returned from here.
    return lc_errorText

}


