/* ---------------------------------------------------------------------------------------------
 * File:        CapLib.js
 *
 * Author:      Alexandre Dallaire
 *
 * Copyright (c) - 2001, La Capitale Assurances Générales inc.
 *
 * History
 * ---------------------------------------------------------------------------------------------
 * Date         User                Description
 * ---------------------------------------------------------------------------------------------
 * 2001/04/30   Alexandre Dallaire  Creation.
 * 2001/05/01   Alexandre Dallaire  Few improvements.
 * 2001/05/04   Alexandre Dallaire  Added contextual help functions (openHelp() & closeLastHelp()).
 * 2001/05/10   Alexandre Dallaire  Added the parseQueryString() function.
 * 2001/05/17   Alexandre Dallaire  Added the getAgeFromDate(), escapeString() and
 *                                  unEscapeString() functions.
 * 2001/05/23   Alexandre Dallaire  Updated the isValidPhoneNumber() function.
 * 2001/08/14   Alexandre Dallaire  Added the isIE6() method.
 * 2001/09/25   Alexandre Dallaire  Added the hide() and show() methods.
 * 2001/10/12   Alexandre Dallaire  Updated the openPopup() with a new parameter (the popup's name).
 * 2003/01/09   Guy Pagé            Added isValidUSZipCode() function.
 * 2003/01/14   Alexandre Dallaire  Added the getElementArrayForTagName() method.
 * 2003/02/05   Guy Pagé            Added isAllCharInTable function.
 * 2003/03/14   Guy Pagé            Added status bar choice in openPopup() function.
 * 2003/05/01   Alexandre Dallaire  Added the useful createCurrency() method !  :O)
 * 2003/05/06   Alexandre Dallaire  Added the getSelectValue() method !		   
 * 2004/02/18   Nicolas Demers	    Added the isNS7() method.
 * 2005/03/14   Guy Pagé            Ajout estEntierPositif
 * 2005/??/??	Nicolas Demers		Added the replaceAll() method.
 * 2005/09/09   Nicolas Demers      Added the reduceToTable method.
 * 2005/??/??   Guy Pagé			Added the recupererObjet() method.
 * 2006/01/23	Nicolas Demers		Actualisation de tous les CapLib et regroupement par thématique
 *									des méthodes.
 * 2006/03/24	Nicolas Demers		Added the isValidContenuChamps() method.
 * 2006/03/24	Nicolas Demers		Added the replaceAllWithString() method.
 * ---------------------------------------------------------------------------------------------
 */
 
 /* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 +
 +  Apporte des modifications
 +		createCurrency( pNumString )
 +		escapeString( pString )
 +		parseQueryString()
 +		toCamelCase( pValueString )
 +		trim( pValueString )
 +		unEscapeString( pString )
 +		replaceAll( pChaine, pCarChange, pCarPar )
 +		replaceAllWithString( pChaine, pStringChange, pStringPar )
 +		reduceToTable( pValueString, pValidationString )
 +
 +  Autre
 +		dummy()
 +		hide( pId )
 +		jump( pSourceComponent, pAimedComponent, pSkipAfter )
 +		loadHelp( pHelpList, pHelpWidthList )
 +		recupererObjet( pId, pNewWindow )
 +		rotate( pImageChoices, pImageLinks )
 +		show( pId )
 +
 +  Fureteur
 +		closeLastHelp()
 +		getBrowserName()
 +		getComputerType()
 +		getFullBrowserVersion()
 +		getNewBrowserVersion()
 +		isIE()
 +		isIE4()
 +		isIE5()
 +		isIE6()
 +		isMac()
 +		isNS()
 +		isNS4()
 +		isNS5()
 +		isNS6()
 +		isNS7()
 +
 +  Gestion des fenêtres
 +		getAvailHeight()
 +		getAvailWidth()
 +		getBGColor()
 +		getFGColor()
 +		getWindowX()
 +		getWindowY()
 +		openHelp( pEvent, pHelpId, pHeight )
 +		openFormPopup( pURL, pWidth, pHeight, pGetHandle, pLeft, pTop, pPopupName, pScrollBar, pStatus, pResizable )
 +		openPopup( pURL, pWidth, pHeight, pGetHandle, pLeft, pTop, pPopupName, pScrollBar, pStatus, pResize )
 +		openWindow( pURL, pAttribs, pGetHandle, pAlias )
 +		paint( pHTMLComponent, pFGHexColor, pBGHexColor, pAttribs )
 +		undoLastPaint()
 +		setBGColor( pBGHexColor )
 +		setFGColor( pFGHexColor )
 +
 +  Validation
 +		estEntierPositif( pVal )
 +		getAgeFromDate( pDate )
 +		getElementArrayForTagName( pTagName )
 +		getRadioValue( pRadioElement )
 +		getSelectValue( pInputSelectElement )
 +		getSelectMultipleValue( pInputSelectElement )
 +		hasNonStandardChars( pValueString )
 +		isAllCharInTable( pValueString, pValidationString )
 +		isEmptyString( pValueString )
 +		isNumeric( pNumString )
 +		isValidContenuChamps( pChamps, pString, pChiffre, pEspace, pAutreCar )
 +		isValidDate( pDate, pSeparator )
 +		isValidEmail( pEmailString )
 +		isValidNAS( pNAS )
 +		isValidPhoneNumber( pPhoneNumberString, pValidationType )
 +		isValidZipCode( pZipCode )
 +		isValidUSZipCode( pZipCode )
 +
 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
 
/* ----------------------------------------------------------
*  Apporte des modifications - Debut
*  ------------------------------------------------------- */

/*
 *  Crée un nombre monétaire à partir d'une string.  Cette méthode effectue les validations
 *  nécessaires afin de rendre le montant valide.
 *
 *  @param pNumString A String object representing the number to create
 *  @return The boolean true if pNumString is a valid number, false otherwise
 */
function createCurrency( pNumString ) {

    if ( isNumeric( pNumString ) ) {
        return pNumString;
    }

    pNumString = pNumString.replace( / /g, "," );
    pNumString = pNumString.replace( /\./g, "," );

    var numArray = pNumString.split( "," );
    var numString = "";

    for ( var i = 0, size = numArray.length; i < size; i++ ) {

        if ( i == ( size - 1 ) &&
             numArray[i].length == 2 ) {
            numString += ".";
        } else if ( i > 0 &&
                    numArray[i].length != 3 ) {
            // Après une virgule, il ne peut y avoir que 2 ou 3 chiffres !
            return null;
        } else if ( i == 0 &&
                    numArray[i].length > 3 ) {
            return null;
        }

        numString += numArray[i];

    }

    if ( numArray.length < 1 ) {
        numString = pNumString;
    }

    if ( !isNumeric( numString ) ) {
        return null;
    }

    return numString;

}

/*
 *  This function escapes a standard string in a safe HTTP communication string.
 *
 *  @return The escaped string passed in parameter
 */
function escapeString( pString ) {

    var str = escape( pString );
    var plusArray = str.split( "+" );
    var slashArray;

    if ( plusArray.length > 1 ) {

        str = "";

        for ( var i = 0; i < plusArray.length; i++ ) {

            str += plusArray[i];

            if ( i < plusArray.length - 1 ) {
                str += "%2B";
            }
        }
    }

    slashArray = str.split( "/" );

    if ( slashArray.length > 1 ) {

        str = "";

        for ( var i = 0; i < slashArray.length; i++ ) {

            str += slashArray[i];

            if ( i < slashArray.length - 1 ) {
                str += "%2F";
            }
        }
    }

    return str;

}

/*
 *  This function parses the current page's query string (?var=value...).
 *
 *  @return An associative Array object containing the variables/values of
 *          the query string or null if no query string detected
 */
var userQueryVarNames = null;

function parseQueryString() {

    var query = unEscapeString( location.search );

    if ( query == null ||
         trim( query ) == "" ) {
        return null;
    }

    query = query.substring( 1, query.length );

    userQueryVarNames = new Array();

    var curVar, curVal;
    var finalArray = new Array();
    var queryArray = query.split( "&" );
    var tempArray;

    for ( var i = 0; i < queryArray.length; i++ ) {

        tempArray = queryArray[i].split( "=" );
        curVar = tempArray[0];
        curVal = tempArray[1];

        userQueryVarNames[userQueryVarNames.length] = curVar;
        finalArray[curVar] = curVal;

    }

    return finalArray;

}  

/*
 *  This function converts a string into a camel case style string.
 *
 *  @param pValueString A String object to convert
 *  @return A String object, pValueString, converted into camel case style
 */
function toCamelCase( pValueString ) {

    if ( pValueString != "" ) {

        var inWord = false;
        var decomp = pValueString.split( "" );

        for ( var cpt=0; cpt < decomp.length - 1; cpt++ ) {

            if ( decomp[cpt] != " " && !inWord) {

                decomp[cpt] = decomp[cpt].toUpperCase();
                inWord = true;

            } else if ( decomp[cpt] == " " ) {
                inWord = false;
            }
        }

        return decomp.join( "" );

    }

    return pValueString;

}

/*
 *  This function trims a String object.
 *
 *  @param pValueString A String object to trim
 *  @return The String object pValueString trimmed
 */
function trim( pValueString ) {

    if ( pValueString == null ||
         ( pValueString.length != null &&
           pValueString.length == 0 ) ) {
        return "";
    }

    while ( pValueString.charAt( 0 ) == " " ) {
        pValueString = pValueString.substring( 1, pValueString.length );
    }

    while ( pValueString.charAt( pValueString.length - 1 ) == " " ) {
        pValueString = pValueString.substring( 0, pValueString.length - 1 );
    }

    return pValueString;

}

/*
 *  This function unescapes a standard string in a normal HTML string.
 *
 *  @return The unescaped string passed in parameter
 */
function unEscapeString( pString ) {

    var str = unescape( pString );
    var plusArray = str.split( "+" );
    var slashArray;

    if ( plusArray.length > 1 ) {

        str = "";

        for ( var i = 0; i < plusArray.length; i++ ) {

            str += plusArray[i];

            if ( i < plusArray.length - 1 ) {
                str += " ";
            }
        }
    }

    return str;

}							 
	  
/*
 *  Cette fonction replaceAll permet de remplacer un caractère par un autre caractère partout dans la chaîne de  
 * 	caractère.
 *										   
 *	@parametre pChaine, chaine à modifier
 *  @parametre pCarChange, le caractère à changer
 *  @parametre pCarPar, le nouveau caractère
 *  @return sChaine, la nouvelle chaîne de caractère
 */
function replaceAll( pChaine, pCarChange, pCarPar ) {
  
   var sChaine = pChaine; 
   var sChaineDeb = "";
   var sChaineFin = ""; 
   
   for ( iCpt =0; iCpt < sChaine.length; iCpt++ ) {
   		if ( sChaine.charAt( iCpt ) == pCarChange ) {
			 
			sChaineDeb = sChaine.substring( 0, iCpt );
			sChaineFin = sChaine.substring( iCpt + 1 );
			sChaine = sChaineDeb + pCarPar + sChaineFin;
			
		}
   }	  
   
   return sChaine;
   
}	

/*
 *  Cette fonction replaceAllWithString permet de remplacer une chaîne de caractère par une autre chaîne de caractère 
 *	partout dans la variable.
 *										   
 *	@parametre pChaine, chaine à modifier
 *  @parametre pStringChange, la chaîne de caractère à changer
 *  @parametre pStringPar, la nouvelle chaîne de caractère
 *  @return sChaine, la chaîne de caractère modifiée
 */
function replaceAllWithString( pChaine, pStringChange, pStringPar ) {
  
  var iLength = 0;
  
   var sChaine = pChaine; 

   while( sChaine.indexOf( pStringChange ) != -1 && iLength < pChaine.length) {
		sChaine = sChaine.replace( pStringChange, pStringPar );
		iLength++;
   }	  
   
   return sChaine;
   
}  

/*
 *  Cette fonction retourne une chaîne de caractère ne contenant que les caractères passés en paramètre.
 *
 *  @param pValueString A String object representing the text to validate
 *  @param pValidationString A String object representing valid chars
 */
function reduceToTable( pValueString, pValidationString ) {	
	var sChaineTmp = "";
    for (i = 0; i < pValueString.length; i++) {		
        if ( pValidationString.indexOf( pValueString.charAt(i) ) != -1 ) {
            sChaineTmp = sChaineTmp + pValueString.charAt(i);
        }
    }
	return sChaineTmp;
}

/* ----------------------------------------------------------
* Apporte des modifications - Fin
* -------------------------------------------------------- */

/* ----------------------------------------------------------
* Autre - Debut
* -------------------------------------------------------- */

/*
 *  This is a dummy function ( ex: <a href="javascript:dummy();" ...> ).
 */
function dummy() {

    return;

}

/*
 *  This function hides a <div> tag.
 *
 *  @param pId The id of the <div> tag to hide.
 */
function hide( pId ) {

    if ( pId == null ) {
        return;
    }

    if ( isIE() ) {
        eval( pId + ".style.display = 'none';" );
    } else if ( isNS4() ) {
        eval( "document." + pId + ".visibility = 'hide';" );
    } else if ( isNS6() ) {
        eval( "document.getElementById( '" + pId + "' ).style.display = 'none';" );
    }
    
}

/*
 *  This function transfers the current focus to the aimed component as
 *  soon as pSkipAfter is reached.  Works only for input textfields.
 *
 *  @param pSourceComponent The source component that generates an onKeyPress event
 *  @param pAimedComponent A String object representing the name of the aimed component
 *  @param pSkipAfter An integer representing the number of chars to count before
 *                    transferring focus to pAimedComponent
 */
function jump( pSourceComponent, pAimedComponent, pSkipAfter ) {
/*
    if ( isIE() ) {

        if ( pSourceComponent.value.length >= pSkipAfter ) {
            eval( "pSourceComponent.form." + pAimedComponent + ".focus()" );
        }
    } else if ( isNS4() || isNS6() ) {

        if ( pSourceComponent.value.length >= pSkipAfter - 1 ) {
            eval( "pSourceComponent.form." + pAimedComponent + ".focus()" );
        }
    }
*/
		
   /*if ( isIE() || isNS6() || isMac() ) {
        if ( pSourceComponent.value.length >= pSkipAfter ) {
            eval( "pSourceComponent.form." + pAimedComponent + ".focus()" );
        }
  } else*/
	if ( isNS4() ) {
    if ( pSourceComponent.value.length >= pSkipAfter - 1 ) {
    	eval( "pSourceComponent.form." + pAimedComponent + ".focus()" );
  	}
  } else {
		if ( pSourceComponent.value.length >= pSkipAfter ) {
    	eval( "pSourceComponent.form." + pAimedComponent + ".focus()" );
  	}
	}
}

/*
 *  This function hides all DIVs help.
 *
 *  @param pHelpList An Array object that contains all the DIV help IDs
 *                   ex :  var helpList = new Array( "help01", "help02" );
 *  @param pHelpWidthList An Array object that contains all the DIV help
 *                        IDs width
 */
function loadHelp( pHelpList, pHelpWidthList ) {

    if ( pHelpList == null ||
         pHelpWidthList == null ||
         pHelpList.length != pHelpWidthList.length ) {
        return;
    }

    if ( isIE() ) {
        for ( var i = 0; i < pHelpList.length; i++ ) {
            if ( eval( "document.all." + pHelpList[i] ) != null ) {
              eval( pHelpList[i] + ".style.width = '" + pHelpWidthList[i] + "px';" );
              eval( pHelpList[i] + ".style.display = 'none';" );
            }
        }
    } else if ( isNS6() ) {
        for ( var i = 0; i < pHelpList.length; i++ ) {
            if ( document.getElementById( pHelpList[i] ) != null ) {
              eval( "document.getElementById( '" + pHelpList[i] + "' ).style.width = '" + pHelpWidthList[i] + "px';" );
              eval( "document.getElementById( '" + pHelpList[i] + "' ).style.display = 'none';" );
            }
        }
    }
}

function recupererObjet( pId, pNewWindow ) {

    var doc = document._form;
    var originalTarget = doc.target;

    if ( pNewWindow ) {
        doc.target = "_blank";
    }

    doc._id.value = pId;
    doc.submit();

    if ( pNewWindow ) {
        doc.target = originalTarget;
    }
}

/*
 *  This function WRITES a client-side rotative banner effect.
 *
 *  @param pImageChoices An Array object representing the name of all the available images to rotate.
 *  @param pImageLinks An Array object representing the links for the corresponding images.  Put null for this
 *                     parameter if no link is needed.  It is mandatory to call the <a> name property the same
 *                     as the pContainerName + "Link".  For example, if pContainerName == "leftBanner", the anchor
 *                     container will be named "leftBannerLink".
 *                     full ex :  <a name="leftBannerLink"><img name="leftBanner" width="10" height="10" border="0"></a>
 */
function rotate( pImageChoices, pImageLinks ) {

    if ( pImageChoices == null ||
         pImageChoices.length == 0 ) {
        return;
    }

    var container = null;
    var htmlOutput = "";
    var imgChoice = Math.round( Math.random() * ( pImageChoices.length - 1 ) );
    var url = location.pathname + location.search;
    var language = ( url.indexOf( "/en/" ) != -1 ) ? "en" : "fr";

    if ( pImageLinks[imgChoice] != null ) {
        htmlOutput += "<a href=\"" + pImageLinks[imgChoice] + "\">";
    }

    htmlOutput += "<img src=\"/images/" + language + "/rotatif/" + pImageChoices[imgChoice] + "\" border=\"0\">";

    if ( pImageLinks[imgChoice] != null ) {
        htmlOutput += "</a>";
    }

    document.write( htmlOutput );
    document.close();

}

/*
 *  This function unhides a div tag.
 *
 *  @param pId The Id of the <div> to unhide.
 */
function show( pId ) {

    if ( pId == null ) {
        return;
    }

    if ( isIE() ) {
        eval( pId + ".style.display = 'block';" );
    } else if ( isNS4() ) {
        eval( "document." + pId + ".visibility = 'show';" );
    } else if ( isNS6() ) {
        eval( "document.getElementById( '" + pId + "' ).style.display = 'block';" );
    }
}

/* ----------------------------------------------------------
* Autre - Fin
* -------------------------------------------------------- */

/* ----------------------------------------------------------
* Fureteur - Debut
* -------------------------------------------------------- */

/*
 *  This function closes the last opened help window (DHTML).
 */
function closeLastHelp() {

    if ( userHelp == null ) {
        return;
    }

    if ( isIE() ) {
        eval( userHelp + ".style.display = 'none';" );
    } else if ( isNS4() ) {
        eval( "document." + userHelp + ".visibility = 'hide';" );
    } else if ( isNS6() ) {
        eval( "document.getElementById( '" + userHelp + "' ).style.display = 'none';" );
    }

    userHelp = null;

}

/*
 *  This function looks for the current browser's name.
 *
 *  @return A String object representing the browser name
 */
function getBrowserName() {

    var browserName = navigator.appName;

    if ( browserName.indexOf( "Explorer" ) != -1 ) {
        return "IE";
    } else if ( browserName.indexOf( "Netscape" ) != -1 ) {
        return "NS";
    }

    return "Unknown";

}


/*
 *  This function looks for the current computer's type.
 *
 *  @return A String object representing the computer type ( "MAC" or "PC" )
 */
function getComputerType() {

    return ( navigator.appVersion.indexOf( "Mac" ) != -1 ) ? "MAC" : "PC";

}

/*
 *  This function looks for the current browser's version.
 *
 *  @return A String object representing the browser name and its current version
 */
function getFullBrowserVersion() {

    var browserName = getBrowserName();
    var browserVersion = navigator.appVersion;

    if ( browserName == "IE" ) {

        var startPos = browserVersion.indexOf( "MSIE" );
        var endPos = browserVersion.indexOf( ";", startPos );

        return browserName + browserVersion.substring( startPos + 5, endPos );

    } else if ( browserName == "NS" ) {
        return browserName + ( ( browserVersion.charAt( 0 ) == "5" ) ? "6" : browserVersion.charAt( 0 ) );
    }

    return "Unknown";

}

/*
 *  This function looks for the current browser's version.
 *
 *  @return A String object representing the browser name and its current version
 */
function getNewBrowserVersion() {

    var browserName = getBrowserName();
    var browserVersion = navigator.appVersion;

    if ( browserName == "IE" ) {

        var startPos = browserVersion.indexOf( "MSIE" );
        var endPos = browserVersion.indexOf( ";", startPos );

        return browserName + browserVersion.substring( startPos + 5, endPos );

	} else if ( browserName == "NS" ) {

		var numBrowser = 0;
		
		if ( navigator.appVersion.indexOf( "4." ) != -1 ) {
			numBrowser = 4;
		} else {
			
			var browserVersion = navigator.appVersion;
  			numBrowser = parseFloat( browserVersion );
			
			if ( numBrowser >= 5 ) {
			
                var regexp = /Netscape\d?\/([0-9.]+)/;
                if ( regexp.exec( navigator.userAgent ) ) {
                  var ver = parseFloat( RegExp.$1 );
                  if ( ver > numBrowser ) {
                    numBrowser = ver;
                  }
                }
  			}
			
    	}
		return browserName + numBrowser;
	}

    return "Unknown";

}

/*
 *  This function looks if the current browser is of type Internet Explorer.
 *
 *  @return The boolean true if the client is in Internet Explorer, false otherwise
 */
function isIE() {

    return ( getBrowserName() == "IE" );

}


/*
 *  This function looks if the current browser is of type Internet Explorer 4.X
 *
 *  @return The boolean true if the client is in Internet Explorer 4.X, false otherwise
 */
function isIE4() {

    return ( getFullBrowserVersion() == "IE4" );

}


/*
 *  This function looks if the current browser is of type Internet Explorer 5.X
 *
 *  @return The boolean true if the client is in Internet Explorer 5.X, false otherwise
 */
function isIE5() {

    return ( getFullBrowserVersion().indexOf( "IE5" ) != -1 );

}


/*
 *  This function looks if the current browser is of type Internet Explorer 6.X
 *
 *  @return The boolean true if the client is in Internet Explorer 6.X, false otherwise
 */
function isIE6() {

    return ( getFullBrowserVersion().indexOf( "IE6" ) != -1 );

}


/*
 *  This function looks if the current computer type is a Macintosh.
 *
 *  @return The boolean true if the client is using a Macintosh, false otherwise
 */
function isMac() {

    return ( getComputerType() == "MAC" );

}

/*
 *  This function looks if the current browser is of type Netscape Communicator.
 *
 *  @return The boolean true if the client is in Netscape Communicator, false otherwise
 */
function isNS() {

    return ( getBrowserName() == "NS" );

}

/*
 *  This function looks if the current browser is of type Netscape 4.X.
 *
 *  @return The boolean true if the client is in Netscape 4.X, false otherwise
 */
function isNS4() {

    return ( getFullBrowserVersion().indexOf( "NS4" ) != -1 );

}

/*
 *  This function looks if the current browser is of type Netscape 5.
 *
 *  @return The boolean true if the client is in Netscape 5, false otherwise
 */
function isNS5() {

    return ( getNewBrowserVersion().indexOf( "NS5" ) != -1 );

}

/*
 *  This function looks if the current browser is of type Netscape 6.
 *
 *  @return The boolean true if the client is in Netscape 6, false otherwise
 */
function isNS6() {

	return ( getNewBrowserVersion().indexOf( "NS6" ) != 1 );
	
}

/*
 *  This function looks if the current browser is of type Netscape 7.
 *
 *  @return The boolean true if the client is in Netscape 7, false otherwise
 */
function isNS7() {
	
	return ( getNewBrowserVersion().indexOf( "NS7" ) != 1 );

}

/* ----------------------------------------------------------
* Fureteur - Fin
* -------------------------------------------------------- */

/* ----------------------------------------------------------
* Gestion des fenêtres - Debut
* -------------------------------------------------------- */

/*
 *  This function looks for the current browser's available height.
 *
 *  @return The current browser's width
 */
function getAvailHeight() {

    if ( isIE() ) {
        return document.body.clientHeight;
    } else if ( isNS4() || isNS6() ) {
        return window.innerHeight;
    }

    return null;

}

/*
 *  This function looks for the current browser's available width.
 *
 *  @return The current browser's width
 */
function getAvailWidth() {

    if ( isIE() ) {
        return document.body.clientWidth;
    } else if ( isNS4() || isNS6() ) {
        return window.innerWidth;
    }

    return null;

}

/*
 *  This function returns the current component background color.
 *
 *  @return A String object representing the hexadecimal background color
 */
function getBGColor() {

    return userBGColor;

}

/*
 *  This function returns the current component's foreground color.
 *
 *  @return A String object representing the hexadecimal foreground color
 */
function getFGColor() {

    return userFGColor;

}

/*
 *  This function fetches current browser's X position.
 *
 *  @return The current browser's X position
 */
function getWindowX() {

    if ( isIE() ) {
        return window.screenLeft;
    } else if ( isNS4() || isNS6() ) {
        return window.screenX
    }

    return null;

}

/*
 *  This function fetches current browser's Y position.
 *
 *  @return The current browser's Y position
 */
function getWindowY() {

    if ( isIE() ) {
        return window.screenTop;
    } else if ( isNS4() || isNS6() ) {
        return window.screenY
    }

    return null;

}

/*
 *  This function opens a new standardized help window (DHTML).  It also manages
 *  horizontal overflowing to avoid truncation of the help box.
 *
 *  @param pEvent The event object within the HTML onXXXXXX trigger (ex : onClick)
 *  @param pHelpId The Id of the <div> containing the contextual help
 */
var userHelp = null;
var X_SPACE = 10, Y_SPACE = 3, DEFAULT_HEIGHT = 200, DEFAULT_WIDTH = 250;

function openHelp( pEvent, pHelpId, pHeight ) {

    userHelp = pHelpId;

    var xCorrect = 0, yCorrect = 0;
    var windowX = getWindowX();
    var windowY = getWindowY();
    var bottom = windowY + getAvailHeight();
    var right = windowX + getAvailWidth();
    var compHeight = DEFAULT_HEIGHT;
    var compWidth = DEFAULT_WIDTH;

    if ( pHeight != null ) {
        compHeight = pHeight;
    }

    if ( isIE() ) {

        compWidth = parseInt( eval( pHelpId + ".style.width;" ) );

        if ( ( pEvent.x + X_SPACE + windowX + compWidth ) >= right ) xCorrect = compWidth + ( 2 * X_SPACE );
        if ( ( pEvent.y + Y_SPACE + windowY + compHeight ) >= bottom ) yCorrect = compHeight;

        eval( pHelpId + ".style.left = '" + ( pEvent.x + X_SPACE - xCorrect ) + "px';" );
        eval( pHelpId + ".style.top = '" + ( pEvent.y + Y_SPACE + document.body.scrollTop - yCorrect ) + "px';" );
        eval( pHelpId + ".style.display = 'block';" );

    } else if ( isNS4() ) {

        compWidth = parseInt( eval( "document." + pHelpId + ".clip.width;" ) );

        if ( ( pEvent.x + X_SPACE + windowX + compWidth ) >= right ) xCorrect = compWidth + ( 2 * X_SPACE );
        if ( ( pEvent.y + Y_SPACE + windowY + compHeight ) >= bottom ) yCorrect = compHeight;

        eval( "document." + pHelpId + ".left = " + ( pEvent.x + X_SPACE - xCorrect ) + ";" );
        eval( "document." + pHelpId + ".top = " + ( pEvent.y + Y_SPACE - yCorrect ) + ";" );
        eval( "document." + pHelpId + ".visibility = 'show';" );

    } else if ( isNS6() ) {

        compWidth = parseInt( eval( "document.getElementById( '" + pHelpId + "' ).style.width;" ) ) + 31;

        if ( ( pEvent.clientX + X_SPACE + windowX + compWidth ) >= right ) xCorrect = compWidth + X_SPACE;
        if ( ( pEvent.clientY + Y_SPACE + windowY + compHeight ) >= bottom ) yCorrect = compHeight;

        eval( "document.getElementById( '" + pHelpId + "' ).style.left = '" + ( pEvent.clientX + X_SPACE - xCorrect ) + "px';" );
        eval( "document.getElementById( '" + pHelpId + "' ).style.top = '" + ( pEvent.clientY + Y_SPACE + window.pageYOffset - yCorrect ) + "px';" );
        eval( "document.getElementById( '" + pHelpId + "' ).style.display = 'block';" );

    }
}

/*
 *  This function opens a new variable form popup window for Web.
 *
 *  @param pURL A String object representing the URL to load in the popup window
 *  @param pWidth A integer representing the width of the popup window
 *  @param pHeight A integer representing the height of the popup window
 *  @param pGetHandle A boolean identifying whether or not the user wants the window handle
 *  @param pLeft A integer representing the left position of the popup window
 *  @param pTop A integer representing the top position of the popup window
 *  @param [pPopupName] A String object representing the popup's window name
 *  @param [pScrollBar] A boolean identifying wheter or not the user wants to show the menu bar
 *  @param [pStatus] A boolean identifying wheter or not the user wants to show the status bar
 *  @param [pResizable] A boolean identifying wheter or not the user wants to enabled resize
 *  @return The window handle is returned if pGetHandle is set to true
 */
function openFormPopup( pURL, pWidth, pHeight, pGetHandle, pLeft, pTop, pPopupName, pScrollBar, pStatus, pResizable ) {

    var scrollBar = ( pScrollBar == null ) ? "yes" : ( pScrollBar ) ? "yes" : "no";
    var showStatus = ( pStatus == null ) ? "no" : ( pStatus ) ? "yes" : "no";
    var letResize = ( pResizable == null ) ? "no" : ( pResizable ) ? "yes" : "no";
    var attribs = "width=" + pWidth + ",height=" + pHeight +
                  ( ( isIE() ) ? ",left=" + pLeft : ",screenX=" + pLeft ) +
                  ( ( isIE() ) ? ",top=" + pTop : ",screenY=" + pLeft ) +
                  ",directories=no,location=no,menubar=no,resizable=" + letResize + ",scrollbars=" + scrollBar + ",status=" + showStatus + ",toolbar=no,titlebar=no";

    var handle = window.open( pURL, ( pPopupName != null ) ? pPopupName : "", attribs );

    if ( pGetHandle ) {
        return handle;
    }
}

/*
 *  This function opens a new standardized popup window.
 *
 *  @param pURL A String object representing the URL to load in the popup window
 *  @param pWidth A integer representing the width of the popup window
 *  @param pHeight A integer representing the height of the popup window
 *  @param pGetHandle A boolean identifying whether or not the user wants the window handle
 *  @param pLeft A integer representing the left position of the popup window
 *  @param pTop A integer representing the top position of the popup window
 *  @param [pPopupName] A String object representing the popup's window name
 *  @param [pScrollBar] A boolean identifying wheter or not the user wants to show the menu bar
 *  @param [pStatus] A boolean identifying wheter or not the user wants to show the status bar
 *  @param [pResize] A boolean identifying wheter or not the user wants to resize the popup window
 *  @return The window handle is returned if pGetHandle is set to true
 */
function openPopup( pURL, pWidth, pHeight, pGetHandle, pLeft, pTop, pPopupName, pScrollBar, pStatus, pResize ) {

    var scrollBar = ( pScrollBar == null ) ? "yes" : ( pScrollBar ) ? "yes" : "no";
    var showStatus = ( pStatus == null ) ? "no" : ( pStatus ) ? "yes" : "no";
    var letResize = ( pResize == null ) ? "no" : ( pResize ) ? "yes" : "no";
    var attribs = "width=" + pWidth + ",height=" + pHeight +
                  ( ( isIE() ) ? ",left=" + pLeft : ",screenX=" + pLeft ) +
                  ( ( isIE() ) ? ",top=" + pTop : ",screenY=" + pLeft ) +
                  ",directories=no,location=no,menubar=no,resizable=" + letResize + ",scrollbars=" + scrollBar + ",status=" + showStatus + ",toolbar=no";

    var handle = window.open( pURL, ( pPopupName != null ) ? pPopupName : "", attribs );

    if ( pGetHandle ) {
        return handle;
    }
}

/*
 *  This function opens a new window with the specified attributes.
 *
 *  @param pURL A String object representing the URL to load in the new window
 *  @param pAttribs A String object representing the attributes of the new window
 *  @param pGetHandle A boolean identifying whether or not the user wants the window handle
 *  @return The window handle is returned if pGetHandle is set to true
 */
function openWindow( pURL, pAttribs, pGetHandle, pAlias ) {

    var handle = window.open( pURL, ( pAlias != null ) ? pAlias : "", pAttribs );

    if ( pGetHandle ) {
        return handle;
    }
}

/*
 *  This function repaints an HTML component in the desired
 *  foreground and background color, no matter which browser is
 *  used.
 *
 *  @param pHTMLComponent The HTML component to repaint
 *  @param pFGHexColor A String object representing the hexadecimal foreground color to use (may be null)
 *  @param pBGHexColor A String object representing the hexadecimal background color to use (may be null)
 *  @param pAttribs A integer constant representing the type(s) of the attribute(s) to apply to the component
 *  @vars pAttribs Here are the global vars that applies to the pAttribs parameter :
 *                 NONE = No attributes, BOLD = Bolded text,
 *                 ITALIC = Italicized text, BOLD_ITALIC = Bolded and italicized text
 */
var userHTMLComponent = null;
var userIsBold = false, userIsItalic = false;
var NONE = 0, BOLD = 1, ITALIC = 2, BOLD_ITALIC = 3;

function paint( pHTMLComponent, pFGHexColor, pBGHexColor, pAttribs ) {

    if ( pAttribs == null ) {
        pAttribs = NONE;
    }

    if ( isIE() ) {

        userHTMLComponent = pHTMLComponent;

        setBGColor( ( pHTMLComponent.style.backgroundColor == "" ) ? "#ffffff" : pHTMLComponent.style.backgroundColor );
        setFGColor( ( pHTMLComponent.style.color == "" ) ? "#000000" : pHTMLComponent.style.color );

        pHTMLComponent.style.backgroundColor = ( pBGHexColor == null ) ? getBGColor() : pBGHexColor;
        pHTMLComponent.style.color = ( pFGHexColor == null ) ? getFGColor() : pFGHexColor;

        switch ( pAttribs ) {
            case 1 :
                userIsBold = ( pHTMLComponent.style.fontWeight == "bold" );
                pHTMLComponent.style.fontWeight = "bold";
                break;
            case 2 :
                userIsItalic = ( pHTMLComponent.style.fontStyle == "italic" );
                pHTMLComponent.style.fontStyle = "italic";
                break;
            case 3 :
                userIsBold = ( pHTMLComponent.style.fontWeight == "bold" );
                userIsItalic = ( pHTMLComponent.style.fontStyle == "italic" );
                pHTMLComponent.style.fontWeight = "bold";
                pHTMLComponent.style.fontStyle = "italic";
                break;
        }
    }
}

/*
 *  This function restores the last color changes that has occured on the last
 *  painted component (with function paint(...) ).
 */
function undoLastPaint() {

    if ( userHTMLComponent == null ) {
        return;
    }

    if ( isIE() ) {

        userHTMLComponent.style.color = getFGColor();
        userHTMLComponent.style.backgroundColor = getBGColor();

        if ( userIsBold ) {
            userHTMLComponent.style.fontWeight = "bold";
        } else {
            userHTMLComponent.style.fontWeight = "normal";
        }

        if ( userIsItalic ) {
            userHTMLComponent.style.fontStyle = "italic";
        } else {
            userHTMLComponent.style.fontStyle = "normal";
        }
    }
}


/*
 *  This function sets the current component background color.
 *
 *  @param pBGHexColor A String object representing the hexadecimal background color
 */
var userBGColor = null;

function setBGColor( pBGHexColor ) {

    userBGColor = pBGHexColor;

}

/*
 *  This function sets the current component foreground color.
 *
 *  @param pFGHexColor A String object representing the hexadecimal foreground color
 */
var userFGColor = null;

function setFGColor( pFGHexColor ) {

    userFGColor = pFGHexColor;

}

/* ----------------------------------------------------------
* Gestion des fenêtres - Fin
* -------------------------------------------------------- */

/* ----------------------------------------------------------
* Validation - Debut
* -------------------------------------------------------- */

/*
 *  Cette fonction retourne vrai si le paramètre ne contient que des chiffres
 */

function estEntierPositif( pVal ) {
    bCheck = true;
	for (var i = 0; i < pVal.length; i++) {
        if ( isNaN( pVal.charAt(i) ) ) {
            bCheck = false;
        }
    }
	return bCheck;
}

/*
 *  This function returns an age based on the date passed in parameter.
 *  The date format must be of the following :  "2001/01/01"
 *
 *  @return An integer representing the date's "age"
 */
var ONE_DAY  = 86400000;
var ONE_YEAR = 31622400000;
/*
function getAgeFromDate( pDate ) {

    var adjust = ONE_DAY * 16;    // 16 days bug in JavaScript
    var date = new Date( pDate ).valueOf();
    var millisecToNow = new Date().valueOf();

    if ( date < 0 ) {
      date = ( date * -1 ) + millisecToNow;
    } else {
      date = millisecToNow - date;
    }

    date += adjust;

    return Math.floor( date / ONE_YEAR );

}
*/
function getAgeFromDate(pDate){
	var actu=new Date();
	var naissance = pDate.split("/");
	var age = 0;

	age = actu.getFullYear() - Number(naissance[0]);
	if ( ( actu.getMonth() + 1 ) <  Number(naissance[1]) )
	{
		age = age - 1;
	} else if ( ( actu.getMonth() + 1 ) ==  Number(naissance[1]) && actu.getDate() <  Number(naissance[2]) )
	{
		age = age - 1;
	}

	return age;
}

/*
 *  This function seeks and returns all elements corresponding to the specified tag name.
 *
 *  @return An Array object containing all the tags found.
 */
function getElementArrayForTagName( pTagName ) {

    if ( isNS6() ) {
        return document.all.tags( pTagName );
    } else if ( isNS4() ) {
        return new Array( 0 );
    } else if ( isNS6() ) {
        return document.getElementsByTagName( pTagName );
    }
}

/*
 *  This function simply fetches a radio button HTML input type.
 *
 *  @param pRadioElement A complete HTML "radio" input type path
 *  @return A String object representing the value found, null otherwise
 */
function getRadioValue( pRadioElement ) {
	
    if ( pRadioElement != null ) {
        for ( var i = 0; i < pRadioElement.length; i++ ) {
            if ( pRadioElement[i].checked ) {
                return pRadioElement[i].value;
            }
        }
    }

    return null;

}

/*
 *  This function simply fetches a input select list value.
 *
 *  @param pInputSelectElement A complete HTML "select" input type path
 *  @return A String object representing the value found, null otherwise
 */
function getSelectValue( pInputSelectElement ) {

    if ( pInputSelectElement == null ||
         pInputSelectElement.options.length < 1 ) {
        return null;
    }

    return pInputSelectElement.options[pInputSelectElement.selectedIndex].value;

}

/*
 *  This function simply fetches a input select multiple list value.
 *
 *  @param pInputSelectElement A complete HTML "select" input type path
 *  @return an array object representing the value found, null otherwise
 */
function getSelectMultipleValue( pInputSelectElement ) {
	
	if ( pInputSelectElement == null ||
         pInputSelectElement.options.length < 1 ) {
        return null;
    }	  
	
	var multipleTableau = new Array();
	var iCpt = 0;
	
	for ( i=0; i < pInputSelectElement.options.length; i++ ) {
	 
	 	if ( pInputSelectElement.options[i].selected ) {
		
		    multipleTableau[iCpt] = pInputSelectElement.options[i].value;
			iCpt++
		}
	
	}

    return multipleTableau;

}

/*
 *  This function looks if a String contains a non-standard Windows character
 *  (those defined for Windows directories :   \/:*?"<>|   ).
 *
 *  @param pValueString A String object representing the text to validate
 *  @return The boolean true if pValueString is non-standard, false otherwise
 */
function hasNonStandardChars( pValueString ) {

    if ( pValueString.indexOf( "\\" ) != -1 ||
         pValueString.indexOf( "/" ) != -1 ||
         pValueString.indexOf( ":" ) != -1 ||
         pValueString.indexOf( "*" ) != -1 ||
         pValueString.indexOf( "?" ) != -1 ||
         pValueString.indexOf( "\"" ) != -1 ||
         pValueString.indexOf( "<" ) != -1 ||
         pValueString.indexOf( ">" ) != -1 ||
         pValueString.indexOf( "|" ) != -1 ) {
        return true;
    }

    return false;

}

/*
 *  This function looks if all char of the first string are in the second string.
 *
 *  @param pValueString A String object representing the text to validate
 *  @param pValidationString A String object representing valid chars
 */
function isAllCharInTable( pValueString, pValidationString ) {
    for (i = 0; i < pValueString.length; i++) {		
        if ( pValidationString.indexOf( pValueString.charAt(i) ) == -1 ) {
            return false;
        }
    }
	return true;
}

/*
 *  This function looks if a string is empty or null.
 *
 *  @param pValueString A String object representing the text to validate
 *  @return The boolean true if pValueString is empty, false otherwise
 */
function isEmptyString( pValueString ) {

    return ( trim( pValueString ) == "" );

}

/*
 *  This function encapsulates isNaN() by accepting floating point numbers
 *  with (,) and rejecting blank or untrimmed strings or even scientific
 *  number (10e8).
 *
 *  @param pNumString A String object representing the number to validate
 *  @return The boolean true if pNumString is a valid number, false otherwise
 */
function isNumeric( pNumString ) {

    if ( pNumString.indexOf( "," ) != -1 ) {

        var numArray = pNumString.split( "," );

        if ( numArray.length > 2 ) {
            return false;
        }

        pNumString = numArray[0] + "." + numArray[1];

    }

    if ( pNumString == null ||
         isNaN( pNumString ) ||
         isEmptyString( pNumString ) ||
         pNumString.toUpperCase().indexOf( "E" ) != -1 ||
         pNumString.indexOf( "0x" ) != -1 ) {
        return false;
    }

    return true;

}

/*
 *  This function validates a date.
 *
 *  @param pDate A String object representing the date to validate
 *  @param pSeparator A String object representing the separators inside pDate
 *  @return The boolean true if pDate is valid, false otherwise
 */
function isValidDate( pDate, pSeparator ) {

    var mois = new Array( 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 );
    var accept = true;

    if ( pDate.length > 7 &&
         pDate.length < 11 ) {

        pDate = pDate.split( pSeparator );

        if ( pDate.length == 3 &&
             isNumeric( pDate[0] ) &&
             isNumeric( pDate[1] ) &&
             isNumeric( pDate[2] ) ) {

            if ( pDate[0] < 1800 || pDate[0] > 4999 ) accept = false;
            if ( pDate[1] < 1 || pDate[1] > 12 ) accept = false;
            if ( pDate[2] < 1 || pDate[2] > mois[pDate[1] -1] ) accept = false;
            if ( pDate[1] == 2 && pDate[2] == 29 ) {
                if ( pDate[0]%4 != 0 || ( pDate[0]%100 == 0 && pDate[0]%1000 != 0 ) ) accept = false;
                else accept = true;
            }
        } else {
            accept = false;
        }
    } else {
        accept = false;
    }

    return ( accept );

}


/*
 *  This function validates the structure of an email.
 *
 *  @param pEmailString A String object representing the email to validate
 *  @return The boolean true if pEmailString is valid, false otherwise
 */
function isValidEmail( pEmailString ) {

  var sTemp = pEmailString.indexOf( "@" );
  var sTemp2 = pEmailString.substr( sTemp );

    if ( pEmailString == null ||
         isEmptyString( pEmailString ) ||
         pEmailString.indexOf( "@" ) == -1 ||
         pEmailString.indexOf( "@" ) == 0 ||
         pEmailString.indexOf( "@" ) == ( pEmailString.length - 1 ) ||
         pEmailString.indexOf( "@" ) != pEmailString.lastIndexOf( "@" ) ||
         pEmailString.indexOf( " " ) != -1 ||
         pEmailString.indexOf( "." ) == -1 ||
         pEmailString.indexOf( "." ) == 0 ||
         pEmailString.indexOf( ".." ) != -1 ||
         pEmailString.indexOf( "," ) != -1 ||
         sTemp2.indexOf( "." ) == -1 ||
         pEmailString.indexOf( "." ) == ( pEmailString.length - 1 ) ||
         hasNonStandardChars( pEmailString ) ) {
        return false;
    } else {
		 var cour = new Array();
		 cour = pEmailString.split( "@" );
		 
		 if ( cour[0].length > 64 || cour[1].length > 64) {
		 	return false;
		 } else {
		 	return true;
		 }
	}
	
}

/*
 *  This function validates a given N.A.S. number.
 *
 *  @param pNAS A String object representing N.A.S. to validate
 *  @return The boolean true if pNAS is valid, false otherwise
 */
function isValidNAS( pNAS ) {

    if ( pNAS.length > 8 ) {

        pNAS = pNAS.toString();
        var decomp = new Array( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
        var total = 0;

        for ( var cpt = 0, cpt2 = 1; cpt < pNAS.length - 1; cpt++ ) {

            if ( pNAS.charAt( cpt ) != " " ) {
                if ( cpt2 < 16 ) {
                    decomp[cpt2] = parseInt( pNAS.charAt( cpt ) );
                }
                cpt2 += 2;
            }
        }

        if ( pNAS.charAt( pNAS.length - 1 ) != " " ) {
            decomp[decomp.length-1] = parseInt( pNAS.charAt( pNAS.length - 1 ) );
        } else {
            return false;
        }

        for ( cpt = 3; cpt < 16; cpt+=4 ) {

            if ( decomp[cpt] * 2 < 10 ) {
                decomp[cpt] *= 2;
            } else {
                decomp[cpt-1] = 1;
                decomp[cpt] = ( decomp[cpt] * 2 ) - 10;
            }
        }

        for ( cpt = 0; cpt < 16; cpt++ ) {
            total += decomp[cpt];
        }

        total = 100 - total;
        total = parseInt( total.toString().charAt( 1 ) );

        if ( total != decomp[decomp.length-1] ) {
            return false;
        }

        return true;

    }

    return false;

}

/*
 *  This function validates a phone number.
 *
 *  @param pPhoneNumberString A String object representing the phone number
 *                            to validate
 *  @param pValidationType An integer identifying the validation type
 *  @vars pValidationType Here are the global vars for pValidationType
 *                        NO_DASH : 6669999 or 4186669999 or 14186669999 or ...(418)...
 *                        SINGLE_DASH : 666-9999 or 418 666-9999 or 1 418 666-9999 or ...(418)...
 *                        FULL_DASH : 666-9999 or 418-666-9999 or 1-418-666-9999 (dash required between each sequences)
 *  @return The boolean true if pPhoneNumberString is valid, false otherwise
 */
var NO_DASH = 0, SINGLE_DASH = 1, FULL_DASH = 2;  // By default, use SINGLE_DASH (666-9999)

function isValidPhoneNumber( pPhoneNumberString, pValidationType ) {

    if ( pPhoneNumberString == null ||
         isEmptyString( pPhoneNumberString ) ) {
        return false;
    }

    if ( pPhoneNumberString.indexOf( "." ) != -1 ) {
        return false;
    }

    if ( pPhoneNumberString.length < 7 ) {
        return false;
    }

    var openPar = pPhoneNumberString.indexOf( "(" );
    var closePar = pPhoneNumberString.indexOf( ")" );

    if ( pValidationType == NO_DASH ) {

        var trimmedPhone = trim( pPhoneNumberString.substring( closePar + 1, pPhoneNumberString.length ) );

		if ( trimmedPhone.length != 7 &&
             trimmedPhone.length != 10 ) {
            return false;
        }

        if ( !isNumeric( trimmedPhone ) ) {
            return false;
        } else if ( openPar < closePar &&
                    !isNumeric( trim( pPhoneNumberString.substring( openPar + 1, closePar ) ) ) ) {
            return false;
        } else if ( openPar != -1 || closePar != -1 ) {
            if ( trim( pPhoneNumberString.substring( openPar + 1, closePar ) ).length != 3 ) {
               return false;
           } else if ( openPar > 0 &&
                       !isNumeric( trim( pPhoneNumberString.substring( 0, openPar ) ) ) ) {
               return false;
           }
        }
    } else if ( pValidationType == SINGLE_DASH ) {

        var rightSideArray = trim( pPhoneNumberString.substring( pPhoneNumberString.lastIndexOf( " " ), pPhoneNumberString.length ) ).split( "-" );

        if ( rightSideArray.length != 2 ||
             !isNumeric( rightSideArray[0] ) ||
             !isNumeric( rightSideArray[1] ) ) {
            return false;
        }

        if ( ( rightSideArray[0] ).length != 3 ||
             ( rightSideArray[1] ).length != 4 ) {
            return false;
        }

        if ( openPar != -1 &&
             !isNumeric( trim( pPhoneNumberString.substring( openPar + 1, closePar ) ) ) ) {
            return false;
        }
        
        if ( ( openPar != -1 && closePar == -1 ) || ( openPar == -1 && closePar != -1 ) ) {
         return false;
		  }
           
        if ( openPar != -1 || closePar != -1 ) {
           if ( trim( pPhoneNumberString.substring( openPar + 1, closePar ) ).length != 3 ) {
               return false;
   		   }
   	  }

        if ( openPar > 0 &&
             !isNumeric( trim( pPhoneNumberString.substring( 0, openPar ) ) ) ) {
            return false;
        }
    } else if ( pValidationType == FULL_DASH ) {

        var phoneArray = trim( pPhoneNumberString ).split( "-" );

        if ( phoneArray.length < 2 ||
             phoneArray.length > 4 ) {
            return false;
        }

        if ( ( phoneArray[phoneArray.length-2] ).length != 3 ||
             ( phoneArray[phoneArray.length-1] ).length != 4 ) {
            return false;
        }

        for ( var cpt = 0; cpt < phoneArray.length; cpt++ ) {
            if ( !isNumeric( phoneArray[cpt] ) ) {
                return false;
            }
        }
    } else {
        return false;
    }

    return true;

}




/*
 *  This function validates a string.
 *
 *  @param pChamps est un objet String qui est à valider
 *  @param pString est un objet Boolean qui permet de savoir si pChamps peut contenir des lettres 
 *  @param pChiffre est un objet Boolean qui permet de savoir si pChamps peut contenir des chiffres
 *  @param pEspace est un objet Boolean qui permet de savoir si pChamps peut contenir des espaces
 *  @param pAutreCar est un objet String qui permet de savoir si pChamps peut contenir des caractères spéciaux
 *  @return The boolean true if String is valid, false otherwise
 */
var VALID_STRING = "abcdefghijklmnopqrstuvwxyz";
var VALID_ACCENT = "àâäçèéêëîìïôòöûüù";
var VALID_CHANGE = "aaaceeeeiiiooouuu";
var VALID_CHIFFRE = "0123456789";
//var VALID_AUTRE = "!/$%',-.:;_? ";

function isValidContenuChamps( pChamps, pString, pChiffre, pEspace, pAutreCar ) {

	var sCarAutorise = "";
	
	if ( pString ) {
		sCarAutorise = VALID_STRING + VALID_ACCENT;
	} 
	if ( pChiffre ) {
		sCarAutorise = sCarAutorise + VALID_CHIFFRE;
	}
	if ( pEspace ) {
		sCarAutorise = sCarAutorise + " ";
	}
	if ( pAutreCar != undefined && pAutreCar != null && pAutreCar != ""  ) {
		if ( pAutreCar.length > 0 ) {
			sCarAutorise = sCarAutorise + pAutreCar;
		}
	}
	for ( var i = 0; i < pChamps.length; i++ ) {
		if ( sCarAutorise.indexOf( pChamps.charAt(i) ) == -1 ) {
			return false;
		}
	}
	
	return true;
	
}

/*
 *  This function remplace les accents.
 *
 *  @param pChamps est un objet String qui est à valider
 *  @param pSearch est un objet Boolean qui permet de savoir si pChamps peut contenir des lettres 
 *  @param pRepl est un objet String qui permet de savoir si pChamps peut contenir des chiffres
 *  @return string sans les accents
 */
 
function replaceAccent( pChamps ) {  

var sortie = "";
var index1;

  for ( var i = 0; i < pChamps.length; i++ ) {

  	index1 = VALID_ACCENT.indexOf( pChamps.charAt(i));
  	if ( index1 != -1) {
       sortie += VALID_CHANGE.charAt(index1);  
	} else {
	  sortie += pChamps.charAt(i); 
	}
  }
  return sortie;  
}  

/*
 *  This function validates a given zip code.
 *
 *  @param pZipCode A String object representing the zip code to validate
 *  @return The boolean true if pZipCode is valid, false otherwise
 */
function isValidZipCode( pZipCode ) {

    if ( pZipCode.length > 5 ) {

        pZipCode = pZipCode.toString().toUpperCase();
        var temp = new Array();

        for ( var cpt = 0, cpt2 = 0; cpt < pZipCode.length; cpt++ ) {

            if ( pZipCode.charAt( cpt ) != " " ) {
                temp[cpt2] = pZipCode.charAt( cpt );
                cpt2++;
            }
        }

        if ( temp.length > 6 ) {
            return false;
        }

        for ( var cpt = 0, cpt2 = 1; cpt2 < pZipCode.length; cpt+=2, cpt2+=2) {

            if ( temp[cpt] < "A" || temp[cpt] > "Z" ) return false;
            if ( temp[cpt2] < "0" || temp[cpt2] > "9" ) return false;
        }

        return true;

    }

    return false;

}

/*
 *  This function validates a given US zip code.
 *
 *  @param pZipCode A String object representing the zip code to validate
 *  @return The boolean true if pZipCode is valid, false otherwise
 */
function isValidUSZipCode( pZipCode ) {

    pZipCode = pZipCode.replace(/ /g,"");

	if ( isNumeric( pZipCode ) && pZipCode <= 99999 ) {
        return true;
    }

    return false;

}

/* ----------------------------------------------------------
* Validation - Fin
* -------------------------------------------------------- */

/*
 *  Gestion de la valeur de undefined pour IE5.
 *
 */
if ( isIE5 ){
	undefined = document.valeurUndefined;
}
