﻿
/*=======================================================*/
/*==========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.toString = function () {return this.getDay();}




/*=======================================================*/
/*==================FONCTIONS============================*/
/*=======================================================*/


function showCU(id){
  document.getElementById('pop_CU_'+id).style.display='';
  showCache();
}
function hideCU(id){
  document.getElementById('pop_CU_'+id).style.display='none';
  hideCache();
}

function getRadioValue(radio,msg) {
  for (var i=0; i<radio.length;i++) {
    if (radio[i].checked) {
      return radio[i].value;
    }
  }
  return false;
}

function isDate(champ,msg){  
  if(isDateValue(champ.value) == false){
    return notgood(champ,msg);
  }   
  return true;
}

function isDateValue(dateStr){
  
  //Modified by DO 12/31/2003
  var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
  var matchArray = dateStr.match(datePat); // is the format ok?
  var datestatus=true;
  datemsg="";
  
  if (matchArray == null || matchArray[1]==null)
  {
    datemsg="----- Please enter date as mm/dd/yyyy " + "\n";
    return false;
  }
  else
  {
    if(matchArray[3]==null || matchArray[5]==null)
    {
      datemsg="----- Please enter date as mm/dd/yyyy " + "\n";
      return false;
    }
  }
  
  month = parseInt(matchArray[3],10);
  day = parseInt(matchArray[1],10);  
  year = parseInt(matchArray[5],10);
  
  if (month < 1 || month > 12)
  { 
    datemsg=datemsg + "----- Month must be between 1 and 12." + "\n";
    datestatus=false;
  }
  
  if (day < 1 || day > 31)
  {
    datemsg=datemsg + "----- Day must be between 1 and 31." + "\n";
    datestatus=false;
  }
  
  if ((month==4 || month==6 || month==9 || month==11) && day==31)
  {
    datemsg=datemsg + "----- Month " + month + " doesn`t have 31 days!" + "\n";
    datestatus=false;
  }
  
  if (month == 2)
  { 
    var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
    if (day > 29 || (day==29 && !isleap))
    {
      datemsg=datemsg + "----- February " + year + " doesn`t have " + day + " days!" + "\n";
      datestatus=false;
    }
  }  
  return datestatus;

}


function setBloc(){  
  //Si un des blocs gauche ou droit est plus grand que le central, on resize ce dernier
  var glass=document.getElementById("cache"); 
  var cont=document.getElementById("global"); 
  
  glass.style.height=(cont.offsetHeight)+'px';    
  
}

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 displayId(id,value){
  var obj=document.getElementById(id);
  obj.style.display=value;
}
function displayThis(obj,value){
  obj.style.display=value;
}
function switchClass(obj,zeClass){
  obj.className=zeClass;
}

function goLang(lang) {  
  location.href= root + lang + '/xslt.aspx';
}


function setEnr(enregistrementid,firstenr,nbenr) {
  document.getElementById('submitor').enregistrementid.value = enregistrementid;
  document.getElementById('submitor').nbenr.value = nbenr;
  document.getElementById('submitor').firstenr.value = firstenr;
} 
  
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 goPop(typerubrique, rubriqueid, elementid, offset, nbrec, firstrec, height, width, ajout) {
 window.open('','popupDetails'+ajout,'scrollbars,resizable,status=yes,toolbar=no,directories=no,width='+width+',height='+height);
 document.getElementById('submitor').target = 'popupDetails'+ajout;
 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();
 document.getElementById('submitor').target = '';
}

function notgood(field,msg) {
  field.focus();
  alert(msg);
  return false;
}

function isFullNb(field,msg,minchars){
  field.value=field.value.trim();
  if (field.value.length<minchars) {return notgood(field,msg);}
  return true;
}

function isAllDigits(champ,msg){    
   var chiffres = new RegExp("^[0-9]*$");
   var verif;   
   verif = chiffres.test(champ.value);         
   if(verif == false){
    return notgood(champ,msg);
   }   
   return true;
}

function containsDigits(champ,msg){    
   var chiffres = new RegExp("[0-9]");
   var verif;   
   verif = chiffres.exec(champ.value);         
   if(verif){
    return notgood(champ,msg);
   }   
   return true;
}

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) {  
  field.value=field.value.killspaces();
  
  var email=field.value;
  var arobase=email.indexOf('@');
  var point=email.indexOf('.',arobase);
  var longueur=email.length;
  if(arobase<=0||point<=arobase+1||longueur<=point+1) {return notgood(field,msg);}
  return true;
}

// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function setMailaction(obj){
  document.getElementById('mailaction').value=obj;
}


var imgLoad;
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';  
  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;
}


function and(val1,val2){
  return val1 && val2; 
}
function or(val1,val2){
  return val1 || val2; 
}

function isInf(val1, val2 ) {
  return val1<val2;
}

function isInfEgal(val1, val2 ) {
  return val1<=val2;
}

function isSup(val1, val2 ) {
  return val1>val2;
}

function isSupEgal(val1, val2 ) {
  return val1>=val2;
}

function soumettreparrain() {
  //document.forms['submitor'].typerubrique.value = '1';
  //document.forms['submitor'].rubriqueid.value = '22';
  for (var i=1; i<6; i++) {
    var el = document.getElementById("staticemail" + i);
    if (el.value!='') {
      if (!isMail(el, 'L\'email fourni a la ligne ' + i + ' n\'a pas un format correct.')) {
        return false;
      }
    }
  }  
  document.getElementById('submitor').actionner.value="LAUNCHPARRAIN";
  go('1','6','','','','');
}


/*=======================================================*/
/*==========CALCULS GMT-4 ET MANIPULATIONS DATES=========*/
/*=======================================================*/

function getHour(){
        
  //wait = new activsoft.ajax.util.WaitPanelObject();
  //wait.showInPosition("WAIT", "Recherche des données...",(YAHOO.util.Dom.getClientHeight() / 2)+YAHOO.util.Dom.getDocumentScrollTop(),YAHOO.util.Dom.getClientWidth() / 2);

  var request = new activsoft.ajax.RequestToSend();          
  request.page = "xslt.aspx";           
  request.request = 'typerubrique=1&rubriqueid=-2';     
  request.method = "POST";     
  request.afterLoadCallBack = getHourBack ;          
  request.send();
}

function getHourBack(){    
  var racine = activsoft.ajax.util.xpathNodeList('//BODY',this.xmlDocumentLoaded.documentElement,this.xmlDocumentLoaded.documentElement)[0];
  if(!racine){return;}
  if(!racine.firstChild){return;}
  var node = racine.firstChild;
  
  while(node){     
    var t=node.attributes[0].nodeValue.split(",");
    zeDate=new Date(t[0],t[1],t[2],t[3],t[4],t[5]);       
    var node = node.nextSibling;
  }  
}

function getDayFromNumber(n){
  switch(n)
  {
  case 1:
    return 'Lundi';
    break;    
  case 2:
    return 'Mardi';
    break;
  case 3:
    return 'Mercredi';
    break;
  case 4:
    return 'Jeudi';
    break;
  case 5:
    return 'Vendredi';
    break;
  case 6:
    return 'Samedi';
    break;
  case 0:
    return 'Dimanche';
    break;
  default:
    return '';
  } 
}
function getMonthFromNumber(n){
  switch(n)
  {
  case 0:
    return 'Janvier';
    break;    
  case 1:
    return 'Février';
    break;
  case 2:
    return 'Mars';
    break;
  case 3:
    return 'Avril';
    break;
  case 4:
    return 'Mai';
    break;
  case 5:
    return 'Juin';
    break;
  case 6:
    return 'Juillet';
    break;
  case 7:
    return 'Août';
    break;
  case 8:
    return 'Septembre';
    break;
  case 9:
    return 'Octobre';
    break;
  case 10:
    return 'Novembre';
    break;
  case 11:
    return 'Décembre';
    break;
  default:
    return '';
  } 
}

//Complément à 2 : 10H4 ==> 10H04
function habille(n){
  if(n.toString().length<2){
    return '0'+n; 
  } 
  else{
    return n;
  }
}
