function MM_goToURL() {
  var i, args=MM_goToURL.arguments;
  document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2)
  	eval(args[i]+".location='"+args[i+1]+"'");
}

function view_onglet_tableau(nom_onglet) {
document.getElementById('onglet_c01').className = (nom_onglet == 'tb_performances' ? 'onglet-enabled-fond' : 'onglet-disabled-fond');
document.getElementById('onglet_c02').className = (nom_onglet == 'tb_statuts' ? 'onglet-enabled-fond' : 'onglet-disabled-fond');
document.getElementById('onglet_c03').className = (nom_onglet == 'tb_detail' ? 'onglet-enabled-fond' : 'onglet-disabled-fond');
document.getElementById('tb_performances').style.visibility = (nom_onglet == 'tb_performances' ? 'visible' : 'hidden');
document.getElementById('tb_statuts').style.visibility = (nom_onglet == 'tb_statuts' ? 'visible' : 'hidden');
document.getElementById('tb_detail').style.visibility = (nom_onglet == 'tb_detail' ? 'visible' : 'hidden');
parent.document.getElementById('frame_tableau_bord').height = document.getElementById(nom_onglet).offsetHeight + 70; /* Hauteur approximative de la hauteur du menu */
}

function view_onglet_demarches(nom_onglet) {
document.getElementById('onglet_c01').className = (nom_onglet == 'tb_journal' ? 'onglet-enabled-fond' : 'onglet-disabled-fond');
document.getElementById('onglet_c02').className = (nom_onglet == 'tb_processus' ? 'onglet-enabled-fond' : 'onglet-disabled-fond');
document.getElementById('onglet_c03').className = (nom_onglet == 'tb_rens' ? 'onglet-enabled-fond' : 'onglet-disabled-fond');
document.getElementById('onglet_c04').className = (nom_onglet == 'tb_propos' ? 'onglet-enabled-fond' : 'onglet-disabled-fond');
document.getElementById('onglet_c05').className = (nom_onglet == 'tb_doc' ? 'onglet-enabled-fond' : 'onglet-disabled-fond');
// document.getElementById('onglet_c06').className = (nom_onglet == 'tb_part' ? 'onglet-enabled-fond' : 'onglet-disabled-fond');
document.getElementById('tb_journal').style.visibility = (nom_onglet == 'tb_journal' ? 'visible' : 'hidden');
document.getElementById('tb_processus').style.visibility = (nom_onglet == 'tb_processus' ? 'visible' : 'hidden');
document.getElementById('tb_rens').style.visibility = (nom_onglet == 'tb_rens' ? 'visible' : 'hidden');
document.getElementById('tb_propos').style.visibility = (nom_onglet == 'tb_propos' ? 'visible' : 'hidden');
document.getElementById('tb_doc').style.visibility = (nom_onglet == 'tb_doc' ? 'visible' : 'hidden');
// document.getElementById('tb_part').style.visibility = (nom_onglet == 'tb_part' ? 'visible' : 'hidden');
parent.document.getElementById('frame_demarches').height = document.getElementById(nom_onglet).offsetHeight + 70; /* Hauteur approximative de la hauteur du menu */
// si onglet processus, on redimmenssione les liens entre cellules
if (nom_onglet == "tb_processus") {	initLienEntreCellules(); }
}

function noFn() {

}

var Compteur = null;
var CompteurTourne = false;

function DemarreHorloge () {
  if(CompteurTourne)
	clearTimeout(Compteur);
  CompteurTourne = false;
  AfficheTemps();
  }

function AfficheTemps () {
  var Temps = new Date();
  var TempsLocal = Temps.getTime()+ (Temps.getTimezoneOffset()-60)*60;
  var Maintenant = new Date(TempsLocal);
  var Heure = " " + Maintenant.getHours();
  var minutes = Maintenant.getMinutes();
  var secondes = Maintenant.getSeconds();
  Heure += ((minutes < 10) ? " H 0" : " H ") + minutes;
//  Heure += ((secondes < 10) ? ":0" : ":") + secondes;
  if (document.getElementById('heure')) {
	document.getElementById('heure').innerHTML = Heure;
  }
/*
  var AujourdHui = " " + Maintenant.getDate();
  var Mois = Maintenant.getMonth()+1;
  var Annee = Maintenant.getYear();
  AujourdHui += "/" + Mois + "/" + Annee;
  document.Horloge.FenetreDate.value = AujourdHui;
*/
  Compteur = setTimeout("AfficheTemps()",1000);
  CompteurTourne = true;
  }

// -------------- valider_imprimer() -------------- 
function valider_imprimer() {
	etat = document.getElementById('listetat').value;

	MM_goToURL('parent',chemin+'cock_index.asp?action=imprimer&etat='+etat);
}

// -------------- valider_message() -------------- 
function valider_message() {
	mesg = document.getElementById('listmesg').value;

	MM_goToURL('parent',chemin+'cock_index.asp?action=courrier&mesg='+mesg);
}

function MM_callJS(jsStr) { //v2.0
  return eval(jsStr);
}

// -------------- retour_index() -------------- 
function retour_index() {
  window.location = "cock_index.asp";
  window.location.reload(true);
}

// -------------- imprimer() -------------- 
function imprimer(_etat) {
if (_etat == "global") {
	alert('Fonction en cours de développement');
}
else {
	alert('Vous pourrez bientôt imprimer l\'état "'+_etat+'".');
}
}

// -------------- selectEtat() -------------- 
function selectEtat(_action) {
_etat = (_etat != '' ? _etat : document.getElementById('listetat').value);
_url = 'cock_index.asp?action='+ _action + '&etat=' + _etat;
document.location = _url;
}

// -------------- selectChoix() -------------- 
function selectChoix(_action) {
_url = 'cock_index.asp?action='+ _action;
document.location = _url;
}

function selectChoix_new(_entete,_action,_menu) {
_url = _entete+'index.asp?menu='+_menu+'&action='+_action;
document.location = _url;
}

// -------------- selectMsg() -------------- 
function selectMesg(_mesg,_menu) {
_mesg = (_mesg != '' ? _mesg : document.getElementById('listmesg').value);
_url = 'cock_index.asp?menu='+_menu+'&action=message&etat=' + _mesg;
document.location = _url;
}

// -------------- selectLastNews() -------------- 
function selectLastNews(_news) {
document.getElementById('form_histo_depuis').value = _news;
document.getElementById('lastnews').submit();
}

function ecrireA(_cli,_destin) {
_url = 'cock_index.asp?action=message';
_url += '&etat=destinataire';
_url += '&id_cdestin=' + _destin;
_url += '&' + _cli;
top.document.location = _url;
}

// -------------- resizePopUp() -------------- 
function resizePopUp(flagResize, largeur, maxHauteur) {
if (flagResize == 1) 
{
	var h = document.getElementById("footer").offsetTop;
	if (h > maxHauteur) {
		h = maxHauteur;
	}
	var posX=(screen.width / 2) - (largeur / 2); 
	var posY=(screen.height / 2) - (h / 2);

	window.resizeTo(largeur, h+30);
	window.moveTo(posX, posY);
}
}

function delay(gap){ /* gap is in millisecs */
	var then,now; then=new Date().getTime();
	now=then;
	while((now-then)<gap)
		{now=new Date().getTime();}
}

function GoToPage(nopage) {
history.go(nopage);
}

function DebugGetHauteur() {
	_elt = null;
	while (_elt==null) {_elt = document.getElementById("balise")};
	var h = 0;
	while (h != _elt.offsetTop) {
		h = _elt.offsetTop;
		delay(500);
		}
	document.write(h);
}

function decimal(nbre,decim) {
	x=nbre.replace(',','.');
	d=Math.pow(10,decim)+'' ;
	x=Math.round(x*d)/d+'';
	if(x.indexOf('.')<0 && d>1) x = x+'.0';
	for(i=0;i<d.length;i++)
	if((x.length-x.indexOf('.'))<d.length) x = x+'0'; 
//x=x.replace('.',',');
	return x;
	}

function validateDate( strValue ) {
/************************************************
DESCRIPTION: Validates that a string contains only
    valid dates with 2 digit month, 2 digit day,
    4 digit year. Date separator can be ., -, or /.
    Uses combination of regular expressions and
    string parsing to validate date.
    Ex. dd/mm/yyyy or dd-mm-yyyy or dd.mm.yyyy

PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.

REMARKS:
   Avoids some of the limitations of the Date.parse()
   method such as the date separator character.
*************************************************/
  var objRegExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/
 
  //check to see if in correct format
  if(!objRegExp.test(strValue))
  	return false; //doesn't match pattern, bad date
  else{
    var strSeparator = strValue.substring(2,3) 
    var arrayDate = strValue.split(strSeparator); 
    //create a lookup for months not equal to Feb.
    var arrayLookup = { '01' : 31,'03' : 31, 
                        '04' : 30,'05' : 31,
                        '06' : 30,'07' : 31,
                        '08' : 31,'09' : 30,
                        '10' : 31,'11' : 30,'12' : 31}
    var intDay = parseInt(arrayDate[0],10); 

    //check if month value and day value agree
    if(arrayLookup[arrayDate[1]] != null) {
      if(intDay <= arrayLookup[arrayDate[1]] && intDay != 0)
        return true; //found in lookup table, good date
    }
    
    //check for February 
    var intMonth = parseInt(arrayDate[1],10);
    if (intMonth == 2) { 
       var intYear = parseInt(arrayDate[2]);
       if (intDay > 0 && intDay < 29) {
           return true;
       }
       else if (intDay == 29) {
         if ((intYear % 4 == 0) && (intYear % 100 != 0) || 
             (intYear % 400 == 0)) {
              // year div by 4 and ((not div by 100) or div by 400) -> ok
             return true;
         }   
       }
    }
  }  
  return false; //any other values, bad date
}