﻿/// <reference name="MicrosoftAjax.debug.js" />
/// <reference name="MicrosoftAjaxTimer.debug.js" />
/// <reference name="MicrosoftAjaxWebForms.debug.js" />


Type.registerNamespace("UI.Controls");
//
UI.Controls.NewEventFormBehavior = function(element) {

    UI.Controls.NewEventFormBehavior.initializeBase(this, [element]);
    // Referencia a Controles y objetos
    this._parentControl = null; // Referencia al control de mapas
    this._controller = null;    // Controlador de acciones
    this._container = null; // Contenedor del formulario de edición
    this._form = null; // contenedor del formulario
    this._btnGrabar = null;
    this._btnSiguiente = null;
    this._btnCancelar = null;
    this._btnReubicar = null;
    this._lstTiposDelito = null;    // Lista de selección de tipos de delito
    this._lstSubTiposDelito = null; // Lista de subtipos de delito
    this._lstLugaresDelito = null;  // Lista de lugares donde se produjeron los delitos
    this._lstTiposDenuncia = null;  // Lista de tipos de denuncia
    this._txtFechaDelito = null;    // Fecha en que se produjo el hecho
    this._lstHorasDelito = null;    // Hora delito
    this._lstMinutosDelito = null;  // Minutos delito
    this._txtDelElementosSustraidos = null; // Elementos Sustraidos
    this._txtDenApellidos = null;   // Apellido del denunciante
    this._txtDenNombre = null;     // Nombres del denunciante
    this._txtDenTelefono = null;    // Teléfono
    this._txtDenDomicilio = null;   // Domicilio
    this._txtDenEmail = null;       // Correo electrónico
    this._txtDelLugar = null;       // Descripción Lugar
    //
    this._pagTitle1 = null;     // Título Solapa1
    this._pagContent1 = null;   // Div de contenido para solapa 1
    this._pagTitle2 = null;     // Titulo Solapa2
    this._pagContent2 = null;   // Div de contenido para solapa 2
    this._panel1 = null;        // Panel que contiene la tabla de carga de delito.
    this._panel2 = null;        // Panel que contiene la tabla 2
    // Fields
    this._selectedPage = 1;     // Página del formulario seleccionada
    this._errors = [];           // Arreglo usado para validar y determinar errores
    this._allowSave = false;    // Bandera que determina si permite grabar o si debe presionar siguiente
    // Propiedades
    this._CfgSubTiposDelito = []; // subtipos de delito (extraído del parámetro en JSON)
    this._CfgLugaresDelito = [];  // lugares donde se produjeron delitos (extraido del parámetro en JSON)
    this._CfgTiposDenuncia = [];  // tipos de denuncia (extraido del parámetro en JSON)
    this._ServicePath = null;     // Ruta del servicio web con el método para insertar un delito
    // Eventos
    this._btnGrabar$delegates = {
        mousedown: Function.createDelegate(this, this._btnGrabar_onMouseDownHandler),
        click: Function.createDelegate(this, this._btnGrabar_onClickHandler)
    };
    this._btnSiguiente$delegates = {
        mousedown: Function.createDelegate(this, this._btnSiguiente_onMouseDownHandler),
        click: Function.createDelegate(this, this._btnSiguiente_onClickHandler)
    };
    this._btnReubicar$delegates = {
        mousedown: Function.createDelegate(this, this._btnReubicar_onMouseDownHandler),
        click: Function.createDelegate(this, this._btnReubicar_onClickHandler)
    };
    this._btnCancel$delegates = {
        mousedown: Function.createDelegate(this, this._btnCancel_onMouseDownHandler),
        click: Function.createDelegate(this, this._btnCancel_onClickHandler)
    };
    this._pagTitle1$delegates = {
        mousedown: Function.createDelegate(this, this._pagTitle1_onMouseDownHandler)
    };
    this._pagTitle2$delegates = {
        mousedown: Function.createDelegate(this, this._pagTitle2_onMouseDownHandler)
    };
}

UI.Controls.NewEventFormBehavior.prototype = {
    initialize: function() {
        UI.Controls.NewEventFormBehavior.callBaseMethod(this, 'initialize');
        //
        this._parentControl = this.get_element().control;
        // Construye elementos
        this.buildControls();
    },
    dispose: function() {
        //Add custom dispose actions here

        UI.Controls.NewEventFormBehavior.callBaseMethod(this, 'dispose');
    },
    get_PlugInId: function() {
        /// <value type="string" mayBeNull="false">
        /// Gets de plugIn unique id
        /// </value>

        return 'ui.controls.NewEventForm';
    },
    /// <summary>
    // loads the current plugin into the main map container, creates menu, toolbar, atach events, etc
    /// </summary>
    /// <param name="container" type="SGis.MapToolkit.MapControl">
    /// The map control container
    /// </param>
    load: function(container) {
        this.resetControls();
    },
    unload: function() {
        // Unloads Plugin
    },
    buildControls: function() {
        //
        this._container = $common.createElementFromTemplate(
        {
            nodeName: "div",
            properties: {
                id: "formContainer",
                style: {
                    zIndex: 400
                }
            },
            cssClasses: ["ui_eventform_container"]

        }, $get('aspnetForm'));
        // Contenedor para sombra
        var opacityShadow = .9;
        if (Sys.Browser.agent == Sys.Browser.InternetExplorer && Sys.Browser.version < 7) {
            opacityShadow = 1;
        }

        var shadow = $create(SGis.AjaxToolTip.ToolTipControl,
            { "ArrowOffset": 240, "Border": "Black", "Color": "#DDDDDD", "Opacity": opacityShadow }, null, null, this._container);

        var titulo = $common.createElementFromTemplate(
        {
            nodeName: "div",
            cssClasses: ["ui_eventform_title"],
            properties: {
                innerHTML: "<span>Ingrese Datos del Delito</span>"
            }
        }, this._container);

        // Contenedor para formulario
        var formOpacity = 1;
        this._form = $common.createElementFromTemplate(
        {
            nodeName: "div",
            cssClasses: ["ui_eventform_tipform_form"],
            opacity: formOpacity
        }, this._container);
        // Páginas de formulario
        this._pagTitle1 = $common.createElementFromTemplate(
        {
            nodeName: "div",
            cssClasses: ["ui_eventform_page_active ui_eventform_page1_active"],
            properties: {
                innerHTML: "<span>Delito</span>"
            },
            opacity: formOpacity,
            events: this._pagTitle1$delegates
        }, this._container);

        this._pagTitle2 = $common.createElementFromTemplate(
        {
            nodeName: "div",
            cssClasses: ["ui_eventform_page_inactive ui_eventform_page2_inactive"],
            properties: {
                innerHTML: "<span>Denunciante</span>"
            },
            opacity: formOpacity,
            events: this._pagTitle2$delegates
        }, this._container);
        //
        var filler = $common.createElementFromTemplate(
        {
            nodeName: "div",
            cssClasses: ["ui_eventform_page_filler"],
            opacity: formOpacity
        }, this._container);
        //

        // contenedor de botones
        var buttons = $common.createElementFromTemplate(
        {
            nodeName: "div",
            cssClasses: ["ui_eventform_buttons"]
        }, this._container);
        // Botón reubicar
        this._btnReubicar = $common.createElementFromTemplate(
        {
            nodeName: "a",
            cssClasses: ["ui_eventform_btnreubicar"],
            properties: {
                href: "#",
                innerHTML: "Reubicar Delito",
                title: "Reubicar Delito"
            },
            events: this._btnReubicar$delegates
        }, buttons);
        // Botón grabar
        this._btnGrabar = $common.createElementFromTemplate(
        {
            nodeName: "a",
            cssClasses: ["ui_eventform_btngrabar"],
            properties: {
                href: "#",
                innerHTML: "Grabar Delito",
                title: "Grabar Delito"
            },
            visible: false,
            events: this._btnGrabar$delegates
        }, buttons);

        // Botón siguiente
        this._btnSiguiente = $common.createElementFromTemplate(
        {
            nodeName: "a",
            cssClasses: ["ui_eventform_btnsiguiente"],
            properties: {
                href: "#",
                innerHTML: "Siguiente",
                title: "Siguiente"
            },
            events: this._btnSiguiente$delegates
        }, buttons);
        // Botón Cancelar
        this._btnCancel = $common.createElementFromTemplate(
        {
            nodeName: "a",
            cssClasses: ["ui_eventform_btncancelar"],
            properties: {
                href: "#",
                innerHTML: "Cancelar Carga de Delito",
                title: "Cancelar Carga de Delito"
            },
            events: this._btnCancel$delegates
        }, this._container);
        // Crea tabla para contenidos
        this._panel1 = $common.createElementFromTemplate(
        {
            nodeName: "div",
            cssClasses: ["ui_eventform_panel1"]
        }, this._form);
        this._panel2 = $common.createElementFromTemplate(
        {
            nodeName: "div",
            cssClasses: ["ui_eventform_panel2"],
            visible: false
        }, this._form);

        var msj = $common.createElementFromTemplate(
        {
            nodeName: "span",
            cssClasses: ["ui_eventform_msj"],
            properties: {
                innerHTML: "Los siguientes datos no ser&aacute;n publicados y ser&aacute;n tratados con estricta confidencialidad por parte del Ministerio de Seguridad. La carga de los mismos es opcional."
            }
        }, this._panel2);

        // Crea Controles para panel 1 - Delito
        var tabla1 = $common.createElementFromTemplate(
        {
            nodeName: "table",
            cssClasses: ["ui_eventform_datos1"]
        }, this._panel1);
        var tbody1 = $common.createElementFromTemplate({ nodeName: "tbody" }, tabla1);
        this.buildLstSubTiposDelito(tbody1);
        this.buildLstLugaresDelito(tbody1);
        this.buildTxtDelLugar(tbody1);
        //this._txtDelLugar = this.buildTxtGeneric(tbody1, 'Lugar del Hecho');
        this.buildTxtFechaHoraDelito(tbody1);
        this.buildTxtDescripcion(tbody1);
        this._txtDelElementosSustraidos = this.buildTxtGeneric(tbody1, 'Elementos Sustra&iacute;dos');
        this.buildLstTiposDenuncia(tbody1);
        //this.buildTxtDenunciante(tbody1);
        // Crea Controles para panel 2 - Denunciante
        var tabla2 = $common.createElementFromTemplate(
        {
            nodeName: "table",
            cssClasses: ["ui_eventform_datos2"]
        }, this._panel2);
        var tbody2 = $common.createElementFromTemplate({ nodeName: "tbody" }, tabla2);
        this._txtDenApellidos = this.buildTxtGeneric(tbody2, 'Apellido');
        this._txtDenNombre = this.buildTxtGeneric(tbody2, 'Nombres');
        this._txtDenTelefono = this.buildTxtGeneric(tbody2, 'Tel&eacute;fono');
        this._txtDenEmail = this.buildTxtGeneric(tbody2, 'e-mail');
        this._txtDenDomicilio = this.buildTxtGeneric(tbody2, 'Domicilio');
    },

    // Construye la fila para escribir el nombre del denunciante, retorna el control creado
    buildTxtGeneric: function(tablebody, label) {
        var tr = $common.createElementFromTemplate({ nodeName: "tr" }, tablebody);
        var td1 = $common.createElementFromTemplate(
        {
            nodeName: "td",
            properties: {
                innerHTML: "<span>" + label + "</span>"
            },
            cssClasses: ["ui_eventform_datos1_label"]
        }, tr);
        var td2 = $common.createElementFromTemplate(
        {
            nodeName: "td",
            cssClasses: ["ui_eventform_datos1_field"]
        }, tr);
        var txt = $common.createElementFromTemplate(
        {
            nodeName: "input",
            properties: {
                style: {
                    width: "254px"
                }
            }
        }, td2);
        return txt;
    },
    // Construye la fila para la selección del tipo de delito
    buildLstSubTiposDelito: function(tablebody) {
        var tr = $common.createElementFromTemplate({ nodeName: "tr" }, tablebody);
        var td1 = $common.createElementFromTemplate(
        {
            nodeName: "td",
            properties: {
                innerHTML: "<span>Tipo de Delito</span>"
            },
            cssClasses: ["ui_eventform_datos1_label"]
        }, tr);
        var td2 = $common.createElementFromTemplate(
        {
            nodeName: "td",
            cssClasses: ["ui_eventform_datos1_field"]
        }, tr);
        this._lstSubTiposDelito = $common.createElementFromTemplate(
        {
            nodeName: "select",
            properties: {
                style: {
                    width: "100%"
                }
            }
        }, td2);
        this.resetLstSubTiposDelito(); // configura lista
    },
    // Construye la fila para la selección de lugares de delito
    buildLstLugaresDelito: function(tablebody) {
        var tr = $common.createElementFromTemplate({ nodeName: "tr" }, tablebody);
        var td1 = $common.createElementFromTemplate(
        {
            nodeName: "td",
            properties: {
                innerHTML: "<span>Tipo de Lugar</span>"
            },
            cssClasses: ["ui_eventform_datos1_label"]
        }, tr);
        var td2 = $common.createElementFromTemplate(
        {
            nodeName: "td",
            cssClasses: ["ui_eventform_datos1_field"]
        }, tr);
        this._lstLugaresDelito = $common.createElementFromTemplate(
        {
            nodeName: "select",
            properties: {
                style: {
                    width: "100%"
                }
            }
        }, td2);
        this.resetLstLugaresDelito();

    },
    // Construye la fila para la selección de fecha y hora
    buildTxtFechaHoraDelito: function(tablebody) {
        var tr = $common.createElementFromTemplate({ nodeName: "tr" }, tablebody);
        var td1 = $common.createElementFromTemplate(
        {
            nodeName: "td",
            properties: {
                innerHTML: "<span>Fecha ocurrido</span>"
            },
            cssClasses: ["ui_eventform_datos1_label"]
        }, tr);
        var td2 = $common.createElementFromTemplate(
        {
            nodeName: "td",
            cssClasses: ["ui_eventform_datos1_field"]
        }, tr);
        var div = $common.createElementFromTemplate(
        {
            nodeName: "div",
            properties: {
                style: {
                    width: "100%"
                }
            }
        }, td2);
        var d = new Date();
        this._txtFechaDelito = $common.createElementFromTemplate(
        {
            nodeName: "input",
            properties: { id: "txtFechaHoraDelito", value: d.localeFormat("d") },
            cssClasses: ["ui_eventform_txtfechahora"]
        }, div);
        // Botón calendario
        var imgCal = $common.createElementFromTemplate(
        {
            nodeName: "div",
            properties: {
                id: "imgCalendar",
                innerHTML: "&nbsp;"
            },
            cssClasses: ["ui_eventform_calendar"]
        }, div);
        // Máscara para fecha
        $create(
            AjaxControlToolkit.MaskedEditBehavior,
            {
                "ClientStateFieldID": "ctl00_NewEventContentPlaceHolder_MskHastaFechaTrayecto_ClientState",
                "CultureAMPMPlaceholder": "",
                "CultureCurrencySymbolPlaceholder": "€",
                "CultureDateFormat": "DMY",
                "CultureDatePlaceholder": "/",
                "CultureDecimalPlaceholder": ",",
                "CultureName": "es-ES",
                "CultureThousandsPlaceholder": ".",
                "CultureTimePlaceholder": ":",
                "ErrorTooltipEnabled": true,
                "Mask": "99/99/9999",
                "MaskType": 1,
                "id": "mskFechaDelito"
            }, null, null, this._txtFechaDelito);
        // Calendaro para seleccionar fecha

        var showCalButton = true;
        if (Sys.Browser.agent == Sys.Browser.InternetExplorer && Sys.Browser.version < 7) {
            opacityShadow = false; // No lo muestra par ie 6 o anterior
        }
        if (showCalButton) {
            $create(
            AjaxControlToolkit.CalendarBehavior,
            {
                "button": imgCal,
                "id": "calendarFechaDelito"
            }, null, null, this._txtFechaDelito);
        }
        // Texto hora
        $common.createElementFromTemplate(
        {
            nodeName: "span",
            properties: {
                innerHTML: "Hora",
                style: {
                    marginLeft: "5px"
                }
            }
        }, div);
        // Lista de horas
        this._lstHorasDelito = $common.createElementFromTemplate(
        {
            nodeName: "select",
            properties: {
                style: {
                    width: "40px",
                    marginLeft: "5px"
                }
            }
        }, div);
        this.resetHorasDelito();
        this._lstMinutosDelito = $common.createElementFromTemplate(
        {
            nodeName: "select",
            properties: {
                style: {
                    width: "40px",
                    marginLeft: "5px"
                }
            }
        }, div);
        this.resetMinutosDelito();
    },
    // Construye la fila para la selección del tipo de denuncia del delito
    buildLstTiposDenuncia: function(tablebody) {
        var tr = $common.createElementFromTemplate({ nodeName: "tr" }, tablebody);
        var td1 = $common.createElementFromTemplate(
        {
            nodeName: "td",
            properties: {
                innerHTML: "<span>¿Realizó la denuncia?</span>"
            },
            cssClasses: ["ui_eventform_datos1_label"]
        }, tr);
        var td2 = $common.createElementFromTemplate(
        {
            nodeName: "td",
            cssClasses: ["ui_eventform_datos1_field"]
        }, tr);
        this._lstTiposDenuncia = $common.createElementFromTemplate(
        {
            nodeName: "select",
            properties: {
                style: {
                    width: "100%"
                }
            }
        }, td2);
        this.resetLstTiposDenuncia(); // configura lista
    },
    // Construye la fila para la carga del detalle de lo ocurrido
    buildTxtDescripcion: function(tablebody) {
        var tr = $common.createElementFromTemplate({ nodeName: "tr" }, tablebody);
        var td1 = $common.createElementFromTemplate(
        {
            nodeName: "td",
            properties: {
                innerHTML: "<span>Descripci&oacute;n de los hechos</span>"
            },
            cssClasses: ["ui_eventform_datos1_label"]
        }, tr);
        var td2 = $common.createElementFromTemplate(
        {
            nodeName: "td",
            cssClasses: ["ui_eventform_datos1_field"]
        }, tr);
        this._txtDescripcion = $common.createElementFromTemplate(
        {
            nodeName: "textarea",
            properties: {
                title: "Describa brevemente lo sucedido",
                cols: "20",
                rows: "5",
                style: {
                    width: "100%"
                }
            }
        }, td2);
    },

    // Construye la fila para la carga del lugar
    buildTxtDelLugar: function(tablebody) {
        var tr = $common.createElementFromTemplate({ nodeName: "tr" }, tablebody);
        var td1 = $common.createElementFromTemplate(
        {
            nodeName: "td",
            properties: {
                innerHTML: "<span>Lugar del Hecho</span>"
            },
            cssClasses: ["ui_eventform_datos1_label"]
        }, tr);
        var td2 = $common.createElementFromTemplate(
        {
            nodeName: "td",
            cssClasses: ["ui_eventform_datos1_field"]
        }, tr);
        this._txtDelLugar = $common.createElementFromTemplate(
        {
            nodeName: "textarea",
            properties: {
                title: "Lugar del hecho",
                cols: "20",
                rows: "2",
                style: {
                    width: "100%"
                }
            }
        }, td2);
    },
    // Construye la fila para escribir el nombre del denunciante
    buildTxtDenunciante: function(tablebody) {
        var tr = $common.createElementFromTemplate({ nodeName: "tr" }, tablebody);
        var td1 = $common.createElementFromTemplate(
        {
            nodeName: "td",
            properties: {
                innerHTML: "<span>Denunciante</span>"
            },
            cssClasses: ["ui_eventform_datos1_label"]
        }, tr);
        var td2 = $common.createElementFromTemplate(
        {
            nodeName: "td",
            cssClasses: ["ui_eventform_datos1_field"]
        }, tr);
        this._txtReportante = $common.createElementFromTemplate(
        {
            nodeName: "input",
            properties: {
                style: {
                    width: "100%"
                }
            }
        }, td2);
    },
    // Selecciona la página de datos 1
    selectPage1: function() {
        this._selectedPage = 1;
        // Oculta resto
        this.hidePage2();
        // Muestra pagina
        this.showPage1();
    },
    // Selecciona la página de datos 2
    selectPage2: function() {
        this._selectedPage = 2;
        // Oculta resto
        this.hidePage1();
        // Muestra pagina
        this.showPage2();
        // Muestra boton grabar al entrar en esta página
        this.showBtnGrabar();
    },
    // Oculta Página 1
    hidePage1: function() {
        var elt = this._pagTitle1;
        Sys.UI.DomElement.removeCssClass(elt, "ui_eventform_page_active");
        Sys.UI.DomElement.removeCssClass(elt, "ui_eventform_page1_active");
        Sys.UI.DomElement.addCssClass(elt, "ui_eventform_page_inactive");
        Sys.UI.DomElement.addCssClass(elt, "ui_eventform_page1_inactive");
        Sys.UI.DomElement.setVisible(this._panel1, false);
    },
    // Oculta Página 2
    hidePage2: function() {
        var elt = this._pagTitle2;
        Sys.UI.DomElement.removeCssClass(elt, "ui_eventform_page_active");
        Sys.UI.DomElement.removeCssClass(elt, "ui_eventform_page2_active");
        Sys.UI.DomElement.addCssClass(elt, "ui_eventform_page_inactive");
        Sys.UI.DomElement.addCssClass(elt, "ui_eventform_page2_inactive");
        Sys.UI.DomElement.setVisible(this._panel2, false);
    },
    // Muestra Pagina 1
    showPage1: function() {
        var elt = this._pagTitle1;
        Sys.UI.DomElement.addCssClass(elt, "ui_eventform_page_active");
        Sys.UI.DomElement.addCssClass(elt, "ui_eventform_page1_active");
        Sys.UI.DomElement.removeCssClass(elt, "ui_eventform_page_inactive");
        Sys.UI.DomElement.removeCssClass(elt, "ui_eventform_page1_inactive");
        Sys.UI.DomElement.setVisible(this._panel1, true);
    },
    // Muestra Página 2
    showPage2: function() {
        var elt = this._pagTitle2;
        Sys.UI.DomElement.addCssClass(elt, "ui_eventform_page_active");
        Sys.UI.DomElement.addCssClass(elt, "ui_eventform_page2_active");
        Sys.UI.DomElement.removeCssClass(elt, "ui_eventform_page_inactive");
        Sys.UI.DomElement.removeCssClass(elt, "ui_eventform_page2_inactive");
        Sys.UI.DomElement.setVisible(this._panel2, true);
    },

    //
    resetControls: function() {
    },
    // Resetea lista de tipos de denuncia
    resetLstTiposDenuncia: function() {
        var lst = this._lstTiposDenuncia;
        lst.options[lst.options.length] = new Option("<Seleccione una opción>", "-1");
        lst.options[lst.options.length - 1].selected = true;
        for (var i in this._CfgTiposDenuncia) {
            var den = this._CfgTiposDenuncia[i];
            var o = new Option(den.DenNombre, den.DenId.toString());
            o.CfgTipoDenuncia = den;
            lst.options[lst.options.length] = o;
        }
    },
    // Resetea lista de lugares de delito
    resetLstLugaresDelito: function() {
        var lst = this._lstLugaresDelito;
        lst.options[lst.options.length] = new Option("<Seleccione Lugar>", "-1");
        lst.options[lst.options.length - 1].selected = true;
        for (var i in this._CfgLugaresDelito) {
            var lug = this._CfgLugaresDelito[i];
            var o = new Option(lug.LugNombre, lug.LugId.toString());
            o.CfgLugaresDelito = lug;
            lst.options[lst.options.length] = o;
        }
    },
    // Resetea lista de subtipos de delito
    resetLstSubTiposDelito: function() {
        var lst = this._lstSubTiposDelito;
        lst.innerHTML = "";
        lst.options[lst.options.length] = new Option("<Seleccione Delito>", "-1");
        lst.options[lst.options.length - 1].selected = true;
        for (var j in this._CfgSubTiposDelito) {
            var std = this._CfgSubTiposDelito[j];
            var o = new Option(std.StdNombre, std.StdId.toString());
            o.CfgSubTipoDelito = std;
            lst.options[lst.options.length] = o;
        }
    },
    // Resetea lista de horas de delito
    resetHorasDelito: function() {
        var lst = this._lstHorasDelito;
        for (var i = 0; i < 24; i++) {
            var o = new Option(i.toString(), i.toString());
            lst.options[lst.options.length] = o;
        }
        lst.options[0].selected = true;
    },
    // Resetea lista de minutos de delito
    resetMinutosDelito: function() {
        var lst = this._lstMinutosDelito;
        for (var i = 0; i < 60; i++) {
            var o = new Option(i.toString(), i.toString());
            lst.options[lst.options.length] = o;
        }
        lst.options[0].selected = true;
    },
    // Muestra el foormulario en las coordenadas de pantalla especificadas
    showForm: function(screenCoords, mapCoords, controller) {
        this._container.style.left = (screenCoords.x + 10) + "px";
        this._container.style.top = (screenCoords.y - 250) + "px";
        this._controller = controller;
        Sys.UI.DomElement.setVisible(this._container, true);
        //
        // Hack para ie6
        var mapLocation = $find("MapLocation");
        if (mapLocation) mapLocation.hackIe6HideSelects();
    },
    // Oculta formulario para carga de evento
    hideForm: function() {
        Sys.UI.DomElement.setVisible(this._container, false);
        // Hack para ie6
        var mapLocation = $find("MapLocation");
        if (mapLocation) mapLocation.hackIe6ShowSelects();
    },
    // Oculta formulario para carga de evento
    hideBtnGrabar: function() {
        Sys.UI.DomElement.setVisible(this._btnGrabar, false);
        Sys.UI.DomElement.setVisible(this._btnSiguiente, true);
        this._allowSave = false;
    },
    // Oculta formulario para carga de evento
    showBtnGrabar: function() {
        Sys.UI.DomElement.setVisible(this._btnGrabar, true);
        Sys.UI.DomElement.setVisible(this._btnSiguiente, false);
        this._allowSave = true;
    },
    // Inicializa el contenido del formulario
    clearForm: function() {
        var d = new Date();
        this._lstLugaresDelito.options[0].selected = true;  // Lista de lugares donde se produjeron los delitos
        this._lstTiposDenuncia.options[0].selected = true;  // Lista de tipos de denuncia
        this._txtFechaDelito.value = d.localeFormat("d");   // Fecha en que se produjo el hecho
        this._lstHorasDelito.options[0].selected = true;    // Hora delito
        this._lstMinutosDelito.options[0].selected = true;  // Minutos delito
        this._txtDescripcion.value = "";
        this._txtDenApellidos.value = "";
        this._txtDenNombre.value = "";
        this._txtDenDomicilio.value = "";
        this._txtDenTelefono.value = "";
        this._txtDenEmail.value = "";
        this._txtDelLugar.value = "";
        this._txtDelElementosSustraidos.value = "";
        this.hideBtnGrabar();
        this.selectPage1();
    },
    // Invoca al servicio web para gragar un delito
    invokeInsertDelitoWebService: function() {
        // Prepara objeto parámetros
        var param = new Object();
        this._errors = new Array();
        // Datos de la denuncia
        param.stdId = this.validStdId();
        param.lugId = this.validLugId();
        param.delLugar = this._txtDelLugar.value;
        param.denId = this.validDenId();
        param.delDescripcion = this.validDelDescripcion();
        param.delFechaString = this.validDelFecha();
        param.delHoraString = this.validDelHora();
        param.delMinutosString = this.validDelMinutos();
        param.delElementosSustraidos = this._txtDelElementosSustraidos.value;
        param.delLat = this._controller._eventY;
        param.delLon = this._controller._eventX;
        // Datos del reportante
        param.delDenApellidos = this._txtDenApellidos.value;
        param.delDenNombre = this._txtDenNombre.value;
        param.delDenTelefono = this._txtDenTelefono.value;
        param.delDenEmail = this._txtDenEmail.value;
        param.delDenDomicilio = this._txtDenDomicilio.value;
        // Datos de domicilio cargado en el buscador
        var loc = $find('MapLocation');
        param.delLocNombre = loc._lstLocalidades.selectedIndex < 0 ? '' : loc._lstLocalidades.options[loc._lstLocalidades.selectedIndex].text;
        param.delBarNombre = loc._txtBarrio.value;
        param.delCalNombre = loc._txtCalle.value;
        param.delCalEsquina = loc._txtCalleEsquina.value;
        // Datos sobre el filtro activo
        var fil = $find('EventFilter');
        param.filFechaDesde = fil._CfgFiltro.FechaDesde;
        param.filFechaHasta = fil._CfgFiltro.FechaHasta;
        // 
        //
        if (this._errors.length == 0) {
            Sys.Net.WebServiceProxy.invoke(this._ServicePath, "InsertDelito", false, param,
        Function.createDelegate(this, this.onInsertDelitoMethodComplete),
        Function.createDelegate(this, this.onInsertDelitoMethodError), null, 50000);
        } else {
            var txt = "No se pudo grabar el delito, corrija los siguientes errores:";
            for (var i = 0; i < this._errors.length; i++) {
                txt = txt + "\n   - " + this._errors[i].toString();
            }
            alert(txt);
        }
    },

    // Valida el subtipo de delito
    validStdId: function() {
        var v = parseInt(this._lstSubTiposDelito.value);
        if (v < 0) {
            Array.add(this._errors, "Debe seleccionar un subtipo de delito");
        }
        return v;
    },

    // Valida el lugar
    validLugId: function() {
        var v = parseInt(this._lstLugaresDelito.value);
        if (v < 0) {
            Array.add(this._errors, "Debe seleccionar un lugar");
        }
        return v;
    },
    // Valida tipo de denuncia
    validDenId: function() {
        var v = parseInt(this._lstTiposDenuncia.value);
        if (v < 0) {
            Array.add(this._errors, "Debe seleccionar una opción de denuncia");
        }
        return v;
    },
    // Valida texto de descripcion
    validDelDescripcion: function() {
        var v = this._txtDescripcion.value.toString().trim();
        if (v.length < 5) {
            Array.add(this._errors, "Descripción del delito demasiado corta");
        }
        return v;
    },
    // Valida texto fecha
    validDelFecha: function() {
        return this._txtFechaDelito.value;
    },
    // Valida Hora
    validDelHora: function() {
        return this._lstHorasDelito.value;
    },
    // Valida minutos
    validDelMinutos: function() {
        return this._lstMinutosDelito.value;
    },
    // Se completo invocación al web service - GetLocalidades
    onInsertDelitoMethodComplete: function(result, userContext, methodName) {
        if (result.Inserted) {
            alert(result.Message);
            if (this._controller) {
                this._controller.invalidate();
                this._controller.setStatusReady(this);
            }
        } else {
            var txt = "No se pudo grabar el delito debido a los siguientes errores:";
            txt = txt + "\n  " + result.Message;
            alert(txt);
        }
    },
    // Error al invocar web service
    onInsertDelitoMethodError: function(webServiceError, userContext, methodName) {
        //debugger;
        var txt = "No se pudo grabar el delito debido a los siguientes errores:";
        for (var i = 0; i < this._errors.length; i++) {
            txt = txt + "\n  " + webServiceError.toString();
        }
        alert(txt);
    },
    //--------------------------------------------------------------------------
    // Acceso a Propiedades
    //--------------------------------------------------------------------------
    get_CfgTiposDelito: function() {
        return this._CfgTiposDelito;
    },
    set_CfgTiposDelito: function(value) {
        if (this._CfgTiposDelito != value) {
            this._CfgTiposDelito = value;
            this.raisePropertyChanged('CfgTiposDelito');
        }
    },
    get_CfgLugaresDelito: function() {
        return this._CfgLugaresDelito;
    },
    set_CfgLugaresDelito: function(value) {
        if (this._CfgLugaresDelito != value) {
            this._CfgLugaresDelito = value;
            this.raisePropertyChanged('CfgLugaresDelito');
        }
    },
    get_CfgSubTiposDelito: function() {
        return this._CfgSubTiposDelito;
    },
    set_CfgSubTiposDelito: function(value) {
        if (this._CfgSubTiposDelito != value) {
            this._CfgSubTiposDelito = value;
            this.raisePropertyChanged('CfgSubTiposDelito');
        }
    },
    get_CfgTiposDenuncia: function() {
        return this._CfgTiposDenuncia;
    },
    set_CfgTiposDenuncia: function(value) {
        if (this._CfgTiposDenuncia != value) {
            this._CfgTiposDenuncia = value;
            this.raisePropertyChanged('CfgTiposDenuncia');
        }
    },
    get_ServicePath: function() {
        return this._ServicePath;
    },
    set_ServicePath: function(value) {
        if (this._ServicePath != value) {
            this._ServicePath = value;
            this.raisePropertyChanged('ServicePath');
        }
    },
    //--------------------------------------------------------------------------
    // Manejadores de Eventos
    //--------------------------------------------------------------------------
    _btnGrabar_onMouseDownHandler: function(sender, args) {
        this.invokeInsertDelitoWebService();
    },
    _btnGrabar_onClickHandler: function(sender, args) {
        sender.preventDefault();
        sender.stopPropagation();
    },
    _btnSiguiente_onMouseDownHandler: function(sender, args) {
        this.selectPage2();
    },
    _btnSiguiente_onClickHandler: function(sender, args) {
        sender.preventDefault();
        sender.stopPropagation();
    },
    //
    _btnReubicar_onMouseDownHandler: function(sender, args) {
        this._controller.setStatusRelocating(sender);
    },
    _btnReubicar_onClickHandler: function(sender, args) {
        sender.preventDefault();
        sender.stopPropagation();
    },
    _btnCancel_onMouseDownHandler: function(sender, args) {
        if (this._controller && confirm("Desea cancelar la carga del delito. Los datos ingresados se perderán.")) {
            this._controller.setStatusReady(sender);
        }
    },
    _btnCancel_onClickHandler: function(sender, args) {
        sender.preventDefault();
        sender.stopPropagation();
    },
    _pagTitle1_onMouseDownHandler: function(sender, args) {
        if (this._selectedPage != 1) {
            this.selectPage1();
        }
    },
    _pagTitle2_onMouseDownHandler: function(sender, args) {
        if (this._selectedPage != 2) {
            this.selectPage2();
        }
    }
}

UI.Controls.NewEventFormBehavior.registerClass('UI.Controls.NewEventFormBehavior', AjaxControlToolkit.BehaviorBase, SGis.MapToolkit.IPlugIn);



if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();