/*
 *	Latitude.js
 *	-----------
 *
 *	Author:	M.D.Waller
 *
 *	This class supports a simple Latitude object.
 */

function Latitude()
{
    var l = 0;
    
    Latitude.prototype.SetDec
        = function (decimal) {
            if ((decimal > 90) || (decimal < -90))
                throw new Error(99,"Invalid Latitude specified: " + decimal.toString());
            l = decimal;
        }
        
    Latitude.prototype.toString
        = function (pattern) {
            switch (pattern.toUpperCase()) {
                case "DMS":
                    var d = 0;
                    var m = 0;
                    var s = 0;
                    var ns;
                    var i;
                    
                    ns = (l < 0 ? "S" : "N");
                    i = Math.abs(l);
                    d = Math.floor(i);
                    i = (i - d) * 60;
                    m = Math.floor(i);
                    s = Math.floor((i - m) * 60 * 100) / 100;
                    return (d.toString() + " " + m.toString() + "' " + s.toString() + "'' " + ns);
                    break;
                case "DEC":
                    return (l.toString());
                    break;
                default:
                    throw new Error(99,"Invalid format string");
            }
        }
    return (this);
}
