
var winImgView;

function blink(id, time) {
  var obj = elem(id);
  time = time || 300;
  obj.style.visibility = (obj.style.visibility=='hidden')? 'visible' : 'hidden';
  obj.timeout = window.setTimeout("blink('"+id+"',"+time+")", time);
  obj.noblink = false;
  obj.setAttribute('onmouseover', "window.clearTimeout("+elem(id).timeout+")");
  obj.setAttribute('onclick', "this.noblink=true;");
  obj.setAttribute('onmouseout', "if (!this.noblink) blink('"+id+"',"+time+")");
}

function pause(milliseconds) {
  var date = new Date();
  var curDate = null;
  do { curDate = new Date(); }
  while(curDate-date < milliseconds);
}

function imagePreview(url, guid) {
  var left = (screen.availWidth>700+480)? 700 : screen.availWidth-480;
  var top = 100;
  if (!guid) guid = '';
  if (!url) url = '';
  url += (guid.match(/[:\/\\\.]/i))? 'zoom.php?url='+guid+'&size=zoom' : 'zoom.php?guid='+guid+'&size=zoom';
  var features = 'left='+left+',top='+top+',width=480,height=360,scrollbars=1,location=0,resizable=1,modal=1';
  winImgView = window.open(url, 'viewimage', features).focus();
}

function imagePreview_old(url, guid, size, mode) {
	if (!mode) mode = '';
  //var left = screen.availWidth - 480;
  var left = 650;
  var top = 100;
	if (ie) {
	  if (url) {
	    var s  = '<html><title>image</title>'
	        s += '<body leftmargin=0 topmargin=0 scroll=auto>'
	        s += '<img src="'+url+'" onload="window.opener.resizeImageWindow(window, this.width, this.height)">'
	        s += '</body></html>'
	  }
	  if (guid!=null) {
	    var s  = '<html><title>image</title>';
	        s += '<body leftmargin="0" topmargin="0" bgcolor="#ffffff" scroll="auto" ';
          s += ' onclick="self.close()" style="cursor:hand; cursor:pointer"><center>';
	        s += '<div><img src="view.php?type=image&guid='+guid+'&mode='+mode+'&size=original" ';
          s += ' onload="window.opener.resizeImageWindow(window, this.width, this.height)"></div>';
	        s += '</center></body></html>';
	  }
	  winImgView = window.open('','viewimage','left='+left+',top='+top+',width=480,height=360,scrollbars=1,location=0,resizable=1,modal=1');
	  var o = winImgView.document.open("text/html", "replace");
	  o.write(s);
	} else {
	  if (url!=null) imgurl = url;
	  if (guid!=null) var imgurl = 'view.php?type=image&guid='+guid+'&mode='+mode+'&size=original'
		winImgView = window.open(imgurl,'viewimage','left='+left+',top='+top+',width=480,height=360,scrollbars=1,location=0,resizable=1,modal=1');
	}
}

function resizeImageWindow(win, w, h) {
  var maxW = screen.availWidth * 0.75;
  var maxH = screen.availHeight * 0.75;
  if (w>maxW) w = maxW
  if (h>maxH) h = maxH
  win.resizeTo(w+64, h+64)
  //win.moveTo(screen.availWidth - (w+164), 100)
  win.focus()
}

function getPos(obj) {
  var pos = new Array(0,0);
  while(obj.offsetParent) {
    pos[0] += obj.offsetLeft;
    pos[1] += obj.offsetTop;
    obj = obj.offsetParent;
  }
  pos[3] = obj.offsetWidth;
  pos[4] = obj.offsetHeight;
  return pos;
}

function elem(id) { return document.getElementById(id); }

function gotoAnchor(anchor) {
	self.location = '#'+anchor;
}


/*** Show Hide Objects ***/
function showObject(id, hideSelf, focusObj, disp) {
  var obj = (typeof(id)=='object')? id : elem(id);
  if (!obj) return;
  var cls = obj.className;
  if (cls=='invisible' || cls=='visible' || cls=='hidden' || cls=='shown') {
    if (cls=='invisible') { obj.className = 'visible'; if (hideSelf=='single' && window.curObject) hideObject(window.curObject); }
    if (cls=='hidden') { obj.className = 'shown'; if (hideSelf=='single' && window.curObject) hideObject(window.curObject); }
  } else {
    if (hideSelf && typeof(hideSelf)=='string' && hideSelf!='single') { var disp = hideSelf; hideSelf = null; } else var disp = '';
    if (obj.style.display=='none') obj.style.display=disp; else obj.style.display='none';
  }
  if (hideSelf) try {
    if (hideSelf=='single') {
      window.curObject = obj;
    } else {
      var src = (typeof(hideSelf)=='object')? hideSelf : event.srcElement;
      src.style.display = 'none';
    }
  } catch(e) { }
  if (focusObj) try {
    var o = (typeof(focusObj)=='object')? focusObj : thisForm(obj).elements[focusObj];
    if (o) o.focus();
  } catch(e) { }
}
function hideObject(id, showSelf, disp) {
  var obj = (typeof(id)=='object')? id : elem(id);
  if (!obj) return;
  var cls = obj.className;
  if (cls=='invisible' || cls=='visible' || cls=='hidden' || cls=='shown') {
    if (obj.className=='visible') obj.className = 'invisible';
    if (obj.className=='shown') obj.className = 'hidden';
  } else {
    if (showSelf && typeof(showSelf)=='string') { var disp = showSelf; showSelf = null; } else var disp = '';
    if (obj.style.display=='none') obj.style.display=disp; else obj.style.display='none';
  }
  if (showSelf) try {
    var src = (typeof(showSelf)=='object')? showSelf : event.srcElement;
    src.style.display = '';
  } catch(e) { }
}
function showHideObject(id) {
  var obj = (typeof(id)=='object')? id : elem(id);
  if (!obj) return;
  if (!obj.className) obj.className = 'visible';
  try {
    var cmd = event.srcElement;
    if (cmd.innerText=='[+]' || cmd.innerText=='[-]') {
      if (obj.className=='invisible' || obj.className=='hidden') cmd.innerText = '[-]';
      if (obj.className=='visible' || obj.className=='shown') cmd.innerText = '[+]';
    }
  } catch(e) {}
  if (obj.className=='invisible') { obj.className = 'visible'; return }
  if (obj.className=='hidden') { obj.className = 'shown'; return }
  if (obj.className=='visible') { obj.className = 'invisible'; return }
  if (obj.className=='shown') { obj.className = 'hidden'; return }
}
/*****/


function editbar(id, mode) {
  var obj = (typeof(id)=='object')? id : elem(id);if (!o) return;
  if (mode=='over' || mode=='on' || mode=='show') {
    o.style.display = '';
  }
  if (mode=='out' || mode=='off' || mode=='hide') {
    o.style.display = 'none';
  }
}

function editunit(id, mode, classname, limit) {
  //if (window.editbusy) return;
  if (!classname) classname = 'edit-unit';
  var obj = document.getElementById(id); if (!obj) return;
  var o = (event.srcElement);

  /* OVER */
  if (mode=='over' || mode=='on' || mode=='show') {
    if (obj.contains(event.srcElement) || obj==event.srcElement) return;
    var margin = parseInt(obj.getAttribute('margin'),10); if (margin==null || isNaN(margin)) margin = -40;
    if (ie) {
      var pageY = document.body.scrollTop + event.y;
      var pageX = document.body.scrollLeft + event.x;
    }
    if (moz) {
      var pageY = event.pageY;
      var pageX = event.pageX;
    }
    if (margin!=-9999) obj.style.top = (pageY + margin)+'px';
    obj.style.zIndex = 5;

    event.cancelBubble = true;
    try { document.body.click(); } catch(e) {}
    document.body.onclick = function() { editunit(id, 'off', classname, limit); }

    if (obj.style.display!='block') obj.style.display = 'block';
    if (!limit) limit = 0;
    if ( limit && pageX < limit && (pageX-obj.offsetWidth)>0 ) {
      var x = (5-obj.offsetWidth)+'px';
      if (obj.style.marginLeft!=x) {
        obj.oldMarginLeft = obj.style.marginLeft;
        obj.style.marginLeft = x;
      }
    } else {
      try { obj.style.marginLeft = obj.oldMarginLeft; } catch(e) {}
    }
  }
  /* OUT */
  if (mode=='out' || mode=='off' || mode=='hide') {
    if (obj.contains(event.toElement) || obj==event.toElement) return;
    obj.style.display = 'none';
  }
}

function editpage(id, mode, classname) {
  if (!classname) classname = 'edit-page';
  var table = document.getElementById('table'+id);

  /* OVER */
  if (mode=='over' || mode=='on' || mode=='show') {
    if (moz) {
      if (window.mouseover) return;
      window.mouseover = event.srcElement;
    }
    window.editbusy = true;
    if (table) table.style.display = 'block';
    event.cancelBubble = true;
    document.body.onclick = function() { editpage(id, 'off', classname); }

    if (ie) {
      table.style.visibility = 'hidden';
      table.style.filter = 'progid:DXImageTransform.Microsoft.Fade(duration=0.25,overlap=0)';
      //table.style.filter += " progid:DXImageTransform.Microsoft.Shadow(color='#666666', Direction=135, Strength=5)";
      table.filters[0].Apply();
      table.style.visibility = 'visible';
      table.filters[0].Play();
    }
    table.style.zIndex = 10;

  }
  /* OUT */
  if (mode=='out' || mode=='off' || mode=='hide') {
    if (moz) {
      var o = window.mouseover;
      if (o.contains(event.toElement)) return;
      window.mouseover = null;
    }
    window.editbusy = false;
    if (moz) table.style.display = 'none';
    if (ie) {
      //clipIt(id, 100);
      table.style.filter = 'progid:DXImageTransform.Microsoft.Fade(duration=0.5,overlap=0)';
      table.filters[0].Apply();
      table.style.visibility = 'hidden';
      table.filters[0].Play();
      table.style.filter = '';
      window.setTimeout("document.getElementById('table"+id+"').style.display='none'", 500);
      document.body.onclick = function() {}
    }
  }
}

function clipIt(id, percent) {
  var obj = document.getElementById('table'+id);
  var w = obj.offsetWidth * (1-percent/100);
  var h = obj.offsetHeight * percent/100;
  obj.style.clip = 'rect(0px, '+obj.offsetWidth+'px, '+h+'px, '+w+'px)';
  if (percent>0) { window.setTimeout("clipIt('"+id+"', "+(percent-5)+")", 10); return }
  var bar = document.getElementById('bar'+id);
  bar.style.display = 'none';
  obj.style.clip = 'rect(auto)';
  document.body.onclick = function() {}
}

function highlight(obj, mode, classname) {
  if (!classname) classname = 'highlight';
  if (!obj) return;

  if (mode=='over' || mode=='on' || mode=='show') {
    obj.oldclass = obj.className; if (obj.className) obj.className += ' ';
    obj.className += classname;
    debug.value += obj.className;
  }
  if (mode=='out' || mode=='off' || mode=='hide') {
    obj.className = obj.oldclass;
  }
}

function setCookie (name, value, expires, path, domain, secure) {
  szCookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
  document.cookie = szCookie;
}

function getCookie (name) {
  if ( document.cookie) { // Le cookie est-il valide ?
    index = document.cookie.indexOf( name);
    if ( index != -1) {
      nDeb = (document.cookie.indexOf( "=", index) + 1);
      nFin = document.cookie.indexOf( ";", index);
      if (nFin == -1) {nFin = document.cookie.length;}
      return unescape(document.cookie.substring(nDeb, nFin));
    }
  }
  return null;
}

/*****************************************/
function rnd(a,b) {
	return a + Math.floor(Math.random()*(b-a+1));
}
function rotorLetterOver(id, interval) {
  var obj = document.getElementById(id); if (!obj) return;
  if (event.srcElement!=obj) return;
  rotorLetter(id, interval);
}
function rotorLetter(id, interval, range) {
  if (!interval) interval = 50;
  if (!range) range = 30;
  var obj = document.getElementById(id); if (!obj) return;

  if (obj.oldtext==null) {
    var text = obj.innerText+'';
    var arr0 = new Array();
    var arr1 = new Array();
    for(var i=0; i<text.length; i++) {
      var code = text.charCodeAt(i);
      arr0.push(code);
      arr1.push(code-rnd(0,range));
    }
    obj.oldtext = arr0;
    obj.newtext = arr1;

  } else {
    var arr0 = obj.oldtext;
    var arr1 = obj.newtext;
    var str = '';
    var changed = false;
    for(var i=0; i<arr0.length; i++) {
      if (arr1[i]!=arr0[i]) {
        arr1[i]++;
        changed = true;
        var char = String.fromCharCode(arr1[i]);
        if (arr1[i]<33) char = '*';
        if (arr1[i]>125 && arr1[i]<161) char = '*';
        //char = '*';
      } else {
        var char = String.fromCharCode(arr1[i]);
      }
      str += char;
    }
    obj.innerText = str;
    if (!changed) { obj.oldtext = null; obj.timer = 0; return; }

  }

  obj.timer = window.setTimeout("rotorLetter('"+id+"', "+interval+")", interval);
}


/***** Edition IFrame *****/
function openDIV(id, url, params) {
  // id : identifiant de l'IFrame d'édition
  // name : nom de la fenêtre d'édition "edit_{name}.php"
  // args : arguments supplémentaires passés à l'url de la page d'édition
  if (!params) params = new Array(); // params : paramètres de la fenêtre d'édition, les deux premiers sont largeur et hauteur de la fenêtre
  var obj = elem(id); if (!obj) { alert("Error: Object '"+id+"' does not exist"); return; }
  obj.style.display = '';
  obj.style.height = params[1] || '2.5em';
  obj.style.zIndex = 10;
  if (params[0]) obj.style.width = params[0];
  // Fermeture de la précédente fenêtre d'édition
  if (window.curIFrame && window.curIFrame!=obj) closeEdit(window.curIFrame);
  window.curIFrame = obj;
  // Affichage du message d'attente
  if (ie || moz || opera) obj.contentWindow.document.write(getHTMLWaitMessage(3));
  // Chargement du formulaire
  obj.src = url;
}
function openEdit(id, name, args, item) {
  // id : identifiant de l'IFrame d'édition
  // name : nom de la fenêtre d'édition "edit_{name}.php"
  // args : arguments supplémentaires passés à l'url de la page d'édition
  // item : ojet au niveau duquel il faut positionner la fenêtre (en x et y)
  var d = new Date();
  var obj = elem(id); if (!obj) { alert("Error: Object '"+id+"' does not exist"); return; }
  obj.style.display = '';
  obj.style.height = '5em';
  obj.style.zIndex = 10;
  obj.style.top = '';
  if (item) {
    if (typeof(item)=='string') item = elem(item);
    pos = getPos(item); obj.style.top = pos[1]+'px'; 
  }
  if (args==null) args = '';
  // Fermeture de la précédente fenêtre d'édition
  if (window.curIFrame && window.curIFrame!=obj) closeEdit(window.curIFrame);
  window.curIFrame = obj;
  // Affichage du message d'attente
  if (ie || moz || opera) obj.contentWindow.document.write(getHTMLWaitMessage(3));
  // Chargement du formulaire
  obj.src = 'templates/edit/index.php?name='+name+'&'+args+'&var='+Date.parse(new Date());
  //if (dialogs) dialogs.push(obj);
}
function closeEdit(obj, behavior, unit) {
  obj.style.display = 'none';
  obj.src = '';
  try {
    if (obj.oldwidth!==null) { obj.style.width = obj.oldwidth; obj.oldwidth = null; }
  } catch(e) {}
  if (!behavior) return;
  switch(behavior) {
    case 'reload' : window.setTimeout("window.location.reload(true)", 100); break;
    case 'goto' : window.setTimeout("window.location = '?unit="+unit+"'", 100); break;
    default: window.setTimeout("window.location.reload(true)", 100);
  }
}
function responseEdit(behavior, unit) { //cette fonction doit être rendue obsolète (voir closeEdit)
  switch(behavior) {
    case 'reload' : window.setTimeout("window.location.reload(true)", 100); break;
    case 'goto' : window.setTimeout("window.location = '?unit="+unit+"'", 100); break;
    default: window.setTimeout("window.location.reload(true)", 100);
  }
}
function getHTMLWaitMessage(cmd) {
  var html = '';
  if ((cmd&1)==1) html += '<BODY bgcolor="#ffffff" scroll="no" style="margin:5px; font-family:verdana; color:#000000">';
  html += '<table border="0" width="100%"><tr><td style="font-size:12px; font-weight:bold">';
  html += labels['loading-please-wait']+'</td><td width="1%">';
  if ((cmd&2)==2) {
    html += '<a href="javascript:parent.closeEditIFrame(window.frameElement)" style="font-size:11px; color:#666666">';
    html += '<img src="media/images/icons/edit_close.png" border="0">';
    html += '</a>';
  }
  html += '</td></tr></table>';
  if ((cmd&1)==1) html += '</BODY>';
  return html;
}
/*****/

/*** Search In LIst ***/
// Recherche un texte dans la liste des fils d'un noeud; rend invisibles
// les fils où il n'est pas trouvé et visibles ceux ou il l'est
function showSearchField(id) {
  var o = elem('tool_'+id+'_search'); if (!o) return;
  if (o.style.display=='none') {
    o.style.display = '';
    elem('tool_'+id+'_search_field').focus();
    if (dialogs) dialogs.push(o); // on ferme automatiquement lorsqu'on clique sur le BODY
  } else {
    o.style.display = 'none';
  }
}
function searchInList(listid, text, counterid) { //listid: id du noeud 'liste'; counter
  var list = elem(listid); if (!list) return;
  var text = text.replace(/\'/i, "\\'");
  if (list.timeout) window.clearTimeout(list.timeout);
  list.timeout = window.setTimeout("searchInList_timed('"+listid+"', '"+text+"', '"+counterid+"')", 200);
}
function searchInList_timed(listid, text, counterid) {
  var list = elem(listid); if (!list) return;
  var items = list.children;
  var c = 0;
  for (var i=0; i<items.length; i++) {
    var o = items[i];
    var innerText = (o.innerText)? o.innerText : o.innerHTML;
    var r = (!text)? 0 : innerText.toLowerCase().indexOf(text.toLowerCase());
    //if (!o.oldDisplay) o.oldDisplay = o.style.display;
    //o.style.display = (r>=0)? o.oldDisplay : 'none';
    o.style.display = (r>-1)? '' : 'none';
    if (r>=0) c++;
  }
  if (counterid) {
    var o = elem(counterid); if (o) o.innerText = c;
    o = elem(counterid+'up'); if (o) o.innerText = c;
    o = elem(counterid+'dn'); if (o) o.innerText = c;
  }
  list.timeout = null;
}
/*****/


/*** DIV Ajax **/
function showDIV(box, unit, layout, classname, autoclose, div, params, tpl) {
  var o = elem(box);
  if (o.style.display!='none') { o.style.display = 'none'; return }
  o.style.display = '';
  var obj = elem(box+'_body');

  if (!classname) classname = 'box';
  if (!layout) layout = '';
  if (!div) div = ''; // id du div

  if (unit.length>38) { obj.src = unit; unit = null; }
  if (!obj.src) obj.src = obj.getAttribute('src');
  if (!tpl) tpl = '_unit';
  if (!obj.src) obj.src = "?unit="+unit+"&tpl="+tpl+"&layout="+layout+"&class="+classname+'&box='+box+'&div='+div;
  if (div) obj.src = obj.src.replace(/&div=[^\&]+/i,'')+'&div='+div;
  if (box) obj.src = obj.src.replace(/&box=[^\&]+/i,'')+'&box='+box;
  if (unit) obj.src = obj.src.replace(/&unit=[^\&]+/i,'')+'&unit='+unit;
  if (layout) obj.src = obj.src.replace(/&layout=[^\&]+/i,'')+'&layout='+layout;
  if (classname) obj.src = obj.src.replace(/&class=[^\&]+/i,'')+'&class='+classname;
  if (params) obj.src = obj.src.replace(/&params=[^\&]+/i,'')+'&params='+params;
  obj.src = obj.src.replace(/&context=[^\&]+/i,'')+'&context='+window.guid.replace(/[\{\-\}]/ig,'');

  obj.innerHTML = '<div class="content"><img src="media/images/wait.gif" align="absmiddle"> '+labels['loading-please-wait']+'</div>';
  window.tempObject = obj;
  window.setTimeout("showDIV2('"+obj.src+"')", 100);
  if (autoclose && dialogs) dialogs.push(o);
}
function showDIV2(src) {
  var obj = send(src);
  var html = obj.responseText
  window.tempObject.innerHTML = html;
}

function loadDIV(id, url, sync) {
  var obj = elem(id+'_body');
  if (!obj) obj = elem(id);
  obj.oldHTML = obj.outerHTML;
  if (url && url.indexOf('?')>-1) obj.src = url;
  if (!obj.src) obj.src = obj.getAttribute('src');
  if (url && url.indexOf('?')==-1) { // Si l'url passée ne contient pas de '?', il faut surcharger les paramètres de l'url de base (obj.src)
    var arr = url.split('&');
    for(i in arr) {
      var reg = new RegExp('&'+arr[i]+'=[^\&]+','ig');
      var ar = arr[i].split('=');
      obj.src = obj.src.replace(reg,'')+'&'+ar[0]+'='+ar[1];;
    }
  }
  if (!obj.src) { alert("error: src is undefined in object '"+id+"'"); return; }
  //obj.src = obj.src.replace(/id=[^&]&/i, '')+'&id='+id.replace(/^div_/i,'');
  if (wait = elem(id+'_wait')) {
    wait.style.display = '';
  } else {
    obj.innerHTML = '<DIV class="rblock-body"><img src="media/images/wait.gif" align="absmiddle"> '+labels['loading-please-wait']+'</DIV>';
  }
  if (main = elem(id+'_main')) main.style.display = 'none';

  if (sync) {
    loadDIV2(obj);
  } else {
    window.tempObject = obj;
    window.setTimeout("loadDIV2(window.tempObject)", 100);
  }
}
function loadDIV2(obj) {
  var id = obj.id;
  var src = obj.src;
  var o = send(src);
  var html = o.responseText;
  if (obj.id.match(/_body$/i)) {
    obj.innerHTML = html;
  } else {
    //if (!html) alert("[%msg-error-menu-is-empty("+obj.src+")%]");
    //obj.outerHTML = html || obj.oldHTML;
    if (html=='') html = '<'+obj.tagName+' id="'+obj.id+'"></'+obj.tagName+'>';
    obj.outerHTML = html;
  }
  try { elem(id).src = src; } catch(e) {} // on change le src du div
}
function closeDIV(id) {
  var o = elem(id);
  o.style.display = 'none';
}
function refreshDIV(id, url) { loadDIV(id, url); }
function reloadDIV(id, url) { loadDIV(id, url); }
function loadDiv(id, url) { loadDIV(id, url); }
function openDialog(url) {
  var features = 'left=200,top=100,width=800,height=600,scrollbars=1,location=0,status=1,resizable=1';
  var win = window.open(url, '', features);
  win.focus();
}
/*****/


/*** Ajax Lists ***/
function load_iframe(id, frame, nodialog) {
  var o = elem(id); if (!o) { alert("error: element "+id+" does not exist"); return; }
  if (!frame.contentWindow.document.body.innerHTML) return;
  var obj = frame.contentWindow.document.getElementById('content');
  //if (!obj) { alert("error: result does not contain 'content' element"); return; }
  var html = obj.value;
  if (!html) return;
  o.outerHTML = html;
  o.style.display = '';
  if (!nodialog) dialogs.push(o); //indique qu'on affiche une partie de page et pas un dialog
}
function hide_dialogs() {
  for (i in dialogs) {
    var o = dialogs[i];
    if (o.contains(event.srcElement)) continue;
    o.style.display = 'none';
    dialogs.pop(o);
  }
}
function ready_state(id, obj) {
  var o = elem(id);
  if (obj.readyState=='loading') {
    o.innerHTML = elem('html-dialog').innerHTML;
    o.style.display = '';
  }
}
function loadMenu(id, href) {
  if (id.toLowerCase()=='_blank') { var o = window.open(href); return; }
  var o = elem(id); if (!o) return;
  o.src = href;
}
/*****/

/*** Ajax ***/
function ajaxLoadHTML(id, params) { // Charge une page avec les paramètres params
  var content = elem(id); if (!content) return;
  var obj = send(php_self, 'tpl=ajax&'+params, '', 'GET');
  content.style.display = '';
  content.innerHTML = obj.responseText;
}
function ajaxLoadURL(id, url) { // Charge une url (externe)
  var frame = elem(id); if (!frame) return;
  var obj = send(url, '', '', 'GET');
  //var o = document.createElement('DIV');
  frame.innerHTML = obj.responseText;
  //frame.innerHTML = o.innerHTML;
  frame.style.display = '';
}
function send(address, request, ctype, method) {
	var obj = getHTTPObject();
	if (!method) method = 'POST';
	if (!ctype) ctype = 'application/x-www-form-urlencoded';
	obj.open(method, address, false);
  obj.setRequestHeader("Content-Type", ctype);
  request = (request)? request : '';
  obj.send(request);
  var r = obj.responseText;
  if (r.substring(0,5)=='error') { alert(r); }
  return obj;
}
function send_sync(address, request, ctype) {
  return send(address, request, ctype);
}
function send_async(address, request, callBack, ctype, method) {
  var obj = getHTTPObject();
  if (!method) method = 'POST';
  if (!ctype) ctype = 'application/x-www-form-urlencoded';
  obj.open(method, address, true);
  obj.setRequestHeader("Content-Type", ctype);
  if (callBack) obj.onreadystatechange = callBack;
  request = (request)? request : ''
  obj.send(request);
  return obj;
}
function getHTTPObject() {
  var xmlhttp = false;
  /* Compilation conditionnelle d'IE */
  /*@cc_on
  @if (@_jscript_version >= 5)
     try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
		 catch (e) {
        try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
				catch (E) { xmlhttp = false; }
     }
  @else
     xmlhttp = false;
  @end @*/

  /* on essaie de créer l'objet si ce n'est pas déjà fait */
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
     try { xmlhttp = new XMLHttpRequest(); }
     catch (e) { xmlhttp = false; }
  }

	return xmlhttp;
  if (xmlhttp) {
     /* on définit ce qui doit se passer quand la page répondra */
     xmlhttp.onreadystatechange = function()
     {
        if (xmlhttp.readyState == 4) { /* 4 : état "complete" */
           if (xmlhttp.status == 200) { /* 200 : code HTTP pour OK */
              /*
              Traitement de la réponse.
              Ici on affiche la réponse dans une boîte de dialogue.
              */
              alert(xmlhttp.responseText);
           }
        }
     }
  }
  return xmlhttp;
}
/*****/

/*** Page Loaded ***/
function pageLoaded() {
  T2 = new Date(); //Ne pas mettre de var pour garder une variable globale
  send_async('request.php?cmd=log&action=processed&time='+(T2-T1));
  return;
  var text = "";
  text += "Loading of page content : " + (T1-T0) + "ms <br>";
  text += "Initializing page display : " + (T2-T1) + "ms <br>";
  text += "Total : " + (T2-T0) + "ms";
  elem('pageData').innerHTML = text;
}
/*****/

/*** Clpboard ***/
function getClipboard() {
	if ( window.clipboardData && clipboardData.setData )	{
		return clipboardData.getData("Text");

  }	else {
    return clipboardData.getData("Text");

  }
}

function setClipboard(s) {
	if (window.clipboardData && clipboardData.setData)	{
		clipboardData.setData("Text", s);

  }	else {
    /*
		// You have to sign the code to enable this or allow the action in about:config by changing
		user_pref("signed.applets.codebase_principal_support", true);
		netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');

		var clip Components.classes['@mozilla.org/widget/clipboard;[[[[1]]]]'].createInstance(Components.interfaces.nsIClipboard);
		if (!clip) return;

		// create a transferable
		var trans = Components.classes['@mozilla.org/widget/transferable;[[[[1]]]]'].createInstance(Components.interfaces.nsITransferable);
		if (!trans) return;

		// specify the data we wish to handle. Plaintext in this case.
		trans.addDataFlavor('text/unicode');

		// To get the data from the transferable we need two new objects
		var str = new Object();
		var len = new Object();
		var str = Components.classes["@mozilla.org/supports-string;[[[[1]]]]"].createInstance(Components.interfaces.nsISupportsString);
		var copytext=meintext;
		str.data=copytext;
		trans.setTransferData("text/unicode",str,copytext.length*[[[[2]]]]);
		var clipid=Components.interfaces.nsIClipboard;
		if (!clip) return false;

		clip.setData(trans,null,clipid.kGlobalClipboard);
		*/
	}
}
/****/

function getEmails(text, glue) {
  var arr = text.match(/[a-z0-9\-\_\.]+@[a-z0-9\-\_\.]+\.[a-z0-9]+/ig);
  if (!arr) return '';
  if (!glue) glue = ',';
  return arr.join(glue);
}

function submitSearchForm(form, q, params) {
  if (!q) return;
  var form = (typeof(form)=='object')? form : document.forms[form];
  form.elements['q'].value = q;
  var a = new Array();
  var m = params.split(/\&/i);
  // Parse params string
  for (i in m) {
    var n = m[i].split(/\=/i);
    a[n[0]] = n[1];
  }
  // Fill search form
  for (i in a) {
    if (!i) continue;
    if (!a[i]) a[i] = '';
    if (!form.elements[i]) continue;
    form.elements[i].value = a[i];
  }
  form.submit();
}

