// Script de limitation du nombre de caractère dans un textarea
var ns6=document.getElementById && !document.all;

function restrictinput(maxlength, e, placeholder) {
  if (window.event && event.srcElement.value.length>=maxlength) return false;
  else if (e.target && e.target==eval(placeholder) && e.target.value.length>=maxlength) {
    var pressedkey=/[a-zA-Z0-9\.\,\/]/;
    if (pressedkey.test(String.fromCharCode(e.which))) e.stopPropagation();
  };
};

function countlimit(maxlength,e,placeholder) {
  var theform=eval(placeholder);
  var lengthleft=maxlength-theform.value.length;
  var placeholderobj=(document.all? document.all[placeholder] : document.getElementById(placeholder));
  if (window.event||e.target && e.target==eval(placeholder)) {
    if (lengthleft<0) theform.value=theform.value.substring(0,maxlength);
    placeholderobj.innerHTML=lengthleft;
  };
};

function displaylimit(theid, thelimit) {
  var theform=document.getElementById(theid);
  var limit_text='<span class="hNormal"><b><span id="'+theform.toString()+'">'+eval(thelimit-theform.value.length)+'</span></b></span> caractères restants.';
  if (document.all||ns6) document.write(limit_text);
  if (document.all) {
    eval(theform).onkeypress=function(){ return restrictinput(thelimit,event,theform)};
    eval(theform).onkeyup=function(){ countlimit(thelimit,event,theform)};
  }
  else if (ns6) {
    document.body.addEventListener('keypress', function(event) { restrictinput(thelimit,event,theform) }, true);
    document.body.addEventListener('keyup', function(event) { countlimit(thelimit,event,theform) }, true);
  };
};

function affiche_coupure(id, largeur, hauteur) {
  largeur = largeur+17;
  hauteur = hauteur+4;
  if (hauteur > (screen.height-150)) hauteur = (screen.height-150);
  var win = window.open('/presse/agrandissement-a'+id+'.html', 'coupure', 'toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=no,copyhistory=no,width='+largeur+',height='+hauteur+',left=' + ((screen.width-largeur)/2) + ',top=' + ((screen.height-hauteur-20)/2));
  win.focus();
};

function affiche_document(id, largeur, hauteur) {
  largeur = largeur+25;
  hauteur = hauteur+55;
  if (hauteur > (screen.height-150)) hauteur = (screen.height-150);
  var win = window.open('/dossier/document-i'+id+'.html', 'document', 'toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=no,copyhistory=no,width='+largeur+',height='+hauteur+',left=' + ((screen.width-largeur)/2) + ',top=' + ((screen.height-hauteur-20)/2));
  win.focus();
};

function affiche_photo(id, largeur, hauteur) {
  var win = window.open('/dossier/photo-p'+id+'.html', 'photo', 'toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no,copyhistory=no,width='+largeur+',height='+hauteur+',left=' + ((screen.width-largeur)/2) + ',top=' + ((screen.height-hauteur-20)/2));
  win.focus();
};

function affiche_video(url, largeur, hauteur) {
  var win = window.open(url, 'video', 'toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no,copyhistory=no,width='+largeur+',height='+hauteur+',left=' + ((screen.width-largeur)/2) + ',top=' + ((screen.height-hauteur-20)/2));
  win.focus();
};

//-- Script scroll

//-- Begin Scroller's Parameters and message -->
var swidth=170;
var sheight=80;
var sbcolor="#AECD88";
var sspeed=1;
var restart=sspeed;
rspeed=sspeed;

//-- begin: Scroller's Algorithm -->
function goup() {
  if (sspeed!=rspeed*8) {
    sspeed=sspeed*2;
    restart=sspeed;
  }
}

function godown() {
  if (sspeed>rspeed) {
    sspeed=sspeed/2;
    restart=sspeed;
  }
}

function start() {
  if (document.getElementById) ns6marquee(document.getElementById('slider'));
  else if (document.all) iemarquee(slider);
  else if(document.layers) ns4marquee(document.slider1.document.slider2);
}

function iemarquee(whichdiv) {
  iediv=eval(whichdiv);
  iediv.style.pixelTop=sheight;
  iediv.innerHTML=wholemessage;
  sizeup=iediv.offsetHeight;
  ieslide();
}

function ieslide() {
  if (iediv.style.pixelTop>=sizeup*(-1)) {
    iediv.style.pixelTop-=sspeed;
    setTimeout("ieslide()",100);
  }
  else {
    iediv.style.pixelTop=sheight;
    ieslide();
  }
}

function ns4marquee(whichlayer) {
  ns4layer=eval(whichlayer);
  ns4layer.top=sheight;
  ns4layer.document.write(wholemessage);
  ns4layer.document.close();
  sizeup=ns4layer.document.height;
  ns4slide();
}

function ns4slide() {
  if(ns4layer.top>=sizeup*(-1)) {
    ns4layer.top-=sspeed;
    setTimeout("ns4slide()",100);
  }
  else {
    ns4layer.top=sheight;ns4slide();
  }
}

function ns6marquee(whichdiv) {
  ns6div=eval(whichdiv);
  ns6div.style.top=sheight;
  ns6div.innerHTML=wholemessage;
  sizeup=ns6div.offsetHeight;
  ns6slide();
}

function ns6slide() {
  if(parseInt(ns6div.style.top)>=sizeup*(-1)) {
    ns6div.style.top=parseInt(ns6div.style.top)-sspeed;
    setTimeout("ns6slide()",100);
  }
  else {
    ns6div.style.top=sheight;ns6slide();
  }
}

window.onload=start

