
function pleinecran(url) {
  propriete = "top=0,left=0,resizable=yes, toolbar=no, scrollbars=yes, menubar=no, location=no, statusbar=no"
  propriete += ",width=" + screen.width + ",height=" + screen.height;
  win = window.open(url,"fenetre", propriete)
}


function popUpWindow(url, left, top, width, height)
{
	  
window.open(url, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=yes,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}
function format(valeur,decimal,separateur) 
{
// formate un chiffre avec 'decimal' chiffres après la virgule et un separateur
	var deci=Math.round( Math.pow(10,decimal)*(Math.abs(valeur)-Math.floor(Math.abs(valeur)))) ; 
	var val=Math.floor(Math.abs(valeur));
	if ((decimal==0)||(deci==Math.pow(10,decimal))) {val=Math.floor(Math.abs(valeur)); deci=0;}
	var val_format=val+"";
	var nb=val_format.length;
	for (var i=1;i<4;i++) 
	{
		if (val>=Math.pow(10,(3*i)))
		{
			val_format=val_format.substring(0,nb-(3*i))+separateur+val_format.substring(nb-(3*i));
		}
	}
	if (decimal>0) 
	{
		var decim=""; 
		for (var j=0;j<(decimal-deci.toString().length);j++) {decim+="0";}
		deci=decim+deci.toString();
		val_format=val_format+"."+deci;
	}
	if (parseFloat(valeur)<0) {val_format="-"+val_format;}
	return val_format;
}
function totalCFA()
{
   var montant = document.getElementById("montant").value;
   var lid = document.getElementById("devise").selectedIndex;
   var devise = document.getElementById("devise").options[lid].value;
   if(montant!=""&&devise!="")
   {
      var multi = devise.split("/")[1];
     
      var mtcfa = multi*montant;
      //alert(mtcfa);
      document.getElementById("cfamontant").value = format(mtcfa,0," ");
   }
}

function verif_nombre(champ)
{
    var chiffres = new RegExp("[0-9\.]"); /* Modifier pour : var chiffres = new RegExp("[0-9]"); */
    var verif;
    var points = 0; /* Supprimer cette ligne */

    for(x = 0; x < champ.value.length; x++)
    {
        verif = chiffres.test(champ.value.charAt(x));
        if(champ.value.charAt(x) == "."){points++;} /* Supprimer cette ligne */
        if(points > 1){verif = false; points = 1;} /* Supprimer cette ligne */
        if(verif == false){champ.value = champ.value.substr(0,x) + champ.value.substr(x+1,champ.value.length-x+1); x--;}
   }

}

function verifEspece()
{
   var text = "";
   if(champvide("montant")){ text = text+ " le montant  \n" }
   if(listeVide("devise")) { text= text+ " La devise \n";}
   if(listeVide("nature")) { text= text+ " La nature \n";}
  
   return text;
   
}
function verifIndivContrib()
{
    var msgcontrib = verifContribution();
    var msginforpers = verifInfoPers();
    var msg = msgcontrib + msginforpers;
    if(msg=='') return true;
    else
    {
      alert(msg);
      return false;
    }
}
function verifInstContrib()
{
    var msgcontrib = verifContribution();
    var msginforpers = verifInfoInst();
    var msg = msgcontrib + msginforpers;
    if(msg=='') return true;
    else
    {
      alert(msg);
      return false;
    }
}
function verifGroupContrib()
{
    var msgcontrib = verifContribution();
    var msginforpers = verifInfoGroup();
    var msg = msgcontrib + msginforpers;
    if(msg=='') return true;
    else
    {
      alert(msg);
      return false;
    }
}
function verifInfoPers()
{
   var text = "";
   if(champvide("nom")){ text = text+ " -Votre nom \n" }
   if(champvide("titre")){ text = text+ " -Votre titre \n" }
   if(champvide("prenom")) { text= text+ " -Votre prenom\n";}
   if(listeVide("pays")) { text= text+ " -Le pays \n";}
   if(text!="")
   {
       text =  "ELEMENTS INFORMATIONS PERSONNELLES NON RENSEIGNES \n"+ text;
   }
   return text;
}
function verifInfoGroup()
{
   var text = "";
   if(champvide("nom")){ text = text+ " -Le nom  \n" }
   if(champvide("pays")) { text= text+ " -le pays \n";}
   if(champvide("localite")) { text= text+ " -la localité \n";}
   
   if(text!="")
   {
       text =  "ELEMENTS INFORMATIONS GROUPE NON RENSEIGNES \n"+ text;
   }
   return text;
}
function verifInfoInst()
{
   var text = "";
   if(champvide("nom")){ text = text+ " -Le nom  \n" }
   if(champvide("pays")) { text= text+ " -le pays \n";}
   if(champvide("localite")) { text= text+ " -la localité \n";}
   
   if(text!="")
   {
       text =  "ELEMENTS INFORMATIONS INSTITUTION NON RENSEIGNES \n"+ text;
   }
   return text;
}

function verifNature()
{
   var text = "";
   if(champvide("quantite")){ text = text+ " la quantité est vide \n" }
   if(champvide("designation")) { text= text+ " La désignation est vide \n";}
   if(champvide("montantestime")) { text= text+ " Le montant estimé est vide \n";}
   return text;
}
function verifContribution()
{
    
   var type = getRadioValue() ;

   switch(type)
   {
       case '1' : var msg = verifEspece(); 
                  
                 if(msg!='') 
                  {
                     msg =  "ELEMENTS CONTRIBUTIONS NON RENSEIGNES \n"  + msg;
                    
                  }
                  return msg;
                  break;
       
       case  '2' : var msg = verifNature(); 
                  
                  if(msg!='') 
                 
                  {
                    	msg =  "ELEMENTS CONTRIBUTIONS NON RENSEIGNES \n"  + msg;
                    	
                  }
                  return msg;
                     //alert (msg);
                     //return false;
                  break;
       case '3' :var msg1 = verifEspece(); 
                 var msg2 = verifNature(); 
                 var msg = msg1 + msg2;
                  if(msg!='') 
                 
                  {
                      msg =  "ELEMENTS CONTRIBUTIONS NON RENSEIGNES \n"  + msg;
                     
                   }
                   return msg;
                  break;
         default: break;
   }

}
function ActiveChamp(Controle, Masquer) 
{

 var objControle = document.getElementById(Controle);
	if (Masquer=='1')
                {
                objControle.disabled= true;
                }

	else
                {
		objControle.disabled= false
               }

}
function ActiveContribution(critere)
{
   
     var tabespece = [];
          tabespece[0] ="montant";
          tabespece[1] ="devise"; 
          tabespece[2] ="nature"; 
          
       var tabnature = [];
          tabnature[0] ="designation";
          tabnature[1] ="quantite"; 
          tabnature[2] ="montantestime"; 
          
   switch(critere)
         {
                case '1' : 
                           { 
                                 for (var i=0;i<tabespece.length;i++) ActiveChamp(tabespece[i],'0') ;
                                 for (var i=0;i<tabnature.length;i++) ActiveChamp(tabnature[i],'1') ;
								
                              }
                             
   
                              break;

               case '2' : { 
                                 for (var i=0;i<tabnature.length;i++) ActiveChamp(tabnature[i],'0') ;
                                 for (var i=0;i<tabespece.length;i++) ActiveChamp(tabespece[i],'1') ;
                               


                              }break; 
                case '3' : { 
                                 for (var i=0;i<tabnature.length;i++) ActiveChamp(tabnature[i],'0') ;
                                 for (var i=0;i<tabespece.length;i++) ActiveChamp(tabespece[i],'0') ;
                               


                              }break;  
         }
}
function getRadioValue() 
{
   var radio = document.frmcontrib.typecontribution;
   
      for (var i=0; i<radio.length;i++) 
     {
             if (radio[i].checked) 
            {
                var retour = radio[i].value;
            }
     }
   
      return retour;
}

function listeVide(id)
{
	var lid = document.getElementById(id).selectedIndex;
	
	var val = document.getElementById(id).options[lid].value;
	if(val=="")
	{
		return true;
	}
	return false;
	
}
function champvide(id)
{
	 if(document.getElementById(id).value=='') 
	 {
	 	return true;
	 }
	 
	 else 
	 {
	 	//alert('le champ est vide');
	 	return false;
	 }
}
function verifUtilisateur2()
{
 	
	 var text="";
	 if(document.getElementById("login").value=='')
	 {
	     text=text+"-le login est vide\n";
	 }
	 else
	 {
	 	if(document.getElementById("login").value.length <6)
	 	text=text+"-le login doit ?tre au moins de 6 caracteres \n";
	 }
	
	 if(document.getElementById("nom").value=='')
	 {
	  	text=text+"-le nom est vide\n";
	 }
	 if(document.getElementById("prenom").value=='')
	 {
	  	text=text+"-le pr?nom est vide\n";
	 }
	 
	 if(document.getElementById("email").value=='')
	 {
	  	text=text+"-adresse mail est vide \n";
	 }
	 else
	 {
	 	adresse = document.getElementById("email").value;
	 	var place = adresse.indexOf("@",1);
		var point = adresse.indexOf(".",place+1);
		if ((place > -1)&&(adresse.length >2)&&(point > 1))
		{
		
		}
		else
		{
		
			text=text+"-adresse email incorrect \n";
	    }
	 }
	
	 if(text=="") 
	 {
	  	return true;
	 }
	 else
	 {
	 	alert(text);
	 	return false;
	 }
}
function verifUtilisateur()
{
 	
	 var text="";
	 if(document.getElementById("login").value=='')
	 {
	     text=text+"-le login est vide\n";
	 }
	 else
	 {
	 	if(document.getElementById("login").value.length <6)
	 	text=text+"-le login doit ?tre au moins de 6 caracteres \n";
	 }
	 if(document.getElementById("passwd").value=='')
	 { 
	 	text=text+"-le mot de passe est vide \n";
	 }
	 else
	 {
	 	if(document.getElementById("passwd").value.length <6)
	 	text=text+"-le mot de passe au moins  6 caracteres \n";
	 }
	 if(document.getElementById("nom").value=='')
	 {
	  	text=text+"-le nom est vide\n";
	 }
	 if(document.getElementById("prenom").value=='')
	 {
	  	text=text+"-le pr?nom est vide\n";
	 }
	 
	 if(document.getElementById("email").value=='')
	 {
	  	text=text+"-adresse mail est vide \n";
	 }
	 else
	 {
	 	adresse = document.getElementById("email").value;
	 	var place = adresse.indexOf("@",1);
		var point = adresse.indexOf(".",place+1);
		if ((place > -1)&&(adresse.length >2)&&(point > 1))
		{
		
		}
		else
		{
		
			text=text+"-adresse email incorrect \n";
	    }
	 }
	
	 if(text=="") 
	 {
	  	return true;
	 }
	 else
	 {
	 	alert(text);
	 	return false;
	 }
}

function Estvide(){
 var text="";
 if(document.getElementById("titre").value=='') text=text+"le titre ne peut pas être vide";
 if(text=="") //document.getElementById("form").submit(); 
 return true;
 else{
 alert(text);
 return false;
 }
 }
function jsdelete()
{
   
      var radio = document.frm.tabsup;
         alert(radio);
      var ret = 0;
      for (var i=0; i<radio.length;i++) 
     {
             if (radio[i].checked) 
            {
                 ret= ret+1;
            }
     }
     if(ret==0)
     {
         alert("Aucun élément n'est selectionné");
         return false;
     }
     else
     {
         return confirm ('Voulez vous vraiment supprimer les éléments sélectionnés?');
     }
     
}
function HeaderJS(lien)
{
	
	document.location.href=lien;
}

function Soumettre(lien,frmid)
{
	document.forms[formname].action = lien;
	document.getElementById(frmname).submit();
	
}

function ConfirmCancel(lien)
{

	if(confirm('voulez-vous vraiment annuler?'))
	{
		document.location=lien;
	}
}

function Confirmer(message,lien)
{

	if(confirm(message))
	{
		document.location=lien;
	}
}

function affiche_date()
		{
			var days=new Array(13);
			days[1]="Dimanche";
			days[2]="Lundi";
			days[3]="Mardi";
			days[4]="Mercredi";
			days[5]="Jeudi";
			days[6]="Vendredi";
			days[7]="Samedi";
			var months=new Array(13);
			months[1]="janvier";
			months[2]="f&eacute;vrier";
			months[3]="mars";
			months[4]="avril";
			months[5]="mai";
			months[6]="juin";
			months[7]="juillet";
			months[8]="août";
			months[9]="septembre";
			months[10]="octobre";
			months[11]="novembre";
			months[12]="d&eacute;cembre";
			var time=new Date();
		var ldays=days[time.getDay() + 1];
		var lmonth=months[time.getMonth() + 1];
		var date=time.getDate();
		var year=time.getFullYear();
		document.write("&nbsp;" + ldays + " " + date + " " + lmonth + " " + year + "&nbsp;&nbsp;&nbsp;");
			
		}
		//<![CDATA[

//-----------------------------------------------------------------------------
// Table Sort Demo
// Copyright 2002 by Mike Hall
// Please see http://www.brainjar.com for terms of use.
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// sortTable(id, col, rev)
//
//  id  - ID of the TABLE, TBODY, THEAD or TFOOT element to be sorted.
//  col - Index of the column to sort, 0 = first column, 1 = second column,
//        etc.
//  rev - If true, the column is sorted in reverse (descending) order
//        initially.
//
// Note: the team name column (index 1) is used as a secondary sort column and
// always sorted in ascending order.
//-----------------------------------------------------------------------------

function sortTable(id, col, rev) {

  // Get the table or table section to sort.
  var tblEl = document.getElementById(id);

  // The first time this function is called for a given table, set up an
  // array of reverse sort flags.
  if (tblEl.reverseSort == null) {
    tblEl.reverseSort = new Array();
    // Also, assume the team name column is initially sorted.
    tblEl.lastColumn = 1;
  }

  // If this column has not been sorted before, set the initial sort direction.
  if (tblEl.reverseSort[col] == null)
    tblEl.reverseSort[col] = rev;

  // If this column was the last one sorted, reverse its sort direction.
  if (col == tblEl.lastColumn)
    tblEl.reverseSort[col] = !tblEl.reverseSort[col];

  // Remember this column is the last one sorted.
  tblEl.lastColumn = col;

  // Set the table display style to "none" - necessary for Netscape 6 
  // browsers.
  var oldDsply = tblEl.style.display;
  tblEl.style.display = "none";

  // Sort the rows based on the content of the specified column using a
  // selection sort.

  var tmpEl;
  var i, j;
  var minVal, minIdx;
  var testVal;
  var cmp;

  for (i = 0; i < tblEl.rows.length - 1; i++) {

    // Assume the current row has the minimum value.
    minIdx = i;
    minVal = getTextValue(tblEl.rows[i].cells[col]);

    // Search the rows that follow the current one for a smaller value.
    for (j = i + 1; j < tblEl.rows.length; j++) {
      testVal = getTextValue(tblEl.rows[j].cells[col]);
      cmp = compareValues(minVal.toUpperCase(), testVal.toUpperCase());
      // Negate the comparison result if the reverse sort flag is set.
      if (tblEl.reverseSort[col])
        cmp = -cmp;
      // Sort by the second column (team name) if those values are equal.
      if (cmp == 0 && col != 1)
        cmp = compareValues(getTextValue(tblEl.rows[minIdx].cells[1]),
                            getTextValue(tblEl.rows[j].cells[1]));
      // If this row has a smaller value than the current minimum, remember its
      // position and update the current minimum value.
      if (cmp > 0) {
        minIdx = j;
        minVal = testVal;
      }
    }

    // By now, we have the row with the smallest value. Remove it from the
    // table and insert it before the current row.
    if (minIdx > i) {
      tmpEl = tblEl.removeChild(tblEl.rows[minIdx]);
      tblEl.insertBefore(tmpEl, tblEl.rows[i]);
    }
  }

  // Make it look pretty.
  makePretty(tblEl, col);

  // Restore the table's display style.
  tblEl.style.display = oldDsply;

  return false;
}

//-----------------------------------------------------------------------------
// Functions to get and compare values during a sort.
//-----------------------------------------------------------------------------

// This code is necessary for browsers that don't reflect the DOM constants
// (like IE).
if (document.ELEMENT_NODE == null) {
  document.ELEMENT_NODE = 1;
  document.TEXT_NODE = 3;
}

function getTextValue(el) {

  var i;
  var s;

  // Find and concatenate the values of all text nodes contained within the
  // element.
  s = "";
  for (i = 0; i < el.childNodes.length; i++)
    if (el.childNodes[i].nodeType == document.TEXT_NODE)
      s += el.childNodes[i].nodeValue;
    else if (el.childNodes[i].nodeType == document.ELEMENT_NODE &&
             el.childNodes[i].tagName == "BR")
      s += " ";
    else
      // Use recursion to get text within sub-elements.
      s += getTextValue(el.childNodes[i]);

  return normalizeString(s);
}

function compareValues(v1, v2) {

  var f1, f2;

  // If the values are numeric, convert them to floats.

  f1 = parseFloat(v1);
  f2 = parseFloat(v2);
  if (!isNaN(f1) && !isNaN(f2)) {
    v1 = f1;
    v2 = f2;
  }

  // Compare the two values.
  if (v1 == v2)
    return 0;
  if (v1 > v2)
    return 1
  return -1;
}

// Regular expressions for normalizing white space.
var whtSpEnds = new RegExp("^\\s*|\\s*$", "g");
var whtSpMult = new RegExp("\\s\\s+", "g");

function normalizeString(s) {

  s = s.replace(whtSpMult, " ");  // Collapse any multiple whites space.
  s = s.replace(whtSpEnds, "");   // Remove leading or trailing white space.

  return s;
}

//-----------------------------------------------------------------------------
// Functions to update the table appearance after a sort.
//-----------------------------------------------------------------------------

// Style class names.
var rowClsNm = "lignePair";
var colClsNm = "colonneTriee";

// Regular expressions for setting class names.
var rowTest = new RegExp(rowClsNm, "gi");
var colTest = new RegExp(colClsNm, "gi");

function makePretty(tblEl, col) {

  var i, j;
  var rowEl, cellEl;

  // Set style classes on each row to alternate their appearance.
  for (i = 0; i < tblEl.rows.length; i++) {
   rowEl = tblEl.rows[i];
   rowEl.className = rowEl.className.replace(rowTest, "");
    if (i % 2 != 0)
      rowEl.className += " " + rowClsNm;
    rowEl.className = normalizeString(rowEl.className);
    // Set style classes on each column to highlight the one that was sorted.
    for (j = 0; j < tblEl.rows[i].cells.length; j++) {
      cellEl = rowEl.cells[j];
      cellEl.className = cellEl.className.replace(colTest, "");
      if (j == col)
        cellEl.className += " " + colClsNm;
      cellEl.className = normalizeString(cellEl.className);
    }
  }

  // Find the table header and highlight the column that was sorted.
  var el = tblEl.parentNode.tHead;
  rowEl = el.rows[el.rows.length - 1];
  // Set style classes for each column as above.
  for (i = 0; i < rowEl.cells.length; i++) {
    cellEl = rowEl.cells[i];
    cellEl.className = cellEl.className.replace(colTest, "");
    // Highlight the header of the sorted column.
    if (i == col)
      cellEl.className += " " + colClsNm;
      cellEl.className = normalizeString(cellEl.className);
  }
}

//]]>
 
function popup(fichier, width, height)
{
   	ff = window.open(fichier,"popup","width="+width
        +", height="+height+", left=10, top=10, scrollbars=no, toolbar=no, menubar=no, resizable=no, location=no, directories=no, status=no");
}
 
function popup2(fichier, width, height)
{
   	ff = window.open(fichier,"popup","width="+width
        +", height="+height+", left=10, top=10, scrollbars=yes, toolbar=no, menubar=no, resizable=no, location=no, directories=no, status=no");
}
function pop()
{
    var myAs = document.getElementsByTagName('a');
    for (var a = 0; a < myAs.length; ++a) {
	// Si le lien a une classe de type pop
        if (myAs[a].className == 'pop') {
	// on extrait l'id de la popup à partir du href
            var pop = document.getElementById(myAs[a].href.substring(myAs[a].href.lastIndexOf('#') + 1));
	// si la popup existe on l'affiche (display block)
            if (pop) {       
                pop.style.display = 'none';
                myAs[a].onclick = function() {
                    thisPopup = document.getElementById(this.href.substring(this.href.lastIndexOf('#') + 1))
                    thisPopup.style.display = (thisPopup.style.display == 'none') ? 'block' : 'none';
                    return false;
                };
		// on efface la popup en cliquant dessus
                pop.onclick = function()
                {
                    this.style.display = 'none';
                };
            }
        }
    }
}
window.onload = pop;
