/*
 *	Longitude.js
 *	------------
 *
 *	Author:	M.D.Waller
 *
 *	This class supports a simple Longitude object.
 */

function Longitude()
{
    var l = 0;
    
    Longitude.prototype.SetDec
        = function (decimal) {
            if ((decimal > 180) || (decimal < -180))
                throw new Error(99,"Invalid Longitude specified: " + decimal.toString());
            l = decimal;
        }
        
    Longitude.prototype.toString
        = function (pattern) {
            switch (pattern.toUpperCase()) {
                case "DMS":
                    var d = 0;
                    var m = 0;
                    var s = 0;
                    var ew;
                    var i;
                    
                    ew = (l < 0 ? "W" : "E");
                    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() + "'' " + ew);
                    break;
                case "DEC":
                    return (l.toString());
                    break;
                default:
                    throw new Error(99,"Invalid format string");
            }
        }
    return (this);
}
