// +----------------------------------------------------------------------------+
// | <G a n e s h a> - Free Web Based Training System                           |
// +----------------------------------------------------------------------------+
// | <G a n e s h a> - Plate-forme de téléformation gratuite et en open source  |
// +----------------------------------------------------------------------------|
// | Copyright (C) 2000-2003  Anéma Formation  <http://www.anema.fr/>           |
// +----------------------------------------------------------------------------+
// |           Developer : Georges CALDEIRA <gcaldeira@anemalab.org>            |
// +----------------------------------------------------------------------------+
// |              Infos on project <http://anemalab.org/>                       |
// +----------------------------------------------------------------------------+
// | This program is free software; you can redistribute it and/or modify       |
// | it under the terms of the GNU General Public License as published by       |
// | the Free Software Foundation; either version 2 of the License, or          |
// | (at your option) any later version.                                        |
// |                                                                            |
// | This program is distributed in the hope that it will be useful,            |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of             |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              |
// | GNU General Public License for more details.                               |
// |                                                                            |
// | You should have received a copy of the GNU General Public License          |
// | along with this program; if not, write to the Free Software                |
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA   |
// +----------------------------------------------------------------------------+


	/*********************************************************/
	function VerifSearch(form) {	
		if ( form.search.value=="" ) {		
			alert (lang[0]);		
			form.search.focus();		
			return ;	
		}	
		form.submit();
	}
	
	/*********************************************************/
	function VerifPost(form) {	
		if ( form.author.value=="" ) {		
			alert (lang[1]);		
			form.author.focus();		
			return ;	
		}	
		if ( form.subject.value=="" ) {		
			alert (lang[2]);		
			form.subject.focus();		
			return ;	
		}	
		if ( form.body.value=="" ) {		
			alert (lang[3]);		
			form.body.focus();		
			return ;	
		}	
		form.submit();
	}
	
	/*********************************************************/
	function VerifSearch(form) {	
		if ( form.search.value=="" ) {		
			alert (lang[0]);		
			form.search.focus();		
			return ;	
		}	
		form.submit();
	}
	
	/*********************************************************/
	function ValiderFormFiche(form){   
		if (form.nom.value == "" )   {       
			alert (lang[4]);       
			form.nom.focus();       
			return;   
		}      
		if (form.prenom.value == "" )   {       
			alert (lang[5]);       
			form.prenom.focus();       
			return;   
		}      
		if (form.adresse.value == "" )   {       
			alert (lang[6]);       
			form.adresse.focus();       
			return;   
		}      
		if (form.cp.value == "" )   {       
			alert (lang[7]);       
			form.cp.focus();       
			return;   
		}      
		if (form.ville.value == "" )   {       
			alert (lang[8]);       
			form.ville.focus();       
			return;   
		}      
		if (form.login.value == "" )   {       
			alert (lang[9]);       
			form.login.focus();       
			return;   
		}   
		form.submit();
	}

	function ValiderFormPassword(form){   
		if (form.pwd.value == "" )   {       
			alert (lang[10]);       
			form.pwd.focus();       
			return;   
		}   
		if (form.pwd2.value == "" )   {       
			alert (lang[11]);       
			form.pwd2.focus();       
			return;   
		}   
		if (form.pwd.value != form.pwd2.value)   {       
			alert (lang[12]);       
			form.pwd2.focus();       
			return;   
		}  
		form.submit();
	}

	/*********************************************************/
	function ValiderFormQuestion(form){   
		if (form.prenom.value == "" )   {       
			alert (lang[5]);       
			form.prenom.focus();       
			return;   
		}   
		if (form.nom.value == "" )   {       
			alert (lang[4]);       
			form.nom.focus();       
			return;   
		}   
		if (form.subject.value == "" )   {       
			alert (lang[2]);       
			form.subject.focus();       
			return;   
		}   
		if (form.message.value == "" )   {
			alert (lang[3]);       
			form.message.focus();       
			return;   
		}   
		form.submit();
	}

	/*********************************************************/
	function ValiderFormMsg(form){   
		if (form.object_wm.value == "" )   {       
			alert (lang[2]);       
			form.object_wm.focus();       
			return;   
		}   	
		if (form.Message.value == "" )   {       
			alert (lang[3]);       
			form.Message.focus();       
			return;   
		}   
		form.submit();
	}

	/*********************************************************/  
	function ValiderFormPlanning(form)  {    
		if (form.fichier.value == "" )    {	   
			alert (lang[14]);	   
			form.fichier.focus();	   
			return;    
		}    
		form.submit();  
	}
	
	/*********************************************************/  
	function ValiderFormFile(form)  {    
		if (form.titre.value == "" )    {	   
			alert (lang[15]);	   
			form.titre.focus();	   
			return;    
		}        
		if (form.fichier.value == "" )    {	   
			alert (lang[16]);	   
			form.fichier.focus();	   
			return;    
		}    
		form.submit();  
	}
	
	/*********************************************************/
	function ValiderFormComment(form)  {    
		if (form.comment.value == "" )    {	   
			alert (lang[17]);	   
			form.comment.focus();	   
			return;    
		}    
		form.submit();  
	}
	
	/*********************************************************/  
	function DeleteFile(url)  {    
		ans=window.confirm(lang[18]);    
		if(ans)	{      
			window.location.replace(url);    
		}  
	}
	
	/*********************************************************/
	function openWindow(theURL,winName,features) {  
		window.open(theURL,winName,features);
	}
	
	/*********************************************************/
	function DeleteMessage(url){    
		ans=window.confirm(lang[19]);    
		if(ans){ window.location.replace(url);}
	}


/*********************************************************/
function setPointer(theRow, theAction, theDefaultColor, thePointerColor) {
    var theCells = null;

    if ( thePointerColor == '' || typeof(theRow.style) == 'undefined' ) {
        return false;
    }

    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor = thePointerColor;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()) {
        if (theAction == 'out') {
            newColor = theDefaultColor;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
};






/***********************************************************************/
/**
* modifications Eric Villard <evillard@nef.fr>
* ajout de fonctions javascript
*/

/**
* change the action of a form
* @param	string	theForm		name of the form
* @param	string	theAction	new action
*/
function changeFormAction (theForm, theAction ) {
	theForm.action = theAction;
	theForm.submit();
}

/**
* select or deselect all the options in a select tag of a form
* @param	object	name	the select tag
* @param	boolean	flag	true : select, false : deselect
*/
function selectAll(name, flag) {
	lim = name.length;
	for (var i=0; i<lim; i++) {
		name.options[i].selected=flag;
	}
}

/**
* fonctions de validations des formulaires de gestion d'évaluations annexes
*/
// création d'évaluations
function validerCreeval(form){   
	if (form.text0.value == "" )   {       
		alert (lang[20]);    
		form.text0.focus();       
		return;   
	}     
	if (form.textarea1.value == "" )   {       
		alert (lang[21]);       
		form.textarea1.focus();       
		return;   
	}     
	form.submit();
}
// modification d'évaluations
function validerModifeval(form){ 
	if (form.LEval.value == 0 )   {       
		alert (lang[22]);    
		form.LEval.focus();       
		return;   
	}      
	if (form.text0.value == "" )   {       
		alert (lang[20]);    
		form.text0.focus();       
		return;   
	}     
	if (form.textarea1.value == "" )   {       
		alert (lang[21]);       
		form.textarea1.focus();       
		return;   
	}     
	form.submit();
}
// suppression d'évaluations
function validerSuppreval(form){ 
	if (form.elements[0].value == "" )   {       
		alert (lang[23]);     
		return;   
	}     
	form.submit();
}
// assignation d'évaluations
function validerAssigneval(form){ 
	if (form.elements[1].value == "" )   {       
		alert (lang[24]);          
		return;   
	}    
	if (form.elements[4].value == "" )   {       
		alert (lang[25]);          
		return;   
	} 
	form.submit();
}
// suppression de session
function validerSupprSession(form){ 
	if (form.elements[1].value == 0 )   {       
		alert (lang[26]);          
		return;   
	}    
	if (form.elements[2].value == "" )   {       
		alert (lang[27]);           
		return;   
	} 
	form.submit();
}
// création de rapports d'évaluations
function validerCrerap(form){ 
	// évaluations
	if (form.LEval.value == 0 )   {       
		alert (lang[22]);    
		form.LEval.focus();       
		return;   
	}
	// stagiaire
	if (form.LStagiaire.value == 0 )   {       
		alert (lang[26]);    
		form.LStagiaire.focus();       
		return;   
	} 
	// tuteur
	if (form.LTuteur.value == 1 )   {       
		alert (lang[28]);    
		form.LTuteur.focus();       
		return;   
	} 
	// date
	// jour 
	if (form.text1.value == "" )   {       
		alert (lang[29]);  
		form.text1.focus();       
		return;   
	} else if (parseInt(form.text1.value) > 31 || parseInt(form.text1.value) < 1 || isNaN(parseInt(form.text1.value))) {
		alert (lang[30]); 
		form.text1.value = "";
		form.text1.focus();       
		return;  
	}
	// mois
	if (form.text2.value == "" )   {       
		alert (lang[31]);  
		form.text2.focus();       
		return;   
	} else if (parseInt(form.text2.value) > 12 || parseInt(form.text2.value) < 1 || isNaN(parseInt(form.text2.value))) {
		alert (lang[32]);
		form.text2.value = ""; 
		form.text2.focus();       
		return;  
	}
	// année
	if (form.text3.value == "" )   {       
		alert (lang[33]);  
		form.text3.focus();       
		return;   
	} else if (parseInt(form.text3.value) < 1900 || isNaN(parseInt(form.text3.value))) {
		alert (lang[34]); 
		form.text3.value = ""; 
		form.text3.focus();       
		return;  
	}
	// temps
	// heures
	if (form.text5.value == "" || parseInt(form.text5.value) < 0)   {       
		form.text5.value = 0;  
	} else if (isNaN(parseInt(form.text5.value))) {
		alert (lang[35]); 
		form.text5.value = ""; 
		form.text5.focus();       
		return;  
	}
	// minutes
	if (form.text6.value == "" || parseInt(form.text6.value) < 0)   {       
		form.text6.value = 0; 
	} else if (isNaN(parseInt(form.text6.value))) {
		alert (lang[36]); 
		form.text6.value = ""; 
		form.text6.focus();       
		return;  
	} else if (parseInt(form.text6.value) > 59) {
		form.text5.value = parseInt(form.text5.value)+1;
		form.text6.value = parseInt(form.text6.value)-60; 
	}
	form.submit();
}
// création de rapports d'évaluations
function validerModifrap(form){
	// stagiaire
	if (form.LStagiaire.value == 0 )   {       
		alert (lang[26]);    
		form.LStagiaire.focus();       
		return;   
	} 
	// évaluations
	if (form.LEval.value == 0 )   {       
		alert (lang[22]);    
		form.LEval.focus();       
		return;   
	} 
	// tuteur
	if (form.LTuteur.value == 1 )   {       
		alert (lang[28]);    
		form.LTuteur.focus();       
		return;   
	}
	// date
	// jour 
	if (form.text1.value == "" )   {       
		alert (lang[29]);  
		form.text1.focus();       
		return;   
	} else if (parseInt(form.text1.value) > 31 || parseInt(form.text1.value) < 1 || isNaN(parseInt(form.text1.value))) {
		alert (lang[30]); 
		form.text1.value = "";
		form.text1.focus();       
		return;  
	}
	// mois
	if (form.text2.value == "" )   {       
		alert (lang[31]);  
		form.text2.focus();       
		return;   
	} else if (parseInt(form.text2.value) > 12 || parseInt(form.text2.value) < 1 || isNaN(parseInt(form.text2.value))) {
		alert (lang[32]);
		form.text2.value = ""; 
		form.text2.focus();       
		return;  
	}
	// année
	if (form.text3.value == "" )   {       
		alert (lang[33]);  
		form.text3.focus();       
		return;   
	} else if (parseInt(form.text3.value) < 1900 || isNaN(parseInt(form.text3.value))) {
		alert (lang[34]); 
		form.text3.value = ""; 
		form.text3.focus();       
		return;  
	}
	// temps
	// heures
	if (form.text5.value == "" || parseInt(form.text5.value) < 0)   {       
		form.text5.value = 0;  
	} else if (isNaN(parseInt(form.text5.value))) {
		alert (lang[35]); 
		form.text5.value = ""; 
		form.text5.focus();       
		return;  
	}
	// minutes
	if (form.text6.value == "" || parseInt(form.text6.value) < 0)   {       
		form.text6.value = 0; 
	} else if (isNaN(parseInt(form.text6.value))) {
		alert (lang[36]); 
		form.text6.value = ""; 
		form.text6.focus();       
		return;  
	} else if (parseInt(form.text6.value) > 59) {
		form.text5.value = parseInt(form.text5.value)+1;
		form.text6.value = parseInt(form.text6.value)-60; 
	}
	form.submit();
}
// suppression d'évaluations
function validerSupprrap(form){ 
	if (form.elements[1].value == 0 )   {       
		alert (lang[26]);          
		return;   
	}  
	if (form.elements[2].value == "" )   {       
		alert (lang[37]);          
		return;   
	}     
	form.submit();
}

	/*********************************************************/
	function ValidCreateDirectory(form) {
		if ( form.directory.value == '' ) {
			alert(lang[40]);
			form.directory.focus();
			return(false);
		}
		form.submit();
	}
	
	/*********************************************************/
	function VerifMail(form) {
		var adresse = form.email.value	;	
		if (adresse == "" )   {       
			alert (lang[55]);       
			form.email.focus();       
			return;   
		}  
		var place   = adresse.indexOf("@",1);
		var point   = adresse.indexOf(".",place+1);
		if ((place > -1)&&(adresse.length >2)&&(point > 1)) {
			return(true);
		} else {
			alert(lang[54]);
			form.email.focus();
			return(false);    
		}
	}
	
	/*********************************************************/
	function ValiderFormInscr(form){   
		if (form.nom.value == "" )   {       
			alert (lang[4]);       
			form.nom.focus();       
			return;   
		}      
		if (form.prenom.value == "" )   {       
			alert (lang[5]);       
			form.prenom.focus();       
			return;   
		}      
		if ( ! VerifMail(form) ) {
			return;
		}
		if (form.adresse.value == "" )   {       
			alert (lang[6]);       
			form.adresse.focus();       
			return;   
		}      
		if (form.cp.value == "" )   {       
			alert (lang[7]);       
			form.cp.focus();       
			return;   
		}      
		if (form.ville.value == "" )   {       
			alert (lang[8]);       
			form.ville.focus();       
			return;   
		}      
		form.submit();
	}	
	
	/*********************************************************/
	function verifcode(form) {
		if ( form.code.value == '' ) {
			alert(lang[49]);
			form.code.focus();
			return(false);
		}
		form.submit();
	}	