var sexeSelected=0;
var ageSelected=0;
var profileSelected=0;
function drawMenuSexe(){
	
	htmlSexe='<select name="sexe" onChange="drawMenuAge(-1)" class="left-profiletext">';
	
	for (var i=0;i< profileJSON.sexe.length;i++){
  		htmlSexe +='<option value='+i+'>'+profileJSON.sexe[i].title; +'</option>';
	}
	htmlSexe +='</select>';

	document.getElementById('selectSexe').innerHTML=htmlSexe;

	drawMenuAge(0);
	return false;
}
function drawMenuAge(sex){
	
	if(sex==-1)
		sexeSelected=document.formProfilRechercherSmall.sexe.options[document.formProfilRechercherSmall.sexe.selectedIndex].value;
	else
		sexeSelected=0;
	

	ageSelected=0;
	profileSelected=0;
	
	htmlAge='<select name="age" onChange="drawMenuProfile(-1)" class="left-profiletext">';
	for (var i=0;i< profileJSON.sexe[sexeSelected].age.length;i++){
  		htmlAge +='<option value='+i+'>'+profileJSON.sexe[sexeSelected].age[i].title; +'</option>';
	}
	htmlAge +='</select>';
	document.getElementById('selectAge').innerHTML=htmlAge;
	
	drawMenuProfile(ageSelected);

	return false;
}
function drawMenuProfile(ag){
	
	if(ag==-1)
		ageSelected=document.formProfilRechercherSmall.age.options[document.formProfilRechercherSmall.age.selectedIndex].value;
	else
		ageSelected=0
	profileSelected=0;

	htmlProfile='<select name="profile" onChange="setProfileSelected(-1)" class="left-profiletext">';
	
	
	for (var i=0;i< profileJSON.sexe[sexeSelected].age[ageSelected].profile.length;i++){
  		
  		htmlProfile +='<option value='+i+'>'+profileJSON.sexe[sexeSelected].age[ageSelected].profile[i].title; +'</option>';

	}
	
	htmlProfile +='</select>';
	document.getElementById('selectProfile').innerHTML=htmlProfile;
	
	return false;
}

function setProfileSelected(prof){

	profileSelected=document.formProfilRechercherSmall.profile.options[document.formProfilRechercherSmall.profile.selectedIndex].value;
	document.formProfilRechercherSmall.formprofile.value=profileJSON.sexe[sexeSelected].age[ageSelected].profile[profileSelected].id;

}


window.onload=function(){
	drawMenuSexe();
}

function submitFormProfile(){
	
	document.formProfilRechercherSmall.formsexe.value=profileJSON.sexe[sexeSelected].id;
	document.formProfilRechercherSmall.formage.value=profileJSON.sexe[sexeSelected].age[ageSelected].id;
	if(!document.formProfilRechercherSmall.formprofile.value)
		document.formProfilRechercherSmall.formprofile.value=profileJSON.sexe[sexeSelected].age[ageSelected].profile[profileSelected].id
	document.formProfilRechercherSmall.submit();
}


