// Functions.js

function clearFields( )
{
	var elt = document.forms.formulaire.elements;
	for( var i = 0; i < elt.length; i++ )
	{
		elt[i].value = '';
	}
}


function setMailAdress( field )
{
	document.getElementById( 'mailad' ).href = 'mai' + 'lto' + ':magal' + 'ie.dorazio' + '@rhone-al' + 'pes-futur.' + 'org';
}


// Javascript Functions.


/**********************************************************************************************
Function : 	changeCSSClass( element, classOn, classOff )
Arguments : 
		- element : The id of the element to act upon
		- classOn : The css class to apply when element is active (OnMouseOver)
		- classOff : The css class to apply when element is inactive (OnMouseOut)
Description :
		This function allow to dinamically swap styles for an HTML element identified
		by an 'id' tag. The element and the CSS classes for Over and Out states must be 
		specified.
Date : 		May, 04th 2005
Author :	Julien Celle
**********************************************************************************************/
function changeCSSClass( element, classOn, classOff )
{
	// onMouseOver="javascript:changeCSSClass( 'test', 'bordtxthover', 'cursbordtxt' );" 
	// onMouseOut="javascript:changeCSSClass( 'test', 'bordtxthover', 'cursbordtxt' );" 
	// id="test" 
	if( document.getElementById( element ).className == classOn )
		document.getElementById( element ).className = classOff;
	else
		document.getElementById( element ).className = classOn;
}

/**********************************************************************************************
Function : 	function moveFromTo( from, to )
Arguments :
		- from : Where to pick 'options' from.
		- to : Where to insert 'options' to.
Description :
		This function allows to move 'option' elements (as found in a 'select' HTML
		tag) from one 'select' entity identified by the 'id' tag 'from' to another 
		'select' entity identified by the 'id' tag 'to'. Elements are deleted from
		the source 'select' element.
Date : 		May, 04th 2005
Author :	Julien CELLE.
**********************************************************************************************/
function moveFromTo( from, to )
{
	var i;
	for( i = 0; i <= document.getElementById( from ).length; i++ )
	{
		if( ( document.getElementById( from ).options[i] != null ) && ( document.getElementById( from ).options[i].selected == true ) )
		{
			document.getElementById( to ).options[document.getElementById( to ).length] = new Option( document.getElementById( from ).options[i].text, document.getElementById( from ).options[i].value );
			document.getElementById( from ).options[i] = null;
			i--;
		}
	}
}

/**********************************************************************************************
Function : 	function addFromTo( from, to )
Arguments :
		- from : Where to pick 'options' from.
		- to : Where to insert 'options' to.
Description :
		This function allows to copy 'option' elements (as found in a 'select' HTML
		tag) from one 'select' entity identified by the 'id' tag 'from' to another 
		'select' entity identified by the 'id' tag 'to'. Elements are NOT deleted
		from the source 'select' element.
Date : 		May, 04th 2005
Author :	Julien CELLE.
**********************************************************************************************/
function addFromTo( from, to )
{
	var i;
	for( i = 0; i <= document.getElementById( from ).length; i++ )
	{
		if( ( document.getElementById( from ).options[i] != null ) && ( document.getElementById( from ).options[i].selected == true ) )
		{
			document.getElementById( to ).options[document.getElementById( to ).length] = new Option( document.getElementById( from ).options[i].text, document.getElementById( from ).options[i].value );
		}
	}
}

/**********************************************************************************************
Function : 	removeFrom( from )
Arguments :	
		- from : where to delete elements from.
Description :
		This function deletes all elements (option) from a 'select' HTML entity.
Date : 		May, 04th 2005
Author :	Julien CELLE.
**********************************************************************************************/
function removeFrom( from )
{
	var i;
	
	if( document.getElementById( from ) )
	{
		for( i = 0; i <= document.getElementById( from ).length; i++ )
		{
			if( ( document.getElementById( from ).options[i] != null ) && ( document.getElementById( from ).options[i].selected == true ) )
			{
				document.getElementById( from ).options[i] = null;
				i--;
			}
		}
	}
}



/**********************************************************************************************
Function : 	backupFields( numof, ids, fieldtype )
Arguments :
		- numof : 'id' of the 'hidden' element containing the number of element to backup
		- ids : 'id's of the elements to backup
		- fieldtype : type of the fields to backup
Description :
		This function backups the data contained in the elements referenced by the 'ids'
		parameter according to the type requested. Data are stored in an array that is
		returned.
Date : 		May, 04th 2005
Author :	Julien Celle.
**********************************************************************************************/
function backupFields( numof, ids, fieldtype )
{
	var i, j;
	var k = parseInt( document.getElementById( numof ).value );
	var tab = null;
	var fid = '';
	var ftype = '';
	
	if( k > 0 )
	{
		tab = new Array( k );
		
		for( i = 0; i < k; i++ )
		{
			tmp = new Array( ids.length );
			
			for( j = 0; j < ids.length; j++ )
			{
				if( fieldtype[j] == 'selectedIndex[]' )
				{
					fid = ids[j] + i + '[]';
					ftype = 'selectedIndex';
				}
				else
				{
					fid = ids[j] + i;
					ftype = fieldtype[j];
				}
				//if( document.getElementById( ids[j] + i ) != null  )
				tmp[j] = document.getElementById( fid )[ftype];
			}
			
			tab[i] = tmp;
		}
	}
	
	return tab;
}

/**********************************************************************************************
Function : 	restoreFields( ids, fieldtype, tab, k )
Arguments :
		- ids : 'id's of the fields to restore
		- fieldtype : types of the fields to restore
		- tab : Array containing the values to restore
		- k : Number of elements to restore
Description :
		This function is the opposite of the 'backupFields( )' function declared
		previously.
Date : 		May, 04th 2005
Author :	Julien Celle.
**********************************************************************************************/
function restoreFields( ids, fieldtype, tab, k )
{
	var i, j;
	var fid = '';
	var ftype = '';
		
	if( k > 0 )
	{
		for( i = 0; i <  k; i++ )
		{
			for( j = 0; j < ids.length; j++ )
			{
				if( fieldtype[j] == 'selectedIndex[]' )
				{
					fid = ids[j] + i + '[]';
					ftype = 'selectedIndex';
				}
				else
				{
					fid = ids[j] + i;
					ftype = fieldtype[j];
				}
				
				document.getElementById( fid )[ftype] = tab[i][j];
			}
		}
	}
}

/**********************************************************************************************
Function : 	addTplElement( target, numof, tpl, ids, fieldtype )
Arguments :
		- target : where to insert the Tpl
		- numof : id of the hidden element containing the number of Tpl elements
			already inserted in the target
		- tpl : the template to insert
		- ids : the ids of the elements to save and restore
		- fieldtype : type of the elements to save and restore
Description :
		This function inserts a template element in a target containing other
		template elements and keeps data already inserted in the previous templates.
Date : 		May, 04th 2005
Author :	Julien Celle.
**********************************************************************************************/
function addTplElement( target, numof, tpl, ids, fieldtype )
{
	var k = parseInt( document.getElementById( numof ).value );
	var tab;
	
	tab = backupFields( numof, ids, fieldtype );
	
	document.getElementById( target ).innerHTML += tpl;
	
	restoreFields( ids, fieldtype, tab, k );
	
	document.getElementById( numof ).value = k + 1;
}


/**********************************************************************************************
Function : 	setTplElement( target, numof, tpl, ids, fieldtype )
Arguments :
		- target : where to insert the Tpl
		- numof : id of the hidden element containing the number of Tpl elements
			already inserted in the target
		- tpl : the template to insert
		- ids : the ids of the elements to save and restore
		- fieldtype : type of the elements to save and restore
Description :
		This function inserts a template element in a target containing other
		template elements and keeps data already inserted in the previous templates.
Date : 		May, 04th 2005
Author :	Julien Celle.
**********************************************************************************************/
function setTplElement( target, numof, tpl, ids, fieldtype )
{
	var k = parseInt( document.getElementById( numof ).value );
	var tab;
	
	tab = backupFields( numof, ids, fieldtype );
	
	document.getElementById( target ).innerHTML = tpl;
	
	restoreFields( ids, fieldtype, tab, k );
	
	document.getElementById( numof ).value = k + 1;
}


/**********************************************************************************************
Function : 	getSelectArray( i, base, size, tabtxt, tabvalues )
Arguments :
		- i : new id of the element to be concatenated with the 'base' name
		- base : base name of the element
		- size : width of the select element
		- tabtxt : label of the option element
		- tabvalues : value of the option element
Description :
		Build a 'select' HTML element form a list of text/values.
Date : 		May, 04th 2005
Author :	Julien Celle.
**********************************************************************************************/
function getSelectArray( i, base, size, tabtxt, tabvalues )
{
	var selectmods = '<select name="' + base + i + '" id="' + base + i + '" class="bordtxtsm" style="width:' + size + '">';
	
	var j;
	
	for( j = 0; j < tabtxt.length; j++ )
		selectmods += '<option value="' + tabvalues[j] + '">' + tabtxt[j] + '</option>';

	selectmods += '</select>';
		
	return selectmods;
}


/**********************************************************************************************
Function : 	getSelectArray( i, base, size, tabtxt, tabvalues )
Arguments :
		- i : new id of the element to be concatenated with the 'base' name
		- base : base name of the element
		- size : width of the select element
		- tabtxt : label of the option element
		- tabvalues : value of the option element
		- nvals : number of elements to display
Description :
		Build a 'select multiple' HTML element form a list of text/values.
Date : 		July, 11th 2005
Author :	Julien Celle.
**********************************************************************************************/
function getMultiSelectArray( i, base, size, tabtxt, tabvalues, nvals )
{
	var selectmods = '<select multiple name="' + base + i + '[]" id="' + base + i + '[]" class="bordtxtsm" size="' + nvals + '" style="width:' + size + '">\n';
	
	var j;
	
	for( j = 0; j < tabtxt.length; j++ )
		selectmods += '<option value="' + tabvalues[j] + '">' + tabtxt[j] + '</option>\n';

	selectmods += '</select>\n';
		
	return selectmods;
}


/**********************************************************************************************
Function : 	generateTplIndices( tpl, ind )
Arguments :
		- tpl : the template to parse
		- ind :	the replace string
Description :
		This function parses a string by looking for '&1' and replacing it by the 
		value of 'ind'. It then returns the newly created string.
Date : 		May, 04th 2005
Author :	Julien Celle.
**********************************************************************************************/
function generateTplIndices( tpl, ind )
{
	var t = new String( tpl );
	var re = new RegExp( "&1", "gi" );

	var ret = tpl.replace( re, ind );
	return ret;
}



/**********************************************************************************************
Function : 	removeTplElement( target, ids, fieldtype, numof, funcname, head, ind )
Arguments :
		- target : the target element where to remove from
		- ids : the 'id's of the elements to save, remove and add
		- fieldtype : the type of the elements to save, remove and add
		- numof : the 'id' of the hidden field containing the current number
			of elements present in the target
		- funcname : the name of the function to use to re-insert the elements
			that were not deleted
		- head : the header (first row of the table)
		- ind : the id of the element to delete.
Description :
		This function does the opposite of the 'addTplElement( )' function. It first 
		saves all the elements inserted in the target, then deletes everything and
		finally re-inserts all the elements but the one selected (ind) in the target
		container.
Date : 		May, 04th 2005
Author :	Julien Celle.
**********************************************************************************************/
function removeTplElement( target, ids, fieldtype, numof, funcname, head, ind )
{
	var i;
	
	var tab = backupFields( numof, ids, fieldtype );
	var newtab = new Array( tab.length - 1 );
	var count = 0;
	
	var fnAdd = new Function( funcname );
	
	for( i = 0; i < tab.length; i++ )
		if( i != ( parseInt( ind ) ) )
			newtab[count++] = tab[i];
	
	document.getElementById( target ).innerHTML = head;
	document.getElementById( numof ).value = 0;
	
	for( i = 0; i < newtab.length; i++ )
		fnAdd( );
			
	restoreFields( ids, fieldtype, newtab, newtab.length );
}

/**********************************************************************************************
Function : 	newWindow( href, title, w, h, x, y, opts )
Arguments :
		- href : URL of the window to open
		- title : title of the new window
		- w : width of the window
		- h : height of the window
		- x : x position of the window
		- y : y position of the window
		- opts : options for the window
Description :
		Wrapper for the 'window.open' javascript function. It allows some flexibility
		and to move and resize the window at the same time. Might be useful for future
		improvements.
Date : 		May, 18th 2005
Author :	Julien Celle.
**********************************************************************************************/
function newWindow( hr, tit, w, h, x, y, opts )
{
	if( opts == '' )
		opts = 'toolbar=no,directories=no,menubar=no,resizable=no,scrollbars=yes,status=no';
	var fullopts = opts + ',width=' + w + ',height=' + h;
	var win = window.open( hr, tit, fullopts );
	win.moveTo( x, y );
	
	return win;
}



/**********************************************************************************************
Function : 	displayDiv( divid, divlist )
Arguments :
		- divid : the id of the 'div' element to display
		- divlist : an array of 'div' to which the 'divid' element belongs
Description :
		This function sets visible (style="display:block") of a 'div' element 
		and hides (style="display:none") the other elements of the array.
Date : 		May, 19th 2005
Author :	Julien Celle.
**********************************************************************************************/
function displayDiv( divid, divlist )
{
	for( var i = 0; i < divlist.length; i++ )
	{
		if( divlist[i] != divid )
			document.getElementById( divlist[i] ).style.display = 'none';
		else
			document.getElementById( divid ).style.display = 'block';
	}
}



/**********************************************************************************************
Function : 	swapImg( divid, divlist )
Arguments :
		- divid : the id of the 'img' element to display
		- divlist : an array of 'img' to which the 'divid' element belongs
Description :
		This function swaps the display image of an 'img' element between 'on' and 'off'.
		Images must be named according to the following reference :
			basename_[on|off].extension
		It also sets the style and the 'onClick' action of the 'img' element depending
		on its being selecting or not.
Date : 		May, 19th 2005
Author :	Julien Celle.
**********************************************************************************************/
function swapImg( divid, divlist )
{
	var basename = '';
	var swapname = '';
	var extension = '';
	var liop = 0;
	var liou = 0;
	
	for( var i = 0; i < divlist.length; i++ )
	{
		basename = document.getElementById( divlist[i] ).src;
		liop = basename.lastIndexOf( '.', basename.length );
		extension = basename.slice( liop, basename.length );
		swapname = basename.slice( 0, liop - 1 );
		liou = swapname.lastIndexOf( '_', swapname.length );
		swapname = swapname.slice( 0, liou );

		if( divlist[i] != divid )
		{
			swapname = swapname.concat( '_off' + extension );
			document.getElementById( divlist[i] ).onClick = 'javascript:swapImg( divlist[i], ERRORTITLEIMGS );';
			document.getElementById( divlist[i] ).className = 'cursor';
		}
		else
		{
			swapname = swapname.concat( '_on' + extension );
			document.getElementById( divlist[i] ).onClick = '';
			document.getElementById( divlist[i] ).className = '';
		}
		
		document.getElementById( divlist[i] ).src = swapname;
	}
}


/**********************************************************************************************
Function : 	modifyParam( param, val )
Arguments :
		- param : the parameter to modify
		- val : the new value of the parameter
Description :
		This function modifies a parameter's value that is located in the search parameters
		of the web page (page.php?param1=value1&param2=value2 ...). If the parameter already
		exists in this string, the value will be modified. If it doesn't exist, the parameter
		will be added to the search string.
Date : 		May, 24th 2005
Author :	Julien Celle.
**********************************************************************************************/
function modifyParam( param, val )
{
	if( window.location.search.length > 0 )
	{
		var str = window.location.search.substr( 1 );
		var params = str.split( '&' );
		var i = str.indexOf( param + '=' );
		var ret = '';
		
		var sep = '?';
		
		for( var j = 0; j < params.length; j++ )
		{
			var tmp = params[j].split( '=' );
			
			if( ( tmp[0] == param ) || ( tmp[0] == 'page' ) )
				continue;
			
			ret += sep + tmp[0] + '=' + tmp[1];
			
			sep = '&';
		}
		
		ret += sep + param + '=' + val;
	}
	else
		ret = '?' + param + '=' + val;
	
	return ret;	
}




/**********************************************************************************************
Function : 	loginStudy( )
Arguments :
		- none
Description :
		This function performs basic check for a login form :
			* Login field cannot be empty.
			* Password field cannot be empty.
Date : 		June, 06th 2005
Author :	Julien Celle.
**********************************************************************************************/
function loginStudy( )
{
	if( document.getElementById( 'login' ).value == '' )
	{
		alert( 'Error : Login cannot be empty.' );
		return false;
	}
	if( document.getElementById( 'passwd' ).value == '' )
	{
		alert( 'Error : Password cannot be empty.' );
		return false;
	}
	
	document.getElementById( 'halidon' ).value = HALIDON_POSTED_VALUE;
	document.forms.formulaire.submit( );
	
	return true;
}


/**********************************************************
* You may use this code for free on any web page provided that 
* these comment lines and the following credit remain in the code.
* Floating Div from http://www.javascript-fx.com
* To use, add "JSFX_FloatDiv( idelt, startx, starty );"
* Coordinates from top right
*********************************************************/
/**********************************************************************************************
Function : 	JSFX_FloatDiv( elt, sx, sy )
Arguments :
		- elt : the 'floating' element
		- sx : shift from right
		- sy : shift from top
Description :
		This function allows an element to 'float' on the page. Whether the user scrolls
		or not, this element will always be visible sx pixels from the right border and
		sy pixels from the top border. This function was taken from http://www.javascript-fx.com
Date : 		June, 06th 2005
Author :	Julien Celle.
**********************************************************************************************/
function JSFX_FloatDiv( elt, sx, sy )
{
	var startX = sx, startY = sy;
	var ns = (navigator.appName.indexOf("Netscape") != -1);
	var d = document;
	var px = document.layers ? "" : "px";
	function ml(id)
	{
		var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
		if(d.layers)el.style=el;
		el.sP=function(x,y){this.style.right=x+px;this.style.top=y+px;};
		el.x = startX; el.y = startY;
		return el;
	}
	window.floatdiv=function()
	{
		var pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
		ftlObj.y += (pY + startY - ftlObj.y)/8;
		ftlObj.sP(ftlObj.x, ftlObj.y);
		setTimeout("floatdiv()", 40);
	}
	ftlObj = ml( elt );
	floatdiv();
}



/**********************************************************************************************
Function : 	postWks( i )
Arguments :
		- i : the new workflow state of the element.
Description :
		Specific function for the 'Animage Study Follow-up Tool'. It sets the new workflow_state
		value for the element and performs some activation form 'select' form elements.
Date : 		June, 06th 2005
Author :	Julien Celle.
**********************************************************************************************/
function postWks( i )
{
	var fname = '';
	/*var lists = Array( 'form_protocole-list[]', 'form_fiche_projet-id__user[]' );
	document.getElementById( 'form_etude-id__workflow_state' ).value = i;*/
	var lists = null;
	
	for( var l = 0; l < lists.length; l++ )
	{
		if( document.getElementById( lists[l] ) != null )
		{
			if( lists[l] == 'form_protocole-list[]' )
			{
				//fname = 'form_protocole-list[]';
				removeFrom( 'pkgom[]' );
				removeFrom( 'protodetail[]' );
			}		
			
			for( var z = 0; z < document.getElementById( lists[l] ).length; z++ )
			{
				if( document.getElementById( lists[l] ).options[z].disabled != true )
					document.getElementById( lists[l] ).options[z].selected = true;
			}
		}
	}
	document.getElementById( 'halidon' ).value = HALIDON_POSTED_VALUE;		
	document.forms.formulaire.submit( );
}


/**********************************************************************************************
Function : 	checkKey( e, t, f )
Arguments :
		- e : the event element
		- t : the type of the element
		- f : the element name
Description :
		This function checks the key pressed by the user for certain types of form elements
		so that types are not mismatched.
Date : 		June, 06th 2005
Author :	Julien Celle.
**********************************************************************************************/
function checkKey( e, t, f )
{
	var val = 0;
	if( navigator.appName == 'Netscape' )
		val = e.charCode;
	else
		val = e.keyCode;

	var good = true;
	
	if( val == 0 ) 
		return true;
		
	switch( t )
	{
	case 'float':
		if( ( ( val < 48 ) || ( val > 57 ) ) && ( val != 46 ) )
		{
			good = false;
			alert( 'This field can only contain \'float\' numerical values' );
		}
		break;
	case 'int':
		if( ( val < 48 ) || ( val > 57 ) )
		{
			good = false;
			alert( 'This field can only contain \'integer\' numerical values' );
		}
		break;
	case 'str':
		if( ( ( val < 65 ) || ( val > 90 ) ) && ( ( val < 97 ) || ( val > 122 ) ) && ( val != 32 ) )
		{
			good = false;
			alert( 'This field can only contain \'alphabetical\' values (no accents)' );
		}
		break;
	case 'moddays':
		var msg = 'Values in this field must be wrtitten as this : "JXX JXX JXX" \n where X represents a number and with spaces delimit acquisitions days.';
		var v = document.getElementById( f ).value;
		
		if( ( val < 48 ) || ( val > 57 ) )
		{
			if( val == 32 )
			{
				if( ( v.length < 1 ) || ( ( v.charCodeAt( v.length - 1 ) < 48 ) && ( v.charCodeAt( v.length - 1 ) > 57 ) ) )
				{
					alert( msg );
					good = false;
				}
				
			}
			else if( ( val == 74 ) || ( val == 106 ) )
			{
				if( ( v.length > 0 ) && ( v.charCodeAt( v.length - 1 ) != 32 ) )
				{
					alert( msg );
					good = false;
				}
			}
			else
			{
				alert( msg );
				good = false;
			}
		}
		else
		{
			var lc = v.charCodeAt( v.length - 1 );
			
			if( ( v.length < 1 ) || ( ( lc != 74 ) && ( lc != 106 ) && ( ( lc < 48 ) || ( lc > 57 ) ) ) )
			{
				alert( msg );
				good = false;
			}
		}
		break;
	default:
		break;
	}
	
	if( good == false )
	{
		e.returnValue = false;
		e.cancel = true;
	}
	
	return good;
}

function getKeyCode( e )
{
	var val = 0;
	
	if( navigator.appName == 'Netscape' )
		val = e.charCode;
	else
		val = e.keyCode;
		
	alert( val );
}

/**********************************************************************************************
Function : 	toggleState( name )
Arguments :
		- name : the name of the targeted element
Description :
		Toggles the 'display' attribute of a 'div' element (block/none) and
		the visualization of the image associated (plus/moins).
Date : 		June, 10th 2005 
Author :	Julien Celle.
**********************************************************************************************/
function toggleState( name )
{
	if( document.getElementById( 'div' + name ).style.display == 'block' ) 
	{
		document.getElementById( 'div' + name ).style.display = 'none';
		document.getElementById( 'im' + name ).src = 'images/plus.gif';
	}
	else
	{
		document.getElementById( 'div' + name ).style.display = 'block';
		document.getElementById( 'im' + name ).src = 'images/moins.gif';
	}
}


/**********************************************************************************************
Function : 	checkSelectable( elt )
Arguments :
		- elt : the id of the element to check.
Description :
		Special function for IE. 
		The 'disabled' option of an "<option>" tag is not implemented under IE.
		"
			The disabled attribute can be set and retrieved. 
			However, the functionality specified by the HTML 4.0 standard is not implemented 
			for this property. There is no functionality implemented for this property unless 
			defined by the author.
		" -> http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/disabled_3.asp
		
		Thus, addition check must be made in this case.
		Something cleaner could surely be done, but it works ...
Date : 		June, 20th 2005 
Author :	Julien Celle.
**********************************************************************************************/
function checkSelectable( elt )
{
	if( document.getElementById( elt ) && ( ( document.getElementById( elt ).type == 'select-one' ) ||( document.getElementById( elt ).type == 'select-multiple' ) ) )
	{
		document.getElementById( elt ).blur( );
		document.getElementById( elt ).focus( );
		if( document.getElementById( elt ).selectedIndex >= 0 )
		{
			if( document.getElementById( elt ).options[document.getElementById( elt ).selectedIndex].disabled == true )
			{
				document.getElementById( elt ).options[document.getElementById( elt ).selectedIndex].selected = false;
				document.getElementById( elt ).selectedIndex = -1;
			}
		}
	}
}

function checkEmptyFormFields( )
{
	var reqfields = new Array( 'form_projet-titre', 'form_projet_porteur-prenom', 'form_projet_porteur-nom', 'form_projet_porteur-tel', 'form_projet_porteur-fax', 'form_projet_porteur-email', 'form_projet_porteur-dirlabo', 'form_projet_porteur-etablissement', 'form_projet_porteur-adresse_etablissement', 'form_projet_porteur-cp', 'form_projet_porteur-ville', 'form_projet-cv_expo', 'form_projet-resume', 'form_projet-mots_clefs', 'form_projet-start_date' );
	var aliases = new Array( 'Titre', 'Prénom', 'Nom', 'Téléphone', 'Fax', 'EMail', 'Directeur du laboratoire', 'Etablissement', 'Adresse', 'Code postal', 'Ville', 'CV Exposant', 'Résumé', 'Mots clefs', 'Dâte de début'  );
	
	for( var i = 0; i < reqfields.length; i++ )
	{
		var elt = document.getElementById( reqfields[i] );
		if( elt.value == '' )
		{
			alert( 'Le champ ' + aliases[i] + ' est vide. Merci de le renseigner.' );
			return false;
		}
	}
		
	return true;
}


function postProjetForm( )
{
	if( !checkEmptyFormFields( ) )
		return false;
	else
	{
		document.getElementById( 'halidon' ).value = HALIDON_POSTED_VALUE;
		document.forms.formulaire.submit( );
		
		return true;
	}
}

function checkSelects( )
{
	var elts = document.forms.formulaire.elements;
	var l = elts.length;
	
	for( i = 0; i < l; i++ )
	{
		if( elts[i].type == 'select-one' )
			if( elts[i][elts[i].selectedIndex].value == '-2' )
			{
				alert( 'Certains éléménts n\'ont pas été sélectionnés.' );
				return false;
			}
	}
	
	return true;
}


function postIt( )
{
	if( checkSelects( ) )
	{
		document.getElementById( 'halidon' ).value = HALIDON_POSTED_VALUE;
		document.forms.formulaire.submit( );
		return true;
	}
	
	return false;
	
}
function suppIt( )
{
        if( checkSelects( ) )
        {
                document.getElementById( 'halidonsupp' ).value = HALIDON_POSTED_VALUE;
                document.forms.formulaire.submit( );
                return true;
        }

        return false;

}

