function correctPNG(){
   for(var i=0; i<document.images.length; i++){
	 var img = document.images[i]
	 var imgName = img.src.toUpperCase()
	 if (imgName.substring(imgName.length-3, imgName.length) == "PNG"){
	   var imgID = (img.id) ? "id='" + img.id + "' " : ""
	   var imgClass = (img.className) ? "class='" + img.className + "' " : ""
	   var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
	   var imgStyle = "display:inline-block;" + img.style.cssText
	   if (img.align == "left") imgStyle = "float:left;" + imgStyle
	   if (img.align == "right") imgStyle = "float:right;" + imgStyle
	   if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
	   var strNewHTML = "<span " + imgID + imgClass + imgTitle
	   + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
		+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
	   + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
	   img.outerHTML = strNewHTML
	   i = i-1
	 }
   }
   /////  This part handles background png's (Koen Betsens)
   for(i=0;i<document.all.length;i++){
	  bg=document.all[i].currentStyle.backgroundImage;
	  if(bg.toUpperCase().substr(bg.length-5,3)=='PNG'){
		 if(bg.search('%20')>0){bg=bg.replace('%20',' ')}
		 document.all[i].style.backgroundImage='none';
		 document.all[i].style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale src='"+bg.substr(5,bg.length-7)+"')"
	  }
   }
}

if (window.attachEvent) {
	window.attachEvent("onload", correctPNG);
}

function destroy(id)
{
  var obj = (dom) ? document.getElementById(id) : document.all[id];

  while(obj.hasChildNodes() == true)
   {
	obj.removeChild(obj.childNodes[0]);
   }  
}

function getRandomNum(lbound, ubound) {
	return (Math.floor(Math.random() * (ubound - lbound)) + lbound);
}

function getRandomChar() {
	var charSet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	return charSet.charAt(getRandomNum(0, charSet.length));
}

function getUID() {
	var rc = "";
	for (var idx = 1; idx < 10; ++idx) {
		rc = rc + getRandomChar();
	}
	return rc;
}

/*function event(elem, handler, funct) {
if(document.all)
	elem[handler] = new Function(funct);
else
	elem.setAttribute(handler,funct);
}*/

/**
    Fonctions MM_
    
*/

function MM_showHideLayers() { //v6.0
  var i,p,v,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; }
    obj.visibility=v; }
}

function MM_findObj(n, d) { //v4.0
  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 && document.getElementById) x=document.getElementById(n); return x;
}

var MM_str_org="'Personne','','R','DateDebut','','RdateF','DateFin','','RdateF'";
var MM_str_v='';
var MM_str_v_array=new Array();


function MMM_vf(){
	MM_str=MM_str_org/*+MM_str_v*/;
	//alert(MM_str);return false;
	eval("MM_validateForm("+MM_str+");");
	return document.MM_returnValue;
}

function MM_validateForm() { //v5.0
  var i,p,q,nm,pswd,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { 
  	test=args[i+2]; 
	val=MM_findObj(args[i]); 
	val2=MM_findObj(args[i+1]);
	valchk=args[i];
    if (val) { 
		nm=val.name; 
		if ((val=val.value)!="") {
			if (test.indexOf('isEmail')!=-1) { 
				if (!echeck(val)) errors+='- Le champ '+nm+' doit contenir une adresse e-mail correcte.\n';
      		} 
			else if(test.indexOf('chk')!=-1){
				p=test.indexOf(':');
				f=test.indexOf('|');
				form=test.substring(f+1);
				
				damin=test.substring(4,p);
				damax=test.substring(p+1,f);
				tmpcpt=0;

				if(!isNaN(document.forms[''+form+''].elements[''+valchk+''].length)){
					for (var y=0;y<document.forms[''+form+''].elements[''+valchk+''].length;y++){
						if(document.forms[''+form+''].elements[''+valchk+''][y].checked) {
							tmpcpt++;
						}
					}
				}
				else if(document.forms[''+form+''].elements[''+valchk+''].checked) tmpcpt++;

				
				if(tmpcpt<damin || (tmpcpt>damax && damax>0)){
					if(damax==0) errors+='- Vous devez cocher au moins '+damin+' cases pour le champ '+valchk+'.\n';
					else if(damin==0 ) errors+='- Vous devez cocher au plus '+damax+' cases pour le champ '+valchk+'.\n';
					else errors+='- Vous devez cocher entre '+damin+' et '+damax+' cases pour le champ '+valchk+'.\n';
				}
				
			}
			else if (test.indexOf('same') != -1 && val2) {

				if (val2.value=="") errors += '- Le champ '+val2.name+' est obligatoire.\n'; 
				else if (val2.value!=val) errors += '- Les champs '+nm+' et '+val2.name+' doivent être identiques.\n'; 
			}
			else if (test.indexOf('dateF') != -1){
				 myarraydate=val.split("/");
				 thisDate=new Date();
				 if(myarraydate.length!=3 || isNaN(myarraydate[0]) || isNaN(myarraydate[1]) || isNaN(myarraydate[2]) || myarraydate[2].length!=4 || !checkDate(myarraydate[0],myarraydate[1],myarraydate[2])) errors += '- Le champ '+nm+' doit contenir une date valide au format JJ/MM/AAAA.\n'; 
			}
			else if (test.indexOf('dateE') != -1){
				 myarraydate=val.split("/");
				 thisDate=new Date();
				 if(myarraydate.length!=3 || isNaN(myarraydate[0]) || isNaN(myarraydate[1]) || isNaN(myarraydate[2]) || myarraydate[0].length!=4 || !checkDate(myarraydate[2],myarraydate[1],myarraydate[0])) errors += '- Le champ '+nm+' doit contenir une date valide au format AAAA/MM/JJ.\n'; 
			}
			else if(test.indexOf('mini') != -1 ){
				if(val.length<test.substring(test.indexOf('mini')+4)) errors+='- Le champ '+nm+' doit contenir au moins '+test.substring(test.indexOf('mini')+4)+' caractères.\n';
			}
			else if (test!='R') {
				
        		if (isNaN(val)) errors+='- Le champ '+nm+' doit contenir un nombre.\n';
        		if (test.indexOf('inRange') != -1) { 
					p=test.indexOf(':');
          			min=test.substring(8,p);
					max=test.substring(p+1);
          			if (val<min || max<val) errors+='- Le champ '+nm+' doit être un nombre entre '+min+' et '+max+'.\n';
    			}
			}
			
			/*if(test.indexOf('mini') != -1 ){
				if(val.length<test.substring(test.indexOf('mini')+4)) errors+='- Le champ '+nm+' doit contenir au moins '+test.substring(test.indexOf('mini')+4)+' caractères.\n';
			}*/
		}
		else if (val2 && test.charAt(0) == 'R' && test.indexOf('same') != -1) {
			if(val=="" && val2.value=="") errors += '- Les champs '+nm+' et '+val2.name+' sont obligatoires.\n'; 
			else if (val=="") errors += '- Le champ '+nm+' est obligatoire.\n'; 
			if(!(val=="" && val2.value=="")&&test.indexOf('mini') != -1 ){
				if(val2.value.length<test.substring(test.indexOf('mini')+4)) errors+='- Le champ '+val2.name+' doit contenir au moins '+test.substring(test.indexOf('mini')+4)+' caractères.\n';
			}
		}
		else if (val2&&val2.value=="" && test.charAt(0) == 'R') errors += '- L\'un des champs '+nm+' et '+val2.name+' est obligatoire.\n'; 
		else if (!val2 && test.charAt(0) == 'R') errors += '- Le champ '+nm+' est obligatoire.\n'; 
		
	}
	else if(test.indexOf('chk')!=-1){
				p=test.indexOf(':');
				f=test.indexOf('|');
				form=test.substring(f+1);
				
				damin=test.substring(4,p);
				damax=test.substring(p+1,f);
				tmpcpt=0;
				for (var y=0;y<document.forms[''+form+''].elements.length;y++){
					if(document.forms[''+form+''].elements[y].name==''+valchk+'' && document.forms[''+form+''].elements[y].checked) {
						tmpcpt++;
					}
				}

				
				if(tmpcpt<damin || (tmpcpt>damax && damax>0)){
					if(damax==0) errors+='- Vous devez cocher au moins '+damin+' cases pour le champ '+valchk+'.\n';
					else if(damin==0 ) errors+='- Vous devez cocher au plus '+damax+' cases pour le champ '+valchk+'.\n';
					else errors+='- Vous devez cocher entre '+damin+' et '+damax+' cases pour le champ '+valchk+'.\n';
				}
				
			}
			//else alert('12');
  } 
  if (errors) alert('Les erreurs suivantes sont apparues :\n\n'+errors);
  document.MM_returnValue = (errors == '');
}


function RefreshCreneaux(formname){

	var regen=false;
	vd1=document.forms[formname].elements['DateDebut'].value;
	vd2=document.forms[formname].elements['DateFin'].value;
	if(document.forms[formname].elements['Personne']) {
		if(formname=='addResa'){
			people=document.forms[formname].elements['Personne'].options[document.forms[formname].elements['Personne'].options.selectedIndex].value;
		}
		else if(formname=='modResa'){
			people=document.forms[formname].elements['Personne'].value;
		}
		
	}
	else people='';
	if(people!=''){
	//alert(people+document.personnechoisie);
		if(people!=document.personnechoisie) regen=true;
		document.personnechoisie=people;
		/*if(firstload) {
			regen=true;
			document.personnechoisie=<?=$personneChoisie?>;
		}*/
		if(vd1!='' && vd2!=''){
			
			arrD1=vd1.split("/");
			var d1=new Date(arrD1[2],(arrD1[1]-1),arrD1[0]);
			arrD2=vd2.split("/");
			var d2=new Date(arrD2[2],(arrD2[1]-1),arrD2[0]);
			if(d1.getDate() && d2.getDate()){
				if(d1<=d2){
					MM_str_v="";
					MM_str_v_array=new Array();
					// récupérer profil de la personne/periode
					getProfil(people,vd1,vd2,d1,d2,formname,regen);
					//pour des raisons de synchro call back, RefreshCreneaux est appelé dans la fonction ajax
				}
				else alert('Vous devez saisir une date de début antérieure ou égale à la date de fin');

			}
			else alert('Vous devez saisir des dates valides');
		}
		else alert('Vous devez saisir des dates de début et de fin');
	}
	else {
		//document.personnechoisie=<?=$personneChoisie?>;
		if(document.personnechoisie){
			var myDiv = (dom) ? document.getElementById('creneauxhere') : document.all['creneauxhere'];
			father=myDiv.parentNode;
			father.removeChild(myDiv);
			var myDiv2 = document.createElement('td');
			if ( agt.indexOf('msie') != -1 ) { myDiv2.setAttribute('className', 'tablevaluel'); }
			else if ( agt.indexOf('mozilla') != -1 ) { myDiv2.setAttribute('class', 'tablevaluel'); }
			myDiv2.colSpan = 2;
			myDiv2.id='creneauxhere';
			father.appendChild(myDiv2);
		}
		alert('Vous devez choisir une personne');
	}
	
}

function dayDiff(da2,da1){
	var dadiff=da2.getTime()-da1.getTime();
	var totaldays=dadiff/(1000*60*60*24);
	return totaldays;
}



function checkThis(woh,chk){
	var thisone=document.getElementById('t'+woh);
	var mychks=thisone.getElementsByTagName('input');
	for(var v=0;v<mychks.length;v++){
		mychks[v].checked=((in_array(mychks[v].value,chk))? true: false);
	}
	
}


function checkAllCreneauxForDate(formname,heidi,all){
	var chkOrNot=(all)?document.forms[formname].elements['chkall']:document.forms[formname].elements[heidi+'chkall'];
	//alert(all);
	var fieldname="creneaux"+heidi+"[]";
	var thisone=document.getElementById('t'+heidi);
	var crenals=thisone.getElementsByTagName('input');
	for(i=0;i<crenals.length;i++){
		//la ligne suivante a été ajoutée pour patcher le chckall
		/*if(all) crenals[i].checked=chkOrNot.checked ; 
		else */
		if(crenals[i].id.indexOf('chkall')==-1){
			if(!crenals[i].disabled) crenals[i].checked=((chkOrNot.checked)? true: false); 
		}
	}
}

function checkAllDateForCreneaux(formname,creneau){

	vd1=document.forms[formname].elements['DateDebut'].value;
	vd2=document.forms[formname].elements['DateFin'].value;
	arrD1=vd1.split("/");
	var d1=new Date(arrD1[2],(arrD1[1]-1),arrD1[0]);
	arrD2=vd2.split("/");
	var d2=new Date(arrD2[2],(arrD2[1]-1),arrD2[0]);
	for(var i=0;i<=dayDiff(d2,d1);i++){
		var thisdar=new Date(d1.getFullYear(),d1.getMonth(),(d1.getDate()+i));
		var strheidi=((thisdar.getDate()<10)? '0': '')+thisdar.getDate()+'-'+((thisdar.getMonth()+1<10)? '0': '')+(thisdar.getMonth()+1)+'-'+thisdar.getFullYear();
		var heidi=thisdar.getFullYear()+((thisdar.getMonth()+1<10)? '0': '')+(thisdar.getMonth()+1)+((thisdar.getDate()<10)? '0': '')+thisdar.getDate();
		//var chkOrNot=document.forms[formname].elements[heidi+'chkall'];
		
		var thisone=document.getElementById('t'+heidi);
		var crenals=thisone.getElementsByTagName('input');
		
		var chkOrNot=document.forms[formname].elements['creneau'+creneau+'chkall'];

		if(!crenals[creneau+1].disabled) crenals[creneau+1].checked=((chkOrNot.checked)? true:false); 
		
		/*
		//inversion
		var chkOrNot=crenals[creneau+1];
		chkOrNot.checked=((chkOrNot.checked)? false:true); 
		*/

	}
}

function checkAll(formname,creneaux){
	// cocher tous les créneaux
	for(i=1;i<=creneaux;i++){
		document.forms[formname].elements['creneau'+i+'chkall'].checked=((document.forms[formname].elements['chkall'].checked)? true:false);
		//checkAllDateForCreneaux(formname,i);
	}
	// puis pour chaque jour faire un checkAllCreneauxForDate
	vd1=document.forms[formname].elements['DateDebut'].value;
	vd2=document.forms[formname].elements['DateFin'].value;

	arrD1=vd1.split("/");
	var d1=new Date(arrD1[2],(arrD1[1]-1),arrD1[0]);
	arrD2=vd2.split("/");
	var d2=new Date(arrD2[2],(arrD2[1]-1),arrD2[0]);
	for(var i=0;i<dayDiff(d2,d1)+1;i++){
		var thisdar=new Date(d1.getFullYear(),d1.getMonth(),(d1.getDate()+i));
		var strheidi=((thisdar.getDate()<10)? '0': '')+thisdar.getDate()+'-'+((thisdar.getMonth()+1<10)? '0': '')+(thisdar.getMonth()+1)+'-'+thisdar.getFullYear();
		var heidi=thisdar.getFullYear()+((thisdar.getMonth()+1<10)? '0': '')+(thisdar.getMonth()+1)+((thisdar.getDate()<10)? '0': '')+thisdar.getDate();
		
		var chkOrNot=document.forms[formname].elements[heidi+'chkall'];
		
		chkOrNot.checked=((chkOrNot.checked)? false:true);
		
		//checkAllCreneauxForDate(formname,heidi,true);
		var chkOrNot=document.forms[formname].elements['chkall'];
		var fieldname="creneaux"+heidi+"[]";
		var thisone=document.getElementById('t'+heidi);
		var crenals=thisone.getElementsByTagName('input');
		for(var j=0;j<crenals.length;j++){
			if(!crenals[j].disabled){
				crenals[j].checked=chkOrNot.checked ; 
			}
		}
		
	}
	
}

function OpenDetails(formname,href){
	//window.open(href, '_blank', 'menubar=no, status=no, scrollbars=yes, menubar=no, resizable=yes, width=600, height=600');

	vd1=document.forms[formname].elements['DateDebut'].value;
	vd2=document.forms[formname].elements['DateFin'].value;

	if(vd1!='' && vd2!=''){
		arrD1=vd1.split("/");
		var d1=new Date(arrD1[2],(arrD1[1]-1),arrD1[0]);
		arrD2=vd2.split("/");
		var d2=new Date(arrD2[2],(arrD2[1]-1),arrD2[0]);
		if(d1.getDate() && d2.getDate()){
			if(d1<=d2){
				details=window.open(href+'&DateDebut='+vd1+'&DateFin='+vd2, '_blank', 'location=yes, status=no, scrollbars=yes, menubar=no, resizable=yes, width=600, height=600');
			}
			else {
				// le fichier listing.inc.php ayant été modifier pour permettre un affichage des orientations sans dates de début ni de fin, le message d'erreur n'a plus lieu d'être
				//alert('Vous devez saisir une date de début antérieure ou égale à la date de fin');	
				details=window.open(href, '_blank', 'location=yes, status=no, scrollbars=yes, menubar=no, resizable=yes, width=600, height=600');
				return(false);
			}
		}
		else {
			// le fichier listing.inc.php ayant été modifier pour permettre un affichage des orientations sans dates de début ni de fin, le message d'erreur n'a plus lieu d'être
			//alert('Vous devez saisir des dates valides');
			details=window.open(href, '_blank', 'location=yes, status=no, scrollbars=yes, menubar=no, resizable=yes, width=600, height=600');
			return(false);
		}
	}
	else {
		// le fichier listing.inc.php ayant été modifier pour permettre un affichage des orientations sans dates de début ni de fin, le message d'erreur n'a plus lieu d'être
		//alert('Vous devez saisir des dates de début et de fin');
		details=window.open(href, '_blank', 'location=yes, status=no, scrollbars=yes, menubar=no, resizable=yes, width=600, height=600');
		return(false);
	}
}

function ViewDetails(formname){
	var peopleId;
	var peopleName;
	if(document.forms[formname].elements['idPersonne']) {
		if(formname=='addResa'){
			peopleId=document.forms[formname].elements['idPersonne'].options[document.forms[formname].elements['idPersonne'].options.selectedIndex].value;
			peopleName=document.forms[formname].elements['idPersonne'].options[document.forms[formname].elements['idPersonne'].options.selectedIndex].text;	
		}
		else if(formname=='modResa'){
			peopleId=document.forms[formname].elements['idPersonne'].value;
			peopleName=document.forms[formname].elements['nomPersonne'].value;
		}
	}
	
	linkdetails='<a href="viewdetails.php?ID='+peopleId+'" onclick="OpenDetails(\''+formname+'\',this.href);return(false);">'+peopleName+'</a>';
	document.getElementById('viewDetails').innerHTML = linkdetails;
}


function getXhr(){
					var xhr = null; 
	if(window.XMLHttpRequest) // Firefox et autres
	   xhr = new XMLHttpRequest(); 
	else if(window.ActiveXObject){ // Internet Explorer 
	   try {
				xhr = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
	}
	else { // XMLHttpRequest non supporté par le navigateur 
	   alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
	   xhr = false; 
	} 
					return xhr;
}

/**
* Méthode qui sera appelée sur dans RefreshCreneaux
*/
function getProfil(idRefPersonne,dateDebut,dateFin,d1,d2,formname,regen){
	var xhr = getXhr();
	// On défini ce qu'on va faire quand on aura la réponse
	xhr.onreadystatechange = function(){
		// On ne fait quelque chose que si on a tout reçu et que le serveur est ok
		if(xhr.readyState == 4 && xhr.status == 200){
			/*leselect = xhr.responseText;
			// On se sert de innerHTML pour rajouter les options a la liste
			document.getElementById('personne').innerHTML = leselect;*/
			
			// ICI LA VARIABLE EST BIEN DEFINIE MAIS PARAIT NE PAS ETRE GLOBALE
			profilPersonne=xhr.responseText;
			//alert(profilPersonne);
			//return profilPersonne;
			displayCreneaux(d1,dayDiff(d2,d1),formname,regen);
			for(i=0;i<MM_str_v_array.length;i++){
				MM_str_v+=","+MM_str_v_array[i];
			}
		}
	}

	// Ici on va voir comment faire du post
	xhr.open("POST","ajaxPeriode.php",true);
	// ne pas oublier ça pour le post
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	// ne pas oublier de poster les arguments
	// ici, l'id de l'auteur
	/*sel = document.getElementById('lettre');
	lettre = sel.options[sel.selectedIndex].value;*/
	xhr.send("idRefPersonne="+idRefPersonne+"&DateDebut="+dateDebut+"&DateFin="+dateFin);
}

/**
* Méthode qui sera appelée sur le click de la lettre
*/
function go(lettre,formname){
	var xhr = getXhr();
	// On défini ce qu'on va faire quand on aura la réponse
	xhr.onreadystatechange = function(){
		// On ne fait quelque chose que si on a tout reçu et que le serveur est ok
		if(xhr.readyState == 4 && xhr.status == 200){
			leselect = xhr.responseText;
			// On se sert de innerHTML pour rajouter les options a la liste
			document.getElementById('personne').innerHTML = leselect;
		}
	}

	// Ici on va voir comment faire du post
	xhr.open("POST","ajaxPersonne.php",true);
	// ne pas oublier ça pour le post
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	// ne pas oublier de poster les arguments
	// ici, l'id de l'auteur
	/*sel = document.getElementById('lettre');
	lettre = sel.options[sel.selectedIndex].value;*/
	xhr.send("formname="+formname+"&lettre="+lettre);
}

function openRedirect(n){
	var hauteur=680;
	var largeur=600;
 var top=(screen.height-hauteur)/2;
  var left=(screen.width-largeur)/2;
 /*  var top=80;
  var left=20;*/
window.open('', n, "resizable=1,scrollbars=1,LEFT="+left+",TOP="+top+",HEIGHT="+hauteur+",WIDTH="+largeur+"");
}

function DateF2DateE(str){
	if(str!=''){
		arr=str.split('-');
		arr2=str.split('/');
		farr=((arr.length>1)? arr: arr2);
		return ((farr.length>2)? farr[2]+'-': '')+farr[1]+'-'+farr[0]+((farr.length>2)? '': '-01');
	}
	else return null;
}

function m2d(str,d){

	if(str!=''){
		arr=str.split('-');
		arr2=str.split('/');
		farr=((arr.length>1)? arr: arr2);
		return ((d=='d')? farr[1]+'-'+farr[0]+'-01': farr[1]+'-'+farr[0]+'-31');
	}
	else return null;
}

function is_array(variable) {
   //var source = variable.toString();
   if(variable.length!='undefined'){
		return true;
   }
   else return false;
   /*
   var source = variable.toSource();
   return (source.search(/^\[([^,]*,)+[^,]*\]/) != -1);
   */
}

function in_array(stringToSearch, arrayToSearch) {
	for (s = 0; s < arrayToSearch.length; s++) {
		thisEntry = arrayToSearch[s].toString();
		if (thisEntry == stringToSearch) {
			return true;
		}
	}
	return false;
}

function masqueSaisieChaineNum(obj, masque) {
  var ch = obj.value
  var tmp = ""
  var j = 0
  ch.toString()
  
  if (window.event.keyCode != 37 && window.event.keyCode != 39 && window.event.type != "keydown" && window.event.keyCode != 8 && window.event.keyCode != 46) {
    if (window.event.type == "keyup") {
      for (i=0; i<ch.length; i++) {
        if (!isNaN(ch.charAt(i)) && ch.charAt(i) != " ") { tmp += ch.charAt(i) }
      }
  
      ch = ""
  
      for (i=0; i<masque.length; i++) {
        if (masque.charAt(i)  == "0") { 
          if (tmp.charAt(j) != "" ) {
            ch += tmp.charAt(j)
            j++
          }
          else { ch += " " }
        }
        else { ch += masque.charAt(i) }
      }
    }
  
    obj.value = ch
  }
}


function checkDate(myDayStr,myMonthStr,myYearStr) {
 
months=new Array;
months['01']='Jan';
months['02']='Feb';
months['03']='Mar';
months['04']='Apr';
months['05']='May';
months['06']='Jun';
months['07']='Jul';
months['08']='Aug';
months['09']='Sep';
months['10']='Oct';
months['11']='Nov';
months['12']='Dec';
if(months[myMonthStr]) {
//if(myDayStr.charAt('0')==0) myDayStr=myDayStr.substring(1);
var myDateStr = myDayStr + ' ' + months[myMonthStr] + ' ' + myYearStr + ' ' +'12:00:00';


/* Using form values, create a new date object
which looks like "Wed Jan 1 00:00:00 EST 1975". */
var myDate = new Date( myDateStr );
// Convert the date to a string so we can parse it.
var myDate_string = myDate.toGMTString();


/* Split the string at every space and put the values into an array so,
using the previous example, the first element in the array is "Wed", the
second element is "Jan", the third element is "1", etc. */
var myDate_array = myDate_string.split( ' ' );


/* If we entered "Feb 31, 1975" in the form, the "new Date()" function
converts the value to "Mar 3, 1975". Therefore, we compare the month
in the array with the month we entered into the form. If they match,
then the date is valid, otherwise, the date is NOT valid. */
if ( myDate_array[2] != months[myMonthStr] ) {
  return false;
} else {
  return true;
}
}
else return false;
}
 


function echeck(str) { 
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   return false
	}


	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false
	}


	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false
	}


	 if (str.indexOf(at,(lat+1))!=-1){
		return false

	 }


	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false
	 }


	 if (str.indexOf(dot,(lat+2))==-1){
		return false
	 }
	
	 if (str.indexOf(" ")!=-1){
		return false
	 }


	 return true					
}




function CreerMenu(profondeur,titre1,titre2,titre3,titre4,target) {
        this.nb=0;this.prof=profondeur;
        this.titre1=titre1; this.titre2=titre2; this.titre3=titre3; this.titre4=titre4; this.target=target
        this.Add=AddObjet;
        this.Aff1=AffMenu1;
        this.Aff2=AffMenu2;
        this.Aff3=AffMenu3;
}
function AddObjet(deep,txt,page,rID) {
        var rub = new Object;
        rub.deep=deep;
        rub.txt=txt;
        rub.page=page;
		rub.rID=rID
        this[this.nb]=rub;
        this.nb++;
}


// Affiche le premier select
function AffMenu1() {
        var Z="<OPTION selected>"+this.titre1+"</OPTION>";
        for (var i=0;i<this.nb;i++) {
                if (this[i].deep==1) {
                        Z+="<OPTION value='"+i+"'>"+this[i].txt+"</OPTION>"
                }
        }
        document.write(Z);
}


// Affiche le second select
function AffMenu2() {
        var Z="<OPTION>"+eval("menu.titre2")+"</OPTION><OPTION></OPTION><OPTION></OPTION><OPTION></OPTION><OPTION></OPTION><OPTION></OPTION>";
        document.write(Z);
}


// Affiche le troisième select
function AffMenu3() {
        var Z="<OPTION>"+eval("menu.titre3")+"</OPTION><OPTION></OPTION><OPTION></OPTION><OPTION></OPTION><OPTION></OPTION><OPTION></OPTION>";
        document.write(Z);
}


function add() {
        var c=new Option("ADD","",true,true);
        document.forms[0].elements["list"].options[0]=c;
}
function Clic(no) {
        var valeur=document.forms["mf"].elements["list"+no].options[ document.forms["mf"].elements["list"+no].selectedIndex].value;
		if ((valeur!="")&&(valeur!=null)&&(no<menu.prof)) {
                var deep=menu[valeur].deep;
                var no2=1;
                for (var noX=(no+1);noX<=menu.prof;noX++) {
                        document.forms["mf"].elements["list"+eval(noX)].options.length=0;
                        var titre=eval("menu.titre"+noX);
                        var c=new Option(titre);
                        document.forms["mf"].elements["list"+(noX)].options[0]=c;
                        document.forms["mf"].elements["list"+(noX)].selectedIndex=0;
                }
                valeur++;
                for (var i=valeur;i<menu.nb;i++) {
                        //alert(i);
                        if (menu[i].deep==deep+1) {
                                //alert("no="+no+" texte="+menu[i].txt);
                                var c=new Option(menu[i].txt,i);
                                document.forms["mf"].elements["list"+(no+1)].options[no2]=c;
                                no2++;
                        } else { if (menu[i].deep==deep){i=menu.nb;}}
                }
                document.forms["mf"].elements["list"+(no+1)].options.length=no2+1;
                document.forms["mf"].elements["list"+(no+1)].selectedIndex=0;
                Clic(no+1)
                valeur--;
        }
        if ((valeur!="")&&(valeur!=null)) {
                var page=menu[valeur].page;
                if ((page!="")&&(page!=null)) {
                        if (menu.target=="self") {window.location=page}
                        else if (menu.target=="_blank") {window.open(page,"","menubar,scrollbars,toolbar,status,location")}
                        else {parent.frames[menu.target].location.href=page;}
                }
        }
}
// Fonctions destinées à afficher l'arborescence du menu
function space(i) {var Z="";for (var j=0;j<i;j++){Z+="&nbsp;&nbsp;&nbsp;&nbsp;";}return Z}
function Arbo(m) {
        var Z="<BR>";
        for (var i=0;i<m.nb;i++) {
                Z+=space(m[i].deep)+m[i].txt+"&nbsp;&nbsp; <A href='"+m[i].page+"'>"+m[i].page+"</A><BR>"
        }
        document.write(Z);
}


// Fonction qui affiche tous éléments sélectionnés
function Affichetout(l)
        {
        var listecomplete="";
        if (l.options.length!=0)
                {

                for(var i=0; i<l.options.length; i++)
                                {
                                if(l.options[i].value != "")
                                        {
										tmpr1=l.options[i].value;
										if (tmpr1.substring(0,3) !="org") {
											listecomplete=listecomplete+tmpr1;
										}
										else {
											listecomplete=listecomplete+tmpr1.substring(3,tmpr1.length)
										}
                                        if(i!=l.options.length-1)         listecomplete=listecomplete+",";
                                        }
                                }
                document.mf.listef.value=listecomplete;
                }
        else
                {
                alert("Vous devez sélectionner au moins un poste");
                }
        }


// Fonction qui permet le transfert ou le retrait d'une liste à l'autre
function Deplacer(l1,l2,l3,lresult,sens,stock)
        {
        if (sens==1)
                {
                if (l3.options.selectedIndex>=0)
                        {
                        var metier=l1.options[l1.options.selectedIndex].text;
                        var competence=l2.options[l2.options.selectedIndex].text;
                        for(var i=0; i<l3.options.length; i++)
                                {
                                if (l3.options[i].value==0)
                                        {
                                        }
                                else
                                        {
                                        if(l3.options[i].selected && l3.options[i].value != "")
                                                {
                                                var no = new Option();
                                                no.value = l3.options[i].value;
                                                stock.value=menu[l3.options[i].value].rID;
                                               // stock.value=stock.value+",";
                                                no.text = metier+" / "+competence+" / "+l3.options[i].text;
                                                lresult.options[lresult.options.length] = no;
                                                }

                                        }
                                }
                        }
                else
                        {
                        alert("Aucune catégorie sélectionnée.");
                        }
                }
        else
                {
                if (lresult.options.selectedIndex>=0)
                        {
                        for(var i=0; i<lresult.options.length; i++)
                                {
                                if(lresult.options[i].selected && lresult.options[i].value != "")
                                        {
										var r1val=lresult.options[i].value;


										if (r1val.substring(0,3) !='org') {
                                        stock.value=stock.value+menu[lresult.options[i].value].rID;
										}
										else {
										stock.value=stock.value+r1val.substring(3,r1val.length);
										}
                                        stock.value=stock.value+",";
                                        lresult.options[i]=null;
                                        }
                                }
                        }
                else
                        {
                        alert("Aucune catégorie sélectionnée.");
                        }
                }
        }


function Deplacer_Simple(listfrom,listto,type,sens,withmenu) {
                if (listfrom.options.selectedIndex>=0)
                        {
                        for(var i=0; i<listfrom.options.length; i++)
                                {
                                if (listfrom.options[i].value=='')
                                        {
                                        }
                                else
                                        {
                                        if(listfrom.options[i].selected && listfrom.options[i].value != "")
                                                {
												if(type=='select') {
													var no = new Option();
													no.value = listfrom.options[i].value;
													no.text = listfrom.options[i].text;
													if(sens==1){
														no.selected=true;
													}
													listto.options[listto.options.length] = no;
													listfrom.options[i]=null;
												}
												else if(type=='texte') {
													if(withmenu=='') listto.value=listfrom.options[i].value;
													else {
														mymenu=eval(withmenu);
														listto.value=mymenu[listfrom.options[i].value].rID;
													}
												}
                                                }
                                        }
                                }
                        }
                else
                        {
                        alert("Aucune sélection");
                        }
 }

function DeplacerFromTo(listfrom,listto,sens) {
                if (listfrom.options.selectedIndex>=0)
                        {
                        for(var i=0; i<listfrom.options.length; i++)
                                {
                                if (listfrom.options[i].value=='')
                                        {
                                        }
                                else
                                        {
                                        if(listfrom.options[i].selected && listfrom.options[i].value != "")
                                                {
                                                var no = new Option();
                                                no.value = listfrom.options[i].value;
                                                no.text = listfrom.options[i].text;
												if(sens==1){
													no.selected=true;
												}
                                                listto.options[listto.options.length] = no;
												listfrom.options[i]=null;
                                                }
                                        }
                                }
                        }
                else
                        {
                        alert("Aucune sélection");
                        }
 }
 
 
 /**
    Created by: Michael Synovic
    on: 01/12/2003
   
    This is a Javascript implementation of the Java Hashtable object.
   
    Contructor(s):
     Hashtable()
              Creates a new, empty hashtable
   
    Method(s):
     void clear()
              Clears this hashtable so that it contains no keys.
     boolean containsKey(String key)
              Tests if the specified object is a key in this hashtable.
     boolean containsValue(Object value)
              Returns true if this Hashtable maps one or more keys to this value.
     Object get(String key)
              Returns the value to which the specified key is mapped in this hashtable.
     boolean isEmpty()
              Tests if this hashtable maps no keys to values.
     Array keys()
              Returns an array of the keys in this hashtable.
     void put(String key, Object value)
              Maps the specified key to the specified value in this hashtable. A NullPointerException is thrown is the key or value is null.
     Object remove(String key)
              Removes the key (and its corresponding value) from this hashtable. Returns the value of the key that was removed
     int size()
              Returns the number of keys in this hashtable.
     String toString()
              Returns a string representation of this Hashtable object in the form of a set of entries, enclosed in braces and separated by the ASCII characters ", " (comma and space).
     Array values()
              Returns a array view of the values contained in this Hashtable.
           
*/
function Hashtable(){
    this.clear = hashtable_clear;
    this.containsKey = hashtable_containsKey;
    this.containsValue = hashtable_containsValue;
    this.get = hashtable_get;
    this.isEmpty = hashtable_isEmpty;
    this.keys = hashtable_keys;
    this.put = hashtable_put;
    this.remove = hashtable_remove;
    this.size = hashtable_size;
    this.toString = hashtable_toString;
    this.values = hashtable_values;
    this.hashtable = new Array();
}

/*=======Private methods for internal use only========*/

function hashtable_clear(){
    this.hashtable = new Array();
}

function hashtable_containsKey(key){
    var exists = false;
    for (var i in this.hashtable) {
        if (i == key && this.hashtable[i] != null) {
            exists = true;
            break;
        }
    }
    return exists;
}

function hashtable_containsValue(value){
    var contains = false;
    if (value != null) {
        for (var i in this.hashtable) {
            if (this.hashtable[i] == value) {
                contains = true;
                break;
            }
        }
    }
    return contains;
}

function hashtable_get(key){
    return this.hashtable[key];
}

function hashtable_isEmpty(){
    return (parseInt(this.size()) == 0) ? true : false;
}

function hashtable_keys(){
    var keys = new Array();
    for (var i in this.hashtable) {
        if (this.hashtable[i] != null)
            keys.push(i);
    }
    return keys;
}

function hashtable_put(key, value){
    if (key == null || value == null) {
        throw "NullPointerException {" + key + "},{" + value + "}";
    }else{
        this.hashtable[key] = value;
    }
}

function hashtable_remove(key){
    var rtn = this.hashtable[key];
    this.hashtable[key] = null;
    return rtn;
}

function hashtable_size(){
    var size = 0;
    for (var i in this.hashtable) {
        if (this.hashtable[i] != null)
            size ++;
    }
    return size;
}

function hashtable_toString(){
    var result = "";
    for (var i in this.hashtable)
    {     
        if (this.hashtable[i] != null)
            result += "{" + i + "},{" + this.hashtable[i] + "}\n";  
    }
    return result;
}

function hashtable_values(){
    var values = new Array();
    for (var i in this.hashtable) {
        if (this.hashtable[i] != null)
            values.push(this.hashtable[i]);
    }
    return values;
}
