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:10px 5px 10px 5px\" 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);
  ajax.setAsync(true);
  if(!resultatCaptcha) {
    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.onCheckCaptchaComplete = function(o){
  resultatCaptcha=o;
}

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

/* 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(o.type=="text"){
    o.ovalue=l;
    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 saisie
function checkFields(f){
  l=f.elements.length;
  for(i=0;i<l;i++){
    if(f.elements[i].type=="text" && 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()", 50);
    }
  },
  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;
    document.forms[this.myField.form.name].elements[this.myField.name].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();
    }
  }
};
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";
    }
  }
}
