//X1 x liefhebber
//Y1 y liefhebber
//X2 x  lossingsplaats
//Y2 y  lossingsplaats
function  getWaarde(getal){
	//+POS.NEG(WAARDE(C5))*(WAARDE(DEEL(C5;2;2))+WAARDE(DEEL(C5;4;2))/60+WAARDE(DEEL(C5;6;5))/3600)*$F$4
	var f4 = 0.0174532925199428;
	var teken = 0;
	if (getal<0){
		teken = -1;
	} else if (getal==0) {
		teken = 0;
	} else {
		teken = 1;
	}
	var deel1 = getal.substr(1,2);
	var deel2 = getal.substr(3,2)/60;
	var deel3 = getal.substr(5,5)/3600;
	return parseFloat(teken) * ( parseFloat(deel1) + parseFloat(deel2) + parseFloat(deel3) ) * parseFloat(f4) ;
}
function  doMathAFSTAND2(X1,Y1,X2,Y2) {
	var	g4 = 0.0067394967422767;
	var h4 = 0.99664718933525;
	var i4 = 6378137;
	var f5 = getWaarde(X1);
	var f6 = getWaarde(Y1);
	var f11 = getWaarde(X2);
	var g11 = getWaarde(Y2);
	var h11 = ( f5 + f11 ) / 2 ;
	var i11 = g11-f6;
	var j11 = g4*Math.pow(Math.cos(h11),2);
	var k11 = Math.sqrt(1+j11);
	var l11 = k11*i11;
	var m11 = Math.atan((h4*Math.tan(f5)));
	var n11 = Math.atan(h4*Math.tan(f11));
	var o11 = Math.sin(m11)*Math.sin(n11)+Math.cos(m11)*Math.cos(n11)*Math.cos(l11);
	
	return Math.round((i4/k11)*(Math.atan(-o11/Math.sqrt(1-Math.pow(o11,2)))+2*Math.atan(1)));
}
function custRound(x,places) {
return (Math.round(x*Math.pow(10,places)))/Math.pow(10,places);
}


var popup = '';
function myvoid() {}

function showpopup(plaats,message) {
    msgWindow=window.open('test','','width=200,height=30');
	msgWindow.moveTo(1,1);
	msgWindow.document.write('<html>');
	msgWindow.document.write('<head>');
	msgWindow.document.write('<title>Afstand</title>');
	msgWindow.document.write('<LINK REL=StyleSheet HREF="css/duiven.css" TYPE="text/css" MEDIA=screen>');
	msgWindow.document.write('</head>');
	msgWindow.document.write('<BODY> De afstand voor ' + plaats +'= ' + message + '<\/BODY>');
    	msgWindow.document.close();
}

function closepopup() {
    if (!p.closed)
        p.close();
}
function show_popup(plaats,X1,Y1,X2,Y2)
{
	if (isNaN(X1)) {
		window.alert('X-coördinaat moet een getal zijn!');
	}else if (isNaN(Y1)) {
		window.alert('Y-coördinaat moet een getal zijn!');
	}else{
		var p=window.createPopup();
		
		var pbody=p.document.body;
		pbody.style.backgroundColor='#FF0000';
		pbody.style.border="solid gray 1px";
		var afstand = doMathAFSTAND2(X1,Y1,X2,Y2);
		pbody.innerHTML='De afstand voor ' + plaats +' = ' + afstand + 'm';//doMathAFSTAND2(X1,Y1,X2,Y2)
		p.show(250,130,290,25,document.body);
		}
}



