﻿//This javascript is independent of all the other scripts so placement doesn't matter
//simply gets the input and calculates the distance from the requested object.

function getdelta(p1, p2) {
    var d = p1 > p2 ? p1 - p2 : p2 - p1;
    return d;
}
function CalculateResult(arr, origin) {
    var dla = getdelta(arr["latitude"], origin.latitude) * baselat;
    var dlo = getdelta(arr["longitude"], origin.longitude) * baselat;
    var calcresult = Math.sqrt(Math.pow(dla, 2) + Math.pow(dlo, 2));
    arr["cvalue"] = qround(calcresult, 1); //1 = 1st sigfig.  
}
function qround(c, d) {
    var del = c.toString().indexOf(".");
    var r = (del != -1) ? c.toPrecision(del + d) : c;
    return r;
}
