	function to_radians(deg,min,sec){

		pi = Math.atan2(1,1) * 4;
		degrees = deg + (min + sec/60)/60;
		//degrees = Math.abs(degrees);
		return degrees*(pi/180);
	}
	
	function distance(){
		r=6378;//km
		
		id_from=document.getElementById('distance_from').value;
		id_to=document.getElementById('distance_to').value;
		
		if(!latitude[id_from]) return 1;
		if(!latitude[id_to]) return 1;
		
		a1=to_radians(latitude[id_from]['deg'],latitude[id_from]['min'],latitude[id_from]['sec']);
		a2=to_radians(latitude[id_to]['deg'],latitude[id_to]['min'],latitude[id_to]['sec']);
		b1=to_radians(longitude[id_from]['deg'],longitude[id_from]['min'],longitude[id_from]['sec']);
		b2=to_radians(longitude[id_to]['deg'],longitude[id_to]['min'],longitude[id_to]['sec']);
			
		res=(Math.acos(Math.cos(a1)*Math.cos(b1)*Math.cos(a2)*Math.cos(b2) + Math.cos(a1)*Math.sin(b1)*Math.cos(a2)*Math.sin(b2) + Math.sin(a1)*Math.sin(a2)) * r);
		
		document.getElementById('distance_result').innerHTML=Math.round(res)+' км';
	}
