var popup;
var typeForm;
function checkEnter(typeF)
{
	if(document.layers){
	document.captureEvents(Event.KEYPRESS)
	}
	typeForm=typeF;
	document.onkeypress=kpress;
}
function kpress(e){
	key=(document.layers)?e.which:window.event.keyCode;
	//key2=String.fromCharCode(key);
	//alert(key);
	
if (key==13) {
	f=document.formulaire;
	//alert("aaa");
	if (typeForm=="rechercherapide"){
		f.cmd.value='affichage3';f.fonction.value='rechercherapide';f.typeaff.value='rr_acc';f.niv.value='0'
	}
	f.cmdform.value=typeForm;
	f.submit();
	}
}
function mOvr(Liste,clrOver){ 
for (i=0;i<Liste.length;i++)
{
	src=document.getElementById('modcomp'+Liste[i]);
	if (!src.contains(event.fromElement)){ 
		src.style.cursor = 'hand'
		src.className = clrOver; 
	} 	
}

} 

function mOut(Liste,clrIn){
for (i=0;i<Liste.length;i++)
{
	src=document.getElementById('modcomp'+Liste[i]);
	if (!src.contains(event.toElement)){ 
		src.style.cursor = 'default'; 						
		src.className = clrIn;
	} 
} 
}

function champok(texte1,texte2) 
  { 

   if (texte1=="") 
     { alert("Vous devez remplir le champ "+texte2+"!");
	   return false;
	 }
	 return true;
  }
  
function Selectionner(f,check,nb,bool)
{
for (i=0;i<nb;i++)
	{
		z=eval(f+"."+check+i);
		z.checked=bool;
	}	
}

function launchCenter(url, name, width, height, scrollb,params,bpop) {
  //alert(scrollb);
  var str="";

//alert(ie);

  if (scrollb==1) str="scrollbars=yes,";
  str += "height=" + height + ",innerHeight=" + height;
  str += ",width=" + width + ",innerWidth=" + width;
  if (params!="") str+=params;
  //alert(str);
  if (window.screen) {
    var ah = screen.availHeight - 30;
    var aw = screen.availWidth - 10;

    var xc = (aw - width) / 2;
    var yc = (ah - height) / 2;

    str += ",left=" + xc + ",screenX=" + xc;
    str += ",top=" + yc + ",screenY=" + yc;
  }
  //alert(str);
  if (popup && bpop!=1)
  {popup.close();
  }
   popup=window.open(url, name, str);
  return ;
}

function chercherSelection(f,check,nb)
{
	str="";
	for (i=0;i<nb;i++)
	{
		//alert("dedans");
		//alert(f+"."+check+i+".value");
		z=eval(f+"."+check+i);
		//alert(z);
		if (z.checked==true)
		{
			if (str=="") 
				{
				str=z.value;
				}
			else
				{
				 str+=","+z.value;	
				}
		}
	}
return str;
}
function chercherNbSelection(f,check,nb)
{
	nbsel=0;
	for (i=0;i<nb;i++)
	{
		z=eval(f+"."+check+i);
		if (z.checked==true)
		{
			nbsel++;
		}
	}
return nbsel;
}

function chercherNotSelection(f,check,nb)
{
	str="";
	for (i=0;i<nb;i++)
	{
		z=eval(f+"."+check+i);
		if (z.checked==false)
		{
			if (str=="") 
				{
				str=z.value;
				}
			else
				{
				 str+=","+z.value;	
				}
		}
	}
return str;
}
function chercherTousSelection(f,check,nb)
{
	str="";
	for (i=0;i<nb;i++)
	{
		z=eval(f+"."+check+i);
			if (str=="") 
				{
				str=z.value;
				}
			else
				{
				 str+=","+z.value;	
				}

	}
return str;
}
function toutSelectionner(f, check,nb)
{
for (i=0;i<nb;i++)
	{
		z=eval(f+"."+check+i);
		z.checked=true;
	}	
}
function goWysiwyg(ctrlName,lg,ht)
{
	agent = navigator.userAgent.toLowerCase();
	if (agent.indexOf("msie")!=-1)
	{	
		if (popup) {popup.close();}
			//popup=window.open('../inc/Wysiwyg.php?field='+ctrlName,'_blank','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=522,height=250');
			launchCenter('../inc/Wysiwyg.php?lg=500&field='+ctrlName+'&lg='+lg+'&ht='+ht, '_blank', lg, ht, 1,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes');
	}
	else
	{
		alert('Le module de mise en page n\'est disponible que sur Internet Explorer 5.x');
	}
	
	
}	

function dateok(unedate,datetxt)
{
	if (datetxt=='') datetxt="date";
	if (!isDate(unedate))
	{
		alert("La "+datetxt+" n'est pas valide !! \n Exemple de format valide : 01/06/2004");
		return false;
	}
	else
	{
		return true;
	}
}
function dateok2(unedate,datetxt)
{
	if (datetxt=='') datetxt="date";
	if (!isDate(unedate))
	{
		//alert("La "+datetxt+" n'est pas valide !! \n Exemple de format valide : 02/02/2001");
		return false;
	}
	else
	{
		return true;
	}
}
function isNum(vid)
{
  var num=parseFloat(vid);
  return !isNaN(num);
}
function isDate(vid)
{
	if (vid.length!=10 && vid.length!=8 && vid.length!=14 && vid.length!=16 && vid.length!=17 && vid.length!=19) return false;
	//*** test date (jj/mm/yyyy ou jj/mm/yy)
	if (vid.charAt(2)!='/' || vid.charAt(5)!='/') return false;
	if (!isNum(vid.substring(0,2)) || !isNum(vid.substring(3,5)) || !isNum(vid.substring(6,10))) return false;
	if (vid.substring(0,1)=="0")
		day=parseInt(vid.substring(1,2));
	else
		day=parseInt(vid.substring(0,2));
		
	if (vid.substring(3,4)=="0")
		month=parseInt(vid.substring(4,5));
	else
		month=parseInt(vid.substring(3,5));
			
	if (day<1||day>31) return false;
	if (month<1||month>12) return false;
	if (vid.length==10)
	{
		year=parseInt(vid.substring(6,10));
		if (year<1900||year>2030) return false;
	}
	else
	{
		year=parseInt(vid.substring(6,8));
		if (year<0||year>100) return false;
		if (year<30) 
			year=year+2000;
		else
			year=year+1900;
	}
	//*****test time (hh:mm)
	if (vid.length==14 || vid.length==16 || vid.length==17 || vid.length==19)
	{
		if (vid.length==14 || vid.length==17)
			temps=vid.substring(9,14);
		else
			temps=vid.substring(11,16);
		hour=parseInt(temps.substring(0,2));
		minute=parseInt(temps.substring(3,5));
		if (hour<0 || hour>23) return false;
		if (minute<0 || minute>59) return false;
	}
	
	return (year*365+(month*30)+day);
}

function Modif()
{
	document.form1.cache.value='1';
}

function gererValidation(bAlert)
{
	cache=eval(document.form1.cache);
	
if (typeof (cache)=="object")
{
	if (cache.value=='1')
		{
			if (bAlert)
			{
			alert("Vous devez préalablement valider votre saisie!");
			return false;
			}
		else
		{
			return confirm("Des modifications sont en cours sur cet écran. Etes vous sûr de vouloir le quitter?");	
		}
		
		}
	else
		{
		return true;
		}
}
else
	{return true}
}   

function doubleGo(p1,p2)
{
	parent.menu.location.href=p1;
	parent.main.location.href=p2;
}

function replacetxt(txt,ch1,ch2)
{
	while (txt.match(ch1))
		{
		txt=txt.replace(ch1,ch2);
		}
	return txt;	
}

/*function gererValidation()
{
	//alert("aaa");
	cache=eval(document.formulaire.cache);
	//alert(typeof (cache));
	
	if (typeof (cache)=="object")
	{
		//alert(cache.value);
		if (cache.value=='1')
			{
			return confirm("Des modifications sont en cours sur cet écran. Etes vous sûr de vouloir le quitter?");	
			}
		else
			{
			return true;
			}
	}
	else
		{return true}
}*/

function aller(page,nopage,nopage1,id)
{
	if (gererValidation())
	{
		//alert("toto");
		document.location.href=page+".php?nopage="+nopage+"&nopage_etude="+nopage1+"&id_etude="+id;
	}
}