var yearPrinc=1993;
var monthPrinc=9;
var dayPrinc=4;

var yearAutres=2011
var monthAutres=9;



function agrandirMilieu() {
    gauche = document.getElementById('divDroiteGaucheInt');
    zoom = document.getElementById('divBlocZoomSur');
    publication = document.getElementById('divBlocPublication');
    avis = document.getElementById('divBlocAvis');
    lien = document.getElementById('divBlocLien');

    /* on teste l'existence d'un div de droite : si aucun, on agrandit*/
    if(zoom==null && publication==null && avis==null && lien==null) {
        gauche.style.width = "622px";
    }
}

/*function activerFlash () {
	theObjects = document.getElementsByTagName("object");
	for (var i = 0; i < theObjects.length; i++)
	{
		theObjects[i].outerHTML = theObjects[i].outerHTML;
	}
}*/

if (window.attachEvent) {
    window.attachEvent("onload", agrandirMilieu);
}
else {
    window.addEventListener('load', agrandirMilieu, false);
}



// 20080304 : election : cocher tout
function checkAll () {
    list = document.getElementsByName('checkboxCanton[]');

    tous = document.getElementById('toutcocher');

    if(tous.checked) {
        for(i=0; i<list.length; i++) {
            list[i].checked = 'checked';
        }
    }
    else {
        for(i=0; i<list.length; i++) {
            list[i].checked = '';
        }
    }
}

function lockAgePrinc () { 

    formMonth=document.getElementById('mois_naissance');
    formDay=document.getElementById('jour_naissance');
    
    currentMonth=formMonth.value;
    currentDay=formDay.value;
    
    if(document.getElementById('annee_naissance').value==yearPrinc){

        selectMenu(formMonth,monthPrinc+1,'lockMonthPrinc()');

        if  (currentMonth < monthPrinc+1)   {                                                      
            document.getElementById('mois_naissance').options[currentMonth-1].selected=true
       }
         
    }         
    else{ 
    
        selectMenu(formMonth,13,'lockMonthPrinc()');        
        document.getElementById('mois_naissance').options[currentMonth-1].selected=true    

        selectMenu(formDay,32);        
        document.getElementById('jour_naissance').options[currentDay-1].selected=true
       
    }
}
function lockMonthPrinc() { 

    formMonth=document.getElementById('mois_naissance');
    formDay=document.getElementById('jour_naissance');
    
    currentMonth=formMonth.value;
    currentDay=formDay.value;
    
   
    if((currentMonth==monthPrinc)&& (document.getElementById('annee_naissance').value==yearPrinc)){
    
        selectMenu(formDay,dayPrinc+1); 
        
        if  (currentDay < dayPrinc+1){                                                         
            document.getElementById('jour_naissance').options[currentDay-1].selected=true
        }
         
    }         
    else{ 
       
        selectMenu(formDay,32);            
        document.getElementById('jour_naissance').options[currentDay-1].selected=true

    }
}

function lockAgeAutres(num) { 

    formMonth=document.getElementById('mois_naissance_'+num);
    formDay=document.getElementById('jour_naissance_'+num);
    
    currentMonth=formMonth.value;
    currentDay=formDay.value;
    
    if(document.getElementById('annee_naissance_'+num).value==yearAutres){
    
     
        selectMenu(formMonth,monthAutres+1 ,'lockMonthAutres('+num+')'); 
        
        if  (currentMonth < monthAutres)                                                         
            document.getElementById('mois_naissance_'+num).options[currentMonth-1].selected=true

    }         
    else{ 
        selectMenu(formMonth,13,'lockMonthAutres('+num+')'); 
        document.getElementById('mois_naissance_'+num).options[currentMonth-1].selected=true    
        
        selectMenu(formDay,32); 
        document.getElementById('jour_naissance_'+num).options[currentDay-1].selected=true   
    }
}

function lockMonthAutres(num) { 

    formMonth=document.getElementById('mois_naissance_'+num);
    formDay=document.getElementById('jour_naissance_'+num);

    currentMonth=formMonth.value;
    currentDay=formDay.value;

    if(currentMonth==monthAutres && document.getElementById('annee_naissance_'+num).value==yearAutres){
        
       selectMenu(formDay,2);
       
    }         
    else{  
    
        selectMenu(formDay,32); 
        document.getElementById('jour_naissance_'+num).options[currentDay-1].selected=true 
        
    }
}


function selectMenu(select,limit,onchange) {

if (onchange==null)
onchange=select.getAttribute('onchange');

var sOpts = "<SELECT name='"+select.getAttribute('name')+"' id='"+select.getAttribute('id')+"' onChange=\""+onchange+"\">";


	for(i=1;i<limit;i++) {
    
        if (i<10)
            im='0'+i
        else 
            im=i
        
        sOpts+='<option value="'+i+'">'+im+'</option>';
    }
	
    select.outerHTML = sOpts  + "</SELECT>";
}
