﻿Type.registerNamespace("KC");

KC.Locate = function() {
    this._latLongPanelId = "LatitudeLongitude1_LatLongFloatingPanel";
}

KC.Locate.prototype = {
    getAerialCheckBox: function() {
        return $get(this._aerialCheckBoxId);
    },

    setAerialCheckBoxId: function(id) {
        this._aerialCheckBoxId = id;
    },

    getLatLongPanelId: function() {
        return this._latLongPanelId;
    },

    setLatLongPanelId: function(id) {
        this._latLongPanelId = id;
    },

    getLatitudeDropDownList: function() {
        return $get(this._latitudeDropDownListId);
    },

    setLatitudeDropDownListId: function(id) {
        this._latitudeDropDownListId = id;
    },

    getLatitudeMinutesTextBox: function() {
        return $get(this._latitudeMinutesTextBoxId);
    },

    setLatitudeMinutesTextBoxId: function(id) {
        this._latitudeMinutesTextBoxId = id;
    },

    getLatitudeSecondsTextBox: function() {
        return $get(this._latitudeSecondsTextBoxId);
    },

    setLatitudeSecondsTextBoxId: function(id) {
        this._latitudeSecondsTextBoxId = id;
    },

    getLatitudeTextBox: function() {
        return $get(this._latitudeTextBoxId);
    },

    setLatitudeTextBoxId: function(id) {
        this._latitudeTextBoxId = id;
    },

    getLongitudeMinutesTextBox: function() {
        return $get(this._longitudeMinutesTextBoxId);
    },

    setLongitudeMinutesTextBoxId: function(id) {
        this._longitudeMinutesTextBoxId = id;
    },

    getLongitudeSecondsTextBox: function() {
        return $get(this._longitudeSecondsTextBoxId);
    },

    setLongitudeSecondsTextBoxId: function(id) {
        this._longitudeSecondsTextBoxId = id;
    },

    getLongitudeTextBox: function() {
        return $get(this._longitudeTextBoxId);
    },

    setLongitudeTextBoxId: function(id) {
        this._longitudeTextBoxId = id;
    },

    AerialCheckBoxVisible: function() {
        if ($get(this._aerialCheckBoxId) != null)
            return true;
        else
            return false;
    },

    ConvertDecimalToMinutes: function(degrees) {
        var deg = 0;
        if (this.IsNumber(degrees)) deg = eval(degrees);
        var minutes = Math.floor(deg * 60);
        seconds = Math.round(((deg * 60 - minutes) * 60) * 100) / 100;
        return [minutes, seconds];
    },

    ConvertMinutesToDecimal: function(minutes, seconds) {
        var min = 0;
        var sec = 0;
        if (this.IsNumber(minutes)) min = eval(minutes);
        if (this.IsNumber(seconds)) sec = eval(seconds);
        return Math.round(((min + sec / 60) / 60) * 1000000) / 1000000;
    },

    IsNumber: function(n) {
        return !isNaN(parseFloat(n)) && isFinite(n);
    },

    LatitudeLongitude: function() {
        if (this.getLatitudeTextBox().style.display == "none") {
            this.getLatitudeTextBox().value = this.ConvertMinutesToDecimal(this.getLatitudeMinutesTextBox().value, this.getLatitudeSecondsTextBox().value).toString().substr(2);
            this.getLongitudeTextBox().value = this.ConvertMinutesToDecimal(this.getLongitudeMinutesTextBox().value, this.getLongitudeSecondsTextBox().value).toString().substr(2);
        }
        var firstDigit = this.getLatitudeTextBox().value.substr(0, 1);
        if (eval(firstDigit) > 4) this.getLatitudeDropDownList().value = 42;
        else this.getLatitudeDropDownList().value = 43;
        var degrees = this.getLatitudeDropDownList().value;
        var lat = eval(degrees + "." + this.getLatitudeTextBox().value);
        var lon = eval("-85." + this.getLongitudeTextBox().value);
        if (this.AerialCheckBoxVisible()) {
            var isChecked = this.getAerialCheckBox().checked;
            var zoomFactor = 0.25;
            if (isChecked) zoomFactor = 0.5;
            pictViewer.MoveGraphic(lat, lon, false, isChecked, zoomFactor);
            if (isChecked) {
                pictViewer.Initialize(lat, lon, true);
                this.ToggleLatLongPanel();
            }
        } else
            pictViewer.MoveGraphic(lat, lon, false, false, 0.25);
    },

    SetLatitudeDropDownList: function(number) {
        if (number.length == 1) {
            switch (eval(number)) {
                case 7: case 8: case 9:
                    this.getLatitudeDropDownList().value = "42";
                    break
                case 4: case 5: case 6:
                    this.getLatitudeTextBox().value = "";
                default:
                    this.getLatitudeDropDownList().value = "43";
            }
        }
    },

    ToggleLatLongPanel: function() {
        toggleFloatingPanelVisibility(this.getLatLongPanelId());
        if ($get(this.getLatLongPanelId()).style.display != "none") {
            if (this.getLatitudeTextBox().style.display != "none") {
                this.getLatitudeTextBox().select();
                this.getLatitudeTextBox().focus();
            } else {
                this.getLatitudeMinutesTextBox().select();
                this.getLatitudeMinutesTextBox().focus();
            }
        }
    },

    dispose: function() {
        alert('KC.Locate disposed ' + this.getLatLongPanelId());
    }
}
KC.Locate.registerClass('KC.Locate', null, Sys.IDisposable);
var locate = new KC.Locate();

// Notify ScriptManager that this is the end of the script.
if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();