function verify_login(){

	if(document.formulairelog.log_pass.value.length==0){

    	alert ('You must give a login');

		this.formulairelog.log_pass.focus();

        	return false;

    }

    else{

    	if(document.formulairelog.password.value.length==0){

         	alert ('You must give a password');

			this.formulairelog.password.focus();

        	return false;

        }

    }

	return true;

}



function envoi(ahealth_register_form,register_with_organisation,tomcat_ip,tomcat_port){

	//alert('tomcat ip is : '+tomcat_ip);

	//alert('tomcat port is : '+tomcat_port);

	first=this.formulaire.first.value;

	last=this.formulaire.last.value;

	if((this.formulaire.password!=null)||(this.formulaire.password2!=null)){

		password=this.formulaire.password.value;

		password2=this.formulaire.password2.value;

		passwordset = true;

	}

	else{

		passwordset = false;

	}

	email=this.formulaire.email.value;

	organization = this.formulaire.organization.value;

	usermembership = this.formulaire.usermembership.value;



	if (first=='')

	{

		alert('You must fill in your first name');

		this.formulaire.first.focus();

		return false;

	}



	if (last=='')

	{

		alert('You must fill in your last name');

		this.formulaire.last.focus();

		return false;

	}

	if((usermembership=='2')||(usermembership=='3')){

		if (password=='')

		{

			alert('You must fill in your password');

			this.formulaire.password.focus();

			return false;

		}



		if (password2=='')

		{

			alert('You must confirm your password');

			this.formulaire.password2.focus();

			return false;

		}

	}

	if (email=='')

	{

		alert('You must fill in your email address');

		this.formulaire.email.focus();

		return false;

	}

	

	if (organization=='')

	{

		/******************************************************************************************************/

		/** PROBLEM: This is defined in static way. The array should be passed by the form to the javascript **/

		/** This should be defined in the conf file as a PHP array and passed to the function envoi().*********/

		/******************************************************************************************************/

		if ((usermembership=='2')||(usermembership=='3'))

		{

			alert('You must fill in your organization name');

			this.formulaire.organization.focus();

			return false;

		}

	}

	

	



	/********************************************/

	/*Fin des verifications des champs non-vides*/

	/********************************************/



	/*******************************************/

	/*Verification de la saisie du mot de passe*/

	/*******************************************/

	if(passwordset){

		if(password==password2)

		{

			/***********************************************************************/

			/** check that password does not have any unauthorized character in it**/

			/***********************************************************************/

			/*if(match(password," ")){

				alert('Y un espace de le mot de passe');

			}

			else{*/

			if(!password.match(" ")){

				if(ahealth_register_form){

					document.formulaire.action='index.php?param=56';

					document.formulaire.submit();

					return true;

				}

				else{

					this.formulaire.submit();

					return true;

				}

			}

			else{

				alert('You can not put a blank in the password.');

			}

		}

		else

		{

			alert('You must type the same passwords');

		}

	}

	else{



			document.formulaire.action='index.php?param=56';

			document.formulaire.submit();

			return true;



	}

}



function professional(){

	interest = this.formulaire.select.value;

	//affiche le formulaire en fonction de cette valeur à faire.

}



function closepush(){

	document.formulaire.submit();

	return true;

	//window.kill();

}



function change(){

	//alert('This is BFC work test ');

	document.formulaire.submit();

	return true;

	//window.close();

}



// Fonctions qui etaient dans Upload

// Start Menu Déroulant



function display(str){

window.status = str;

	return true;

}

function akoter(){

	if (document.forms.superform.elements[1].options[document.forms.superform.elements[1].selectedIndex].value != "" )

 	{

	urlredir = document.forms.superform.elements[1].options[document.forms.superform.elements[1].selectedIndex].value ;

  		location.href=urlredir;

 	}

}



var contributionArray =  new Array(

"('version','version',true,true)"

);



var reportArray =  new Array(

"('version','version',true,true)",

"('for review','for review',true,true)",

"('reviewed','reviewed',true,true)",

"('draft','draft',true,true)"

);



var guidelineArray =  new Array(

"('draft','draft',true,true)",

"('version','version',true,true)"

);



function remplirtitres(inForm,selected) {

	var selectedArray = eval(selected + "Array");

	while (selectedArray.length < inForm.status.options.length) {

		inForm.status.options[(inForm.status.options.length - 1)] = null;

	}

	for (var i=0; i < selectedArray.length; i++) {

		eval("inForm.status.options[i]=" + "new Option" + selectedArray[i]);

	}



// Si vous souhaitez que par defaut le pointeur se positione sur un autre champ que le titre

//Changez le 0 en la valeur que vous voulez en partant du haut



	document.forms.superform.elements[1].selectedIndex =0;



//Pour tricher avec Netscape ou un autre ca simule le reload ( hahah )





	if (inForm.type.options[0].value == '') {

		 inForm.type.options[0]= null;

		 if ( navigator.appName == 'Netscape') {

		 		if (parseInt(navigator.appVersion) < 4) {

					 	window.history.go(0);

						}

						else {

					 			 if (navigator.platform == 'Win32' || navigator.platform == 'Win16') {

					 			 window.history.go(0);

	         			 }

      	}

   		}

   }

}







var global_push1 = 0;

var global_push2 = 0;

var global_push3 = 0;

var global_push4 = 0;



function verify_data_upload(){

	var flag = false;

	if ( document.superform.label.value.length == 0  ) {

		alert( 'You must fill in the Title of your document');

		return false;

	}

  	else {

		if ( document.superform.userfile.value.length == 0  ) {

			alert( 'You must attach a document to your upload');

    			return false;

		}

		else {

			/*for (i = 0; i < document.superform.checkbox.length; i++) {

				//alert(field.checkbox[i].checked);

				if(document.superform.checkbox[i].checked==true){

					flag = true;

				}

			}

			if(flag){

				var mailval = '';

				for (i = 0; i < document.superform.checkbox.length; i++) {

					//alert(document.superform.checkbox[i].checked);

					if(document.superform.checkbox[i].checked==true){

						if (mailval != '')

							mailval = mailval + ',' ;

						mailval = mailval + document.superform.checkbox[i].value ;

						flag = true;

					}

				}

				//document.superform.action='index.php?param=1&chemin='+chemin+'&hasbeenupload=1&yesno=yes&list='+mailval;

// alert( mailval);

				return true;

			}

			else{

				//alert('don\'t send mail');

				//document.superform.action='index.php?param=1&chemin='+chemin+'&hasbeenupload=1&yesno=no';

				return true;

			}*/

			return true;

		}

  	}

}





function verify_data_forum(forum_name){

	if(document.superform.subject!=undefined){

		if(document.superform.subject.value.length < 6 ){

			alert('Your subject must contain more than five characters');

			return false;

		}

	}

	if(document.superform.message.value.length < 10 ){

		alert('Your message must contain more than nine characters');

		return false;

	}

	else{

		

		if(document.superform.userfile.value.length == 0){

			//alert (document.superform.title.value.length);

			if(document.superform.title.value.length!=0){

				alert('You must choose a document to upload.');

				return false;

			}

			if(document.superform.id_reply.value!=0){

				

				forum_name = escape(forum_name); 

				document.superform.action='index.php?param=15&yesno=yes&insert_message=1&forum_name='+forum_name+'&reply='+document.superform.id_reply.value+'#'+document.superform.id_reply.value;

				//alert (document.superform.action);

				//return false;

				//document.superform.submit();

				return true;

			}

			else{

				forum_name = escape(forum_name); 

				document.superform.action='index.php?param=15&yesno=yes&insert_message=1&forum_name='+forum_name;

				//document.superform.submit()

				return true;

			}

		}

		else{

			//  alert (document.superform.userfile.value);



			

			if(document.superform.title.value.length==0){

				if (confirm('Your document has no title. One will be set by default')){

					var filename;

					var b = document.superform.userfile.value.split("\\");

					for(i = 0 ; i < b.length ; i++){

						//document.write("b[" + i + "] a la valeur <b>" + b[i] + "</b><br>");

						filename =  b[i]

					}

					//alert(filename);

					document.superform.title.value = 'Click here to view the attachment ('+filename+')';

					// return true;

				}

				else{

					return false;

				}

			}

			

			

				//alert (document.superform.id_reply.value);

				if(document.superform.id_reply.value!=0){

					//return false;

					forum_name = escape(forum_name);

					document.superform.action='index.php?param=15&hasbeenupload=1&yesno=yes&insert_message=1&forum_name='+forum_name+'&reply='+document.superform.id_reply.value+'#'+document.superform.id_reply.value;

					//document.superform.submit();

					return true;

				}

				else{

					forum_name = escape(forum_name);

					document.superform.action='index.php?param=15&hasbeenupload=1&yesno=yes&insert_message=1&forum_name='+forum_name;

					//document.superform.submit();

					return true;

				}

			

		}

	}

}









function fonctionPush(){

     document.pushform.submit();

}





function ouvrir_popup2(url,ww,hw) {

	

	eval("terregov= window.open( '" + url + "', 'terregov', 'width="+ ww + ",height=" + hw+ ",toolbar=0,location=0,directories=0,status=0,menuBar=0,scrollBars=1,resizable=1,left=10,top=10');");

	eval("terregov.focus();");

	

}





function ouvrir_popup(url,ww,hw,chemin,type,status) {

	//alert('Test : var global push is '+global_push1+' and type is '+type+' and status is  '+ status);

	if((global_push1==1)||(global_push2==1)||(global_push3==1)){

		//alert('cas4');

		url = 'index.php?param=24&chemin='+chemin;

	}

	if( (( ((type=='contribution')||(type=='report')) && (status!='version') && (status!='for_review'))||(type=='guideline')) && (global_push1==0)){

		//alert('cas1');

		global_push1=1;

		global_push2=0;

		global_push3=0;

	}

	if(((type=='report') && (status=='version')) && (global_push2==0)){

		//alert('cas2');

		global_push1=0;

		global_push2=1;

		global_push3=0;

	}

	if(((type=='report') && (status=='for_review')) && (global_push3==0)){

		//alert('cas3');

		global_push1=0;

		global_push2=0;

		global_push3=1;

	}

	

	

	else{

		if((type=='contribution') && (status=='version')&&(global_push4==0)){

			//alert('cas5');

			url = 'index.php?param=24&modify=true&type='+type+'&status='+status+'&chemin='+chemin;

			global_push4++;		

		}

		else{

			//alert('cas6');

			url = 'index.php?param=24&chemin='+chemin;

		}		

	}

	

	eval("terregov= window.open( '" + url + "', 'terregov', 'width="+ ww + ",height=" + hw+ ",toolbar=0,location=0,directories=0,status=0,menuBar=0,scrollBars=1,resizable=1,left=10,top=10');");

	eval("terregov.focus();");

	

}



function checkYesNo(radio){

	for (var a=0; a<radio.length;a++){

		if(radio[a].checked){

			//alert(radio[a].value);

			return true;

		}

		else{

			alert ('You must choose the Yes Button');

			return false;

		}

		if(radio[a].value=='Yes'){

			

		}

		else{

			

		}

	}

}

function back(file,chemin){

	if(file=='browser'){

       alert('back browser');

	}

    if(file=='forum'){

       alert('back forum');

	}

}

function checkyesno(){

    alert('You don\'t want to notify people');

}

//FIN DU SCRIPT MENU DEROULANT

//Fin fonctions qui etaient dans uplaod



function verify_delete_dir()

{

	if (confirm('Are you sure you want to delete this folder?')){

		//document.formulaire.submit();

		return true;

	}

    else{

    	return false;

	}

}



function verify_delete_file()

{

	if (confirm('Are you sure you want to delete this file?')){

		//document.formulaire.submit();

		return true;

	}

    else{

    	return false;

	}

}



function verify_delete_directory_non_empty()

{

	if ( confirm('The folder is not empty. This will erase all the data. Are you still sure ?') )

    	//document.formulaire.submit();

		return true;

    else{

		history.go(-1);

    	return false;

	}

}





function verify_create()

{

   if ( document.createform.textfield.value.length == 0  ) {

		alert( 'You must give a name for the folder');

    	return false;

	}

}

function closepush(){

	document.formulaire.submit();

	//window.kill();

}

function change(){

	//alert('This is BFC work test ');

	document.formulaire.submit();

	//window.close();

}

function closepush(){

	document.formulaire.submit();

	//window.kill();

}

function change(){

	//alert('This is BFC work test ');

	document.formulaire.submit();

	//window.close();

}

function verify_message(){

	//alert('valeur du titre'+document.formulaire_forum);

	//alert('valeur du texte');

	//return false;

	if(document.formulaire_forum.titre.value.length < 6){

    	alert('You must give a title that contains more than six characters');

    	return false;

    }

    else{

    	if(document.formulaire_forum.texte.value.length < 6){

    	 	alert('You must give a text that contains more than six characters');

    	 	return false;

         }

         else{

         	return true;

         }

    }



}

function test(){

	alert('coucou');

}

function Check_all_box(field)

{

	for (i = 0; i < field.length; i++) {

			field[i].checked = true;

	}

		//checkflag = "true";

		//return "Select All";

		document.formulaire.action='index.php?param=2&yesno=yes&flag=1';

		//document.formulaire.submit();

}



function unCheck_all_box(field)

{

	for (i = 0; i < field.length; i++) {

		field[i].checked = false; 

	}

		//checkflag = "false";

		//return "Deselect All";

		document.formulaire.action='index.php?param=2&yesno=no&flag=1';

		//document.formulaire.submit();

}



function checkPreferences(param_id){

	

	var flag = "";

	if(document.formulaire_preferences.new_login.value.length!=0){

		flag += "new_login="+document.formulaire_preferences.new_login.value;

	}

	if(document.formulaire_preferences.new_password.value.length!=0){

		flag += "&new_password="+document.formulaire_preferences.new_password.value;

	}

	

	if(document.formulaire_preferences.new_mail.value.length!=0){

		alert('Warning : if your mail is not correct, you won\'t be notified correctly.');

		var pos = document.formulaire_preferences.new_mail.value.search("@");

		if(pos==-1){

			alert('Warning : Your email must have an @ in it.');

			return false;

		}

		else{

			if(document.formulaire_preferences.new_mail.value.length<3){

				alert('Warning : Your email must have at least three letters.');

				return false;

			}

			else{

				flag += "&new_mail="+document.formulaire_preferences.new_mail.value;

			}

		}

	}

	if(document.formulaire_preferences.new_phone!=undefined){

		if(document.formulaire_preferences.new_phone.value.length!=0){

			flag += "&new_phone="+document.formulaire_preferences.new_phone.value;

		}

	}

		

		if(document.formulaire_preferences.checkboxnotify.checked){

			if(document.formulaire_preferences.inv.value==0){

				

				alert('You will now appear in the notified list');

				flag += "&notify="+document.formulaire_preferences.inv.value;

			}

			else{

				alert('You will now disappear from the notified list');

				flag += "&notify="+document.formulaire_preferences.inv.value;

			}

		}

	

	//alert(flag);

	document.formulaire_preferences.action='index.php?param=6&param_id='+param_id+'&'+flag;

	document.formulaire_preferences.submit();

}

function change_document_weight(doc_id,folder_id,signe){

	if(signe=='plus'){

		//alert('('+doc_id+','+folder_id+')');

		document.weightform.action='index.php?param=9&doc='+folder_id+'&weight_plus='+doc_id;

		document.weightform.submit();

	}

	if(signe=='moins'){

		//alert('('+doc_id+','+folder_id+')');

		document.weightform.action='index.php?param=9&doc='+folder_id+'&weight_moins='+doc_id;

		document.weightform.submit();

	}

}

function change_doc_func(){

	alert('Warning: You are changing a document properties.');

	document.change_doc.action = 'index.php?param=11';

	document.change_doc.submit();

}



function test(partner,doc,folder){

	alert('*'+partner+'*'+doc+'*'+folder+'*');

	document.change_doc.action = "index.php";

	document.change_doc.submit();

}

function delete_thread(form_name,forum_name){

	var tmp_form = form_name.replace('formulaire_','');

	alert('You are ersasing the thread '+tmp_form);

	document.form_name.action = 'index.php?param=3&forum_name='+forum_name;

	document.form_name.submit();

}

function CheckTextField(){

	if(document.search_form.SearchText.value==""){

		alert ('You must type in words');

		return false;

	}

	else{

		return true;

	}

}

function verify_user_creation(){

	if(document.user.userpartner.value.length==0){

		alert('This user has no partner');

		return true;

	}

	else{

		if(document.user.userfirstname.value.length==0){

			alert('You must give a first name');

			return false;

		}

		else{

			if(document.user.userlastname.value.length==0){

				alert('You must give a last name');

				return false;

			}

			else{

				if(document.user.usermail.value.length==0){

					alert('You must give a mail');

					return false;

				}

				else{

					if(document.user.userphone.value.length==0){

						alert('You must give a phone number');

						return false;

					}

					else{

						

						if(document.user.userreturn[0].checked==true){

							document.user.action='';

							document.user.submit();

							return true;

						}

						else{

							if(document.user.userreturn[1].checked==true){

								document.user.action='?param=28';

								document.user.submit();

								return true;

							}

							else{

								return false;

							}

						}

					}

				}

			}

		}

	}

}

function verify_del_creation(){

	if(document.delcreation.delname.value.length==0){

		alert('You must give the workpackage a name');

		return false;

	}

	else{

		if(document.delcreation.delnumber.value.length==0){

			alert('You must give a work package number');

			return false;

		}

		else{

			if(document.delcreation.delreturn[0].checked==true){

				document.delcreation.action='';

				document.delcreation.submit();

				return true;

			}

			else{

				if(document.delcreation.delreturn[1].checked==true){

					document.delcreation.action='?param=31';

					document.delcreation.submit();

					return true;

				}

				else{

					return false;

				}

			}

		}

	}

}



/***********************************************/

/** Check the field of the rule creation form **/

/***********************************************/

function checkRuleCreationForm(){



        if(document.createruleform.label.value.length==0){

                alert('You must give a rule name');

                return false;

        }

        if( document.createruleform.elements[1].selectedIndex == -1 ) {

                alert('You must select a role');

                return false;

        }



        if ( (document.createruleform.open_checkbox.checked) || (document.createruleform.close_checkbox.checked) || (document.createruleform.validate_checkbox.checked) || (document.createruleform.delete_checkbox.checked) || (document.createruleform.read_checkbox.checked))

        {

                return true;

        }

        else {

                alert('You must at least select one permission');

                return (false);

        }

}









function checkBothNoneAndOtherItem( tsel) {



		var nbSelected = 0;

		var noneSelected = 0;

		

		for (var i=0; i <tsel.options.length; i++) {

        	if ( tsel.options[i].selected) {

				++nbSelected;

           		if ( tsel.options[i].value == '-1')

					noneSelected = 1;

	   		}

		}

		

		if ((nbSelected >1) && (noneSelected == 1)) {

			/* Impossible : Can't select both the "NONE item" and other "item(s)" */

			

				tsel.focus();

                alert('You can\'t select both "None" and other Item(s)');

                return false;

		}

		return true;

}







function isDigit(val) {

	for(var i=0;i<val.length;i++){

		if(!isCharDigit(val.charAt(i))){return false;}

	}

	

	return true;

}



function isCharDigit(num) {

	if (num.length>1){return false;}

	var string="1234567890";

	if (string.indexOf(num)!=-1){return true;}

	return false;

}



/***********************************************/

/** Check the field of the rule creation form **/

/***********************************************/

function checkCategoryCreationForm(){



        if(document.createcategoryform.label.value.length==0){

                alert('You must give a Category name');

                return false;

        }

		/* Verify that at least one Rule is associated to the category */

        if( document.createcategoryform.elements[1].selectedIndex == -1 ) {

                alert('You must select a Rule');

                return false;

        }



	/* Verify that for the RESPONSIBLE IS field, that both NONE and another item(s) is selected */

	if ( ! checkBothNoneAndOtherItem( document.createcategoryform.elements[5])) return false;

	/* Verify that for the INVOLVED IN IS field, that both NONE and another item(s) is selected */

	if ( ! checkBothNoneAndOtherItem( document.createcategoryform.elements[7])) return false;



	if( ! isDigit( document.createcategoryform.start_date.value)) {

		alert('Start Date must be a digit (Month Number)');

		document.createcategoryform.start_date.focus();

            	return false;

	}

	

	if( ! isDigit( document.createcategoryform.end_date.value)) {

		alert('End Date must be a digit (Ending at Month xx)');

		document.createcategoryform.end_date.focus();

        	return false;

	}

	

	/*****************************************************************************************************/

	/** Check if none responsible partner has been selected and none involved partner has been selected **/

	/** then the checkbox with all users must be selected ************************************************/

        /*****************************************************************************************************/

	if((document.createcategoryform.elements[7].value==-1)&&(document.createcategoryform.elements[5].value==-1)){

		if(!document.createcategoryform.elements[6].checked){

			alert(' if you don\'t chose partner involved or responsible, you should chose the Public Users');

			return false;

		}

	}

	return true;

}





/***********************************************/

/** Check if you are sure to delete this rule **/

/***********************************************/

function verify_delete_rule()

{

	if (confirm('Are you sure you want to delete this rule?')){

		return true;

	}

    else{

    	return false;

	}

}



/***********************************************/

/** Check if you are sure to delete this rule **/

/***********************************************/

function verify_delete_category()

{

	if (confirm('Are you sure you want to delete this category?')){

		return true;

	}

    else{

    	return false;

	}

}



/****************************************************************/

/** Check if you are sure to delete this rule on this category **/

/****************************************************************/

function verify_delete_category_rule()

{

	if (confirm('Are you sure you want to delete this rule on this category?')){

		return true;

	}

    else{

    	return false;

	}

}

/******************************************/

/** Check the value for partner formular **/

/******************************************/

function verify_partner_creation(){

	if(document.organisation.orgcompletename.value.length==0){

		alert('You must give a complete name');

		return true;

	}

	else{

		if(document.organisation.orgshortname.value.length==0){

			alert('You must give a short name');

			return false;

		}

		else{

			if(document.organisation.orgurl.value.length==0){

				alert('You must give an url like http://...');

				return false;

			}

			else{

				if(document.organisation.orgdescription.value.length==0){

					alert('You must give a short description.');

					return false;

				}

				else{

					if ( document.organisation.orglogo.value.length == 0  ) {

						if(confirm( 'Are you sure you don\'t want to attach a logo image?')){

							document.organisation.action='';

							document.organisation.submit();

							return true;

						}

						else{

							return false;

						}

					}

				}

			}

		}

	}

}



/*********************************************/

/** Check the parameter of the search form  **/

/*********************************************/

function checkSearchForm(){

	if(document.searchform.searchField.value.length==0){

		alert('You must type in a search word');

		return false;

	}

	else{

		if((!document.searchform.documentLabel.checked) && (!document.searchform.forumTitle.checked) && (!document.searchform.forumMessage.checked)){

			alert('You must choose at least one search category');

			return false;

		}

		else{

			return true;

		}

	}

}



/************************************************************/

/** Reload the register form regarding the membership used **/

/************************************************************/

function changeInscriptionRequiredField(){

	usermembership = this.formulaire.usermembership.value;

	param_added = '';

	if (this.formulaire.first.value!='')

	{

		first=this.formulaire.first.value;

		param_added = param_added +'first='+first+'&';	

	}



	if (this.formulaire.last.value!='')

	{

		last=this.formulaire.last.value;

		param_added = param_added +'last='+last+'&';	

	}

	if (this.formulaire.email.value!='')

	{

		email=this.formulaire.email.value;

		param_added = param_added +'email='+email+'&';

	}

	

	if (this.formulaire.organization.value!='')

	{

		organization = this.formulaire.organization.value;

		param_added = param_added +'organization='+organization+'&';

	}

	if ((usermembership=='2')||(usermembership=='3')){

		//alert('You need to put your password again');

		/** if(this.formulaire.password.value!='')

		{

			password=this.formulaire.password.value;

			param_added = param_added +'password='+password+'&';	

		}

		

		if(this.formulaire.password2.value!='')

		{

			password2=this.formulaire.organization.value;

			param_added = param_added +'password2='+password2+'&';		

		}**/

	}

	/******************************************************************************************************/

	/** PROBLEM: This is defined in static way. The array should be passed by the form to the javascript **/

	/** This should be defined in the conf file as a PHP array and passed to the function envoi().*********/

	/******************************************************************************************************/

	if ((usermembership=='2')||(usermembership=='3')){

		document.location.href = '/my_spip/index.php?param=8&session=&password_required=true&'+param_added+'usermembership='+usermembership;

		return true;

	}

	else{

		document.location.href = '/my_spip/index.php?param=8&session=&password_required=false&'+param_added+'usermembership='+usermembership;

		return true;

	}

}

