/* permet d'afficher le dropdant liste dans le boton autre portail */

function show_div()
{
    if(document.getElementById("divNewsession").style.display=="none")

        document.getElementById("divNewsession").style.display="block";

    else
        document.getElementById("divNewsession").style.display="none";
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,d,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { 
    	obj=obj.style; 
    	v=(v=='show')?'visible':(v=='hide')?'hidden':v;
    	d=(v=='hidden')?'none':'block'; 
    }
    obj.visibility=v;
    obj.display=d;  
  }
}

function P7_hideDiv(evt) { //v1.3 by PVII
 var b,relT,mT=false; 
 if(document.layers){b=evt.target;if(b.p7aHide){
  b.visibility="hidden";}else{routeEvent(evt);}
 }else if(document.all&&!window.opera){b=event.srcElement;
  while(b!=null){if(b.tagName=="DIV" && b.p7ahD){mT=true;break;}b=b.parentElement;}
  if(!b.contains(event.toElement)){b.style.visibility="hidden";}
 }else if(document.getElementById){b=evt.currentTarget;relT=evt.relatedTarget;
  while(relT!=null){if(b==relT){mT=true;break;}
  relT=relT.parentNode;}if(!mT){b.style.visibility="hidden";}}
}

function P7_autoHide() { //v1.3 by PVII
 var i,g,args=P7_autoHide.arguments;
 for(i=0;i<args.length;i++){if((g=MM_findObj(args[i]))!=null){
  g.p7aHide=true;if(document.layers){
  g.captureEvents(Event.MOUSEOUT);}g.onmouseout=P7_hideDiv;g.p7ahD=true;}}
}

/************************************* pour la page de recherche afficher le popup ********************************************/

function showListCode()
{
 document.getElementById("listCode").style.visibility='visible';
}

function closePopup()
{
 document.getElementById("listCode").style.visibility='hidden';
}

function insertCode(codeValue)
{ 
  document.getElementById("listCode").style.visibility='hidden';
  document.forms("searchAdherentForm").all("codeNafSearch").value= codeValue;

  
}
function showDescription(valueId, nameAction)
{
  window.location.href="../"+nameAction+"="+valueId;
}


/******************* calculer le nombre de resultat **********************/
function countTableRows()
{
if (document.getElementById("tableListResult"))
{
	var rows=document.getElementById("tableListResult").rows.length-2;
	document.getElementById("nbResult").innerText =rows+" réponses";
}
}

/************* change de couleur de ligne************/
function mouseOverColor(element)
{
element.className="showRowSelected" ;
}

function mouseOutColor(element, colorCurrent)
{
  element.className=colorCurrent;
}
/**************************************************************/
/*                     tri les colonne                        */
/**************************************************************/

function ov(_o,_tf)
{
  if(_tf)_o.className="header2";
  else _o.className="header1";
}
function stripHTML(_str)
{
  if(!_str)return;

  var _str2;
  var _reg=/<.*?>/gi;
  while(_str.match(_reg)!=null)
  {
    _str=_str.replace(_reg,"");
  }
  return _str;
}
function bubbleSort(_a,c,_ud,_isNumber)
{
  for(var i=0;i<_a.length;i++)
  {
    for(var j=i;j<_a.length;j++)
    {
      var _left=stripHTML(_a[i][c]);
      var _right=stripHTML(_a[j][c]);
      var _sign=_ud?">":"<";
      var _yes=false;
      if(_isNumber)
      {
         if(_ud && (parseInt(_left)-parseInt(_right)>0))_yes=true;
         if(!_ud && (parseInt(_left)-parseInt(_right)<0))_yes=true;
      }
      else
      {
        if(_ud && _left.toLowerCase() > _right.toLowerCase())_yes=true;
        if(!_ud && _left.toLowerCase() < _right.toLowerCase())_yes=true;
      }
      if(_yes)
      {
        /* swap rows */
        for(var x=0;x<_a[i].length;x++)
        {
          var _t=_a[i][x];
          _a[i][x]=_a[j][x];
          _a[j][x]=_t;
        }
      }
    }
  }
  return _a;
}
var lastSort=null;
function sortNow(_c,_isNumber)
{
  var _a=new Array();
  var _o=null;
  var _i=0;
  while(_o=document.getElementById("g"+_i))
  {
    _a[_i]=new Array();
    var _j=0;
    while(_p=document.getElementById("h"+_i+"_"+_j))
    {
      _a[_i][_j]=_p.innerHTML;
      _j++;
    }
    _i++;
  }
  _a=bubbleSort(_a,_c,lastSort!=_c,_isNumber);
  for(var b=0;b<_a.length;b++)
  {
    for(var c=0;c<_a[b].length;c++)
    {
      document.getElementById("h"+b+"_"+c).innerHTML=_a[b][c];
    }
  }
  if(lastSort!=_c)
    lastSort=_c;
  else
    lastSort=null;
}

// ****************************************
// Writes in a layer
// Compatibility : IE 4, Netscape 4
// Usage: usage: writeInLayer('targetLayer','text to write')
// ****************************************
function writeInLayer(layerID,content)	{
	x = MM_findObj(layerID);
	if (document.layers)	{
		x.document.open();
		x.document.write(content);
		x.document.close();
	} else {
		x.innerHTML = content;
	}
}


function displayTableValue(texte, nbCharMax) {
	var	output = texte;
	if (texte.length > nbCharMax)
		output = texte.substring(0, nbCharMax-1) + "...";
	document.write(output);
}


/* Cette fonction vérifie la cohérence des mots de passe saisis 			*/
/* Attention : ne fonctionne qu'avec des champs portant les identifiants 	*/
/* "mbPwdEmail2" et "mbPwdEmailConfirm"										*/
function checkPasswd() {
	var pass1 = MM_findObj("mbPwdEmail2", this.document);
	var pass2 = MM_findObj("mbPwdEmailConfirm", this.document);
	if ((pass1.value != pass2.value)) {
		alert(unescape("Une erreur a %E9t%E9 d%E9tect%E9e dans la validation du mot de passe"));
		pass1.value = "";
		pass2.value = "";
	}
}

/***************************************************************
* SCRIPT PERMETTANT DE VERIFIER LA VALIDITE D'UNE DATE
****************************************************************/

/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
	return true
}

/****Version francaise de la verification de la date*****/
function isDate_fr(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	//var strMonth=dtStr.substring(0,pos1)
	//var strDay=dtStr.substring(pos1+1,pos2)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		//alert(unescape("Le format de la date devrait %EAtre : jj/mm/aaaa"))
		alert(unescape("Le format de date attendu est: jj/mm/aaaa \n\n Merci de corriger svp"))
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Veuillez entrer un mois valide svp")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Veuillez entrer un jour valide svp")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert(unescape("Veuillez entrer une ann%E9e %E0 4 chiffres svp entre " + minYear + " et " + maxYear))
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Veuillez entrer une date valide svp")
		return false
	}
	return true
}

//On suppose que la date entrée a été validée auparavant
//au format dd/mm/yyyy
function getDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	//var strMonth=dtStr.substring(0,pos1)
	//var strDay=dtStr.substring(pos1+1,pos2)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
		     
	d = new Date();
	d.setDate(day);
	d.setMonth(month);
	d.setFullYear(year); 
	return d;  
}

//Retorune:
//   0 si date_1=date_2
//   1 si date_1>date_2
//  -1 si date_1<date_2	  
function compare(date_1, date_2){
  diff = date_1.getTime()-date_2.getTime();
  return (diff==0?diff:diff/Math.abs(diff));
}

function compare_bis(Date1,Date2) {
	//var Date1=new Date(DateTo);
	//var Date2=new Date(DateFrom);
		
	if(Date1.getYear()<Date2.getYear())
	{
	// alert("Date 2 year greater"+Date1.getYear()+Date2.getYear());
	return true;
	}
	if(Date1.getYear()>Date2.getYear())
	{
	// alert("Date 1 year greater"+Date1.getYear()+Date2.getYear());
	return false;
	}
	
	var month1 = (Date1.getMonth()!=0) ? Date1.getMonth() : 12;
	var month2 = (Date2.getMonth()!=0) ? Date2.getMonth() : 12;
	
	if(month1 < month2)
	{
	 //alert("Date 1 Month lesser "+ month1 + " than " + month2);
		return true;
	}
	if(month1 > month2)
	{
	 //alert("Date 1 Month greater "+month1 + " than " + month2);
	return false;
	}
	if(Date1.getDate()<=Date2.getDate())
	{
	// alert("Date 2 Day greater or equal"+Date1.getDate()+Date2.getDate());
		return true;
	}
	// alert("Date 1 Day greater"+Date1.getDate()+Date2.getDate());
	return false;
}

/************************* AJAX : validation de l'existance d'un email ******************************/
function AJAXInteraction(url, callback) {
    var req = init();
    req.onreadystatechange = processRequest;
        
    function init() {
      if (window.XMLHttpRequest) {
        return new XMLHttpRequest();
      } else if (window.ActiveXObject) {
        return new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
    
    function processRequest () {
      // readyState of 4 signifies request is complete
      if (req.readyState == 4) {
		// status of 200 signifies sucessful HTTP call
        if (req.status == 200) {
          if (callback) callback(req.responseText);
        }
      }
    }

    this.doGet = function() {
      // make a HTTP GET request to the URL asynchronously
      req.open("GET", url, true);       
      req.send(null);
    }
}

function validateUserMail() {	
    var target = document.getElementById("mbLoginEmail2");
    var mbId = document.getElementById("mbId"); 
    var url = "../retrieveAjaxAction.do?mail=" + encodeURIComponent(target.value) + "&mbId=" + mbId.value;
    
    var ajax = new AJAXInteraction(url, validateCallback); 
    ajax.doGet(); 
}

function validateUserMail_bis(targetId) {	
    var target = document.getElementById(targetId);
    //var mbId = document.getElementById("mbId"); 
    var url = "../retrieveAjaxAction.do?mail=" + encodeURIComponent(target.value); // + "&mbId=" + mbId.value;
    
    var ajax = new AJAXInteraction(url, validateCallback); 
    ajax.doGet(); 
}

function validateCallback(responseText) {  
  //var msg = responseXML.getElementsByTagName("valid")[0].firstChild.nodeValue;	
 
   if (responseText == "false") {
		/*
       var mdiv = document.getElementById("userIdMessage");

       // set the style on the div to invalid

       mdiv.className = "bp_invalid";
       mdiv.innerHTML = "Invalid User Id";
       var submitBtn = document.getElementById("submit_btn");
       submitBtn.disabled = true;
       */      
    } else {
    	alert(unescape("Un membre poss%E8de d%E9j%E0 cet email. \n\n Veuillez renseigner un autre email svp."));
    	
    	//document.getElementById("mbLoginEmail2").value="";
		
		/*
       var mdiv = document.getElementById("userIdMessage");

       // set the style on the div to valid

       mdiv.className = "bp_valid";
       mdiv.innerHTML = "Valid User Id";
       var submitBtn = document.getElementById("submit_btn");
       submitBtn.disabled = false;
       */
    }  
} 

function setMessageAlertModification() {
	document.getElementById("alertModif").innerText = "N'oubliez pas d'enregistrer la fiche!!";
	//window.location = "#alertModifAnchor";
}

/**************************************************
 Retourne la date courante sous format jj/mm/aaaa
**************************************************/
function getCurrentDate() {
	var d =  new Date();
	var annee = d.getFullYear();
	var mois = d.getMonth() + 1;
	var jour = d.getDate();
			
	jour = (jour.toString().length==2) ? jour : "0" + jour;
	mois = (mois.toString().length==2) ? mois : "0" + mois;
	
	var result = jour + "/" + mois + "/" + annee;
	return result; 
}

/*** redefinir de le style de page maison apm et conseil administration ****/
function reSizeIframe()
{
 	//var parentWin = document.parentWindow.parent.location.href;
 	var parentWin = window.parent.location.href; 	
 
	 if (parentWin.indexOf("Extranet")> 0 || parentWin.indexOf("Intranet")> 0)
	 {
	   document.getElementById("body_backImg").id="pageContent";
	 
	   document.getElementById("divScroll").style.height="596px";
	 
	    if (document.getElementById("trLienRetour"))
		 {
		   document.getElementById("trLienRetour").style.visibility="hidden";
		 }
	 }
	 else
	 {
	     if (document.getElementById("trLienRetour"))
		 {
		   document.getElementById("trLienRetour").style.visibility="visible";
		 }
	 }
 }
 
 /***************************************************************/
/*          afficher une doc regarde apm                       */
/***************************************************************/
function showRegardeApm()
{
 var chemin = window.location.href;
 var indexChemin = chemin.indexOf("#");
 var numberDoc = chemin.substring(chemin.indexOf('#')+1);
  document.getElementById(numberDoc+"div").style.visibility = "visible";
  document.getElementById(numberDoc+"div").style.valign = "top";  
}

function rien() {
		}
		
		
function fixDisplayTable(id, withLinker){
	var table = document.getElementById(id);
	if(table == null || table.getElementsByTagName("tr") == null) return;
    var rows = table.getElementsByTagName("tr");
    for (i=1; i < rows.length; i++) {
        var columns = rows[i].getElementsByTagName("td");
	    rows[i].onmouseover = function(){this.style.cursor="pointer";mouseOverColor(this)};
	    if(i%2==0)
        	rows[i].onmouseout = function(){this.style.cursor="";mouseOutColor(this,'bloc_pair');};
        else
        	rows[i].onmouseout = function(){this.style.cursor="";mouseOutColor(this,'bloc_impair');};
  
  		if(withLinker){
  			var linkerTd = columns[columns.length-1];
		  	var linker = linkerTd.getElementsByTagName("a");
		   	rows[i].onclick = function() {
				var linker = this.getElementsByTagName("td")[0].getElementsByTagName("a");
		    	eval(linker[0].href);
			}				    	
		}
    }
}

/************************************
Aide a la saisie de date
*************************************/
function aideSaisieDate(champId) {
	 var dateStr = document.getElementById(champId).value;
	 if(dateStr != null) {
	 	if((dateStr.length==2 && dateStr.indexOf("/")!=1) || (dateStr.length==5))
	 		document.getElementById(champId).value = dateStr + "/";
	 }
}

/* Fermeture d'un popup div*/
function closeDiv(divId) {
	document.getElementById(divId).style.display="none";
}

/* Ouverture d'un popup div*/
function showDiv(divId) {
	document.getElementById(divId).style.display="block";
}


/*************************************
* Ouvre une fenetre en le recentrant
**************************************/
function wopen(url, name, w, h) {
	  // Fudge factors for window decoration space.
	  // In my tests these work well on all platforms & browsers.
	  w += 32;
	  h += 96;
	  wleft = (screen.width - w) / 2;
	  wtop = (screen.height - h) / 2;
	  // IE5 and other old browsers might allow a window that is
	  // partially offscreen or wider than the screen. Fix that.
	  // (Newer browsers fix this for us, but let's be thorough.)
	  if (wleft < 0) {
	    w = screen.width;
	    wleft = 0;
	  }
	  if (wtop < 0) {
	    h = screen.height;
	    wtop = 0;
	  }
	  var win = window.open(url,
	    name,
	    'width=' + w + ', height=' + h + ', ' +
	    'left=' + wleft + ', top=' + wtop + ', ' +
	    'location=no, menubar=no, ' +
	    'status=no, toolbar=no, scrollbars=no, resizable=no');
	  // Just in case width and height are ignored
	  win.resizeTo(w, h);
	  // Just in case left and top are ignored
	  win.moveTo(wleft, wtop);
	  win.focus();
}

function showClub(clubId) {
	window.location = "../clubDescription/show.do?clubId=" + clubId;
}
