function winZoom(image,l,h,alt,mention,titre,margev) {
	inferieur = String.fromCharCode(60)
	ph=window.open("","ph", "scrollbars=no,status=no,toolbar=no,menubar=no,height="+(h)+",width="+l); 
	ph.document.open();
	ph.document.writeln("<HTML><HEAD><TITLE>"+titre+"</TITLE></HEAD>");
	ph.document.writeln('<BODY MARGINHEIGHT="0" MARGINWIDTH="0" LEFTMARGIN="0" TOPMARGIN="0" LINK="#FFFFFF" bgcolor="#FFFFFF" text="#ffffff" onBlur="self.close();">');
	ph.document.writeln('<CENTER><FONT FACE="Verdana,Geneva,Arial,Helvetica,sans-serif" SIZE="-1" COLOR="#696969"><IMG SRC="'+image+'" WIDTH='+l+' HEIGHT='+h+' ALT="'+alt+'" BORDER=0>');
	ph.document.writeln('</FONT>'+inferieur +'/BODY>'+inferieur +'/HTML>');
	ph.document.close();
}	
function winZoom2(image,titre) {
inferieur = String.fromCharCode(60);
titre=escape(titre);
ph=window.open("","ph", "scrollbars=no,status=no,toolbar=no,menubar=no,width=100,height=100");
ph.document.writeln('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">');
ph.document.writeln("<html><head>");
       ph.document.writeln(inferieur +'title>'+unescape(titre)+inferieur +'/title>'+inferieur +'/head>');
       ph.document.writeln('<body style="padding:0px 0px 0px 0px;margin:0px 0px 0px 0px;background-color:black;color:#ffffff;text-align:center" onBlur="self.close();" >');
ph.document.writeln("<script language=\"javascript\" type=\"text/javascript\">var i=new Image();i.src='"+image+"';function setSize(W, H) {window.resizeTo(W, H);var cp = document.createElement(\"div\");cp.style.position = \"absolute\";cp.style.width = \"0px\";cp.style.height = \"0px\";cp.style.right = \"0px\";cp.style.bottom = \"0px\";cp.style.margin=\"0px 0px 0px 0px\";cp.style.padding=\"0px 0px 0px 0px\";document.body.appendChild(cp);var current_width = cp.offsetLeft;var current_height = cp.offsetTop;var dw = W + document.body.clientWidth - current_width;var dh = H + document.body.clientHeight - current_height;window.resizeTo(dw+40, dh+20);document.body.removeChild(cp);return { missed_width: dw, missed_height: dh };}function f(){setSize(i.width,i.height);window.defaultStatus='"+escape(titre)+"';}");
       ph.document.writeln(inferieur +'/script>');
       ph.document.writeln('<img onload="f();" style=\"margin:0px\" src="'+image+'" name="image" border="0" alt="'+unescape(titre)+'"  />');
       ph.document.writeln(inferieur +'/body>'+inferieur +'/html>');
       ph.document.close();

}
function winZoom3(image,titre) {
       inferieur = String.fromCharCode(60)
       ph=window.open("","ph", "scrollbars=no,status=no,toolbar=no,menubar=no,width=100,height=100");
       ph.document.writeln("<HTML><HEAD><script language=javascript>var i=new Image();i.src='"+image+"';function f(){window.resizeTo(i.width+10,i.height+25);/*window.innerHeight=i.height;window.innerWidth=i.width;alert(i.height);alert(i.width);*/window.defaultStatus='"+titre+"';}</script><TITLE>"+titre+"</TITLE></HEAD>");
       ph.document.writeln('<BODY MARGINHEIGHT="0" MARGINWIDTH="0" LEFTMARGIN="0" TOPMARGIN="0" LINK="#FFFFFF" bgcolor="black" text="#ffffff" onBlur="self.close();" onload="f();">');
       ph.document.writeln('<CENTER><IMG SRC="'+image+'" name=image BORDER=0>');
       ph.document.writeln(inferieur +'/BODY>'+inferieur +'/HTML>');
       ph.document.close();
}


function winStream(file,l,h,titre,mime) {
        inferieur = String.fromCharCode(60)
        ph=window.open("","ph", "scrollbars=no,status=no,toolbar=no,menubar=no,resizable=yes,height="+(h)+",width="+l);
        ph.document.open();
        ph.document.writeln("<HTML><HEAD><TITLE>"+titre+"</TITLE></HEAD>");
        ph.document.writeln('<BODY MARGINHEIGHT="0" MARGINWIDTH="0" LEFTMARGIN="0" TOPMARGIN="0" LINK="#FFFFFF" bgcolor="#FFFFFF" text="#ffffff" >');
        ph.document.writeln('<embed id=ii type="'+mime+'" src="'+file+'" autostart="true" controls=true loop=-1 border=0 width='+l+' height='+h+'>');
        ph.document.writeln(inferieur +'/BODY>'+inferieur +'/HTML>');
        ph.document.close();
}
function winAction(url){
  var w = window.open('','action','width=400,height=400,scrollbars=yes,location=no,resizable=yes');
  w.location = url;
}
function sstree_toggle(elm,iopen,iclose) {
 var newDisplay = "none";
 if(iopen=='') iopen='/tzr/templates/images/folder-open.gif';
 if(iclose=='') iclose='/tzr/templates/images/folder-closed.gif';
 if(iopen=='none') iopen='';
 if(iclose=='none') iclose='';
 if(iclose!='none') elm.style.backgroundImage = 'url( '+iclose+' )';
 var e = elm.nextSibling; 
 while (e != null) {
  if (e.tagName == "OL" || e.tagName == "ol" || e.tagName == "ul" || e.tagName == "UL") {
   if (e.style.display == "none") {
    newDisplay = "block";
    if(iopen!='none') {elm.style.backgroundImage = 'url( '+iopen+' )';};
   }
   break;
  }
  e = e.nextSibling;
 }
 while (e != null) {
  if (e.tagName == "OL" || e.tagName == "ol" || e.tagName == "ul" || e.tagName == "UL") e.style.display = newDisplay;
  e = e.nextSibling;
 }
}

function sstree_toggleBullet(elm) {
 var newDisplay = "none";
 var e = elm.nextSibling; 
 while (e != null) {
  if (e.tagName == "OL" || e.tagName == "ol" || e.tagName == "UL" || e.tagName == "ul") {
   if (e.style.display == "none") newDisplay = "block";
   break;
  }
  e = e.nextSibling;
 }
 while (e != null) {
  if (e.tagName == "OL" || e.tagName == "ol" || e.tagName == "UL" || e.tagName == "ul") e.style.display = newDisplay;
  e = e.nextSibling;
 }
}



function sstree_collapseAll() {
  var lists = document.getElementsByTagName('OL');
  for (var j = 0; j < lists.length; j++) 
   lists[j].style.display = "none";
  lists = document.getElementsByTagName('UL');
  for (var j = 0; j < lists.length; j++) 
   lists[j].style.display = "none";
  var e = document.getElementById("root");
  e.style.display = "block";
}
function sstree_open(tag) {
  var lists = document.getElementsByTagName('A');
  for (var j = 0; j < lists.length; j++)
   if(lists[j].id==tag) sstree_toggle(lists[j],'','');
}


function writeInfo(i,s) {
  var obj = document.getElementById(i);
  obj.innerHTML=s;
}

if(typeof(TZR)=="undefined") TZR=new Object();
TZR.isFormOk=true;
TZR.formValidation=true;
TZR.validator=new Array();
TZR.dependency=new Object();
TZR.onsubmit=new Array();
// validation des formulaires
TZR.isShortTextValid = function (id,fmt,fieldlabel,color,linktext,listid) {
  var o = document.getElementById(id);
  var phrase = o.value;
  var resultat = fmt.test(phrase);
  if(linktext){
    o=document.getElementById(linktext);
  }
  if(!resultat) {
    if(o.isValid!==false){
      if(color.charAt(0)=='#') {
	o.obackgroundColor=o.style.backgroundColor;
	o.style.backgroundColor=color;
      } else {
	o.oclassName=o.className;
	o.className=color;
      }
    }
    o.isValid=false;
    TZR.isFormOk=false;
    return false;
  } else {
    if(color.charAt(0)=='#') {
      if(o.obackgroundColor) o.style.backgroundColor=o.obackgroundColor;
      else o.style.backgroundColor='';
    } else {
      if(o.oclassName) o.className=o.oclassName;
    }
    o.isValid=true;
    return true;
  }
}

// validation des formulaires
TZR.isLinkValid = function (id,fmt,fieldlabel,color,linktext,listid) {
  var o = document.getElementById(id);
  var typ=o.type;
  // Cas "radio" ou "checkbox"
  if(typ=="radio" || typ=="checkbox"){
    return TZR.isRadioValid(id,fmt,fieldlabel,color,linktext,listid);
  }else{
    var resultat = true;
    // Cas "un select"
    if(fmt=='compselect'){
      resultat = false;
      for(var i=0;i<o.options.length;i++){
	if(o.options[i]!=null && o.options[i].selected && o.options[i].value!=''){
	  resultat=true;
	  break;
	}
      }
    }else if(fmt=='') { // Cas "2 select non obligatoire"
      for(var i=0;i<o.options.length;i++) if(o.options[i]!=null) o.options[i].selected=true;
    } else if(fmt=='/(.+)/') { // Cas "2 select obligatoire"
      if(o.options.length==0) resultat=false;
      else for(var i=0;i<o.options.length;i++) if(o.options[i]!=null) o.options[i].selected=true;
    } else { // Autre cas : autocomplete, lien base doc...
      var phrase = o.value;
      var resultat = fmt.test(phrase);
      if(linktext){
	o=document.getElementById(linktext);
      }
    }
    if(!resultat) {
      if(o.isValid!==false){
	if(color.charAt(0)=='#') {
	  o.obackgroundColor=o.style.backgroundColor;
	  o.style.backgroundColor=color;
	} else {
	  o.oclassName=o.className;
	  o.className=color;
	}
      }
      o.isValid=false;
      TZR.isFormOk=false;
      return false;
    } else {
      if(color.charAt(0)=='#') {
	if(o.obackgroundColor) o.style.backgroundColor=o.obackgroundColor;
	else o.style.backgroundColor='';
      } else {
	if(o.oclassName) o.className=o.oclassName;
      }
      o.isValid=true;
      return true;
    }
  }
}
TZR.isRadioValid = function (id,fmt,fieldlabel,color,linktext,listid) {
  var resultat=false;
  var o=document.getElementById(id);
  var l=listid.length;
  for(var i=0;i<l;i++){
    if(document.getElementById(listid[i]).checked){
      resultat=true;
      break;
    }
  }
  var tab=TZR.getParent(o,'TABLE');
  if(!resultat){
    if(o.isValid!==false){
      if(color.charAt(0)=='#') {
	tab.obackgroundColor=tab.style.backgroundColor;
	tab.style.backgroundColor=color;
      } else {
	tab.oclassName=tab.className;
	tab.className=color;
      }
    }
    o.isValid=false;
    TZR.isFormOk=false;
    return false;
  } else {
    if(color.charAt(0)=='#') {
      if(tab.obackgroundColor) tab.style.backgroundColor=tab.obackgroundColor;
      else tab.style.backgroundColor='';
    } else {
      if(tab.oclassName) tab.className=tab.oclassName;
    }
    o.isValid=true;
    return true;
  }
}
TZR.isThesaurusValid=function(id,fmt,fieldlabel,color){
  var o=document.getElementById("div"+id);
  var ok=false;
  jQuery('#table'+id+" input").each(function(i){
    if(this.value!=''){
      ok=true;
      return false;
    }
  });
  if(!ok){
    if(o.isValid!==false){
      if(color.charAt(0)=='#') {
	o.obackgroundColor=o.style.backgroundColor;
	o.style.backgroundColor=color;
      } else {
	o.oclassName=o.className;
	o.className=color;
      }
    }
    o.isValid=false;
    TZR.isFormOk=false;
    return false;
  } else {
    if(color.charAt(0)=='#') {
      if(o.obackgroundColor) o.style.backgroundColor=o.obackgroundColor;
      else o.style.backgroundColor='';
    } else {
      if(o.oclassName) o.className=o.oclassName;
    }
    o.isValid=true;
    return true;
  }
} 
TZR.isCaptchaValid = function(id,fmt,fieldlabel,color){
  var response=0;
  o=document.getElementById(id);
  jQuery.ajax({async:false,
	       url:"/tzr/scripts/ajax8.php?class=XModTable&function=xmodtable_captcha",
	       cache:false,
	       data:{value:o.value,id:id},
	       success:function(resp){response=resp;}
  });
  if(response=='0') response=false;
  else response=true;
  if(!response) {
    document.getElementById("ca"+id).onclick();
    document.getElementById(id).value="";
    if(o.isValid!==false){
      if(color.charAt(0)=='#') {
	o.obackgroundColor=o.style.backgroundColor;
	o.style.backgroundColor=color;
      } else {
	o.oclassName=o.className;
	o.className=color;
      }
    }
    o.isValid=false;
    TZR.isFormOk=false;
    return false;
  } else {
    if(color.charAt(0)=='#') {
      if(o.obackgroundColor) o.style.backgroundColor=o.obackgroundColor;
      else o.style.backgroundColor='';
    } else {
      if(o.oclassName) o.className=o.oclassName;
    }
    o.isValid=true;
    TZR.isFormOk=true;
    return true;
  }
}
TZR.actualizeCaptcha=function(url,id){
  document.getElementById('cimg'+id).src=url+"?id="+id+"&"+(new Date()).getTime();
}
TZR.getUrlTitle=function(url,color){
  var urlu=document.getElementById("url"+url);
  var urll=document.getElementById("label"+url);
  urlu.style.backgroundImage="url('/tzr/templates/ico/general/indicator.gif')";
  urlu.style.backgroundPosition="right center";
  urlu.style.backgroundRepeat="no-repeat";
  var reg=/^((http.+)|(\/.*))$/;
  if(!reg.test(urlu.value)){
    urlu.obackgroundColor=urlu.style.backgroundColor;
    urlu.style.backgroundColor=color;
  }else{
    var title=TZR.file_get_contents('/tzr/scripts/ajax8.php?function=xurldef_getPageTitle&class=XUrlDef&url='+escape(urlu.value));
    if(title=="error"){
      urlu.obackgroundColor=urlu.style.backgroundColor;
      urlu.style.backgroundColor=color;
      return false;
    }else{
      if(urlu.obackgroundColor) urlu.style.backgroundColor=urlu.obackgroundColor;
      else urlu.style.backgroundColor='';
      urll.value=title;
    }
  }
  urlu.style.backgroundImage="";
  urlu.style.backgroundPosition="";
  urlu.style.backgroundRepeat="";
}
TZR.openPopup = function(url){
  window.open(url,'','menubar=no,status=no,resizable=1,scrollbars=1,width=700,height=500');
  return false;
}
TZR.validFormInPopup = function(f){
  var ret=TZR.isFormValidWithFocus(f,true);
  if(ret){
    window.opener.name=TZR.uniqid('TZR');
    document.editform.target=window.opener.name;
    f.submit();
    self.close();
    return false;
  }else{
    return false;
  }
}
TZR.isFormValid = function (f) {
  return TZR.isFormValidWithFocus(f,false);
}
TZR.isFormValidWithFocus=function(f,foc) {
  TZR.isFormOk=true;
  for(var i=0;i<TZR.validator.length;i++){
    var o=document.getElementById(TZR.validator[i][0]);
    if(o!=null && o.form.name==f.name) {
      if(TZR.validator[i][99]){
	TZR.isIdxValid(i);
	if(foc) {
	  if(!TZR.isFormOk) {
	    if(TZR.validator[i][5])
	      o=document.getElementById(TZR.validator[i][5]);
	    jQuery(o).parents('fieldset.fieldsetAccordionClose').find('>legend').click();
	    o.focus();
	    return false;
	  }
	}
      }
    }else{
      TZR.validator.splice(i,1);
      i--;
    }
  }
  nb=TZR.onsubmit.length;
  for(i=0; i<nb; i++) {
    eval(TZR.onsubmit[i]);
  }
  if(!TZR.isFormOk) {
    if(typeof(TZR.customValid)!='undefined')
      return TZR.customValid(f);
    else 
      return confirm('Some data are not valid. Save anyway ?');
  }
  return true;
}
TZR.isIdxValid = function (i) {
   var isValid=false;
   var val=TZR.validator[i];
   if(val[4]=='XShortTextDef') 
      isValid=TZR.isShortTextValid(val[0],val[1],val[2],val[3]);
   else if(val[4]=='XRealDef') 
      isValid=TZR.isShortTextValid(val[0],val[1],val[2],val[3]);
   else if(val[4]=='XPasswdDef') 
      isValid=TZR.isShortTextValid(val[0],val[1],val[2],val[3]);
   else if(val[4]=='XDocumentDef') 
      isValid=TZR.isShortTextValid(val[0],val[1],val[2],val[3],val[5]);
   else if(val[4]=='XLinkDef') 
      isValid=TZR.isLinkValid(val[0],val[1],val[2],val[3],val[5],val[6]);
   else if(val[4]=='XStringSetDef') 
      isValid=TZR.isLinkValid(val[0],val[1],val[2],val[3],val[5],val[6]);
   else if(val[4]=='XThesaurusDef')
      isValid=TZR.isThesaurusValid(val[0],val[1],val[2],val[3]);
   else if(val[4]=='Captcha')
      isValid=TZR.isCaptchaValid(val[0],val[1],val[2],val[3]);
   return isValid;
}
TZR.addAutoComplete=function(url,id,moid,table,field,target_fields,callback){
  jQuery("#_INPUT"+id).keydown(function(event){
    if(event.keyCode!=13 && event.keyCode!=9) document.getElementById(this.id.replace('_INPUT','')).value="";
  }).autocomplete(url, {
    extraParams:{moid:moid,table:table,field:field,target_fields:target_fields},
    width:300,
    delay:500,
    mustMatch:true,
    minChars:2
  }).result(function(event, data, formatted) {
    var hidden=jQuery("#"+this.id.replace('_INPUT',''));
    if(data!=undefined){
      if(!data[1]){
	this.value="";
	hidden.val(data[1]);
      }else{
	hidden.val(data[1]);
      }
      if(callback) callback(id,data[1],data[0]);
    }
  });
}
TZR.isIdValid = function (id) {
  found=false;
  nb=TZR.validator.length;
  for(i=0;i<nb;i++) {
    if(id==TZR.validator[i][0]) {
      if(!TZR.isIdxValid(i)) return false;
    }
  }
  if(typeof(TZR.customOnBlur)!='undefined')
    return TZR.customOnBlur(id);
  return true;
}
TZR.copyDivToHidden = function (idsrc, iddst) {
  var objsrc = document.getElementById(idsrc);
  var objdst = document.getElementById(iddst);
  if(objsrc.innerHTML=="...") objdst.value="";
  else objdst.value = objsrc.innerHTML;
  return true;
}

TZR.addOnSubmit=function (src) {
  nb=TZR.onsubmit.length;  
  TZR.onsubmit[nb]=src;
}
TZR.addValidator=function(src){
  var o=document.getElementById(src[0]);
  if(!o) return false;
  if(src[99]===undefined) src[99]=true;
  var v=jQuery(o).data('validators');
  if(!v) v=[src];
  else v.push(src);
  jQuery(o).data('validators',v);
  TZR.validator.push(src);
  return true;
}
TZR.changeValidatorsState=function(id,active){
  if(!active) active=false;
  var vs=jQuery('#'+id).data('validators');
  if(vs){
    for(var i in vs){
      vs[i][99]=active;
    }
  }
}
TZR.editSec=function (selfu, moid, oid) {
  window.open(selfu+'&function=secEdit&template=xmodule/edit-sec.html&moid='+moid+'&tplentry=br&oid='+oid,
	      'SecBrowser','width=600,height=320,resizable=yes,scrollbars=yes,dependent=yes');
  return false;
}

TZR.autocomplete_cb = function (suggestion) {     
  if ( suggestion ) {
    var inp = TZR.autocomplete_field;
    var inp_enc = TZR.autocomplete_encoded_field;
    inp_enc.value=suggestion[0];
    // IE
    if ( document.selection ) {
      var sel = document.selection.createRange();
      sel.text = suggestion[1];            
      sel.move( 'character', -suggestion[1].length );
      sel.findText( suggestion[1] );
      sel.select();
    } else {
      var preLength = inp.value.length;
      inp.value += suggestion[1];
      inp.selectionStart = preLength;
      inp.selectionEnd   = inp.value.length;
    } 
  }
}

TZR.autocomplete_running=false;
TZR.autocomplete_precheck = function ( tab, field, myform, e ) {
  // Check for alpha numeric keys
  TZR.autocomplete_field = myform.elements[field+'_HID'];
  TZR.autocomplete_encoded_field = myform.elements[field];
  if ( ( e.keyCode >= 48 && e.keyCode <= 57 ) || ( e.keyCode >= 65 && e.keyCode <= 90 ) ) {
    x_xlinkdef_autocomplete( tab, field, TZR.autocomplete_field.value, TZR.autocomplete_cb);
  }
}
      
// Inverse la coche de toutes les checkbox d'un formulaire
TZR.toggleCheckBoxes = function(src,startn,endn) {
  if(!startn) startn='selectstart';
  var start=false;
  for(var i=0;i<src.elements.length;i++) {
    if(endn){
      if(src.elements[i].value==endn) break;
    }
    if(start) src.elements[i].checked = !src.elements[i].checked;
    if(src.elements[i].value==startn) start=true;
  }
}
// Coche ou decoche toutes les checkbox d'un formulaire
TZR.checkBoxes = function(src,value,startn,endn) {
  if(!startn) startn='selectstart';
  var start=false;
  for(var i=0;i<src.elements.length;i++) {
    if(endn){
      if(src.elements[i].value==endn) break;
    }
    if(start && (src.elements[i].type=='checkbox')) src.elements[i].checked=value;
    if(src.elements[i].value==startn) start=true;
  }
}
// Retourne vrai si au moins une checkbox est coché dans le formulaire
TZR.checkBoxesIsChecked = function(src,startn,endn) {
  if(!startn) startn='selectstart';
  var start=false;
  for(var i=0;i<src.elements.length;i++) {
    if(endn){
      if(src.elements[i].value==endn) break;
    }
    if(start && src.elements[i].checked) return true;
    if(src.elements[i].value==startn) start=true;
  }
  return false;
}

TZR.referer = function(markers,lang) {
 var maintenant = new Date();
 var msg=maintenant.toLocaleString();
 var n1=new Image();
 n1.src='/tzr/scripts/marker.php?_marks='+markers+'&_lang='+lang+'&alea='+msg;
}
TZR.refererWithTotalOn = function(markers,lang,totalon) {
 var maintenant = new Date();
 var msg=maintenant.toLocaleString();
 var n1=new Image();
 n1.src='/tzr/scripts/marker.php?_marks='+markers+'&_lang='+lang+'&_total='+totalon+'&alea='+msg;
}

TZR.setDateEmpty = function(id) {
  document.getElementById(id).value='';
  return false;
}

TZR.selectDocument=function(selfu,moid,id){
  w=window.open(selfu+'&function=index2Light&nosess=1&template=xmoddocmgt/poptreed.html&moid='+moid+
		'&tplentry=br&showfiles=1&_raw=1&_silent=1&action=selectDoc&target='+id,
	      	'DocumentBrowser','width=400,height=600,resizable=yes,scrollbars=yes,dependent=yes');
}

TZR.setDocumentEmpty = function(id) {
  document.getElementById("id_"+id).value='';
  document.getElementById("id_INPUT"+id).value='';
  return false;
}

var selectedtopic;
var selectedtopics_title;
TZR.selectTopic = function(selfu, moid, t1,t2) {
  selectedtopic=t1;
  selectedtopic_title=t2;
  w=window.open(selfu+'&function=home&template=xmodinfotree/popaction.html&moid='+moid+'&tplentry=mit&do=showtree&action=selectTopic'+
	        '&maxlevel=1','TreeBrowser','width=400,height=600,resizable=yes,scrollbars=yes,dependent=yes');
}

TZR.applySelected=function(func,form,message,template,tplentry,noselect) {
   if(TZR.checkBoxesIsChecked(form)){
     form.target='_self';
     form._function.value=func;
     form.message.value=message;
     if(template!==false) form.template.value=template;
     if(tplentry!==false) form.tplentry.value=tplentry;
     if(!form.onsubmit || form.onsubmit()) form.submit();
   }else{
     alert(noselect);
     return;
   }
}

TZR.doubleAdd = function(src,dst,morder) {
  var i=0;
  if(morder){
    var order=jQuery(dst).data('orderedopt');
    if(!order) {
      order=[];
      for (i=0;i<dst.options.length;i++) {
	order[dst.options[i].attributes.order.value]=dst.options[i];
      }
    }
    for (i=src.options.length-1;i>=0;i--) {
      if (src.options[i].selected) { 
	order[src.options[i].attributes.order.value]=src.options[i];
	src.options[i]=null;
      }
    }
    dst.options.length=0;
    for(var i=0;i<order.length;i++){
      if(order[i]) dst.options[dst.options.length]=order[i];
    }
    var order=jQuery(dst).data('orderedopt',order);
  }else{
    for (i=src.options.length-1;i>=0;i--) {
      if (src.options[i].selected) { 
	var a=new Option(src.options[i].text,src.options[i].value);
	jQuery(a).attr('order',src.options[i].attributes.order.value);
	dst.options[dst.options.length]=a;
	src.options[i]=null;
      }
    }
  }
  jQuery(src).val('');
  jQuery(dst).val('');
}

TZR.idxidx=10;
TZR.addTableLine = function(tableid,td,tdtoclone) {
  if(td[1]=='--') return;
  if(typeof(tdtoclone)=='undefined') tdtoclone=0;
  var table = document.getElementById(tableid);
  var tbody = table.tBodies[0];
  var tr = tbody.rows[tdtoclone].cloneNode(true);
  for(i=0;i<tr.cells.length; i++) {
    tr.cells[i].innerHTML="";
  }
  table.tBodies[0].appendChild(tr);
  var td3;
  for(i=0;i<td.length; i++) {
    td3=td[i].replace(/xidxid/g,'xid'+TZR.idxidx);
    jQuery(tr.cells[i]).html(td3);
  }
  TZR.idxidx++;
}

/* ajout d'une valeur a partir d'une combo */
TZR.addValueToShortText = function(text, multi, sep) {
   var text1 = document.getElementById(text);
   var combo1 = document.getElementById(text+'_H');
   if(combo1.selectedIndex==0) return;
   if(multi) {
     if(text1.value=='') sep='';
     text1.value+=sep+combo1.options[combo1.selectedIndex].text;
   } else {
     text1.value=combo1.options[combo1.selectedIndex].text;
   }
   return;
}

/* trouve le tag "parentTagName" parent de "element" */
TZR.getParent = function(element, parentTagName) {
  if ( ! element ) return null;	
  else if ( element.nodeType == 1 && element.tagName.toLowerCase() == parentTagName.toLowerCase() ) return element;
  else return TZR.getParent(element.parentNode, parentTagName);
}

/* supprimer une ligne dans un tableau */
TZR.delLine = function(link) {
  var td = link.parentNode;
  var table = TZR.getParent(td, 'TABLE');
  var tbody = table.tBodies[0];
  tbody.removeChild(TZR.getParent(td, 'TR'));
}

// Recupere le contenu d'une url via ajax en synchrone
TZR.file_get_contents=function(url,nocache){
    var req = null;
    try { req = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {
        try { req = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {
            try { req = new XMLHttpRequest(); } catch(e) {}
        }
    }
    if (req == null) throw new Error('XMLHttpRequest not supported');
    if(typeof(nocache)!='undefined'){
	url+="&uniqid="+TZR.uniqid();
    }
    req.open("GET", url, false);
    req.send(null);
    return req.responseText;
}
TZR.winEditor = null;
TZR.openhtmlfileeditor = function(options){
  var url = options.url+'&editflag='+escape(options.editflag)+'&uploader='+escape(options.uploader)+'&downloader='+escape(options.downloader);
  try{
    TZR.winEditor.location = url;
    TZR.winEditor.focus();
  } catch(e){
    TZR.winEditor = window.open(url, 'file editor', 'width=800px,height=700px;')
  }
}
// Génére un identifiant unique avec un prefix eventuel
TZR.uniqid=function(prefix){
  if(typeof(prefix)=='undefined') prefix="";
  var alea=Math.random()*1000000000;
  return prefix+alea.toString();
}
TZR.addDependency=function(ftype,fd,f,vd,v,op,s,nochange){
  if(typeof(TZR.dependency[fd])=='undefined'){
    TZR.dependency[fd]=new Object();
    TZR.dependency[fd]['_depfields']=new Object();
    TZR.dependency[fd]['_!=']=new Object();
  }
  if(vd=='') vd='_empty';
  if(op=='='){
    if(typeof(TZR.dependency[fd][vd])=='undefined') TZR.dependency[fd][vd]=new Object();
  }else{
    if(typeof(TZR.dependency[fd]['_!='][vd])=='undefined') TZR.dependency[fd]['_!='][vd]=new Object();
  }
  TZR.dependency[fd]['_depfields'][f]=1;
  if(op=='=') TZR.dependency[fd][vd][f]={field:f,ftype:ftype,value:v,style:s,op:op,nochange:nochange};
  else TZR.dependency[fd]['_!='][vd][f]={field:f,ftype:ftype,value:v,style:s,op:op,nochange:nochange};
}
TZR.activeDependency=function(f){
  jQuery(f).find('select').bind("change",{form:f},TZR.checkDependency);
  jQuery(f).find(':checkbox,:radio').bind("click",{form:f},TZR.checkDependency);
  var els=jQuery(f).find('select');
  for(var i=0;i<els.length;i++){
    jQuery(els[i]).triggerHandler("change");
  }
  var oks=new Object();
  var els=jQuery(f).find(':checkbox:checked,:radio:checked');
  for(var i=0;i<els.length;i++){
    jQuery(els[i]).triggerHandler("click");
    oks[els[i].name]=1;
  }
  var els=jQuery(f).find(':checkbox,:radio');
  for(var i=0;i<els.length;i++){
    if(els[i].checked || oks[els[i].name]==1) continue;
    jQuery(els[i]).triggerHandler("click");
    oks[els[i].name]=1;
  }
}
// Dependance uniquement sur select simple, radio et checkbox de booleen
TZR.checkDependency=function(e){
  var t=e.target;
  var n=t.name;
  var v=t.value;
  if(typeof(n)=='undefined' || n=="") return;
  if(t.type=="hidden") return;
  if(t.type=="radio" && !t.checked) v="";
  if(t.type=="checkbox"){
    n=n.replace(/(\[.+\])$/g,"");
    n=n.replace(/(_HID)$/g,"");
    if(t.checked) v=1;
    else v=2;
  }
  if(v=='') v='_empty';
  if(typeof(TZR.dependency[n])=='undefined') return;
  if(typeof(TZR.dependency[n][v])!='undefined'){
    for(var i in TZR.dependency[n][v]){
      var dep=TZR.dependency[n][v][i];
      TZR.setDependencyValue(e.data.form,dep.field,dep.ftype,dep.value,dep.nochange);
      if(!e.data.nostyle) TZR.setDependencyStyle(dep.field,dep.style);
    }
  }
  for(var v2 in TZR.dependency[n]['_!=']){
    if(v==v2) continue;
    for(var i in TZR.dependency[n]['_!='][v2]){
      if(typeof(TZR.dependency[n][v])!="undefined" && typeof(TZR.dependency[n][v][i])!="undefined") continue;
      var dep=TZR.dependency[n]['_!='][v2][i];
      TZR.setDependencyValue(e.data.form,dep.field,dep.ftype,dep.value,dep.nochange);
      if(!e.data.nostyle){
	TZR.setDependencyStyle(dep.field,dep.style);
      }
    }
  }
}

TZR.setDependencyStyle=function(field,style){
  var toStyle=document.getElementById('cont-'+field);
  if(typeof(toStyle)!='undefined' && toStyle){
    if(style=='hidden'){
      toStyle.style.display='none';
    }else if(style=="invalid"){
      jQuery(toStyle).find(":input").attr('disabled',true);
    }else{
      jQuery(toStyle).find(":input").attr('disabled',false);
      toStyle.style.display='';
    }
  }
}
TZR.setDependencyValue=function(form,field,ftype,value,nochange){
  if(!nochange || nochange=="0"){
    TZR.setValue(form,field,ftype,value);
    if(typeof(TZR.dependency[field])=='undefined') return;
    TZR.checkDependency({target:{name:field,value:value},data:{nostyle:false,form:form}});
  }
}
TZR.setValue=function(form,field,ftype,value){
  if(typeof(field)=='string' && !form){
    fid=document.getElementById(field);
    field=fid.name;
    form=fid.form;
  }else if(typeof(field)=='string' && typeof(form)=='string'){
    form=jQuery('form[name='+form+']').get(0);
  }

  if(ftype=="XLinkDef") TZR.setLinkValue(form,field,value);
  else TZR.setTextValue(form,field,value);
}
// form (objet), field (string)
TZR.setLinkValue=function(form,field,value){
  var cont=document.getElementById('cont-'+field);
  var ret=jQuery(cont).find(":radio[name='"+field+"']").val([value]);
  if(ret.length==0) var ret=jQuery(cont).find("select[name='"+field+"']").val(value);
  if(ret.length==0) var ret=jQuery(cont).find("select[name='"+field+"[]']").val(value);
  if(ret.length==0) var ret=jQuery(cont).find(":checkbox[name^='"+field+"[']").val([value]);
}
TZR.setTextValue=function(form,field,value){
  form.elements[field].value=value;
}

// Affiche du contenu centré dans l'écran avec une div d'arriere plan pleine page
// content est soit du texte, soit l'id d'un objet deja existant
TZR.dispFullScreenContent=function(content,color,op){
  if(!color) color="#000000";
  if(!op) op=0.2;

  var div=document.getElementById('fsoverlay');
  if(!div){
    jQuery("body").append('<div id="fsoverlay"></div>');
    jQuery("#fsoverlay").css({position:"absolute", zIndex:99998, padding:0, margin:0, top:0, left:0, background:color,
	  	              opacity:op, width:"100%", height:jQuery(document).height()});
  }
  if(content.substr(0,1)!="#"){
    jQuery("#fscontent").remove();
    jQuery("body").append('<div id="fscontent"></div>');
    jQuery("#fscontent").css({position:"absolute", zIndex:99999, padding:0, margin:0, top:0, left:0});
    jQuery("#fscontent").html(content);
    jQuery("#fscontent").css({top:(jQuery(window).height()-jQuery("#fscontent").outerHeight())/2+jQuery(window).scrollTop(),
    				    left:(jQuery(window).width()-jQuery("#fscontent").outerWidth())/2, visibility:"visible"});
  }else{
    jQuery(content).css({visibility:"visible", display:"block"});
    jQuery(content).css({position:"absolute", zIndex:99999, padding:0, margin:0,
				    top:(jQuery(window).height()-jQuery(content).outerHeight())/2+jQuery(window).scrollTop(),
				    left:(jQuery(window).width()-jQuery(content).outerWidth())/2});
  }
}
TZR.hideFullScreenContent=function(content){
  jQuery("#fsoverlay").remove();
  if(content!=undefined && content.substr(0,1)=="#"){
    jQuery(content).css('display','none');
  }else{
    jQuery("#fscontent").remove();
  }
}

/* Fonctions pour faciliter la gestion des champs préremplis avec leur libellé */
// Initialise les différentes propiétés du champ (o=objet, l=libellé)
function inputInit(o,l,cpltblur){
  if(cpltblur==undefined) cpltblur=true;
  if(typeof o=="string") { o=document.getElementById(o); }
  if(o.type=="text" || o.type=="textarea" || o.type=="password"){
    o.cpltblur=cpltblur;
    o.ovalue=l;
    if(o.value=="") o.value=l;
    o.onfocus=delValue;
    o.onblur=retablishValue;
    o.onchange=function(){};
  }else if(o.type=="select-one"){
    o.options[0].text=l;
  }
}
// Efface le contenu d'un champ (o=objet (se renseigne automatiquement sur un onfocus))
function delValue(o){
  if(o==undefined || o.type=="focus") o=this;
  if(o.value==o.ovalue){
    o.value="";
  }else{
    var r=new RegExp("^"+o.ovalue+" : ","");
    o.value=o.value.replace(r,"");
  }
}
// Rétabli le libellé si necessaire lors de la perte du focus (o=objet (se renseigne automatiquement sur un onblur))
function retablishValue(o){
  if(o==undefined || o.type=="blur") o=this;
  if(o.value==""){
    o.value=o.ovalue;
  }else if(o.cpltblur){
    o.value=o.ovalue+" : "+o.value;
  }
}
// A appeller sur le submit pour vider les champs non saisis
function checkFields(f){
  l=f.elements.length;
  for(i=0;i<l;i++){
    if((f.elements[i].type=="text" || f.elements[i].type=="textarea")){      
      if(f.elements[i].value==f.elements[i].ovalue){
	f.elements[i].value="";
      }else{
	var r=new RegExp("^"+f.elements[i].ovalue+" : ","");
	f.elements[i].value=f.elements[i].value.replace(r,"");
      }
    }
  }
}

/* Fonctions pour formater les champs date et heure/durée (besoin de jquery.ui.datepicker)*/
TZR.formatDate=function(obj,fmt){
  if(fmt==undefined) fmt=jQuery.datepicker._defaults.dateFormat;
  var val=obj.value;
  if(val=='') return false;
  // traitement interval
  fmt_re = fmt.replace(new RegExp('dd|mm|y','g'), '\\d{1,2}').replace(new RegExp('\/','g'),'[\/.-]');
  range_pattern = new RegExp('('+fmt_re+')\\s*\<\>\\s*('+fmt_re+')');
  matches = val.match(range_pattern);
  if (matches != null && matches.length == 3)
    dates = new Array(matches[1], matches[2]);
  else
    dates = new Array(val);
  values = new Array();
  var fmttab=fmt.split(/[\/.-]/);
  for (i in dates) {
    var tab=dates[i].split(/[\/.-]/);
    var date=new Date(2010,0,1);
    for(var j in fmttab){
      if((fmttab[j]=='dd' || fmttab[j]=='d') && tab[j]!=undefined && tab[j]!='') date.setDate(tab[j]);
      if((fmttab[j]=='mm' || fmttab[j]=='m') && tab[j]!=undefined && tab[j]!='') date.setMonth(tab[j]-1);
      if((fmttab[j]=='yy' || fmttab[j]=='y') && tab[j]!=undefined && tab[j]!=''){
        if(tab[j].length==1) date.setYear("200"+tab[j]);
        else if(tab[j].length==2) date.setYear("20"+tab[j]);
        else if(tab[j].length==3) date.setYear("2"+tab[j]);
        else date.setYear(tab[j]);
      }
    }
    values[i] = jQuery.datepicker.formatDate(fmt,date);
  }
  obj.value = values.join(' <> ');
}
TZR.format2dates=function(obj,b,e,fmt){
  if(fmt==undefined) fmt=jQuery.datepicker._defaults.dateFormat;
  var form=obj.form;
  var b=form.elements[b];
  var e=form.elements[e];
  TZR.formatDate(obj);
  var begindate=jQuery.datepicker.parseDate(fmt,b.value); 
  var enddate=jQuery.datepicker.parseDate(fmt,e.value); 
  if(obj==b && begindate>enddate) e.value=b.value;
  else if(obj==e && begindate>enddate) b.value=e.value;
}
TZR.formatHour=function(obj,n){
  val=obj.value;
  tab=val.split(":");
  var rtab=new Array();

  if(/^[0-9]$/.test(tab[0])) {
    rtab[0]="0"+tab[0];
  }else if(/^[0-9]{2}$/.test(tab[0])) {
    rtab[0]=tab[0];
  }else{
    return;
  }
  if(n>1){
   if(!tab[1]){
     rtab[1]="00";
   }else if(/^[0-9]$/.test(tab[1])){
     rtab[1]="0"+tab[1];
   }else if(/^[0-9]{2}$/.test(tab[1])) {
     rtab[1]=tab[1];
   }else{
     return;
   }
  }
  if(n>2){
   if(!tab[2]){
     rtab[2]="00";
   }else if(/^[0-9]$/.test(tab[2])){
     rtab[2]="0"+tab[2];
   }else if(/^[0-9]{2}$/.test(tab[2])) {
     rtab[2]=tab[2];
   }else{
     return;
   }
  }
  obj.value=rtab.join(":");
}

TZR.format2hours=function(obj,n,b,e,bd,ed){
  var form=obj.form;
  b=form.elements[b];
  e=form.elements[e];
  if(bd!=undefined) bd=form.elements[bd];
  if(ed!=undefined) ed=form.elements[ed];
  TZR.formatHour(obj,n);
  var reg=/^[0-9]{2}(:[0-9]{2})?(:[0-9]{2})?$/;
  var tab=obj.value.split(":");
  if(obj.value==""){
    b.value="";
    e.value="";
  }else if(obj==b && b.value>e.value && (bd==undefined || ed==undefined || bd.value==ed.value) && reg.test(b.value)){
    var hour=parseFloat(tab[0]);
    var minute=parseFloat(tab[1]);
    if(hour==23) e.value="23:59";
    else e.value=(hour+1)+":"+minute;
    TZR.formatHour(e,n);
  }else if(obj==e && b.value>e.value && (bd==undefined || ed==undefined || bd.value==ed.value) && reg.test(e.value)){
    var hour=parseFloat(tab[0]);
    var minute=parseFloat(tab[1]);
    if(hour==0) b.value="00:00";
    else b.value=(hour-1)+":"+minute;
    TZR.formatHour(b,n);
  }
}


/* Fonction du champ couleur */
function colourPickerCallback(acolor){
  TZR.ColourPicker.setFieldColor(acolor);
}
function colourPickerClose(acolor){
  TZR.ColourPicker.hidden();
}

TZR.ColourPicker = {
  target:null,
  lastColor:'#7f7f7f',
  myAppName:'ColourPicker',
  myfield:null,
  init:function(target){
    if(!this.target){
      this.target = document.getElementById(target);
      var so = new SWFObject('/tzr/templates/flash/Colourpicker.swf', this.myAppName, "435px", "220px", 8, "#FFFFFF");
      if(deconcept.SWFObjectUtil.getPlayerVersion(so.getAttribute("version")).major >= 8) {
	so.addParam("menu", "false");
	so.addParam("allowScriptAccess", "sameDomain");
	so.write(target);
      }
    }
  },
  initField:function(field){
    var value;
    if(field) this.myField = field;
    else field=this.myField;
    TZR.ColourPicker.show(field);
    var swf = this.getMyApp();
    if(swf.setColour){
      if(field.value) value=field.value;
      else value=this.lastColor;
      swf.setColour(value, field.name);
    }else{
      setTimeout("TZR.ColourPicker.initField()", 250);
    }
  },
  show:function(field){
    coor=getAnchorPosition(field.id);
    this.target.style.left = coor.x+field.clientWidth+10;
    this.target.style.top = coor.y;
  },
  hidden:function(){
    this.target.style.top = '-500px';
  },
  setFieldColor:function(acolor){
    TZR.ColourPicker.hidden();
    this.lastColor=acolor;
    document.getElementById('col'+this.myField.id).style.backgroundColor=acolor;
    this.myField.value=acolor;
  },
  getMyApp:function () {
    if (navigator.appName.indexOf ("Microsoft") !=-1) {
      return window[this.myAppName];
    } else {
      return document[this.myAppName];
    }
  }
}
// fonctions des champs de geodesiccoordinates
TZR.geodesic = {
  geoSearch:null,
  dms2dd:function(inid, outid){
    var dms = document.getElementById(inid).value;
    var exp = new RegExp(/[ ]*([0-9]{1,2})° ([0-9]{1,2})' ([0-9]{1,2}\.[0-9]{0,3})'' ([NS]{1})[ ]+([0-9]{1,3})° ([0-9]{1,2})' ([0-9]{1,2}\.[0-9]{0,3})'' ([WOE]{1})/);
    if (exp.test(dms)){
      var dd = document.getElementById(outid);
      var dlng = RegExp.$5;
      var mlng = RegExp.$6;
      var slng = RegExp.$7;
      var lng = RegExp.$8;
      var dlat = RegExp.$1;
      var mlat = RegExp.$2;
      var slat = RegExp.$3;
      var lat = RegExp.$4;
      if (lat == 'S'){
	lat = '-';
      } else {
	lat = '';
      }
      if (lng == 'W' || lng == 'O'){
	lng = '-';
      } else {
	lng = '';
      }
      var ddlat = parseInt(dlat) + parseFloat(mlat/60) + parseFloat(slat/3600);
      var ddlng = parseInt(dlng) + parseFloat(mlng/60) + parseFloat(slng/3600);
      dd.value = lat+ddlat+';'+lng+ddlng;
    }else{
      //      var dd = document.getElementById('dd').value='####';
    }
  },
  setPointCoordinates:function(field, rawvalue, dmsvalue){
    document.getElementById(field.fid).value = rawvalue;
    document.getElementById('dms'+field.fid).value = dmsvalue;
    document.getElementById(field.fid+'_autogc').checked = false;
    this.geocodeauto(document.getElementById(field.fid+'_autogc'), field.fid);
  },
  geocodeauto:function(cb, fid){
    if (cb.checked){
      document.getElementById(fid+'_b1').style.display='block';
      document.getElementById(fid+'_b2').style.display='block';      
    } else {
      document.getElementById(fid+'_b1').style.display='none';
      document.getElementById(fid+'_b2').style.display='none';
      document.getElementById(fid+'_unchanged').value = '0';
      document.getElementById(fid+'_accuracy1').innerHTML = '';
      document.getElementById(fid+'_upd').innerHTML = '';
      document.getElementById(fid+'_accuracy2').value = 'N/A';
    }
    
  },
  openGeoSearch:function( url, fname, fid, ftable){	
    var v = document.getElementById(fid).value;
    if (v != ';'){
      var c = v.split(';');
      var newp = false;
      var lat = c[0];
      var lng = c[1];
    } else {
      var newp = true;
      var lat = 0;
      var lng = 0;
    }
    try{
      TZR.geodesic.geoSearch.setPoint({table:ftable, name:fname, id:fid, newpoint:newp, lat:lat, lng:lng});
      TZR.geodesic.geoSearch.focus();
    }catch(e){
      TZR.geodesic.geoSearch = window.open(url+'&fid='+fid+'&ftable='+ftable+'&fname='+fname+'&flatlng='+escape(v), 'GeoSearch',"resizable=no,width=700,height=530,left=100,top=100");
    TZR.geodesic.geoSearch.focus();
    }
  },
  clear:function(fid){
    document.getElementById(fid).value='';
    document.getElementById('dms'+fid).value='';
    document.getElementById(fid).value='';
    document.getElementById(fid+'_accuracy1').innerHTML = '';
    document.getElementById(fid+'_upd').innerHTML = '';
    document.getElementById(fid+'_accuracy2').value = 'N/A';
  },
  openGeoView:function(coordstring, url, fname, fid, ftable){
    var v = coordstring;
    if (v != ';'){
      var c = v.split(';');
      var newp = false;
      var lat = c[0];
      var lng = c[1];
    } else {
      var newp = true;
      var lat = 0;
      var lng = 0;
    }
    try{
      TZR.geoSearch.setPoint({table:ftable, name:fname, id:fid, newpoint:newp, lat:lat, lng:lng});
      TZR.geoSearch.focus();
    }catch(e){
      TZR.geoSearch = window.open(url+'&fid='+fid+'&ftable='+ftable+'&fname='+fname+'&flatlng='+escape(v), 'GeoView',"resizable=no,width=700,height=530,left=100,top=100");
    TZR.geoSearch.focus();
    }
  }
};

// Applique une popup a des objets (obj est un objet jQuery)
TZR.applyHottip=function(obj,param){
  param=jQuery.extend(true,{fill:'#F7F7F7',strokeStyle:'#B7B7B7',spikeLength:10,spikeGirth:10,padding:8,cornerRadius:0,
			    cssStyles:{fontFamily:'"lucida grande",tahoma,verdana,arial,sans-serif',fontSize:'11px'},
			    closeWhenOthersOpen:true},param);
  obj.bt(param);
  return obj;
}

function showObj(objid){
  var o = document.getElementById(objid);
  if(o){
    o.style.visibility = "visible";
    o.style.position = "relative";
  }
}
function hideObj(objid){
  var o = document.getElementById(objid);
  if(o){
    o.style.visibility = "hidden";
    o.style.position = "absolute";
  }
}
function showHide(objid){
  var o = document.getElementById(objid);
  if(o){
    if(o.style.visibility == "hidden"){
      o.style.visibility = "visible";
      o.style.position = "relative";
    }else{
      o.style.visibility = "hidden";
      o.style.position = "absolute";
    }
  }
}

// Function appelé à la fin du chargment de la page
function onLoadComplete(){
  // Correction des PNG sous IE
	  if(window.attachEvent && window.correctPNG) correctPNG();
}

window.onload=onLoadComplete;

// Fonction de nettoyage des objets
TZR.initObjCleaner=function(){
  if(!TZR.objCleaner) TZR.objCleaner=setInterval(function(){TZR.checkObjCleaner();},30000);
}
TZR.stopObjCleaner=function(){
  if(TZR.objCleaner) clearInterval(TZR.objCleaner);
}
TZR.addToObjCleaner=function(id,jso,f){
  if(!TZR.objToClean) TZR.objToClean=new Object();
  if(!f) f=TZR.cleanObj;
  TZR.objToClean[id]={o:jso,f:f};
}
TZR.checkObjCleaner=function(){
  for(var i in TZR.objToClean){
    if(!document.getElementById(i)){
      TZR.objToClean[i].f(TZR.objToClean[i].o);
      delete TZR.objToClean[i];
    }
  }
}
TZR.cleanObj=function(o){
  if(!delete o) o=undefined;
}
// Change le titre de la fenetre courante
TZR.setDocumentTitle=function(title,noprefix){
  if(!TZR.title) TZR.title=document.title;
  if(noprefix) document.title=title;
  else document.title=TZR.title+" : "+title;
  jQuery('#cv8-pagetitle').html(TZR.maintitle);
}

// Redimensionne l'interface (width : taille de la zone centrale ou toggle pour switcher entre plein ecran/taille d'origine
TZR.resizeTo=function(width){
  if(!width) return;
  if(width=='toggle'){
    var toadd=jQuery(window).width()-jQuery('#cv8-container').width();
    toadd-=5;
    if(toadd!=0){
      var w1=jQuery('#cv8-content').width()+toadd;
      var w2=jQuery('#cv8-container').width()+toadd;
    }else{
      var w1='';
      var w2='';
    }
  }else{
    var w1=width;
    var w2=jQuery('#cv8-container').width()+width-jQuery('#cv8-content').width();
    var sw=jQuery(window).width();
    if(w1>sw){
      TZR.resizeTo('toggle');
      return;
    }
  }

  jQuery('#cv8-content').width(w1);
  jQuery('#cv8-container').width(w2);
  jQuery('div.cv8-contenu-haut').width('100%');
  return w1;
}

// Fonction pour appliquer l'alernance de couleur et le hover sur les tables .cv8_tablelist
TZR.applyAlternate=function(what,table){
  if(table==undefined){
    if(what==undefined) var what=document;
    var jts=jQuery('table.cv8_tablelist',what);
  }else{
    jts=jQuery(table);
  }
  jts.each(function(){
    if(!jQuery(this).hasClass('nohover')) jQuery('tbody:first>tr:visible',this).alternate({odd:'odd', even:'even', hover:'hover'});
    else jQuery('tbody:first>tr:visible',this).alternate({odd:'odd', even:'even'});
  });
}

// Ajoute un item à un menu
TZR.addMenuItem=function(mid,group,text,url,newgroup){
  var li='<li';
  if(newgroup) li+=' class="sf-menu-grp"';
  li+='>';
  if(url==undefined) li+=text;
  else if(url=='#') li+='<a href="'+url+'" onclick="return false;">'+text;
  else if(url.substr(0,11)=='javascript:') li+='<a href="#" onclick="'+url.replace("javascript:","").replace(/\"/g,'&quot;','g')+'return false;">'+text;
  else li+='<a class="cv8-ajaxlink" href="'+url+'">'+text;
  if(newgroup) li+='<span class="sf-sub-indicator"> »</span>';
  li+='</a>';
  if(newgroup) li+='<ul id="'+mid+'-'+newgroup+'"></ul>';
  li+='</li>';
  jQuery('#'+mid+'-'+group).append(li);
}

// Ajoute un item à une toolbar
TZR.addToolBarItem=function(tid,group,order,picto,url,text,target){
  if(document.getElementById(tid+'-'+group)==undefined){
    jQuery('#'+tid).append('<ul class="sf-menu sf-js-enabled sf-shadow" id="'+tid+'-'+group+'"><li class="separe"></li></ul>');
  }else{
    jQuery('#'+tid+'-'+group).show();
  }
  var li='<li class="icon" morder="'+order+'">';
  if(!url) li+=picto;
  else if(url.substr(0,11)=='javascript:') li+='<a href="#" onclick="'+url.replace("javascript:","").replace('"','&quot;','g')+'return false;"><img height="18" width="14" alt="'+text+'" src="'+picto+'"/></a>';
  else li+='<a class="cv8-ajaxlink" href="'+url+'"><img height="18" width="14" alt="'+text+'" src="'+picto+'"/></a>';
  li+='</li>';

  var added=false;
  var jul=jQuery('#'+tid+'-'+group);
  jul.find('li').each(function(){
    if(parseInt(jQuery(this).attr('morder'))>order){
      jQuery(this).before(li);
      added=true;
      return false;
    }
  });
  if(!added) jul.append(li);
}

// Met à jour le texte d'information
TZR.setInfoText=function(text){
  if(text!==undefined && text!==null) jQuery('#cv8-infotext>div.cv8-infotextg>div.cv8-txtseul').html(text+'&nbsp;');
}
// Recupère le texte d'information
TZR.getInfoText=function(){
  return jQuery('#cv8-infotext>div.cv8-infotextg>div.cv8-txtseul').html();
}
// Efface le chemin actuel
TZR.clearNav=function(){
  jQuery('#cv8-path>ul>li:gt(0)').remove();
}
// Ajoute une entrée au chemin
TZR.addNav=function(title,url){
  jQuery('#cv8-path>ul').append('<li><a class="cv8-ajaxlink" href="'+url+'">'+title+'</a></li>');
}
// Affiche une fenetre modale permettant de s'authentifier
TZR.authAlert=function(){
  jQuery("#cv8-unauth").dialog({modal:true,resizable:false,draggable:false,width:450,height:110,close:function(){
    document.auth.login.value="";
    document.auth.password.value="";
    retablishValue(document.auth.login);
    retablishValue(document.auth.password);
  }});
}
TZR.submitLogin=function(form){
  jQuery.post(form.action,jQuery(form).serializeArray(),function(data,status){
    if(data=='ok'){
      jQuery("#cv8-unauth-error").css('visibility','hidden');
      jQuery("#cv8-unauth").dialog('close');
    }else{
      jQuery("#cv8-unauth-error").css('visibility','visible');
    }
  });
}
TZR.cancelLogin=function(form){
  jQuery("#cv8-unauth").dialog('close');
}

// Fonction de chargement via jQuery.load avec callback de gestion de l'authentification,overlay automatique
// Parametres : url, target (cible du chargement et de l'overlay), cb (callback)
//              noautocreate (par defaut, la fonction creee les div module-container si la cible est #cv8-content)
//              nocheckauth (desactive la verification de l'authentification), mode (mode de chargement : load, post)
//              noautoscroll (desactive le scroll automatique), nocache (desactivation du cache navigateur, true par defaut)
TZR.jQueryAjax=function(obj){
  if(!TZR.ajaxQueue) TZR.ajaxQueue=0;
  TZR.ajaxQueue++;
  var url=obj.url;
  var data=obj.data;
  var cb=obj.cb;
  var mode=obj.mode;
  var nocheckauth=obj.nocheckauth;
  var noautocreate=obj.noautocreate;
  var noautoscroll=obj.noautoscroll;
  var nocache=obj.nocache;
  if(nocache==undefined) nocache=true;
  if(!obj.target) obj.target='#cv8-content';
  var jt=jQuery(obj.target);
  if(obj.overlay) var jo=jQuery(obj.overlay);
  else var jo=jt;
  // Ajoute un overlay le temps du chargement
  if(jt.attr('id')=='cv8-content'){
    if(mode=="load" && !noautocreate){
      jt.html('<div class="cv8-module" id="cv8-module-0"><div class="cv8-module-bg"><div class="cv8-module-container" id="cv8-module-container-0"></div></div></div>');
      var jt=jQuery('#cv8-module-container-0');
    }
    var overlay=TZR.setOverlay(jo);
  }else{
    var overlay=TZR.setOverlay(jo);
  }
  // Scroll le contenu si necessaire
  var pos=jt.position().top;
  if(jQuery(document).scrollTop()>pos) jQuery(document).scrollTop(pos);
  // Activation/desactivation du cache
  var actcachesetting=jQuery.ajaxSettings.cache;
  if(nocache) jQuery.ajaxSettings.cache=false;
  else jQuery.ajaxSettings.cache=true;
  // Complete l'url
  if(url==url.replace('_raw=','')) url+='&_raw=1';
  if(url==url.replace('_ajax=','')) url+='&_ajax=1';
  if(typeof(data)=='function'){
    cb=data;
    data=undefined;
  }
  // Construit la callback (desactivation overlay + allback personnalisable)
  var callback=function(responseText,textStatus,XMLHttpRequest){
    TZR.ajaxQueue--;
    TZR.unsetOverlay(overlay);
    if(!nocheckauth){
      if(XMLHttpRequest.status==401){
	TZR.authAlert();
	return false;
      }
    }
    if(cb) return cb(responseText,textStatus,XMLHttpRequest);
  };
  // Appel ajax
  if(mode=="load") jt.load(url,data,callback);
  if(mode=="post") jQuery.post(url,data,callback);
  jQuery.ajaxSettings.cache=actcachesetting;
  return overlay;
}
TZR.jQueryLoad=function(obj){
  obj.mode="load";
  TZR.jQueryAjax(obj);
}
TZR.jQueryPost=function(obj){
  obj.mode="post";
  TZR.jQueryAjax(obj);
}
// Soumet un formulaire via ajax (div : element cible pour l'overlay / loadresult : charge le resultat dans div)
TZR.ajaxSubmitForm=function(form,div,loadresult,cplt){
  if(form.enctype=="multipart/form-data" || form.ENCTYPE=="multipart/form-data") return TZR.iframeSubmitForm(form,div,loadresult,cplt);
  if(loadresult==undefined) loadresult=true;
  if(!TZR.isFormValidWithFocus(form,true)) return false;
  if(div==undefined) div=jQuery(form).parents('div.cv8-module-container')[0];
  var param={target:div,url:form.action,data:jQuery(form).serializeArray()};
  if(cplt!=undefined) jQuery.extend(param,cplt);
  if(loadresult) TZR.jQueryLoad(param);
  else TZR.jQueryPost(param);
  return false;
}
// Soumet un formulaire via iframe (div : element cible pour l'overlay / loadresult : charge le resultat dans div)
TZR.iframeSubmitForm=function(form,div,loadresult,cplt){
  if(loadresult==undefined) loadresult=true;
  if(div==undefined) div=jQuery(form).parents('div.cv8-module-container')[0];
  var jdiv=jQuery(div);
  var overlay='';
  if(form._next){
    var _next=form._next.value;
    form._next.value="";
  }
  return TZR.iframeSubmitFormKernel.submit(form,{onStart:function(){
    var ret=TZR.isFormValidWithFocus(form,true);
    if(!ret) return false;
    overlay=TZR.setOverlay(jdiv);
    return true;
  },onComplete:function(html){
    if(loadresult){
      if(_next) jdiv.load(_next,function(){TZR.unsetOverlay(overlay);});
      else{
	jdiv.html(html);
	TZR.unsetOverlay(overlay);
      }
    }else{
      TZR.unsetOverlay(overlay);
    }
    if(cplt){
      if(cplt.cb) cplt.cb(html);
    }
  }});
}
// Ajout/suppression d'un overlay sur une div
TZR.setOverlay=function(o,opts){
  if(!opts) opts=new Object();
  var jo=jQuery(o);
  offset=jo.offset();
  var overlay=jQuery('<div><div style="width:100%; height:100%;"></div><img src="/tzr/templates/ico/general/indicator-big.gif" style="position:absolute; margin-left:-50px; left:50%; margin-top:-10px; top:50%;"></div>');
  var css=jQuery.extend({position:'absolute',top:offset.top,left:offset.left,opacity:0.3,width:jo.outerWidth(),height:jo.outerHeight(),'background-color':'#000000','z-index':999},opts);
  var css2={opacity:css.opacity,"background-color":css["background-color"]};
  delete css.opacity;
  delete css["background-color"];
  if(css.height<20) css.height=20;
  overlay.css(css);
  jQuery('div',overlay).css(css2);
  jQuery('body').append(overlay);
  overlay.data('_timer',setInterval(function(){
    offset=jo.offset();
    var css=jQuery.extend({top:offset.top,left:offset.left,width:jo.outerWidth(),height:jo.outerHeight()},opts);
    if(css.height<20) css.height=20;
    overlay.css(css);
  },100));
  return overlay;
}
TZR.unsetOverlay=function(o){
  clearInterval(jQuery(o).data('_timer'));
  jQuery(o).remove();
}
// Ajoute une entrée dans l'historique navigateur
TZR.addNavHistory=function(title,nowaitajax){
  // Attend la fin du traitement de la pile ajax
  if(!nowaitajax && TZR.ajaxQueue){
    setTimeout(function(){TZR.addNavHistory(title,nowaitajax);},200);
    return false;
  }
  var jh=jQuery('#cv8-history-list');
  // Prepare la liste des historique à effacer
  var htodel=new Array();
  if(TZR.historymode=='loadnav'){
    jh.find('li').each(function(i){
      if(this.id=="_"+location.hash.substring(1)) return false;
      jQuery(this).remove();
      htodel.push(this.id.substring(1));
    });
    TZR.historymode='normal';
  }
  jh.find('li').each(function(i){
    if(i>TZR.historysize-2){
      jQuery(this).remove();
      htodel.push(this.id.substring(1));
    }
  });
  // Prepare les parametres à enregistrer
  var hid='history-'+Math.floor(Math.random()*999999);
  var container=new Array();
  jQuery('div.cv8-module-container').each(function(){
    if(typeof(this._here)=='string') container.push(this._here);
  });
  if(TZR.maintitle && TZR.maintitle!=title && title.indexOf(TZR.maintitle+" > ")!=0) title=TZR.maintitle+" > "+title;
  jQuery.post('/tzr/scripts/addHistory.php?PHPSESSID='+TZR._sessid,{hid:hid,maintitle:TZR.maintitle,title:title,url:TZR.mainurl,comment:TZR.getInfoText(),'container':container,'todel':htodel});
  TZR.lasthid=hid;
  TZR.setDocumentTitle(title);
  jQuery(window).history('add',hid);
  jh.find('li.active').removeClass('active');
  if(title.length>35) var stitle=title.substr(0,32)+"...";
  else stitle=title;
  TZR.applyHottip(jQuery('<li class="active" id="_'+hid+'"><a href="#" onclick="TZR.loadNavHistory(\''+hid+'\');return false;">'+stitle+'</a></li>').prependTo(jh).attr('bt-xTitle',title.replace(new RegExp('>','g'), '<br>&nbsp;&nbsp;>') ));
}

// Charge une page de l'historique navigateur
TZR.loadNavHistory=function(hid,nav){
  if(nav){
    var jh=jQuery('#cv8-history-list');
    jh.find('li.active').removeClass('active');
    jQuery('#_'+hid).addClass('active');
    TZR.historymode='loadnav';
  }
  TZR.jQueryLoad({noautocreate:true,url:TZR._self+"class=XSession&function=goHistory&template=generic8-historycontent.html&skip=1&hid="+hid});
}

// Enregistre un cookie
TZR.setCookie=function(name,value,expire,path,domain,secure) {
  document.cookie=name+"="+escape(value)+((expire)?"; expires="+expire.toGMTString():"")+((path)?"; path="+path:"")+((domain)?"; domain="+domain:"")+((secure)?"; secure":"");
}
// Recupere un cookie
TZR.getCookie=function(name,isfloat,isbool){
  var deb=document.cookie.indexOf(name+"=")
  if(deb>=0) {
    deb+=name.length+1;
    var fin=document.cookie.indexOf(";",deb);
    if(fin<0) fin=document.cookie.length;
    var val=unescape(document.cookie.substring(deb,fin));
    if(isbool){
      if(!val || val=="false" || val=="0") return false;
      else return true;
    }
    if(isfloat) return parseFloat(val);
    return val;
  }
  return "";
}

// Accordeon sur des fieldset (obj=>noeud contenant les fieldset à traiter, open=index à ouvrir (0 par defaut, 'all' pour tout ouvrir))
TZR.fieldsetAccordion=function(obj,open){
  if(!open) open=0
  jQuery(obj).find('fieldset').addClass('fieldsetAccordion').each(function(i){
    var jt=jQuery(this);
    jQuery('>legend',jt).click(function(){
      jQuery(this.parentNode).toggleClass('fieldsetAccordionClose fieldsetAccordionOpen');
      jQuery('>div,>table',this.parentNode).slideToggle(200);
    }).css('cursor','pointer');
    if(open!='all' && i!=open && !jt.hasClass('fieldsetAccordionOpen')){
      jt.addClass('fieldsetAccordionClose');
      jQuery('>div,>table',jt).hide();
    }else{
      jt.addClass('fieldsetAccordionOpen');
    }
  });
}


/* Mediatheque */
// Inverse la selection d'une fiche via un des elements du DOM
TZR.selectMedia=function(obj){
  li=jQuery(obj).parents('.cv8_inlineblock')[0];
  var cb=jQuery(':checkbox',li)[0];
  cb.checked=!cb.checked;
}
// Inverse la selection des fiches d'une ligne via un des elements du DOM
TZR.selectMediaLine=function(obj){
  jli=jQuery(obj).parents('li.cv8_inlineblock');
  var cb=jQuery(':checkbox',jli)[0];
  cb.checked=!cb.checked;
  var y=jli.offset().top;
  jli.prevAll().each(function(){
    var _y=jQuery(this).offset().top;
    if(y!=_y) return false;
    jQuery(':checkbox',this)[0].checked=cb.checked;
  });
  jli.nextAll().each(function(){
    var _y=jQuery(this).offset().top;
    if(y!=_y) return false;
    jQuery(':checkbox',this)[0].checked=cb.checked;
  });
}


/* Gestion selection */
// Met à jour la selection
TZR.SELECTION=new Object();
TZR.SELECTION.update=function(moid,geturl){
  if(!moid) moid=0;
  var jp=jQuery('#cv8-panier');
  jp.show();
  var url=TZR._self+'&moid='+TZR._sysmods_xmoduser2+'&function=browseSelection&template=generic8-panier.html&skip=1&tplentry=br&tabs='+moid;
  if(!geturl) TZR.jQueryLoad({url:url,target:'#cv8-panier',cb:function(resp,status,xml){if(resp=="") jp.hide();}});
  else return url;
}
// Met à jour le nombre de fiche cochée pour un module
TZR.SELECTION.updateChecked=function(moid){
  jQuery('#selection-nbchecked'+moid).html(jQuery('#selection-sc'+moid+' :checkbox:checked[name^="_selected"]').length);
}
// Supprime les fiches selectionnées de la selection
TZR.SELECTION.delTo=function(moid){
  var f=document.forms['selectionform'+moid];
  f._function.value="delToUserSelection";
  f._next.value=TZR.SELECTION.update(moid,true);
  TZR.ajaxSubmitForm(f,'#cv8-panier');
  return false;
}
// Applique une fonction sur les elements de la selection
// use param.applyToSelection=1 pour appliquer à tous les elements
TZR.SELECTION.applyTo=function(moid,func,next,param,confirm,ftarget,refresh){
  var f=document.forms['selectionform'+moid];
  if(jQuery(':checkbox:checked',f).length==0 && param.applyToSelection!=1) return false;
  if(confirm && typeof(confirm)=='function' && !confirm.call()) return false;
  if(ftarget===undefined || ftarget===null) ftarget='#cv8-panier';
  if(next===undefined || next===null) f._next.value=TZR.SELECTION.update(moid,true);
  var jf=jQuery(f);
  jf.find('input.applyToInput').remove();
  f._function.value=func;
  if(typeof(param)=='object'){
    for(var i in param){
      jf.append('<input class="applyToInput" type="hidden" name="'+i+'" value="'+param[i]+'">');
    }
  }
  if(!ftarget) f.submit();
  else TZR.ajaxSubmitForm(f,ftarget);
  if(refresh){
    jQuery('#cv8-content div.cv8-module-container').each(function(){
      jQuery(this).data('tzrobj').refresh();
    });
  }
  return false;
}
TZR.SELECTION.exportSelection=function(moid) {
  window.open('','print','width=650,height=550,scrollbars=yes,location=no,resizable=yes');
  var form=document.forms['selectionform'+moid];
  form._next.value='';
  form._function.value='preExportBrowse';
  form.template.value='xmodtable/preexportbrowse.html';
  form.tplentry.value='br';
  form.target='print';
  form.method='post';
  form.selectedfields.value='';
  form.submit();
}
/* Soumet un formulaire (peut avoir des champs fichier) sans rechargement de la page */
/* Utilisation : TZR.iframeSubmitFormKernel.submit(form,{onStart:function,onComplete:function},true/false); */
TZR.iframeSubmitFormKernel={
  frame:function(c) {
    var n = 'iframe' + Math.floor(Math.random() * 99999);
    var d = document.createElement('DIV');
    d.innerHTML='<iframe src="about:blank" initialized="0" style="display:none" id="'+n+'" name="'+n+'" onload="TZR.iframeSubmitFormKernel.loaded(\''+n+'\');"></iframe>';
    document.body.appendChild(d);
    var i = document.getElementById(n);
    if (c && typeof(c.onComplete) == 'function') {
      i.onComplete = c.onComplete;
    }
    return n;
  },
  form : function(f, name) {
    f.target=name;
    return name;
  },
  submit : function(f, c, validwithfocus) {
    var ret=false;
    if (c && typeof(c.onStart) == 'function') {
      ret=c.onStart();
    } else {
      ret=true;
    }
    if(!ret) return false;
    var id=this.form(f, TZR.iframeSubmitFormKernel.frame(c));
    jQuery(f).append('<input type="hidden" name="_iframeencode" value="1">');
    document.getElementById(id).initialized=1;
    return true;
  },
  loaded : function(id) {
    var i = document.getElementById(id);
    if(i.initialized!=1) return false;
    if (i.contentDocument) {
      var d = i.contentDocument;
    } else if (i.contentWindow) {
      var d = i.contentWindow.document;
    } else {
      var d = window.frames[id].document;
    }
    if(d.location.href != "about:blank" && typeof(i.onComplete) == 'function') {
      if(d.body.innerHTML.indexOf('<textarea id="_iframeencode">')===0){
	i.onComplete(jQuery('#_iframeencode',d.body).val());
      }else{
	i.onComplete(d.body.innerHTML);
      }
    }
    setTimeout(function(){jQuery(i).parent().remove()},500);
  }
}


/* Multiple files uploader */
// Lancement d'un upload de 1 ou pls fichiers
TZR.uploadifyStart=function(event, data){
  if(TZR.uploadifyInProgressFiles==undefined) TZR.uploadifyInProgressFiles=0
  TZR.uploadifyInProgressFiles+=data.filesSelected;
  TZR.uploadifyAutoSave=confirm(TZR.uploadifyAutoSaveMessage);
  if(TZR.uploadifyKeepAliveURL && !TZR.uploadifyKeepAliveTimer){
    TZR.uploadifyKeepAliveTimer=setInterval("TZR.uploadifyKeepAlive()",1000);
  }
  TZR.addOnSubmit('TZR.uploadifyCheckSubmit()');
}
// Annulation d'un fichier
TZR.uploadifyCancel=function(event, ID, fileObj, data, clearFast){
  TZR.uploadifyInProgressFiles--;
}
// Upload d'un fichier terminé
TZR.uploadifyComplete=function(event, ID, fileObj, response, data){
  jQuery("#" + event.target.id + ID + " .percentage").text(" - Completed");
  jQuery("#" + event.target.id + ID + " .cancel").remove();
  TZR.uploadifyInProgressFiles--;
  return false;
}
// Fin de traitement de file d'attente
TZR.uploadifyAllComplete=function(event, uploadObj){
  clearInterval(TZR.uploadifyKeepAliveTimer);
  TZR.uploadifyKeepAliveTimer=undefined;
  if(TZR.uploadifyAutoSave) {
    var form=jQuery(event.target).parents('form:first')[0];
    if(jQuery(form).triggerHandler('submit')!==false) form.submit();
  }
  TZR.uploadifyAutoSave=false;
}
// Garde en vie la session en cours
TZR.uploadifyKeepAlive=function(){
  TZR.file_get_contents(TZR.uploadifyKeepAliveURL,true);
}
// Verifie si aucun upload n'est en cours
TZR.uploadifyCheckSubmit=function(){
  if(TZR.uploadifyInProgressFiles>0) TZR.isFormOk=false;
}
// Passe en mode standard
TZR.uploadifySwapMode=function(fieldname){
  TZR.uploadifyInProgressFiles=0;
  var std=document.getElementById(fieldname+'stdupload');
  var multi=document.getElementById(fieldname+'multiupload');
  if(std.style.display=='none'){
    document.getElementById(fieldname+'swaplink').style.display='none';
    document.getElementById(fieldname+'multiuploadUploader').style.display='none';
    document.getElementById(fieldname+'multiuploadQueue').style.display='none';
    std.style.display='block';
    multi.style.display='none';
    document.forms.editform.elements[fieldname+'_STDMODE'].value='stdmode';
  }
  return false;
}

/* Gestion des champs thesaurus */
// Active le thesaurus
TZR.activeThesaurus=function(varid,moid,field,rw){
  var div=jQuery('#div'+varid);
  var table=jQuery('#table'+varid);
  var tree=jQuery("#tree"+varid);
  tree.simpleTree({
    drag:false,
    docToFolderConvert:true,
    afterClick:function(node,updateonly){
      var span=jQuery("span:first span:first",node);
      var oid=node.attr('tzroid');
      if(span.hasClass("selected") && !updateonly){
        span.removeClass("selected").addClass("unselected");
	jQuery('input[value="'+oid+'"]',table).parents('tr:first').remove();
      }else{
	if(updateonly) var tds=jQuery('input[value="'+oid+'"]',table).parents('tr:first').find('td');
	else var tds=jQuery('tr:first',table).clone().appendTo(table).show().find('td');
	if(tds.length==0) return;
	var parents=span.parentsUntil('li.root');
	var text='';
	span.removeClass("unselected").addClass("selected");
	jQuery('input',tds[0]).val(oid);
	for(var i=parents.length-1;i>=0;i--){
	  if(parents[i].nodeName=="LI"){
	    text+=jQuery('span:first span:first',parents[i]).html()+" > ";
	  }
	}
	tds[1].innerHTML=text.substr(0,text.length-3);
      }
    },
    afterAjax:function(node){
      TZR.applySelectedValue(node,varid);
      if(rw) TZR.applyThesaurusMenu(node,varid,moid,field);
    }
  });
  TZR.applySelectedValue(tree,varid);
  if(rw) TZR.applyThesaurusMenu(tree,varid,moid,field);
}
// Selectionne les termes
TZR.applySelectedValue=function(node,varid){
  var table=jQuery('#table'+varid);
  jQuery('li',node).each(function(){
    var jt=jQuery(this);
    var oid=jt.attr('tzroid');
    if(oid && jQuery('input[value="'+oid+'"]',table).length>0){
      jt.find('>span>span').addClass('selected');
    }
  });
}
// Applique le menu contextuel à un thesaurus
TZR.applyThesaurusMenu=function(node,varid,moid,field){
  if(!document.getElementById('xthesaurusmenu')){
    jQuery('<ul id="xthesaurusmenu" class="contextMenu"><li><a href="#add">Add</li><li class="edit"><a href="#edit">Edit</a></li><li class="cut separator"><a href="#del">Delete</a></li></ul>').appendTo(document.body);
  }
  jQuery("li>span>span",node).contextMenu({menu:'xthesaurusmenu',
					   beforeShow:function(o){
					     if(jQuery(o).parents('li:first').hasClass('root')){
					       this.disableContextMenuItems('#del,#edit');
					     }else{
					       this.enableContextMenuItems('#del,#edit');
					     }
					   }},function(action, el, pos) {
    if(action.lastIndexOf('#')!==-1) action=action.substr(action.lastIndexOf('#')+1);
    var tree=el.parents('ul.simpleTree:first')[0];
    var oid=el.parents('li:first').attr('tzroid');
    if(action=="del"){
      jQuery.ajax({url:'/tzr/scripts/ajax8.php?PHPSESSID='+TZR._sessid+'&class=xthesaurusdef&function=xthesaurusdef_delvalue&moid='+moid+'&field='+field+'&oid='+oid,async:false,success:function(data){
	if(data=="ok"){
	  el.parent().addClass('active');
	  tree.delNode();
	  TZR.removeThesaurusValue(varid,oid);
	}
      }})
    }else if(action=="edit"){
      var input=jQuery('<input type="text" name="value">');
      input.val(el.html());
      input.keypress(function(e){
	if(e.which==0 || e.which==27){
	  jQuery(this).parent().find('span:first').show();
	  jQuery(this).remove();
	}else if(e.which==13){
	  var _this=this;
	  jQuery.ajax({url:'/tzr/scripts/ajax8.php?PHPSESSID='+TZR._sessid+'&class=xthesaurusdef&function=xthesaurusdef_editvalue&moid='+moid+'&field='+field+'&oid='+oid,async:false,data:{value:this.value},success:function(data){
	    var span=jQuery(_this).parent().find('span:first');
	    var li=span.parents('li:first');
	    if(data=="ok"){
	      span.html(_this.value);
	      tree.option.afterClick(li,true);
	    }
	    span.show();
	    jQuery(_this).remove();
	  }});
	  return false;
	}
      }).bind('click dblclick mousedown mouseup mousemove',function(e){e.stopPropagation();});
      el.hide().parent().append(input);
      input[0].focus();
    }else if(action=='add'){
      var input=jQuery('<input type="text" name="value">');
      input.keypress(function(e){
	if(e.which==0){
	  jQuery(this).parent().parent().addClass('active');
	  tree.delNode();
	}else if(e.which==13){
	  var _this=this;
	  jQuery.ajax({url:'/tzr/scripts/ajax8.php?PHPSESSID='+TZR._sessid+'&class=xthesaurusdef&function=xthesaurusdef_addvalue&moid='+moid+'&field='+field,async:false,data:{value:this.value,parentoid:el.parents('li:first').attr('tzroid')},success:function(data){
	    if(data){
	      jQuery(_this).parent().html(_this.value).parents('li:first').attr('tzroid',data);
	      jQuery(_this).remove();
	    }else{
	      jQuery(_this).parent().parent().addClass('active');
	      tree.delNode();
	    }
	  }});
	  return false;
	}
      }).bind('click dblclick mousedown mouseup mousemove',function(e){e.stopPropagation();});
      tree.getSelected().find('span.active').removeClass('active');
      el.parent().addClass('active');
      tree.addNode(varid+'_tmp','<span></span>',function(dst,src){
	TZR.applyThesaurusMenu(dst,varid,moid,field);
	jQuery('>span>span',src).html(input);
	input[0].focus();
      });
    }
  });  
}
// Supprime une valeur du thesaurus de la selection
TZR.removeThesaurusValue=function(varid,oid){
  var tree=jQuery("#tree"+varid);
  var table=jQuery('#table'+varid);
  if(typeof(oid)=='object'){
    oid=jQuery(oid).parents('tr:first').find('input').val();
  }
  jQuery('input[value="'+oid+'"]',table).parents('tr:first').remove();
  jQuery('li[tzroid="'+oid+'"] span.selected',tree).removeClass("selected").addClass("unselected");
}
// Ajoute une valeur suite à une saisie via le champ en autocomplete
TZR.autocompleteThesaurus=function(varid,oid,v){
  if(oid && v){
    var table=jQuery('#table'+varid);
    if(table.find('input[value="'+oid+'"]').length>0) return;
    var tree=jQuery('#tree'+varid);
    var tds=jQuery('tr:first',table).clone().appendTo(table).show().find('td');
    if(tds.length==0) return;
    jQuery('input',tds[0]).val(oid);
    tds[1].innerHTML=v;
    tree.find('li[tzroid="'+oid+'"]>span>span').addClass('selected').removeClass('unselected');
  }
}

// Fonctions d'ajout de ligne, de colonne et d'application de tablesorter à un champ XTableDef
TZR.XTableAddLine=function(tableid,fname){
  var jt=jQuery('#'+tableid);
  var tr=jt[0].tBodies[0].rows[jt[0].tBodies[0].rows.length-1];
  var jnewtr=jQuery(tr).clone(true);
  var reg=new RegExp(fname+"\\[(\\d+)\\]","g");
  var reg2=new RegExp("\\[_rlabels\\]\\[(\\d+)\\]","g");
  var regres=reg.exec(tr.innerHTML);
  var newnum=parseInt(regres[1])+1;
  jnewtr.html(tr.innerHTML.replace(reg,fname+"["+newnum+"]").replace(reg2,"[_rlabels]["+newnum+"]").replace('<td>'+regres[1]+'</td>','<td>'+newnum+'</td>'));
  jnewtr.insertAfter(tr).find('input').keyup(function(){jQuery("#"+tableid).trigger("update");}).bind('click mousedown',function(e){e.stopPropagation();}).val('');
  jt.trigger("update");
}
TZR.XTableAddColumn=function(tableid,fname){
  var jt=jQuery('#'+tableid);
  var trs=jt.find('tr')
  trs.each(function(i){
    if(this.cells.length>1){
      var reg=/(\[[^\]]+\])\[(\d+)\]/g;
      var td=this.cells[this.cells.length-2];
      var jnewtd=jQuery(td).clone(true);
      var regres=reg.exec(td.innerHTML);
      var newnum=parseInt(regres[2])+1;
      jnewtd.html(td.innerHTML.replace(reg,"$1["+newnum+"]"));
      jnewtd.insertAfter(td).find('input').keyup(function(){jQuery("#"+tableid).trigger("update");}).bind('click mousedown',function(e){e.stopPropagation();}).val('');;
    }
  });
  jt.trigger("update");
}
TZR.XTableSorter=function(tableid){
  jQuery('#'+tableid).find('input').keyup(function(){jQuery("#"+tableid).trigger("update");}).bind('click mousedown',function(e){e.stopPropagation();});
  jQuery('#'+tableid).tablesorter({textExtraction:function(node){
    var i=jQuery('input',node);
    if(i.length>0) return i[0].value;
    else return node.innerHTML;
  }});
}

/*
 * nyroModal - jQuery Plugin
 * http://nyromodal.nyrodev.com
 *
 * Copyright (c) 2010 Cedric Nirousset (nyrodev.com)
 * Licensed under the MIT license
 *
 * $Date: 2010-02-23 (Tue, 23 Feb 2010) $
 * $version: 1.6.2
 */
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('6o(k($){c 1F=6F.1F.2F();c 58=(1F.6i(/.+(?:7N|6h|7w|6g|44)[\\/: ]([\\d.]+)/)||[0,\'0\'])[1];c 26=(/44/.22(1F)&&!/6g/.22(1F)&&6b(58)<7&&(!14.67||3Z(67)===\'k\'));c U=$(\'U\');c 4;c 4X;c 32=m;c W={};c 2r=m;c 2g;c 30;c 5={3W:m,1N:m,1q:m,16:m,2p:m,1G:m,1r:m,1K:m,3V:m,1B:m,1g:D,2a:D,1n:D,15:D,P:D,j:D,l:D,N:D,C:D,3S:1S 2X(),3R:1S 2X()};c 1o={8:m,b:m,2K:m};c 1j={8:D,b:D,2K:p};c 4M;$.1C.K=k(f){6(!R)u m;u R.3Q(k(){c 3P=$(R);6(R.3k.2F()==\'23\'){3P.1D(\'4J.K\').1Y(\'4J.K\',k(e){6(e.5E())u m;6(3P.L(\'4H\'))u p;6(R.5A==\'5y/23-L\'){1O($.Q(f,{E:R}));u p}e.1U();1O($.Q(f,{E:R}));u m})}q{3P.1D(\'1u.K\').1Y(\'1u.K\',k(e){6(e.5E())u m;e.1U();1O($.Q(f,{E:R}));u m})}})};$.1C.3O=k(f){6(!R.1i)1O(f);u R.3Q(k(){1O($.Q(f,{E:R}))})};$.3O=k(f){1O(f)};$.3N=k(f,1m,28){Z(f,1m,28);6(!1m&&5.3W){6(5.15&&f.2Y)4.3L(5,4,k(){});6(5.C&&f.O)4v();6(!5.1B&&(f.2K||(!5.1K&&((\'8\'3I f&&f.8==4.8)||(\'b\'3I f&&f.b==4.b))))){5.1K=p;6(5.C)3H(p);6(5.C&&5.C.6C(\':4q\')&&!5.2p){6(2r)5.l.o({12:\'\'});4.2A(5,4,k(){4.2K=m;5.1K=m;6(2r)5.l.o({12:\'4n\'});6($.1J(4.4k))4.4k(5,4)})}}}};$.7J=k(){1V()};$.2B=k(){c 2D=2W(1);6(2D)u 2D.3O(2L());u m};$.2I=k(){c 2D=2W(-1);6(2D)u 2D.3O(2L());u m};$.1C.K.f={H:m,1g:m,6j:p,5:m,F:\'\',3G:D,E:\'\',34:\'\',4h:D,3c:\'7M\',3F:\'K\',l:D,2Y:\'#6y\',21:{},1e:{6U:\'7p\'},8:D,b:D,4b:2n,4a:5I,5H:p,5D:p,1l:25,5s:\'[^\\.]\\.(74|7b|7c|7d|7e|7l)\\s*$\',5h:m,54:\'51\',5d:p,5c:p,W:D,59:\'<a 1a="#" 11="2I">6W</a><a 1a="#"  11="2B">72</a>\',2t:2t,6d:m,33:1p,1b:{15:{12:\'36\',1E:\'2b\',1f:0,1h:0,b:\'1p%\',8:\'1p%\'},N:{12:\'36\',1f:\'50%\',1h:\'50%\'},3i:{},l:{},P:{12:\'36\',1f:\'50%\',1h:\'50%\',V:\'-3A\',S:\'-3A\'}},3m:{v:\'<v 11="N"></v>\',21:\'<v 11="N"></v>\',23:\'<v 11="N"></v>\',4Q:\'<v 11="N"></v>\',1v:\'<v 11="76"></v>\',1e:\'<v 11="7a"></v>\',B:\'<v 11="5u"></v>\',3x:\'<v 11="5u"></v>\',6f:\'<v 11="N"></v>\'},5a:\'<a 1a="#" 11="3w" 1d="7E" O="7I">5X</a>\',O:D,5Q:p,4r:\'.K\',3v:\'.3w\',5r:\'<a 1a="#" 11="3w">6A</a>\',5q:\'1B\',60:\'6I 6K l 6N 6Q 6T.<3u />6V 5C 6X 6Y.<3u /><a 1a="#" 11="3w">5X</a>\',4T:D,3t:3t,2v:2v,4N:D,3s:3s,2f:D,4u:D,3b:3b,3r:3r,3q:3q,3p:3p,3f:3f,2A:2A,4k:D,3L:3L,1Z:D};k 1O(f){6(5.1G||5.1r||5.16)u;H(\'1O\');5.3W=p;4X=$.Q(p,f);4Z(f);6(!5.1n)5.2a=5.1g=D;5.1B=m;5.3V=m;5.1q=m;5.3S=1S 2X();5.3R=1S 2X();4.F=5w();6(4.3G){6(!4.l)4.E=p;4.F=4.3G;4.3G=D}6($.1J(4.4h))4.4h(4);c E=4.E;c t=4.t;1j.8=4.8;1j.b=4.b;6(4.F==\'1e\'){Z({1E:\'4q\'},\'1b\',\'l\');4.l=\'<4S 7O="7T:7K-6p-6s-6t-6w" 8="\'+4.8+\'" b="\'+4.b+\'"><3o 1c="6B" 2H="\'+t+\'"></3o>\';c j=\'\';$.3Q(4.1e,k(1c,4l){4.l+=\'<3o 1c="\'+1c+\'" 2H="\'+4l+\'"></3o>\';j+=\' \'+1c+\'="\'+4l+\'"\'});4.l+=\'<4C 1k="\'+t+\'" F="6M/x-6O-6P" 8="\'+4.8+\'" b="\'+4.b+\'"\'+j+\'></4C></4S>\'}6(E){c X=$(E).6R();6(4.F==\'23\'){c L=$(E).6S();L.3h({1c:4.3F,2H:1});6(4.19)L.3h({1c:4.3c,2H:4.19.1Q(1)});1x();$.21($.Q({},4.21,{t:t,L:L,F:X.I(\'5j\')?X.I(\'5j\'):\'3a\',5Z:4m,1B:1t}));H(\'4D 5P 2w: \'+X.I(\'2u\'))}q 6(4.F==\'4Q\'){1L();X.I(\'2s\',\'2c\');X.I(\'2u\',t);X.2Z(\'<48 F="2b" 1c="\'+4.3F+\'" 2H="1" />\');6(4.19)X.2Z(\'<48 F="2b" 1c="\'+4.3c+\'" 2H="\'+4.19.1Q(1)+\'" />\');5.j.M(\'<B 4c="0" 4e="0" 1c="2c" 1k="2y:\\\'\\\';"></B>\');$(\'B\',5.j).o({8:4.8,b:4.b}).1B(1t).2o(4j);H(\'4D 6m 2w: \'+X.I(\'2u\'));1x();1z()}q 6(4.F==\'1v\'){H(\'51 2w: \'+t);c O=X.I(\'O\')||4.54;1L();5.j.M(\'<2U 1d="6r" />\').29(\'2U\').I(\'5R\',O);5.j.o({5S:0});$(\'2U\',5.j).1B(1t).2o(k(){H(\'51 6x: \'+R.1k);$(R).1D(\'2o\');c w=5.j.8();c h=5.j.b();5.j.o({5S:\'\'});1o.8=w;1o.b=h;Z({8:w,b:h,4x:w,4y:h});1j.8=w;1j.b=h;Z({1E:\'4q\'},\'1b\',\'l\');5.1q=p;6(5.1G||5.1r)1z()}).I(\'1k\',t);1x()}q 6(4.F==\'3x\'){1L();5.j.M(\'<B 4c="0" 4e="0" 1k="2y:\\\'\\\';" 1c="2c" 1d="2c"></B>\');H(\'6l 4D 2w: \'+t);$(\'B\',5.j).2P(0).o({8:\'1p%\',b:$.5b.5f?\'5g%\':\'1p%\'}).2o(4B);5.1q=p;1x()}q 6(4.F==\'B\'){1L();5.j.M(\'<B 4c="0" 4e="0" 1k="2y:\\\'\\\';" 1c="2c" 1d="2c"></B>\');H(\'6l 2w: \'+t);$(\'B\',5.j).2P(0).o({8:\'1p%\',b:$.5b.5f?\'5g%\':\'1p%\'}).2o(4B);5.1q=p;1x()}q 6(4.F){H(\'5n: \'+4.F);1L();5.j.M(4.l);c w=5.j.8();c h=5.j.b();c v=$(4.F);6(v.1i){Z({F:\'v\'});w=v.8();h=v.b();6(2g)30=2g;2g=v;5.j.1A(v.24())}1j.8=w;1j.b=h;Z({8:w,b:h});6(5.j.M())5.1q=p;q 1t();6(!5.1N)1x();q 2x()}q{H(\'5P 2w: \'+t);Z({F:\'21\'});c L=4.21.L||{};6(4.19){6(3Z L=="4E"){L+=\'&\'+4.3c+\'=\'+4.19.1Q(1)}q{L[4.3c]=4.19.1Q(1)}}1x();$.21($.Q(p,4.21,{t:t,5Z:4m,1B:1t,L:L}))}}q 6(4.l){H(\'5n: \'+4.F);Z({F:\'6f\'});1L();5.j.M($(\'<v/>\').M(4.l).24());6(5.j.M())5.1q=p;q 1t();1x()}q{}}k 4Z(f){H(\'4Z\');4=$.Q(p,{},$.1C.K.f,f);3y()}k Z(f,1m,28){6(5.3W){6(1m&&28){$.Q(p,4[1m][28],f)}q 6(1m){$.Q(p,4[1m],f)}q{6(5.2p){6(\'8\'3I f){6(!5.1K){f.4L=f.8;32=p}3z f[\'8\']}6(\'b\'3I f){6(!5.1K){f.4O=f.b;32=p}3z f[\'b\']}}$.Q(p,4,f)}}q{6(1m&&28){$.Q(p,$.1C.K.f[1m][28],f)}q 6(1m){$.Q(p,$.1C.K.f[1m],f)}q{$.Q(p,$.1C.K.f,f)}}}k 4P(){6(26&&!5.1g){6(1X.4R){4.2m=1X.4R.61;4.2i=1X.4R.3B}q{4.2m=1X.U.61;4.2i=1X.U.3B}}q{4.2m=0;4.2i=0}}k 3y(){4P();4.S=-(4.8+4.4U)/2;4.V=-(4.b+4.4Y)/2;6(!5.1g){4.S+=4.2m;4.V+=4.2i}}k 3C(){4P();c 1M=2C(5.P);4.2S=-(5.P.b()+1M.h.18+1M.h.1l)/2;4.2Q=-(5.P.8()+1M.w.18+1M.w.1l)/2;6(!5.1g){4.2Q+=4.2m;4.2S+=4.2i}}k 4v(){c O=$(\'55#5l\',5.C);6(O.1i)O.5m(4.O);q 5.C.2Z(\'<55 1d="5l">\'+4.O+\'</55>\')}k 1L(){H(\'1L\');6(!5.1n){6(4.H)Z({7P:\'7Q\'},\'1b\',\'15\');c 1n={2O:4.33,12:\'4n\',1f:0,1h:0,8:\'1p%\',b:\'1p%\'};c 46=U;c 47=\'\';6(4.1g){5.1g=46=$(4.1g);c 2N=5.1g.6q();c w=5.1g.5t();c h=5.1g.3D();6(26){Z({b:\'1p%\',8:\'1p%\',1f:0,1h:0},\'1b\',\'15\')}5.2a={1f:2N.1f,1h:2N.1h,8:w,b:h};c 5v=(/44/.22(1F)?0:17(U.3a(0),\'5x\'));c 5z=(/44/.22(1F)?0:17(U.3a(0),\'5B\'));1n={12:\'36\',1f:2N.1f+5v,1h:2N.1h+5z,8:w,b:h}}q 6(26){U.o({S:0,49:0});c w=U.8();c h=$(14).b()+\'G\';6($(14).b()>=U.3D()){h=U.3D()+\'G\'}q w+=20;w+=\'G\';U.o({8:w,b:h,12:\'6E\',1E:\'2b\'});$(\'M\').o({1E:\'2b\'});Z({1b:{15:{12:\'36\',2O:4.33+1,b:\'5G%\',8:\'5G%\',1f:4.2i+\'G\',1h:4.2m+\'G\'},N:{2O:4.33+2},P:{2O:4.33+3}}});47=$(\'<B 1d="6H" 1k="2y:\\\'\\\';"></B>\').o($.Q({},4.1b.15,{1s:0,2O:50,18:\'3l\'}))}46.1A($(\'<v 1d="5J"><v 1d="5K"></v><v 1d="5L"><v 1d="5M"></v></v><v 1d="5N"></v><v 1d="5O"></v></v>\').13());5.1n=$(\'#5J\').o(1n).2j();5.15=$(\'#5K\').o($.Q({3E:4.2Y},4.1b.15)).4d(47);5.15.1Y(\'1u.K\',5T);5.P=$(\'#5O\').o(4.1b.P).13();5.C=$(\'#5L\').o(4.1b.N).13();5.l=$(\'#5M\');5.j=$(\'#5N\').13();6($.1J($.1C.5V)){5.l.5V(k(e,d){c 35=5.l.3a(0);6((d>0&&35.3B==0)||(d<0&&35.6Z-35.3B==35.70)){e.1U();e.71()}})}$(1X).1Y(\'4f.K\',4g);5.l.o({8:\'1I\',b:\'1I\'});5.C.o({8:\'1I\',b:\'1I\'});6(!4.1g&&4.6j){$(14).1Y(\'2A.K\',k(){14.78(4M);4M=14.79(68,69)})}}}k 68(){$.3N(1j)}k 1x(){H(\'1x\');6(!5.1N){1L();5.16=p;4.3t(5,4,4i)}q{5.16=p;5.1r=p;4.3r(5,4,k(){2x();5.16=m;1z()})}}k 5T(e){6(!4.5)1V()}k 4g(e){6(e.31==27){6(!4.5)1V()}q 6(4.W&&5.1N&&5.1q&&!5.16&&!5.1r){6(e.31==39||e.31==40){e.1U();$.2B();u m}q 6(e.31==37||e.31==38){e.1U();$.2I();u m}}}k 5w(){c E=4.E;c t;6(E&&E.3k){c X=$(E);t=X.I(E.3k.2F()==\'23\'?\'2u\':\'1a\');6(!t)t=1P.1a.1Q(14.1P.7k.1i+7);4.t=t;6(X.I(\'6k\')==\'5\')4.5=p;4.O=X.I(\'O\');6(E&&E.1w&&E.1w.2F()!=\'7v\'){c 4K=E.1w.3n(\' \');4.W=4K>0?E.1w.7H(0,4K):E.1w}c 2G=4o(t,E);6(2G)u 2G;6(4p(t))u\'1e\';c B=m;6(E.2s&&E.2s.2F()==\'5e\'||(E.3e&&E.3e.2e(/:\\d*$/,\'\')!=14.1P.3e.2e(/:\\d*$/,\'\'))){B=p}6(E.3k.2F()==\'23\'){6(B)u\'3x\';Z(4s(t));6(X.I(\'5A\')==\'5y/23-L\')u\'4Q\';u\'23\'}6(B)u\'B\'}q{t=4.t;6(!4.l)4.E=p;6(!t)u D;6(4p(t))u\'1e\';c 5i=1S 4t("^5k://|6n://","g");6(t.6i(5i))u\'B\'}c 2G=4o(t,E);6(2G)u 2G;c j=4s(t);Z(j);6(!j.t)u j.19}k 4o(t,E){c 1v=1S 4t(4.5s,\'i\');6(1v.22(t)){u\'1v\'}}k 4p(t){c 1e=1S 4t(\'[^\\.]\\.(1e)\\s*$\',\'i\');u 1e.22(t)}k 4s(t){c J={t:D,19:D};6(t){c 34=4w(t);c 5o=4w(14.1P.1a);c 5p=14.1P.1a.1Q(0,14.1P.1a.1i-5o.1i);c 3J=t.1Q(0,t.1i-34.1i);6(3J==5p||3J==$(\'6u\').I(\'1a\')){J.19=34}q{J.t=3J;J.19=34}}u J}k 1t(){H(\'1t\');5.1B=p;6(!5.1N)u;6($.1J(4.4T))4.4T(5,4);5.P.6v(4.5q).M(4.60);$(4.3v,5.P).1D(\'1u.K\').1Y(\'1u.K\',1V);3C();5.P.o({V:4.2S+\'G\',S:4.2Q+\'G\'})}k 3K(){H(\'3K\');6(!5.j.M())u;5.l.M(5.j.24());5.j.4z();4A();6(4.F==\'3x\'){$(4.E).I(\'2s\',\'2c\').L(\'4H\',1).4J().I(\'2s\',\'5e\').6z(\'4H\')}6(!4.5)5.N.2Z(4.5a);6($.1J(4.4N))4.4N(5,4);5.l.1A(5.3S);$(4.3v,5.C).1D(\'1u.K\').1Y(\'1u.K\',1V);$(4.4r,5.C).K(2L())}k 2L(){u 4X;c 1T=$.Q(p,{},4);6(1o.8)1T.8=D;q 1T.8=1j.8;6(1o.b)1T.b=D;q 1T.b=1j.b;1T.1b.l.1E=\'1I\';u 1T}k 4A(){H(\'4A\');c 3m=$(4.3m[4.F]);5.l.1A(3m.3M().2h());5.C.6D(3m);6(4.W){5.l.1A(4.59);W.1R=$(\'[1w="\'+4.W+\'"], [1w^="\'+4.W+\' "]\');W.1H=W.1R.1H(4.E);6(4.2t&&$.1J(4.2t))4.2t(W.1H+1,W.1R.1i,5,4);c 1T=2L();c 4F=2W(-1);6(4F){c 2l=$(\'.2I\',5.C).I(\'1a\',4F.I(\'1a\')).1u(k(e){e.1U();$.2I();u m});6(26&&4.F==\'1e\'){2l.4d($(\'<B 1d="6G" 1k="2y:\\\'\\\';"></B>\').o({12:2l.o(\'12\'),1f:2l.o(\'1f\'),1h:2l.o(\'1h\'),8:2l.8(),b:2l.b(),1s:0,18:\'3l\'}))}}q{$(\'.2I\',5.C).2h()}c 4G=2W(1);6(4G){c 2d=$(\'.2B\',5.C).I(\'1a\',4G.I(\'1a\')).1u(k(e){e.1U();$.2B();u m});6(26&&4.F==\'1e\'){2d.4d($(\'<B 1d="6J" 1k="2y:\\\'\\\';"></B>\').o($.Q({},{12:2d.o(\'12\'),1f:2d.o(\'1f\'),1h:2d.o(\'1h\'),8:2d.8(),b:2d.b(),1s:0,18:\'3l\'})))}}q{$(\'.2B\',5.C).2h()}}3H()}k 2W(4I){6(4.W){6(!4.5c)4I*=-1;c 1H=W.1H+4I;6(1H>=0&&1H<W.1R.1i)u W.1R.2P(1H);q 6(4.6d){6(1H<0)u W.1R.2P(W.1R.1i-1);q u W.1R.2P(0)}}u m}k 3H(1K){H(\'3H\');5.N=5.C.3M(\'v:6L\');1o.8=m;1o.b=m;6(m&&!4.2K){1j.8=4.8;1j.b=4.b}6(4.5D&&(!4.8||!4.b)){5.C.o({1s:0,8:\'1I\',b:\'1I\'}).2j();c j={8:\'1I\',b:\'1I\'};6(4.8){j.8=4.8}q 6(4.F==\'B\'){j.8=4.4b}6(4.b){j.b=4.b}q 6(4.F==\'B\'){j.b=4.4a}5.l.o(j);6(!4.8){4.8=5.l.5t(p);1o.8=p}6(!4.b){4.b=5.l.3D(p);1o.b=p}5.C.o({1s:1});6(!1K)5.C.13()}6(4.F!=\'1v\'&&4.F!=\'1e\'){4.8=2k.5F(4.8,4.4b);4.b=2k.5F(4.b,4.4a)}c 3j=2C(5.C);c 3g=2C(5.N);c 1y=2C(5.l);c j={l:{8:4.8,b:4.b},3i:{8:4.8+1y.w.Y,b:4.b+1y.h.Y},N:{8:4.8+1y.w.Y+3g.w.Y,b:4.b+1y.h.Y+3g.h.Y}};6(4.5H){c 2T=5.2a?5.2a.b:$(14).b()-3j.h.18-(j.N.b-4.b);c 2J=5.2a?5.2a.8:$(14).8()-3j.w.18-(j.N.8-4.8);2T-=4.1l*2;2J-=4.1l*2;6(j.l.b>2T||j.l.8>2J){6(4.F==\'1v\'||4.F==\'1e\'){c 3T=4.4x?4.4x:4.8;c 3U=4.4y?4.4y:4.b;c 3d=j.l.8-3T;c 2V=j.l.b-3U;6(2V<0)2V=0;6(3d<0)3d=0;c 3X=2T-2V;c 3Y=2J-3d;c 4V=2k.4W(3X/3U,3Y/3T);3Y=2k.5U(3T*4V);3X=2k.5U(3U*4V);j.l.b=3X+2V;j.l.8=3Y+3d}q{j.l.b=2k.4W(j.l.b,2T);j.l.8=2k.4W(j.l.8,2J)}j.3i={8:j.l.8+1y.w.Y,b:j.l.b+1y.h.Y};j.N={8:j.l.8+1y.w.Y+3g.w.Y,b:j.l.b+1y.h.Y+3g.h.Y}}}6(4.F==\'1e\'){$(\'4S, 4C\',5.l).I(\'8\',j.l.8).I(\'b\',j.l.b)}q 6(4.F==\'1v\'){$(\'2U\',5.l).o({8:j.l.8,b:j.l.b})}5.l.o($.Q({},j.l,4.1b.l));5.N.o($.Q({},j.3i,4.1b.3i));6(!1K)5.C.o($.Q({},j.N,4.1b.N));6(4.F==\'1v\'&&4.5h){$(\'2U\',5.l).73(\'5R\');c 1W=$(\'v\',5.l);6(4.O!=4.54&&4.O){6(1W.1i==0){1W=$(\'<v>\'+4.O+\'</v>\');5.l.1A(1W)}6(4.5d){c 5W=2C(1W);1W.o({8:(j.l.8+1y.w.1l-5W.w.Y)+\'G\'})}}q 6(1W.1i=0){1W.2h()}}6(4.O)4v();j.N.4U=3j.w.18;j.N.4Y=3j.h.18;Z(j.N);3y()}k 1V(e){H(\'1V\');6(e)e.1U();6(5.1n&&5.1N){$(1X).1D(\'4f.K\');6(!4.1g)$(14).1D(\'2A.K\');5.1N=m;5.16=p;5.3V=p;6(5.1G||5.1r){4.3f(5,4,k(){5.P.13();5.1G=m;5.1r=m;4.2v(5,4,1Z)})}q{6(2r)5.l.o({12:\'\'});5.N.o({1E:\'2b\'});5.l.o({1E:\'2b\'});$(\'B\',5.l).13();6($.1J(4.4u)){4.4u(5,4,k(){4.3b(5,4,k(){2x();4.2v(5,4,1Z)})})}q{4.3b(5,4,k(){2x();4.2v(5,4,1Z)})}}}6(e)u m}k 1z(){H(\'1z\');6(5.1N&&!5.16){6(5.1q){6(5.j.M()){5.16=p;6(5.1r){3K();5.2p=p;4.3q(5,4,k(){5.P.13();5.1r=m;5.1G=m;2f()})}q{4.3f(5,4,k(){5.P.13();5.1G=m;3K();3C();3y();5.2p=p;4.3s(5,4,2f)})}}}q 6(!5.1G&&!5.1r){5.16=p;5.1G=p;6(5.1B)1t();q 5.P.M(4.5r);$(4.3v,5.P).1D(\'1u.K\').1Y(\'1u.K\',1V);3C();4.3p(5,4,k(){5.16=m;1z()})}}}k 4m(L){H(\'77: \'+R.t);6(4.19){c j={};c i=0;L=L.2e(/\\r\\n/2R,\'5Y\').2e(/<41(.|\\s)*?\\/41>/2R,k(x){j[i]=x;u\'<42 52="62: 3l" 11=63 1w="\'+(i++)+\'"></42>\'});L=$(\'<v>\'+L+\'</v>\').29(4.19).M().2e(/<42 52="62: 3l;?" 11="?63"? 1w="(.?)"><\\/42>/2R,k(x,y,z){u j[y]}).2e(/5Y/2R,"\\r\\n")}5.j.M(64(L));6(5.j.M()){5.1q=p;1z()}q 1t()}k 4j(){H(\'4j\');c X=$(4.E);X.I(\'2u\',X.I(\'2u\')+4.19);X.I(\'2s\',\'\');$(\'48[1c=\'+4.3F+\']\',4.E).2h();c B=5.j.3M(\'B\');c 65=B.1D(\'2o\').24().29(4.19||\'U\').7f(\'41[1k]\');B.I(\'1k\',\'7g:7h\');5.j.M(65.M());6(5.j.M()){5.1q=p;1z()}q 1t()}k 4B(){6((14.1P.3e&&4.t.3n(14.1P.3e)>-1)||4.t.3n(\'5k://\')){c B=$(\'B\',5.1n).24();c j={};6(4.5Q){j.O=B.29(\'O\').5m();6(!j.O){5C{j.O=B.29(\'O\').M()}7i(7j){}}}c U=B.29(\'U\');6(!4.b&&U.b())j.b=U.b();6(!4.8&&U.8())j.8=U.8();$.Q(1j,j);$.3N(j)}}k 2t(66,Y,A,f){6(Y>1)f.O+=(f.O?\' - \':\'\')+66+\'/\'+Y}k 2x(){H(\'2x\');5.16=m;6(30){30.1A(5.l.24());30=D}q 6(2g){2g.1A(5.l.24());2g=D}5.l.4z();W={};5.C.13().3M().2h().4z().I(\'52\',\'\').13();6(5.3V||5.1r)5.C.13();5.C.o(4.1b.N).1A(5.l);1z()}k 1Z(){H(\'1Z\');$(1X).1D(\'4f\',4g);5.16=m;5.1n.2h();5.1n=D;6(26){U.o({b:\'\',8:\'\',12:\'\',1E:\'\',S:\'\',49:\'\'});$(\'M\').o({1E:\'\'})}6($.1J(4.1Z))4.1Z(5,4)}k 4i(){H(\'4i\');5.1N=p;5.16=m;1z()}k 2f(){H(\'2f\');5.16=m;5.2p=m;5.C.o({1s:\'\'});2r=/7m/.22(1F)&&!/(7n|6h)/.22(1F)&&7o(58)<1.9&&4.F!=\'1v\';6(2r)5.l.o({12:\'4n\'});5.l.1A(5.3R);6(4.F==\'B\')5.l.29(\'B\').I(\'1k\',4.t);6($.1J(4.2f))4.2f(5,4);6(32){32=m;$.3N({8:4.4L,b:4.4O});3z 4[\'4L\'];3z 4[\'4O\']}6(1o.8)Z({8:D});6(1o.b)Z({b:D})}k 4w(t){6(3Z t==\'4E\'){c 53=t.3n(\'#\');6(53>-1)u t.1Q(53)}u\'\'}k 64(L){6(3Z L==\'4E\')L=L.2e(/<\\/?(M|7q|U)([^>]*)>/2R,\'\');c j=1S 2X();$.3Q($.7r({0:L},R.7s),k(){6($.3k(R,"41")){6(!R.1k||$(R).I(\'1w\')==\'7t\'){6($(R).I(\'6k\')==\'7u\')5.3R.3h(R);q 5.3S.3h(R)}}q j.3h(R)});u j}k 2C(10){10=10.3a(0);c J={h:{43:17(10,\'V\')+17(10,\'7x\'),18:17(10,\'5x\')+17(10,\'7y\'),1l:17(10,\'7z\')+17(10,\'7A\')},w:{43:17(10,\'S\')+17(10,\'49\'),18:17(10,\'5B\')+17(10,\'7B\'),1l:17(10,\'7C\')+17(10,\'7D\')}};J.h.1M=J.h.43+J.h.18;J.w.1M=J.w.43+J.w.18;J.h.6a=J.h.1l+J.h.18;J.w.6a=J.w.1l+J.w.18;J.h.Y=J.h.1M+J.h.1l;J.w.Y=J.w.1M+J.w.1l;u J}k 17(10,1c){c J=6b($.7F(10,1c,p));6(7G(J))J=0;u J}k H(2M){6($.1C.K.f.H||4&&4.H)6c(2M,5,4||{})}k 3t(A,f,T){A.15.o({1s:0}).6e(7L,0.75,T)}k 2v(A,f,T){A.15.56(5I,T)}k 3p(A,f,T){A.P.o({V:f.2S+\'G\',S:f.2Q+\'G\',1s:0}).2j().2q({1s:1},{2z:T,2E:2n})}k 3f(A,f,T){T()}k 3s(A,f,T){A.P.o({V:f.2S+\'G\',S:f.2Q+\'G\'}).2j().2q({8:f.8+\'G\',b:f.b+\'G\',V:f.V+\'G\',S:f.S+\'G\'},{2E:57,2z:k(){A.C.o({8:f.8+\'G\',b:f.b+\'G\',V:f.V+\'G\',S:f.S+\'G\'}).2j();A.P.56(69,T)}})}k 3b(A,f,T){A.C.2q({b:\'3A\',8:\'3A\',V:(-(25+f.4Y)/2+f.2i)+\'G\',S:(-(25+f.4U)/2+f.2m)+\'G\'},{2E:57,2z:k(){A.C.13();T()}})}k 3r(A,f,T){A.P.o({V:A.C.o(\'V\'),S:A.C.o(\'S\'),b:A.C.o(\'b\'),8:A.C.o(\'8\'),1s:0}).2j().6e(2n,1,k(){A.C.13();T()})}k 3q(A,f,T){A.C.13().o({8:f.8+\'G\',b:f.b+\'G\',S:f.S+\'G\',V:f.V+\'G\',1s:1});A.P.2q({8:f.8+\'G\',b:f.b+\'G\',S:f.S+\'G\',V:f.V+\'G\'},{2z:k(){A.C.2j();A.P.56(2n,k(){A.P.13();T()})},2E:57})}k 2A(A,f,T){A.C.2q({8:f.8+\'G\',b:f.b+\'G\',S:f.S+\'G\',V:f.V+\'G\'},{2z:T,2E:2n})}k 3L(A,f,T){6(!$.7R.7S.3E){A.15.o({3E:f.2Y});T()}q A.15.2q({3E:f.2Y},{2z:T,2E:2n})}$($.1C.K.f.4r).K()});c 45=\'\';k 6c(2M,A,f){6(A.1n&&A.15){A.15.2Z(2M+\'<3u />\'+45);45=\'\'}q 45+=2M+\'<3u />\'}',62,490,'||||currentSettings|modal|if||width|||height|var|||settings||||tmp|function|content|false||css|true|else|||url|return|div|||||elts|iframe|contentWrapper|null|from|type|px|debug|attr|ret|nyroModal|data|html|wrapper|title|loading|extend|this|marginLeft|callback|body|marginTop|gallery|jFrom|total|setCurrentSettings|elm|class|position|hide|window|bg|anim|getCurCSS|border|selector|href|cssOpt|name|id|swf|top|blocker|left|length|initSettingsSize|src|padding|deep1|full|resized|100|dataReady|transition|opacity|loadingError|click|image|rel|showModal|outerContent|showContentOrLoading|append|error|fn|unbind|overflow|userAgent|loadingShown|index|auto|isFunction|resizing|initModal|outer|ready|processModal|location|substring|links|new|currentSettingsNew|preventDefault|removeModal|divTitle|document|bind|endRemove||ajax|test|form|contents||isIE6||deep2|find|blockerVars|hidden|nyroModalIframe|next|replace|endShowContent|contentElt|remove|marginScrollTop|show|Math|prev|marginScrollLeft|400|load|animContent|animate|fixFF|target|galleryCounts|action|hideBackground|Load|endHideContent|javascript|complete|resize|nyroModalNext|getOuter|link|duration|toLowerCase|imgType|value|nyroModalPrev|maxWidth|windowResizing|getCurrentSettingsNew|msg|pos|zIndex|eq|marginLeftLoading|gi|marginTopLoading|maxHeight|img|diffH|getGalleryLink|Array|bgColor|prepend|contentEltLast|keyCode|shouldResize|zIndexStart|hash|elt|absolute||||get|hideContent|selIndicator|diffW|hostname|hideLoading|outerWrapper2|push|wrapper2|outerWrapper|nodeName|none|wrap|indexOf|param|showLoading|hideTransition|showTransition|showContent|showBackground|br|closeSelector|nyroModalClose|iframeForm|setMargin|delete|50px|scrollTop|setMarginLoading|outerHeight|backgroundColor|formIndicator|forceType|calculateSize|in|req|fillContent|updateBgColor|children|nyroModalSettings|nyroModalManual|me|each|scriptsShown|scripts|useW|useH|closing|started|calcH|calcW|typeof||script|pre|margin|msie|tmpDebug|contain|iframeHideIE|input|marginRight|minHeight|minWidth|frameborder|before|hspace|keydown|keyHandler|processHandler|endBackground|formDataLoaded|endResize|val|ajaxLoaded|fixed|imageType|isSwf|visible|openSelector|extractUrlSel|RegExp|beforeHideContent|setTitle|getHash|imgWidth|imgHeight|empty|wrapContent|iframeLoaded|embed|Form|string|linkPrev|linkNext|nyroModalprocessing|dir|submit|indexSpace|setWidth|windowResizeTimeout|endFillContent|setHeight|setMarginScroll|formData|documentElement|object|handleError|borderW|ratio|min|callingSettings|borderH|setDefaultCurrentSettings||Image|style|hashPos|defaultImgAlt|h1|fadeOut|350|browserVersion|galleryLinks|closeButton|support|ltr|setWidthImgTitle|_blank|boxModel|99|addImageDivTitle|reg1|method|http|nyroModalTitle|text|Content|hashLoc|curLoc|errorClass|contentLoading|regexImg|outerWidth|wrapperIframe|plusTop|fileType|borderTopWidth|multipart|plusLeft|enctype|borderLeftWidth|try|autoSizable|isDefaultPrevented|max|110|resizable|300|nyroModalFull|nyroModalBg|nyroModalWrapper|nyroModalContent|nyrModalTmp|nyroModalLoading|Ajax|titleFromIframe|alt|lineHeight|clickBg|floor|mousewheel|outerDivTitle|Close|nyroModalLN|success|contentError|scrollLeft|display|nyroModalScript|filterScripts|iframeContent|nb|XMLHttpRequest|windowResizeHandler|200|inner|parseInt|nyroModalDebug|galleryLoop|fadeTo|manual|opera|webkit|match|windowResize|rev|Iframe|Data|https|jQuery|AE6D|offset|nyroModalImg|11cf|96B8|base|addClass|444553540000|Loaded|000000|removeData|Cancel|movie|is|wrapInner|static|navigator|nyroModalIframeHideIeGalleryPrev|nyroModalIframeHideIe|The|nyroModalIframeHideIeGalleryNext|requested|first|application|cannot|shockwave|flash|be|blur|serializeArray|loaded|wmode|Please|Prev|again|later|scrollHeight|clientHeight|stopPropagation|Next|removeAttr|jpg||wrapperImg|AjaxLoaded|clearTimeout|setTimeout|wrapperSwf|jpeg|png|tiff|gif|not|about|blank|catch|err|host|bmp|mozilla|compatible|parseFloat|transparent|head|clean|ownerDocument|forceLoad|shown|nofollow|khtml|marginBottom|borderBottomWidth|paddingTop|paddingBottom|borderRightWidth|paddingLeft|paddingRight|closeBut|curCSS|isNaN|substr|close|nyroModalRemove|D27CDB6E|500|nyroModalSel|rv|classid|color|white|fx|step|clsid'.split('|'),0,{}))
function swap_image() {
    tmp = jQuery(this).attr('src');
    jQuery(this).attr('src', jQuery(this).parent().attr('data-swap'));
    jQuery(this).parent().attr('data-swap', tmp);
};
jQuery(document).ready(function(){
  // active le mousehover sur image contenu dans les lien de class swap
  jQuery('a.swap img').hover(swap_image, swap_image);
  jQuery("img[src*='png']").addClass('pngtrans');
});

