var semaphore=false;

function com(id) {mag=open('gestion/com.php?id='+id,'mag','width=450,height=500,status=no,scrollbars=YES,menubar=no,toolbar=no,location=no').focus();}
function recomand(id) {mag=open('gestion/recomand.php?id='+id,'mag','width=350,height=450,status=no,scrollbars=YES,menubar=no,toolbar=no,location=no').focus();}
function suppc(n) {mag=open('gestion/supp.php?cat='+n+'&t=c','mag','width=500,height=300,status=no,scrollbars=YES,menubar=no,toolbar=no,location=no').focus();}
function supps(id) {mag=open('gestion/supp.php?id='+id+'&t=s','mag','width=500,height=300,status=no,scrollbars=YES,menubar=no,toolbar=no,location=no').focus();}
function suppcom(id_com,id_site) {mag=open('../gestion/supp.php?id='+id_com+'&id_site='+id_site+'&t=com','mag','width=500,height=300,status=no,scrollbars=YES,menubar=no,toolbar=no,location=no').focus();}
function display_info(id) {mag=open('p_infos_site.php?id='+id,'info','width=900,height=550,status=no,scrollbars=YES,menubar=no,toolbar=no,location=no').focus();}
function compt_out(id) { parent.document.getElementById("RSIFrame").src='gestion/out.php?go=no&url_id='+id; }
function aller(formulaire) { location.href = formulaire.page.options[formulaire.page.selectedIndex].value; }
function vote(id) {mag=open('gestion/vote.php?id='+id+'&t=s','vote','width=250,height=100,status=no,scrollbars=NO,menubar=no,toolbar=no,location=no').focus();}

/* GESTION de la  Modif rapide */
function fast_site_edit(id,numero){
        RSIrefresh_site(id,numero,'edition');
}

function fast_site_cancel(id,numero){
        RSIrefresh_site(id,numero,'display');
}
function fast_site_verif(id,numero){
        RSIrefresh_site(id,numero,'verif');
}
function fast_site_dead(id,numero){
        RSIrefresh_site(id,numero,'dead');
}
// validation d'un element
function fast_site_valid(id,numero,to_confirm,message) {
        if (!to_confirm || confirm(message)==true) { RSIrefresh_site(id,numero,'activer'); }
}
// validation d'un categorie
function fast_cat_valid(id,to_confirm,message) {
        if (!to_confirm || confirm(message)==true) { RSIrefresh_cat(id,'activer'); }
}

// activation d'un user
function fast_user_activate(id,to_confirm,message,p) {
        if (!to_confirm || confirm(message)==true) { RSIrefresh_user(id,'activate',p); }
}
// desactivation d'un user
function fast_user_unactivate(id,to_confirm,message,p) {
        if (!to_confirm || confirm(message)==true) { RSIrefresh_user(id,'unactivate',p); }
}
// suppression d'un user
function fast_user_delete(id,to_confirm,message,p) {
        if (!to_confirm || confirm(message)==true) { RSIrefresh_user(id,'delete',p); }
}

/* FONCTIONS generique RSI */
//charge une site
function RSIrefresh_site(id,numero,action) {
        if (sem_get()) return alert("Wait, please");
        sem_ver();
        document.getElementById("site_" + id).innerHTML="Refresh in progress ...";
        setTimeout("document.getElementById('RSIFrame').src='gestion/gest_site.php?id=" + id + "&p=" + numero + "&action=" + action + "'",50);
}

function RSIrefresh_cat(id,action) {
        if (sem_get()) return alert("Wait, please");
        sem_ver();
        document.getElementById("cat_" + id).innerHTML="Refresh in progress ...";
        setTimeout("document.getElementById('RSIFrame').src='gestion/gest_cat.php?id=" + id + "&action=" + action + "'",50);
}
function RSIrefresh_user(id,action,p) {
        if (sem_get()) return alert("Wait, please");
        sem_ver();
        document.getElementById("user_" + id).innerHTML="Refresh in progress ...";
        setTimeout("document.getElementById('RSIFrame').src='../gestion/gest_user.php?id=" + id + "&action=" + action + "&p="+p+"'",50);
}

// fonction appelé par les pages gest_xxx.php qui s'auto met à jour
function RSIloadSourceFinish(ID_DIV,value) {
        sem_dever();
        window.parent.document.getElementById(ID_DIV).innerHTML=value;
}
/*SEMAPHORE */
function sem_ver() {
        parent.document.getElementById('SEM').innerHTML="VERROU";
        parent.document.getElementById('RSI_info').innerHTML="Refresh in progess, please Wait";
        parent.document.getElementById('RSI_info').style.visibility = "visible";
}

function sem_dever() {
        parent.document.getElementById('SEM').innerHTML="";
        parent.document.getElementById('RSI_info').innerHTML="";
        parent.document.getElementById('RSI_info').style.visibility = "hidden";
}
function sem_get() {
        if (parent.document.getElementById('SEM').innerHTML=="VERROU")
                return true;
                else return false;
}
// **************
function elt_preview(id,url,view) {
        if (view) {
                window.parent.document.getElementById('ifr_elt_'+id).src=url;
                window.parent.document.getElementById('ifr_elt_'+id).className = "ifr_on";
                window.parent.document.getElementById('ifr_elt_'+id).height = "300";
                window.parent.document.getElementById('un_prev_elt_'+id).style.visibility = "visible";
                window.parent.document.getElementById('prev_elt_'+id).style.visibility = "hidden";
                }
        else {
                window.parent.document.getElementById('ifr_elt_'+id).src=url;
                window.parent.document.getElementById('ifr_elt_'+id).className = "ifr_off";
                window.parent.document.getElementById('ifr_elt_'+id).height = "0";
                window.parent.document.getElementById('un_prev_elt_'+id).style.visibility = "hidden";
                window.parent.document.getElementById('prev_elt_'+id).style.visibility = "visible";
        }

}


function SelAll (){
for (var i=0;i<document.formu.elements.length;i++){
   var e = document.formu.elements[i];
    e.checked = 1;
    }
}

function UnSelAll (){
for (var i=0;i<document.formu.elements.length;i++){
    var e = document.formu.elements[i];
   e.checked = 0;
    }
}

function CheckSel(msg){
for (var i=0;i<document.formu.elements.length;i++)
         if (document.formu.elements[i].checked==1) return true;
if (msg!="") alert (msg);
return false;
}

function InvSelect() {
for (var i = 0; i < document.formu.elements.length; i++) {
   if(document.formu.elements[i].type == 'checkbox'){
     document.formu.elements[i].checked =!(document.formu.elements[i].checked);
   }
 }
}

function form_del(err_mess){
if (CheckSel("")){
        centrePop("poplist",400,450);
        document.formu.target="poplist";
        document.formu.action = "gestion/supp.php";
        }
}

function form_move(err_mess){
if (CheckSel("")){
        centrePop("poplist",400,450);
        document.formu.target="poplist";
        document.formu.action = "gestion/move.php";
        }
}

function form_valid(err_mess){
if (CheckSel("")){
        centrePop("poplist",400,450);
        document.formu.target="poplist";
        document.formu.action = "gestion/valid.php";
        }
}

function centrePop(name,largeur,hauteur) {
      var gauche = (screen.width - largeur)/2
      var haut =  (screen.height - hauteur)/2
      window.open("",name,"width="+largeur
         +",height="+hauteur+",left="+gauche
         +",top="+haut+",status=no,scrollbars=YES")
}

var url='http://';
function ChangeInputURL() {
if (document.formu.url.disabled==true){
                document.formu.url.disabled=false;
                document.formu.url.value=url;
        }
        else {
                url=document.formu.url.value;
                document.formu.url.disabled=true;
                document.formu.url.value="Note Mode - Pas d'Url";
                }
}

function clic(id){
        document.getElementById('s_'+id).innerHTML="- Vu";
           if(document.images)
                  (new Image()).src="gestion/out.php?go=no&url_id=" + id;
   return true;
}

function filtre_page(filtre,p) {
        location.href = '?p='+p+'&filtre='+filtre;
}

function ChangeIM(form,dossier){
        document.getElementById(1).innerHTML="<img src='"+dossier+form.im.options[form.im.selectedIndex].value+"'>";
}



