function OpenLayer(id){
  $('#'+id).toggle();
}

function OpenLayerMulti(id){
  OpenLayer(id);
  OpenLayer(id+'_abs');
}

function FocusArea(){
  $('#66666_abs').show();
  $('#66666').show();
  $('#bouton-reply-messagerie').hide();
  $('#bouton-send-messagerie2').show();
  $('#66666 form textarea').focus();
}


function getClientSize() {
     var dimensions = {width: 0, height: 0};
     if (document.documentElement) {
         dimensions.width = document.documentElement.offsetWidth;
         dimensions.height = document.documentElement.offsetHeight;
     } else if (window.innerWidth && window.innerHeight) {
         dimensions.width = window.innerWidth;
         dimensions.height = window.innerHeight;
     }
     return dimensions;
}


function reduitareamoderated(id, obj, objc) {
  if (document.getElementById("comment"+id).style.display == "block") {
    document.getElementById("comment"+id).style.display = "none" ;
  }
  obj.checked = 1;
  objc.checked = 0;
  document.getElementById('karma'+id).value = "-10";
}

function modifier(id, obj, objc) {
  obj.checked = 1;
  objc.checked = 1;
  document.getElementById('karma'+id).value = "-10";
  document.getElementById('comment'+id).style.display = "block" ;
}

function reduitareamoderatedcomment(id, obj, objc) {
  if (document.getElementById("comment"+id).style.display == "block") {
    document.getElementById("comment"+id).style.display = "none" ;
  }
  obj.checked = 1;
  objc.checked = 0;
}

function modifiercomment(id, obj, objc) {
  obj.checked = 1;
  objc.checked = 1;
  document.getElementById('comment'+id).style.display = "block" ;
}

function checkkarma(id) {
  if (document.getElementById('checkcomment'+id).checked == true) {
    document.getElementById('karma'+id).value = "-10";
  }
  else {
    if (document.getElementById('modere2'+id).checked == true)
    document.getElementById('karma'+id).value = "1";
  }
}

function file(fichier) {
  var xhr=null;
  // firefox, opera, IE7
  if (window.XMLHttpRequest) {
    xhr = new XMLHttpRequest();
  }
  // IE 6
  else if (window.ActiveXObject) {
    xhr = new ActiveXObject("Microsoft.XMLHTTP");
  }
  xhr.open("GET", fichier, false);
  xhr.send(null);
  if (xhr.readyState == 4) {
    return(xhr.responseText);
  }
  else {
    return(file_error);
  }
}

function style_messag(id) {
  private = document.dec.private.value;
  pid = document.dec.pid.value;
  data = document.dec.data.value;
  entravail = document.dec.entravail.value;
  texte = file("js/ajax/style_messagerie.php?m=message&id=" + id + "&private=" + private + "&pid=" + pid + "&nord=" + data + "&sud=" + entravail);
  document.getElementById(id).innerHTML = texte;id = "message"+id;
  document.getElementById(id).focus();
}

function gotocluster(s) {
  var d = s.options[s.selectedIndex].value
  top.location.href = d
  s.selectedIndex=0
}


function swapstar(thread, couleur) {
  texte = file("js/ajax/swap_star.php?thread=" + thread + "&couleur=" + couleur);
  document.getElementById('star-'+thread).innerHTML = texte;
}

function change_abo_forum(rubrique, abo) {
  if (abo == 1) {
    valid = confirm(forum_unsubscribe);
    if (valid) {
      texte = file("js/ajax/switch_abo_forum.php?rubrique="+rubrique);
      document.getElementById("abo_forum").innerHTML = texte;
    }
  }
  else {
    valid = confirm(forum_subscribe);
    if (valid) {
      texte = file("js/ajax/switch_abo_forum.php?rubrique="+rubrique);
      document.getElementById("abo_forum").innerHTML = texte;
    }
  }
}

function focusInput(elmt){
  elmt.className="focus";
}

function unFocusInput(elmt){
  elmt.className="";
}


function confirm_del_folio() {
  if (confirm(folio_delete)) {
    return(true);
  }
  else {
    return(false);
  }
}

function confirm_reg_folio() {
  if (confirm(folio_regenerate)) {
    return(true);
  }
  else {
    return(false);
  }
}

function change_check(idmsg) {
  if (document.getElementById('modere0'+idmsg).checked == true) {
    document.getElementById('modere1'+idmsg).checked = true;
  }
  else {
    if (document.getElementById('modere1'+idmsg).checked == true) {
      document.getElementById('modere2'+idmsg).checked = true;
    }
    else {
      document.getElementById('modere0'+idmsg).checked = true;
    }
  }
}

function DivStatus( numero ){
  var divID = "descr" + numero;
  var imgID = "expandoGif" + numero;
  if ( document.getElementById && document.getElementById( divID ) ) // Pour les navigateurs récents
    {
      Pdiv = document.getElementById( divID );
      Pimg = document.getElementById( imgID );
      PcH = true;
    }
  else if ( document.all && document.all[ divID ] ) // Pour les veilles versions
    {
      Pdiv = document.all[ divID ];
      Pimg = document.all[ imgID ];
      PcH = true;
    }
  else if ( document.layers && document.layers[ divID ] ) // Pour les très veilles versions
    {
      Pdiv = document.layers[ divID ];
      Pimg = document.layers[ imgID ];
      PcH = true;
    }
  else {

      PcH = false;
  }
  if ( PcH ) {
      $(Pdiv).slideToggle(150);

      if($(Pimg).attr('src')=="images/cross.gif" ){
        $(Pimg).attr('src',"images/noncross.gif");
      }
      else {
        $(Pimg).attr('src',"images/cross.gif");
      }
  }
}

function showHideUserMenu(elmt){

  $('#usermenuinfos').slideToggle(300,
  function(){
    if($(this).is(':visible')){
      etat='down';
      $('#expandusermenu').attr('src','images/arrow-up.png');
    }
    else {
      etat='up';
      $('#expandusermenu').attr('src','images/arrow-dn.png');
    }
    $.cookie('BOX_OPEN', etat , { path: '/', expires: 365 });
  });
  $(elmt).children().blur();
  return false;
}

function email2click(){
  $('.email2click_a').each(function(){
    $(this).after('<a href="mailto:'+$(this).children('.email2click_1').html()+'@'+$(this).children('.email2click_2').html()+'">Email</a> ');
  });
  $('.email2click_b').each(function(){
    $(this).after('<a href="mailto:'+$(this).children('.email2click_1').html()+'@'+$(this).children('.email2click_2').html()+'">'+$(this).children('.email2click_1').html()+'@'+$(this).children('.email2click_2').html()+'</a> ');
  });
}

$(document).ready(function(){
  $('textarea.field-exemple,input.field-exemple').each(function(){
    if($(this).attr('title').length > 0 && $(this).val().length == 0){
      $(this).val($(this).attr('title'));
      $(this).addClass('field-exemple-empty');
    }
  }).focus(function(){
    if($(this).hasClass('field-exemple-empty')){
      $(this).val('');
      $(this).removeClass('field-exemple-empty');
    }
  }).blur(function(){
    if($(this).val().length == 0){
      $(this).addClass('field-exemple-empty');
      $(this).val($(this).attr('title'));
    }
  }).parents('form').submit(function(){
    $(this).find('.field-exemple-empty').val('');
  });
});
