﻿
/*=======================================================*/
/*==========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()+1) + '/' + 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();}




/*=======================================================*/
/*==================FONCTIONS============================*/
/*=======================================================*/

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 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=yes,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 goUrl(zeUrl){
  location.href=zeUrl;
}
function goUrlSelf(zeUrl){
  window.open(zeUrl,'popupMedias','scrollbars,resizable,status=yes,toolbar=yes,directories=no,width='+1024+',height='+768);
}

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 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 isInf(a,b){
  if(a<b) {return true;}
  else{return false;}
}
function and(a,b){
  if(a&&b) {return true;}
  else{return false;}
}

function changeParentalCodeAjax(){
        
  //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);
  
  s=document.getElementById('submitor');
  
  var request = new activsoft.ajax.RequestToSend();          
  request.page = "xslt.aspx";           
  request.request = 'typerubrique=1&rubriqueid=24&firstrec=2&nbrec=2&rec2='+s.enr15.value+'&rec3='+s.enr16.value;     
  request.method = "POST";     
  request.afterLoadCallBack = changeParentalCodeAjaxBack ;          
  request.send();
}

function changeParentalCodeAjaxBack(){    
  var racine = activsoft.ajax.util.xpathNodeList('//BODY',this.xmlDocumentLoaded.documentElement,this.xmlDocumentLoaded.documentElement)[0];
  if(!racine){return;}
  if(!racine.firstChild){return;}
  var node2 = racine.firstChild;
  var t;
  
   
  t=node2.attributes[0].nodeValue;           
  
  
  if(t=='1'){
    document.getElementById('wrongPass').style.display='none';
    document.getElementById('goodPass').style.display='';
  }
  else{
    document.getElementById('wrongPass').style.display='';
    document.getElementById('goodPass').style.display='none';
  }
}

function checkParentalCodeAjax(){
        
  //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);
  
  s=document.getElementById('submitor');
  var code=prompt('Veuillez saisir le code parental pour afficher cette chaine : ','');
  if(!code) {return;}
  
  var request = new activsoft.ajax.RequestToSend();          
  request.page = "xslt.aspx";           
  request.request = 'typerubrique=1&rubriqueid=25&firstrec=2&nbrec=1&rec2='+code;     
  request.method = "POST";     
  request.afterLoadCallBack = checkParentalCodeAjaxBack ;          
  request.send();
}

function checkParentalCodeAjaxBack(){    
  var racine = activsoft.ajax.util.xpathNodeList('//BODY',this.xmlDocumentLoaded.documentElement,this.xmlDocumentLoaded.documentElement)[0];
  if(!racine){return;}
  if(!racine.firstChild){return;}
  var node3 = racine.firstChild;
  var t;   
  t=node3.attributes[0].nodeValue;  
  
  if(t=='1'){
    val=document.getElementById('submitor').choixChaine.value;
    return ChangeChannel(val.replace('_1',''));
  }
  else{
    alert('Code parental incorrect.');
  }
}


/*=======================================================*/
/*==========CALCULS GMT-5 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;
  
  
  if(node){     
    var t=node.attributes[0].nodeValue.split(",");
    zeDate=new Date(t[0],t[1],t[2],t[3],t[4],t[5]); 
    //debugger;
    node = node.nextSibling;
    var t=node.attributes[0].nodeValue.split(",");
    dateParis=new Date(t[0],t[1],t[2],t[3],t[4],t[5]); 
    node = node.nextSibling;
    var t=node.attributes[0].nodeValue.split(",");
    dateLondon=new Date(t[0],t[1],t[2],t[3],t[4],t[5]); 
    node = node.nextSibling;
    try{
      var t=node.attributes[0].nodeValue.split(",");
      dateLocale=new Date(t[0],t[1],t[2],t[3],t[4],t[5]); 
    }
    catch(err){
      
    }
    node = node.nextSibling;
    if(node.attributes[0].nodeValue=='' && logge!=''){      
      location.href='xslt.aspx?deco=1';      
    }
  }  
}

function getDayFromNumber(n){
  switch(n)
  {
  case 1:
    return 'Lundi';
    break;    
  case 2:
    return 'Mardi';
    break;
  case 3:
    return 'Merc.';
    break;
  case 4:
    return 'Jeudi';
    break;
  case 5:
    return 'Vend.';
    break;
  case 6:
    return 'Sam.';
    break;
  case 0:
    return 'Dim.';
    break;
  default:
    return '';
  } 
}
function getMonthFromNumber(n){
  switch(n)
  {
  case 0:
    return 'Janv.';
    break;    
  case 1:
    return 'Févr.';
    break;
  case 2:
    return 'Mars';
    break;
  case 3:
    return 'Avr.';
    break;
  case 4:
    return 'Mai';
    break;
  case 5:
    return 'Juin';
    break;
  case 6:
    return 'Juil.';
    break;
  case 7:
    return 'Août';
    break;
  case 8:
    return 'Sept.';
    break;
  case 9:
    return 'Oct.';
    break;
  case 10:
    return 'Nov.';
    break;
  case 11:
    return 'Déc.';
    break;
  default:
    return '';
  } 
}

//Complément à 2 : 10H4 ==> 10H04
function habille(n){
  if(n.toString().length<2){
    return '0'+n; 
  } 
  else{
    return n;
  }
}

