// Fichier de fonction javascript

function test_abondance(abond_tot,abond_1,abond_2)
{
	with(abond_tot.form)
	{
		if ( eval(abond_1.value) + eval(abond_2.value) > eval(abond_tot.value) )
		{
			alert('La somme des abondances = '+(eval(abond_1.value) + eval(abond_2.value))+' ne peut etre superieure à l\'abondance totale ='+abond_tot.value);
			abond_1.value = '';
			abond_2.value = '';
		}
	}
}

function test_group(champ)
{
 with( champ.form )
 {
         if ((CLASSIF_P.selectedIndex != 1) && (CLASSIF_P.selectedIndex != 5))
         {
	        alert ("Le champ Numéro de groupe ne peut être renseigné car la classification de référence n'est pas égale à CPCS ou à WRB");
	       GROUPE.value='';
         }
 }
}

function initialise_classif(champ)
{
 with( champ.form )
 {
        GROUPE.value='';
        RPF_P.value='';
 }
}


function test_RPF(champ)
{
 with( champ.form )
 {
         if (CLASSIF_P.selectedIndex != 7)
         {
	       alert ("Le champ Nom RP ne peut être renseigné car la classification de référence n'est pas égale à 7");
	       RPF_P.value='';
         }
 }
}


function windows_organisme_test(frame_champ, path_recherche, liste, champ, champ1, champ2, champ3, champ4,nom)
{
	var res = test_ordre_remplissage_text(champ, champ1, champ2, champ3, champ4,nom);
	if ( res == 0 )
	{
		windows_organisme(frame_champ, path_recherche, liste);
	}
}

function verif_champ_differenciation (champ, nom_diff,index)
{
	with ( champ.form )
    {
		if ( champ.selectedIndex != 0 && champ.selectedIndex != "" )
		{
			if( DIFFER1.selectedIndex != (index + 2) && DIFFER2.selectedIndex != index && DIFFER3.selectedIndex != index && DIFFER4.selectedIndex != index )  
			{
				alert('ERREUR : Vous ne pouvez saisir la differenciation 2ème '+nom_diff+' car celle-ci n\'a pas été choisie dans les différenciations');
				champ.selectedIndex = 0;
			}
		}
	}
}

function verif_cara (champ, type)
{
         with ( champ.form )
         {
			if ( type == 'profil' )
			{
            	verif_champ_differenciation(DIFFER_TEXT_P,'TEXTURE',1);
                verif_champ_differenciation(DIFFER_CHARG_P,'CHARGE',2);
                verif_champ_differenciation(DIFFER_EFFERV_P,'EFFERVESCENCE',3);
                verif_champ_differenciation(DIFFER_SALURE_P,'SALURE',4);
                verif_champ_differenciation(DIFFER_COUL_P,'COULEUR',5);
                verif_champ_differenciation(DIFFER_STRUC_P,'STRUCTURE',6);
                verif_champ_differenciation(DIFFER_COMPAC_P,'COMPACITE',7);
                verif_champ_differenciation(DIFFER_PERMEA_P,'PERMEABILITE',8);
			}
			else if ( type == 'usol' )
			{
           		verif_champ_differenciation(DIFFER_TEXT,'TEXTURE',1);
                verif_champ_differenciation(DIFFER_CHARG,'CHARGE',2);
                verif_champ_differenciation(DIFFER_EFFERV,'EFFERVESCENCE',3);
                verif_champ_differenciation(DIFFER_SALURE,'SALURE',4);
                verif_champ_differenciation(DIFFER_COUL,'COULEUR',5);
                verif_champ_differenciation(DIFFER_STRUC,'STRUCTURE',6);
                verif_champ_differenciation(DIFFER_COMPAC,'COMPACITE',7);
                verif_champ_differenciation(DIFFER_PERMEA,'PERMEABILITE',8);
			}
         }
}



function test_dif_egal(champ)
{
         with (champ.form )
         {
              if ((champ==DIFFER1)
                 &&((champ.selectedIndex==DIFFER2.selectedIndex + 2 && DIFFER2.selectedIndex != 0 && DIFFER2.selectedIndex != "")
                 ||(champ.selectedIndex==DIFFER3.selectedIndex  + 2 && DIFFER3.selectedIndex != 0 && DIFFER3.selectedIndex != "")
                 ||(champ.selectedIndex==DIFFER4.selectedIndex  + 2 && DIFFER4.selectedIndex != 0 && DIFFER4.selectedIndex !="")))
              {
                 alert('La differenciation 1 ne peut avoir la même valeur que les autres differenciations') ;
                 DIFFER1.selectedIndex=0 ;
                 DIFFER1.focus() ;
              }
              else if ((champ==DIFFER2)
                     &&((champ.selectedIndex==DIFFER1.selectedIndex - 2 && DIFFER1.selectedIndex != 0 && DIFFER1.selectedIndex != "" && DIFFER1.selectedIndex != 2)
                     ||(champ.selectedIndex==DIFFER3.selectedIndex && DIFFER3.selectedIndex != 0 && DIFFER3.selectedIndex != "")
                     ||(champ.selectedIndex==DIFFER4.selectedIndex && DIFFER4.selectedIndex != 0 && DIFFER4.selectedIndex !="")))
              {
                     alert('La differenciation 2 ne peut avoir la même valeur que les autres differenciations') ;
                     DIFFER2.selectedIndex=0 ;
                     DIFFER2.focus() ;
              }
              else if ((champ==DIFFER3)
                         &&((DIFFER1.selectedIndex==champ.selectedIndex +2 && DIFFER1.selectedIndex != 0 && DIFFER1.selectedIndex != "" && DIFFER1.selectedIndex != 2)
                         ||(DIFFER2.selectedIndex==champ.selectedIndex && DIFFER2.selectedIndex != 0 && DIFFER2.selectedIndex != "")
                         ||(DIFFER4.selectedIndex==champ.selectedIndex && DIFFER4.selectedIndex != 0 && DIFFER4.selectedIndex !="")))
              {
                         alert('La differenciation 3 ne peut avoir la même valeur que les autres differenciations');
                         DIFFER3.selectedIndex=0 ;
                         DIFFER3.focus() ;
              }
              else if ((champ==DIFFER4)
                      &&((DIFFER1.selectedIndex==champ.selectedIndex +2 && DIFFER1.selectedIndex != 0 && DIFFER1.selectedIndex != "" && DIFFER1.selectedIndex != 2)
                      ||(DIFFER2.selectedIndex==champ.selectedIndex && DIFFER2.selectedIndex != 0 && DIFFER2.selectedIndex != "")
                      ||(DIFFER3.selectedIndex==champ.selectedIndex && DIFFER3.selectedIndex != 0 && DIFFER3.selectedIndex != "")))
              {
                      alert('La differenciation 4 ne peut avoir la même valeur que les autres differenciations') ;
                      DIFFER4.selectedIndex=0 ;
                      DIFFER4.focus() ;
              }
          
         }
}

function test_dif1 (champ)
{
    with (champ.form )
    {

         if (champ==DIFFER1 && champ.selectedIndex <= 2)
         {
                alert('Attention! Vous avez rentré une différenciation principale inférieure ou égale à 1! Vous ne pourrez donc pas rentrer les autres différenciations!') ;
                DIFFER2.selectedIndex=0 ;
                DIFFER3.selectedIndex=0 ;
                DIFFER4.selectedIndex=0 ;
                DIFFER1.focus() ;
        }
        else if ((champ==DIFFER2)&&(DIFFER1.selectedIndex <= 2))
        {
                alert('Impossible la différenciation 1 est inférieur ou égale à 1 ') ;
                DIFFER2.selectedIndex=0 ;
                DIFFER1.focus() ;
        }
        else if ((champ==DIFFER3)&&(DIFFER1.selectedIndex <= 2))
        {
                        alert('Impossible la différenciation 1 est inférieur ou égale à 1 ') ;
                        DIFFER3.selectedIndex=0 ;
                        DIFFER1.focus() ;
        }
        else if ((champ==DIFFER4)&&(DIFFER1.selectedIndex <= 2))
        {
             alert('Impossible la différenciation 1 est inférieur ou égale à 1 ') ;
             DIFFER4.selectedIndex=0 ;
             DIFFER1.focus() ;
        }
     }
}

function test_nb_us(champ)
{
	with (champ.form)
	{
		if ( eval(champ.value) == 1 )
		{ 
			ORGAN_UC_US.selectedIndex = 1;
		}
		else 
		{ 
			ORGAN_UC_US.selectedIndex=0;
		}
	}
}

function test_organ_uc_us(champ) 
{
	with (champ.form)
	{
		if ( NB_US.value == "" || eval(NB_US.value) == 0 ) 
		{
			alert('Veuillez d\'abord renseigner le nombre d\'UTS pr\u00e9sent dans l\'UCS !') ;
    		champ.selectedIndex = 0;
    		NB_US.focus() ;
		}
		else if ( eval(NB_US.value) == 1) 
		{
			alert('Vous ne pouvez pas modifier cette valeur !') ;
    		champ.selectedIndex = 1;
    	}
		else if ( eval(NB_US.value) != 1 && champ.selectedIndex == 1) 
		{
			alert('Le nombre d\'UTS n\'est pas égal à 1 !') ;
    		champ.selectedIndex = 0;
    	}
	}
}

function windows_etage_geol_test(frame_champ, path_recherche, liste, champ, champ1, champ2, champ3, champ4,nom)
{
	if ( champ.selectedIndex == "" || champ.selectedIndex == 0 )
	{
		alert('Veuiller d\'abord remplir le parametre '+nom+' !');
		return -1;
	}
	var res = test_ordre_remplissage_select(champ, champ1, champ2, champ3, champ4,nom);
	if ( res == 0 )
	{
		windows_etage_geol(frame_champ, path_recherche, liste);
	}
}

function test_navigateur()
{
     var nav_ok;
     nav_ok = 1;
   
     if ( navigator.appName.substring(0,1) == "N"
          && navigator.appVersion.substring(0,3) < 5 )
     {
         /* Navigateur Inférieur à Netscape 5.0 */         
         nav_ok = 0;
     }
     else if ( navigator.appName.substring(0,1) == "M"
               && navigator.appVersion.substring(0,3) < 4 )
     {
         /* Navigateur Inférieur à Internet Explorer 4.0 */      
        nav_ok = 0;
     }
     else 
     {
        //rien
     }
    
    if (  nav_ok == 0 )
    {
        return 0;
    } 
    else
    {
        return 1;
    }
}




