 //////////////////////
// GENERAL
//////////////////////

function gId(id) {
return document.getElementById(id);
}

function affload() {
MM_showHideLayers('loading','','show');
};

function infoload(t) {
affload();MM_setTextOfLayer('loading_info','',t);
};
document.write("<div id='loading' class=noprint style='position:"+((navigator.appName.indexOf("Microsoft")!=-1)?"absolute":"fixed")+"; z-index:9999; width: 90%; height: 22px; left: 5%;bottom: 0px; background-color: #f0f0f0; border:1px solid #ccc;filter:Alpha(Opacity=30%);' align=center valign=middle><img src="+images_path+"3/loading.gif height=18 width=18><div style=display:inline; id='loading_info'>...</div></div>");

var nocontent;


function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}


function MM_showHideObject(obj,v) { //v6.0
obj.disabled=(v=='show')?'false':'true';
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; 
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; if (d.forms) for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  if (d.layers) for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_setTextOfLayer(objName,x,newText,preserve) { //v4.01
if (!preserve) newText=unescape(newText); //else alert(newText);
  if ((obj=MM_findObj(objName))!=null) with (obj)
    if (document.layers) {document.write(newText); document.close();}
    else innerHTML = newText;
}

function MM_changeProp(objName,x,theProp,theValue) { //v6.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)) {
    if (obj.style) obj=obj.style;
    if (theProp && theValue!='' && theValue!='undefined' && (theValue == true || theValue == false)) {
      eval("obj."+theProp+"="+theValue);
    }
    else if (theProp) {
    eval("obj."+theProp+"=unescape('"+escape(theValue)+"');");
    }
  }
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function titre(colbord,colfond,titre,espace,picto,apres,classe,helpid) {
if (!espace) {espace=0;};
if (apres || helpid>0) document.write("<table border=0 cellspacing=0 cellpadding=0><tr valign=bottom><td align=left>");
document.write("<img src="+images_path+"pix.gif height=2 width=2>");
if (colbord) document.write("<table border=0 cellspacing="+espace+" cellpadding=1><tr><td bgcolor="+colbord+">");
document.write("<table border=0 cellspacing=0 cellpadding=2");
//if (classe) document.write(" class="+classe);
document.write("><tr><td");
if (colfond) document.write(" bgcolor="+colfond);
if (classe) document.write(" class="+classe);
document.write(">");
document.write(titre);
if (colbord) document.write("</td></table>");
document.write("</td></table>\n");
if (apres) document.write("</td><td align=right>"+apres);//+"<font size=-2>&nbsp;&nbsp;</font>");
if (apres || helpid>0) document.write("</td></table>");
};


function email_open(url,name,args) {
 window.open(((args)?"index.php?"+args:url),name,'width=700,height=560,menubar=no,scrollbars=yes,status=yes,resizable=yes'); 
};

function news_open(ext,id,taille,editer,dans_news) {
var target=id;
if (editer==1) {ext="&ss=article_edition&"+ext;target+="edit";} else {ext="&ss=article_affichage&"+ext;target+="aff";};
if (editer && dans_news==1) target="_self";
var url='index.php?s=1&nomenu=1'; if (id) url+='&id='+id;
if (!taille) taille="width=600,height=500";
window.open(url+ext,target,taille+',resizable=yes,menubar=no,status=no,scrollbars=yes');
};

function help(id) {
};


function news_op(id,dans_news) {
	news_open('',id,'','',dans_news);
	return false;
};

function news_outils(id,idgroupe,lu,pj,ext,type,editer,taille,cible,sousnews,editfile,dans_news,envoi,valide) {
//if (editer==1) document.write("<a href=# onclick=\"news_open('"+ext+"&idgroupe="+idgroupe+"',"+id+",'"+taille+"',1,"+dans_news+");return false;\"><img src="+images_path+"boutons/bouton_news_editer.gif width=28 height=17 border=0 alt=\"Editer ce document\"></a>");
//if (envoi!=0) document.write("<a href=# onclick=\"email_open('index.php?s=5&ss=ecrire&nomenu=1&idarticle="+id+ext+"&idgroupe="+idgroupe+"','');return false;\"><img src="+images_path+"boutons/bouton_news_email.gif width=28 height=17 border=0 alt=\"Envoyer ce document par courrier électronique\"></a>");
};



function winopen(args,taille,name,method)
{ if (!name) name='';
  if (method=="POST") {
  	w=window.open("",name,"resizable=yes,scrollbars=yes,status=no,menubar=no,"+taille);
	w.document.write('<form method=post action=index.php name=foauto><input type=hidden name=parse value=\"'+args+'\"><input type=submit value=Go></form>');
	w.document.foauto.submit();
  } else {
  	window.open("index.php?"+args,name,"resizable=yes,scrollbars=yes,status=no,menubar=no,"+taille);
  };
  return false;
};

function printopen(ext,modele) {
if (modele>0) ext+="&print="+modele; else ext+="&print=-1";
window.open("?"+ext,'','width=640,height=452,resizable=yes,scrollbars=yes,status=no,location=no,menubar=yes');
};
function rappel_login(iddest,cachepasse,ext)
{
if (!iddest) iddest="";
window.open("index.php?s=2&ss=rappel_login&nomenu=1&idcontact="+iddest+"&cachepasse="+cachepasse+"&"+ext,'wremlogin','width=300,height=200,scrollbars=auto,menubar=no,status=no');
};

function edithtml(what,id,ext) {
window.open("?lib=edithtml.php&w=550&h=350&path="+what+"&id="+id+ext,"edithtml"+id,"width=600,height=500,menubar=no,status=yes,scrollbars=yes,resizable=yes");
};

function open_postit(editer,a,a_sens,action,titre) {
if (!a_sens) a_sens=1;
if (!action) action="ecrire";
if (!titre) titre="note"+editer;
if (action=='ecrire' || document.cookie.indexOf('postitopen['+editer+']=1')==-1) {
w=window.open('index.php?s=0&ss=notes&action='+action+'&nomenu=1&id='+editer+'&postita='+a+'&a_sens='+a_sens,titre,'width=440,height=260,menubar=no,scrollbars=yes,status=no,resizable=yes');
}// else w=eval('note'+editer);
//if (w && w!="undefined") w.focus();
};

function alert_init() {
if (MM_findObj("ifral")) { tal=setTimeout("ifral.location='./?lib=cron.php';",30000); } //tal=setTimeout("ifral.location='./?shared=cron.php';alert_init();",120000);popup=1&nojs=1
else {tal=setTimeout("alert_init();",1000);};
};

function printit(nsmess,iemess,othermess){
    window.print();
};

var domot,domota,domotw=new Array(),domoth=new Array();
function sh(o,v,noinline,oheight) {
if (document.getElementById(o)) {
	if (!v && v!='0') {noinline=1;v=(document.getElementById(o).style.overflow=='hidden')?1:0;}
	if (v=='auto') {if (document.getElementById(o).oheight) v=0; else v=1;
	}
	if (v) {
	
		if (oheight) document.getElementById(o).oheight=oheight;
		if (!document.getElementById(o).oheight) document.getElementById(o).oheight=document.getElementById(o).style.height;
		if (!document.getElementById(o).oheight) document.getElementById(o).oheight=document.getElementById(o).height;
		if (domota) eval(domota);clearTimeout(domot);document.getElementById(o).style.overflow='visible';
		if (!noinline) { document.getElementById(o).style.display='inline';document.getElementById(o).style.zIndex=999;} else document.getElementById(o).style.height='';}
	else {	
	
		document.getElementById(o).style.overflow='hidden';document.getElementById(o).style.zIndex=1;
		if (document.getElementById(o).oheight) {
		document.getElementById(o).style.height=document.getElementById(o).oheight;
		}
		 else {
		 //domota+="document.getElementById('"+o+"').style.height=0;";
		 document.getElementById(o).style.height=1;
		 }
	};
}
};

function shh(divn,show) {
	if (show) { MM_showHideLayers(divn,'','show');MM_changeProp(divn,'','overflow','visible');MM_changeProp(divn,'','height',''); } else { MM_showHideLayers(divn,'','hide');MM_changeProp(divn,'','overflow','hidden'); };
};
function sho(divn,show) {
	if (show) { MM_showHideLayers(divn,'','show'); } else { MM_showHideLayers(divn,'','hide'); };
};
function shs(divn,show) {
	if (show) { MM_changeProp(divn,'','overflow','auto'); } else { MM_changeProp(divn,'','overflow','hidden');};
};

function shb(o,v,top) {
	if (v) {
		clearTimeout(domot);
		if (!domoth[o] && document.getElementById(o).style.height) domoth[o]=document.getElementById(o).style.height;
		document.getElementById(o).style.height='';
		document.getElementById(o).style.overflow='visible';
		document.getElementById(o).style.position='absolute';
		if (top) document.getElementById(o).style.top=top;
		document.getElementById(o).style.zIndex=999;
	} else {	
		domota="document.getElementById('"+o+"').style.overflow='hidden';document.getElementById('"+o+"').style.position='';document.getElementById('"+o+"').style.zIndex=1;";
		if (domoth[o]) domota+="document.getElementById('"+o+"').style.height='"+domoth[o]+"'";
		eval(domota);
	};
};


function dateday(name,journame,ji) {
y=MM_findObj(name+'[2]').value;
if (!ji) ji=0;	
if (y>0 && (y<70 || y>=1970)) {           //
	d=new Date(y,MM_findObj(name+'[1]').selectedIndex-1,MM_findObj(name+'[0]').selectedIndex+ji);
	//alert(d.getDate()+" "+d.getMonth()+" "+d.getYear());
	MM_setTextOfLayer(journame,'',formdatejour[d.getDay()]);//MM_findObj(journame).selectedIndex=1+d.getDay();
	MM_findObj(name+'[0]').selectedIndex=d.getDate();
	MM_findObj(name+'[1]').selectedIndex=d.getMonth()+1;
y=d.getYear();
if (y>40 && y<999) y+=1900; else if (y>0 && y<40) y+=2000;
	MM_findObj(name+'[2]').value=y;
};
if (MM_findObj(name)) MM_findObj(name).value=y+"/"+(d.getMonth()+1)+"/"+d.getDate();
};

function news_valid(id,valid,dans_news) {
	ext="";if (dans_news) ext="&nomenu=1";
	if (valid==1) str="Validation de ce document"; else str="Refus de ce document";
	rep=prompt(str+"\nVotre commentaire: ","");
	if (rep!=null) window.location="index.php?s=1&ss=articles&classeur=101&action=valider&idvalide="+id+"&valide="+valid+"&rep="+escape(rep)+ext;

};

function choix_pseudo(champobj,champ,opt) {
var val='';
if (champ!="") {
	obj=MM_findObj(champ); val=obj.value;
	};
	w=window.open("",'choixpseudo'+champ.substring(0,3),'width=520,height=450,scrollbars=no,menubar=no,status=no,resizable=yes');
	if (w) {
		w.document.write('<link rel="stylesheet" type="text/css" href="index.php/shared/shared.css"><body><form method=post action=index.php name=foauto><input type=hidden name=parse value="nomenu=1&s=2&ss=choix_pseudo&seltout='+val+'&champ='+champ+opt+'">');//&effacrit=1
		if (val) {w.document.write('<input type=submit value=Go>');w.document.foauto.submit();}
		else w.document.write('Recherche rapide : <input type=text name=cherche size=30><br><input type=submit value="Valider directement cette recherche" onclick=foauto.miseajour_selectall.value=1;><input type=hidden name=miseajour_selectall value=0><br><input type=submit value="Vérifier la recherche ou Recherche avancée">');
	} else window.open('./?nomenu=1&s=2&ss=choix_pseudo&seltout='+val+'&champ='+champ+opt,'choixpseudo'+champ.substring(0,3),'width=520,height=450,scrollbars=no,menubar=no,status=no,resizable=yes');

//window.open('?nomenu=1&s=2&ss=choix_pseudo&effacrit=1&seltout='+val+'&champ='+champ+opt,'choixpseudo'+champ.substring(0,3),'width=520,height=350,scrollbars=yes,menubar=no,status=no,resizable=yes');
};

function choix_pseudo_onchange(o,opt,nom,formnom,ext) {
//alert(o+' '+o.type+' '+opt);
if (opt==-2) {o=MM_findObj(nom);var lo=prompt('id#/ref# ?',o.value); o.value=' '+lo+' ';if (o.options) o.options[o.selectedIndex].text+=' : '+lo;} 
else if (opt==-1) {choix_pseudo(formnom,nom,ext,0);if (o.options) o.selectedIndex=0;} 
else if (opt==-3) {choix_pseudo(formnom,nom,'&chtype=0&openenq=0&'+ext,1);if (o.options) o.selectedIndex=0;} 
else if (opt==-4) {choix_pseudo(formnom,nom,'&chtype=1&openenq=1&'+ext,1);if (o.options) o.selectedIndex=0;} 
else if (opt>=0) {o=MM_findObj(nom);o.value=opt;} 
else if (o.options) o.selectedIndex=0; 


}

var windoww=0,windowh=0;//=(nav)?window.innerWidth:document.body.offsetWidth,windowh=(nav)?window.innerHeight:document.body.offsetHeight;

if (parseInt(navigator.appVersion)>3) {
 if (navigator.appName=="Netscape") {
  windoww = window.innerWidth-16;
  windowh = window.innerHeight-16;
 }
 if (navigator.appName.indexOf("Microsoft")!=-1) {
 	function getiew() {
		  windoww = document.body.offsetWidth-20;
		  windowh = document.body.offsetHeight-20;
 	}
 	t=setTimeout('getiew();',10);
 }
}

function closeload() {
if (windowonload) eval(windowonload);
MM_showHideLayers('loading','','hide');
}

function selthis(o,s,a,e,bgcolorchecked) {
if (s==1) { 
 o.style.backgroundColor='#ccc'; 
 if (mousebutton) {s=2;ow_cancelstate=1;}
} else if (s==0) {
 var ocheck=findChild(o,"checkbox");if (ocheck && ocheck.checked) o.style.backgroundColor=(bgcolorchecked)?"#"+bgcolorchecked:'#bbb'; else o.style.backgroundColor='';
}
if (s==2) { 
var eventtype=evente.tagName.toLowerCase();
if (eventtype.length==1 && eventtype!="a") {eventtype=evente.parentNode.tagName.toLowerCase();}
if (!evente || (!(evente.type || evente.href || evente.onclick) && eventtype!="input" && eventtype!="a" && eventtype!="input" && eventtype!="select" && eventtype!="checkbox")) {
if (a) eval(a); else {var ocheck=findChild(o,"checkbox");if (ocheck && ocheck.click) ocheck.click();}
return false;
} 
}
}
function allownumbersonly(v) {
var r='';
for(var i=0;i<v.length;i++) {if (v.charAt(i)==",") r+="."; else if (v.charAt(i)=="." || v.charAt(i)=="-" || (v.charCodeAt(i)>="0".charCodeAt(0) && v.charCodeAt(i)<="9".charCodeAt(0) ) ) r+=v.charAt(i);}
return r;
}

function agenda_outils (ext,id,editer,valider,annuler,extc) {
if (editer)  {document.write("<a href=# onclick=\"agenda_open('"+ext+"&idagenda="+id+"');return false;\"><img src="+images_path+"3/modify.png width=28 height=17 border=0 alt=\"Editer\"></a>");};
};

function agenda_menu(ext,pastitre) {
document.write("<a href=# class=tool onclick=\"agenda_open('"+ext+"');return false;\"><img src="+images_path+"boutons/bouton_agenda_ecrire.gif width=27 height=17 border=0 alt=\"Nouveau rendez-vous\"></a>");
document.write("<a href=# onclick=\"window.open('index.php?s=3&ss=imprimer&nomenu=1&"+ext+"','agendaimprim','width=640,height=400,scrollbars=yes,status=no,menubar=no');return false;\"><img src="+images_path+"3/print.png width=27 height=17 border=0 alt=\"Imprimer l'agenda et les contacts associés\"></a>");
};

function agenda_open(ext) {
window.open('index.php?nomenu=1&'+ext+'&s=3&ss=ecrire','','width=700,height=350,scrollbars=yes,menubar=no,status=no,resizable=yes');
}
function ToggleAll(form,nam,like,foo) {
	var i=0,e;
	if (form!='' && document.getElementById(form)) form=document.getElementById(form);
 if (form && form!='undefined')
 {
  if (like=="false") var state=false; else if (like=="true") var state=true; else if (like) var state=like.checked; else var state=true;
  for (i=0;i<form.elements.length;i++) {
    e = form.elements[i];
    if (e.name != 'allbox' && e.type=='checkbox' && (!nam || e.name.substring(0,nam.length)==nam || e.id.substring(0,nam.length)==nam)) {
    	if (e.click && e.checked==false && state==true) e.click(); else e.checked=state;
    }
  }
 }
};

function getAbsolutePosition(element,nogetpos) {
    if (!nogetpos) nogetpos=0;
    var r = { x: element.offsetLeft, y: element.offsetTop,w: element.offsetWidth,h: element.offsetHeight }; 
    if (nogetpos<2 && element.offsetParent && element.scrollTop>12) { r.y -=element.scrollTop;}
    if (element.offsetParent) {
      var tmp = getAbsolutePosition(element.offsetParent,nogetpos+1);
      r.x += tmp.x;
      r.y += tmp.y; //if (tmp.scrollTop)  r.y -=tmp.scrollTop;
    }
    return r;
  };
  
function checkdivpos(en) {
	var pos=getAbsolutePosition(document.getElementById(en));
}
var ajax_oldhtml=new Array();
function ajaxopen(divname,url,width,height,submit_reload_divname,alturl,add_backbutton) {
var res='',noajax=0;
var basehref="."; 
if (!divname) divname='ajax';
if (add_backbutton==1) ajax_oldhtml[divname]=document.getElementById(divname).innerHTML;
if (o=document.getElementById(divname)) {
	MM_setTextOfLayer(divname,'','<img src='+images_path+'boutons/loader.gif style=position:absolute;z-index:99; width=16 height=16 alt="'+divname+','+url+'" />'+document.getElementById(divname).innerHTML);
     if (!url && o.attributes.getNamedItem('owajax')) url=o.attributes.getNamedItem('owajax').value;//'./?'+
     if (o.owajaxtimer) t=setTimeout("ajaxopen('"+divname+"')",o.owajaxtimer*1000);
     if(window.XMLHttpRequest) // FIREFOX
          xhr_object = new XMLHttpRequest(); 
     else if(window.ActiveXObject) // IE
          xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); 
     else noajax=1;//          return(false); 
     if (!noajax) {
     	if (width && height) {
     		MM_changeProp(divname,'','width',width);
     		MM_changeProp(divname,'','height',height);
     		MM_changeProp(divname,'','left',mousex);
			MM_changeProp(divname,'','top',mousey+10);
	     	MM_showHideLayers(divname,'','show');
	     	checkdivpos(divname);
	     	MM_setTextOfLayer(divname,'',"<div href=# style=background-color:#ccc;text-align:right;width:100%; onclick=MM_showHideLayers('ajax','','hide');MM_setTextOfLayers('ajax','','');>X</div>"+'<p><img src='+images_path+'boutons/loader.gif style=position:absolute;z-index:99; width=16 height=16 alt=... />');
     	}
     if (url.indexOf('?')<=0 && url.indexOf('/')<=5)      url=basehref+"/?"+url;
     xhr_object.open("GET", url+"&mode=ajax&reals="+s, false); 
     xhr_object.send(null);      
     if(xhr_object.readyState == 4) res=(xhr_object.responseText);
     }
     if (res) {
     	if (res.indexOf('noop')>0) {} else {//res.indexOf('error') || 
	     	var submitaction='';
		     if (width && height) {
		     	if (submit_reload_divname) submitaction="parent.ajaxopen('"+submit_reload_divname+"');";//\\\",1000);";
		     	res=res.replace("popup=","lib=").replace("</form","<input type=hidden name=aftersubmit value=\""+submitaction+"\"><input type=button value=Cancel onclick=MM_showHideLayers('ajax','','hide');MM_setTextOfLayers('ajax','','');></form").replace('method='," target=ifral onsubmit=\"MM_showHideLayers('"+divname+"','','hide');\" method=");//window.open('','recordthis','width=10,height=10');
		     	res="<div href=# style=background-color:#ccc;text-align:right;width:100%; onclick=MM_showHideLayers('ajax','','hide');MM_setTextOfLayers('ajax','','');><img src="+images_path+"arrows/x.gif width=7 height=7 alt=X /></div>"+res;
		     }
		     else if (add_backbutton==1) {
		     	res="<div href=# style=background-color:#ccc;height:12px;text-align:left;width:100%; onclick=MM_setTextOfLayer('"+divname+"','',ajax_oldhtml['"+divname+"']);><img align=right src="+images_path+"arrows/x.gif hspace=3 vspace=3 width=7 height=7 alt=X /><img src="+images_path+"arrows/l.gif hspace=3 vspace=3 width=7 height=7 alt=Close /></div>"+res;
		     }
	     	o.innerHTML=res;
	     	
     	}
     } else {
     	if (!alturl) alturl=url;
     	if (alturl!="none" && width && height) {
     		height+=30;width+=20;
     		winopen(alturl,'width='+width+',height='+height);
     	}
     }
}
     return false;
}