////////////////////////////
// Fonction Verif formulaire
////////////////////////////
function verifierForm(formObj) {
for (i=0;i<formObj.length;i++)
if (formObj.elements[i].value=="" |
	formObj.elements[i].value=="Invalid") {
	alert("Tous les champs n'ont pas été remplis")
	formObj.elements[i].focus()
return
}
formObj.submit()
}
////////////////////////////


////////////////////////////////////////
// Fonction CHECK ALL pour les checkbox
////////////////////////////////////////
//formulaire -> c'est le nom du formulaire
//champ -> c'est une partie du nom du champ (sans les [])
////////////////////////////////////////
function checkall(formulaire, champ){
   temp = formulaire.elements.length;
   if (formulaire.elements[0].checked){
	   	for (i=1; i < temp; i++){
				if (formulaire.elements[i].name.indexOf(champ)>-1){
       		formulaire.elements[i].checked=1;
				}
    	}
   }else{
      for (i=1; i < temp; i++){
				if (formulaire.elements[i].name.indexOf(champ)>-1){
       		formulaire.elements[i].checked=0;
				}	
    	}
   }
}
////////////////////////////////////////


function alert_lien(chemin, message){
// Cette fonction doit être utilisée UNIQUEMENT pour les messages d'alerte sur DES LIENS HREF
// + chemin représente l'URL vers lequel doit aller la page
// + message représente le message d'alerte qui sera envoyé aux utilisateurs
	goahead=confirm(message); 
	if (goahead==1){
		document.location.href=chemin;
	}
}

function alert_form(message){
// Cette fonction doit être utilisée UNIQUEMENT pour les messages d'alerte sur DES FORMULAIRES
// à mettre avec l'évènement onSubmit sur la balise html FORM
// + message représente le message d'alerte qui sera envoyé aux utilisateurs
	if (confirm(message)) {
		return true; 
	}else{
		return false;
	} 
}
/*
SCRIPT POUR FORMATAGE dates JAVASCRIPT
<input name="ladate" type="text" size="10" maxlength="10" onKeyUp="DateFormat(this, this.value)"
onKeypress="OnlyNumeric(this, this.value)" onBlur="VerifDate(this, this.value)">
*/
function OnlyNumeric(NameTextbox, DateValue){
    if (!DateValue) return false;
    var Chars = "0123456789/";
    for (var i = 0; i < DateValue.length; i++) {
        if (Chars.indexOf(DateValue.charAt(i))!=-1)
        return false;
    }
    return true;
}
function HeureFormat(NameTextbox, HeureValue){
    if (OnlyNumeric(NameTextbox, HeureValue)){
        NameTextbox.value = NameTextbox.value.substr(0, (HeureValue.length-1));
    }else{
        if (HeureValue.length==2){
            NameTextbox.value+=":";
        }
    }
}

function DateFormat(NameTextbox, DateValue){
    if (OnlyNumeric(NameTextbox, DateValue)){
        NameTextbox.value = NameTextbox.value.substr(0, (DateValue.length-1));
    }else{
        if ((DateValue.length==2) || (DateValue.length==5)){
            NameTextbox.value+="/";
        }
    }
}
function VerifHeure(NameTextbox, HeureValue){
    var Heure=NameTextbox.value.substr(0,2);
    var Minute=NameTextbox.value.substr(3,2);
    if (Heure.length == 1) {
        Heure='0' + Heure;
    }
    if (Minute.length == 1) {
        Minute='0' + Minute;
    }
    if(((Heure<0) || (Heure>23)) || ((Minute<0) || (Minute>59))){
        alert("L'heure n'a pas le format correct (hh:mm) ou n'est pas une heure valide");
    }else{
        NameTextbox.value=Heure + ':' + Minute;
    }
}
function VerifDate(NameTextbox, DateValue){
    if (DateValue.length>7){
        var Jour=NameTextbox.value.substr(0,2);
        var Mois=NameTextbox.value.substr(3,2);
        var Annee=NameTextbox.value.substr(6,4);
        if (Annee.length == 2) {
            var Today = new Date();
            var checkAnnee=Today.getFullYear() + 30;
            var mCheckYear='20' + Annee;
            if (mCheckYear>=checkAnnee){
                Annee='19' + Annee;
            }else{
                Annee='20' + Annee;
            }
        }
        if (CheckDate(DateValue)){
            NameTextbox.value=Jour + "/" + Mois + "/" + Annee;
        }else{
            alert("La date n'a pas le format correct (jj/mm/aaaa) ou n'est pas une date valide");
        }
    }
}

function CheckDate(DateValue) {
    correct = true;
    if ( (DateValue.length < 11) && (DateValue.length > 7) ) {
        j = DateValue.substring(0,2);
        m = DateValue.substring(3,5);
        a = DateValue.substring(6,DateValue.length);
        bi = ((parseInt(a) % 4) == 0);

        if (((m == "01") || (m == "03") || (m == "05") || (m == "07") || (m == "08") || (m == "10") || (m == "12") ) && ( (Math.round(j) >= 1) && (Math.round(j) <= 31))){
            correct = true;
        }else{
            if (((m == "04") || (m == "06") || (m == "09") || (m == "11")) && ((Math.round(j) >= 1) && (Math.round(j) <= 30))){
                correct = true;
            }else{
                if (bi){
                    correct = (((Math.round(j) >= 1) && (Math.round(j) <= 29)) && (m == "02"));
                }else {
                    correct = (((Math.round(j) >= 1) && (Math.round(j) <= 28)) && (m == "02"));
                }
            }
        }
    }else{
        correct = false;
    }
    return correct;
}



/*
SCRIPT qui permet de vérrouiller une listbox multiple
onmouseover="lock_listbox(this.form.elements['nomdelalistbox[]'])"
*/
function lock_listbox_multiple(formobj){
    var array_selected = new Array();
    for (i=0; i<formobj.options.length; i++) {
        if (formobj.options[i].selected){
            array_selected.push(formobj.options[i].value);
        }
    }
    formobj.onchange=function(){
        for (i=0; i<formobj.options.length; i++) {
            formobj.options[i].selected=false;
            for (j=0; j<array_selected.length; j++) {
                if (array_selected[j]==formobj.options[i].value){
                    formobj.options[i].selected=true;
                }
            }
        }

    }
    formobj.className="grise";
}


function lock_listbox(formobj){
    var chosen=formobj.options.selectedIndex;
    formobj.onchange=function(){
        formobj.options.selectedIndex=chosen;
    }
    formobj.className="grise";
}


// -------------------------------------------------------------------
// hasOptions(obj)
//  Utility function to determine if a select object has an options array
// -------------------------------------------------------------------
function hasOptions(obj) {
    if (obj!=null && obj.options!=null) { return true; }
    return false;
    }

// -------------------------------------------------------------------
// selectUnselectMatchingOptions(select_object,regex,select/unselect,true/false)
//  This is a general function used by the select functions below, to
//  avoid code duplication
// -------------------------------------------------------------------
function selectUnselectMatchingOptions(obj,regex,which,only) {
    if (window.RegExp) {
        if (which == "select") {
            var selected1=true;
            var selected2=false;
            }
        else if (which == "unselect") {
            var selected1=false;
            var selected2=true;
            }
        else {
            return;
            }
        var re = new RegExp(regex);
        if (!hasOptions(obj)) { return; }
        for (var i=0; i<obj.options.length; i++) {
            if (re.test(obj.options[i].text)) {
                obj.options[i].selected = selected1;
                }
            else {
                if (only == true) {
                    obj.options[i].selected = selected2;
                    }
                }
            }
        }
    }

// -------------------------------------------------------------------
// selectMatchingOptions(select_object,regex)
//  This function selects all options that match the regular expression
//  passed in. Currently-selected options will not be changed.
// -------------------------------------------------------------------
function selectMatchingOptions(obj,regex) {
    selectUnselectMatchingOptions(obj,regex,"select",false);
    }
// -------------------------------------------------------------------
// selectOnlyMatchingOptions(select_object,regex)
//  This function selects all options that match the regular expression
//  passed in. Selected options that don't match will be un-selected.
// -------------------------------------------------------------------
function selectOnlyMatchingOptions(obj,regex) {
    selectUnselectMatchingOptions(obj,regex,"select",true);
    }
// -------------------------------------------------------------------
// unSelectMatchingOptions(select_object,regex)
//  This function Unselects all options that match the regular expression
//  passed in.
// -------------------------------------------------------------------
function unSelectMatchingOptions(obj,regex) {
    selectUnselectMatchingOptions(obj,regex,"unselect",false);
    }

// -------------------------------------------------------------------
// sortSelect(select_object)
//   Pass this function a SELECT object and the options will be sorted
//   by their text (display) values
// -------------------------------------------------------------------
function sortSelect(obj) {
    var o = new Array();
    if (!hasOptions(obj)) { return; }
    for (var i=0; i<obj.options.length; i++) {
        o[o.length] = new Option( obj.options[i].text, obj.options[i].value, obj.options[i].defaultSelected, obj.options[i].selected) ;
        }
    if (o.length==0) { return; }
    o = o.sort(
        function(a,b) {
            if ((a.text+"") < (b.text+"")) { return -1; }
            if ((a.text+"") > (b.text+"")) { return 1; }
            return 0;
            }
        );

    for (var i=0; i<o.length; i++) {
        obj.options[i] = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
        }
    }

// -------------------------------------------------------------------
// selectAllOptions(select_object)
//  This function takes a select box and selects all options (in a
//  multiple select object). This is used when passing values between
//  two select boxes. Select all options in the right box before
//  submitting the form so the values will be sent to the server.
// -------------------------------------------------------------------
function selectAllOptions(obj) {
    if (!hasOptions(obj)) { return; }
    for (var i=0; i<obj.options.length; i++) {
        obj.options[i].selected = true;
        }
    }

// -------------------------------------------------------------------
// moveSelectedOptions(select_object,select_object[,autosort(true/false)[,regex]])
//  This function moves options between select boxes. Works best with
//  multi-select boxes to create the common Windows control effect.
//  Passes all selected values from the first object to the second
//  object and re-sorts each box.
//  If a third argument of 'false' is passed, then the lists are not
//  sorted after the move.
//  If a fourth string argument is passed, this will function as a
//  Regular Expression to match against the TEXT or the options. If
//  the text of an option matches the pattern, it will NOT be moved.
//  It will be treated as an unmoveable option.
//  You can also put this into the <SELECT> object as follows:
//    onDblClick="moveSelectedOptions(this,this.form.target)
//  This way, when the user double-clicks on a value in one box, it
//  will be transferred to the other (in browsers that support the
//  onDblClick() event handler).
// -------------------------------------------------------------------
function moveSelectedOptions(from,to) {
    // Unselect matching options, if required
    if (arguments.length>3) {
        var regex = arguments[3];
        if (regex != "") {
            unSelectMatchingOptions(from,regex);
            }
        }
    // Move them over
    if (!hasOptions(from)) { return; }
    for (var i=0; i<from.options.length; i++) {
        var o = from.options[i];
        if (o.selected) {
            if (!hasOptions(to)) { var index = 0; } else { var index=to.options.length; }
            to.options[index] = new Option( o.text, o.value, false, false);
            }
        }
    // Delete them from original
    for (var i=(from.options.length-1); i>=0; i--) {
        var o = from.options[i];
        if (o.selected) {
            from.options[i] = null;
            }
        }
    if ((arguments.length<3) || (arguments[2]==true)) {
        sortSelect(from);
        sortSelect(to);
        }
    from.selectedIndex = -1;
    to.selectedIndex = -1;
    }

// -------------------------------------------------------------------
// copySelectedOptions(select_object,select_object[,autosort(true/false)])
//  This function copies options between select boxes instead of
//  moving items. Duplicates in the target list are not allowed.
// -------------------------------------------------------------------
function copySelectedOptions(from,to) {
    var options = new Object();
    if (hasOptions(to)) {
        for (var i=0; i<to.options.length; i++) {
            options[to.options[i].value] = to.options[i].text;
            }
        }
    if (!hasOptions(from)) { return; }
    for (var i=0; i<from.options.length; i++) {
        var o = from.options[i];
        if (o.selected) {
            if (options[o.value] == null || options[o.value] == "undefined" || options[o.value]!=o.text) {
                if (!hasOptions(to)) { var index = 0; } else { var index=to.options.length; }
                to.options[index] = new Option( o.text, o.value, false, false);
                }
            }
        }
    if ((arguments.length<3) || (arguments[2]==true)) {
        sortSelect(to);
        }
    from.selectedIndex = -1;
    to.selectedIndex = -1;
    }

// -------------------------------------------------------------------
// moveAllOptions(select_object,select_object[,autosort(true/false)[,regex]])
//  Move all options from one select box to another.
// -------------------------------------------------------------------
function moveAllOptions(from,to) {
    selectAllOptions(from);
    if (arguments.length==2) {
        moveSelectedOptions(from,to);
        }
    else if (arguments.length==3) {
        moveSelectedOptions(from,to,arguments[2]);
        }
    else if (arguments.length==4) {
        moveSelectedOptions(from,to,arguments[2],arguments[3]);
        }
    }

// -------------------------------------------------------------------
// copyAllOptions(select_object,select_object[,autosort(true/false)])
//  Copy all options from one select box to another, instead of
//  removing items. Duplicates in the target list are not allowed.
// -------------------------------------------------------------------
function copyAllOptions(from,to) {
    selectAllOptions(from);
    if (arguments.length==2) {
        copySelectedOptions(from,to);
        }
    else if (arguments.length==3) {
        copySelectedOptions(from,to,arguments[2]);
        }
    }

// -------------------------------------------------------------------
// swapOptions(select_object,option1,option2)
//  Swap positions of two options in a select list
// -------------------------------------------------------------------
function swapOptions(obj,i,j) {
    var o = obj.options;
    var i_selected = o[i].selected;
    var j_selected = o[j].selected;
    var temp = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
    var temp2= new Option(o[j].text, o[j].value, o[j].defaultSelected, o[j].selected);
    o[i] = temp2;
    o[j] = temp;
    o[i].selected = j_selected;
    o[j].selected = i_selected;
    }

// -------------------------------------------------------------------
// moveOptionUp(select_object)
//  Move selected option in a select list up one
// -------------------------------------------------------------------
function moveOptionUp(obj) {
    if (!hasOptions(obj)) { return; }
    for (i=0; i<obj.options.length; i++) {
        if (obj.options[i].selected) {
            if (i != 0 && !obj.options[i-1].selected) {
                swapOptions(obj,i,i-1);
                obj.options[i-1].selected = true;
                }
            }
        }
    }

// -------------------------------------------------------------------
// moveOptionDown(select_object)
//  Move selected option in a select list down one
// -------------------------------------------------------------------
function moveOptionDown(obj) {
    if (!hasOptions(obj)) { return; }
    for (i=obj.options.length-1; i>=0; i--) {
        if (obj.options[i].selected) {
            if (i != (obj.options.length-1) && ! obj.options[i+1].selected) {
                swapOptions(obj,i,i+1);
                obj.options[i+1].selected = true;
                }
            }
        }
    }

// -------------------------------------------------------------------
// removeSelectedOptions(select_object)
//  Remove all selected options from a list
//  (Thanks to Gene Ninestein)
// -------------------------------------------------------------------
function removeSelectedOptions(from) {
    if (!hasOptions(from)) { return; }
    for (var i=(from.options.length-1); i>=0; i--) {
        var o=from.options[i];
        if (o.selected) {
            from.options[i] = null;
            }
        }
    from.selectedIndex = -1;
    }

// -------------------------------------------------------------------
// removeAllOptions(select_object)
//  Remove all options from a list
// -------------------------------------------------------------------
function removeAllOptions(from) {
    if (!hasOptions(from)) { return; }
    for (var i=(from.options.length-1); i>=0; i--) {
        from.options[i] = null;
        }
    from.selectedIndex = -1;
    }

// -------------------------------------------------------------------

// addOption(select_object,display_text,value,selected)
//  Add an option to a list
// -------------------------------------------------------------------
function addOption(obj,text,value,selected) {
    if (obj!=null && obj.options!=null) {
        obj.options[obj.options.length] = new Option(text, value, false, selected);
	}
}


// liste déroulante avec redirection
function openURL(formObj){
    selInd=formObj.selectedIndex;
    goURL=formObj.options[selInd].value;
    document.location.href=goURL;
}


function bookmarksite(title, url){
if (document.all)
	window.external.AddFavorite(url, title);
else if (window.sidebar)
	window.sidebar.addPanel(title, url, "")
}

function texte_compteur(limitField, limitCount, limitNum){
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}
/* Menu à onglets */
function multiClass(eltId){
	arrLinkId = new Array('_0','_1','_2');
	intNbLinkElt = new Number(arrLinkId.length);
	arrClassLink = new Array('current','ghost');
	strContent = new String()
	for (i=0; i<intNbLinkElt; i++) {
		strContent = "menu"+arrLinkId[i];
		if ( arrLinkId[i] == eltId ) {
			document.getElementById(arrLinkId[i]).className = arrClassLink[0];
			document.getElementById(strContent).className = 'on content';
		} else {
			document.getElementById(arrLinkId[i]).className = arrClassLink[1];
			document.getElementById(strContent).className = 'off content';
		}
	}	
}

function popup(url) {
	window.open(url, "myWindow","height=450,width=920,menubar=no,status=no,scrollbars=yes,resizable=yes");
}
function hidden_tableau(action, array_data){
	tableau=array_data.split(',');
	for(var i=0; i<tableau.length; i++) {
		Obj=document.getElementById(tableau[i]);
		if(action=='hidden'){
			Obj.style.visibility='hidden';
			Obj.style.display='none';
		}else{
			Obj.style.visibility='visible';
			Obj.style.display='';
		}
	}
} 
