﻿function selectorMultinivelV2() {
    this.idSelectorRegion = "";
    this.idSelectorDestination = "";
    this.idSelectorLocation = "";
    this.msgSelect = "Select";
    this.msgAll = "All";
    this.clp = "";
    this.product = "";
}

selectorMultinivelV2.prototype.getSelectedValue = function() {
    var selected = "";
    //if (document.getElementById(this.idSelectorRegion).selectedIndex > 0) selected = document.getElementById(this.idSelectorRegion).value;
    if (document.getElementById(this.idSelectorDestination).selectedIndex > 0) selected = document.getElementById(this.idSelectorDestination).value;
    if (document.getElementById(this.idSelectorLocation).selectedIndex > 0) selected = document.getElementById(this.idSelectorLocation).value;
    return selected;
}


selectorMultinivelV2.prototype.resetSelectors = function() {
    document.getElementById(this.idSelectorRegion).selectedIndex = 0;
    var selector = document.getElementById(this.idSelectorLocation);
    selector.options.length = 0;
    selector.options[0] = new Option('- - - - - - - - - - - - - - - - - - - - ', -1);
    selector.disabled = true;
    selector = document.getElementById(this.idSelectorDestination);
    selector.options.length = 0;
    selector.options[0] = new Option('- - - - - - - - - - - - - - - - - - - - ', -1);
    selector.disabled = true;
}

selectorMultinivelV2.prototype.obtenerZonasDePadre = function(idpadre, selectorId, selzon) {
    var selector = document.getElementById(selectorId);
    var xmlDocZonas = new XMLRemoteRequest("xmlDocZonas");
    xmlDocZonas.getRemoteDocument("/include/ctlselectorMultinivelV2/obtenerZonasdePadre.ashx?idZon=" + idpadre + "&tipo=" + this.product + "&clp=" + this.clp);
    var list = xmlDocZonas.selectNodes("zonas/zona")
    selector.options.length = 0;
    if (list.length == 0) {
        selector.options[0] = new Option('- - - - - - - - - - - - - - - - - - - - ', -1);
        selector.disabled = true;
    }
    else {
        if (selectorId == "<%=me.Zona.clientId%>") selector.options[0] = new Option(this.msgAll, -1)
        else selector.options[0] = new Option(this.msgSelect, -1)
        selector.disabled = false;
        for (var i = 0; i < list.length; i++) {
            var id = list[i].getAttribute("id");
            var nombre = list[i].getAttribute("nombre");
            selector.options[i + 1] = new Option(nombre, id)
        }
        if (selzon != null) selector.value = selzon;
    }
    if (selector.getAttribute('selectHijo') != null) this.obtenerZonasDePadre(selector.value, selector.getAttribute('selectHijo'));
}


