/***************************************************************************************************
*
*-- Form validation script 
*******************************************************************************************************
*--        Constants and Globals
*                Global used for flagging the validateBlank() function within most other validation functions
*/                var blankOK = false;
/*                Global used for class switching.  Do not modify
*/                var revertClass = '';
/*                Change this to the classname you want for the error highlighting
*/                var errorClass = 'errHilite';
/*                If the bConfirm flag is set to true, the users will be prompted with CONFIRM box with this message
*/                var confirmMsg = 'Vos coordonnes sont prtes  tre envoyes.\nSVP cliquez sur \'Ok\' pour valider ou \'Cancel\' pour annuler.';
/*                If user cancels CONFIRM, then this message will be alerted.  If you don't want this alert to show, then
*                empty the variable (  var confirmAbortMsg = '';  )
*/                var confirmAbortMsg = 'Soumission annule.  Donnes non enregistres.';
/*
*********** WARNING: DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING! ****************/

function validateForm(Frm, bConfirm, bDisable)
        {
        var testOk;
        for (var i=0; i<Frm.elements.length; i++)                                                // Loops through all the form's elements
                {
                if (Frm.elements[i].alt)                                                                        // Gets the ALT text if it exists, starting the validation
                        {
                        var validateType = Frm.elements[i].alt;
                        var validateObj = Frm.elements[i];
                        testOk = false;
                        var params = validateType.split(/[|]/);                                        // Separates validation string into parameters

                        if (params[0] == 'money')                                                                // Sets flags for money syntax
                                {
                                var dollarsign        = (params[1].indexOf('$') != -1);
                                var grouping        = (params[1].indexOf(',') != -1);
                                var decimal                = (params[1].indexOf('.') != -1);
                                }

                        if (params[params.length-1] == 'bok')                                        // Sets flag if field is allowed to be blank
                                blankOK = true;

                        switch (params[0])                                                                                // Calls appropriate validation function based on type
                                {
                                case 'blank'        : if (validateBlank(validateObj)) testOk = true; break;
                                case 'number'        : if (validateNumber(validateObj)) testOk = true; break;
                                case 'numberl'        : if (validateNumberL(validateObj, params[1])) testOk = true; break;
                                case 'email'        : if (validateEmail(validateObj)) testOk = true; break;
                                case 'cc'                : if (validateCC(validateObj)) testOk = true; break;
                                case 'selecti'        : if (validateSelectI(validateObj, params[1])) testOk = true; break;
                                // Add additional cases here
                                default                        : alert('Validation Type Not Found');
                                }
                        if (!testOk) return false;
                        }
                }
        if (typeof bConfirm == 'undefined') bConfirm = 0;                                // Checks for submission flags
        if (typeof bDisable == 'undefined') bDisable = 0;
        if (bConfirm)
                {
                if(!confirm(confirmMsg))
                        {
                        if (confirmAbortMsg != '') alert(confirmAbortMsg);                // Displays confim if requested
                        return false;
                        }
                }
        if (bDisable) Frm.Submit.disabled=true;                                                        // Disables submit if requested
        return true;                                                                                                        // Form has been validated
        }

/***************************************************************************/
function validateBlank(formObj)
        {
        var objName = formatName(formObj.name);
        if (formObj.value == "")
                {
                alert('SVP remplissez le champ '+objName);
                errorProcess(formObj,0,1);
                return false;
                }
        return true;
        }


/***************************************************************************/
function validateEmail(formObj)
        {
        if (blankOK)
                { blankOK=false; return true; }
        else if (!validateBlank(formObj))
                return false;

        var emailStr = formObj.value;
        var emailReg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
        var emailReg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid
        if (!emailReg1.test(emailStr) && emailReg2.test(emailStr)) // if syntax is valid
                {
                return true;
                }
        else
                {
                window.alert("SVP, entrez une adresse e-mail valide.");
                errorProcess(formObj,1,1);
                return false;
                }
        return true;
        }

/***************************************************************************/
function formatName(wStr)
        {
        wStr = wStr.replace(/_/g," ");
        return wStr;
        }
/***************************************************************************/
function errorProcess(tempObj, sel, foc)
        {
        revertClass = tempObj.className;
        tempObj.className = errorClass;
        if (sel) tempObj.select();
        if (foc) tempObj.focus();
        }
/***************************************************************************/
function clearStyle(tempObj)
        {
        if (tempObj.className == errorClass) tempObj.className = revertClass;
        }



