// Copyright 2000 Adobe Systems Incorporated. All rights reserved. Permission
// to use, modify, distribute, and publicly display this file is hereby
// granted. This file is provided "AS-IS" with absolutely no warranties of any
// kind. Portions (C) Netscape Communications 1999.

// If you modify this file, please share your changes with Adobe and other SVG
// developers at http://www.adobe.com/svg/.

// Version 3/23/00

function choice(form){

	  /*On supprimme les ?l?ments d?j? pr?sents dans la liste des sous-th?mes*/
	  var  chstheme = form.sThemeCp;
	  toto = form.sThemeCp.selectedIndex;
      var stheme = chstheme.options[toto];
	  while(chstheme.length!=1){
	  		chstheme.removeChild(chstheme.options[1]);
	  }
		i= form.themeCp.selectedIndex;
		theme = form.themeCp.options[i].text;
		nb = form.concatThemeCp.options.length;
	
			for(i=0;i<nb;i++){
				tmp = form.concatThemeCp.options[i].text;
				j = tmp.indexOf("(",1);
				l = tmp.length;
				k = tmp.lastIndexOf(")",l);
			
				if(j != -1){
					ch = tmp.substring(j+1,k);
				
					if(j < k){
						if(ch == theme){
							st = tmp.substring(0,j);						
							if(st != ""){

			                	if(form.sThemeCp.length == toto){
			        				label = new Option(st,st,true,true);
			        			}
			                	else if(st == stheme.value){
			                		label = new Option(st,st,true,true);
			                	}
			        			else{
			        				label = new Option(st,st,false,false);
			        			}
			                	
								form.sThemeCp.options[form.sThemeCp.length] = label;	
							}
						}
						
						if(theme == 'choix...'){
							st = tmp.substring(0,j);						
							if(st != ""){

			                	if(form.sThemeCp.length == toto){
			        				label = new Option(st,st,true,true);
			        			}
			                	else if(st == stheme.value){
			                		label = new Option(st,st,true,true);
			                	}
			        			else{
			        				label = new Option(st,st,false,false);
			        			}
			                	
								form.sThemeCp.options[form.sThemeCp.length] = label;	
							}
						}
						
					}
				}	
			}
}


function genCommune(form){

        var chcommune = form.communeCp;
        toto = form.communeCp.selectedIndex;
        var commune = chcommune.options[toto];
        
        while(chcommune.length!=1){
                chcommune.removeChild(chcommune.options[1]);
        }
        i= form.cantonCp.selectedIndex;
        canton = form.cantonCp.options[i].text;
        nb = form.concatCantonCommuneCp.options.length;

        for(i=0;i<nb;i++){
        	tmp = form.concatCantonCommuneCp.options[i].text;
          j = tmp.indexOf("(",1);
          jj = tmp.lastIndexOf("(",tmp.length);
          art = tmp.lastIndexOf("(Les)",tmp.length);
          indexLes = tmp.indexOf("(Les)",1);
          indexLa = tmp.indexOf("(La)",1);
          indexLe = tmp.indexOf("(Le)",1);
          l = tmp.length;
          k = tmp.lastIndexOf(")",l);

          if(j != -1){
          	if(art != -1){
          		tmpch = tmp.substring(0,art);
          		arti = tmpch.lastIndexOf("(",tmpch.length);
          		ch = tmp.substring(arti + 1,tmpch.length) + "(Les)";
          	}
          	else{
          		ch = tmp.substring(jj+1,k);
          		if(ch == "Le)"){
             		 ch = tmp.substring(1,k);	
             		}
          	}
         	if( ch == "Neubourg (Le)"){
          		if(ch == canton){
          		for(l=0;l<form.concatNeubourg.options.length;l++){
          			
          			tmpneu = form.concatNeubourg.options[l].text;
          			
          			if(form.communeCp.length == toto){
        				label = new Option(tmpneu,tmpneu,true,true);
        			}
                	else if(tmpneu == commune.value){
                		label = new Option(tmpneu,tmpneu,true,true);
                	}
        			else{
        				label = new Option(tmpneu,tmpneu,false,false);
        			}
          			form.communeCp.options[form.communeCp.length] = label;
          		}
          		}
                     	
          				
            }
            if(j < k){
            	if(ch == canton){
            		if(art != -1)
              		st = tmp.substring(0,arti);
              	else
              		st = tmp.substring(0,jj);
                if(st != ""){
                	

                	if(form.communeCp.length == toto){
        				label = new Option(st,st,true,true);
        			}
                	else if(st == commune.value){
                		label = new Option(st,st,true,true);
                	}
        			else{
        				label = new Option(st,st,false,false);
        			}
                	
                	
                  form.communeCp.options[form.communeCp.length] = label;
                }
             	}
             	if(canton == 'choix...'){
             		if(art == -1){
             			if(indexLes == -1 && indexLa == -1 && indexLe == -1)
             				st = tmp.substring(0,j);
                	if(indexLes != -1){
                		st = tmp.substring(0,indexLes + 5);
                	
                	}
                	if(indexLa != -1){
                		st = tmp.substring(0,indexLa + 4);
                	}
                	if(indexLe != -1){
                		st = tmp.substring(0,indexLe + 4);
                	}
                	
                }
                if(art != -1){
                	if(indexLes != -1){
                		st = tmp.substring(0,indexLes + 5);
                	}
                }
                if(st != ""){
                		ind = st.indexOf("Andelys (Les)",1);
                		if(ind != -1){
                			st = st.substring(0,ind-1);
                		}
                		if( st != ""){
                			

                        	if(form.communeCp.length == toto){
                				label = new Option(st,st,true,true);
                			}
                        	else if(st == commune.value){
                        		label = new Option(st,st,true,true);
                        	}
                			else{
                				label = new Option(st,st,false,false);
                			}
                       
                  		form.communeCp.options[form.communeCp.length] = label;
                  	}
                } 	
             }
            }
                
                	
                
                /*
                else{
                	st = tmp.substring(0,arti);
                	if(st != ""){
                		label = new Option(st,st,false,false);
                		form.communeCp.options[form.communeCp.length] = label;
                	}
                }
                */
             	}
            }
        if( canton == "Neubourg (Le)"){
        	chcommune.removeChild(chcommune.options[form.communeCp.length -1]);
        }
          }

function genCommunePop(form){

    var chcommune = form.communePop;
    toto = form.communePop.selectedIndex;
    var commune = chcommune.options[toto];
    
    i= form.cantonPop.selectedIndex;
    canton = form.cantonPop.options[i].text;
    
     if(canton == "choix..."){
    	if(toto != 0){
    		document.location='/pleade/recpop';
    }
    }

    if(canton != "choix..." ){
    while(chcommune.length!=1){
            chcommune.removeChild(chcommune.options[1]);
    }
    }
   
    nb = form.concatCantonCommunePop.options.length;
    
    for(i=0;i<nb;i++){
    	tmp = form.concatCantonCommunePop.options[i].text;
      j = tmp.indexOf("(",1);
      jj = tmp.lastIndexOf("(",tmp.length);
      art = tmp.lastIndexOf("(Les)",tmp.length);
      indexLes = tmp.indexOf("(Les)",1);
      indexLa = tmp.indexOf("(La)",1);
      indexLe = tmp.indexOf("(Le)",1);
      l = tmp.length;
      k = tmp.lastIndexOf(")",l);

      if(j != -1){
      	if(art != -1){
      		tmpch = tmp.substring(0,art);
      		arti = tmpch.lastIndexOf("(",tmpch.length);
      		ch = tmp.substring(arti + 1,tmpch.length) + "(Les)";
      	}
      	else{
      		ch = tmp.substring(jj+1,k);
      		if(ch == "Le)"){
      		 ch = tmp.substring(1,k);	
      		}
      		
      	}
    
      	
      	if( ch == "Neubourg (Le)"){
      		if(ch == canton){
      		for(l=0;l<form.concatNeubourg.options.length;l++){
      			
      			tmpneu = form.concatNeubourg.options[l].text;
      			
      			if(form.communePop.length == toto){
    				label = new Option(tmpneu,tmpneu,true,true);
    			}
            	else if(tmpneu == commune.value){
            		label = new Option(tmpneu,tmpneu,true,true);
            	}
    			else{
    				label = new Option(tmpneu,tmpneu,false,false);
    			}
      			form.communePop.options[form.communePop.length] = label;
      		}
      		}
                 	
      				
        }
      		
      	
      	
        if(j < k){
        	if(ch == canton){
        		if(art != -1){
          		st = tmp.substring(0,arti);
        		}
          	else{
          		st = tmp.substring(0,jj);
          		
          	}
          		setTimeout("",500);
            if(st != ""){
            
            	if(form.communePop.length == toto){
    				label = new Option(st,st,true,true);
    			}
            	else if(st == commune.value){
            		label = new Option(st,st,true,true);
            	}
    			else{
    				label = new Option(st,st,false,false);
    			}
            	
              form.communePop.options[form.communePop.length] = label;
            }
           
         	if(canton == 'choix...'){
         		if(art == -1){
         			if(indexLes == -1 && indexLa == -1 && indexLe == -1)
         				st = tmp.substring(0,j);
            	if(indexLes != -1){
            		st = tmp.substring(0,indexLes + 5);
            		alert("stles:"+st);
            	}
            	if(indexLa != -1){
            		st = tmp.substring(0,indexLa + 4);
            	}
            	if(indexLe != -1){
            		
            		st = tmp.substring(1,indexLe + 4);
            		/*alert("st le :"+st);*/
            	}
            	
            }
            if(art != -1){
            	if(indexLes != -1){
            		st = tmp.substring(0,indexLes + 5);
            	}
            }
            if(st != ""){
            		ind = st.indexOf("Andelys (Les)",1);
            		if(ind != -1){
            			st = st.substring(0,ind-1);
            		}
            		
            		if( st != ""){
            			if(form.communePop.length == toto){
            				label = new Option(st,st,true,true);
            			}
            			else if(st == commune.value){
                    		label = new Option(st,st,true,true);
                    	}
            			else{
            				label = new Option(st,st,false,false);
            			}
              		form.communePop.options[form.communePop.length] = label;
              	}
            		
            		
             		
            		
            }
            
          
            
         }
        }
            
            	
            
            /*
            else{
            	st = tmp.substring(0,arti);
            	if(st != ""){
            		label = new Option(st,st,false,false);
            		form.communeCp.options[form.communeCp.length] = label;
            	}
            }
            */
         	}
        }
  
 
      }
    
    if( canton == "Neubourg (Le)"){
    	chcommune.removeChild(chcommune.options[form.communePop.length -1]);
    }
    
}



