// JavaScript Document

function MM_reloadPage(init) {	//reloads the window if Nav4 resized
	if (init==true) with (navigator) {
		if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
			document.MM_pgW=innerWidth;
			document.MM_pgH=innerHeight; onresize=MM_reloadPage;
		}
	}
	else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}

function Lvl_targetIframe(f,i,u){ //v1.0 4LevelWebs
	 var b=(!f)?i:f+".frames['"+i+"']",o=(eval("opener&&opener.parent."+b))?"opener.":'';
	 var el=eval(o+"parent."+b);
	 el.location=u;
	 document.MM_returnValue=false;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
	window.open(theURL,winName,features);
}

function MM_swapImgRestore() { //v3.0
	var i,x,a=document.MM_sr;
	for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
	var d=document;
	if(d.images){
		if(!d.MM_p) d.MM_p=new Array();
		var i,j=d.MM_p.length,a=MM_preloadImages.arguments;
		for(i=0; i<a.length; i++)
		if (a[i].indexOf("#")!=0){
			d.MM_p[j]=new Image;
			d.MM_p[j++].src=a[i];
		}
	}
}

function MM_findObj(n, d) { //v4.01
	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 && d.getElementById) x=d.getElementById(n);
	return x;
}

function MM_swapImage() { //v3.0
	var i,j=0,x,a=MM_swapImage.arguments;
	document.MM_sr=new Array;
	for(i=0;i<(a.length-2);i+=3)
	if ((x=MM_findObj(a[i]))!=null){
		document.MM_sr[j++]=x;
		if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];
	}
}

function popUpWindow(path, name, width, height, resiz, scrol, nav, addr, menu, status, tool) {
// this function displays a screen centered pop-up window with desired options
	x = (screen.width / 2) - (width / 2);
	y = (screen.height / 2) - (height / 2);
	newWindow = window.open(''+path+'', ''+name+'', 'width='+width+',height='+height+',top='+y+',left='+x+',resizable='+resiz+',scrollbars='+scrol+',directories='+nav+',location='+addr+',menubar='+menu+',status='+status+',toolbar='+tool+'');
	return newWindow;
}

function popUpSimpleWindow(path) {
	popUpWindow(path, '', 600, 500, 'yes', 'yes', 'no', 'no', 'no', 'no', 'yes');
}

function verifyRAP(msg) { // vérifie que toutes les dimensions du RAP ('modules/01/diagnostic-RAP.php') aient été définies avant l'envoi du formulaire
	nbchecked = 0;
	for (i=0; i<4; i++) {
		if (document.form_RAP.RAP_somatique[i].checked) {
			nbchecked++;
		}
		if (document.form_RAP.RAP_psychiatrique[i].checked) {
			nbchecked++;
		}
		if (document.form_RAP.RAP_motivationnelle[i].checked) {
			nbchecked++;
		}
		if (document.form_RAP.RAP_crise[i].checked) {
			nbchecked++;
		}
		if (document.form_RAP.RAP_ressources[i].checked) {
			nbchecked++;
		}
		if (document.form_RAP.RAP_dependance[i].checked) {
			nbchecked++;
		}
	}
	if (nbchecked == 6) {
		document.form_RAP.submit();
	}
	else {
		window.alert (msg);
	}
}

function verifyTTToptionselected(msg) { // vérifie qu'une option de traitement a bien été sélectionnée avant d'envoyer le choix au serveur
	if (document.form_TTToptions.StepName.value == "Empty" || !document.form_TTToptions.StepName.value) {
		window.alert (msg);
	}
	else {
		document.form_TTToptions.submit();
	}
}

function resetSousModule(moduleName, msg) { // demande confirmation avant d'effacer les données de session du sous-module (pour module 5, cannabis)
	if (window.confirm(msg)) {
		window.location.href = './' + moduleName + '.php?reset=1';
	}
}

function resetModule(msg, redirTo) { // demande confirmation avant de renvoyer vers la page 'moduleName' avec la requête '?reset=1', ce qui efface les données de session
	if (window.confirm(msg)) {
		if (redirTo) {
			window.location.href = './' + redirTo + '.php?reset=1';
		}
		else {
			window.location.href = './anamnese.php?reset=1';
		}
	}
}

function leaveModule(confmsg) { // demande confirmation avant de quitter un module
	if (window.confirm(confmsg)) {
		window.location.href = '../../home.php';
	}
}

