function ecrireCookie(nom, valeur){
  var argv=ecrireCookie.arguments;
  var argc=ecrireCookie.arguments.length;
  var expires=(argc > 2) ? argv[2] : null;
  var path=(argc > 3) ? argv[3] : null;
  var domain=(argc > 4) ? argv[4] : null;
  var secure=(argc > 5) ? argv[5] : false;
  document.cookie=nom+"="+escape(valeur)+
  ((expires==null) ? "" : ("; expires="+expires.toGMTString()))+
  ((path==null) ? "" : ("; path="+path))+
  ((domain==null) ? "" : ("; domain="+domain))+
  ((secure==true) ? "; secure" : "");
}

function getCookieVal(offset){
  var endstr=document.cookie.indexOf (";", offset);
  if (endstr==-1) endstr=document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr)); 
}

function lireCookie(nom){
  var arg=nom+"=";
  var alen=arg.length;
  var clen=document.cookie.length;
  var i=0;
  while (i<clen) {
    var j=i+alen;
    if (document.cookie.substring(i, j)==arg) return getCookieVal(j);
    i=document.cookie.indexOf(" ",i)+1;
    if (i==0) break;
  }
  return null; 
}


// affichage du calque
function afficheBrm(){
    var larg=document.body.clientWidth;

 	document.getElementById('blocRideau').style.width=larg;
	document.getElementById('blocRideau').style.display='block';
	document.getElementById('blocQuest').style.display='block';
}

function cacheBrm(){
//  document.all.blocQuest.style.display='none';
	document.getElementById('blocRideau').style.display='none';
	document.getElementById('blocQuest').style.display='none';
}

// fonction javascript pour générer un nombre aléatoire :
function alea(valMax) {
  x = Math.ceil(Math.random()*valMax);
  return x;
}

// Insertion du cookie questionnaire puis affichage du calque
function validQuest(url) {
  date=new Date;
  date.setDate(date.getDate()+90);

  ecrireCookie("barosite", 1, date);
  afficheBrm();
}

function popunder(){
  url="http://www.etudes-en-ligne.fr/BaroSite/Pimkie/index.php"
  
  cacheBrm()
  window.open(url,'Zoom','width=950,height=600,left=70,top=30,scrollbars=yes,toolbar=no,menubar=no,resize=no')
  window.focus()
}

// traitement et vérification du cookie
function openpp() {
  var varFreq=50; // fréquence max d'affichage
  var blocker=0; // blocage du popup si variable à 1
  
  if (blocker==1) return; // Si le blocker est à 1 on ne fait rien
  if (lireCookie("barosite")!=null) return; // Si le calque s'est déjà ouvert on ne fait rien

  nbreAlea=alea(varFreq);
  //alert(nbreAlea);
  if (nbreAlea==1) validQuest();
}

// calque du questionnaire
document.write ('<div id="blocRideau" style="left: 0px; top:0px; width:100%; height:1800px; position:absolute; z-index:20; display:none; background-color:#000000; filter:alpha(opacity=60); -moz-opacity:.60; opacity:.60"></div>'+
'<div style="top:180px; left:70px; position:absolute; width:982px; z-index:21;">'+
'<div id="blocQuest" style="margin:auto; width:350px; display:none;">'+
'<table width="475" border="0" cellspacing="0" cellpadding="0">'+
'  <tr>'+
'    <td><img src="CalqueHP_01.jpg" width="205" height="175"></td>'+
'    <td><img src="CalqueHP_02.jpg" width="270" height="175"></td>'+
'  </tr>'+
'  <tr>'+
'    <td><a href="javascript:popunder()"><img src="CalqueHP_03.jpg" width="205" height="30" border="0"></a></td>'+
'    <td rowspan="3"><img src="CalqueHP_06.jpg" width="270" height="105"></td>'+
'  </tr>'+
'  <tr>'+
'    <td><a href="javascript:cacheBrm()"><img src="CalqueHP_04.jpg" width="205" height="30" border="0"></a></td>'+
'  </tr>'+
'  <tr>'+
'    <td><img src="CalqueHP_05.jpg" width="205" height="45"></td>'+
'  </tr>'+
'</table>'+
'</div></div>');

setTimeout('openpp()', 5);