$(document).ready(function()
{
    $('#theme').change(function()
    {
    	changeDate();
    });

    $('#date').change(function()
    {
    	changeHeure();
    });
    
    $('#clientOui').change(function()
    {
    	checkClient();
    });
    
    $('#clientNon').change(function()
    {
    	checkClient();
    });     
});

function checkClient()
{
    if ($('#clientOui').attr('checked')) {
        $('#connu').parent('div').slideUp();
        $('#offrePart').parent('div').slideUp();
    }
    else if ($('#clientNon').attr('checked')) {
        $('#connu').parent('div').slideDown();
        $('#offrePart').parent('div').slideDown();
    }
}

function changeDate()
{
    var i;
    var theTheme = document.forms.formation.theme.selectedIndex - 1;
    var dateSelect = document.forms.formation.date;
    var nbDateOld = dateSelect.length;
    
    for(i=nbDateOld-1;i>0;i--){
		dateSelect.options[i] = null;
    }
    if(theTheme>=0){
        for(i=0;i<datesTab[theTheme].length;i++){
			dateSelect.options[i+1] = new Option(datesTab[theTheme][i], i+1);
        }
    }
    dateSelect.selectedIndex = 0;
	changeHeure();
}

function changeHeure()
{
    var i;
    var theTheme = document.forms.formation.theme.selectedIndex - 1;
    var theDate = document.forms.formation.date.selectedIndex - 1;
    var heureSelect = document.forms.formation.horaire;
    var nbHeureOld = heureSelect.length;

    for(i=nbHeureOld-1;i>0;i--){
		heureSelect.options[i] = null;
    }
    if(theDate>=0){
        for(i=0;i<heuresTab[theTheme][theDate].length;i++){
			heureSelect.options[i+1] = new Option(heuresTab[theTheme][theDate][i], i+1);
        }
    }
    heureSelect.selectedIndex = 0;
}

