﻿// Fichier JScript

//Ouvre une fenêtre popup
function OpenPopUp(URL) 
{
    var result;
    var param = 'location:no;status:no;scroll:yes;resizable:yes;help:no;dialogWidth:800px;dialogHeight:600px';              
    if (window.showModalDialog) {
        result = window.showModalDialog(URL,'Napoleonica  - la revue',param);
    }
    else 
    {
        if(navigator.appName == 'Netscape')
            result = window.open(URL,'Napoleonica  - la revue');
        else
            result = window.open(URL,'Napoleonica  - la revue',param);
    }
    return result;
}

//Ouvre une fenêtre popup
function OpenPopUpAdmin(URL) 
{
    var result;
    var param = 'location=no,status=no,scroll=yes,resizable=yes,help=no,width=700px,height=600px';              
    
    if (window.showModalDialog) {
        window.open(URL,'Napoleonica',param);
    }
    else 
    {
        if(navigator.appName == 'Netscape')
            window.open(URL,'Napoleonica  - la revue');
        else
            window.open(URL,'Napoleonica  - la revue',param);
    }
}


//Génère le click entrée
function KeyPressEnterSubmit(sBtnID)
{
// Si la touche [Entree] est tapée
    if (event.keyCode == 13)
    {
        var btn = document.getElementById(sBtnID);
            
        // Annule le lancement automatique
        event.returnValue = false;
        event.cancel = true;
         
        // Lance le formulaire par un click sur le bouton "Lancer la recherche"
        btn.click();
    }
}


//Génère le click entrée
function KeyPressEnterSubmitMenu(sTbxLogin, sTbxPwd, sBtnLogin, sTbxSearch, sBtnSearch)
{
// Si la touche [Entree] est tapée
    if (event.keyCode == 13)
    {
        var TbxLogin = document.getElementById(sTbxLogin);
        var TbxPwd = document.getElementById(sTbxPwd);
        var BtnLogin = document.getElementById(sBtnLogin);
    
        if (TbxLogin!=null && TbxPwd!=null && BtnLogin!=null)
        {
            if (Trim(TbxLogin.value)!='' && Trim(TbxPwd.value)!='')
            {
                // Annule le lancement automatique
                event.returnValue = false;
                event.cancel = true;
                // Lance le formulaire par un click sur le bouton "Lancer la recherche"
                BtnLogin.click();
                return true;
            }
        }
    
        var TbxSearch = document.getElementById(sTbxSearch);
        var BtnSearch = document.getElementById(sBtnSearch);

        if (TbxSearch!=null && BtnSearch!=null)
        {
            if (Trim(TbxSearch.value)!='')
            {
                // Annule le lancement automatique
                event.returnValue = false;
                event.cancel = true;
                // Lance le formulaire par un click sur le bouton "Lancer la recherche"
                BtnSearch.click();
                return true;
            }
        }

    }
}

function Trim(szBuf)
{
	return RTrim(LTrim(szBuf));
}

// Suppression des espaces en fin de chaine
function RTrim(szBuf)
{
	szBuf = String(szBuf);
	return szBuf.replace (/([ ]*)$/, "");
}

// Suppression des espaces en debut de chaine
function LTrim(szBuf)
{
	szBuf = String(szBuf);
	return szBuf.replace (/^([ ]*)/, "");
}

// Limite la longueur maximum de saisie
function LimitLength(oInput, iMaxLength){

    if(oInput.value.length >= iMaxLength)
    {
        oInput.value = oInput.value.substring(0,iMaxLength-1); 
    } 
}