// JavaScript Document for Air Madagascar
var xmlFile = 'xml/pointcarteairmad_UK.xml'

function getValue ( xmlDoc, id ) {
	return $(xmlDoc).find('point[@id='+ id +']').text();
}

$( function () {
	// loading xmlDoc
	
	var $xmlDoc;
	
	$.ajax({
		type:'GET',
		url: xmlFile,
		dataType: "xml",
		success: function(xml) {
			$xmlDoc = $(xml);
			$xmlDoc.find('point').each( function () {
				var $option = $('<option>');				
				$option.val( $(this).attr('id') );
				$option.text( $(this).attr('ville') );
				$('#listeville').append( $option );			
			});
		}
	});
	
	showCoord = function (idTown) {
		//alert (idTown + ',' + $xmlDoc.find('point#'+ idTown ).text().toLowerCase() );
		$('.adresses').load( 'adresses/' + $xmlDoc.find('point#'+ idTown ).text().toLowerCase() + '.html');
		$('#listeville').find('option[@value=' + idTown + ']').attr('selected', 'selected');
	}
	
	$('#listeville').change( function () {
		if ($(this).val() != '' )
			showCoord ( $(this).val() );
	});
	
});