function ValidateBox(control)
{
//alert('ValidateBox: Start');
    try
    {
        //------------------------------------------------------
        //Get the Custom Properties from the COntrol
        //------------------------------------------------------
        var tmpType = 'obj' + control + '.Type';
        var Type = eval(tmpType);
        
        var tmpHidden = 'obj' + control + '.Hidden';
        var Hidden = eval(tmpHidden);
        
        var tmpInputMask = 'obj' + control + '.InputMask';
        var InputMask = eval(tmpInputMask);

        var tmpInputMaskLength = 'obj' + control + '.InputMaskLength';
        var InputMaskLength = eval(tmpInputMaskLength);
        
        var tmpMaxLength = 'obj' + control + '.MaxLength';
        var MaxLength = eval(tmpMaxLength);

        var tmpMaxLengthMessage = 'obj' + control + '.MaxLengthMessage';
        var MaxLengthMessage = eval(tmpMaxLengthMessage);
       
        var tmpRequired = 'obj' + control + '.Required';
        var Required = eval(tmpRequired);
        
        var tmpAutoPostBack = 'obj' + control + '.AutoPostBack';
        var AutoPostBack = eval(tmpAutoPostBack);

        var tmpBGInfoColor = 'obj' + control + '.BGInfoColor';
        var BGInfoColor = eval(tmpBGInfoColor);
        
        var tmpNextControlToFocus = 'obj' + control + '.NextControlToFocus';
        var NextControlToFocus = eval(tmpNextControlToFocus);
        
        var tmpInvalidMessage = 'obj' + control + '.InvalidMessage';
        var InvalidMessage = eval(tmpInvalidMessage);
        //------------------------------------------------------
        //------------------------------------------------------

        var o = document.getElementById(control);
        if (o != null)
        {
            var MainDiv = document.getElementById(control + 'MainDiv');
            
            //Mask Input requires an object reference for the control
            if(InputMaskLength > 0 && InputMask != '')
            {
                try
                {
                    ValidatorBoxMaskInput(control);
                }
                catch(er)
                {
                    alert('ValidateBox: Call: ValidatorBoxMaskInput: ' + er.message); 
                }
                 try
                {
                    ValidatorBoxCheckMask(control);  
                }
                catch(er)
                {
                    alert('ValidateBox: Call: ValidatorBoxCheckMask: ' + er.message);                
                }
            }
            if(Required == 'True')
            {
                ValidatorBoxCheckRequired(control);
            }
                        
            var MaxDiv = document.getElementById(control + 'MaxDiv');
            if(MaxDiv != null)
            {
                ValidatorBoxCheckMaxChars(control);    
                
                if(InputMask != null)
                {
                    ValidatorBoxCheckMask(control)
                }
            }
            
            if (MainDiv != null)
            {
                if (InvalidMessage != null )
                    {
                        //We have an InvalidMessage: Show Div
                        MainDiv.style.backgroundColor=BGInfoColor;
                        MainDiv.style.border='solid 1px #000';        
                    }
            }
            else
            {
                alert('The object "' + control + '" Is null');
            }
            
         }            
        else
        {
            alert('ValidateBox: ' + control + ': is null');
        }
    }
    catch(err)
    {
        alert('ValidateBox: err: ' + err.description);
        throw err;
    } 
}

function InvalidateBox(control)
{
    try
    {
        //------------------------------------------------------
        //------------------------------------------------------
        var tmpBGInfoColor = 'obj' + control + '.BGInfoColor';
        var BGInfoColor = eval(tmpBGInfoColor);
        var o = document.getElementById(control);
        if (o != null)
        {
            var MainDiv = document.getElementById(control + 'MainDiv');
            if (MainDiv != null)
            {
                //Reset some of the Styles
                MainDiv.style.backgroundColor=BGInfoColor;
                MainDiv.style.border='solid 1px #000';
            }
            else
            {
                alert('InvalidateBox: The object "' + control + 'MainDiv" Is null');
            }
         }            
        else
        {
            alert('InvalidateBox: ' + control + ': is null');
        }
    }
    catch(err)
    {
        alert('InvalidateBox: err: ' + err.description);
        throw err;
    } 
}

function CheckForMaskClear(control)
{
//alert('CheckForMaskClear: Start');
    var c = document.getElementById(control);
    var tmpMaxLength = 'obj' + control + '.MaxLength';
    var MaxLength = eval(tmpMaxLength);
    //alert('CheckForMaskClear: eval(MaxLength)=' + MaxLength);
    //var tmpInputMaskLength = 'obj' + control + '.InputMaskLength';
    //var InputMaskLength = eval(tmpInputMaskLength);

    if(MaxLength == 0)//No MaxLength
    {
        //alert('CheckForMaskClear: MaxLength =0');
        //Do not Clear: Allow as many chars as they want
    }
    else
    {
        //Check to see if the Value.,Length >= MaxChars
        //alert('CheckForMaskClear2: MaxLength=' + MaxLength);

        if(c.value.length >= MaxLength)
        {
            c.value='';
        }
    }
    
}

function ValidatorBoxRegisterOnKeyUpHandler(control)
{
try
{
    //------------------------------------------------------
    //Get the Custom Properties from the COntrol
    //------------------------------------------------------
    //NextControlToFocus
    var tmpType = 'obj' + control + '.Type';
    var Type = eval(tmpType);

    var tmpHidden = 'obj' + control + '.Hidden';
    var Hidden = eval(tmpHidden);

    var tmpInputMask = 'obj' + control + '.InputMask';
    var InputMask = eval(tmpInputMask);

    var tmpInputMaskLength = 'obj' + control + '.InputMaskLength';
    var InputMaskLength = eval(tmpInputMaskLength);

    var tmpMaxLength = 'obj' + control + '.MaxLength';
    var MaxLength = eval(tmpMaxLength);

    var tmpMaxLengthMessage = 'obj' + control + '.MaxLengthMessage';
    var MaxLengthMessage = eval(tmpMaxLengthMessage);

    var tmpRequired = 'obj' + control + '.Required';
    var Required = eval(tmpRequired);
      
    var tmpAutoPostBack = 'obj' + control + '.AutoPostBack';
    var AutoPostBack = eval(tmpAutoPostBack);

    var tmpBGInfoColor = 'obj' + control + '.BGInfoColor';
    var BGInfoColor = eval(tmpBGInfoColor);

    var tmpNextControlToFocus = 'obj' + control + '.NextControlToFocus';
    var NextControlToFocus = eval(tmpNextControlToFocus);
    //------------------------------------------------------
    //------------------------------------------------------

    var c = document.getElementById(control);
    if (c != null)
    {
        var OnKeyUp = '';
        var OnKeyDown = '';
        
        OnKeyUp = OnKeyUp + "ValidateBox('" + control + "');";
      
            
        //Add the Event Handler       
        c.onkeyup = function() {eval(OnKeyUp);};
        //c.onkeydown = function() {eval(OnKeyUp);};
     }
    else
    {
        alert('ValidatorBoxRegisterOnKeyUpHandler:  ' + control + ' Is null');
    }
}
catch(err)
{
    alert('ValidatorBoxRegisterOnKeyUpHandler: err: ' + err.description);
    throw err;
}
}

function ValidatorBoxCheckMaxChars(control)
{
//alert('ValidatorBoxCheckMaxChars: Start');
try
{
    var tmpMaxLength = 'obj' + control + '.MaxLength';
    var MaxLength = eval(tmpMaxLength);

    var tmpMaxLengthMessage = 'obj' + control + '.MaxLengthMessage';
    var MaxLengthMessage = eval(tmpMaxLengthMessage);
    
    var tmpHideMessage = 'obj' + control + '.HideMessage';
    var HideMessage = eval(tmpHideMessage);

    
//obj.innerHTML
    var obj = document.getElementById(control);
    var MaskDiv = document.getElementById(control + "InputMaskDiv");
    var MaxDiv = document.getElementById(control + "MaxDiv");
    
    if(MaxLength > 0)
    {
        if (obj != null)
        {
            //---------------------------------------
            //Show the Divs
            //---------------------------------------
            if (MaxDiv != null)
            {
                MaxDiv.style.display='';
            }
            if (MaskDiv != null)
            {
                MaskDiv.style.display='';
            }
            //---------------------------------------
            
            if ( obj.type == "textarea" )
            {
                if (document.all)
                {
                    //Use IE
                    if (obj.innerText.length > MaxLength)
                    {
                        if (MaxDiv != null)
                        {
                            if (HideMessage == "True")
                            {
                                MaxDiv.innerHTML = '';
                            }
                            else
                            {
                                MaxDiv.innerHTML = MaxLengthMessage + '0';
                            }
                            MaxDiv.style.display='none';
                                                    }
                        if (MaskDiv != null)
                        {
                            //Hide the Div 
                            MaskDiv.style.display='none';
                        }
                        obj.innerText = obj.innerText.substring(0,MaxLength);
                    }
                    else if(obj.innerText.length == MaxLength)
                    {
                        if (MaxDiv != null)
                        {
                            if (HideMessage == "True")
                            {
                                MaxDiv.innerHTML = '';
                            }
                            else
                            {
                                MaxDiv.innerHTML = MaxLengthMessage + '0';
                            }
                            //MaxDiv.innerHTML = MaxLengthMessage + '0';
                            MaxDiv.style.display='none';
                        }
                        if (MaskDiv != null)
                        {
                            //Hide the Div 
                            MaskDiv.style.display='none';
                        }
                    }
                    else
                    {
                        var charsLeft = MaxLength - obj.innerText.length;
                        if (MaxDiv != null)
                        {
                            if (HideMessage == "True")
                            {
                                MaxDiv.innerHTML = '';
                            }
                            else
                            {
                                MaxDiv.innerHTML = MaxLengthMessage + charsLeft;
                            }
                            
                            MaxDiv.style.display='';
                        }
                        if (MaskDiv != null)
                        {
                            //Show the Div 
                            MaskDiv.style.display='';
                        }
                    }
                }
                else
                {
                    //Use FF
                    if (obj.value.length > MaxLength)
                    {
                        if (MaxDiv != null)
                        {
                            if (HideMessage == "True")
                            {
                                MaxDiv.innerHTML = '';
                            }
                            else
                            {
                                MaxDiv.innerHTML = MaxLengthMessage + '0';
                            }
                            MaxDiv.style.display='none';
                        }
                        if (MaskDiv != null)
                        {
                            //Hide the Div 
                            MaskDiv.style.display='none';
                        }
                        obj.value = obj.value.substring(0,MaxLength);
                    }
                    else if(obj.value.length == MaxLength)
                    {
                        if (MaxDiv != null)
                        {
                            if (HideMessage == "True")
                            {
                                MaxDiv.innerHTML = '';
                            }
                            else
                            {
                                MaxDiv.innerHTML = MaxLengthMessage + '0';
                            }
                            MaxDiv.style.display='none';
                        }
                        if (MaskDiv != null)
                        {
                            //Hide the Div 
                            MaskDiv.style.display='none';
                        }
                    }
                    else
                    {
                        var ContentLen = obj.value.length;
                        var charsLeft = MaxLength - ContentLen;
                        if (MaxDiv != null)
                        {
                            if (HideMessage == "True")
                            {
                                MaxDiv.innerHTML = '';
                            }
                            else
                            {
                                MaxDiv.innerHTML = MaxLengthMessage + charsLeft;
                            }
                            MaxDiv.style.display='';
                        }
                        if (MaskDiv != null)
                        {
                            //Show the Div 
                            MaskDiv.style.display='';
                        }
                    }
                }
            }
            else if (obj.type == "text")
            {
                if (obj.value.length > 0 && obj.value.length > MaxLength)
                {
                    if (MaxDiv != null)
                    {
                        if (HideMessage == "True")
                        {
                            MaxDiv.innerHTML = '';
                        }
                        else
                        {
                            MaxDiv.innerHTML = MaxLengthMessage + '0';
                        }
                        MaxDiv.style.display='none';
                    }
                    if (MaskDiv != null)
                    {
                        //Hide the Div 
                        MaskDiv.style.display='none';
                    }
                    //obj.value = document.all(control).value.substring(0,MaxLength);
                }
                else if (obj.value.length == MaxLength)
                {
                    if (MaxDiv != null)
                    {
                        if (HideMessage == "True")
                        {
                            MaxDiv.innerHTML = '';
                        }
                        else
                        {
                            MaxDiv.innerHTML = MaxLengthMessage + '0';
                        }
                    
                        //MaxDiv.innerHTML = MaxLengthMessage + '0';
                        MaxDiv.style.display='none';
                    }
                    if (MaskDiv != null)
                        {
                            //Hide the Div 
                            MaskDiv.style.display='none';
                        }
                }
                else
                {
                    var charsLeft = MaxLength - obj.value.length;
                    if (MaxDiv != null)
                    {
                        MaxDiv.style.display='';
                        if(charsLeft==0)
                        {
                            if (HideMessage == "True")
                            {
                                MaxDiv.innerHTML = '';
                            }
                            else
                            {
                                MaxDiv.innerHTML = MaxLength;
                            }
                        }
                        else
                        {
                            if (HideMessage == "True")
                            {
                                MaxDiv.innerHTML = '';
                            }
                            else
                            {
                                MaxDiv.innerHTML = MaxLengthMessage + charsLeft;
                            }
                        }
                    }
                    if (MaskDiv != null)
                    {
                        //Hide the Div 
                        MaskDiv.style.display='';
                    }
                }
            }
            else
            {
                //Do nothing
            }
        }

    }
}
catch(err)
{
    alert('ValidatorBoxCheckMaxChars: err: ' + err.description);
    throw err;
}
}

function ValidatorBoxCheckMask(control)
{
try
{
    var tmpMaxLength = 'obj' + control + '.MaxLength';
    var MaxLength = eval(tmpMaxLength);

    var tmpMaxLengthMessage = 'obj' + control + '.MaxLengthMessage';
    var MaxLengthMessage = eval(tmpMaxLengthMessage);

    var obj = document.getElementById(control);
    var MaskDiv = document.getElementById(control + "InputMaskDiv");
    var MainDiv = document.getElementById(control + 'MainDiv');
    
    var tmpInvalidMessage = 'obj' + control + '.InvalidMessage';
    var InvalidMessage = eval(tmpInvalidMessage);
    
    var tmpInputMaskLength = 'obj' + control + '.InputMaskLength';
    var InputMaskLength = eval(tmpInputMaskLength);
    
    var rv;
            
    if(MaxLength > 0)
    {
        if (obj != null)
        {
            if ( obj.type == "textarea" )
            {
                if (document.all)
                {
                    //Use IE
                    if (obj.innerText.length > MaxLength)
                    {
                        //alert('ValidateBox: textarea: IE: text len > MaxLen');
                    }
                    else if(obj.innerText.length == MaxLength)
                    {
                        if (MaskDiv != null)
                        {
                            //Hide the Div 
                            MaskDiv.style.display='none';
                        }
                        
                        if ((MainDiv != null) && (InvalidMessage == null || obj.innerText.length == InputMaskLength))
                        {
                            //Reset the Main Div
                            //MainDiv.style.backgroundColor='transparent';
                            //MainDiv.style.border='solid 0px #000';
                        }
                    }
                    else
                    {
                        var charsLeft = MaxLength - obj.innerText.length;
                        if (MaskDiv != null)
                        {
                            //Show the Div 
                            MaskDiv.style.display='';
                        }
                    }
                    
                }
                else
                {
                    //Use FF
                    if (obj.value.length > MaxLength)
                    {
                        //alert('ValidateBox: textarea: FF: text len > MaxLen');
                    }
                    else if(obj.value.length == MaxLength)
                    {
                        if (MaskDiv != null)
                        {
                            //Hide the Div 
                            MaskDiv.style.display='none';
                        }
                        
                        if ((MainDiv != null) && (InvalidMessage == null || obj.value.length == InputMaskLength))
                        {
                            //Reset the Main Div
                            //MainDiv.style.backgroundColor='transparent';
                            //MainDiv.style.border='solid 0px #000';
                        }
                    }
                    else
                    {
                        var ContentLen = obj.value.length;
                        var charsLeft = MaxLength - ContentLen;
                        if (MaskDiv != null)
                        {
                            //Show the Div 
                            MaskDiv.style.display='';
                        }
                    }
                }
            }
            else if (obj.type = "text")
            {
                if (obj.value.length > MaxLength)
                {
                    //alert('ValidateBox: text: len > MaxLen');
                }
                else if (obj.value.length == MaxLength)
                {
                    if (MaskDiv != null)
                    {
                        //Hide the Div 
                        MaskDiv.style.display='none';
                    }
                    
                    if ((MainDiv != null) && (InvalidMessage == null || obj.value.length == InputMaskLength))
                    {
                        //Reset the Main Div
                        //MainDiv.style.backgroundColor='transparent';
                        //MainDiv.style.border='solid 0px #000';
                    }
                }
                else
                {
                    if (MaskDiv != null)
                    {
                    //Show the Div 
                    MaskDiv.style.display='';
                    }
                }
            }
            else
            {
                if (MaskDiv != null)
                {
                    //Show the Div 
                    MaskDiv.style.display='';
                }
            }
        }

    }
}
catch(err)
{
    alert('ValidatorBoxCheckMask: ' + err.description);
    throw err;
}
}

function ValidatorBoxCheckRequired(control)
{
//alert('ValidatorBoxCheckRequired: Start');
try
{
    var tmpRequired = 'obj' + control + '.Required';
    var Required = eval(tmpRequired);

    var tmpBGInfoColor = 'obj' + control + '.BGInfoColor';
    var BGInfoColor = eval(tmpBGInfoColor);

    var tmpCaption = 'obj' + control + '.Caption';
    var Caption = eval(tmpCaption);

    var o = document.getElementById(control);
    var CaptionDiv = document.getElementById(control + "CaptionDiv");
    var MainDiv = document.getElementById(control + 'MainDiv');
    var RequiredDiv = document.getElementById(control + 'RequiredDiv');
    
    var tmpInvalidMessage = 'obj' + control + '.InvalidMessage';
    var InvalidMessage = eval(tmpInvalidMessage);
    
    var tmpInputMaskLength = 'obj' + control + '.InputMaskLength';
    var InputMaskLength = eval(tmpInputMaskLength);
       
    if (Required == 'True')
    {
        //Only Check if it is Required
        if (o != null)
        {
            //See if there is any data
            if (o.value.length > 0)
            {
                //Reset the MainDiv to Normal
                if (MainDiv != null)
                {
                    MainDiv.style.backgroundColor='transparent';
                    MainDiv.style.border='solid 0px #000';    
                }

                if (RequiredDiv != null)
                {
                    RequiredDiv.style.display='none';
                }
                
                //Reset the Caption Text
                if (CaptionDiv != null)
                {
                    CaptionDiv.innerHTML=Caption;
                }
            }
            else
            {
                //Reset the MainDiv to Info
                if (MainDiv != null)
                {
                    MainDiv.style.backgroundColor=BGInfoColor;
                    MainDiv.style.border='solid 1px #000';    
                }
                
                if (RequiredDiv != null)
                {
                    RequiredDiv.style.display='';
                }
                
                //Update the Caption Text
                if (CaptionDiv != null)
                {
                    CaptionDiv.innerHTML=Caption; // + ' - Required';
                }
            }
        }
    }
    else
    {
        if (InvalidMessage == null || o.value.length == InputMaskLength)
        {
            //Reset the MainDiv to Normal
            if (MainDiv != null)
            {
                //MainDiv.style.backgroundColor='transparent';
                //MainDiv.style.border='solid 0px #000';    
            }

            if (RequiredDiv != null)
            {
                RequiredDiv.style.display='none';
            }
            
            //Reset the Caption Text
            if (CaptionDiv != null)
            {
                CaptionDiv.innerHTML=Caption;
            }
        }
        //Reset the MainDiv to Normal
        if (MainDiv != null)
        {
            //MainDiv.style.backgroundColor='transparent';
            //MainDiv.style.border='solid 0px #000';    
        }
    }
}
catch(err)
{
    alert('ValidatorBoxCheckRequired: ' + err.description);
    throw err;
}
}


function ValidatorBoxToggleHelp(control)
{
//alert('ValidatorBoxToggleHelp: Start');
    var o = document.getElementById(control);
    if (o != null)
    {
        if (o.style.display == 'none') 
        {
            o.style.display = '';
        }
        else
        {
            o.style.display = 'none';
        }
    }
}

function HideValidatorBoxMaxDiv(control)
{
    var MaxDiv = document.getElementById(control + 'MaxDiv');
    if (MaxDiv != null)
    {
        //Hide the Div 
        MaxDiv.style.display='none';
    }
}

// ======================================