function objFecha(id, fecha, fechaFin, encabezado) {
    this.setId(id);
    this.setEncabezado(encabezado);
    this.setFechaInicial(fecha);
    this.setFecha(fecha);
    this.setFechaFin(fechaFin);
    //Construccion de los combos;

    this.setComboAnio();
    this.setDiv();
    var css = document.createElement('link');
    css.href = "/interfaz/css/fecha/fecha.css";
    css.type = "text/css";
    css.rel = "stylesheet";
    document.lastChild.firstChild.appendChild(css);
}

objFecha.prototype = {
    // Definimos las propiedades;
    encabezado: true,
    fechaEntrante: "",
    pId: "",
    pFecha: "",
    pMes: "",
    pDia: "",
    pAnio: "",

    pAnioFin: "",
    pMesFin: "",
    pDiaFin: "",
    pFechaFin: "",

    pComboMes: "",
    pComboDia: "",
    pComboAnio: "",
    divFecha: "",
    proc: "", //verifica en que paso esta la pagina....;
    // Definir los metodos.;
    setEncabezado: function(encabezado) {
        if (encabezado) {
            this.encabezado = false;
        }
        else {
            this.encabezado = true;
        }
    },
    setDiv: function() {
        //Div;
        var divFecha = document.createElement("div");
        divFecha.id = "divFecha" + this.pId;
        //Tabla;
        varTablaDiv = document.createElement("table");
        varTablaDiv.id = this.pId;
        varTablaDiv.fin = this.pFechaFin;

        if (this.encabezado) {
            rowLabels = varTablaDiv.insertRow(0);
            cellMonthLabel = rowLabels.insertCell(0);
            cellDayLabel = rowLabels.insertCell(1);
            cellYearLabel = rowLabels.insertCell(2);
            labelMonth = document.createTextNode("Month");
            labelDay = document.createTextNode("Day");
            labelYear = document.createTextNode("Year");
            cellMonthLabel.appendChild(labelMonth);
            cellDayLabel.appendChild(labelDay);
            cellYearLabel.appendChild(labelYear);
            rowCombos = varTablaDiv.insertRow(1);
        }
        else {
            rowCombos = varTablaDiv.insertRow(0);
        }
        cellComboMonth = rowCombos.insertCell(0);
        cellComboDay = rowCombos.insertCell(1);
        cellComboYear = rowCombos.insertCell(2);

        cellComboMonth.appendChild(this.pComboMes);
        cellComboDay.appendChild(this.pComboDia);
        cellComboYear.appendChild(this.pComboAnio);

        divFecha.appendChild(varTablaDiv);
        this.divFecha = divFecha;
        if (paso == "Paso1" || paso == "Edit" || paso == "Hotel") {
            cambiarFec(this.pId, this.getFecha());
        }
    },
    getDiv: function() {
        return this.divFecha;
    },
    setId: function(id) {
        this.pId = id;
    },
    setFechaInicial: function(fecha) {
        var fech = new Date(incFecha(fechaActual()));
        var Mes = fech.getMonth() + 1;
        var Dia = fech.getDate();
        var Anio = fech.getFullYear();
        this.fechaEntrante = "" + Mes + "/" + Dia + "/" + Anio;
    },
    setFecha: function(fecha) {
        if (fecha == "") {
            fecha = this.fechaEntrante;
        }
        this.pFecha = fecha;
        // Debe cargar mes dia y anio descomponiendo fecha;
        var fecha = new Date(fecha);
        this.pMes = fecha.getMonth() + 1;
        this.pDia = fecha.getDate();
        this.pAnio = fecha.getFullYear();
    },
    setFechaFin: function(fechaFin) {
        this.pFechaFin = fechaFin;
        var fechFin = new Date(fechaFin);
        this.pMesFin = fechFin.getMonth() + 1;
        this.pDiaFin = fechFin.getDate();
        this.pAnioFin = fechFin.getFullYear();
    },
    getFecha: function() {
        return "" + this.pMes + "/" + this.pDia + "/" + this.pAnio;
    },
    getComboMes: function() {
        return this.pComboMes;
    },
    getComboDia: function() {
        return this.pComboDia;
    },
    getComboAnio: function() {
        return this.pComboAnio;
    },
    setComboMes: function() {
        if (paso == "Paso1" || paso == "Paso2" || paso == "Paso3" || paso == "Hotel") {
            if (this.pId == "fecha1") {
                var fecha = new Date(this.fechaEntrante);
            }
            else {
                var fecha = new Date(incFecha(obternerFec(this.pId)));
            }
        }
        else {
            var fecha = new Date(this.fechaEntrante);
        }
        anioCom = fecha.getFullYear();
        if (anioCom == this.pComboAnio.valor) {
            //SE LE RESTA UNO PARA POSICIONARME SOBRE EL ARREGLO;
            inicio = parseInt(fecha.getMonth() + 1) - 1;
        }
        else {
            inicio = 0;
        }

        var dMonths = document.createElement("select");
        dMonths.id = "ComboMes" + this.pId;
        dMonths.setAttribute(dclase, "select");
        dMonths.parentId = this.pId;
        //VALOR DEL ANIO SELECCIONADO;
        dMonths.valor = "";
        dMonths.fin = this.pFechaFin;
        dMonths.encab = this.encabezado;
        dMonths.fechaSel = this.pFecha;

        if (this.pComboAnio.valor == this.pAnioFin) {
            dMesfinal = parseInt(this.pMesFin) - 1;
        }
        else { dMesfinal = 11; }


        var meses = "JAN|FEB|MAR|ABR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC";
        var meses1 = meses.split("|");

        for (i = inicio; i <= dMesfinal; i++) {
            var mes = document.createElement('option');
            mes.text = meses1[i];
            mes.value = i;
            if ((this.pMes - 1) == i) {
                mes.selected = true;
            }
            if (isIe) {
                dMonths.add(mes);
            }
            else {
                dMonths.appendChild(mes);
            }
        }
        dMonths.onchange = function() {
            proc = paso;
            this.pMes = parseInt(this.options[this.selectedIndex].value) + 1;
            diaChan = document.getElementById("ComboDia" + this.parentId).value;
            aniChan = document.getElementById("ComboAnio" + this.parentId).value;

            var nuevaFecha = getfecha(this.pMes + "/" + diaChan + "/" + aniChan);
            this.fechaSel = nuevaFecha;
            DivObjHijoMes = new objFecha(this.parentId, nuevaFecha, this.fin, this.encab);
            elemento = document.getElementById("ComboMes" + this.parentId);
            padre = elemento.parentNode;
            padre.replaceChild(DivObjHijoMes.pComboMes, elemento);

            elemento1 = document.getElementById("ComboDia" + this.parentId);
            padre1 = elemento1.parentNode;
            padre1.replaceChild(DivObjHijoMes.pComboDia, elemento1);
            elemento2 = document.getElementById("ComboAnio" + this.parentId);
            padre2 = elemento2.parentNode;
            padre2.replaceChild(DivObjHijoMes.pComboAnio, elemento2);
            
            if (proc == "Paso1" || proc == "Paso2" || proc == "Paso3" || proc == "Hotel") {
                contruirFech(this.parentId, nuevaFecha);
            }
            if (proc == "Paso1" || proc == "Paso2" || proc == "Edit" || proc == "Hotel") {
                cambiarFec(this.parentId, nuevaFecha);
            }
        },
        dMonths.valor = this.pMes;
        this.pComboMes = dMonths;
        this.setComboDia();
    },
    setComboDia: function() {
        var dDays = document.createElement("select");
        dDays.id = "ComboDia" + this.pId;
        dDays.setAttribute(dclase, "select");
        dDays.parentId = this.pId;
        dDays.valor = "";
        dDays.fin = this.pFechaFin;
        dDays.encab = this.encabezado;
        dDays.fechaSel = this.pFecha;

        // Determinar el fin de los dias segun el mes seleccionado;
        if (paso == "Paso1" || paso == "Paso2" || paso == "Paso3" || paso == "Hotel") {
            if (this.pId == "fecha1") {
                var fecha = new Date(this.fechaEntrante);
            }
            else {
                var fecha = new Date(incFecha(obternerFec(this.pId)));
            }
        }
        else {
            var fecha = new Date(this.fechaEntrante);
        }
        inicio = fecha.getMonth();
        //recogo el valor del mes posicionado;
        var dmes = this.pComboMes.valor;
        var anioSeleccionado = this.pComboAnio.valor;
        //Determinar el inicio de los dias segun si el mes actual es el mes seleccionado;
        dmesactual = inicio + 1;

        anioCom = fecha.getFullYear();
        if (anioCom == this.pComboAnio.valor && dmesactual == this.pComboMes.valor) {
            diniciodias = fecha.getDate();
        }
        else {
            diniciodias = 1;
        }
        if (this.pComboAnio.valor == this.pAnioFin && this.pComboMes.valor == this.pMesFin) {
            dfindias = parseInt(this.pDiaFin);
        }
        else {
            dfindias = fechaDia(dmes, anioSeleccionado);
        }
        //construir el select;
        for (i = diniciodias; i <= dfindias; i++) {
            var Day1 = document.createElement('option');
            Day1.text = i;
            Day1.value = i;
            if (this.pDia == i) {
                Day1.selected = true;
            }
            else {
                Day1.selected = false;
            }
            if (isIe) {
                dDays.add(Day1);
            }
            else {
                dDays.appendChild(Day1);
            }
        }
        dDays.onchange = function() {
            proc = paso;
            this.pDia = parseInt(this.options[this.selectedIndex].value);
            mesChan = parseInt(document.getElementById("ComboMes" + this.parentId).value) + 1;
            aniChan = document.getElementById("ComboAnio" + this.parentId).value;

            var nuevaFecha = getfecha(mesChan + "/" + this.pDia + "/" + aniChan);
            this.fechaSel = nuevaFecha;
            DivObjHijoDia = new objFecha(this.parentId, nuevaFecha, this.fin, this.encab);
            elemento = document.getElementById("ComboDia" + this.parentId);
            padre = elemento.parentNode;
            padre.replaceChild(DivObjHijoDia.pComboDia, elemento);

            elemento1 = document.getElementById("ComboMes" + this.parentId);
            padre1 = elemento1.parentNode;
            padre1.replaceChild(DivObjHijoDia.pComboMes, elemento1);
            elemento2 = document.getElementById("ComboAnio" + this.parentId);
            padre2 = elemento2.parentNode;
            padre2.replaceChild(DivObjHijoDia.pComboAnio, elemento2);

            if (proc == "Paso2" || proc == "Edit") {
                contruirSegmento(this.parentId, nuevaFecha);
            }
            if (proc == "Paso1" || proc == "Paso2" || proc == "Paso3" || proc == "Hotel") {
                contruirFech(this.parentId, nuevaFecha);

            }
            if (proc == "Paso2" || proc == "Edit" || proc == "Hotel") {
                cambiarFec(this.parentId, nuevaFecha);
            }
        },
        dDays.valor = this.pDia;
        this.pComboDia = dDays;
    },
    //ANIO SI;
    setComboAnio: function() {
        var anioSele = this.pAnio;
        var dYears = document.createElement("select");
        dYears.id = "ComboAnio" + this.pId;
        dYears.setAttribute(dclase, "select");
        dYears.parentId = this.pId;
        dYears.valor = "";
        dYears.encab = this.encabezado;
        dYears.fin = this.pFechaFin;
        dYears.fechaSel = this.pFecha;

        if (paso == "Paso1" || paso == "Paso2" || paso == "Paso3" || paso == "Hotel") {
            if (this.pId == "fecha1") {
                var fecha = new Date(this.fechaEntrante);
            }
            else {
                var fecha = new Date(incFecha(obternerFec(this.pId)));
            }
        }
        else {
            var fecha = new Date(this.fechaEntrante);
        }
        dAnioinicio = fecha.getFullYear();
        //Determinar el inicio de los anios apartir del anio actual;
        dAniofinal = this.pAnioFin;

        //construir el select;
        for (i = dAnioinicio; i <= dAniofinal; i++) {
            var Anio = document.createElement('option');
            Anio.text = i;
            Anio.value = i;
            //carga el select;
            if (this.pAnio == i) {
                Anio.selected = true;
            }
            else {
                Anio.selected = false;
            }
            if (isIe) {
                dYears.add(Anio);
            }
            else {
                dYears.appendChild(Anio);
            }
        }
        dYears.onchange = function() {
            proc = paso;
            this.pAnio = this.options[this.selectedIndex].value;
            mesChan = parseInt(document.getElementById("ComboMes" + this.parentId).value) + 1;
            diaChan = document.getElementById("ComboDia" + this.parentId).value;

            var nuevaFecha = getfecha(mesChan + "/" + diaChan + "/" + this.pAnio);

            this.fechaSel = nuevaFecha;

            DivObjHijo = new objFecha(this.parentId, nuevaFecha, this.fin, this.encab);
            elemento = document.getElementById("ComboAnio" + this.parentId);
            padre = elemento.parentNode;
            padre.replaceChild(DivObjHijo.pComboAnio, elemento);
            elemento1 = document.getElementById("ComboMes" + this.parentId);
            padre1 = elemento1.parentNode;
            padre1.replaceChild(DivObjHijo.pComboMes, elemento1);
            elemento2 = document.getElementById("ComboDia" + this.parentId);
            padre2 = elemento2.parentNode;
            padre2.replaceChild(DivObjHijo.pComboDia, elemento2);

            if (proc == "Paso2" || proc == "Edit") {
                contruirSegmento(this.parentId, nuevaFecha);
            }
            if (proc == "Paso1" || proc == "Paso2" || proc == "Paso3" || proc == "Hotel") {
                contruirFech(this.parentId, nuevaFecha);
            }
            if (proc == "Paso2" || proc == "Edit" || proc == "Hotel") {
                cambiarFec(this.parentId, nuevaFecha);
            }
        },
        dYears.valor = this.pAnio;
        this.pComboAnio = dYears;
        this.setComboMes();
    }
}