/*
 * @(#)Test.java
 *  Description: Converter
 *  Rev:         C
 *  Created:     Wed. June 25, 1997, 21:22:23
 *  Author:      Karlheinz Welker
 *  mailto:      bluecell@bluecell.org
 *
 *  Copyright Karlheinz Welker
 *  12524 Berlin
 *  
 *  The copyright to the computer program(s) herein
 *  is the property of Karlheinz Welker, Germany.
 *  The program(s) may be used and/or copied  only with
 *  the written permission of Karlheinz Welker
 *  or in accordance with the terms and conditions
 *  stipulated  in the agreement/contract under which
 *  the  program(s) have been supplied.
 *
 *
 

 * Umrechner für Koordinaten
 *
 * @author   <a href="mailto:bluecell@bluecell.org">Karlheinz Welker</a>
 * @version  1.2 12/03/2007
 */

// Convert Degrees, Minutes, Seconds to decimal Degrees
function conv_dms2d (d, m, s) {
  var dd;
  var sign;

  sign = (d < 0) ? -1.0 : 1.0;
  dd = sign * Math.round((Math.abs(d) + m/60.0 + s/3600.0) * 10000000.0)/10000000.0;
  display_dms2d(dd);
}

function display_dms2d (d)
{
  document.DMS_to_D.D_out.value = d;
}

// Convert decimal Degrees to
// - Degrees, Minutes, Seconds
// - Degrees, decimal Minutes
function conv_d2dms (dd) {
  var sign;
  var d;
  var m;
  var s;

  sign = (dd < 0) ? -1.0 : 1.0;
  m = Math.abs(dd);
  d = Math.floor(m);
  m = (m - d) * 60.0;
  dm = Math.round(m * 100000.0)/100000.0;
  d = sign * d;
  s = m;
  m = Math.floor(m);
  s = Math.round((s - m) * 60000.0)/1000.0;

  display_d2dms (d, m, s, dm);
}

function display_d2dms (d, m, s, dm)
{
  document.D_to_DMS.D_out.value = d;
  document.D_to_DMS.M_out.value = m;
  document.D_to_DMS.S_out.value = s;
  document.D_to_DMS.D2_out.value = d;
  document.D_to_DMS.M2_out.value = dm;
}

