
// Get Object By Id
function getObject( psId )
{
    var obj;

    if( document.getElementById )
        obj = document.getElementById(psId);
    else if ( document.all )
        obj = eval('document.all.'+psId);

    return obj;
}

// Highlight / Clear 
function highLight( poElement )
{
    var higlightClassName = poElement.getAttribute("highlight");
    addClass( poElement, higlightClassName);
}
function clearLight( poElement )
{
    var higlightClassName = poElement.getAttribute("highlight");
    removeClass( poElement, higlightClassName);
}


/******************************************/
/**          CONTROLES ET OUTILS         **/
/******************************************/

// Vérifie que la longueur d'un poItem ne dépasse pas un certain nb de caractères
function checkLongueur( poItem, piLimitMax )
{
    if (poItem.value.length>piLimitMax) 
    {
        alert (""+piLimitMax+" caractères maximum !");
        poItem.value = poItem.value.substr(0,piLimitMax);
    }
}

// Encodage de l'URL
function urlencode( str )
{
    var newstr;
    newstr = str.replace (/&/g, "%26");
    return newstr;
}

// Empêcher la validation intempestive
function submitonce( theform )
{
    if (document.all || document.getElementById) {
        // on gèle les boutons "submit" and "reset"
        for (i=0;i<theform.length;i++) {
            var tempobj=theform.elements[i];
            if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset")
                tempobj.disabled=true;
        }
    }
}

function Trim( s )
{
    // Remove leading spaces and carriage returns
    while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
        s = s.substring(1,s.length);

    // Remove trailing spaces and carriage returns
    while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
        s = s.substring(0,s.length-1);

    return s;
}

function checkFrenchDate( psDate, psLabel ) {
    var msg = "";
    if( psDate != "" && (isNaN( psDate.replace(/\//g, "") ) || psDate.indexOf("/") != 2 || psDate.lastIndexOf("/") != 5) ) {
        msg += "\n - la DATE " + psLabel + " doit être du type : jj/mm/aaaa.";
    }
    else if( psDate != "")
    {
        var arrDate = psDate.split("-");
        if ( arrDate[1] < 0 || arrDate[1] > 12 )
            msg += "\n - la DATE " + psLabel + " doit avoir un mois compris entre 01 et 12.";
        if ( arrDate[2] < 0 || arrDate[2] > 31 )
            msg += "\n - la DATE " + psLabel + " doit avoir un jour compris entre 01 et 31.";
    }
    return msg;
}