﻿this.OFramework = new function () {
    var tag = document.getElementById("OFrameworkJS");
    var src = tag.src.toLowerCase();
    this.BaseURI = src.indexOf("searchforms/oframework.js") > -1 ? src.replace("searchforms/oframework.js", "") : "../";
    this.ThemeID = tag.getAttribute("ThemeID") != null ? tag.getAttribute("ThemeID") : "default";
    this.SkinID = tag.getAttribute("SkinID") != null ? tag.getAttribute("SkinID") : "default";
    this.ThemeURI = tag.getAttribute("ThemeURI") != null ? tag.getAttribute("ThemeURI") : this.BaseURI + "SearchForms/Templates/" + this.ThemeID + "/";

    document.write("<link id='OFrameworkCSS' rel='stylesheet' type='text/css' href='" + this.ThemeURI + this.SkinID + ".css'>");

    //IE operation aborted fix
    //document.write("<span id='OFrameworkControls'></span>");
    //this.Container = document.getElementById("OFrameworkControls");

    this.Container = null;
    this.GetContainer = function () {
        if (this.Container == null) {
            this.Container = document.createElement("span");
            this.Container.className = "OFContainer";
            this.Container.style.zIndex = 20000;
            document.body.insertBefore(this.Container, document.body.childNodes[0]);
        }
        return this.Container;
    }

    this.Globalization = new function () {
        this.CultureInfo = function (id) {
            this.Date = new Object();
            switch (id) {
                case '3':
                    {
                        this.LanguageID = "3";
                        this.Date.Separator = "/";
                        this.Date.Format = "dd/mm/yyyy";
                        this.Date.MonthNames = ["janvier", "février", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre", "décembre"];
                        this.Date.ShortDayNames = ["di", "lu", "ma", "me", "je", "ve", "sa"];
                        this.Date.DayNames = ["dimanche", "lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi"];
                        break;
                    }
                case '4':
                    {
                        this.LanguageID = "4";
                        this.Date.Separator = "/";
                        this.Date.Format = "dd/mm/yyyy";
                        this.Date.MonthNames = ["enero", "febrero", "marzo", "abril", "mayo", "junio", "julio", "agosto", "septiembre", "octubre", "noviembre", "diciembre"];
                        this.Date.ShortDayNames = ["do", "lu", "ma", "mi", "ju", "vi", "sá"];
                        this.Date.DayNames = ["domingo", "lunes", "martes", "miércoles", "jueves", "viernes", "sábado"];
                        break;
                    }
                case '5':
                    {
                        this.LanguageID = "5";
                        this.Date.Separator = ".";
                        this.Date.Format = "yyyy.mm.dd";
                        this.Date.MonthNames = ["sausis", "vasaris", "kovas", "balandis", "gegužė", "birželis", "liepa", "rugpjūtis", "rugsėjis", "spalis", "lapkritis", "gruodis"];
                        this.Date.ShortDayNames = ["S", "P", "A", "T", "K", "Pn", "Š"];
                        this.Date.DayNames = ["sekmadienis", "pirmadienis", "antradienis", "trečiadienis", "ketvirtadienis", "penktadienis", "šeštadienis"];
                        break;
                    }
                case '6':
                    {
                        this.LanguageID = "6";
                        this.Date.Separator = ".";
                        this.Date.Format = "dd.mm.yyyy";
                        this.Date.MonthNames = ["Январь", "Февраль", "Март", "Апрель", "Май", "Июнь", "Июль", "Август", "Сентябрь", "Октябрь", "Ноябрь", "Декабрь"];
                        this.Date.ShortDayNames = ["Вс", "Пн", "Вт", "Ср", "Чт", "Пт", "Сб"];
                        this.Date.DayNames = ["воскресенье", "понедельник", "вторник", "среда", "четверг", "пятница", "суббота"];
                        break;
                    }
                case '7':
                    {
                        this.LanguageID = "7";
                        this.Date.Separator = "/";
                        this.Date.Format = "dd/mm/yyyy";
                        this.Date.MonthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
                        this.Date.ShortDayNames = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"];
                        this.Date.DayNames = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
                        break;
                    }
                case '8':
                    {
                        this.LanguageID = "8";
                        this.Date.Separator = ".";
                        this.Date.Format = "dd.m.yyyy";
                        this.Date.MonthNames = ["Януари", "Февруари", "Март", "Април", "Май", "Юни", "Юли", "Август", "Септември", "Октомври", "Ноември", "Декември"];
                        this.Date.ShortDayNames = ["не", "по", "вт", "ср", "че", "пе", "съ"];
                        this.Date.DayNames = ["неделя", "понеделник", "вторник", "сряда", "четвъртък", "петък", "събота"];
                        break;
                    }
                case '9':
                    {
                        this.LanguageID = "9";
                        this.Date.Separator = "/";
                        this.Date.Format = "dd/mm/yyyy";
                        this.Date.MonthNames = ["ינואר", "פברואר", "מרץ", "אפריל", "מאי", "יוני", "יולי", "אוגוסט", "ספטמבר", "אוקטובר", "נובמבר", "דצמבר"];
                        this.Date.ShortDayNames = ["א", "ב", "ג", "ד", "ה", "ו", "ש", ];
                        this.Date.DayNames = ["יום ראשון", "יום שני", "יום שלישי", "יום רביעי", "יום חמישי", "יום שישי", "שבת"];
                        break;
                    }
                default:
                    {
                        this.LanguageID = "1";
                        this.Date.Separator = "/";
                        this.Date.Format = "m/d/yyyy";
                        this.Date.MonthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
                        this.Date.ShortDayNames = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"];
                        this.Date.DayNames = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
                        break;
                    }
            }

            this.GetLanguageCode = function (id) {
                if (id == null) id = this.LanguageID
                switch (id) {
                    case "3": return "fr"; break;
                    case "4": return "es"; break;
                    case "5": return "lt"; break;
                    case "6": return "ru"; break;
                    case "7": return "gb"; break;
                    case "8": return "bg"; break;
                    case "9": return "he"; break;
                    default: return "en"; break;
                }
            }
            this.IsDefaultLanguage = function () { return this.LanguageID == "1"; }
            //this.__defineGetter__("IsDefaultLanguage", function(){return this.LanguageID=="1";});
        }
    }

    //this.Culture = new this.Globalization.CultureInfo();

    this.date = function (d, m, y) {

        this.ds = new Array(1, 1, 1);
        switch (arguments.length) {
            case 3:
                {
                    y = parseInt(y, 10);
                    m = parseInt(m, 10);
                    d = parseInt(d, 10);
                    this.ds = new Array(d, m, y);
                    if (isNaN(d) || isNaN(m) || isNaN(y) || d < 0 || d > 31 || m < 1 || m > 12 || y < 0) throw ("Invalid date format");
                    break;
                }
            case 1:
                {
                    if (typeof (d) != "object") return null;
                    y = d.getFullYear();
                    m = d.getMonth() + 1;
                    d = d.getDate();
                    this.ds = new Array(d, m, y);
                    break;
                }
                //case 0 : {this.ds = new Array(1,1,1);break;}
        }



        this.get_Day = function () { return this.ds[0]; };
        this.set_Day = function (n) { this.ds[0] = n; };
        this.get_Month = function () { return this.ds[1]; };
        this.set_Month = function (n) { this.ds[1] = n; };
        this.get_Year = function () { return this.ds[2]; };
        this.set_Year = function (n) { this.ds[2] = n; };

        this.Parse = function (s, ci) {
            try {
                var dFormat = ci != null ? ci.Date.Format : OFramework.Culture.Date.Format;
                var dSeparator = ci != null ? ci.Date.Separator : OFramework.Culture.Date.Separator;
                var objDateFormatParts = dFormat.split(dSeparator);
                var objDateParts = s.split(dSeparator);
                for (var i = 0; i < objDateParts.length; i++) {
                    if (objDateFormatParts[i].indexOf("d") > -1) {
                        var objDay = objDateParts[i];
                        continue;
                    }
                    if (objDateFormatParts[i].indexOf("m") > -1) {
                        var objMonth = objDateParts[i];
                        continue;
                    }
                    if (objDateFormatParts[i].indexOf("y") > -1) {
                        var objYear = objDateParts[i];
                        continue;
                    }
                }
                return new OFramework.date(objDay, objMonth, objYear);
            }
            catch (e) { alert(e); return null; }
        }
        this.ToString = function (f) {
            var dFormat = OFramework.Culture.Date.Format;
            var dSeparator = OFramework.Culture.Date.Separator;

            if (arguments.length == 0) f = dFormat;

            var objDateFormatParts = dFormat.split(dSeparator);
            for (var i = 0; i < objDateFormatParts.length; i++) {
                if (objDateFormatParts[i].indexOf("d") > -1) var dayPart = objDateFormatParts[i];
                if (objDateFormatParts[i].indexOf("m") > -1) var monthPart = objDateFormatParts[i];
                if (objDateFormatParts[i].indexOf("y") > -1) var yearPart = objDateFormatParts[i];
            }
            if (monthPart.length > 1 && this.Month < 10) m = "0" + this.Month;
            if (dayPart.length > 1 && this.Day < 10) d = "0" + this.Day;
            if (yearPart.length > 1 && this.Year < 10) y = "0" + this.Year;
            return f.replace(dayPart, d).replace(monthPart, m).replace(yearPart, y);
        }
        this.toString = this.ToString;
        this.parse = this.Parse;

    }

    this.Date = new this.date();
    //d = new Date();
    //d.setFullYear(
    this.DateFromString = function (s) {
        //alert(s);
        try {
            var dFormat = OFramework.Culture.Date.Format;
            var dSeparator = OFramework.Culture.Date.Separator;
            var objDateFormatParts = dFormat.split(dSeparator);
            var objDateParts = s.split(dSeparator);
            for (var i = 0; i < objDateParts.length; i++) {
                if (objDateFormatParts[i].indexOf("d") > -1) {
                    var objDay = objDateParts[i];
                    continue;
                }
                if (objDateFormatParts[i].indexOf("m") > -1) {
                    var objMonth = objDateParts[i];
                    continue;
                }
                if (objDateFormatParts[i].indexOf("y") > -1) {
                    var objYear = objDateParts[i];
                    continue;
                }
            }
            //alert(objYear + " : " + objMonth + " : " + objDay);
            var retObj = new Date();
            retObj.setFullYear(parseInt(objYear, 10), parseInt(objMonth, 10) - 1, parseInt(objDay, 10));
            //alert(retObj);
            return retObj;
        }
        catch (e) { return null; }
    }
    this.DateToString = function (s) {
        var dFormat = OFramework.Culture.Date.Format;
        var dSeparator = OFramework.Culture.Date.Separator;

        var objDateFormatParts = dFormat.split(dSeparator);
        var dayPart; var monthPart; var yearPart;
        for (var i = 0; i < objDateFormatParts.length; i++) {
            if (objDateFormatParts[i].indexOf("d") > -1) dayPart = objDateFormatParts[i];
            if (objDateFormatParts[i].indexOf("m") > -1) monthPart = objDateFormatParts[i];
            if (objDateFormatParts[i].indexOf("y") > -1) yearPart = objDateFormatParts[i];
        }
        var d = s.getDate();
        var m = s.getMonth() + 1;
        var y = s.getFullYear();
        if (monthPart.length > 1 && m < 10) m = "0" + m;
        if (dayPart.length > 1 && d < 10) d = "0" + d;
        if (yearPart.length > 1 && y < 10) y = "0" + y;
        return dFormat.replace(dayPart, d).replace(monthPart, m).replace(yearPart, y);
    }
    Date.prototype.Equals = function (d) {
        if (d == null) return false;
        var d1d = this.getDate();
        var d1m = this.getMonth();
        var d1y = this.getFullYear();

        var d2d = d.getDate();
        var d2m = d.getMonth();
        var d2y = d.getFullYear();

        return (d1d == d2d && d1m == d2m && d1y == d2y);
    }
    Date.prototype.CompareTo = function (d) {
        var d1d = this.getDate();
        var d1m = this.getMonth();
        var d1y = this.getFullYear();

        var d2d = d.getDate();
        var d2m = d.getMonth();
        var d2y = d.getFullYear();

        var date1 = new Date(d1y, d1m, d1d);
        var date2 = new Date(d2y, d2m, d2d);
        if (date1 == date2) return 0;
        if (date1 < date2) return -1;
        if (date1 > date2) return 1;
    }
    Date.prototype.ToString = function () {
        if (this == null) return "";
        var d = this.getDate();
        var m = this.getMonth() + 1;
        var y = this.getFullYear();
        if (m < 10) m = "0" + m;
        if (d < 10) d = "0" + d;
        if (y < 10) y = "0" + y;
        return m + "/" + d + "/" + y;
    }

    this.NumberFromString = function (s) { }
    this.NumberToString = function (s) { }

    this.Array = function () {
        var o = new Array()
        o.Contains = function (val) {
            for (var i = 0; i < this.length; i++) if (this[i] == val) return true;
            return false;
        }
        return o;
    }

    this.Controls = new function () {
        //this._list = new Array();

        this.Control = function () {
            this.ID = null;
            this.Type = "Control";
            this.Container = null;
            this.HTMLElement = null;
            this.Template = null;
            this.Controls = new Array();

            this.Width = 0;
            this.Height = 0;
            this.Top = 0;
            this.Left = 0;

            this.Render = function () {
                if (this.Container != null) {
                    this.Container.innerHTML = this.Template;
                }
                else window.document.write(this.Template);
            }
            this.Register = function () {
                if (OFramework.Controls[this.ID] == null) OFramework.Controls[this.ID] = this;
                else return OFramework.Controls[this.ID];
                //for(var i=0; i<OFramework.Controls._list.length; i++){if(OFramework.Controls._list[i].ID==this.ID){return OFramework.Controls._list[i];}}
                //OFramework.Controls._list[OFramework.Controls._list.length]=this;
            }
        }

        this.IFrame = function () {
            this.Type = "IFrame";
            this.ID = "IFrame";
            this.Template = "<iframe id='OFrame_IFrame' style='display:block;position:absolute' onMouseOut='alert(this)'>";
            this.Register();

            this.Render();
        }
        this.IFrame.prototype = new this.Control();

        this.Overlay = function () {
            if (OFramework.Controls["OFrameworkOverlay"] != null) return OFramework.Controls["OFrameworkOverlay"];
            var o = document.createElement("div");
            o.Type = "Overlay";
            o.className = "overlay";

            o.Show = function () {
				var obj1 = window.document.documentElement;
				var obj2 = window.document.documentElement.ownerDocument.body;
				var obj = obj1.scrollHeight > obj2.scrollHeight ? obj1 : obj2;
                this.style.display = "block";
                this.style.width = obj.scrollWidth + "px";
                this.style.height = (obj.scrollHeight > obj.clientHeight ? obj.scrollHeight : obj.clientHeight) + "px";
                this.style.zIndex = 10000;
            }
            o.Hide = function () {
                this.style.display = "none";
            }

            OFramework.Controls["OFrameworkOverlay"] = o;
            OFramework.GetContainer().appendChild(o);
            return o;
        }

        this.ModalPopUp = function (oContainer) {
            oContainer.Type = "ModalPopUp";
            oContainer.style.display = "none";
            //o.className = "overlay";

            oContainer.Overlay = new OFramework.Controls.Overlay();
            var width =
			oContainer.Show = function () {
			    this.Overlay.Show();
			    this.style.display = "block";
			    this.style.position = "fixed";
			    this.style.left = (OFramework.getWindowWidth() - this.scrollWidth) / 2 + "px";
			    this.style.top = (OFramework.getWindowHeight() - this.scrollHeight) / 2 + "px";

			    this.style.zIndex = parseInt(this.Overlay.style.zIndex) + 1;
			}
            oContainer.Close = function () {
                this.style.display = "none";
                this.Overlay.Hide();
            }
            return oContainer;
        }

        this.InputText = function (oContainer) {
            var o = document.createElement("input");
            o.Type = "InputText";
            o.type = "text";
            o.className = "text";
            o.Value = "";
            o.value = "";
            o.HintText = "";

            o.Focus = function () {
                this.className = "text focus";
                OFramework.ActiveElement = this;
                if (this.HintText != "" && this.value == this.HintText) this.value = "";
            }
            o.Blur = function () {
                if (OFramework.ActivePopUp != null) {
                    if (this.List != null && this.List.CanHide) {
                        o.List.Hide();
                        this.className = "text";
                        OFramework.ActiveElement = null;
                    }
                }
                else {
                    this.className = "text";
                    OFramework.ActiveElement = null;
                }

                if (this.HintText != "" && this.value == "") this.value = this.HintText;
            }
            //            alert("b4 o.onfocus and o.onblur");
            o.onfocus = o.Focus
            o.onblur = o.Blur;
            //          alert("after o.onfocus and o.onblur");
            o.DataBind = function () {
                this.List = new OFramework.Controls.HtmlDropdownListBody();
                if (this.DataSource == null) { return; }
                if (!this.DataSource.DataLoaded) {
                    this.value = "loading...";
                    this.disabled = true;
                    window.setTimeout("document.getElementById(\"" + this.id + "\").DataBind()", 100); return;
                }
                else {
                    this.disabled = false;
                    if (this.Value != "") window.setTimeout("document.getElementById(\"" + this.id + "\").SetValue(\"" + this.Value + "\")", 50);
                    else this.value = this.HintText != "" ? this.HintText : "";
                }
            }
            //alert("after data bind");
            o.onkeydown = function (e) {
                e = document.all ? event : e;
                if (this.List == null) return;
                switch (e.keyCode) {
                    case 40:
                        {
                            this.List.MoveDown();
                            e.cancelBubble = true;
                            break;
                        }
                    case 38:
                        {
                            this.List.MoveUp();
                            e.cancelBubble = true;
                            break;
                        }
                    case 9:
                        {
                            this.List.Close();
                            e.cancelBubble = true;
                            break;
                        }
                    case 13:
                        {
                            this.List.Close();
                            e.cancelBubble = true;
                            break;
                        }
                }
            }
            //alert("after keydown");
            o.onkeyup = function (e) {
                this.Value = this.value;
                if (this.List == null) return;

                e = document.all ? event : e;
                if (e.keyCode == 40 || e.keyCode == 38 || e.keyCode == 9 || e.keyCode == 13) { e.cancelBubble = true; return; }
                var filteredData = new Array();
                var idData = new Array();
                var codeData = new Array()
                if (this.value.length > 0) {
                    var userVal = this.value.toLowerCase();
                    for (var i = 0; i < this.DataSource.length; i++) {
                        if (this.DataSource[i].id.toLowerCase() == userVal) idData.push(this.DataSource[i]);
                        else if (this.DataSource[i].code && this.DataSource[i].code.toLowerCase() == userVal) codeData.push(this.DataSource[i]);
                        else if (this.DataSource[i].name.toLowerCase().indexOf(userVal) == 0) filteredData.push(this.DataSource[i]);
                    }

                    filteredData = idData.concat(codeData).concat(filteredData);
                }
                if (filteredData.length > 0) {
                    this.List.Show(this, filteredData)
                    this.List.SetSelectedIndex(0);
                }
                else this.List.Hide();
            }
            //alert("after keyup");
            o.SetValue = function (val) {
                this.Value = val == null ? "" : val;
                var dataItem = null;
                if (this.DataSource != null && this.DataSource.DataLoaded) {
                    for (var i = 0; i < this.DataSource.length; i++) {
                        if (this.DataSource[i].id == this.Value) {
                            dataItem = this.DataSource[i];
                            break;
                        }
                    }
                }
                this.value = dataItem != null ? dataItem.name : this.Value;
                if (this.Parent != null && this.Parent.FieldChanged != null) this.Parent.FieldChanged(this, dataItem);
            }

            if (oContainer != null) oContainer.appendChild(o);
            return o;
        }

        this.InputDate = function (oContainer) {
            var o = document.createElement("div");
            o.Type = "InputDate";
            o.className = "date";
            o.hideFocus = true;
            o.innerHTML = OFramework.Culture.Date.Format;
            o.Value = null;
            o.MinDate = null;
            o.MaxDate = null;

            o.onselectstart = function () { return false; }

            o.Calendar = new OFramework.Controls.CalendarPopUp()
            o.Activate = function () {
                this.Focus();
                this.Calendar.focus();
            }
            o.Focus = function () {
                if (OFramework.ActiveElement != null) OFramework.ActiveElement.Blur();
                OFramework.ActiveElement = this;
                this.className = "date focus";
                this.Calendar.CanHide = true;
                this.Calendar.Show(this);
            }
            o.onclick = function (e) {
                if (OFramework.ActiveElement != null) OFramework.ActiveElement.Blur();
                OFramework.ActiveElement = this;
                this.className = "date focus";
                this.Calendar.CanHide = true;
                this.Calendar.Show(this);
            };

            o.Blur = function () {
                if (this.Calendar.CanHide) {
                    o.Calendar.Hide();
                    this.className = "date";
                    OFramework.ActiveElement = null;
                }
            }
            o.SetValue = function (val, raiseEvent) {
                if (val == null) return;
                if (val.Equals(this.Value)) raiseEvent = false;
                this.innerHTML = OFramework.DateToString(val);
                this.Value = val;
                if (raiseEvent && this.Parent != null && this.Parent.FieldChanged != null) this.Parent.FieldChanged(this, val);
            }
            o.onfocus = o.Focus
            o.onblur = o.Blur;

            if (oContainer != null) oContainer.appendChild(o);
            return o;
        }
        this.CalendarPopUp = function () {
            if (document.getElementById("CalendarPopUp") != null) return document.getElementById("CalendarPopUp");
            var o = document.createElement("div");
            o.id = "CalendarPopUp";
            o.type = "CalendarPopUp";
            o.className = "popup calendar";

            o.MinDate = null;
            o.MaxDate = null;
            o.SelectedDate = null;
            o.CurrentDate = null;

            o.Show = function (attachTo) {
                if (OFramework.ActivePopUp != null) OFramework.ActivePopUp.Hide();
                this.AttachedTo = attachTo;
                this.style.top = (OFramework.getPosTop(attachTo) + attachTo.offsetHeight + 1) + "px";
                this.style.left = OFramework.getPosLeft(attachTo) + "px";
                this.style.display = "block";
                this.style.zIndex = OFramework.getZIndex(attachTo) + 100;
                OFramework.ActivePopUp = this;

                this.MinDate = this.AttachedTo.MinDate;
                this.MaxDate = this.AttachedTo.MaxDate;
                this.SetDate(this.AttachedTo.Value);
                this.Render();
            }
            o.Hide = function () {
                this.style.display = "none";
                this.AttachedTo = null;
                OFramework.ActivePopUp = null;
            }
            o.Close = function () {
                this.CanHide = true;
                if (this.AttachedTo != null) {
                    this.AttachedTo.SetValue(this.SelectedDate, true)
                    this.AttachedTo.Blur();
                }
            }
            o.SetDate = function (val) {
                this.SelectedDate = val != null ? val : new Date();
            }
            o.Render = function (o) {
                var cDay, cMonth, cYear;
                var cDate = o != null ? o : new Date(this.SelectedDate.getFullYear(), this.SelectedDate.getMonth(), this.SelectedDate.getDate());
                if (this.MinDate != null && cDate <= this.MinDate) {
                    cDate = new Date(this.MinDate.getFullYear(), this.MinDate.getMonth(), this.MinDate.getDate());
                }
                if (this.MaxDate != null && cDate >= this.MaxDate) {
                    cDate = new Date(this.MaxDate.getFullYear(), this.MaxDate.getMonth(), this.MaxDate.getDate());
                }
                //if(this.MaxDate != null && cDate > this.MaxDate) cDate = this.MaxDate;
                this.CurrentDate = cDate;
                cDay = cDate.getDate();
                //cMonth = cDate.getMonth();
                //cYear = cDate.getFullYear();
                //cDate = new Date(cYear, cMonth, 1);



                var container = document.createElement("table");
                container.cellPadding = 0;
                container.cellSpacing = 0;
                container.border = 0;
                container.Cells = new Array();
                var layout = this.AttachedTo.CalendarLayout;
                var cols = 0; var rows = 0;
                try {
                    rows = parseInt(layout.substring(2), 10);
                    cols = parseInt(layout.substring(0, 1), 10);
                    colWidth = parseInt(100 / cols);
                    for (var r = 0; r < rows; r++) {
                        container.insertRow(r);
                        container.rows[r].vAlign = "top";
                        for (var c = 0; c < cols; c++) {
                            container.rows[r].insertCell(c);
                            container.Cells[container.Cells.length] = container.rows[r].cells[c];
                            if (c < cols - 1) container.rows[r].cells[c].style.width = colWidth + "%";
                        }
                    }
                    container.style.width = 160 * container.rows[0].cells.length;
                    container.style.height = 140 * container.rows.length;
                }
                catch (e) { }
                if (container.Cells.length < 2) container = document.createElement("span");

                this.style.width = container.style.width;
                this.style.height = container.style.height;

                var displayCount = container.Cells ? container.Cells.length : 1;
                for (var mCount = 0; mCount < displayCount; mCount++) {
                    cMonth = cDate.getMonth();
                    cYear = cDate.getFullYear();
                    cDate = new Date(cYear, cMonth, 1);

                    var dayOffset = cDate.getDay();
                    var fDayAvailable = false;
                    var lDayAvailable = false;

                    var calBody = document.createElement("table");
                    calBody.border = "0";
                    calBody.style.width = "100%";
                    calBody.style.height = "100%";
                    calBody.className = "calText";
                    calBody.onselectstart = function () { return false; }
                    var newRow, cCell;

                    newRow = calBody.insertRow(0);
                    newRow.align = "center";
                    newRow.className = "cHead";
                    var rwMonth = newRow.insertCell(0);
                    if (mCount == 0) {
                        rwMonth.innerHTML = "&lt;"
                        rwMonth.className = "navBtn";
                        rwMonth.onclick = this.PrewMonth;
                    }
                    cCell = newRow.insertCell(1);
                    cCell.colSpan = 5;
                    if (displayCount > 1) {
                        cCell.innerHTML = OFramework.Culture.Date.MonthNames[cMonth] + " " + cYear;
                    }
                    else {
                        this.WriteDDown(cCell, cMonth, cYear);
                    }
                    var fwMonth = newRow.insertCell(2);
                    if (mCount == (container.Cells ? cols - 1 : 0)) {
                        fwMonth.innerHTML = "&gt;"
                        fwMonth.className = "navBtn";
                        fwMonth.onclick = this.NextMonth;
                    }

                    for (var r = 1; r < 8; r++) {
                        newRow = calBody.insertRow(r);
                        newRow.align = "center";
                        newRow.className = "wDay";
                        for (var c = 0; c < 7; c++) {
                            var cCell = newRow.insertCell(c);
                            if (c == 0 || c == 6) {
                                noSel = "wkNoSelDay";
                                cCell.className = "wkDay";
                            }
                            else {
                                noSel = "wNoSelDay";
                                cCell.className = "wDay";
                            }
                            if (r == 1) {//day names
                                cCell.innerHTML = OFramework.Culture.Date.ShortDayNames[c];
                                //cCell.className = ""
                            }
                            else if (r == 2 & c < dayOffset || cDate.getMonth() > cMonth || cDate.getFullYear() > cYear) {
                                cCell.innerHTML = "";
                                cCell.onmouseover = null;
                                cCell.onmouseout = null;
                            }
                            else {
                                cCell.innerHTML = cDate.getDate();
                                if ((this.MinDate != null && cDate >= this.MinDate) || (this.MaxDate != null && cDate <= this.MaxDate) || (this.MinDate != null && this.MaxDate != null && cDate >= this.MinDate && cDate <= this.MaxDate) || (this.MinDate == null && this.MaxDate == null)) {
                                    cCell.onmouseover = this.CellOver;
                                    cCell.onmouseout = this.CellOut;
                                    cCell.onclick = this.CellClick;
                                    cCell.Year = cYear;
                                    cCell.Month = cMonth;
                                    cCell.Day = cDate.getDate();
                                }
                                else {
                                    cCell.onmouseover = null;
                                    cCell.onmouseout = null;
                                    cCell.className = noSel;
                                }
                                if (!rwMonth.isDisbl && this.MinDate != null && cDate <= this.MinDate) { rwMonth.isDisbl = true; rwMonth.className = "navBtn_off" }
                                if (!fwMonth.isDisbl && this.MaxDate != null && cDate >= this.MaxDate) { fwMonth.isDisbl = true; fwMonth.className = "navBtn_off" }
                                if (cDate.Equals(this.SelectedDate)) cCell.className = "cDay";
                                cDate.setDate(cDate.getDate() + 1)
                            }
                        }
                    }
                    if (container.Cells) container.Cells[mCount].appendChild(calBody);
                    else container.appendChild(calBody);

                }
                this.innerHTML = "";
                this.appendChild(container);
            }
            o.CellOver = function (e) {
                cElement = document.all ? event.srcElement : e.currentTarget
                cStyle = cElement.className;
                cElement.className = "cDay";
            }
            o.CellOut = function (e) {
                cElement = document.all ? event.srcElement : e.currentTarget
                cElement.className = cStyle;
            }
            o.CellClick = function (e) {
                cElement = document.all ? event.srcElement : e.currentTarget
                document.getElementById("CalendarPopUp").SelectedDate = new Date(cElement.Year, cElement.Month, cElement.Day);
                document.getElementById("CalendarPopUp").Close();
            }

            o.NextMonth = function (e) {
                cElement = document.all ? event.srcElement : e.currentTarget
                if (cElement.isDisbl) return;
                var cDate = document.getElementById("CalendarPopUp").CurrentDate;
                cDate.setMonth(cDate.getMonth() + 1)
                document.getElementById("CalendarPopUp").Render(cDate);
            }
            o.PrewMonth = function (e) {
                cElement = document.all ? event.srcElement : e.currentTarget
                if (cElement.isDisbl) return;
                var cDate = document.getElementById("CalendarPopUp").CurrentDate;
                cDate.setMonth(cDate.getMonth() - 1)
                document.getElementById("CalendarPopUp").Render(cDate);
            }
            o.GoTo = function (m, y) {
                var cDate = document.getElementById("CalendarPopUp").CurrentDate;
                cDate.setFullYear(y, m);
                document.getElementById("CalendarPopUp").Render(cDate);
            }

            o.WriteDDown = function (oContainer, cMonth, cYear) {
                var dDown = document.createElement("select");
                dDown.className = "calText";
                dDown.onchange = function () {
                    var params = this.value.split("-");
                    document.getElementById("CalendarPopUp").GoTo(params[0], params[1]);
                }
                var minIndexDate = new Date(cYear, cMonth, 1);
                var maxIndexDate = new Date(cYear, cMonth, 1);
                minIndexDate.setMonth(minIndexDate.getMonth() - 6);
                maxIndexDate.setMonth(maxIndexDate.getMonth() + 5);

                if (minIndexDate < this.MinDate) {
                    minIndexDate = new Date(this.MinDate.getFullYear(), this.MinDate.getMonth(), 1);
                    maxIndexDate.setMonth(minIndexDate.getMonth() + 12)
                }
                if (this.MaxDate != null && this.axIndexDate > this.MaxDate) {
                    maxIndexDate = new Date(this.MaxDate.getFullYear(), this.MaxDate.getMonth(), 1); ;
                }

                for (i = 1; i < 13; i++) {
                    o = new Option(OFramework.Culture.Date.MonthNames[minIndexDate.getMonth()].substring(0, 3) + " " + minIndexDate.getFullYear(), minIndexDate.getMonth() + "-" + minIndexDate.getFullYear());
                    dDown.options.add(o);
                    minIndexDate.setMonth(minIndexDate.getMonth() + 1);
                }
                dDown.value = cMonth + "-" + cYear;
                oContainer.appendChild(dDown);
            }

            o.onblur = function () {
                if (OFramework.ActiveElement != null) OFramework.ActiveElement.Blur();
            }
            o.onmouseleave = function () {
                if (!this.CanHide) this.CanHide = true;
            }
            o.onmouseenter = function () {
                if (this.CanHide) {
                    this.CanHide = false;
                    this.hideFocus = true;
                    this.focus();
                }
            }
            o.onmouseout = o.onmouseleave;
            o.onmousemove = o.onmouseenter;

            OFramework.GetContainer().appendChild(o);
            return o;
        }

        this.DropdownList = function (oContainer) {

            var o = document.createElement("select");
            o.className = "select";
            o.Value = "";
            o.SelectedItem = null;
            o.Filter = null;
            o.DataSource = null;

            o.Focus = function () {
                this.className = "select focus";
                OFramework.ActiveElement = this;
            }
            o.Blur = function () {
                this.className = "select";
                OFramework.ActiveElement = null;
            }
            o.onfocus = o.Focus
            o.onblur = o.Blur;

            o.SetValue = function (val, raiseEvent) {
                if (this.DataSource == null) return;
                if (!this.DataSource.DataLoaded) {
                    this.Value = val;
                    return;
                }
                var found = false;
                var dSource = this.DataSource;
                if (this.DefaultItem) dSource = new Array(this.DefaultItem).concat(dSource);
                for (var i = 0; i < dSource.length; i++) {
                    if (((this.DefaultItem && i > 0) || (!this.DefaultItem)) && this.Filter != null && !this.Filter.Value.Contains(dSource[i][this.Filter.Property])) continue;
                    if (dSource[i].id == val) {
                        this.Value = val;
                        this.SelectedItem = dSource[i];
                        //this.SetText(dSource[i].name);
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    this.SelectedItem = dSource[0];
                    this.Value = dSource[0].id;
                    //this.SetText(dSource[0].name);
                }

                if (raiseEvent && this.Parent != null && this.Parent.FieldChanged != null) this.Parent.FieldChanged(this, this.SelectedItem.id);
            }

            o.DataBind = function () {
                if (this.DataSource == null) return;
                if (!this.DataSource.DataLoaded) {
                    this.disabled = true;
                    if (this.options.length > 0) this.options[0].text = "loading...";
                    else o.options.add(new Option("loading...", ""));
                    window.setTimeout("document.getElementById(\"" + this.id + "\").DataBind()", 100); return;
                }
                this.innerHTML = "";
                //this.options.add(new Option("--select--", 0));
                for (var i = 0; i < this.DataSource.length; i++) {
                    this.options.add(new Option(this.DataSource[i].name, this.DataSource[i].id));
                }
                this.disabled = false;
            }

            if (oContainer != null) oContainer.appendChild(o);
            return o;
        }

        this.SelectList = function (oContainer) {
            var o = document.createElement("select");
            o.Type = "SelectList";
            o.className = "select";
            o.multiple = true;
            o.Value = "";
            o.Filter = null;
            o.DataSource = null;
            o.Linked = false;
            o.GroupSort = [];

            o.Focus = function () {
                this.className = "select focus";
                OFramework.ActiveElement = this;
            }
            o.Blur = function () {
                this.className = "select";
                OFramework.ActiveElement = null;
            }
            o.MouseClick = function () {

            }
            o.OnChange = function () {
                if (this.Linked) {
                    var sIndex = null;
                    var eIndex = null;
                    for (i = 0; i < this.options.length; i++) {
                        if (this.options[i].selected && this.options[i] && this.options[i].value != "null") {
                            if (sIndex == null) sIndex = i;
                            eIndex = i;
                        }
                    }
                    if (sIndex != null && eIndex != null) {
                        for (i = sIndex; i <= eIndex; i++) this.options[i].selected = true;
                    }
                }

                var sel_array = new Array()
                for (i = 0; i < this.options.length; i++) {
                    if (this.options[i].selected && this.options[i].value != "null") sel_array.push(this.options[i].value);
                }
                if (sel_array.length > 5) {
                    alert("Too many options selected!");
                    this.SetValue(this.Value, false, true);
                    return;
                }
                if (this.Linked && sel_array.length > 2) sel_array.splice(1, sel_array.length - 2);
                var newValue = sel_array.toString();
                if (newValue != this.Value) {
                    this.Value = newValue;
                    if (this.Parent != null && this.Parent.FieldChanged != null) this.Parent.FieldChanged(this, this.Value);
                }
            }
            o.onfocus = o.Focus
            o.onblur = o.Blur;
            o.onclick = o.MouseClick;
            o.onchange = o.OnChange;

            o.SetValue = function (val, raiseEvent, flag) {
                if (!flag && OFramework.ActiveElement == this) return;
                this.Value = val;
                if (this.DataSource == null || !this.DataSource.DataLoaded) return;

                var sel_array = val.split(',');
                var last_option_selected = null;
                if (this.Linked) {
                    var sValue = sel_array[0];
                    var eValue = sel_array[sel_array.length - 1];
                    var flag = false;
                    for (i = 0; i < this.options.length; i++) {
                        if (this.options[i].value == sValue) flag = true;
                        this.options[i].selected = flag;
                        if (this.options[i].value == eValue) flag = false;
                    }
                }
                else {
                    for (i = 0; i < this.options.length; i++) {
                        this.options[i].selected = sel_array.contains(this.options[i].value);
                    }
                }
                if (raiseEvent && this.Parent != null && this.Parent.FieldChanged != null) this.Parent.FieldChanged(this, this.Value);
            }

            o.DataBind = function () {
                if (this.DataSource == null) return;
                if (OFramework.ActiveElement == this) {
                    this.FilterGroups();
                    return;
                }
                if (!this.DataSource.DataLoaded) {
                    this.disabled = true;
                    this.innerHTML = "";
                    this.options.add(new Option("loading...", ""));

                    window.setTimeout("document.getElementById(\"" + this.id + "\").DataBind()", 100); return;
                }
                this.innerHTML = "";

                this.BuildGroups();
                this.SetValue(this.Value, false);
                this.disabled = false;
            }

            o.BuildGroups = function () {
                var data_array = new Array();
                var gs = new Array();
                var oGroup = null;
                var dataItem = null;
                var use_optgroup = false;
                switch (this.id) {
                    case "CruiseSearchForm_Ship":
                        {
                            use_optgroup = true;
                            var suppliers = OFramework.DataSources["CruiseFormData"].CruiseLines;
                            for (var i = 0; i < suppliers.length; i++) {
                                dataItem = suppliers[i];
                                oGroup = document.createElement("optgroup");
                                oGroup.label = dataItem.name;
                                oGroup.value = dataItem.id;
                                data_array["group_" + oGroup.value] = oGroup;
                            }
                            for (var i = 0; i < this.DataSource.length; i++) {
                                dataItem = this.DataSource[i];
                                oGroup = data_array["group_" + dataItem.cid];
                                var option = document.createElement("option");
                                option.value = dataItem.id;
                                option.appendChild(document.createTextNode(dataItem.name));
                                if (oGroup) oGroup.appendChild(option);
                            }
                            break;
                        }
                    case "CruiseSearchForm_Destination":
                        {
                            for (var i = 0; i < this.DataSource.length; i++) {
                                dataItem = this.DataSource[i];
                                if (!this.Linked && this.GroupSort.contains(dataItem.id)) {
                                    gs[gs.length] = new Option(dataItem.name, dataItem.id);
                                    continue;
                                }
                                if (dataItem.pid) continue;
                                oGroup = document.createElement("optgroup");
                                oGroup.label = dataItem.name;
                                oGroup.value = dataItem.id;
                                data_array["group_" + oGroup.value] = oGroup;
                            }
                            for (var i = 0; i < this.DataSource.length; i++) {
                                dataItem = this.DataSource[i];
                                if (dataItem["pid"] == null) continue;
                                if (!this.Linked && this.GroupSort.contains(dataItem.id)) continue;
                                oGroup = data_array["group_" + dataItem.pid];
                                var option = document.createElement("option");
                                option.value = dataItem.id;
                                option.innerHTML = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + dataItem.name
                                if (oGroup) oGroup.appendChild(option);
                            }
                            break;
                        }
                    default:
                        {
                            for (var i = 0; i < this.DataSource.length; i++) {
                                dataItem = this.DataSource[i];
                                if (!this.Linked && this.GroupSort.contains(dataItem.id)) {
                                    gs[gs.length] = new Option(dataItem.name, dataItem.id);
                                    continue;
                                }
                                if (dataItem.pid) continue;
                                oGroup = document.createElement("optgroup");
                                oGroup.label = dataItem.name;
                                oGroup.value = dataItem.id;
                                data_array["group_" + oGroup.value] = oGroup;
                            }
                            break;
                        }
                }
                for (var name in data_array) {
                    if (name.indexOf("group_") == 0) {
                        dataItem = data_array[name];
                        if (use_optgroup) {
                            if (dataItem.childNodes.length > 0) this.appendChild(dataItem);
                        }
                        else {
                            var option = document.createElement("option");
                            option.value = dataItem.value;
                            option.appendChild(document.createTextNode(dataItem.label));
                            this.appendChild(option);
                            //if (dataItem.childNodes.length > 0) alert("appending " + dataItem.childNodes.length + " child options");
                            while (dataItem.childNodes.length > 0) {
                                this.appendChild(dataItem.childNodes[0]);
                            }
                        }
                    }
                }
                if (gs.length > 0) {
                    for (var i = 0; i < gs.length; i++) {
                        this.options.add(gs[i], i);
                    }
                    if (this.options.length > gs.length) {
                        var s = new Option("-------------", "null");
                        s.style.color = "silver";
                        s.disabled = true;
                        this.options.add(s, gs.length);
                    }
                }
            }

            o.FilterGroups = function () {
                if (this.id != "CruiseSearchForm_Ship") return;
                var suppliers = OFramework.DataSources["CruiseFormData"].CruiseLines;
                var rem = new Array();
                for (var n = 0; n < this.childNodes.length; n++) {
                    var found = false;
                    var node = this.childNodes[n];
                    for (var c = 0; c < suppliers.length; c++) {
                        if (suppliers[c].id == node.value) {
                            found = true;
                            break;
                        }
                    }
                    if (!found) rem[rem.length] = node;
                }
                for (var i = 0; i < rem.length; i++) this.removeChild(rem[i]);
            }

            if (oContainer != null) oContainer.appendChild(o);
            return o;
        }

        this.HtmlDropdownList = function (oContainer) {

            var o = document.createElement("div");
            o.Type = "HtmlDropdownList";
            o.className = "dropdown";
            o.hideFocus = true;
            o.innerHTML = "<br />";
            o.Value = "";
            o.SelectedItem = null;
            o.Filter = null;
            o.DataSource = null;
            o.List = new OFramework.Controls.HtmlDropdownListBody();
            o.GroupSort = [];

            o.Focus = function () {
                this.className = "dropdown focus";
                OFramework.ActiveElement = this;
                this.List.CanHide = true;
                this.List.Show(this);
                Value = "";
            }
            o.onclick = function (e) {
                this.className = "dropdown focus";
                OFramework.ActiveElement = this;
                this.List.CanHide = true;
                this.List.Show(this);
                Value = "";
            };
            o.Blur = function () {
                if (OFramework.ActivePopUp != null) {
                    if (this.List.CanHide) {
                        o.List.Hide();
                        this.className = "dropdown";
                        OFramework.ActiveElement = null;
                    }
                }
                else {
                    this.className = "dropdown";
                    OFramework.ActiveElement = null;
                }
            }
            o.onfocus = o.Focus
            o.onblur = o.Blur;
            o.onselectstart = function () { return false; }



            o.onkeydown = function (e) {
                e = document.all ? event : e;
                var seltext = filterList(e.keyCode, o);
                switch (e.keyCode) {
                    case 40:
                        {
                            this.List.MoveDown();
                            e.cancelBubble = true;
                            break;
                        }
                    case 38:
                        {
                            this.List.MoveUp();
                            e.cancelBubble = true;
                            break;
                        }
                    case 9:
                        {
                            this.List.Close();
                            e.cancelBubble = true;
                            break;
                        }
                    case 13:
                        {
                            this.List.Close();
                            e.cancelBubble = true;
                            break;
                        }
                }
            }

            o.SetValue = function (val, raiseEvent) {
                if (this.DataSource == null) return;
                if (!this.DataSource.DataLoaded) {
                    this.Value = val;
                    return;
                }
                var found = false;
                var dSource = this.DataSource;
                if (this.DefaultItem) dSource = new Array(this.DefaultItem).concat(dSource);
                for (var i = 0; i < dSource.length; i++) {
                    if (((this.DefaultItem && i > 0) || (!this.DefaultItem)) && this.Filter != null && !this.Filter.Value.Contains(dSource[i][this.Filter.Property])) continue;
                    if (dSource[i].id == val) {
                        this.Value = val;
                        this.SelectedItem = dSource[i];
                        this.SetText(dSource[i].name);
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    this.SelectedItem = dSource[0];
                    this.Value = dSource[0].id;
                    this.SetText(dSource[0].name);
                }

                if (raiseEvent && this.Parent != null && this.Parent.FieldChanged != null) this.Parent.FieldChanged(this, this.SelectedItem.id);
            }
            o.SetText = function (val) {
                var newLen = val.length - 1;
                var styleWidth = (this.style != null && this.style.width != null) ? parseInt(this.style.width, 10) : 150;
                var width = this.clientWidth > 0 ? this.clientWidth : styleWidth;

                if (val.length * 7 > width) {
                    this.innerHTML = val.substring(0, width / 7);
                }
                else this.innerHTML = val;
                if (this.innerHTML.length == 0 && val.length > 4) this.innerHTML = val.substring(0, 4);
            }
            o.SetFilter = function (prop, val) {
                if (val == null) { this.Filter = null; }
                else {
                    this.Filter = new Object();
                    this.Filter.Property = prop;
                    this.Filter.Value = val;
                }
                this.SetValue(this.Value, false);
            }
            o.GetItem = function (val) {
                if (this.DataSource == null) return null;
                for (var i = 0; i < this.DataSource.length; i++) {
                    if (this.DataSource[i].id == val) return this.DataSource[i];
                }
                return null;
            }
            o.DataBind = function () {
                if (this.DataSource == null) { this.innerHTML = "&nbsp;<br/>"; return; }
                if (!this.DataSource.DataLoaded) {
                    this.innerHTML = "loading...";
                    window.setTimeout("document.getElementById(\"" + this.id + "\").DataBind()", 100); return;
                }
                else {
                    var val = null;
                    if (this.DefaultItem) val = this.Value == "" ? this.DefaultItem.id : this.Value;
                    else if (this.DataSource.length > 0) {
                        val = this.Value == "" ? this.DataSource[0].id : this.Value;
                    }
                    if (val != null) window.setTimeout("document.getElementById(\"" + this.id + "\").SetValue(\"" + val + "\")", 50);
                }
            }

            if (oContainer != null) {
                oContainer.appendChild(o);
            }
            return o;
        }

        this.HtmlDropdownListBody = function () {

            if (document.getElementById("DDListPopUp") != null) return document.getElementById("DDListPopUp");
            var o = document.createElement("div");

            o.id = "DDListPopUp";
            o.type = "DDListPopUp";
            o.className = "popup list";

            o.Show = function (attachTo, dSource) {
                if (attachTo == null) return;
                if (OFramework.ActivePopUp != null) OFramework.ActivePopUp.Hide();
                this.AttachedTo = attachTo;
                this.style.top = (OFramework.getPosTop(attachTo) + attachTo.offsetHeight + 1) + "px";
                this.style.left = OFramework.getPosLeft(attachTo) + "px";
                this.style.display = "block";
                this.style.zIndex = OFramework.getZIndex(attachTo) + 100;
                var lw = this.AttachedTo.getAttribute("listWidth");
                this.style.width = lw != null ? lw : "100px";
                var lh = this.AttachedTo.getAttribute("listHeight");
                if (lh == null) lh = 5;

                OFramework.ActivePopUp = this;
                this.CanHide = true;
                var setSelIndex = 0;
                dSource = dSource != null ? dSource : ((this.AttachedTo.DataSource != null && this.AttachedTo.DataSource.DataLoaded) ? this.AttachedTo.DataSource : null);
                var itemTemplate = this.AttachedTo.ItemTemplate != "" ? this.AttachedTo.ItemTemplate : null;
                if (dSource != null) {
                    if (this.AttachedTo.GroupSort != null && this.AttachedTo.GroupSort.length > 0) {
                        var top = new Array();
                        var bottom = new Array();
                        for (var i = 0; i < dSource.length; i++) {
                            if (this.AttachedTo.GroupSort.contains(dSource[i].id)) top[top.length] = dSource[i];
                            else bottom[bottom.length] = dSource[i];
                        }
                        dSource = top.concat(bottom);
                    }
                    if (this.AttachedTo.DefaultItem) dSource = new Array(this.AttachedTo.DefaultItem).concat(dSource);
                    if (lh > dSource.length) lh = dSource.length;
                    this.innerHTML = "";
                    for (var i = 0; i < dSource.length; i++) {
                        if (((this.AttachedTo.DefaultItem && i > 0) || (!this.AttachedTo.DefaultItem)) && this.AttachedTo.Filter != null && !this.AttachedTo.Filter.Value.Contains(dSource[i][this.AttachedTo.Filter.Property])) continue;
                        var o = document.createElement("div");
                        o.className = "list_item";
                        o.innerHTML = itemTemplate != null ? OFramework.ProcessItemTemplate(itemTemplate, dSource[i]) : dSource[i].name;
                        o.Value = dSource[i].id
                        o.ItemIndex = this.childNodes.length;
                        o.onmouseover = function () { OFramework.ActivePopUp.SetSelectedIndex(this.ItemIndex); }
                        o.onclick = function () { OFramework.ActivePopUp.Close(); }
                        this.appendChild(o);

                        if (this.AttachedTo.Value == o.Value) setSelIndex = o.ItemIndex;
                    }
                    this.SetSelectedIndex(setSelIndex, true);

                    var mul = this.childNodes.length > 0 ? this.childNodes[0].scrollHeight : this.scrollHeight;
                    this.style.height = (lh * mul + 2) + "px";
                }
                else this.Hide();
            }
            o.Hide = function () {
                if (OFramework.ActivePopUp == null) return;
                OFramework.ActivePopUp.style.display = "none";
                OFramework.ActivePopUp.CanHide = false;
                OFramework.ActivePopUp.AttachedTo = null;
                OFramework.ActivePopUp = null;

                window.onmousedown = null;
            }
            o.Close = function () {
                this.CanHide = true;
                if (this.SelectedIndex > -1) {
                    var selItem = this.childNodes[this.SelectedIndex];
                    if (this.AttachedTo != null) this.AttachedTo.SetValue(selItem.Value, true);
                }
                if (this.AttachedTo != null) this.AttachedTo.Blur();
            }

            o.onblur = function (e, src) {
                if (src == null) src = this;
                this.CanHide = true;
                this.Hide();
            }
            o.onmouseover = function (e) {
                if (!this.mouseCanEnter) return;
                else { this.mouseCanEnter = false; this.mouseCanLeave = true; }
                if (!this.CanHide) this.CanHide = false;
                e = document.all ? event : e; e.cancelBubble = true;

                window.onmousedown = OFramework.ActivePopUp.Hide;
            }
            o.onmouseout = function (e) {
                if (!this.mouseCanLeave) return;
                else { this.mouseCanLeave = false; this.mouseCanEnter = true; }
                if (this.CanHide) this.CanHide = true;
                e = document.all ? event : e; e.cancelBubble = true;
            }
            o.onmousedown = function (e) {
                this.CanHide = false;
                e = document.all ? event : e; e.cancelBubble = true;
            }
            o.mouseCanEnter = true;
            o.mouseCanLeave = false;


            o.onkeydown = function (e) {
                e = document.all ? event : e;

                switch (e.keyCode) {
                    case 40:
                        {
                            this.MoveDown();
                            e.cancelBubble = true;
                            break;
                        }
                    case 38:
                        {
                            this.MoveUp();
                            e.cancelBubble = true;
                            break;
                        }
                    case 9:
                        {
                            this.Close();
                            e.cancelBubble = true;
                            break;
                        }
                    case 13:
                        {
                            this.Close();
                            e.cancelBubble = true;
                            break;
                        }
                }
            }
            o.SelectedIndex = -1;
            o.SetSelectedIndex = function (val, scroll) {
                if (this.SelectedIndex > -1 && this.SelectedIndex < this.childNodes.length) this.childNodes[this.SelectedIndex].className = 'list_item';
                this.SelectedIndex = val;
                this.childNodes[this.SelectedIndex].className = 'list_item_hover';
                if (scroll) {
                    this.scrollTop = this.childNodes[this.SelectedIndex].offsetTop;
                }
            }
            o.MoveUp = function () {
                if (this.SelectedIndex > 0) this.SetSelectedIndex(this.SelectedIndex - 1);
                this.childNodes[this.SelectedIndex].scrollIntoView();
            }
            o.MoveDown = function () {
                if (this.SelectedIndex < this.childNodes.length - 1) this.SetSelectedIndex(this.SelectedIndex + 1);
                this.childNodes[this.SelectedIndex].scrollIntoView();
            }
            OFramework.GetContainer().appendChild(o);
            return o;
        }

        this.Clone = function (srcObj) {
            //alert("deep: in this.clone"+ srcObj);
            var retObj = null;
            switch (srcObj.Type) {
                case "InputText": { retObj = new OFramework.Controls.InputText(); break; }
                case "InputDate": { retObj = new OFramework.Controls.InputDate(); break; }
            }

            if (retObj == null) return null;

            //if(srcObj.style!=null && srcObj.style.cssText!=""){retObj.style.cssText=srcObj.style.cssText;}
            //if(srcObj.Parent!=null){retObj.Parent=srcObj.Parent;}
            //if(srcObj.DataSource!=null){retObj.DataSource=srcObj.DataSource;retObj.DataBind();}
            //if(srcObj.ItemTemplate!=null){retObj.ItemTemplate=srcObj.ItemTemplate;}
            //if(srcObj.MinDate!=null){retObj.MinDate=srcObj.MinDate;}
            //if(srcObj.MaxDate!=null){retObj.MaxDate=srcObj.MaxDate;}

            //if(srcObj.listWidth!=null){retObj.listWidth=srcObj.listWidth;}
            //if(srcObj.listHeight!=null){retObj.listHeight=srcObj.listHeight;}
            return retObj;
        }
    }
    this.Controls.prototype = new Array();

    this.Console = new function () {
        this.container = null;

        this.Write = function (s) {
            if (this.container == null) this.container = this.createContainer();
            this.container.innerHTML += "<br>" + s;
        }

        this.createContainer = function () {
            var o = document.createElement("div");
            o.id = "OFrameworkConsole";
            o.innerHTML = "Console";
            document.body.appendChild(o);
            return o;
        }
    }

    this.TemplateControl = function (oContainer, oTemplate) {
        var o = document.createElement("div");
        o.Type = "TemplateControl";

        this.LoadComplete = function (data) {
            o.innerHTML = data;
            OFramework.ProcessTemplate(o, o.firstChild);
        }
        var tLoader = new OFramework.HtmlLoader(this.LoadComplete);
        tLoader.open("GET", oTemplate + ".html", true);
        tLoader.send(null);


        if (oContainer != null) oContainer.appendChild(o);
        return o;

    }

    this.AirSearchForm = function (oContainer) {
        oContainer.className = "OFContainer";
        oContainer.Type = "AirSearchForm";
        oContainer.innerHTML = "loading...";
        oContainer.Target = "_top";
		oContainer.TargetURL = null;
        oContainer.StateBag = new Array();
        oContainer.SearchType = "RoundTrip";

        oContainer.UseLangID = !OFramework.Culture.IsDefaultLanguage();
        oContainer.Load = function () {
            var tLoader = new OFramework.HtmlLoader(oContainer.LoadComplete);
            var tFileName = oContainer.UseLangID ? "air_search_form_" + OFramework.Culture.GetLanguageCode() + ".html" : "air_search_form.html";
            tLoader.open("GET", OFramework.ThemeURI != null ? OFramework.ThemeURI + tFileName : tFileName, true);
            tLoader.send(null);
        }

        oContainer.LoadComplete = function (data, success) {
            if (success) {
                oContainer.innerHTML = data.replace(/Container./g, "document.getElementById('" + oContainer.id + "').");
                OFramework.ProcessTemplate(oContainer, oContainer.firstChild);
                window.setTimeout("document.getElementById('" + oContainer.id + "').Init()", 50);
            }
            else {
                if (oContainer.UseLangID) {
                    oContainer.UseLangID = false;
                    oContainer.Load();
                }
                else {
                    oContainer.innerHTML = "Error loading template source";
                }
            }
        }
        oContainer.Load();
        oContainer.DataSource = new OFramework.DataSources.JSDataSource("Countries", oContainer);
        oContainer.DataBind = function () {
            if (this.DataSource.DataLoaded && this.To.DataSource.DataLoaded) {
                if (this.StateBag["ResOption"] != null) {
                    this.ResOption.checked = true;
                    this.ResOption.value = this.StateBag["ResOption"];
                }
                for (var i = 0; i < this.To.DataSource.length; i++) {
                    if (this.To.DataSource[i].id == this.To.Value) {
                        this.CheckResidency(this.To.DataSource[i]);
                        break;
                    }
                }
            }
            else {
                window.setTimeout("document.getElementById(\"" + this.id + "\").DataBind()", 50);
            }
        }
        oContainer.Set = function (f, v) {
            var oElem = OFramework.Eval(this, f);
            if (oElem) {
                switch (f) {
                    case "SearchType": this.SearchType = v; break;
                    case "NonStopOption": this[f].checked = (v == "true"); break;
                    case "RefOption": this[f].checked = (v == "true"); break;
                    case "ResOption": this.StateBag[f] = v; break;
                    case "FromDate": this.FromDate.SetValue(OFramework.DateFromString(v), true); break;
                    case "ReturnDate": this.ReturnDate.SetValue(OFramework.DateFromString(v), true); break;

                    case "MultiCityTBL.FlyDate.0": oElem.SetValue(OFramework.DateFromString(v), true); break;
                    case "MultiCityTBL.FlyDate.1": oElem.SetValue(OFramework.DateFromString(v), true); break;
                    case "MultiCityTBL.FlyDate.2": oElem.SetValue(OFramework.DateFromString(v), true); break;
                    case "MultiCityTBL.FlyDate.3": oElem.SetValue(OFramework.DateFromString(v), true); break;
                    case "MultiCityTBL.FlyDate.4": oElem.SetValue(OFramework.DateFromString(v), true); break;
                    case "MultiCityTBL.FlyDate.5": oElem.SetValue(OFramework.DateFromString(v), true); break;

                    default: if (oElem.SetValue) oElem.SetValue(v);
                }
            }
            else this.StateBag[f] = v;
        }
        oContainer.Init = function () {
            this.From = document.getElementById(this.id + '_From');
            this.FromDate = document.getElementById(this.id + '_FromDate');
            this.FromTime = document.getElementById(this.id + '_FromTime');
            this.FromInterval = document.getElementById(this.id + '_FromInterval');
            this.FromRadius = document.getElementById(this.id + '_FromRadius');

            this.To = document.getElementById(this.id + '_To');
            this.ReturnDate = document.getElementById(this.id + '_ReturnDate');
            this.ReturnTime = document.getElementById(this.id + '_ReturnTime');
            this.ToInterval = document.getElementById(this.id + '_ToInterval');
            this.ToRadius = document.getElementById(this.id + '_ToRadius');

            this.Adults = document.getElementById(this.id + '_Adults');
            this.Seniors = document.getElementById(this.id + '_Seniors');
            this.Youths = document.getElementById(this.id + '_Youths');
            this.Children = document.getElementById(this.id + '_Children');
            this.InfantsInLap = document.getElementById(this.id + '_InfantsInLap');
            this.InfantsInSeat = document.getElementById(this.id + '_InfantsInSeat');


            this.PrefAirline = document.getElementById(this.id + '_Airlines');
            this.PrefAirlineTwo = document.getElementById(this.id + '_AirlinesTwo');
            this.PrefAirlineThree = document.getElementById(this.id + '_AirlinesThree');
            this.Class = document.getElementById(this.id + '_Class');
            this.NonStopOption = document.getElementById(this.id + '_NonStopOption');
            this.RefOption = document.getElementById(this.id + '_RefundableOption');
            this.ResOption = document.getElementById(this.id + '_ResidentCHK');

            this.Panels = new Object();
            this.Panels.FromTo = document.getElementById(this.id + '_FromToPanel');
            this.Panels.Dates = document.getElementById(this.id + '_DatesPanel');
            this.Panels.Return = document.getElementById(this.id + '_ReturnPanel');
            this.Panels.Residency = document.getElementById(this.id + '_ResidencyPanel');
            this.Panels.MultiCity = document.getElementById(this.id + '_MultiCityPanel');
            this.Panels.RowOne = document.getElementById(this.id + '_RowOnePanel');
            this.Panels.RowTwo = document.getElementById(this.id + '_RowTwoPanel');
            this.Panels.RowThree = document.getElementById(this.id + '_RowThreePanel');
            this.Panels.RowFour = document.getElementById(this.id + '_RowFourPanel');
            this.Panels.ReturnDate = document.getElementById(this.id + '_ReturnDatePanel');
            this.Panels.ReturnDateLBL = document.getElementById(this.id + '_ReturnDateLBL');
            this.Panels.ReturnTime = document.getElementById(this.id + '_ReturnTimePanel');
            this.Panels.ReturnTimeLBL = document.getElementById(this.id + '_ReturnTimeLBL');

            this.SType = new Object()
            this.SType.DDList = document.getElementById(this.id + '_SearchTypeDD');
            this.SType.RoundTrip = document.getElementById(this.id + '_SearchTypeRoundTrip');
            this.SType.OneWay = document.getElementById(this.id + '_SearchTypeOneWay');
            this.SType.MultiDestination = document.getElementById(this.id + '_SearchTypeMultiDestination');

            if (this.Panels.Residency != null) {
                this.Panels.Residency.Label = document.getElementById(this.id + '_ResidencyLBL');
                this.Panels.Residency.Template = this.Panels.Residency.Label.innerHTML;
            }
            if (document.getElementById(this.id + '_FromIntervalCHK') != null) {
                this.FromInterval = document.getElementById(this.id + '_FromIntervalCHK');
                this.FromInterval.Value = "";
                this.FromInterval.SetValue = function (v) { if (this.value == v) { this.checked = true; this.Value = v } else { this.Value = ""; } }
                this.FromInterval.onchange = function () { this.Value = this.checked ? this.value : "" };
            }
            if (document.getElementById(this.id + '_ToIntervalCHK') != null) {
                this.ToInterval = document.getElementById(this.id + '_ToIntervalCHK');
                this.ToInterval.Value = "";
                this.ToInterval.SetValue = function (v) { if (this.value == v) { this.checked = true; this.Value = v } else { this.Value = ""; } }
                this.ToInterval.onchange = function () { this.Value = this.checked ? this.value : "" };
            }
            if (document.getElementById(this.id + '_IntervalCHK') != null) {
                this.FromInterval = document.getElementById(this.id + '_IntervalCHK');
                this.FromInterval.Value = "";
                this.FromInterval.SetValue = function (v) { if (this.value == v) { this.checked = true; this.Value = v } else { this.Value = ""; } }
                this.FromInterval.onchange = function () { this.Value = this.checked ? this.value : "" };
                this.ToInterval = this.FromInterval;
            }
            if (document.getElementById(this.id + '_FromRadiusCHK') != null) {
                this.FromRadius = document.getElementById(this.id + '_FromRadiusCHK');
                this.FromRadius.Value = "";
                this.FromRadius.SetValue = function (v) { if (this.value == v) { this.checked = true; this.Value = v } else { this.Value = ""; } }
                this.FromRadius.onchange = function () { this.Value = this.checked ? this.value : "" };
            }
            if (document.getElementById(this.id + '_ToRadiusCHK') != null) {
                this.ToRadius = document.getElementById(this.id + '_ToRadiusCHK');
                this.ToRadius.Value = "";
                this.ToRadius.SetValue = function (v) { if (this.value == v) { this.checked = true; this.Value = v } else { this.Value = ""; } }
                this.ToRadius.onchange = function () { this.Value = this.checked ? this.value : "" };
            }
            if (document.getElementById(this.id + '_RadiusCHK') != null) {
                this.FromRadius = document.getElementById(this.id + '_RadiusCHK');
                this.FromRadius.Value = "";
                this.FromRadius.SetValue = function (v) { if (this.value == v) { this.checked = true; this.Value = v } else { this.Value = ""; } }
                this.FromRadius.onchange = function () { this.Value = this.checked ? this.value : "" };
                this.ToRadius = this.FromRadius;
            }

            //set default values
            var today = new Date(); today = new Date(today.getFullYear(), today.getMonth(), today.getDate());
            var offset = isNaN(OFramework.QSParams["MinAirDepartureDate"]) ? 0 : parseInt(OFramework.QSParams["MinAirDepartureDate"], 0) + 1;
            var mDate = new Date(today.getFullYear(), today.getMonth(), today.getDate() + offset);
            var dDate = new Date(today.getFullYear(), today.getMonth(), today.getDate() + 7);
            var rDate = new Date(today.getFullYear(), today.getMonth(), today.getDate() + 14);


            this.FromDate.MinDate = mDate;
            this.FromDate.SetValue(dDate);
            this.ReturnDate.MinDate = dDate;
            this.ReturnDate.SetValue(rDate);

            this.Adults.SetValue(1);

            this.MultiCityTBL = document.getElementById(this.id + '_MultiCityTBL');
            this.MultiCityTBL.Items = 1;
            this.MultiCityTBL.From = new Array();
            this.MultiCityTBL.To = new Array();
            this.MultiCityTBL.FlyDate = new Array();
            this.MultiCityTBL.FlyTime = new Array();
            for (var i = 0; i < 6; i++) {
                this.MultiCityTBL.From[i] = document.getElementById(this.id + '_FromCity_' + i);
                this.MultiCityTBL.To[i] = document.getElementById(this.id + '_ToCity_' + i);
                this.MultiCityTBL.FlyDate[i] = document.getElementById(this.id + '_FlyDate_' + i);
                this.MultiCityTBL.FlyDate[i].MinDate = mDate;
                //if(i==0)this.MultiCityTBL.FlyDate[i].SetValue(dDate);
                this.MultiCityTBL.FlyTime[i] = document.getElementById(this.id + '_FlyTime_' + i);
            }
            for (var f in this.StateBag) {
                var oElem = OFramework.Eval(this, f);
                if (!oElem) continue;
                switch (f) {
                    case "SearchType": this.SearchType = this.StateBag[f]; break;
                    case "NonStopOption": this[f].checked = (this.StateBag[f] == "true"); break;
                    case "RefOption": this[f].checked = (this.StateBag[f] == "true"); break;
                    case "ResOption": break;
                    case "FromDate": this.FromDate.SetValue(OFramework.DateFromString(this.StateBag[f]), true); break;
                    case "ReturnDate": this.ReturnDate.SetValue(OFramework.DateFromString(this.StateBag[f]), true); break;

                    case "MultiCityTBL.Items":
                        {
                            while (this.MultiCityTBL.Items < this.StateBag[f]) this.AddSegment();
                            break;
                        }
                    case "MultiCityTBL.FlyDate.0": oElem.SetValue(OFramework.DateFromString(this.StateBag[f]), true); break;
                    case "MultiCityTBL.FlyDate.1": oElem.SetValue(OFramework.DateFromString(this.StateBag[f]), true); break;
                    case "MultiCityTBL.FlyDate.2": oElem.SetValue(OFramework.DateFromString(this.StateBag[f]), true); break;
                    case "MultiCityTBL.FlyDate.3": oElem.SetValue(OFramework.DateFromString(this.StateBag[f]), true); break;
                    case "MultiCityTBL.FlyDate.4": oElem.SetValue(OFramework.DateFromString(this.StateBag[f]), true); break;
                    case "MultiCityTBL.FlyDate.5": oElem.SetValue(OFramework.DateFromString(this.StateBag[f]), true); break;

                    default: if (oElem.SetValue) oElem.SetValue(this.StateBag[f]);
                }
            }
            this.ChangeSearchType(this.SearchType);
            this.DataBind();
        }
        oContainer.FieldChanged = function (obj, val) {
            switch (obj.id) {
                case this.id + "_SearchTypeDD":
                    {
                        this.ChangeSearchType(this.SType.DDList.Value);
                        break;
                    }
                case this.id + "_To":
                    {
                        this.CheckResidency(val);
                        break;
                    }
                case this.id + "_FromDate":
                    {
                        this.ReturnDate.MinDate = this.FromDate.Value;
                        if (this.ReturnDate.Value.CompareTo(val) < 0) this.ReturnDate.SetValue(val, true);
                        break;
                    }
                case this.id + "_FlyDate_0":
                    {
                        var dObj = this.MultiCityTBL.FlyDate[1];
                        if (dObj == null) return;
                        dObj.MinDate = this.MultiCityTBL.FlyDate[0].Value;
                        //this.ReturnDate.MinDate = this.FromDate.Value;
                        if (dObj.Value != null && dObj.Value.CompareTo(val) < 0) dObj.SetValue(val, true);
                        break;
                    }
                case this.id + "_FlyDate_1":
                    {
                        var dObj = this.MultiCityTBL.FlyDate[2];
                        dObj.MinDate = this.MultiCityTBL.FlyDate[1].Value;
                        if (dObj == null) return;
                        //this.ReturnDate.MinDate = this.FromDate.Value;
                        if (dObj.Value != null && dObj.Value.CompareTo(val) < 0) dObj.SetValue(val, true);
                        break;
                    }
                case this.id + "_FlyDate_2":
                    {
                        var dObj = this.MultiCityTBL.FlyDate[3];
                        dObj.MinDate = this.MultiCityTBL.FlyDate[2].Value;
                        if (dObj == null) return;
                        //this.ReturnDate.MinDate = this.FromDate.Value;
                        if (dObj.Value != null && dObj.Value.CompareTo(val) < 0) dObj.SetValue(val, true);
                        break;
                    }
                case this.id + "_FlyDate_3":
                    {
                        var dObj = this.MultiCityTBL.FlyDate[4];
                        dObj.MinDate = this.MultiCityTBL.FlyDate[3].Value;
                        if (dObj == null) return;
                        //this.ReturnDate.MinDate = this.FromDate.Value;
                        if (dObj.Value != null && dObj.Value.CompareTo(val) < 0) dObj.SetValue(val, true);
                        break;
                    }
                case this.id + "_FlyDate_4":
                    {
                        var dObj = this.MultiCityTBL.FlyDate[5];
                        dObj.MinDate = this.MultiCityTBL.FlyDate[4].Value;
                        if (dObj == null) return;
                        //this.ReturnDate.MinDate = this.FromDate.Value;
                        if (dObj.Value != null && dObj.Value.CompareTo(val) < 0) dObj.SetValue(val, true);
                        break;
                    }
                case this.id + "_FlyDate_5":
                    {
                        var dObj = this.MultiCityTBL.FlyDate[6];
                        if (dObj == null) return;
                        dObj.MinDate = this.MultiCityTBL.FlyDate[5].Value;
                        //this.ReturnDate.MinDate = this.FromDate.Value;
                        if (dObj.Value != null && dObj.Value.CompareTo(val) < 0) dObj.SetValue(val, true);
                        break;
                    }
            }
        }
        oContainer.ChangeSearchType = function (val) {
            switch (val) {
                case "OneWay":
                    {
                        if (this.Panels.FromTo) this.Panels.FromTo.style.display = document.all ? "block" : "table-row";
                        if (this.Panels.Dates) this.Panels.Dates.style.display = document.all ? "block" : "table-row";
                        if (this.Panels.Return) this.Panels.Return.style.display = "none";
                        if (this.Panels.MultiCity) this.Panels.MultiCity.style.display = "none";

                        if (this.Panels.RowOne) this.Panels.RowOne.style.display = document.all ? "block" : "table-row";
                        if (this.Panels.RowTwo) this.Panels.RowTwo.style.display = document.all ? "block" : "table-row";
                        if (this.Panels.RowThree) this.Panels.RowThree.style.display = document.all ? "block" : "table-row";
                        if (this.Panels.RowFour) this.Panels.RowFour.style.display = document.all ? "block" : "table-row";

                        if (this.Panels.ReturnDateLBL) this.Panels.ReturnDateLBL.style.visibility = "hidden";
                        if (this.Panels.ReturnDate) this.Panels.ReturnDate.style.visibility = "hidden";
                        if (this.Panels.ReturnTimeLBL) this.Panels.ReturnTimeLBL.style.visibility = "hidden";
                        if (this.Panels.ReturnTime) this.Panels.ReturnTime.style.visibility = "hidden";

                        if (this.SType.OneWay != null && !this.SType.OneWay.checked) this.SType.OneWay.checked = true;
                        break;
                    }
                case "RoundTrip":
                    {
                        if (this.Panels.FromTo) this.Panels.FromTo.style.display = document.all ? "block" : "table-row";
                        if (this.Panels.Dates) this.Panels.Dates.style.display = document.all ? "block" : "table-row";
                        if (this.Panels.Return) this.Panels.Return.style.display = document.all ? "block" : "table-row";
                        if (this.Panels.MultiCity) this.Panels.MultiCity.style.display = "none";

                        if (this.Panels.RowOne) this.Panels.RowOne.style.display = document.all ? "block" : "table-row";
                        if (this.Panels.RowTwo) this.Panels.RowTwo.style.display = document.all ? "block" : "table-row";
                        if (this.Panels.RowThree) this.Panels.RowThree.style.display = document.all ? "block" : "table-row";
                        if (this.Panels.RowFour) this.Panels.RowFour.style.display = document.all ? "block" : "table-row";

                        if (this.Panels.ReturnDateLBL) this.Panels.ReturnDateLBL.style.visibility = "visible";
                        if (this.Panels.ReturnDate) this.Panels.ReturnDate.style.visibility = "visible";
                        if (this.Panels.ReturnTimeLBL) this.Panels.ReturnTimeLBL.style.visibility = "visible";
                        if (this.Panels.ReturnTime) this.Panels.ReturnTime.style.visibility = "visible";

                        if (this.SType.RoundTrip != null && !this.SType.RoundTrip.checked) this.SType.RoundTrip.checked = true;
                        break;
                    }
                case "MultiDestination":
                    {
                        if (this.Panels.FromTo) this.Panels.FromTo.style.display = "none";
                        if (this.Panels.Dates) this.Panels.Dates.style.display = "none";
                        if (this.Panels.MultiCity) this.Panels.MultiCity.style.display = document.all ? "block" : "table-row";

                        if (this.Panels.RowOne) this.Panels.RowOne.style.display = "none";
                        if (this.Panels.RowTwo) this.Panels.RowTwo.style.display = "none";
                        if (this.Panels.RowThree) this.Panels.RowThree.style.display = "none";
                        if (this.Panels.RowFour) this.Panels.RowFour.style.display = "none";

                        if (this.SType.MultiDestination != null && !this.SType.MultiDestination.checked) this.SType.MultiDestination.checked = true;
                        break;
                    }
            }

            this.SearchType = val;
        }
        oContainer.AddSegment = function () {
            if (this.MultiCityTBL.Items == 6) return;
            this.MultiCityTBL.rows[this.MultiCityTBL.Items].style.display = document.all ? "block" : "table-row";
            this.MultiCityTBL.Items++;
        }
        oContainer.RemoveSegment = function () {
            if (this.MultiCityTBL.Items == 1) return;
            this.MultiCityTBL.Items--;
            this.MultiCityTBL.rows[this.MultiCityTBL.Items].style.display = "none";
        }
        oContainer.CheckResidency = function (val) {
            if (this.Panels.Residency == null) return;
            this.Panels.Residency.style.display = "none";
            if (this.ResOption != null) this.ResOption.checked = val != null ? this.ResOption.checked && this.ResOption.value == val.country : false;

            if (!val) return;
            if (this.DataSource != null && this.DataSource.DataLoaded) {
                for (var i = 0; i < this.DataSource.length; i++) {
                    var ds = this.DataSource[i];
                    if (ds.id == val.country && ds.flag == "1") {
                        this.Panels.Residency.style.display = document.all ? "block" : "table-row";
                        if (this.ResOption != null) this.ResOption.value = ds.id;
                        this.Panels.Residency.Label.innerHTML = this.Panels.Residency.Template.replace('[country]', ds.name);
                        return;
                    }
                }
            }
        }
        oContainer.AdvancedSearch = function () {
            var baseStr = OFramework.BaseURI + "air/default.aspx";
            var sStr = baseStr;
            if (OFramework.QSParams["siid"] != null) sStr += (sStr == baseStr ? "?" : "&") + "siid=" + OFramework.QSParams["siid"];
            if (OFramework.QSParams["sid1"] != null) sStr += (sStr == baseStr ? "?" : "&") + "sid1=" + OFramework.QSParams["sid1"];
            if (OFramework.QSParams["sid2"] != null) sStr += (sStr == baseStr ? "?" : "&") + "sid2=" + OFramework.QSParams["sid2"];
            if (OFramework.QSParams["referrer"] != null) sStr += (sStr == baseStr ? "?" : "&") + "referrer=" + OFramework.QSParams["referrer"];
            if (!OFramework.Culture.IsDefaultLanguage()) sStr += (sStr == baseStr ? "?" : "&") + "lang=" + OFramework.Culture.LanguageID;

            window.open(sStr, this.Target);
        }
        oContainer.SubmitSearch = function () {
            if (!this.ValidateInput()) return;
			var baseStr = this.TargetURL == null ? OFramework.BaseURI + "air/default.aspx" : this.TargetURL;
            var sStr = baseStr;
            if (OFramework.QSParams["siid"] != null) sStr += (sStr == baseStr ? "?" : "&") + "siid=" + OFramework.QSParams["siid"];
            if (OFramework.QSParams["sid1"] != null) sStr += (sStr == baseStr ? "?" : "&") + "sid1=" + OFramework.QSParams["sid1"];
            if (OFramework.QSParams["sid2"] != null) sStr += (sStr == baseStr ? "?" : "&") + "sid2=" + OFramework.QSParams["sid2"];
            if (OFramework.QSParams["referrer"] != null) sStr += (sStr == baseStr ? "?" : "&") + "referrer=" + OFramework.QSParams["referrer"];
			if (OFramework.QSParams["uuid"] != null) sStr += (sStr == baseStr ? "?" : "&") + OFramework.QSParams["uuid"];
            if (!OFramework.Culture.IsDefaultLanguage()) sStr += (sStr == baseStr ? "?" : "&") + "lang=" + OFramework.Culture.LanguageID;

            var airSegCount = 2;
            var segmentData = "";

            var fromInterval = this.FromInterval != null ? this.FromInterval.Value : "";
            var toInterval = this.ToInterval != null ? this.ToInterval.Value : "";

            if (this.SearchType == "RoundTrip") {
                airSegCount = 2;
                segmentData += "AirSeg_1="
		            + this.From.Value
		            + "|" + this.To.Value
		            + "|" + this.FromDate.Value.ToString()
		            + "|" + (this.FromTime != null ? this.FromTime.Value : "")
		            + "|" + (this.FromRadius != null ? this.FromRadius.Value : "")
		            + "|" + (this.ToRadius != null ? this.ToRadius.Value : "")
		            + "|" + fromInterval
		            + "|" + toInterval
		            + "";
                segmentData += "&AirSeg_2="
		            + this.To.Value
		            + "|" + this.From.Value
		            + "|" + this.ReturnDate.Value.ToString()
		            + "|" + (this.ReturnTime != null ? this.ReturnTime.Value : "")
		            + "|" + (this.ToRadius != null ? this.ToRadius.Value : "")
		            + "|" + (this.FromRadius != null ? this.FromRadius.Value : "")
		            + "|" + toInterval
		            + "|" + fromInterval
		            + "";
            }

            if (this.SearchType == "OneWay") {
                airSegCount = 1;
                segmentData += "AirSeg_1="
		            + this.From.Value
		            + "|" + this.To.Value
		            + "|" + this.FromDate.Value.ToString()
		            + "|" + (this.FromTime != null ? this.FromTime.Value : "")
		            + "|" + (this.FromRadius != null ? this.FromRadius.Value : "")
		            + "|" + (this.ToRadius != null ? this.ToRadius.Value : "")
		            + "|" + fromInterval
		            + "|" + toInterval
		            + "";
            }
            if (this.SearchType == "MultiDestination") {
                airSegCount = this.MultiCityTBL.Items;
                for (var i = 0; i < airSegCount; i++) {
                    segmentData += (i > 0 ? "&" : "") + "AirSeg_" + (i + 1) + "="
		            + this.MultiCityTBL.From[i].Value
		            + "|" + this.MultiCityTBL.To[i].Value
		            + "|" + this.MultiCityTBL.FlyDate[i].Value.ToString()
		            + "|" + (((this.MultiCityTBL.FlyTime != null) && (this.MultiCityTBL.FlyTime[i] != null)) ? this.MultiCityTBL.FlyTime[i].Value : "")
		            + "|"
		            + "|"
		            + "|"
		            + "|"
		            + "";
                }
            }
            sStr += (sStr == baseStr ? "?" : "&") + "AirSegCount=" + airSegCount + "&aCount=" + this.Adults.Value;

            if (this.Seniors != null && this.Seniors.Value != 0) sStr += "&sCount=" + this.Seniors.Value;
            if (this.Youths != null && this.Youths.Value != 0) sStr += "&yCount=" + this.Youths.Value;
            if (this.Children != null && this.Children.Value != 0) sStr += "&cCount=" + this.Children.Value;
            if (this.InfantsInLap != null && this.InfantsInLap.Value != 0) sStr += "&iLCount=" + this.InfantsInLap.Value;
            if (this.InfantsInSeat != null && this.InfantsInSeat.Value != 0) sStr += "&iSCount=" + this.InfantsInSeat.Value;

            var airlines = "";
            if (this.PrefAirline != null && this.PrefAirline.Value != "") airlines = this.PrefAirline.Value;
            if (this.PrefAirlineTwo != null && this.PrefAirlineTwo.Value != "") airlines += (airlines != "" ? "," : "") + this.PrefAirlineTwo.Value;
            if (this.PrefAirlineThree != null && this.PrefAirlineThree.Value != "") airlines += (airlines != "" ? "," : "") + this.PrefAirlineThree.Value;
            if (airlines != "") sStr += "&Airline=" + airlines;

            if (this.Class != null && this.Class.Value != "") sStr += "&Class=" + this.Class.Value;
            if (this.NonStopOption != null && this.NonStopOption.checked) sStr += "&DirectFlight=1";
            if (this.RefOption != null && this.RefOption.checked) sStr += "&Refundable=1";
            if (this.ResOption != null && this.ResOption.checked) sStr += "&Resident=" + this.ResOption.value;

            sStr += "&" + segmentData;
            //alert(sStr);
            window.open(sStr, this.Target);
        }
        oContainer.ValidateInput = function () {
            var alert_message = "";
            if (this.SearchType == "OneWay" || this.SearchType == "RoundTrip") {
                if (this.From.Value == "") alert_message += " - departure city\n";
                if (this.To.Value == "") alert_message += " - arrival city\n";
            }
            else {
                for (var i = 0; i < this.MultiCityTBL.Items; i++) {
                    if (this.MultiCityTBL.From[i].Value == "") alert_message += " - segment #" + (i + 1) + " departure city\n";
                    if (this.MultiCityTBL.To[i].Value == "") alert_message += " - segment #" + (i + 1) + " arrival city\n";
                    if (this.MultiCityTBL.FlyDate[i].Value == null) alert_message += " - segment #" + (i + 1) + " departure date\n";
                }
            }
            if (this.Adults.Value + (this.Seniors != null ? this.Seniors.Value : 0) < (this.InfantsInLap != null ? this.InfantsInLap.Value : 0)) {
                alert_message += " - infants in lap must be less than the number of adults and/or seniors travelling\n";
            }
            if (this.Adults.Value + (this.Seniors != null ? this.Seniors.Value : 0) == 0 && (this.Youths != null ? this.Youths.Value : 0) + (this.Children != null ? this.Children.Value : 0) > 0) {
                alert_message += " - youths/children must be accompanied by an adult/senior\n";
            }
            var passNum = this.Adults.Value + (this.Seniors != null ? this.Seniors.Value : 0) + (this.Youths != null ? this.Youths.Value : 0) + (this.Children != null ? this.Children.Value : 0) + (this.InfantsInLap != null ? this.InfantsInLap.Value : 0) + (this.InfantsInSeat != null ? this.InfantsInSeat.Value : 0);
            if (passNum == 0) alert_message += " - the number of passengers travelling \n";

            if (alert_message != "") {
                alert("The following information was not provided : \n" + alert_message);
                return false;
            }
            return true;
        }
        return oContainer;
    }

    this.CruiseSearchForm = function (oContainer, flt) {
        if (oContainer == null) return;
        oContainer.className = "OFContainer";
        oContainer.Type = "CruiseSearchForm";
        oContainer.innerHTML = "loading...";
        oContainer.Target = "_top";
        oContainer.TargetURL = null;
        oContainer.Filter = { Enabled: true, Value: "*.*.*.*.*.*.*.*" };
        oContainer.GroupSort = { Destination: [], Departure: [] };

        oContainer.UseLangID = !OFramework.Culture.IsDefaultLanguage();
        oContainer.Load = function () {
            var tLoader = new OFramework.HtmlLoader(oContainer.LoadComplete);
            var tFileName = oContainer.UseLangID ? "cruise_search_form_" + OFramework.Culture.GetLanguageCode() + ".html" : "cruise_search_form.html";
            tLoader.open("GET", OFramework.ThemeURI != null ? OFramework.ThemeURI + tFileName : tFileName, true);
            tLoader.send(null);
        }

        oContainer.LoadComplete = function (data, success) {
            if (success) {
                oContainer.innerHTML = data.replace(/Container./g, "document.getElementById('" + oContainer.id + "').");
                OFramework.ProcessTemplate(oContainer, oContainer.firstChild, true);
                window.setTimeout("document.getElementById('" + oContainer.id + "').Init()", 50);
            }
            else {
                if (oContainer.UseLangID) {
                    oContainer.UseLangID = false;
                    oContainer.Load();
                }
                else {
                    oContainer.innerHTML = "Error loading template source";
                }
            }
        }

        switch (flt) {
            case 0: { oContainer.Filter.Enabled = false; break; }
            case 1: { oContainer.Filter.Enabled = document.all ? false : true; break; }
            case 2: { oContainer.Filter.Enabled = document.all ? true : false; break; }
            default: { if (flt != null) { oContainer.Filter.Value = flt; } break; }
        }
        oContainer.Load();
        oContainer.DataSource = new OFramework.DataSources.JSDataSource("CruiseFormData", oContainer, "flt=" + oContainer.Filter.Value);
        oContainer.DataBind = function () {
            if (this.DataSource.DataLoaded) {
                if (this.DataSource.Filter) this.Filter.Value = this.DataSource.Filter;
                if (this.SailingsLBL) {
                    var label = this.SailingsLBL.getAttribute("label");
                    this.SailingsLBL.innerHTML = (label != null ? label : "Sailings") + " : " + this.DataSource.DataCount;
                }
                if (this.CruiseLine) {
                    this.CruiseLine.DataSource = this.DataSource["CruiseLines"];
                    this.CruiseLine.DataSource.DataLoaded = true;
                    if (this.CruiseLine.Type == "SelectList") this.CruiseLine.DataBind();
                }
                if (this.Ship) {
                    this.Ship.DataSource = this.DataSource["Ships"];
                    this.Ship.DataSource.DataLoaded = true;
                    if (this.Ship.Type == "SelectList") this.Ship.DataBind();
                }
                if (this.Destination) {
                    this.Destination.DataSource = this.DataSource["Destinations"];
                    this.Destination.DataSource.DataLoaded = true;
                    if (this.Destination.Type == "SelectList") this.Destination.DataBind();
                }
                if (this.Departure) {
                    this.Departure.DataSource = this.DataSource["DeparturePorts"];
                    this.Departure.DataSource.DataLoaded = true;
                    if (this.Departure.Type == "SelectList") this.Departure.DataBind();
                }
                if (this.Length) {
                    this.Length.DataSource = this.DataSource["CruiseLength"];
                    this.Length.DataSource.DataLoaded = true;
                    if (this.Length.Type == "SelectList") this.Length.DataBind();
                }
                if (this.Month) {
                    this.Month.DataSource = this.DataSource["DepatureDates"];
                    this.Month.DataSource.DataLoaded = true;
                    if (this.Month.Type == "SelectList") this.Month.DataBind();
                }
                if (this.TType) this.TType.DataBind(this.DataSource["TTypes"]);
                if (this.Specials) {
                    this.Specials.DataSource = this.DataSource["Consolidators"];
                    this.Specials.DataSource.DataLoaded = true;
                    if (this.Specials.Type == "SelectList") this.Specials.DataBind();
                }
                var fltValues = this.Filter.Value.split(".");
                if (fltValues.length == 8) {
                    if (fltValues[0] != "*" && this.CruiseLine) this.CruiseLine.SetValue(fltValues[0]);
                    if (fltValues[1] != "*" && this.Ship) this.Ship.SetValue(fltValues[1]);
                    if (fltValues[2] != "*" && this.Destination) this.Destination.SetValue(fltValues[2]);
                    if (fltValues[3] != "*" && this.Length) this.Length.SetValue(fltValues[3]);
                    if (fltValues[4] != "*" && this.Departure) this.Departure.SetValue(fltValues[4]);
                    if (fltValues[5] != "*" && this.Month) this.Month.SetValue(fltValues[5]);
                    if (this.TType) this.TType.SetValue(fltValues[6]);
                    if (fltValues[7] != "*" && this.Specials) this.Specials.SetValue(fltValues[7]);
                }
            }
            else {
                if (this.SailingsLBL) this.SailingsLBL.innerHTML = "loading...";
                window.setTimeout("document.getElementById(\"" + this.id + "\").DataBind()", 50);
            }
        }
        oContainer.Set = function (f, v) { }
        oContainer.Init = function () {
            this.SailingsLBL = document.getElementById(this.id + '_SailingsLBL');
            this.Destination = document.getElementById(this.id + '_Destination');
            this.Departure = document.getElementById(this.id + '_Departure');
            this.CruiseLine = document.getElementById(this.id + '_CruiseLine');
            this.Ship = document.getElementById(this.id + '_Ship');
            this.Length = document.getElementById(this.id + '_Length');
            this.Month = document.getElementById(this.id + '_Month');

            this.PriceRange = document.getElementById(this.id + '_PriceRange');
            this.SpecialFares = document.getElementById(this.id + '_SpecialFares');

            this.TType = new Object();
            this.TType.Value = "";
            this.TType.DDList = document.getElementById(this.id + '_TransportationType');
            this.TType.All = document.getElementById(this.id + '_TTypeAll');
            this.TType.CruiseOnly = document.getElementById(this.id + '_TTypeCruiseOnly');
            this.TType.CruiseAir = document.getElementById(this.id + '_TTypeCruiseAir');
            this.TType.SetValue = function (val) {
                if (val == "*") val = "";
                if (this.DDList) {
                    this.DDList.SetValue(val);
                }
                else {
                    if (this.CruiseOnly && this.CruiseOnly.value == val) this.CruiseOnly.checked = true;
                    if (this.CruiseAir && this.CruiseAir.value == val) this.CruiseAir.checked = true;
                    if (this.All && this.All.value == val) this.All.checked = true;
                    this.Value = val;
                }
            }
            this.TType.DataBind = function (data) {
                if (this.CruiseOnly) this.CruiseOnly.disabled = true;
                if (this.CruiseAir) this.CruiseAir.disabled = true;

                if (this.DDList) {
                    this.DDList.DataSource = data;
                    this.DDList.DataSource.DataLoaded = (data != null);
                    if (this.DDList.Type == "SelectList") this.DDList.DataBind();
                }
                else if (data != null) {
                    for (var i = 0; i < data.length; i++) {
                        if (this.CruiseOnly && this.CruiseOnly.value == data[i].id) this.CruiseOnly.disabled = false;
                        if (this.CruiseAir && this.CruiseAir.value == data[i].id) this.CruiseAir.disabled = false;
                    }
                }
            }

            //this.Transportation = document.getElementById(this.id + '_TransportationType');
            this.Specials = document.getElementById(this.id + '_Specials');

            this.OpenTarget = document.getElementById(this.id + '_OpenTarget');
            this.OnLoad();
        }
        oContainer.OnLoad = function () {
            this.DataBind();
        }

        oContainer.FieldChanged = function (obj, val) {
            if (this.Filter.Enabled) {
                if (obj == this.CruiseLine && val == "") this.Ship.Value = "";
                this.FilterData();
            }
            else {
                switch (obj) {
                    case this.CruiseLine:
                        {
                            var flt = new OFramework.Array();
                            flt.push(val);
                            this.Ship.SetFilter("cid", val != "" ? flt : null);
                            break;
                        }
                }
            }
        }
        oContainer.FilterData = function () {
            if (this.SailingsLBL) this.SailingsLBL.innerHTML = "Filtering...";

            this.Filter.Value = "";
            this.Filter.Value += (this.CruiseLine && this.CruiseLine.Value != "" ? this.CruiseLine.Value : "*") + ".";
            this.Filter.Value += (this.Ship && this.Ship.Value != "" ? this.Ship.Value : "*") + ".";
            this.Filter.Value += (this.Destination && this.Destination.Value != "" ? this.Destination.Value : "*") + ".";
            this.Filter.Value += (this.Length && this.Length.Value != "" ? this.Length.Value : "*") + ".";
            this.Filter.Value += (this.Departure && this.Departure.Value != "" ? this.Departure.Value : "*") + ".";
            this.Filter.Value += (this.Month && this.Month.Value != "" ? this.Month.Value : "*") + ".";
            this.Filter.Value += (this.TType.DDList && this.TType.DDList.Value != "" ? this.TType.DDList.Value : (this.TType.Value != "" ? this.TType.Value : "*")) + ".";
            this.Filter.Value += (this.Specials && this.Specials.Value != "" ? this.Specials.Value : "*");

            if (this.CruiseLine) {
                this.CruiseLine.DataSource.DataLoaded = false;
                this.CruiseLine.DataBind();
            }
            if (this.Ship) {
                this.Ship.DataSource.DataLoaded = false;
                this.Ship.DataBind();
            }
            if (this.Destination) {
                this.Destination.DataSource.DataLoaded = false;
                this.Destination.DataBind();
            }
            if (this.Length) {
                this.Length.DataSource.DataLoaded = false;
                this.Length.DataBind();
            }
            if (this.Departure) {
                this.Departure.DataSource.DataLoaded = false;
                this.Departure.DataBind();
            }
            if (this.Month) {
                this.Month.DataSource.DataLoaded = false;
                this.Month.DataBind();
            }
            if (this.TType.DDList) {
                this.TType.DDList.DataSource.DataLoaded = false;
                this.TType.DDList.DataBind();
            }
            if (this.Specials) {
                this.Specials.DataSource.DataLoaded = false;
                this.Specials.DataBind();
            }
            OFramework.DataSources["CruiseFormData"] = null;
            OFramework.DataSources.Bindings["CruiseFormData"] = null;
            this.DataSource = new OFramework.DataSources.JSDataSource("CruiseFormData", oContainer, "flt=" + this.Filter.Value);
            this.DataBind();
        }
        oContainer.ChangeTType = function (val) {
            if (this.CruiseOnly) this.CruiseOnly.disabled = true;
            if (this.CruiseAir) this.CruiseAir.disabled = true;
            if (this.All) this.All.disabled = true;

            this.TType.Value = val;
            this.FieldChanged(this.TType, val);
        }
        oContainer.AdvancedSearch = function () {
            var baseStr = OFramework.BaseURI + "cruises/search.aspx";
            var sStr = baseStr;
            if (OFramework.QSParams["siid"] != null) sStr += (sStr == baseStr ? "?" : "&") + "siid=" + OFramework.QSParams["siid"];
            if (OFramework.QSParams["sid1"] != null) sStr += (sStr == baseStr ? "?" : "&") + "sid1=" + OFramework.QSParams["sid1"];
            if (OFramework.QSParams["sid2"] != null) sStr += (sStr == baseStr ? "?" : "&") + "sid2=" + OFramework.QSParams["sid2"];
            if (OFramework.QSParams["referrer"] != null) sStr += (sStr == baseStr ? "?" : "&") + "referrer=" + OFramework.QSParams["referrer"];
            if (!OFramework.Culture.IsDefaultLanguage()) sStr += (sStr == baseStr ? "?" : "&") + "lang=" + OFramework.Culture.LanguageID;

            window.open(sStr, this.Target);
        }
        oContainer.SubmitSearch = function () {
            if (!this.ValidateInput()) return;
            var baseStr = this.TargetURL == null ? OFramework.BaseURI + "cruises/search.aspx" : this.TargetURL;
            var sStr = baseStr;
            if (OFramework.QSParams["siid"] != null) sStr += (sStr == baseStr ? "?" : "&") + "siid=" + OFramework.QSParams["siid"];
            if (OFramework.QSParams["sid1"] != null) sStr += (sStr == baseStr ? "?" : "&") + "sid1=" + OFramework.QSParams["sid1"];
            if (OFramework.QSParams["sid2"] != null) sStr += (sStr == baseStr ? "?" : "&") + "sid2=" + OFramework.QSParams["sid2"];
            if (OFramework.QSParams["referrer"] != null) sStr += (sStr == baseStr ? "?" : "&") + "referrer=" + OFramework.QSParams["referrer"];
			if (OFramework.QSParams["uuid"] != null) sStr += (sStr == baseStr ? "?" : "&") + OFramework.QSParams["uuid"];
            if (!OFramework.Culture.IsDefaultLanguage()) sStr += (sStr == baseStr ? "?" : "&") + "lang=" + OFramework.Culture.LanguageID;

            sStr += (sStr == baseStr ? "?" : "&") + "SearchCruise=1";

            if (this.CruiseLine && this.CruiseLine.Value != "") sStr += "&CruiseLine=" + this.CruiseLine.Value;
            if (this.Ship && this.Ship.Value != "") sStr += "&Ship=" + this.Ship.Value;
            if (this.Destination && this.Destination.Value != "") sStr += "&Destinations=" + this.Destination.Value;
            if (this.Departure && this.Departure.Value != "") sStr += "&DeparturePorts=" + this.Departure.Value;
            if (this.Length && this.Length.Value != "") {
                var values = this.Length.Value.split(",")
                var min = null;
                var max = null;
                for (i = 0; i < this.Length.DataSource.length; i++) {
                    if (this.Length.DataSource[i]["id"] == values[0]) min = this.Length.DataSource[i]["min"];
                    if (this.Length.DataSource[i]["id"] == values[values.length - 1]) max = this.Length.DataSource[i]["max"];
                }
                if (min != null && max != null) sStr += "&MinDuration=" + min + "&MaxDuration=" + max;
            }
            if (this.Month && this.Month.Value != "") {
                var dates = this.Month.Value.split(",");
                sStr += "&StartDate=" + this.GetDateStart(dates[0]);
                sStr += "&EndDate=" + this.GetDateEnd(dates[dates.length - 1]);
            }
            if (this.PriceRange && this.PriceRange.Value != "") sStr += "&pRange=" + this.PriceRange.Value;
            if (this.SpecialFares && this.SpecialFares.Value != "") sStr += "&sFares=" + this.SpecialFares.Value;
            if (this.TType.DDList && this.TType.DDList.Value != "") sStr += "&transportId=" + this.TType.DDList.Value;
            else if (this.TType.Value != "") sStr += "&transportId=" + this.TType.Value;
            if (this.Specials && this.Specials.Value != "") sStr += "&consolidators=" + this.Specials.Value;
            var win = this.OpenTarget && this.OpenTarget.checked ? this.OpenTarget.value : this.Target;
            //alert(win + " : " + sStr);
            window.open(sStr, win);
        }
        oContainer.GetDateStart = function (obj) {
            var date = obj.split("-");
            var dateObj = new Date();
            dateObj.setFullYear(parseInt(date[1], 10), parseInt(date[0], 10) - 1, 1);
            return (dateObj.getMonth() + 1) + "/" + dateObj.getDate() + "/" + dateObj.getFullYear();
        }
        oContainer.GetDateEnd = function (obj) {
            var date = obj.split("-");
            var dateObj = new Date();
            dateObj.setFullYear(parseInt(date[1], 10), parseInt(date[0], 10), 1);
            dateObj.setDate(0);
            return (dateObj.getMonth() + 1) + "/" + dateObj.getDate() + "/" + dateObj.getFullYear();
        }
        oContainer.ValidateInput = function () {
            return true;
        }
        oContainer.Reset = function () {
            this.Filter.Value = "*.*.*.*.*.*.*.*";
            if (this.CruiseLine) this.CruiseLine.SetValue("");
            if (this.Ship) this.Ship.SetValue("");
            if (this.Destination) this.Destination.SetValue("");
            if (this.Length) this.Length.SetValue("");
            if (this.Departure) this.Departure.SetValue("");
            if (this.Month) this.Month.SetValue("");
            if (this.Transportation) this.Transportation.SetValue("");
            if (this.Specials) this.Specials.SetValue("");
            if (this.Filter.Enabled) {
                OFramework.DataSources["CruiseFormData"] = null;
                OFramework.DataSources.Bindings["CruiseFormData"] = null;
                this.DataSource = new OFramework.DataSources.JSDataSource("CruiseFormData", oContainer, "flt=" + this.Filter.Value);
                this.DataBind();
            }
        }
        return oContainer;
    }

    this.HotelSearchForm = function (oContainer) {
        oContainer.className = "OFContainer";
        oContainer.Type = "HotelSearchForm";
        oContainer.innerHTML = "loading...";
        oContainer.Target = "_top";

        oContainer.UseLangID = !OFramework.Culture.IsDefaultLanguage();
        oContainer.Load = function () {
            var tLoader = new OFramework.HtmlLoader(oContainer.LoadComplete);
            var tFileName = oContainer.UseLangID ? "hotel_search_form_" + OFramework.Culture.GetLanguageCode() + ".html" : "hotel_search_form.html";
            tLoader.open("GET", OFramework.ThemeURI != null ? OFramework.ThemeURI + tFileName : tFileName, true);
            tLoader.send(null);
        }

        oContainer.LoadComplete = function (data, success) {
            if (success) {
                oContainer.innerHTML = data.replace(/Container./g, "document.getElementById('" + oContainer.id + "').");
                OFramework.ProcessTemplate(oContainer, oContainer.firstChild);
                window.setTimeout("document.getElementById('" + oContainer.id + "').Init()", 50);
            }
            else {
                if (oContainer.UseLangID) {
                    oContainer.UseLangID = false;
                    oContainer.Load();
                }
                else {
                    oContainer.innerHTML = "Error loading template source";
                }
            }
        }
        oContainer.Load();

        oContainer.Init = function () {
            this.Destination = document.getElementById(this.id + '_Destination');
            this.CheckInDate = document.getElementById(this.id + '_CheckInDate');
            this.CheckInDay = document.getElementById(this.id + '_CheckInDay');
            this.CheckOutDate = document.getElementById(this.id + '_CheckOutDate');
            this.CheckOutDay = document.getElementById(this.id + '_CheckOutDay');
            this.RoomCount = document.getElementById(this.id + '_RoomCount');
            this.HotelName = document.getElementById(this.id + '_HotelName');
            this.HotelClass = document.getElementById(this.id + '_Class');


            this.RoomOne = document.getElementById(this.id + '_RoomOneTR');
            this.RoomOne.Adults = document.getElementById(this.id + '_RoomOneAdults');
            this.RoomOne.Children = document.getElementById(this.id + '_RoomOneChildren');
            this.RoomOne.Children.TR = document.getElementById(this.id + '_RoomOneChildTR');
            this.RoomOne.ChildOneAge = document.getElementById(this.id + '_RoomOneChildOneAge');
            this.RoomOne.ChildTwoAge = document.getElementById(this.id + '_RoomOneChildTwoAge');
            this.RoomOne.ChildThreeAge = document.getElementById(this.id + '_RoomOneChildThreeAge');
            this.RoomOne.ChildFourAge = document.getElementById(this.id + '_RoomOneChildFourAge');

            this.RoomTwo = document.getElementById(this.id + '_RoomTwoTR');
            this.RoomTwo.Adults = document.getElementById(this.id + '_RoomTwoAdults');
            this.RoomTwo.Children = document.getElementById(this.id + '_RoomTwoChildren');
            this.RoomTwo.Children.TR = document.getElementById(this.id + '_RoomTwoChildTR');
            this.RoomTwo.ChildOneAge = document.getElementById(this.id + '_RoomTwoChildOneAge');
            this.RoomTwo.ChildTwoAge = document.getElementById(this.id + '_RoomTwoChildTwoAge');
            this.RoomTwo.ChildThreeAge = document.getElementById(this.id + '_RoomTwoChildThreeAge');
            this.RoomTwo.ChildFourAge = document.getElementById(this.id + '_RoomTwoChildFourAge');

            this.RoomThree = document.getElementById(this.id + '_RoomThreeTR');
            this.RoomThree.Adults = document.getElementById(this.id + '_RoomThreeAdults');
            this.RoomThree.Children = document.getElementById(this.id + '_RoomThreeChildren');
            this.RoomThree.Children.TR = document.getElementById(this.id + '_RoomThreeChildTR');
            this.RoomThree.ChildOneAge = document.getElementById(this.id + '_RoomThreeChildOneAge');
            this.RoomThree.ChildTwoAge = document.getElementById(this.id + '_RoomThreeChildTwoAge');
            this.RoomThree.ChildThreeAge = document.getElementById(this.id + '_RoomThreeChildThreeAge');
            this.RoomThree.ChildFourAge = document.getElementById(this.id + '_RoomThreeChildFourAge');


            //set default values
            var today = new Date();
            var dDate = new Date(today.getFullYear(), today.getMonth(), today.getDate() + 7);
            var rDate = new Date(today.getFullYear(), today.getMonth(), today.getDate() + 8);

            this.CheckInDate.MinDate = today;
            this.CheckInDate.SetValue(dDate);
            this.CheckInDay.innerHTML = OFramework.Culture.Date.ShortDayNames[dDate.getDay()];

            this.CheckOutDate.MinDate = dDate;
            this.CheckOutDate.SetValue(rDate);
            this.CheckOutDay.innerHTML = OFramework.Culture.Date.ShortDayNames[rDate.getDay()];


            var ds = new OFramework.DataSources.HtmlDataSource();
            for (i = 0; i < 18; i++) {
                var lbl = i == 0 ? "<1" : i;
                ds.push({ id: i, name: lbl });
            }
            with (this.RoomOne.ChildOneAge) { DataSource = ds; DataBind(); }
            with (this.RoomOne.ChildTwoAge) { DataSource = ds; DataBind(); }
            with (this.RoomOne.ChildThreeAge) { DataSource = ds; DataBind(); }
            with (this.RoomOne.ChildFourAge) { DataSource = ds; DataBind(); }
            with (this.RoomTwo.ChildOneAge) { DataSource = ds; DataBind(); }
            with (this.RoomTwo.ChildTwoAge) { DataSource = ds; DataBind(); }
            with (this.RoomTwo.ChildThreeAge) { DataSource = ds; DataBind(); }
            with (this.RoomTwo.ChildFourAge) { DataSource = ds; DataBind(); }
            with (this.RoomThree.ChildOneAge) { DataSource = ds; DataBind(); }
            with (this.RoomThree.ChildTwoAge) { DataSource = ds; DataBind(); }
            with (this.RoomThree.ChildThreeAge) { DataSource = ds; DataBind(); }
            with (this.RoomThree.ChildFourAge) { DataSource = ds; DataBind(); }

        }
        oContainer.FieldChanged = function (obj, val) {
            switch (obj) {
                case this.CheckInDate:
                    {
                        var nDate = new Date(val.getFullYear(), val.getMonth(), val.getDate() + 1);
                        this.CheckOutDate.MinDate = nDate;
                        if (this.CheckOutDate.Value.CompareTo(nDate) < 0) this.CheckOutDate.SetValue(nDate, true);

                        this.CheckInDay.innerHTML = OFramework.Culture.Date.ShortDayNames[val.getDay()];
                        break;
                    }
                case this.CheckOutDate:
                    {
                        this.CheckOutDay.innerHTML = OFramework.Culture.Date.ShortDayNames[val.getDay()];
                        break;
                    }
                case this.RoomCount: { this.Display(); break; }
                case this.RoomOne.Children: { this.Display(); break; }
                case this.RoomTwo.Children: { this.Display(); break; }
                case this.RoomThree.Children: { this.Display(); break; }
            }
        }
        oContainer.Display = function () {
            this.RoomTwo.style.display = "none";
            this.RoomThree.style.display = "none";
            var bStr = document.all ? "block" : "table-row";

            switch (this.RoomCount.Value) {
                case "1": { this.RoomTwo.Children.SetValue(0, false); this.RoomThree.Children.SetValue(0, false); break }
                case "2": { this.RoomTwo.style.display = bStr; this.RoomThree.Children.SetValue(0, false); break; }
                case "3": { this.RoomTwo.style.display = bStr; this.RoomThree.style.display = bStr; break; }
            }

            if (this.RoomOne.Children.TR != null) this.RoomOne.Children.TR.style.display = this.RoomOne.Children.Value == 0 ? "none" : bStr;
            this.RoomOne.ChildOneAge.style.visibility = this.RoomOne.Children.Value > 0 ? "visible" : "hidden";
            this.RoomOne.ChildTwoAge.style.visibility = this.RoomOne.Children.Value > 1 ? "visible" : "hidden";
            this.RoomOne.ChildThreeAge.style.visibility = this.RoomOne.Children.Value > 2 ? "visible" : "hidden";
            this.RoomOne.ChildFourAge.style.visibility = this.RoomOne.Children.Value > 3 ? "visible" : "hidden";

            if (this.RoomTwo.Children.TR != null) this.RoomTwo.Children.TR.style.display = this.RoomTwo.Children.Value == 0 ? "none" : bStr;
            this.RoomTwo.ChildOneAge.style.visibility = this.RoomTwo.Children.Value > 0 ? "visible" : "hidden";
            this.RoomTwo.ChildTwoAge.style.visibility = this.RoomTwo.Children.Value > 1 ? "visible" : "hidden";
            this.RoomTwo.ChildThreeAge.style.visibility = this.RoomTwo.Children.Value > 2 ? "visible" : "hidden";
            this.RoomTwo.ChildFourAge.style.visibility = this.RoomTwo.Children.Value > 3 ? "visible" : "hidden";

            if (this.RoomThree.Children.TR != null) this.RoomThree.Children.TR.style.display = this.RoomThree.Children.Value == 0 ? "none" : bStr;
            this.RoomThree.ChildOneAge.style.visibility = this.RoomThree.Children.Value > 0 ? "visible" : "hidden";
            this.RoomThree.ChildTwoAge.style.visibility = this.RoomThree.Children.Value > 1 ? "visible" : "hidden";
            this.RoomThree.ChildThreeAge.style.visibility = this.RoomThree.Children.Value > 2 ? "visible" : "hidden";
            this.RoomThree.ChildFourAge.style.visibility = this.RoomThree.Children.Value > 3 ? "visible" : "hidden";
        }
        oContainer.SubmitSearch = function () {
            if (!this.ValidateInput()) return;
            var baseStr = OFramework.BaseURI + "hotel/default.aspx";
            var sStr = baseStr;
            if (OFramework.QSParams["siid"] != null) sStr += (sStr == baseStr ? "?" : "&") + "siid=" + OFramework.QSParams["siid"];
            if (OFramework.QSParams["sid1"] != null) sStr += (sStr == baseStr ? "?" : "&") + "sid1=" + OFramework.QSParams["sid1"];
            if (OFramework.QSParams["sid2"] != null) sStr += (sStr == baseStr ? "?" : "&") + "sid2=" + OFramework.QSParams["sid2"];
            if (OFramework.QSParams["referrer"] != null) sStr += (sStr == baseStr ? "?" : "&") + "referrer=" + OFramework.QSParams["referrer"];
            if (!OFramework.Culture.IsDefaultLanguage()) sStr += (sStr == baseStr ? "?" : "&") + "lang=" + OFramework.Culture.LanguageID;

            var SegmentData = "&RoomCount=" + this.RoomCount.Value;
            switch (this.RoomCount.Value) {
                case "1":
                    {
                        SegmentData += "&R1=" + this.RoomOne.Adults.Value + "|" + this.RoomOne.Children.Value + "|" + this.RoomOne.ChildOneAge.Value + "," + this.RoomOne.ChildTwoAge.Value + "," + this.RoomOne.ChildThreeAge.Value + "," + this.RoomOne.ChildFourAge.Value
                        break;
                    }
                case "2":
                    {
                        SegmentData += "&R1=" + this.RoomOne.Adults.Value + "|" + this.RoomOne.Children.Value + "|" + this.RoomOne.ChildOneAge.Value + "," + this.RoomOne.ChildTwoAge.Value + "," + this.RoomOne.ChildThreeAge.Value + "," + this.RoomOne.ChildFourAge.Value;
                        SegmentData += "&R2=" + this.RoomTwo.Adults.Value + "|" + this.RoomTwo.Children.Value + "|" + this.RoomTwo.ChildOneAge.Value + "," + this.RoomTwo.ChildTwoAge.Value + "," + this.RoomTwo.ChildThreeAge.Value + "," + this.RoomTwo.ChildFourAge.Value;
                        break;
                    }
                case "3":
                    {
                        SegmentData += "&R1=" + this.RoomOne.Adults.Value + "|" + this.RoomOne.Children.Value + "|" + this.RoomOne.ChildOneAge.Value + "," + this.RoomOne.ChildTwoAge.Value + "," + this.RoomOne.ChildThreeAge.Value + "," + this.RoomOne.ChildFourAge.Value;
                        SegmentData += "&R2=" + this.RoomTwo.Adults.Value + "|" + this.RoomTwo.Children.Value + "|" + this.RoomTwo.ChildOneAge.Value + "," + this.RoomTwo.ChildTwoAge.Value + "," + this.RoomTwo.ChildThreeAge.Value + "," + this.RoomTwo.ChildFourAge.Value;
                        SegmentData += "&R3=" + this.RoomThree.Adults.Value + "|" + this.RoomThree.Children.Value + "|" + this.RoomThree.ChildOneAge.Value + "," + this.RoomThree.ChildTwoAge.Value + "," + this.RoomThree.ChildThreeAge.Value + "," + this.RoomThree.ChildFourAge.Value;
                        break;
                    }
            }
            //add rest of the stuff
            sStr += (sStr == baseStr ? "?" : "&") + "loc=" + encodeURI(this.Destination.Value);
            sStr += "&fDate=" + encodeURI(this.CheckInDate.Value.ToString());
            sStr += "&tDate=" + encodeURI(this.CheckOutDate.Value.ToString());
            if (this.HotelName != null && this.HotelName.Value != "") sStr += "&hName=" + this.HotelName.Value;
            if (this.HotelClass != null && this.HotelClass.Value != "") sStr += "&hClass=" + this.HotelClass.Value;
            //final concat
            sStr += SegmentData;

            //alert(sStr);
            window.open(sStr, this.Target);
        }
        oContainer.ValidateInput = function () {
            alert_message = "";

            if (!this.Destination.Value || this.Destination.Value == "") alert_message += " - destination\n";
            if (this.CheckInDate.Value == "") alert_message += " - check in date\n";
            if (this.CheckOutDate.Value == "") alert_message += " - check out date\n";

            if (alert_message != "") {
                alert("The following information was not provided : \n" + alert_message);
                return false;
            }
            return true;
        }
        return oContainer;
    }

    this.DataSources = new function () {
        this.DataSource = function (oID, source) {
            if (OFramework.DataSources[oID] != null) return OFramework.DataSources[oID];
            var o = new Array();
            o.DataLoaded = false;
            o.LoadComplete = function (data) {
                if (data != null && data.firstChild != null) {
                    for (var n = 0; n < data.firstChild.childNodes.length; n++) {
                        var node = data.firstChild.childNodes[n];
                        if (node.nodeType == 1) {
                            var newDataItem = new Object();
                            for (a = 0; a < node.attributes.length; a++) {
                                newDataItem[node.attributes[a].name] = node.attributes[a].value;
                            }
                            o.push(newDataItem);
                        }
                    }
                }
                o.DataLoaded = true;
            }

            var tLoader = new OFramework.XmlLoader(o.LoadComplete);
            tLoader.open("GET", OFramework.BaseURI + "SearchForms/Data/" + source, true);
            tLoader.send(null);

            OFramework.DataSources[oID] = o;
            return o;
        }
        this.HtmlDataSource = function (source) {
            var o = new Array();
            if (source != null && source.childNodes != null) {
                for (var n = 0; n < source.childNodes.length; n++) {
                    var node = source.childNodes[n];
                    if (node.nodeType == 1 && node.nodeName.toLowerCase() == "item") {
                        var newDataItem = new Object();
                        for (a = 0; a < node.attributes.length; a++) {
                            newDataItem[node.attributes[a].name] = node.attributes[a].value;
                        }
                        o.push(newDataItem);
                    }
                }
            }
            o.DataLoaded = true;
            return o;
        }
        this.JSDataSource = function (oID, oBind, params) {
            if (OFramework.DataSources.Bindings[oID] == null) OFramework.DataSources.Bindings[oID] = new Array();
            if (OFramework.DataSources[oID] != null) {
                if (!OFramework.DataSources[oID].DataLoaded) OFramework.DataSources.Bindings[oID].push(oBind);
                return OFramework.DataSources[oID];
            }
            else {
                var retObj = new Object();
                retObj.DataLoaded = false;

                OFramework.DataSources.Bindings[oID].push(oBind);
                OFramework.DataSources[oID] = retObj;

                var source = "data.aspx?type=" + oID;
                if (params != null) source += "&" + params;
                if (OFramework.QSParams["siid"] != null) source += "&siid=" + OFramework.QSParams["siid"];
                else if (OFramework.QSParams["data_siid"] != null) source += "&siid=" + OFramework.QSParams["data_siid"];
                if (!OFramework.Culture.IsDefaultLanguage()) source += "&lang=" + OFramework.Culture.LanguageID;
                window.setTimeout(function () { var sObj = document.createElement("script"); sObj.src = OFramework.BaseURI + source; sObj.defer = true; OFramework.GetContainer().appendChild(sObj); }, 50); return;
                return retObj;
            }
        }
        this.XmlDataSource = function (oID, oBind, params) {
            var o = new Array();
            o.DataLoaded = false;
            o.LoadComplete = function (data) {
                if (data != null && data.firstChild != null) {
                    o.ProcessDataNode(data.firstChild, o);
                }
                o.DataLoaded = true;
                oBind.DataBind();
            }
            o.ProcessDataNode = function (node, parent) {
                if (node.nodeType == 1) {
                    for (a = 0; a < node.attributes.length; a++) {
                        parent[node.attributes[a].name] = node.attributes[a].value;
                    }
                    for (var n = 0; n < node.childNodes.length; n++) {
                        var cNode = node.childNodes[n];
                        var newDataItem = cNode.nodeName.length == 1 ? new Object() : new Array();
                        o.ProcessDataNode(cNode, newDataItem)
                        if (cNode.nodeName.length == 1) parent.push(newDataItem);
                        else {
                            newDataItem.DataLoaded = true;
                            parent[cNode.nodeName] = newDataItem;
                        }
                    }
                }
            }

            var source = "data.aspx?type=" + oID + "&format=xml";
            if (params != null) source += "&" + params;
            if (OFramework.QSParams["siid"] != null) source += "&siid=" + OFramework.QSParams["siid"];
            else if (OFramework.QSParams["data_siid"] != null) source += "&siid=" + OFramework.QSParams["data_siid"];
            if (!OFramework.Culture.IsDefaultLanguage()) source += "&lang=" + OFramework.Culture.LanguageID;

            var tLoader = new OFramework.XmlLoader(o.LoadComplete);
            tLoader.open("GET", OFramework.BaseURI + source, true);
            tLoader.send(null);

            return o;
        }
        this.DataLoaded = function (oID) {
            if (!OFramework.DataSources.Bindings[oID]) return;
            for (var i = 0; i < OFramework.DataSources.Bindings[oID].length; i++) {
                OFramework.DataSources.Bindings[oID][i].DataSource = OFramework.DataSources[oID];
            }
        }
        this.Bindings = new Array();
    }
    this.DataSources.prototype = new Array();

    this.Templates = new function () {

    }
    this.Templates.prototype = new Array();

    this.ProcessTemplate = function (oContainer, oElement, flag) {

        for (var c = 0; c < oElement.childNodes.length; c++) {
            var oNode = oElement.childNodes[c];
            var oNodeType = null;
            var newNode = null;

            if (oNode.scopeName == "OFramework") {
                oNodeType = oNode.localName != null ? oNode.localName.toLowerCase() : oNode.nodeName.toLowerCase();
            }
            else if (oNode.nodeName.indexOf("OFRAMEWORK") == 0 || oNode.nodeName.indexOf("OFramework") == 0) {
                oNodeType = oNode.nodeName.substring(11, oNode.nodeName.length).toLowerCase();
            }
            if (oNodeType != null) {

                switch (oNodeType) {
                    case "input": { newNode = new OFramework.Controls.InputText(); break; }
                    case "dateinput": { newNode = new OFramework.Controls.InputDate(); break; }
                    case "calendarbutton": { newNode = new OFramework.Controls.CalendarButton(); break; }
                    case "dropdownlist": { newNode = new OFramework.Controls.HtmlDropdownList(); break; }
                    case "selectmultiple": { newNode = new OFramework.Controls.SelectList(); break; }
                }

                if (newNode == null) continue;
                //parent
                newNode.Parent = oContainer;
                //attributes
                for (var a = 0; a < oNode.attributes.length; a++) {
                    if (!oNode.attributes[a].specified) continue;
                    var att = oNode.attributes[a].name;
                    var att_val = oNode.attributes[a].value;
                    switch (att.toLowerCase()) {
                        case "id": { newNode.id = oContainer.id + "_" + att_val; continue; }
                        case "style": { newNode.style.cssText = oNode.style.cssText; continue; }
                        case "datasource":
                            {
                                //newNode.DataSource = new OFramework.DataSources.DataSource(att_val, att_val + ".xml");
                                if (!flag) newNode.DataSource = new OFramework.DataSources.JSDataSource(att_val, newNode);
                                continue;
                            }
                        case "itemtemplate": { newNode.ItemTemplate = att_val; continue; }
                        case "emptyitem": { newNode.DefaultItem = new Object(); newNode.DefaultItem.id = ""; newNode.DefaultItem.name = "&nbsp;"; continue; }
                        case "calendarlayout": { newNode.CalendarLayout = att_val; continue; }
                        case "hinttext": { newNode.HintText = att_val; continue; }
                        case "linked": { newNode.Linked = true; }
                        case "group": { newNode.GroupSort = att_val.split(','); }
                    }
                    newNode.setAttribute(att, att_val);
                }
                if (oNodeType == "dropdownlist" && oNode.childNodes.length > 0) {
                    var ds = new OFramework.DataSources.HtmlDataSource(oNode);
                    if (newNode.DataSource == null) {
                        newNode.DefaultItem = ds.shift(); newNode.DataSource = ds;
                    }
                    else newNode.DefaultItem = ds[0];
                    oNode.innerHTML = "";
                }
                if (newNode.DataSource != null) newNode.DataBind();
                oNode = oElement.replaceChild(newNode, oNode);
            }
            else {
                if (oNode.id && oNode.id != "") oNode.id = oContainer.id + "_" + oNode.id;
                if (oNode.htmlFor && oNode.htmlFor != "") oNode.htmlFor = oContainer.id + "_" + oNode.htmlFor;
            }
            if (oNode.childNodes.length > 0) OFramework.ProcessTemplate(oContainer, oNode, flag);
        }
    }
    this.ProcessItemTemplate = function (sTemplate, sData) {
        var retStr = sTemplate;
        for (s in sData) {
            retStr = retStr.replace(s, sData[s]);
        }
        return retStr;
    }

    this.XmlLoader = function (iCallback) {
        var xmlLoader = null;
        try { xmlLoader = new XMLHttpRequest(); }
        catch (e) {
            try { xmlLoader = new ActiveXObject('Microsoft.XMLHTTP'); }
            catch (e2) {
                try { xmlLoader = new ActiveXObject('Msxml2.XMLHTTP'); }
                catch (e3) { xmlLoader = null; }
            }
        }
        xmlLoader.onreadystatechange = function () {
            if (xmlLoader.readyState == 4) {
                if (xmlLoader.status == 200) iCallback(xmlLoader.responseXML);
            }
        }

        return xmlLoader;
    }

    this.HtmlLoader = function (iCallback) {
        var htmlLoader = null;
        try { htmlLoader = new XMLHttpRequest(); }
        catch (e) {
            try { htmlLoader = new ActiveXObject('Microsoft.XMLHTTP'); }
            catch (e2) {
                try { htmlLoader = new ActiveXObject('Msxml2.XMLHTTP'); }
                catch (e3) { htmlLoader = null; }
            }
        }
        htmlLoader.onreadystatechange = function () {
            if (htmlLoader.readyState == 4) {
                if (htmlLoader.status == 200) iCallback(htmlLoader.responseText, true);
                if (htmlLoader.status == 404) iCallback(null, false); //file not found error, try switch language ?
            }
        }
        return htmlLoader;
    }

    this.getPosTop = function (obj) {
        var cTop = 0;
        if (obj.offsetParent) {
            while (obj.offsetParent) {
                cTop += obj.offsetTop
                obj = obj.offsetParent;
            }
        }
        else if (obj.y) cTop += obj.y;
        return cTop;

    }
    this.getPosLeft = function (obj) {
        var cLeft = 0;
        if (obj.offsetParent) {
            while (obj.offsetParent) {
                cLeft += obj.offsetLeft
                obj = obj.offsetParent;
            }
        }
        else if (obj.x) cLeft += obj.x;
        return cLeft;
    }
    this.WinProperties = new function () {
        this.Width = function () {
            if (typeof (window.innerWidth) == 'number') return window.innerWidth;
            else if (document.documentElement && document.documentElement.clientWidth) return document.documentElement.clientWidth;
            else if (document.body && document.body.clientWidth) return document.body.clientWidth;
            return 0;
        }
        this.Height = function () {
            if (typeof (window.innerHeight) == 'number') return window.innerHeight;
            else if (document.documentElement && document.documentElement.clientHeight) return document.documentElement.clientHeight;
            else if (document.body && document.body.clientHeight) return document.body.clientHeight;
            return 0;
        }
        this.ScrollTop = function () {
            if (typeof (window.scrollTop) == 'number') return window.scrollTop;
            else if (document.documentElement && document.documentElement.scrollTop) return document.documentElement.scrollTop;
            else if (document.body && document.body.scrollTop) return document.body.scrollTop;
            return 0;
        }
        this.ScrollLeft = function () {
            if (typeof (window.scrollLeft) == 'number') return window.scrollLeft;
            else if (document.documentElement && document.documentElement.scrollLeft) return document.documentElement.scrollLeft;
            else if (document.body && document.body.scrollLeft) return document.body.scrollLeft;
            return 0;
        }
    }
    this.getWindowWidth = function () {
        if (typeof (window.innerWidth) == 'number') return window.innerWidth;
        else if (document.documentElement && document.documentElement.clientWidth) return document.documentElement.clientWidth;
        else if (document.body && document.body.clientWidth) return document.body.clientWidth;
        return 0;
    }
    this.getWindowHeight = function () {
        if (typeof (window.innerHeight) == 'number') return window.innerHeight;
        else if (document.documentElement && document.documentElement.clientHeight) return document.documentElement.clientHeight;
        else if (document.body && document.body.clientHeight) return document.body.clientHeight;
        return 0;
    }
    this.getZIndex = function (obj) {
        var z = OFramework.GetStyle(obj, document.all ? 'zIndex' : 'z-index');
        if (z && z != "auto") return parseInt(z);
        else return obj.parentNode ? OFramework.getZIndex(obj.parentNode) : 0;
    }
    this.addEvent = function (elm, strEvent, fnHandler) {
        return (elm.addEventListener
	    ? elm.addEventListener(strEvent, fnHandler, false)
	    : elm.attachEvent('on' + strEvent, fnHandler)
	    );
    }
    this.Eval = function (oObj, sStr) {
        var sParts = sStr.split(".");
        for (i = 0; i < sParts.length; i++) {
            if (oObj[sParts[i]] != null) oObj = oObj[sParts[i]];
            else return null;
        }
        return oObj;
    }
    this.GetStyle = function (element, style) {
        var nn = null; var styles = null;
        if (window.getComputedStyle) { try { styles = window.getComputedStyle(element, null) } catch (e) { }; nn = styles != null ? styles.getPropertyValue(style) : null; }
        else if (document.defaultView && document.defaultView.getComputedStyle) { styles = document.defaultView.getComputedStyle(element, ''); nn = styles != null ? styles[style] : null; }
        var ie = element.currentStyle ? element.currentStyle[style] : null;
        var is = element.style ? element.style[style] : null;
        return nn || ie || is;
    }

    this.Dictionary = function (str, d1, d2) {
        this.Add = function (key, value) { this[key] = value; }
        this.Remove = function (key) { this[key] = null; }
        this.GetValue = function (key) { return this[key]; }

        if (str.length > 1) {
            str = str.substring(1, str.length);
            var keyValuePairs = str.split(d1);
            for (var k = 0; k < keyValuePairs.length; k++) {
                keyValuePair = keyValuePairs[k].split(d2);
                this.Add(unescape(keyValuePair[0]), unescape(keyValuePair[1]))
            }
        }
    }
    this.Dictionary.prototype = new Array();
    this.QSParams = new this.Dictionary(window.location.search, "&", "=");
    this.Culture = new this.Globalization.CultureInfo(this.QSParams["lang"] != null ? this.QSParams["lang"].toLowerCase() : "1");
}

var Value;
function filterList(key,oContainer)
{
		if(Value==null || Value=="")
			Value=String.fromCharCode(key);		
		else
			Value+=String.fromCharCode(key);
		
		var DivEle=document.getElementById("DDListPopUp");
		var List=oContainer.List;
		var divArr = List.getElementsByTagName("div");	
		for(var i=0;i<divArr.length;i++)
		{
				var ele=divArr[i];
				ele.className='list_item';
		}
		for(var i=0;i<divArr.length;i++)
		{
				var ele=divArr[i];
				var eleVal=ele.innerHTML;
				var str=eleVal;
				eleVal=eleVal.toUpperCase();
				Value=Value.toUpperCase();
				ele.className='list_item';
				if(eleVal.startsWith(Value))
				{
						ele.className='list_item_hover';
					    DivEle.scrollTop = ele.offsetTop;	
						oContainer.innerHTML=str;
						break;
				}
		}
		window.setTimeout("resetVal()", 1500);
		return str;
}

/*function setDropDownValue(oContainer)
{
		var List=oContainer.List;
		var divArr = List.getElementsByTagName("div");		
		for(var i=0;i<divArr.length;i++)
		{
				var ele=divArr[i];
				if(ele.className=='list_item_hover')
				{
					oContainer.innerHTML=str;
					break;
				}
		}
		return;
}*/

function resetVal()
{
		Value="";
}

String.prototype.startsWith = function(str)
{
	return this.indexOf(str) === 0;
}

Array.prototype.contains = function(obj) {
  var i = this.length;
  while (i--) {
    if (this[i] === obj) {
      return true;
    }
  }
  return false;
}

