﻿var toclose=0;
var curzindex=1000;
var Budgtimer;


/*=======================================================*/
/*==========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();}

Array.prototype.remove = function(from, to) {
  var rest = this.slice((to || from) + 1 || this.length);
  this.length = from < 0 ? this.length + from : from;
  return this.push.apply(this, rest);
};


/*=======================================================*/
/*==================FONCTIONS============================*/
/*=======================================================*/

function showId(id, caller, decaltop, decalleft){
  var el=document.getElementById(id);
  if(!el){return;}
  
  if(el.style.display==''){el.style.display='none';return;}
  
  el.style.top=findPosY(caller)+decaltop+'px';
  el.style.left=findPosX(caller)+decalleft+'px';
  curzindex++;
  el.style.zIndex=curzindex;
  
  el.style.display='';
}
function hideId(id){
  var el=document.getElementById(id);
  if(!el){return;}  
  
  el.style.display='none';
}

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 changePic(Id){
  $('#grandePhoto').stop(true,true).fadeOut('slow', function() {document.getElementById('grandePhoto').src=eval('grandePhoto'+Id)   });
  $('#grandePhoto').stop(true,true).fadeIn('slow', function() {});
  clearInterval(wait);
}

//On parcours le tableau jusqu'a trouver l'image en cours, et on prend la suivante.
//Si c'est la dernière on reprend la première
function changePicAuto(){
  var iloop=0;
  var exit=false;
  
  while(iloop<=(tabIds.length-2) && exit==false){      
    if(tabIds[iloop]==curId){
      iloop++;
      exit=true;
    }
    else{
      iloop++;
    }      
    if(iloop>tabIds.length-2){
      iloop=0;
      exit==true;    
    }
  }
  $('#grandePhoto').stop(true,true).fadeOut('slow', function() {document.getElementById('grandePhoto').src=eval('grandePhoto'+tabIds[iloop])});
  $('#grandePhoto').stop(true,true).fadeIn('slow', function() {});
  curId = tabIds[iloop];
}

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 et() {
  return "&";
}

function setEnr(enregistrementid,firstenr,nbenr) {
  document.getElementById('submitor').enregistrementid.value = enregistrementid;
  document.getElementById('submitor').nbenr.value = nbenr;
  document.getElementById('submitor').firstenr.value = firstenr;
  document.getElementById('submitor').method = 'post';
} 
  
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 goUrl(url) {
  location.href=url;
} 

function goPdf(typerubrique,rubriqueid,elementid,offset,nbrec,firstrec) {
  document.forms['submitor'].typerubrique.value = typerubrique;
  document.forms['submitor'].rubriqueid.value = rubriqueid;
  document.forms['submitor'].elementid.value = elementid;
  document.forms['submitor'].offset.value = offset;
  document.forms['submitor'].nbrec.value = nbrec;
  document.forms['submitor'].firstrec.value = firstrec;
  document.forms['submitor'].target="pdf"+Math.floor(Math.random()*10000);
  document.forms['submitor'].action="DirectPdf.aspx";
  document.forms['submitor'].submit();
  document.forms['submitor'].action="xslt.aspx";
  document.forms['submitor'].target="";
}

function soumettreparrain() {
  //document.forms['submitor'].typerubrique.value = '1';
  //document.forms['submitor'].rubriqueid.value = '22';
  for (var i=1; i<7; i++) {
    var el = document.getElementById("email" + 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').enregistrementid.value = -99;
  go('1','7','','','','');
}

function isDateField(champ,msg){  
  if(isDateValue(champ.value) == false){
    return notgood(champ,msg);
  }   
  return true;
}
function isHourField(champ,msg){  
  if(isHourValue(champ.value) == false){
    return notgood(champ,msg);
  }   
  return true;
}

function isHourValue(dateStr){
  
  //Modified by DO 12/31/2003
  var datePat = /^(\d{1,2})(h|\:)(\d{1,2})$/;
  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)
    {
      datemsg="----- Please enter date as mm/dd/yyyy " + "\n";
      return false;
    }
  }
  
  hour = parseInt(matchArray[1],10);
  minute = parseInt(matchArray[3],10);  
    
  if (hour > 23)
  {        
    return false;  
  } 
  if (hour < 0)
  {        
    return false;  
  }  
  
  if (minute > 59)
  {        
    return false;  
  } 
  if (minute < 0)
  {        
    return false;  
  }  
   
  return datestatus;

}
  
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 notgood(field,msg) {
  try{
    field.focus();
  }
  catch(err){}
  
  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;
}

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(a,b){
  if(a&&b) {return true;}
  else{return false;}
}

function isSup(a,b){
  if(a>b) {return true;}
  else{return false;}
}


function isSupEgale(a,b){
  if(a>=b) {return true;}
  else{return false;}
}


function isInf(a,b){
  if(a<b) {return true;}
  else{return false;}
}


/*=======================================================*/
/*==========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;
  }
}


/*=======================================================*/
/*==========TOOLTIPS=====================================*/
/*=======================================================*/


function remplirTexteDL(idtext, input){
  var listInput = document.getElementByTagName
}

function addToolTip(){
  var tt=document.getElementById("tooltip");
  if (tt==null){
    document.write("<div id='tooltip'></div>");
  }
}
// the tooltip object
var tooltip = {
    // setup properties of tooltip object
    id:"tooltip",
    offsetx : 10,
    offsety : 10,
    _x : 0,
    _y : 0,
    _tooltipElement:null,
    _saveonmouseover:null
}

function showTool(e, elem) {
  var el =document.getElementById(elem);  
  if(el){tooltip.show(el)};
}

function hideTool(e, elem) {
  var el =document.getElementById(elem);
  if(el){tooltip.hide(el)};
}

/**
* Open ToolTip. The title attribute of the htmlelement is the text of the tooltip
* Call this method on the mouseover event on your htmlelement
* ex :  <div id="myHtmlElement" onmouseover="tooltip.show(this)"...></div>
*/
tooltip.show = function (htmlelement) {

    // we save text of title attribute to avoid the showing of tooltip generated by browser
    var text=htmlelement.getAttribute("title");
    htmlelement.setAttribute("title","");
    htmlelement.setAttribute("title_saved",text);

	if(document.getElementById){
        this._tooltipElement = document.getElementById(this.id);
	}else if ( document.all ) {
        this._tooltipElement = document.all[this.id].style;
	}

    this._saveonmouseover = document.onmousemove;
    document.onmousemove = this.mouseMove;

    this._tooltipElement.innerHTML = text;

    this.moveTo(this._x + this.offsetx , this._y + this.offsety);

    if(this._tooltipElement.style){
        this._tooltipElement.style.visibility ="visible";
    }else{
        this._tooltipElement.visibility = "visible";
    }
   return false;
}

/**
* hide tooltip
* call this method on the mouseout event of the html element
* ex : <div id="myHtmlElement" ... onmouseout="tooltip.hide(this)"></div>
*/
tooltip.hide = function (htmlelement) {
    htmlelement.setAttribute("title",htmlelement.getAttribute("title_saved"));
    htmlelement.removeAttribute("title_saved");

    if(this._tooltipElement.style){
        this._tooltipElement.style.visibility ="hidden";
    }else{
        this._tooltipElement.visibility = "hidden";
    }
    document.onmousemove=this._saveonmouseover;
}



// Moves the tooltip element
tooltip.mouseMove = function (e) {
   // we don't use "this" because this method is assign to an event of document
   // and so is dereferenced
    if(e == undefined)
        e = event;

    if( e.pageX != undefined){ // gecko, konqueror,
        tooltip._x = e.pageX;
        tooltip._y = e.pageY;
    }else if(event != undefined && event.x != undefined && event.clientX == undefined){ // ie4 ?
        tooltip._x = event.x;
        tooltip._y = event.y;
    }else if(e.clientX != undefined ){ // IE6,  IE7, IE5.5
        if(document.documentElement){
            tooltip._x = e.clientX + ( document.documentElement.scrollLeft || document.body.scrollLeft);
            tooltip._y = e.clientY + ( document.documentElement.scrollTop || document.body.scrollTop);
        }else{
            tooltip._x = e.clientX + document.body.scrollLeft;
            tooltip._y = e.clientY + document.body.scrollTop;
        }
    /*}else if(event != undefined && event.x != undefined){ // IE6,  IE7, IE5.5
        tooltip.x = event.x + ( document.documentElement.scrollLeft || document.body.scrollLeft);
        tooltip.y = event.y + ( document.documentElement.scrollTop || document.body.scrollTop);
    */
    }else{
        tooltip._x = 0;
        tooltip._y = 0;
    }
    tooltip.moveTo( tooltip._x +tooltip.offsetx , tooltip._y + tooltip.offsety);

}

// Move the tooltip element
tooltip.moveTo = function (xL,yL) {
    if(this._tooltipElement.style){
        this._tooltipElement.style.left = xL +"px";
        this._tooltipElement.style.top = yL +"px";
    }else{
        this._tooltipElement.left = xL;
        this._tooltipElement.top = yL;
    }
}
function enableAllCtrl(){
   var count = document.forms[0].elements.length;
   for(i=0; i<count; i++) 
   {
      var element = document.forms[0].elements[i]; 
      if (element.disabled) { 
      	 element.disabled=false;
      } 
   }  
}

function disableCtrl(startWith){
   var count = document.forms[0].elements.length;
   var l=startWith.length;
   for(i=0; i<count; i++) 
   {
      /*
      if(document.forms[0].elements[i].id.substring(0,startWith.lenght)!=''){
        alert(startWith +' -- ' +document.forms[0].elements[i].id.substring(0,l));
        document.forms[0].elements[i].disabled=true;
      }
      */
      if(startWith==document.forms[0].elements[i].id.substring(0,l)){        
        document.forms[0].elements[i].disabled=true;
      }
   }  
}

function checkName(caller, imgid, djid){
  
  //Appel Ajax pour vérifier le login
  wait = new activsoft.ajax.util.WaitPanelObject();
  wait.showInPosition("WAIT", "Vérification du nom...",(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=34&nbrec=1&firstrec=2&rec2="+djid+"&elementid="+imgid+"&urlvalue="+caller.value;          
  request.afterLoadCallBack = retourcheckName ;          
  request.send();
}

function setBloc(){  
  //Si un des blocs gauche ou droit est plus grand on resize
  var left=document.getElementById("smallLeft"); 
  var right=document.getElementById("bigRight"); 
  var toresize=document.getElementById("divToResize"); 
  
  if(!left || !right){return;}
    
  //Le gauche est plus grand
  if((right.offsetHeight<=left.offsetHeight)){   
    toresize.style.height=(left.offsetHeight)-52+'px';    
    return;
  }   
  
}

function isSiretValide(siret) { 
  var estValide; 
  if ( (siret.length != 14) || (isNaN(siret)) ) 
    estValide = false; 
  else { 
     // Donc le SIRET est un numérique à 14 chiffres 
     // Les 9 premiers chiffres sont ceux du SIREN (ou RCS), les 4 suivants 
     // correspondent au numéro d'établissement 
     // et enfin le dernier chiffre est une clef de LUHN. 
    var somme = 0; 
    var tmp; 
    for (var cpt = 0; cpt<siret.length; cpt++) { 
      if ((cpt % 2) == 0) { // Les positions impaires : 1er, 3è, 5è, etc... 
        tmp = siret.charAt(cpt) * 2; // On le multiplie par 2 
        if (tmp > 9) 
          tmp -= 9;    // Si le résultat est supérieur à 9, on lui soustrait 9 
      } 
     else 
       tmp = siret.charAt(cpt); 
       somme += parseInt(tmp); 
    } 
    if ((somme % 10) == 0) 
      estValide = true; // Si la somme est un multiple de 10 alors le SIRET est valide 
    else 
      estValide = false; 
  } 
  return estValide; 
}

var TimeInfoBulle;
function setInfoBulle(text,time){
  clearTimeout(TimeInfoBulle);
  document.getElementById('infoBulle').innerHTML = text;
  document.getElementById('infoBulle').className='visible';
  TimeInfoBulle=setTimeout(resetInfoBulle,time);
}

function resetInfoBulle(){
  document.getElementById('infoBulle').innerHTML = '&#160;';  
  document.getElementById('infoBulle').className='notvisible';
}

function getEtAmp(){
  return '&'; 
}


function checkNum(obj) {
  var  reg=new  RegExp("[^\\d]*", "g");
  obj.value = obj.value.replace(reg,'');
}


function calculTaux(){
  
  if($('#hintBudg:visible')){
    $('#hintBudg').slideUp(function(){
      if($('#enr21').val()==''){return;}
  
      var tmpval = $('#enr21').val();
      if($('#enr22').val()!=''){tmpval = $('#enr22').val();}
      
     
     $('#toReplaceBudg').stop().load(rootabs+'xslt.aspx?typerubrique=1&rubriqueid=100&elementid='+encodeURIComponent(tmpval), function(){
       $('#hintBudg').removeClass('hint');
       $('#hintBudg').removeClass('hint_ok');
       if($('#taux').val()=='insuffisant' || $('#taux').val()=='moyen'){       
         $('#hintBudg').addClass('hint');
       }
       if($('#taux').val()=='normal' || $('#taux').val()=='excellent'){        
         $('#hintBudg').addClass('hint_ok');
       }
       $('#hintBudg').slideDown();
     });   
     
     
     $("#slider-range").slider( "values" , 0 , $('#enr21').val() );
     $("#slider-range").slider( "values" , 1 , $('#enr22').val() );
    });
  }
  else{
    if($('#enr21').val()==''){return;}
      var tmpval = $('#enr21').val();
      if($('#enr22').val()!=''){tmpval = $('#enr22').val();}
      
     
     $('#toReplaceBudg').stop().load(rootabs+'xslt.aspx?typerubrique=1&rubriqueid=100&elementid='+encodeURIComponent(tmpval), function(){
       $('#hintBudg').removeClass('hint');
       $('#hintBudg').removeClass('hint_ok');
       if($('#taux').val()=='insuffisant' || $('#taux').val()=='moyen'){       
         $('#hintBudg').addClass('hint');
       }
       if($('#taux').val()=='normal' || $('#taux').val()=='excellent'){        
         $('#hintBudg').addClass('hint_ok');
       }
       $('#hintBudg').slideDown();
     });   
     
     
     $("#slider-range").slider( "values" , 0 , $('#enr21').val() );
     $("#slider-range").slider( "values" , 1 , $('#enr22').val() );
  }
  
  
  
}

function adaptMarker(latloncompiled){
  
  //On repositionne un Marker s'il en existe déjà un a cet emplacement.
  //Recursivité
  if(jQuery.inArray(latloncompiled, collMark)>-1){
    //debugger;
    _lat=_lat+(Math.random()/50);
    _lon=_lon+(Math.random()/50);
    
    adaptMarker(_lat+';'+_lon);
  }
  return;
   
}
var clicked='ok';
function getCookieValNew(offset)
{
  var endstr=document.cookie.indexOf (";", offset);
  if (endstr==-1) endstr=document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
}
function LireCookieNew(nom)
{
  var arg=nom+"=";
  var alen=arg.length;
  var clen=document.cookie.length;
  var i=0;
  while (isInf(i,clen))
  {
    var j=i+alen;
    
    if (document.cookie.substring(i, j)==arg) return getCookieValNew(j);
      i=document.cookie.indexOf(" ",i)+1;
    if (i==0) break;
  }
  return null;
}
function EffaceCookieNew(nom)
{
  date=new Date;
  date.setFullYear(date.getFullYear()-1);
  EcrireCookieNew(nom,null,date);
}
function EcrireCookieNew(nom, valeur)
{
  var argv=EcrireCookieNew.arguments;
  var argc=EcrireCookieNew.arguments.length;
  var expires=(isSup(argc,2)) ? argv[2] : null;
  var path=(isSup(argc,3)) ? argv[3] : null;
  var domain=(isSup(argc,4)) ? argv[4] : null;
  var secure=(isSup(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 logCookieNew(nomCookie,mail) {        
  date=new Date;
  date.setTime(new Date(2100,5,24));
  //date.setTime(date.getTime()+30000);
  EcrireCookieNew(nomCookie,mail,date,'/');
} 


function showDialog(dialogId,width){
  var widthModal = 500;
  if(width){
    widthModal = width;
  }
  $("#"+dialogId).dialog("destroy");
  $( "#"+dialogId).dialog({
    autoOpen: true,
    show: "blind",
    hide: "explode",
    width:widthModal,
    modal:true,
    close: function(event, ui) { 
      $(this).destroy;
    }
  });
}


function verif(){
  var allFull='Vous n\'avez pas rempli tous les champs obligatoires.';
  var wrongMail='Adresse mail invalide.';
  
  if(document.getElementById("submitor_contact").enr1.value == ''){
    $('#error_contact').html(allFull);
    $('#error_contact').fadeIn('slow', function() {});
    return false;
  }

  if(document.getElementById("submitor_contact").enr2.value == ''){
    $('#error_contact').html(allFull);
    $('#error_contact').fadeIn('slow', function() {});
    return false;
  }
      
  if(!isMailContact(document.getElementById("submitor_contact").enr3)){
    $('#error_contact').html(wrongMail);
    $('#error_contact').fadeIn('slow', function() {});
    return false;
  }
  
  return true;
}

function isMailContact(field) {  
  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 false;}
  return true;
}

function reset(){
  document.getElementById("submitor_contact").reset();
}
function callVerif(){
  $('#error_contact').hide();
  racine = document.getElementById('submitor_contact').racine.value;
  if (verif()) {
    goMailContact();
  }
}

function goMailContact() {
  var time_contact = null;
  racine = document.getElementById("submitor_contact").racine.value;
  $.post(
    racine+'xsltMailer.aspx',
    $("#submitor_contact").serialize(),
    function (data) {
      $('#response_contact').html(merci);
      $('#response_contact').fadeIn('slow', function() {});
      time_contact = setTimeout(function(){
        $('#contact_dialog').dialog("close");
      },4000);
    }
  );
}
 
 
function goSearchDjModal(typerubrique,rubriqueid,elementid,offset,nbrec,firstrec) {
  document.getElementById('submitor_recherche_dj').target='';
  document.getElementById('submitor_recherche_dj').typerubrique.value = typerubrique;
  document.getElementById('submitor_recherche_dj').rubriqueid.value = rubriqueid;
  document.getElementById('submitor_recherche_dj').elementid.value = elementid;
  document.getElementById('submitor_recherche_dj').offset.value = offset;
  document.getElementById('submitor_recherche_dj').nbrec.value = nbrec;
  document.getElementById('submitor_recherche_dj').firstrec.value = firstrec;
  document.getElementById('submitor_recherche_dj').submit();
} 
 
function showDialogConfirmContactAo(elementId){
  $( ".ui-dialog" ).dialog( "destroy" );
  $( "#dialog_confirm_contact_ao" ).dialog({
			resizable: false,
			height:200,
      width:445,
			modal: true,
			buttons: {
				"Confirmer": function() {
          setEnr(36,696969,1);
          go('1','36',elementId,'','','');
				},
				"Annuler": function() {
					$( this ).dialog( "close" );
				}
			}
		});
}

function highlight(nb,element){
  clearTimeout(interval_highlight);
  var interval_highlight = null;
  for(i=0;i<nb;i++){
    interval_highlight = setTimeout(function(){
      $(element).effect("highlight", {color:"#FA0F26"}, 2500);
    },3500);
    
  }
}
 
function SaveEval(idAO){
  var membreId = $('#enr4_'+idAO).val();
  
  var  reg=new  RegExp("[^\\d]*", "g"); 
  var montant = $('#enr2_'+idAO).val().replace(reg,'');
  var feedback = $('#enr3_'+idAO).val();
  var elementid = idAO;
  $.ajax({
    url: rootabs+'xslt.aspx?',
    data: $("#submitor").find("select, input, textarea").not(".noSubmit").serialize()+'&typerubrique=1&rubriqueid=666&enr2='+montant+'&enr3='+feedback+'&enr4='+membreId+'&ELEMENTID='+elementid+'&actionner=SAVEEVAL',
    type: "POST",
    success: function(response){
      if(response["ERROR"] == 1){
        $('#evalFail_'+response["AOID"]).slideDown();
      }
      else{
        $('#evalConfirm_'+response["AOID"]).slideDown(function(){
          $('#divEval_'+idAO).slideUp(2000);
          nbEvalAttente = nbEvalAttente - 1;
          $('.nbEvalAttente').html(nbEvalAttente); 
        });      
        
      }
      
    }
  });
} 

function submitQuestionnaire(element,reponseId,membreId,reponseText){
  var reponseId = reponseId;
  var questionId = $(element).prevAll('.questionHidden').first().val();
  $.ajax({
    url: rootabs+'xslt.aspx?actionner=QUESTIONNAIRE&membreid='+membreId+'&questionid='+questionId+'&reponseid='+reponseId+'&reponsetext='+reponseText,
    type: "GET",
    success: function(response){
    
      /* if(response["ERROR"] == 1){
        $('#evalFail_'+response["AOID"]).slideDown();
      }
      else{
        $('#evalConfirm_'+response["AOID"]).slideDown(function(){
          $('#divEval_'+idAO).slideUp(2000);
          nbEvalAttente = nbEvalAttente - 1;
          $('.nbEvalAttente').html(nbEvalAttente); 
        });      
        
      } */
      
    }
  });
} 


function updateAdressAjax(adresse,membreId){
  var membreId = membreId;
  var adresse_update = adresse;
  $.ajax({
    url: rootabs+'xslt.aspx?actionner=UPDATE_ADRESSE&membreid='+membreId+'&adresse_update='+adresse_update,
    type: "GET",
    success: function(response){
      goAchatFlyer();
    }
  });
} 




/*--------------------------------------------------------------------*/
/*-------------------------VERSION IMPRIMABLE-------------------------*/
/*--------------------------------------------------------------------*/

function PrintElem(elem, title)
{
  var content = "";
  $(elem).each(function(){
    content+='<'+$(this)[0].tagName+' class="'+$(this)[0].className+'">'+$(this).html()+'</'+$(this)[0].tagName+'>';
  });
  
  Popup(content, title);
}


function Popup(data,title) 
{
  var mywindow = window.open('', 'my div', 'scrollbars,toolbar=no,directories=no,height=400,width=600');
  mywindow.document.write('<html><head><title>'+title+'</title>');
  mywindow.document.write('<link rel="stylesheet" href="'+rootabs+'css/style_bandeaux.css" type="text/css" />');
  mywindow.document.write('</head><body class="noback"><div style="text-align:center;margin:15px;"><a href="'+rootabs+'xslt.aspx"><img alt="jechercheundj_logo" src="'+rootabs+'img/header_logo.gif"></a></div><div class="printed">');
  mywindow.document.write(data);
  mywindow.document.write('</div><div style="text-align:center;margin:15px;"><a href="'+rootabs+'xslt.aspx"><img alt="jechercheundj_logo" src="'+rootabs+'img/header_logo.gif"></a></div></body></html>');
  mywindow.document.close();
  mywindow.print();
  return true;
}

