var miles_in_lat = 60;

function getCircleRadius(dist, center_lat) {

	var y = convertLatToY(center_lat);

	var dy = parseFloat(parseFloat(1/miles_in_lat) * dist);

	var point2 = parseFloat(center_lat) + dy;

	var y2 = convertLatToY(point2);

	return parseInt(y - y2);

}

function convertLatToY(lat) {
	var y = 0;
		
	var diff = parseFloat(maxy - miny);
		
	var pixdiff = parseFloat(diff / height);
		
	var mypos = parseFloat(maxy - lat);
		
	y = parseInt(mypos / pixdiff);

	return y;
		
}

function addMileMarker(dst, elm){
	var w = '';

	if (elm.getAttribute('LL_RES_LAT') != null) {
        	w = getCircleRadius(dst, elm.getAttribute("LL_RES_LAT"));
	} else {
		w = getCircleRadius(dst, elm.getAttribute("O_RES_LAT"));
	}
	
        var img = document.createElement('img');
        img.src = 'http://mapping.redata.com/mapping_v2006/jsps/COMMON/trans_cir.png';
        img.style.position = 'absolute';
        img.style.top = (parseInt(elm.getAttribute('y')) - w) + 'px';
        img.style.left = (parseInt(elm.getAttribute('x')) - w) + 'px';
        img.style.width = (w * 2) + 'px';
        img.style.height = (w * 2) + 'px';
        img.onload = null;

        container.appendChild(img);
}

function distance(lat1, lon1, lat2, lon2) {
	var radlat1 = Math.PI * parseFloat(lat1)/180;
	var radlat2 = Math.PI * parseFloat(lat2)/180;
	var radlon1 = Math.PI * parseFloat(lon1)/180;
	var radlon2 = Math.PI * parseFloat(lon2)/180;
	var theta = lon1-lon2;
	var radtheta = Math.PI * theta/180;
	var dist = Math.sin(radlat1) * Math.sin(radlat2) + Math.cos(radlat1) * Math.cos(radlat2) * Math.cos(radtheta);
	dist = Math.acos(dist);
	dist = dist * 180/Math.PI;
	dist = dist * 60 * 1.1515;
	dist = dist * 0.8684;

	var nf = new NumberFormat();
        nf.setNumber(dist);
        nf.setPlaces(2);
        return nf.toFormatted();
}                            

