(function() {
// Récupération des flux et activation des champs select

	var getOptions = function( url, cible ) {
		
		
		$.ajax({
			type: 'GET',
			url: url,
			success: function( rtr ){
				items = $(rtr).find('Item');
				for( var i=0; i < items.length; i++ ){
					cible.append('<option value="'+$(items[i].getElementsByTagName('Code')).text()+'">'+$(items[i].getElementsByTagName('Label')).text()+'</option>');
				}
				cible.attr( 'disabled', false );
			},
			error: function( rtr ) {
				console.log( 'err : '+url );
				console.log( rtr );
			},
//			crossDomain:true,
			dataType : 'xml'
		});
	}


	getOptions( 'controller/proxy-rflex.php?url=Pages/JobBoards/ExportReference.ashx?codetable=JobFamily', $('select[name="metier"]') );
	getOptions( 'controller/proxy-rflex.php?url=Pages/JobBoards/ExportReference.ashx?codetable=ActivitySector', $('select[name="secteur"]') );
	getOptions( 'controller/proxy-rflex.php?url=Pages/JobBoards/ExportReference.ashx?codetable=Region', $('select[name="region"]') );
	

// Gestion de la soumission du formulaire
	
	
	$('#job-search form').live('submit', function(e){
		e.preventDefault();
		
		var vars = [];
		$('#job-search').find('select, input[type!="submit"]').each( function(){
			if( $(this).val() != '0' && $(this).val() != '' && $(this).val() != $(this).attr('placeholder') )
				vars.push( encodeURIComponent($(this).attr('name'))+'='+encodeURIComponent($(this).val()) );
		});
		
		
		window.location = $('#job-search form').attr('action')+( vars.length ? '?'+vars.join('&') : '' );
		
	});
	
	


})();


