function GEI(id){
	return document.getElementById(id);
}
function init(){
	if(window.Event){
		document.captureEvents(Event.MOUSEMOVE);
	}
	document.onmousemove=getXY;
}
var posX='';
var posY='';
function getXY(e){
	x=(window.Event)?e.pageX:event.clientX;
	y=(window.Event)?e.pageY:event.clientY;
	posX=x;
	posY=y;
}
function setLiWidth(times){
	GEI('sitemap').onmouseover='';/*clear event, once is enough*/
	var ul=GEI('ulholder2').getElementsByTagName('ul');
	var lis=ul[0].getElementsByTagName('li');
	var W=0;
	for(var i=0;i<lis.length;i++){
		if(lis[i].offsetWidth>W){
			W=lis[i].offsetWidth;
		}
	}
	/*
	We want to have three columns, so we give the container div three times the li's width plus 30(depends on CSS) as a total padding.
	For some reason, IE needs to multiply width by 4 to make three columns...
	*/
	GEI('ulholder1').style.width=(W*times+30)+'px'
	for(var i=0;i<lis.length;i++){
		lis[i].style.width=W+'px';
	}
}
/*
Wait for the whole document to be loaded, then add an onMouseOver event to the sitemap button that will reorganise the menu, so that it looks good
The reason we do not automaticaly reorganize on page load is that the menu elements are initialy at style.display:none; and therefor have no width;
which causes a problem with the scripts that takes to longest width and applies it to everything else. Applying a width of 0 to everything is bad...
*/
window.onload=function(){
	init();
	GEI('sitemap').onmouseover=function(){
		if(document.all){
			/*
			Internet Explorer requires a short interval between the MouseOver and the start of the script,
			presumably because IE dosn't get out of style.display:none; as fast as other browsers which,
			if we don't wait, puts every width to 0 since no width exists at the time
			*/
			setTimeout("setLiWidth(4)", 50);
		}else{
			setLiWidth(3);
		}
	}
}
function createAJAX(){
	try{
		/*Opera 8.0+, Firefox, Safari*/
		AJAX=new XMLHttpRequest();
	}catch(e){
		/*Internet Explorer Browsers*/
		try{
			AJAX=new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
				AJAX=new ActiveXObject("Microsoft.XMLHTTP");
			}catch(e){
				return false;
			}
		}
	}
	return AJAX;
}
function login(tab){
	var AJAX=createAJAX();
	if(AJAX){
		status=AJAX.onreadystatechange=function(){
			if(AJAX.readyState==4){
				GEI('ade').innerHTML=AJAX.responseText;
			}
		};
		var url="../php/connsub.php?i=1&q="+tab;
		AJAX.open("GET", url, true);
		AJAX.send(null);
		showLoading();
	}else{
		/*...*/
	}
}
function logout(){
	var AJAX=createAJAX();
	if(AJAX){
		status=AJAX.onreadystatechange=function(){
			if(AJAX.readyState==4){
				GEI('ade').innerHTML=AJAX.responseText;
			}
		};
		var url="../php/login.php?i=1";
		AJAX.open("GET", url, true);
		AJAX.send(null);
		showLoading();
	}else{
		/*...*/
	}
}
function gotos(tab){
	var query='';
	if(tab=='calendar'){
		query=window.location.toString();
		query=query.substr(query.indexOf('?'));
		query=query.replace('?','&');
		query=query.replace(/(#.*)$/,'');
	}
	var AJAX=createAJAX();
	if(AJAX){
		status=AJAX.onreadystatechange=function(){
			if(AJAX.readyState==4){
				GEI('ade').innerHTML=AJAX.responseText;
			}
		};
		var url="../php/"+tab+".php?i=1"+query;
		AJAX.open("GET", url, true);
		AJAX.send(null);
		showLoading();
	}else{
		/*...*/
	}
}
function getActInfo(id){
	var AJAX=createAJAX();
	if(AJAX){
		status=AJAX.onreadystatechange=function(){
			if(AJAX.readyState==4){
				GEI('ade').innerHTML=AJAX.responseText;
			}
		};
		var url="../php/getacts.php?i=1&id="+id;
		AJAX.open("GET", url, true);
		AJAX.send(null);
		showLoading();
	}else{
		/*...*/
	}
}
function modAct(id){
	var AJAX=createAJAX();
	if(AJAX){
		status=AJAX.onreadystatechange=function(){
			if(AJAX.readyState==4){
				GEI('ade').innerHTML=AJAX.responseText;
			}
		};
		var url="../php/admact.php?i=1&id="+id;
		AJAX.open("GET", url, true);
		AJAX.send(null);
		showLoading();
	}else{
		/*...*/
	}
}
function delAct(id){
	if(confirm("Voulez-vous vraiment effacer cette activité? Cette action est irréversible.")){
		var AJAX=createAJAX();
		if(AJAX){
			status=AJAX.onreadystatechange=function(){
				if(AJAX.readyState==4){
					GEI('ade').innerHTML=AJAX.responseText;
				}
			};
			var url="../php/addact.php?i=1&del=1&id="+id;
			AJAX.open("GET", url, true);
			AJAX.send(null);
			showLoading();
		}else{
			/*...*/
		}
	}
}
function toggleannee(Obj){
	var setTo='';
	if(Obj.value=="2"){setTo='disabled';}
	GEI('annee').disabled=setTo;
}
function togglepass(Obj){
	if(Obj.checked==''){
		GEI('password').disabled="disabled";
		GEI('cpassword').disabled="disabled";
	}else{
		GEI('password').disabled='';
		GEI('cpassword').disabled='';
	}
}
function validatesub(Obj){
	errs=0;
	for(i=0;i<Obj.length;i++){
		if(!/^f_/.test(Obj[i])&&Obj[i].disabled!='disabled'){
			if(Obj[i].name=="nom"||Obj[i].name=="prenom"){
				if(/*/\w/.test(*/Obj[i].value!=""/*)*/){
					Obj[i].className="";
				}else{
					Obj[i].className="pasok fpasok";
					errs++;
				}
			}
			if(Obj[i].name=="courriel"){
				if(/^\w+((\.|-)\w+)*@\w+((\.|-)\w+)*\.\w{2,4}$/.test(Obj[i].value)){
					Obj[i].className="";
				}else{
					Obj[i].className="pasok fpasok";
					errs++;
				}
			}
			if(Obj[i].name=="username"||Obj[i].name=="password"){
				if(!/[^a-zA-Z0-9_-]/.test(Obj[i].value)&&Obj[i].value!=""){
					Obj[i].className="";
				}else{
					Obj[i].className="pasok fpasok";
					errs++;
				}
			}
			if(Obj[i].id=="cpassword"){
				if(Obj[i].value==GEI('password').value&&Obj[i].value!=""){
					Obj[i].className="";
				}else{
					Obj[i].className="pasok fpasok";
					errs++;
				}
			}
			if(Obj[i].name=="capcha"){
				if((Obj[i].value)!=''){
					Obj[i].className="";
				}else{
					Obj[i].className="pasok fpasok";
					errs++;
				}
			}
		}
	}
	if(errs==0){
		var AJAX=createAJAX();
		if(AJAX){
			status=AJAX.onreadystatechange=function(){
				if(AJAX.readyState==4){
					GEI('ade').innerHTML=AJAX.responseText;
				}
			};
			var url="../php/createaccount.php?i=1";
			var params="";
			var amp="";
			for(i=0;i<Obj.length;i++){
				if(Obj[i].disabled!='disabled'&&Obj[i].value!=''){
					params+=amp+Obj[i].name+"="+encode(Obj[i].value);
					amp="&";
				}
			}
			AJAX.open("POST", url, true);
			AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			AJAX.setRequestHeader("Content-length", params.length);
			AJAX.setRequestHeader("Connection", "close");
			AJAX.send(params);
			showLoading();
		}else{
			/*...*/
		}
	}
}
function validateinfo(Obj){
	errs=0;
	for(i=0;i<Obj.length;i++){
		if(!/^f_/.test(Obj[i])&&Obj[i].disabled!='disabled'){
			if(Obj[i].name=="nom"||Obj[i].name=="prenom"){
				if(/\w/.test(Obj[i].value)){
					Obj[i].className="";
				}else{
					Obj[i].className="pasok fpasok";
					errs++;
				}
			}
			if(Obj[i].name=="courriel"){
				if(/^\w+(\.\w+)*@\w+(\.\w+)*\.\w{2,4}$/.test(Obj[i].value)){
					Obj[i].className="";
				}else{
					Obj[i].className="pasok fpasok";
					errs++;
				}
			}
			if(GEI('toggler').checked!=""&&Obj[i].name=="password"){
				if(!/[^a-zA-Z0-9_-]/.test(Obj[i].value)&&Obj[i].value!=""){
					Obj[i].className="";
				}else{
					Obj[i].className="pasok fpasok";
					errs++;
				}
			}
			if(GEI('toggler').checked!=""&&Obj[i].id=="cpassword"){
				if(Obj[i].value==GEI('password').value&&Obj[i].value!=""){
					Obj[i].className="";
				}else{
					Obj[i].className="pasok fpasok";
					errs++;
				}
			}
		}
	}
	if(errs==0){
		var AJAX=createAJAX();
		if(AJAX){
			status=AJAX.onreadystatechange=function(){
				if(AJAX.readyState==4){
					GEI('ade').innerHTML=AJAX.responseText;
				}
			};
			var url="../php/moncompte.php?i=1";
			var params="";
			var amp="";
			for(i=0;i<Obj.length;i++){
				if(Obj[i].disabled!='disabled'&&Obj[i].value!=''){
					params+=amp+Obj[i].name+"="+encode(Obj[i].value);
					amp="&";
				}
			}
			AJAX.open("POST", url, true);
			AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			AJAX.setRequestHeader("Content-length", params.length);
			AJAX.setRequestHeader("Connection", "close");
			AJAX.send(params);
			showLoading();
		}else{
			/*...*/
		}
	}
}
function validatelogin(Obj){
	if(GEI('username').value!=""&&GEI('password').value!=""){
		var AJAX=createAJAX();
		if(AJAX){
			status=AJAX.onreadystatechange=function(){
				if(AJAX.readyState==4){
					GEI('ade').innerHTML=AJAX.responseText;
				}
			};
			var url="../php/login.php?i=1";
			var params="";
			var amp="";
			for(i=0;i<Obj.length;i++){
				if(Obj[i].disabled!='disabled'&&Obj[i].value!=''){
					params+=amp+Obj[i].name+"="+encode(Obj[i].value);
					amp="&";
				}
			}
			AJAX.open("POST", url, true);
			AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			AJAX.setRequestHeader("Content-length", params.length);
			AJAX.setRequestHeader("Connection", "close");
			AJAX.send(params);
			showLoading();
		}else{
			/*...*/
		}
	}
}
function subtoact(ACT,WHO){
	var AJAX=createAJAX();
	if(AJAX){
		status=AJAX.onreadystatechange=function(){
			if(AJAX.readyState==4){
				GEI('ade').innerHTML=AJAX.responseText;
			}
		};
		var url="../php/subtoact.php?i=1";
		var params="a="+ACT+"&w="+WHO;
		AJAX.open("POST", url, true);
		AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		AJAX.setRequestHeader("Content-length", params.length);
		AJAX.setRequestHeader("Connection", "close");
		AJAX.send(params);
		showLoading();
	}else{
		/*...*/
	}
}
function changeyear(Obj){
	var AJAX=createAJAX();
	if(AJAX){
		status=AJAX.onreadystatechange=function(){
			if(AJAX.readyState==4){
				GEI('ade').innerHTML=AJAX.responseText;
			}
		};
		var url="../php/ade_e.php?i=1&y="+Obj[Obj.selectedIndex].value;
		AJAX.open("GET", url, true);
		AJAX.send(null);
		showLoading();
	}else{
		/*...*/
	}
}
/*function switchlist(Obj){
	var AJAX=createAJAX();
	if(AJAX){
		status=AJAX.onreadystatechange=function(){
			if(AJAX.readyState==4){
				GEI('adelist').innerHTML=AJAX.responseText;
			}
		};
		var url="../php/ade_e.php?i=1&y="+Obj[Obj.selectedIndex].value;
		AJAX.open("GET", url, true);
		AJAX.send(null);
		showLoading();
	}else{
		/*...*//*
	}
}*/
function popupcal(){
	GEI('calholder').innerHTML='<iframe id="califrame" class="nobdr" src ="../php/mini-cal.php" width="190" height="182"><iframe>';
	GEI('califrame').style.width="190px";
	GEI('califrame').style.height="182px";
	GEI('califrame').style.left=posX+'px';
	GEI('califrame').style.top=posY+'px';
	GEI('califrame').style.background="#fff";
}
function addAct(Obj){
	errs=0;
	for(i=0;i<Obj.length;i++){
		if(!/^f_/.test(Obj[i])&&Obj[i].disabled!='disabled'){
			if(Obj[i].name=="nom"){
				if(/\w/.test(Obj[i].value)){
					Obj[i].className="";
				}else{
					Obj[i].className="pasok fpasok";
					errs++;
				}
			}
			if(Obj[i].name=="date"){
				if(Obj[i].value!=""){
					Obj[i].className="";
				}else{
					Obj[i].className="pasok fpasok";
					errs++;
				}
			}
			if(Obj[i].name=="limite"){
				if(!/[^0-9]/.test(Obj[i].value)){
					Obj[i].className="";
				}else{
					Obj[i].className="pasok fpasok";
					errs++;
				}
			}
		}
	}
	if(errs==0){
		var AJAX=createAJAX();
		if(AJAX){
			status=AJAX.onreadystatechange=function(){
				if(AJAX.readyState==4){
					GEI('ade').innerHTML=AJAX.responseText;
				}
			};
			var url="../php/addact.php?i=1";
			var params="";
			var amp="";
			for(i=0;i<Obj.length;i++){
				if(Obj[i].disabled!='disabled'&&Obj[i].value!=''){
					params+=amp+Obj[i].name+"="+encode(Obj[i].value);
					amp="&";
				}
			}
			AJAX.open("POST", url, true);
			AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			AJAX.setRequestHeader("Content-length", params.length);
			AJAX.setRequestHeader("Connection", "close");
			AJAX.send(params);
			showLoading();
		}else{
			/*...*/
		}
	}
}
function getPosition(e){
	e=e||window.event;
	var cursor={x:0,y:0};
	if(e.pageX||e.pageY){
		cursor.x=e.pageX;
		cursor.y=e.pageY;
	}else{
		var de=document.documentElement;
		var b=document.body;
		cursor.x=e.clientX+
			(de.scrollLeft||b.scrollLeft)-(de.clientLeft||0);
		cursor.y=e.clientY+
			(de.scrollTop || b.scrollTop)-(de.clientTop||0);
	}
	alert(cursor);
	/*return cursor;*/
}
function encode(string){
	var entities='160,nbsp,161,iexcl,162,cent,163,pound,164,curren,165,yen,166,brvbar,167,sect,168,uml,169,copy,170,ordf,171,laquo,172,not,173,shy,174,reg,175,macr,176,deg,177,plusmn,178,sup2,179,sup3,180,acute,181,micro,182,para,183,middot,184,cedil,185,sup1,186,ordm,187,raquo,188,frac14,189,frac12,190,frac34,191,iquest,192,Agrave,193,Aacute,194,Acirc,195,Atilde,196,Auml,197,Aring,198,AElig,199,Ccedil,200,Egrave,201,Eacute,202,Ecirc,203,Euml,204,Igrave,205,Iacute,206,Icirc,207,Iuml,208,ETH,209,Ntilde,210,Ograve,211,Oacute,212,Ocirc,213,Otilde,214,Ouml,215,times,216,Oslash,217,Ugrave,218,Uacute,219,Ucirc,220,Uuml,221,Yacute,222,THORN,223,szlig,224,agrave,225,aacute,226,acirc,227,atilde,228,auml,229,aring,230,aelig,231,ccedil,232,egrave,233,eacute,234,ecirc,235,euml,236,igrave,237,iacute,238,icirc,239,iuml,240,eth,241,ntilde,242,ograve,243,oacute,244,ocirc,245,otilde,246,ouml,247,divide,248,oslash,249,ugrave,250,uacute,251,ucirc,252,uuml,253,yacute,254,thorn,255,yuml,402,fnof,913,Alpha,914,Beta,915,Gamma,916,Delta,917,Epsilon,918,Zeta,919,Eta,920,Theta,921,Iota,922,Kappa,923,Lambda,924,Mu,925,Nu,926,Xi,927,Omicron,928,Pi,929,Rho,931,Sigma,932,Tau,933,Upsilon,934,Phi,935,Chi,936,Psi,937,Omega,945,alpha,946,beta,947,gamma,948,delta,949,epsilon,950,zeta,951,eta,952,theta,953,iota,954,kappa,955,lambda,956,mu,957,nu,958,xi,959,omicron,960,pi,961,rho,962,sigmaf,963,sigma,964,tau,965,upsilon,966,phi,967,chi,968,psi,969,omega,977,thetasym,978,upsih,982,piv,8226,bull,8230,hellip,8242,prime,8243,Prime,8254,oline,8260,frasl,8472,weierp,8465,image,8476,real,8482,trade,8501,alefsym,8592,larr,8593,uarr,8594,rarr,8595,darr,8596,harr,8629,crarr,8656,lArr,8657,uArr,8658,rArr,8659,dArr,8660,hArr,8704,forall,8706,part,8707,exist,8709,empty,8711,nabla,8712,isin,8713,notin,8715,ni,8719,prod,8721,sum,8722,minus,8727,lowast,8730,radic,8733,prop,8734,infin,8736,ang,8743,and,8744,or,8745,cap,8746,cup,8747,int,8756,there4,8764,sim,8773,cong,8776,asymp,8800,ne,8801,equiv,8804,le,8805,ge,8834,sub,8835,sup,8836,nsub,8838,sube,8839,supe,8853,oplus,8855,otimes,8869,perp,8901,sdot,8968,lceil,8969,rceil,8970,lfloor,8971,rfloor,9001,lang,9002,rang,9674,loz,9824,spades,9827,clubs,9829,hearts,9830,diams,338,OElig,339,oelig,352,Scaron,353,scaron,376,Yuml,710,circ,732,tilde,8194,ensp,8195,emsp,8201,thinsp,8204,zwnj,8205,zwj,8206,lrm,8207,rlm,8211,ndash,8212,mdash,8216,lsquo,8217,rsquo,8218,sbquo,8220,ldquo,8221,rdquo,8222,bdquo,8224,dagger,8225,Dagger,8240,permil,8249,lsaquo,8250,rsaquo,8364,euro';
	var a=entities.split(',');
	for(s=0;s<a.length;s+=2){
		v=a[s];
		/*Don't add default &amp; &quot; etc.*//*
		if(v==34||v==38||v==60||v==62){
			continue;
		}*/
		/*v = parseInt(a[s]).toString(16)*/
		var reg = new RegExp(String.fromCharCode(v), "g");
		string=string.replace(reg,'%'+parseInt(a[s]).toString(16));
	}
	return string;
}
function showLoading(){
	GEI('ade').innerHTML='<img class="center" src="../cms/int/MEx_loading.gif" />';
}