// Boite à outils javascripts pour les formulaires
function select_horaire(jour) {
	poste=ajout.type.value;		
	if ( poste.substr(0,4) == "NUIT" ) {		
			ajout.hdeb.value = "00:00";
			ajout.hfin.value = "08:00";
	} else {
		switch(jour){
		case 1 :				
			if ( poste.substr(0,2) == "CS" ) {		
				ajout.hdeb.value = "18:00";
				ajout.hfin.value = "23:00";
			} else {
				ajout.hdeb.value = "17:30";
				ajout.hfin.value = "22:30";
			}
			break;
		case 2 :				
			if ( poste.substr(0,2) == "CS" ) {		
				ajout.hdeb.value = "18:00";
				ajout.hfin.value = "23:00";
			} else {
				ajout.hdeb.value = "17:30";
				ajout.hfin.value = "22:30";
			}
			break;
		case 3 :				
			if ( poste.substr(0,2) == "CS" ) {		
				ajout.hdeb.value = "18:00";
				ajout.hfin.value = "23:00";
			} else {
				ajout.hdeb.value = "17:30";
				ajout.hfin.value = "22:30";
			}
			break;
		case 4 :				
			if ( poste.substr(0,2) == "CS" ) {		
				ajout.hdeb.value = "18:00";
				ajout.hfin.value = "23:00";
			} else {
				ajout.hdeb.value = "17:30";
				ajout.hfin.value = "22:30";
			}
			break;
		case 5 :		
			if ( poste.substr(0,2) == "CS" ) {
				ajout.hdeb.value = "19:00";
				ajout.hfin.value = "00:00";
			} else {
				ajout.hdeb.value = "17:30";
				ajout.hfin.value = "00:00";
			}
			break;
		case 6 :		
			if ( poste.substr(0,2) == "CS" ) {
				ajout.hdeb.value = "14:00";
				ajout.hfin.value = "00:00";
			} else {
				ajout.hdeb.value = "08:00";
				ajout.hfin.value = "00:00";
			}
			break;
		case 7 :		
			if ( poste.substr(0,2) == "CS" ) {
				ajout.hdeb.value = "12:00";
				ajout.hfin.value = "23:00";
			} else {
				ajout.hdeb.value = "08:00";
				ajout.hfin.value = "23:00";
			}
			break;		
		}
	}
}

function Filtre(mois,annee,semaine) {		
  if ( semaine == '' ) {
   filtres.action="?mois="+mois+"&annee="+annee;
  } else {					
	 filtres.action="?semaine="+semaine+"&mois="+mois+"&annee="+annee;
  }	
	filtres.submit();
}

function FiltreAct(annee,mois,jour,act) {							
	filtres.action="?annee="+annee+"&mois="+mois+"&jour="+jour+"&action="+act;	
	filtres.submit();
}

function open_cr(poste_id,mode) {
  if ( mode == 0 ) {
    url="modules/cr.php?id="+poste_id;
  } else {
    url="../pdf/scripts/cr.php?id="+poste_id;
  }  
  window.open(url, '', 'height=890, width=850, top=10, left=100, toolbar=no, menubar=no, location=no, resizable=no, scrollbars=auto, status=no');
}

function submit_form(script,action,id) {
  cr.action = "../db/"+script+"?action="+action+"&id="+id;
  cr.submit();
}


function HeureCheckEJS()
{
	krucial = new Date;
	heure = krucial.getHours();
	min = krucial.getMinutes();
	sec = krucial.getSeconds();	
	jour = krucial.getDate();
	mois = krucial.getMonth()+1;
	annee = krucial.getFullYear();
	if (sec < 10)
		sec0 = "0";
	else
		sec0 = "";
	if (min < 10)
		min0 = "0";
	else
		min0 = "";
	if (sec < 10)
		sec0 = "0";
	else
		sec0 = "";
	if (heure < 10)
		heure0 = "0";
	else
		heure0 = "";	
	DinaHeure = jour + "/" + mois + "/" + annee + "  " + heure0 + heure + ":" + min0 + min + ":" + sec0 + sec;
	which = DinaHeure
	if (document.getElementById){
		document.getElementById("ejs_heure").innerHTML=which;
	}
	setTimeout("HeureCheckEJS()", 1000)
}

function open_user() {  
  url="modules/user.php";  
  window.open(url, '', 'height=600, width=620, top=10, left=100, toolbar=no, menubar=no, location=no, resizable=no, scrollbars=auto, status=no');
}

function open_reg() {  
  url="regulation.html";  
  window.open(url, '', 'height=1000, width=1050, top=0, left=0, toolbar=no, menubar=no, location=no, resizable=no, scrollbars=auto, status=no');
}

// Fonction de "http://www.pbdr.com/vbtips/asp/JavaNumberValid.htm"
function is_numeric( strString )
//  check for valid numeric strings	
{
	var strValidChars = "0123456789.-";
	var strChar;
	var blnResult = true;

	if (strString.length == 0) return false;
	
		//  test strString consists of valid characters listed above
		for (i = 0; i < strString.length && blnResult == true; i++)
		{
			strChar = strString.charAt(i);
			
			if (strValidChars.indexOf(strChar) == -1)
			{
				blnResult = false;
			}
		}

		return blnResult;
}

function DateInt()
{
	var now = new Date();

		var h = now.getHours();
	        var m = now.getMinutes();
       		var s = now.getSeconds();
				
	return ( h * 60 * 60 ) + ( m * 60 ) + s;
}

function sleep( intTime )
{
	if( !is_numeric( intTime ) )
	{
		return;  // Arret de l'éxecution
	}
		
	intTime = ( intTime / 1000 );
	var Exp = DateInt() + intTime; // TimeOut
		
		while( Exp > DateInt() )
		{
			;
		}
}
