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;
}

TZR = new Object();
TZR.isFormOk=true;
TZR.formValidation=true;
TZR.validator=new Array();
TZR.onsubmit=new Array();
//
TZR.selectAll = function (f,value) {
  start=false;
  for(var i=0;i< f.elements.length; i++) {
    if(start && (f.elements[i].type=='checkbox')) f.elements[i].checked = value;
    if(f.elements[i].value=='selectstart') start=true;
  }
}
// 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.isCaptchaValid = function(id,fmt,fieldlabel,color){
  resultatCaptcha=false;
  o=document.getElementById(id);
  ajax.setAsync(false);
  x_xmodtable_captcha(id,o.value,TZR.onCheckCaptchaComplete);
  var response = false;
  if( TZR.xmlHttpRequest.readyState == 4 ) {
    try {
      var response = JSON.parse( TZR.xmlHttpRequest.responseText );
      response=response.response;
    }catch(e){
    }
  }
  ajax.setAsync(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.isFormValid = function (f) {
  return TZR.isFormValidWithFocus(f,false);
}
TZR.isFormValidWithFocus = function (f,foc) {
  TZR.isFormOk=true;
  nb=TZR.validator.length;
  for(var i=0;i<nb;i++) {
    var o = document.getElementById(TZR.validator[i][0]);
    if(o!=null && o.form.name==f.name) {
      TZR.isIdxValid(i);
      if(foc) {
	if(!TZR.isFormOk) {
	  if(TZR.validator[i][5])
	    o=document.getElementById(TZR.validator[i][5]);
	  o.focus();
	  return false;
	}
      }
    }
  }
  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]=='Captcha')
      isValid=TZR.isCaptchaValid(val[0],val[1],val[2],val[3]);
   return isValid;
}

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) {
  nb=TZR.validator.length;  
  TZR.validator[nb]=src;
}

TZR.editSec = function (selfu, moid, oid) {
   window.open(selfu+'&function=secEdit&template=xmodule/edit-sec.html&moid='+moid+'&tplentry=br&oid='+oid,
   'SecBrowser','width=500,height=300,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);
  }
}
      
TZR.toggleCheckBoxes = function(src) {
  var start=false;
  var i=0;
  for(i=0;i< src.elements.length; i++) {
    if(start) src.elements[i].checked = !src.elements[i].checked;
    if(src.elements[i].value=='selectstart') start=true;
  }
}
TZR.checkBoxes = function(src, value) {
  var start=false;
  var i=0;
  for(i=0;i< src.elements.length; i++) {
    if(start) src.elements[i].checked=value;
    if(src.elements[i].value=='selectstart') {
      start=true;
    }
  }
}
TZR.checkBoxesIsChecked = function(src) {
  var start=false;
  var i=0;
  for(i=0;i< src.elements.length; i++) {
    if(start && src.elements[i].checked) return true;
    if(src.elements[i].value=='selectstart') {
      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+'&class=XModDocMgt&function=index2&template=xmoddocmgt/poptree2.html&moid='+moid+
		'&tplentry=br&showfiles=1&target='+id,
	      	'DocumentBrowser','width=400,height=500,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+'&class=XModInfoTree&function=home&template=xmodinfotree/pop2.html&moid='+
		moid+'&tplentry=mit&do=showtree',
	      	'TreeBrowser','width=400,height=300,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;
     form.template.value=template;
     form.tplentry.value=tplentry;
     form.submit();	
   }else{
     alert(noselect);
     return;
   }
}

TZR.doubleAdd = function(src, dst) {
  var i=0;
  for (i=src.options.length-1;i>=0;i--) {
    if (src.options[i].selected) { 
      dst.options[dst.options.length]=new Option(src.options[i].text,src.options[i].value);
      src.options[i]=null;
    }
  }
}

TZR.idxidx=10;
TZR.addTableLine = function(tableid,td) {
  if(td[1]=='--') return;
  var table = document.getElementById(tableid);
  var tbody = table.tBodies[0];
  var tr = tbody.rows[0].cloneNode(true);
  table.tBodies[0].appendChild(tr);
  var td3;
  for(i=0;i<td.length; i++) {
    td3=td[i].replace(/xidxid/g,'xid'+TZR.idxidx);
    var span=document.createElement("span");
    span.innerHTML=td3;
    tr.cells[i].appendChild(span);
    tr.cells[i].innerHTML=td3;
    var allscripts=tr.cells[i].getElementsByTagName("script")
    for(var j=0; j<allscripts.length; j++) {
      var s=allscripts[j];
       if(s.src && s.src!="") {
         eval(getFileContent(s.src))
       }else {
         eval(s.innerHTML)
       }
    }
  }
  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'));
}
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.uniqid=function(prefix){
  if(typeof(prefix)=='undefined') prefix="";
  var alea=Math.random()*1000000000;
  return prefix+alea.toString();
}

/* 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){
  if(typeof o=="string") { o=document.getElementById(o); }
  if(o.type=="text" || o.type=="textarea"){
    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="";
  }
}
// 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;
  }
}
// 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") && f.elements[i].value==f.elements[i].ovalue){
      f.elements[i].value="";
    }
  }
}

/* Fonctions pour formater les champs date(fr seulement pour le moment) et heure/durée */
TZR.formatDate=function(obj){
  val=obj.value;
  tab=val.split("/");
  date=new Date();
  
  if(!tab[0])
    tab[0]=date.getDate();
  if(!tab[1])
    tab[1]=date.getMonth()+1;
  if(!tab[2])
    tab[2]=date.getFullYear();
  
  if(/^[1-9]$/.test(tab[0])) {
    tab[0]="0"+tab[0];
  }
  if(/^[1-9]$/.test(tab[1])) {
    tab[1]="0"+tab[1];
  }
  if(/^[0-9]$/.test(tab[2])) {
    tab[2]="200"+tab[2];
  }
  if(/^[0-9]{2}$/.test(tab[2])) {
    tab[2]="20"+tab[2];
  }
  obj.value=tab.join("/");
}

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(":");
}

/* 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();
    }
  }
};

TZR.KeyPad={
 emptyCell:"&nbsp;",
 fakeDigit:"*",
 addDigit:function(digit){
  this.realfield.value+=digit;
  if(typeof(this.fakefield)=="object") this.fakefield.value+=this.fakeDigit;
 },
 reset:function(){
  this.realfield.value="";
  if(typeof(this.fakefield)=="object") this.fakefield.value="";
 },
 get:function(realfield,fakefield,col,row,alphabet){
  this.realfield=realfield;
  this.fakefield=fakefield;
  var tot=col*row;
  var alphaarray=alphabet.split(",");
  var alphalength=alphaarray.length;
  for(var i=alphalength; i<tot; i++) {
   alphaarray.push(this.emptyCell);
  }
  var grille=new Array();
  var stringgrille="<table class=\"keyPad\">";
  var val;
  for(i=0;i<tot;i++){
   val=Math.round(Math.random()*(alphaarray.length-1));
   if(i%col==0) stringgrille+="<tr>";
   stringgrille+="<td>";
   if(alphaarray[val]==this.emptyCell){
    stringgrille+=('<span class="empty">'+alphaarray[val]+"</td>");
   }else{
    stringgrille+=('<span class="full" onclick="TZR.KeyPad.addDigit(\''+alphaarray[val]+'\');"">'+alphaarray[val]+"</span></td>");
   }
   if((i+1)%col==0) stringgrille+="</tr>";
   alphaarray.splice(val,1);
  }
  stringgrille+='<tr><td colspan="'+col+'"><span class="reset" onclick="TZR.KeyPad.reset()">Reset</span></td></tr>';
  stringgrille+="</table>";
  return stringgrille;
 }
};

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";
    }
  }
}

// Redimenssionement des onglets
function resizeTabs(){
  var tablist=document.getElementById('tzr-tablist');
  if(document.getElementById('tzr-tablist')){
    var l=tablist.childNodes.length;
    var cont=document.getElementById('tzr-tabcontentcontainer');
    for(i=0;i<l;i++){
      if(tablist.childNodes[i].firstChild){
	tablist.childNodes[i].firstChild.style.paddingBottom=(Position.cumulativeOffset(cont)[1]-Position.cumulativeOffset(tablist.childNodes[i])[1]-7)+"px";
      }
    } 
  }
}

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

window.onload=onLoadComplete;

////////Stop editting////////////////
TZRTABS = new Object();
TZRTABS.initialtab=[1, "sc1"]

function _cascadedstyle(el, cssproperty, csspropertyNS){
if (el.currentStyle)
return el.currentStyle[cssproperty]
else if (window.getComputedStyle){
var elstyle=window.getComputedStyle(el, "")
return elstyle.getPropertyValue(csspropertyNS)
}
}
TZRTABS.enablepersistence=true;
TZRTABS.previoustab="";
TZRTABS.initTabColor="";
TZRTABS.initTabpostcolor="";
TZRTABS.optimalWidth = "";
TZRTABS.expandcontent = function (cid,aobject) {
  /* rr IE => save du general, qui est ok */
  if (TZRTABS.previoustab == "sc1" && TZRTABS.optimalWidth == ""){
    TZRTABS.optimalWidth = document.getElementById('tzr-tabcontentcontainer').offsetWidth;
  }/* fin */

  if (document.getElementById){
    TZRTABS.highlighttab(aobject)
    TZRTABS.detectSourceindex(aobject)
    if (TZRTABS.previoustab!="")
    document.getElementById(TZRTABS.previoustab).style.display="none"
    document.getElementById(cid).style.display="block"
    /* rr IE => force width */
    if (TZRTABS.optimalWidth && TZRTABS.optimalWidth != ""){
      document.getElementById(cid).style.width=TZRTABS.optimalWidth;
    }/* fin */
    
    TZRTABS.previoustab=cid
    if (aobject.blur){
      aobject.blur()
    }
    if (TZRTABS.enablepersistence){
      TZRTABS.setCookieTab(cid);
    }
    return false
  } else {
    return true;
  }
}
TZRTABS.collecttablinks = function (){
var tabobj=document.getElementById("tzr-tablist")
if (tabobj)
tabobjlinks=tabobj.getElementsByTagName("A")
else
tabobjlinks = new Array()
}

TZRTABS.highlighttab = function (aobject) {
if (typeof tabobjlinks=="undefined")
TZRTABS.collecttablinks()
for (i=0; i<tabobjlinks.length; i++){
tabobjlinks[i].style.backgroundColor=TZRTABS.initTabColor
//tabobjlinks[i].style.backgroundColor='red';
}
var themecolor=aobject.getAttribute("theme")? aobject.getAttribute("theme") : TZRTABS.initTabpostcolor
//aobject.style.backgroundColor=document.getElementById("tzr-tabcontentcontainer").style.backgroundColor=themecolor
aobject.style.backgroundColor=themecolor
}

TZRTABS.detectSourceindex = function (aobject) {
for (i=0; i<tabobjlinks.length; i++){
if (aobject==tabobjlinks[i]){
tabsourceindex=i //source index of tab bar relative to other tabs
break
}
}
}
TZRTABS.init = function (){
  var cookiename=TZRTABS.cookieName();
  TZRTABS.collecttablinks()
  if (tabobjlinks.length > 0){// some page do not have tab
    TZRTABS.initTabpostcolor=_cascadedstyle(tabobjlinks[0], "backgroundColor", "background-color")
    if(tabobjlinks[1]) {
      TZRTABS.initTabColor=_cascadedstyle(tabobjlinks[1], "backgroundColor", "background-color")
    } else {
      TZRTABS.initTabColor=TZRTABS.initTabpostcolor;
    }
    var tabcontentid=TZRTABS.getCookieTab(cookiename);
    if (typeof TZRTABS.enablepersistence!="undefined" && TZRTABS.enablepersistence && tabcontentid != ''){
      var tab = document.getElementById('tab'+tabcontentid);
      if (tab != null){
	TZRTABS.expandcontent(tabcontentid, tab);
      }else {
	TZRTABS.expandcontent(TZRTABS.initialtab[1], tabobjlinks[TZRTABS.initialtab[0]-1]);
      }
    }else{
      TZRTABS.expandcontent(TZRTABS.initialtab[1], tabobjlinks[TZRTABS.initialtab[0]-1]);
    }
  }
}

if (window.addEventListener)
window.addEventListener("load", TZRTABS.init, false)
else if (window.attachEvent)
window.attachEvent("onload", TZRTABS.init)
else if (document.getElementById)
window.onload=TZRTABS.init;
     
TZRTABS.cookieName = function(){
return  'tzrtab'+TZRTABS.moid;
}
TZRTABS.setCookieTab = function(cid){
  if (typeof TZRTABS.moid != 'undefined' && TZRTABS.moid != ''){
    document.cookie = TZRTABS.cookieName() + '=' + cid; //+';expires='+fin;
  }
}
TZRTABS.getCookieTab = function(){
  var cookie_name = TZRTABS.cookieName();
  var results = document.cookie.match ( cookie_name + '=(.*?)(;|$)' );
  if ( results )
    return ( unescape ( results[1] ) );
  else
    return '';
}
TZRTABS.resetCookieTab = function(moid){
  var cookie_date = new Date ( );  // current date & time
  cookie_date.setTime ( cookie_date.getTime() - 1 );
  document.cookie = 'tzrtab' + moid + "=; expires=" + cookie_date.toGMTString();
}
TZRTABS.ajaxPopulate = function(cid,url){
  ret=TZR.file_get_contents(url);
  Element.update(document.getElementById(cid),ret);
}

var datatable_search_timeout = new Array();

function createRowsArray (table) {
  var rows = new Array();
  var r = 0;
  if (table.tHead == null && table.tFoot == null)
    for (var r1 = 0; r1 < table.rows.length; r1++, r++)
      rows[r] = table.rows[r1];
  else  
    for (var t = 0; t < table.tBodies.length; t++)
      for (var r1 = 0; r1 < table.tBodies[t].rows.length; r1++, r++)
        rows[r] = table.tBodies[t].rows[r1];
  return rows;
}

function visibleRows( rows )
{
  var n = 0;
  var vrows = new Array( );
  for( var i in rows )
  {
    if( rows[i].style.display != 'none' )
      vrows[vrows.length] = rows[i];
  }
  return vrows;
}

function insertSortedRows(table, rows) 
{
  var cycle = parseInt( table.getAttribute('pp_cycle') );

  if (document.all) var rowsCopy = new Array(rows.length)
  for (var r = 0; r < rows.length; r++) {
    if (document.all) rowsCopy[r] = rows[r].cloneNode(true);
    table.deleteRow(rows[r].rowIndex);
  }

  if( document.all )
    rowsCopy = tableSearch( table, rowsCopy );
  else
    rows = tableSearch( table, rows );

  var tableSection = table.tBodies[table.tBodies.length - 1];
  for (var r = 0; r < rows.length; r++)
  {
    var row = document.all ? rowsCopy[r] : rows[r];
    if( cycle )
      row.className = (r % 2 != 0 ? 'h' : 'n')
    tableSection.appendChild(row);
  }
}

function tableSearch( table, rows )
{
  var srch = document.getElementsByName( 'txt_'+table.id );
  if( srch && srch.length && srch[0].value.length )
  {
    var processed=0;
    srch = srch[0].value.toLowerCase();
    for( var i=0; i<rows.length; i++ )
    {
      var is_in = 0;
      for( j=0; j<rows[i].childNodes.length; j++ )
      {
        if( !rows[i].childNodes[j].firstChild )
          continue;
        val = rows[i].childNodes[j].firstChild.nodeValue;
//        is_in |= ( val.toLowerCase().search( srch ) != -1 );
        is_in |= ( val.toLowerCase().indexOf( srch ) != -1 );
        processed++;
      }
      if( !is_in )
        rows[i].style.display = 'none';
      else
        rows[i].style.display = '';
    }
//    alert( processed);
  }
  else
  {
    for( var i=0; i<rows.length; i++ )
    {
        rows[i].style.display = '';
    }
  }
  return rows;
}


function sortRowsAlpha (row1 , row2) {
  var column = sortRowsAlpha.col;
  var cell1 = row1.cells[column].firstChild.nodeValue;
  var cell2 = row2.cells[column].firstChild.nodeValue;
  return cell1 < cell2 ? - 1 : (cell1 == cell2 ? 0 : 1);
}
function sortRowsNumber (row1 , row2) {
  var column = sortRowsNumber.col;
  var cell1 = parseFloat(row1.cells[column].firstChild.nodeValue);
  var cell2 = parseFloat(row2.cells[column].firstChild.nodeValue);
  return cell1 < cell2 ? - 1 : (cell1 == cell2 ? 0 : 1);
}
function findFirstLinkChild (el) {
  var child = el.firstChild;
  while (child.tagName != 'A')
    child = child.nextSibling;
  return child;
}
function testSortTableAlpha(table, col) {
  sortRowsAlpha.col = col;
  sortTable(table, sortRowsAlpha);
  table.setAttribute( 'last_sortCol', col );
  table.setAttribute( 'last_sortFun', 'Alpha' );
}
function testSortTableNumerical (table, col) {
  sortRowsNumber.col = col;
  sortTable(table, sortRowsNumber);
  table.setAttribute( 'last_sortCol', col );
  table.setAttribute( 'last_sortFun', 'Numerical' );
}

function sortTable (table, sortFun) 
{
  var rows = createRowsArray(table);
  if (rows.length > 0) 
  {
    rows.sort(sortFun);
    insertSortedRows(table, rows);
  }
}

function do_searchTable( table_id )
{
  var table = document.getElementById( table_id );
  var sortCol = parseInt( table.getAttribute('last_sortCol') );
  var sortFun = table.getAttribute('last_sortFun');
  if( sortFun == 'Numerical' )
    testSortTableNumerical( table, sortCol );
  else if( sortFun == 'Alpha' )
    testSortTableAlpha( table, sortCol );
  else if( sortFun == '' )
  {
    var rows = createRowsArray( table );
    insertSortedRows( table, rows );
  }
}

function searchTable( table_id, event )
{
  if( event && event.keyCode == 13 )
  {
    var vrows;
    var table = document.getElementById( table_id );
    do_searchTable( table_id );
    vrows = visibleRows( createRowsArray(table) );
    if( vrows.length == 1 )
    {
      if( vrows[0].getAttribute('onClick').length )
      {
        eval( vrows[0].getAttribute('onClick') );
        return false;
      }
    }
    return false;
  }
  if( datatable_search_timeout[table_id] )
  {
    window.clearTimeout( datatable_search_timeout[table_id] );
    datatable_search_timeout[table_id] = undefined;
  }
  datatable_search_timeout[table_id] = window.setTimeout( 'do_searchTable("'+table_id+'")', 500 );
  return true;
}

function row_hl( table, row )
{
  if( row.className.match(/sel/) )
    return;
  row.className = row.getAttribute('dflt_class') + '_hl';
}

function row_ll( table, row )
{
  if( row.className.match(/sel/) )
    return;
  row.className = row.getAttribute('dflt_class');
}

function row_sel( table, row )
{
  var selectable = parseInt( table.getAttribute('pp_selectable') );
  if( !selectable )
    return;
  else if( selectable == 2 )
  {
    if( row.className.match(/sel/) )
      row.className = row.getAttribute('dflt_class');
    else
      row.className = row.getAttribute('dflt_class') + '_sel';
  }
  else
  {
    for (var t = 0; t < table.tBodies.length; t++)
      for (var r1 = 0; r1 < table.tBodies[t].rows.length; r1++)
        table.tBodies[t].rows[r1].className = table.tBodies[t].rows[r1].getAttribute('dflt_class');

    row.className = row.getAttribute('dflt_class') + '_sel';
  }
}

function datatable_get_selected( table )
{
  var sel = new Array();
  var r=0;
  for (var t = 0; t < table.tBodies.length; t++)
    for (var r1 = 0; r1 < table.tBodies[t].rows.length; r1++, r++)
    {
      if( table.tBodies[t].rows[r1].className.match(/sel/) )
        sel[sel.length] = r;
    }
  return sel;
}
