﻿// JScript File
var p_origValidate;
// on load event


window.onload = function()
{    
    // save & replace client validation
    if (typeof(Page_ClientValidate) == 'function')
    {
        p_origValidate=Page_ClientValidate;
        Page_ClientValidate=validateForm;
    }
}

// This function steps through all validators of a page and displays an alert
// if a validator is not valid
function validateForm(validationGroup)
{

    // call validator
    p_origValidate(validationGroup);
    
    var validators = new Array();
    validators = Page_Validators;
    var validatorText = new Object();
    var control = new String;
    var error = new Boolean;
   
    error = false;
   
    //current control evaluated
    control = document.getElementById(validators[0].controltovalidate).id;
    for (i = 0; i < validators.length; i++)
    {
        if (!validators[i].isvalid)
        {
            validatorText[validators[i].controltovalidate] = validators[i].errormessage;
            var element = document.getElementById(validators[i].controltovalidate);
            element.style.backgroundColor = '#FFBBAA';
            
            element.title = validatorText[validators[i].controltovalidate];
            
            // TODO: get this to work so ToolTip does not always show last element
/*            element.onmouseover = function()
            {
                Tip(validatorText);
            }
*/          
            //element.setAttribute("onmouseover", "Tip('" + validatorText + "');");
            
            
            error = true;
           
        }
        else if (validators[i].isvalid)
        {
            element = document.getElementById(validators[i].controltovalidate);    
            if (element != null && (i == 0 || control != element.id))
            {
                element.style.backgroundColor = 'white';
                if (validatorText[validators[i].controltovalidate] != null)
                    element.title = validatorText[validators[i].controltovalidate];
                else
                    element.title = "";
            }
            
            /*element.onmouseover = function(evt)
            {
                tt_Hide();
            }*/
            
        }
      
        if(element != null)
        control = document.getElementById(validators[i].controltovalidate).id;
    }
    
    //Display error messages
    if (error)
    {
        return false;
    }
   
    return true;
}
