﻿
/*=======================================================*/
/*==========SURCHARGES DES TYPES String et Date==========*/
/*=======================================================*/
String.prototype.trim = function(){
return this.replace(/^\s+/, "").replace(/\s+$/, "");
}
String.prototype.killspaces = function(){
  var reg=new RegExp(" ", "g");  
  return this.replace(reg, "");
}
Date.prototype.addSeconds = function (n) {this.setSeconds (this.getSeconds () + n)}
//Date.prototype.toString = function () {return [getDayFromNumber(this.getDay()), habille(this.getDate()), getMonthFromNumber(this.getMonth())].join ('&#160;')+'&#160;:&#160;'+[habille(this.getHours()),habille(this.getMinutes())].join('h')+''}
Date.prototype.toStringFr = function () {return habille(this.getDate()) + '/' + habille(this.getMonth()) + '/' + this.getFullYear()}
Date.prototype.toStringHours = function () {return [habille(this.getHours()),habille(this.getMinutes())].join('h')+''}
//Date.prototype.getStringMonth = function () {return [getDayFromNumber(this.getDay()), habille(this.getDate()), getMonthFromNumber(this.getMonth())].join ('&#160;')}
//Date.prototype.toString = function () {return this.getDay();}


function setPost(){
  document.getElementById('submitor').method='post'; 
}

function launchOnEnter(expression) {
  if(event.keyCode==3 || event.keyCode==13) {
    eval(expression);
  }
}

function search(event){
  if((event.keyCode==3)||(event.keyCode==13)) {
    go('1','11',document.getElementById('submitor').rec2.value,'','','');
  }
  void(0);
}

function emptySearch(inputObj,txt){
  if(inputObj.value==txt){
    inputObj.value="";
  } 
}
function fillSearch(inputObj,txt){
  if(inputObj.value==""){
    inputObj.value=txt;
  } 
}

function displayThis(obj,value){
  obj.style.display=value;
}
function switchClass(obj,zeClass){
  obj.className=zeClass;
}
function showListLang(obj){
  displayThis(document.getElementById('listLang'),'');
  obj.style.backgroundColor= '#FFFFFF';
  obj.style.color= '#FFFFFF';
  
  //on programme l'evenement sur click du div global pour cacher le div de lang
  setTimeout("YAHOO.util.Event.addListener('global','click',hideListLang);",100);    
    
}
function hideListLang(){
  var obj=document.getElementById('trigLang');
  displayThis(document.getElementById('listLang'),'none');
  obj.style.backgroundColor= '';
  obj.style.color= '';
  
  //On déprogramme l'évenement click sur div global
  YAHOO.util.Event.removeListener("global","click",hideListLang);  
}
function changeLang(elem,lang){
  var obj=document.getElementById('trigLang');
  obj.innerHTML=elem.innerHTML;
  hideListLang();
  goLang(lang);
}
function goLang(lang) {  
  location.href= root + lang + '/xslt.aspx';
}

function setBloc(){  
  //Si un des blocs gauche ou droit est plus grand que le central, on resize ce dernier
  var left=document.getElementById("blocGaucheAccueil"); 
  var right=document.getElementById("blocDroiteAccueil"); 
  var center=document.getElementById("blocMilieuAccueil");   
  
  if((center.offsetHeight >= left.offsetHeight) && (center.offsetHeight >= right.offsetHeight)){
    return;
  }
  
  //Le droit est plus grand
  if(left.offsetHeight<=right.offsetHeight){
    center.style.height=(right.offsetHeight)+'px';    
    return;
  }
  //Le gauche est plus grand
  if(right.offsetHeight<=left.offsetHeight){
    center.style.height=(left.offsetHeight)+'px';    
    return;
  }    
}
function setBlocDoc(){  
  //Si un des blocs gauche ou droit est plus grand que le central, on resize ce dernier
  var left=document.getElementById("divLeftDoc"); 
  var right=document.getElementById("divRightDoc"); 
  var center=document.getElementById("divMidDoc"); 
  var mediatop = document.getElementById("divTopDoc"); 
  
  if((center.offsetHeight >= (left.offsetHeight-mediatop.offsetHeight)) && (center.offsetHeight >= right.offsetHeight)){
    return;
  }
  
  //Le droit est plus grand
  if((left.offsetHeight-mediatop.offsetHeight)<=right.offsetHeight){
    center.style.height=(right.offsetHeight)+'px';    
    return;
  }
  //Le gauche est plus grand
  if(right.offsetHeight<=(left.offsetHeight-mediatop.offsetHeight)){
    center.style.height=((left.offsetHeight-mediatop.offsetHeight))+'px';    
    return;
  }    
}


var timer=setTimeout('1',0);

function setEnr(enregistrementid,firstenr,nbenr) {
  document.getElementById('submitor').enregistrementid.value = enregistrementid;
  document.getElementById('submitor').nbenr.value = nbenr;
  document.getElementById('submitor').firstenr.value = firstenr;
} 

function Bip(id) { 
  var mesDivs = document.getElementsByTagName("div");
  for(var i=0; i<mesDivs.length; i++) {
    if(mesDivs[i].id.indexOf('menu')==0) {
      mesDivs[i].style.visibility = "hidden";
    }
  }
  document.getElementById('menu'+id).style.visibility='visible';
}

    
function setTimer(s) {
  clearTimeout(timer);
  timer=setTimeout(s,600);
}
  
function go(typerubrique,rubriqueid,elementid,offset,nbrec,firstrec) {
  document.getElementById('submitor').target='';
  document.getElementById('submitor').typerubrique.value = typerubrique;
  document.getElementById('submitor').rubriqueid.value = rubriqueid;
  document.getElementById('submitor').elementid.value = elementid;
  document.getElementById('submitor').offset.value = offset;
  document.getElementById('submitor').nbrec.value = nbrec;
  document.getElementById('submitor').firstrec.value = firstrec;
  document.getElementById('submitor').submit();
} 

function notgood(field,msg) {
  field.focus();
  alert(msg);
  return false;
}

function isFull(field,msg){
  if (field.value=='') {return notgood(field,msg);}
  return true;
}

function isDigit(field,msg) {
  i = field.value.charCodeAt(0);
  if (!((47<i)&&(i<58))){return notgood(field,msg);}
  return true;
}

function isSelect(field,msg){
  if (field.selectedIndex==0 && field.options[0].value=="") {return notgood(field,msg);}
  return true;
}

function isMail(field,msg) {
  email=field.value;
  arobase=email.indexOf('@');
  point=email.indexOf('.',arobase);
  longueur=email.length;
  if(arobase<=0||point<=arobase+1||longueur<=point+1) {return notgood(field,msg);}
  return true;
}

function goMail(elementid,zeracine) {
  mailfen = window.open('','mail','scrollbars,toolbar=no,directories=no,width=350,height=200');
  racine=zeracine;
  
  imgLoad =new Image; imgLoad.src= racine + 'img/wait.gif';
  imgLoad.height=73;
  imgLoad.width=75;
  
  mailfen.moveTo((screen.width/2)-(350/2),(screen.height/2)-(200/2));
  
  wait = setTimeout("if(imgLoad.complete){writeMessageBeforeMailAndSend("+elementid+");}",315);    
}  

function writeMessageBeforeMailAndSend(elementid){
  mailfen.document.writeln('<html>');
  mailfen.document.writeln('<head>');
  mailfen.document.writeln('  <title>Envoi de message</title>');
  mailfen.document.writeln('</head>');
  mailfen.document.writeln('<body>    ');
  mailfen.document.writeln('  <table cellpadding="0" border="0" cellspacing="0" width="100%">');
  mailfen.document.writeln('    <tr>');
  mailfen.document.writeln('      <td align="center">');
  mailfen.document.writeln('        &#160;');
  mailfen.document.writeln('      </td>');
  mailfen.document.writeln('    </tr>');
  mailfen.document.writeln('    <tr>');
  mailfen.document.writeln('      <td align="center">');
  mailfen.document.writeln('        &#160;');
  mailfen.document.writeln('      </td>');
  mailfen.document.writeln('    </tr>');
  mailfen.document.writeln('    <tr>');
  mailfen.document.writeln('      <td align="center">');
  mailfen.document.writeln('        <span class="texte">');
  mailfen.document.writeln('          <img height="73" width="75" id="wait" src="' + racine + 'img/wait.gif"/>');
  mailfen.document.writeln('        </span>');
  mailfen.document.writeln('      </td>');
  mailfen.document.writeln('    </tr>');
  mailfen.document.writeln('    <tr>');
  mailfen.document.writeln('      <td align="center" style="font-family:verdana;font-size:10px;">');
  mailfen.document.writeln('        <span class="texte">');
  mailfen.document.writeln('          Veuillez patienter...');
  mailfen.document.writeln('        </span>');
  mailfen.document.writeln('      </td>');
  mailfen.document.writeln('    </tr>');
  mailfen.document.writeln('  </table>   ');    
  mailfen.document.writeln('</body>');
  mailfen.document.writeln('</html>');
  
  document.getElementById('submitor').target = 'mail';
  document.getElementById('submitor').action = racine + 'xsltMailer.aspx';
  ///alert(document.getElementById('submitor').elementid);
  document.getElementById('submitor').elementid.value = elementid;
  document.getElementById('submitor').submit();
  document.getElementById('submitor').reset();
  document.getElementById('submitor').target = '';
  document.getElementById('submitor').action='xslt.aspx';    
}
  

function findPosX(obj)
{
  var curleft = 0;
  if(obj.offsetParent)
      while(1) 
      {
        curleft += obj.offsetLeft;
        if(!obj.offsetParent)
          break;
        obj = obj.offsetParent;
      }
  else if(obj.x)
      curleft += obj.x;
  return curleft;
}

function findPosY(obj)
{
  var curtop = 0;
  if(obj.offsetParent)
      while(1)
      {
        curtop += obj.offsetTop;
        if(!obj.offsetParent)
          break;
        obj = obj.offsetParent;
      }
  else if(obj.y)
      curtop += obj.y;
  return curtop;
}

var callerPrint;
var zePop;
function print_page(caller,rub){
  pop = window.open(root+'xslt.aspx?typerubrique=1&rubriqueid=19&elementid='+rub,'popupPrint','scrollbars,resizable,status=yes,toolbar=no,directories=no,width='+770+',height='+450);
  callerPrint=caller; 
  zePop=pop; 
}

function setConteneur(div){  
  if(div){
    
    var topaste=callerPrint.cloneNode(true);
    topaste.style.position='relative';
    topaste.style.top='0px';
    topaste.style.left='0px';
    topaste.style.marginLeft='15px';
    topaste.style.marginTop='15px';
    /*topaste.style.border='1px solid #000000';*/
    
    //imported = pop.document._importNode(topaste,true);
    
    try{
      div.appendChild(topaste);
    }
    catch(err){
      div.className=topaste.className;
      div.id=topaste.id;
      div.style.position='relative';
      div.style.top='0px';
      div.style.left='0px';
      div.innerHTML=topaste.innerHTML;
    }
    
  }
}

function replaceAmp(input){
  return input.replace(/&amp;/g,"&");
}
