function MM_openBrWindow(theURL,winName,features) 
{
  window.open(theURL,winName,features);
}

function GetNumSynchro()
{
var serverName = window.location.hostname;
var pathNom = window.location.pathname;
if (pathNom.substr(0,10) == "/pcnettest")
{
    var url = "http://"+serverName+"/pcnettest/commun_ajax_action.php?ACTION=SYNCHRO";
}
else
{
    var url = "http://"+serverName+"/pcnet/commun_ajax_action.php?ACTION=SYNCHRO";
}

var xhr = null; 
     
    if(window.XMLHttpRequest) // Firefox et autres
       xhr = new XMLHttpRequest(); 
    else if(window.ActiveXObject){ // Internet Explorer 
       try {
                xhr = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                xhr = new ActiveXObject("Microsoft.XMLHTTP");
            }
    }
    else { // XMLHttpRequest non supporté par le navigateur 
       alert("Votre navigateur n'est pas compatible avec cette application..."); 
       xhr = false; 
    }
xhr.open("POST",url, false );
xhr.send("");
var numsynchro=xhr.responseText;
return numsynchro;
}

function actionPage(formulaire,destination,action)
{
  numsynchro = GetNumSynchro();
  Form = eval("document."+formulaire);
	Form.elements["PARAM_Destination"].value = destination;
	Form.elements["PARAM_Action"].value = action;
	Form.elements["PARAM_NumSynchro"].value = numsynchro;
	Form.submit();
}

function OpenSychroWindows(page,w,h)
{
    NumSynchro=GetNumSynchro();
    window.open(page+'?NumSynchro='+NumSynchro+'','PetC','menubar=no, status=no, directories=no, location=no, resizable=yes, scrollbars=no, menubar=no, width=' + w + ', height=' + h);
}

function highLight(item)
{
    document.getElementById(item).style.backgroundColor = "99FFF3";
}

function lowLight(item)
{
    document.getElementById(item).style.backgroundColor = "";
}

function swichDiv(newItem)
{
    newAdrItem = "DivAdr_" + newItem;
    newNameItem = "DivName_" + newItem;
    oldItem = document.getElementById("oldValue").value;
    oldAdrItem = "DivAdr_" + oldItem;
    oldNameItem = "DivName_" + oldItem;
    if (oldItem != "")
    {
    document.getElementById(oldAdrItem).style.visibility = "hidden";
    document.getElementById(oldNameItem).style.backgroundColor = "white";
    }
    document.getElementById("oldValue").value = newItem;
    if (newItem != "")
    {
    document.getElementById(newAdrItem).style.visibility = "visible";
    document.getElementById(newNameItem).style.backgroundColor = "yellow";
    }
}

//multiselect pour les compétences
function multiselect_champs(champs,champs_affiche){
   //on récupère l'endroit sélectionner dans le select source
    selection = champs.selectedIndex;
    if(selection != -1){
        //on déselectionne tous les champs du select de destination où va être placer le(s) champ(s) selectionner
        while(champs_affiche.selectedIndex != -1){
            champs_affiche.options[champs_affiche.selectedIndex].selected = false;
        }

        while(champs.selectedIndex > -1){
            if(champs.options[champs.selectedIndex].value == "Id_type_bien"){
                champs.options[champs.selectedIndex] = null;
                champs.form.Id_categorie_bien.options[0].select= true;
            }else{
                //on cherche la place de notre champ
                for(place=0;place<champs_affiche.length;place++){
                    if(champs_affiche.options[place].text > champs.options[champs.selectedIndex].text){
                        break;
                    }
                }
                //on décale tous les champs
                for(i=champs_affiche.length;i>place;i--){
                    champs_affiche.options[i] = new Option(champs_affiche.options[(i-1)].text,champs_affiche.options[(i-1)].value);
                }

                //on insère le champ selectionner
                champs_affiche.options[place] = new Option(champs.options[champs.selectedIndex].text,champs.options[champs.selectedIndex].value);
                champs.options[champs.selectedIndex] = null;
                champs_affiche.options[place].selected = true;
            }
        }

        if(champs.length > 0){
            if(selection >= champs.length ){
                selection = champs.length-1;
            }
            champs.options[selection].selected = true;
        }
    }
}

function multiselect_all(frm){
    for(i=0;i<frm.liste_champs.length;i++){
        frm.liste_champs.options[i].selected = true;
    }
    frm.liste_champs.name = "liste_champs[]";

    for(i=0;i<frm.selection.length;i++){
        frm.selection.options[i].selected = true;
    }
    frm.selection.name = "selection[]";
}

function multiselect_priorite(selection,mode){
    if(selection.length < 2 ){return;}
    old_place = selection.selectedIndex;
    if(mode == 'up' && old_place > 0){
        new_place = old_place-1;
    }else if(mode == 'down' && old_place < selection.length-1){
        new_place = old_place+1;
    }
    
    tmp = new Option(selection.options[new_place].text,selection.options[new_place].value);
    selection.options[new_place] = new Option(selection.options[old_place].text,selection.options[old_place].value);
    selection.options[old_place] = new Option(tmp.text,tmp.value);
    selection.options[new_place].selected = true;
}
