var sexeSelected=0;
var ageSelected=0;
var profileSelected=0;
function drawMenuSexe(){
	
	htmlSexe='<select name="sexe" onChange="drawMenuAge(-1)" class="center-homepage-profiltextdl">';
	
	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.form1.sexe.options[document.form1.sexe.selectedIndex].value;
	else
		sexeSelected=0;
	

	ageSelected=0;
	profileSelected=0;
	
	htmlAge='<select name="age" onChange="drawButtonRadioProfile(-1)" class="center-homepage-profiltextdl">';
	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;
	
	drawButtonRadioProfile(ageSelected);

	return false;
}
function drawButtonRadioProfile(ag){
	
	if(ag==-1)
		ageSelected=document.form1.age.options[document.form1.age.selectedIndex].value;
	else
		ageSelected=0
	profileSelected=0;

	htmlProfile='';
	htmlProfile +='<div class="center-homepage-profileCat etiquette"><input class="center-homepage-profilbutton" type="radio" onClick="setProfileSelected('+profileJSON.sexe[sexeSelected].age[ageSelected].profile[0].id+')" name="profile" value=0 checked/>&nbsp;'+profileJSON.sexe[sexeSelected].age[ageSelected].profile[0].title; +'</div>';
	for (var i=1;i< profileJSON.sexe[sexeSelected].age[ageSelected].profile.length;i++){
  		htmlProfile +='<div class="center-homepage-profileCat etiquette"><input class="center-homepage-profilbutton" type="radio" onClick="setProfileSelected('+profileJSON.sexe[sexeSelected].age[ageSelected].profile[i].id+')" name="profile" value='+i+' />&nbsp;'+profileJSON.sexe[sexeSelected].age[ageSelected].profile[i].title; +'</div><br/>';

	}
	//htmlProfile +='</select>';
	document.getElementById('optionsProfile').innerHTML=htmlProfile;
	document.form1.formprofile.value=profileJSON.sexe[sexeSelected].age[ageSelected].profile[0].id
	return false;
}

function setProfileSelected(prof){
	document.form1.formprofile.value=prof;
}


window.onload=function(){
	drawMenuSexe();
}

function submitFormProfile(){
	
	document.form1.formsexe.value=profileJSON.sexe[sexeSelected].id;
	document.form1.formage.value=profileJSON.sexe[sexeSelected].age[ageSelected].id;
	if(!document.form1.formprofile.value)
		document.form1.formprofile.value=profileJSON.sexe[sexeSelected].age[ageSelected].profile[profileSelected].id
	document.form1.submit();
}


