// JavaScript Document
function makeSublist(parent,child,isSubselectOptional,childVal)
{
	$("body").append("<select style='display:none' id='"+parent+child+"'></select>");
	$('#'+parent+child).html($("#"+child+" option"));
	
		var parentValue = $('#'+parent).attr('value');
		$('#'+child).html($("#"+parent+child+" .sub_"+parentValue).clone());
	
	childVal = (typeof childVal == "undefined")? "" : childVal ;
	$("#"+child+' option[@value="'+ childVal +'"]').attr('selected','selected');
	
	$('#'+parent).change( 
		function()
		{
			var parentValue = $('#'+parent).attr('value');
			$('#'+child).html($("#"+parent+child+" .sub_"+parentValue).clone());
			if(isSubselectOptional) $('#'+child).prepend("<option value='none'> -- Selectionner une matière -- </option>");
			$('#'+child).trigger("change");
                        $('#'+child).focus();
		}
	);
}

$(document).ready(function() { 
	//Création des listes secondaires
	makeSublist('type_cours','matiere', false, '');

	$('#matiere').change( function() {
		var id_matiere = $('#matiere').val();
		if(id_matiere != 'none')
		{
			var sel_matiere = document.getElementById('matiere').options[document.getElementById('matiere').selectedIndex].text;
			var sel_type = $('#type_cours').val();
			
			sel_matiere = RemoveSpec(sel_matiere);
			//alert(sel_matiere);
			
			if(sel_type == "ss")
				var txt = "soutien-scolaire-";
			else if(sel_type == "ld")
				var txt = "cours-particuliers-";
			else if(sel_type == "ac")
				var txt = "pour-vos-enfants-";
			window.location = 'reservation-' + txt + sel_matiere + ',' + sel_type + ',' + id_matiere + '.html';
		}
	});
});

function RemoveSpec(Texte){

	var Accents = 'àâäéèêëïïöôûüù /';
	var NoAccen = 'aaaeeeeiioouuu--';

	Accents = Accents.split('');
	NoAccen = NoAccen.split('');
	
	var i=0;
	while(Accents[i]){
		var Reg=new RegExp(Accents[i],'gi');
		Texte=Texte.replace(Reg,NoAccen[15]);
		i++;
	}
	return Texte;
}