/***********************************************************
 *                                                         *
 *  MOT2U Calendar v4.532.749.0958                         *
 *                                                         *
 *  @Author: Chris Bearcroft                               *
 *  @Copyright: MOT2U 2011                                 *
 *  @Created: 09-12-2011, 12:05 PM (GMT)                   *
 *                                                         *
 *  This file also contains code used in the dhtmlx.com    *
 *  package which was downloaded free from their website,  *
 *  we do not own the codes from them nor do we hold any   *
 *  copyrights over it, we only hold the copyrights to     *
 *  the code surrounding the code provided by dhtmlx.com.  *
 *                                                         *
 ***********************************************************/

(function (root) {
    "use strict";
    root.document.getElementsByClassName = function (c) {
        var i, classes,
            retnode = [],
            myclass = new RegExp('\\b' + c + '\\b'),
            elem = this.getElementsByTagName('*');
        for (i = 0; i < elem.length; i += 1) {
            classes = elem[i].className;
            if (myclass.test(classes)) { retnode.push(elem[i]); }
        }
        return (retnode);
    };
    root._Calendar = function (name, options) {
        if (name) {
            var that = this, calendar, myRoot, mcd, id, i, t, k;
            options = options || {};
            this.Options = {
                Name: name.substr(1),
                Type: name.substr(0, 1),
                Store: {},
                Storage: {},
                setCur: {},
                setCurGlobal: false,
                Calendar: '',
                active: false,
                funcObj: {},
                addClear: false,
                clearImage: "http://oss.mot2u.com/public/images/calendar/close-button.png",
                dRef: {"Jan": "01", "Feb": "02", "Mar": "03", "Apr": "04", "May": "05", "Jun": "06",
                       "Jul": "07", "Aug": "08", "Sep": "09", "Oct": "10", "Nov": "11", "Dec": "12"},
                temp: options
            };
            if (!this.Options.Store[name]) {
                this.Options.Store[this.Options.Name] = {};
            }
            if (options && this.Options.temp.addClear !== undefined && this.Options.temp.addClear) {
                this.Options.addClear = true;
            }
            this.strtotime = function (str, now) {
                var i, l, match, s, parse = '';
                str = str.replace(/\s{2,}|^\s|\s$/g, ' '); // unecessary spaces
                str = str.replace(/[\t\r\n]/g, ''); // unecessary chars
                if (str === 'now') {
                    return now === null || isNaN(now) ? new Date().getTime() / 1000 | 0 : now | 0;
                } else if (!isNaN(parse = Date.parse(str))) {
                    return parse / 1000 | 0;
                } else if (now) {
                    now = new Date(now * 1000); // Accept PHP-style seconds
                } else {
                    now = new Date();
                }
                str = str.toLowerCase();
                var __is = {
                    day: {
                        'sun': 0,
                        'mon': 1,
                        'tue': 2,
                        'wed': 3,
                        'thu': 4,
                        'fri': 5,
                        'sat': 6
                    },
                    mon: [
                        'jan',
                        'feb',
                        'mar',
                        'apr',
                        'may',
                        'jun',
                        'jul',
                        'aug',
                        'sep',
                        'oct',
                        'nov',
                        'dec'
                    ]
                };
                var process = function (m) {
                    var ago = (m[2] && m[2] === 'ago');
                    var num = (num = m[0] === 'last' ? -1 : 1) * (ago ? -1 : 1);
                    switch (m[0]) {
                    case 'last':
                    case 'next':
                        switch (m[1].substring(0, 3)) {
                        case 'yea':
                            now.setFullYear(now.getFullYear() + num);
                            break;
                        case 'mon':
                            now.setMonth(now.getMonth() + num);
                            break;
                        case 'wee':
                            now.setDate(now.getDate() + (num * 7));
                            break;
                        case 'day':
                            now.setDate(now.getDate() + num);
                            break;
                        case 'hou':
                            now.setHours(now.getHours() + num);
                            break;
                        case 'min':
                            now.setMinutes(now.getMinutes() + num);
                            break;
                        case 'sec':
                            now.setSeconds(now.getSeconds() + num);
                            break;
                        default:
                            var day = __is.day[m[1].substring(0, 3)];
                            if (typeof day !== 'undefined') {
                                var diff = day - now.getDay();
                                if (diff === 0) {
                                    diff = 7 * num;
                                } else if (diff > 0) {
                                    if (m[0] === 'last') {
                                        diff -= 7;
                                    }
                                } else {
                                    if (m[0] === 'next') {
                                        diff += 7;
                                    }
                                }
                                now.setDate(now.getDate() + diff);
                            }
                        }
                        break;
                    default:
                        if (/\d+/.test(m[0])) {
                            num *= parseInt(m[0], 10);
                            switch (m[1].substring(0, 3)) {
                            case 'yea':
                                now.setFullYear(now.getFullYear() + num);
                                break;
                            case 'mon':
                                now.setMonth(now.getMonth() + num);
                                break;
                            case 'wee':
                                now.setDate(now.getDate() + (num * 7));
                                break;
                            case 'day':
                                now.setDate(now.getDate() + num);
                                break;
                            case 'hou':
                                now.setHours(now.getHours() + num);
                                break;
                            case 'min':
                                now.setMinutes(now.getMinutes() + num);
                                break;
                            case 'sec':
                                now.setSeconds(now.getSeconds() + num);
                                break;
                            }
                        } else {
                            return false;
                        }
                        break;
                    }
                    return true;
                };
                match = str.match(/^(\d{2,4}-\d{2}-\d{2})(?:\s(\d{1,2}:\d{2}(:\d{2})?)?(?:\.(\d+))?)?$/);
                if (match !== null) {
                    if (!match[2]) {
                        match[2] = '00:00:00';
                    } else if (!match[3]) {
                        match[2] += ':00';
                    }
                    s = match[1].split(/-/g);
                    s[1] = __is.mon[s[1] - 1] || s[1];
                    s[0] = +s[0];
                    s[0] = (s[0] >= 0 && s[0] <= 69) ? '20' + (s[0] < 10 ? '0' + s[0] : s[0] + '') :
                           (s[0] >= 70 && s[0] <= 99) ? '19' + s[0] : s[0] + '';
                    return parseInt(this.strtotime(s[2] + ' ' + s[1] + ' ' + s[0] + ' ' +
                           match[2]) + (match[4] ? match[4] / 1000 : ''), 10);
                }
                var regex = '([+-]?\\d+\\s' +
                '(years?|months?|weeks?|days?|hours?|min|minutes?|sec|seconds?' +
                '|sun\\.?|sunday|mon\\.?|monday|tue\\.?|tuesday|wed\\.?|wednesday' +
                '|thu\\.?|thursday|fri\\.?|friday|sat\\.?|saturday)' + '|(last|next)\\s' +
                '(years?|months?|weeks?|days?|hours?|min|minutes?|sec|seconds?' +
                '|sun\\.?|sunday|mon\\.?|monday|tue\\.?|tuesday|wed\\.?|wednesday' +
                '|thu\\.?|thursday|fri\\.?|friday|sat\\.?|saturday))' + '(\\sago)?';
                match = str.match(new RegExp(regex, 'gi'));
                if (match === null) {
                    return false;
                }
                for (i = 0, l = match.length; i < l; i++) {
                    if (!process(match[i].split(' '))) {
                        return false;
                    }
                }
                return now.getTime() / 1000 | 0;
            };
            this.date = function (format, timestamp) {
                var that = this,
                    jsdate, f, formatChr = /\\?([a-z])/gi,
                    formatChrCb,
                    _pad = function (n, c) {
                        if ((n = n + '').length < c) {return new Array((++c) - n.length).join('0') + n;}
                        return n;
                    },
                    txt_words = ["Sun", "Mon", "Tues", "Wednes", "Thurs", "Fri", "Satur",
                                 "January", "February", "March", "April", "May", "June",
                                 "July", "August", "September", "October", "November", "December"];
                formatChrCb = function (t, s) {return f[t] ? f[t]() : s;};
                f = {
                    d: function () {return _pad(f.j(), 2);},
                    D: function () {return f.l().slice(0, 3);},
                    j: function () {return jsdate.getDate();},
                    l: function () {return txt_words[f.w()] + 'day';},
                    N: function () {return f.w() || 7;},
                    S: function () {var j = f.j();return j > 4 || j < 21 ? 'th' :
                       {1: 'st', 2: 'nd', 3: 'rd'}[j % 10] || 'th';},
                    w: function () {return jsdate.getDay();},
                    z: function () {var a = new Date(f.Y(), f.n() - 1, f.j()),
                       b = new Date(f.Y(), 0, 1);return Math.round((a - b) / 864e5) + 1;},
                    W: function () {var a = new Date(f.Y(), f.n() - 1, f.j() - f.N() + 3),
                       b = new Date(a.getFullYear(), 0, 4); return _pad(1 + Math.round((a - b)
                       / 864e5 / 7), 2);},
                    F: function () {return txt_words[6 + f.n()];},
                    m: function () {return _pad(f.n(), 2);},
                    M: function () {return f.F().slice(0, 3);},
                    n: function () {return jsdate.getMonth() + 1;},
                    t: function () {return (new Date(f.Y(), f.n(), 0)).getDate();},
                    L: function () {return new Date(f.Y(), 1, 29).getMonth() === 1 | 0;},
                    o: function () {var n = f.n(),W = f.W(),Y = f.Y();return Y +
                                    (n === 12 && W < 9 ? -1 : n === 1 && W > 9);},
                    Y: function () {return jsdate.getFullYear();},
                    y: function () {return (f.Y() + "").slice(-2);},
                    a: function () {return jsdate.getHours() > 11 ? "pm" : "am";},
                    A: function () {return f.a().toUpperCase();},
                    B: function () {var H = jsdate.getUTCHours() * 36e2,i = jsdate.getUTCMinutes() * 60,
                    s = jsdate.getUTCSeconds();return _pad(Math.floor((H + i + s + 36e2) / 86.4) % 1e3, 3);},
                    g: function () {return f.G() % 12 || 12;},
                    G: function () {return jsdate.getHours();},
                    h: function () {return _pad(f.g(), 2);},
                    H: function () {return _pad(f.G(), 2);},
                    i: function () {return _pad(jsdate.getMinutes(), 2);},
                    s: function () {return _pad(jsdate.getSeconds(), 2);},
                    u: function () {return _pad(jsdate.getMilliseconds() * 1000, 6);},
                    e: function () {throw 'Not supported (see source code of date() ' +
                                          'for timezone on how to add support)';},
                    I: function () {var a = new Date(f.Y(), 0),c = Date.UTC(f.Y(), 0),b = new Date(f.Y(), 6),
                    d = Date.UTC(f.Y(), 6);return 0 + ((a - c) !== (b - d));},
                    O: function () {var a = jsdate.getTimezoneOffset();return (a > 0 ? "-" : "+") +
                                    _pad(Math.abs(a / 60 * 100), 4);},
                    P: function () {var O = f.O();return (O.substr(0, 3) + ":" + O.substr(3, 2));},
                    T: function () {return 'GMT';},
                    Z: function () {return -jsdate.getTimezoneOffset() * 60;},
                    c: function () {return 'Y-m-d\\Th:i:sP'.replace(formatChr, formatChrCb);},
                    r: function () {return 'D, d M Y H:i:s O'.replace(formatChr, formatChrCb);},
                    U: function () {return jsdate.getTime() / 1000 | 0;}
                };
                this.date = function (format, timestamp) {
                    that = this;
                    jsdate = ((typeof timestamp === 'undefined')?new Date():
                    (timestamp instanceof Date)?new Date(timestamp):new Date(timestamp * 1000));
                    return format.replace(formatChr, formatChrCb);
                };
                return this.date(format, timestamp);
            };
            this.Event = this.event = function (o, t, f) {
                root.Et = o.attachEvent ?
                    o.attachEvent("on" + (t.replace(/^on/i, "")), function () { f(o); }) :
                    o.addEventListener(t.replace(/^on/i, ""), function () { f(o); }, false);
            };
            this.getDatesBetween = function (f, t) {
                var v, i, c, a = [], n = 0;
                if (f) { f = this.strtotime(String(f).split('-').reverse().join('-')); }
                if (t) { t = this.strtotime(String(t).split('-').reverse().join('-')); }
                if (f && t) {
                    if (f > t) {
                        v = f;
                        f = t;
                        t = v;
                    }
                    for (i = f; i <= t; i += (60 * 60 * 24)) {
                        c = this.date("d-m-Y", i);
                        a[n] = c;
                        n = n + 1;
                    }
                    return (a);
                }
            };
            this.actionCalendar = function (type, o) {
                var i, t = root.document.getElementsByTagName('input');
                o = o ? name.substr(1) + '-' + o : name.substr(1);
                for (i in t) {
                    if (typeof t[i] === 'object' && t[i].type === 'text' &&
                         (that.Options.Type === '.' ?
                         (that.find(t[i].className, o)) :
                         (that.find(t[i].id, o)))) {
                        if (type === "add") {
                            t[i].disabled = "";
                        } else {
                            t[i].disabled = "disabled";
                        }
                    }
                }
            };
            this.readOnly = function () {
                this.Options.temp.readOnly = true;
                return (this);
            };
            this.addClear = function () {
                this.Options.addClear = true;
                this.Options.temp.addClear = true;
                return (this);
            };
            this.addImage = function () {
                var image = root.document.createElement("a"),
                    j, id, reg,
                    t = root.document.getElementsByTagName('input');
                for (j in t) {
                    if (typeof t[j] === 'object' && t[j].type === 'text' &&
                            this.find(this.Options.Type === '.' ?
                            t[j].className : t[j].id, this.Options.Name)) {
                        id = root.document.getElementById('Link_' + this.Options.Name + '_' + j);
                        if (this.find(this.Options.Type === '.' ?
                                t[j].className :
                                t[j].id, this.Options.Name) && t[j].value !== ""
                                && !id && that.Options.addClear) {
                            image.style.background = "url(" + this.Options.clearImage + ") no-repeat";
                            image.style.fontSize   = '8pt';
                            image.style.padding    = '0 0 0 12px';
                            image.style.margin     = '0 8px 0 -20px';
                            image.style.cursor     = 'pointer';
                            image.style.zIndex     = '1888';
                            image.style.position   = 'relative';
                            image.className        = 'CalendarClose';
                            image.id               = 'Link_' + this.Options.Name + '_' + j;
                            image.onclick          = function () {
                                this.previousSibling.value = '';
                                this.parentNode.removeChild(this);
                            };
                            t[j].parentNode.insertBefore(image, t[j].nextSibling);
                        }
                        t[j].style.cursor      = 'text';
                        t[j].style.position    = t[j].style.position || '';
                        t[j].style.padding     = t[j].style.padding || '';
                        t[j].style.fontSize    = t[j].style.fontSize || '';
                        t[j].style.width       = t[j].style.width || '';
                        t[j].style.margin      = t[j].style.margin || '';
                        t[j].style.border      = t[j].style.border || '';
                        t[j].style.background  = t[j].style.background || '';
                        t[j].style.zIndex      = '100';
                        t[j].style.color       = '#000000';
                        t[j].className         = (that.Options.Type === '.' ? that.Options.Name + ' ' : '') +
                                                 'input_' + this.Options.Name + '_' + j;
                        if (options && that.Options.temp.readOnly) { t[j].readOnly = 'readonly'; }
                    }
                }
            };
            this.setBaseDate = function (o, i) {
                var b, e = ['+', '-', '*', '/'], date, arr, call, g, i, z = [], k = {keys: [], pos: []}, j = 0,
                    format = function (s) { if (+s < 10) { s = '0' + s; } return (s); }, ccall,
                    reformat = function (arr) {
                        if ((arr = arr.match(/(\d\d)-(\d\d)-(\d\d\d\d)/)) !== undefined) {
                            if (arr && (arr[1] && arr[2] && arr[3])) { arr = [arr[3], arr[2], arr[1]]; }
                        }
                        return (arr);
                    },
                    newDate = function (t) {
                        var c, w, v, date = new Date(),
                            ref = (format(date.getDate()) + '-' + format(date.getMonth()
                                   + 1) + '-' + date.getFullYear());
                        
                        t = t.toUpperCase().replace(/\s/g, '').replace(/\$/, '');
                        if (t.toLowerCase() === 'now') { t = t + '+0'; }
                        if ((w = t.match(/((\d\d-\d\d-\d\d\d\d|NOW)(\-|\+|\/|\*))?([0-9-+*\/\(\)]+)/i)) !== undefined) {
                            c = [w[2] || '',(w[3] || '') + w[4]];
                            if (c[0] === '' || c[0].toLowerCase() === 'now') { c[0] = ref; }
                            c = c.join('$');
                            v = c.substr(c.indexOf('$') + 1, c.substr(c.indexOf('$') +
                                1).length).replace(/[\[\]]/g, '');
                            if (v.substr(0, 1) === '*') { v = (+(c[0] + c[1])) + v; }
                            t = [c.substr(0, c.indexOf('$')), v];
                        }
                        if (typeof t === 'string') {
                            t = [(t.toLowerCase().substr(1, t.length - 2) !== 'now' ?
                                    (t.match(/[0-9-\/]/i) ? format(t) : ref) : ref), ''];
                        }
                        date = reformat(t[0]);
                        date = new Date(date[0], date[1] - 1, date[2]);
                        t[0] = (format(date.getDate()) + '-' + format(date.getMonth() + 1) + '-' + date.getFullYear());
                        return (t);
                    };
                arr = newDate(o || 'now');
                call = arr[0]; arr[0] = reformat(arr[0]);
                date = (new Date(arr[0][0], call.toLowerCase() === 'now' ? arr[0][1] : arr[0][1] - 1, arr[0][2]));
                if (o && arr[1] !== '') {
                    date.setDate(date.getDate() + (new Function("return " + arr[1])()));
                }
                call = ((format(date.getDate()) + '-' + format(date.getMonth() + 1) + '-' + date.getFullYear()));
                if (i && (g = this.Options.setCur[this.Options.Name][i]) !== undefined) {
                    this.Options.setCur[this.Options.Name][i] = call;
                } else if (!i && (g = this.Options.setCurGlobal) !== undefined) {
                   this.Options.setCurGlobal = call;
                }
                this.Options.temp.setBaseDate = o;
                ccall = call.split('-');
                this.Options.Storage.baseDate = this.date(ccall[2] + '-' + ccall[1] + '-' + ccall[0]);
                return (this);
            };
            this.pop = function (pop, params, type, instant) {
                var i;
                if (instant && pop instanceof Array) { params = pop; pop = this.Options.Name; }
                if (pop instanceof Object) {
                    for (i in pop) {
                        if (typeof pop[i] === 'object') {
                            this.pop(i, pop[i], type, instant);
                        }
                    }
                } else if (typeof pop === 'string' && (!instant || instant && params)) {
                    params = (type === 'range' && typeof params[0] !== 'object') ? [params] : params;
                    if (pop && params) {
                        if (!this.Options.Store[this.Options.Name][pop]) {
                            this.addSubCalendar(pop);
                        }
                        if (!this.Options.Store[this.Options.Name][pop][type]) {
                            this.Options.Store[this.Options.Name][pop][type] = params;
                        } else {
                            this.Options.Store[this.Options.Name][pop][type] = 
                            this.Options.Store[this.Options.Name][pop][type].concat(params);
                        }
                    }
                }
                return (this);
            };
            this.addFranchise = function (pop, params) { return (this.pop(pop, params, 'franchise', true)); };
            this.disableDates = function (pop, params) { return (this.pop(pop, params, 'disableDates', true)); };
            this.disableRange = function (pop, params) { return (this.pop(pop, params, 'disableRange', true)); };
            this.disableDays = function (pop, params) { return (this.pop(pop, params, 'disableDays', true)); };
            this.addSubCalendar = function (key) {
                var i;
                if (key instanceof Array) {
                    for (i in key) {
                        if (key[i] !== undefined) {
                            this.addSubCalendar(key[i]);
                        }
                    }
                } else if (typeof key === 'string') {
                    if (typeof key === 'string' && !this.Options.Store[this.Options.Name][key]) {
                        this.Options.Store[this.Options.Name][key] = {};
                    }
                }
                return (this);
            };
            this.find = function (string, elem, offset) {
                var i, t = (offset && offset > -1 ? string.substr(offset) : string).split(' '), r = false;
                string += '';
                for (i = 0; i < t.length;) {
                    if (t[i] && t[i] === elem) {
                        r = true;
                    }
                    i = i + 1;
                }
                if (!r) { r = (string.indexOf(elem, (offset || 0)) > -1) ? true : r; }
                return (r);
            };
            this.dhtmlXCalendarObject = function (inps, skin, that, Options, inputInc, funcObj) {
                var element = inps;
                this.i = {};
                this.uid = function() {
                    if (!this.uidd) this.uidd = new Date().getTime();
                    return this.uidd++;
                }
                var p = null;
                if (typeof(inps) == "string") {

                    var t0 = document.getElementById(inps);
                } else {
                    var t0 = inps;
                }
                if (t0 && typeof(t0) == "object" && t0.tagName && String(t0.tagName).toLowerCase() != "input") p = t0;
                t0 = null;
                if (typeof(inps) != "object" || !inps.length) inps = [inps];
                for (var q=0; q<inps.length; q++) {
                    if (typeof(inps[q]) == "string") inps[q] = (document.getElementById(inps[q])||null);
                    if (inps[q] != null && inps[q].tagName && String(inps[q].tagName).toLowerCase() == "input") {
                        this.i[this.uid()] = inps[q];
                    }
                    inps[q] = null;
                }
                this.addImage = function () {
                    var image = root.document.createElement("a"),
                        j, id,
                        i = 0,
                        t = root.document.getElementsByTagName('input');
                    for (j in t) {
                        if (typeof t[j] === 'object' && t[j].type === 'text' &&
                                that.find(Options.Type === '.' ? t[j].className : t[j].id, Options.Name)) {
                            id = root.document.getElementById('Link_' + Options.Name + '_' + j);
                            if (that.find(Options.Type === '.' ?
                                    t[j].className :
                                    t[j].id, Options.Name) && t[j].value !== "" && !id && Options.addClear) {
                                image.style.background = "url(" + Options.clearImage + ") no-repeat";
                                image.style.fontSize   = '8pt';
                                image.style.padding    = '0 0 0 12px';
                                image.style.margin     = '0 8px 0 -20px';
                                image.style.cursor     = 'pointer';
                                image.style.zIndex     = '1888';
                                image.style.position   = 'relative';
                                image.className        = 'CalendarClose';
                                image.id               = 'Link_' + Options.Name + '_' + j;
                                image.onclick          = function () {
                                    this.previousSibling.value = '';
                                    this.parentNode.removeChild(this);
                                };
                                t[j].parentNode.insertBefore(image, t[j].nextSibling);
                            }
                        }
                    }
                };
                this.find = function (string, elem, offset) {
                    var i, t = (offset && offset > -1 ? string.substr(offset) : string).split(' '), r = false;
                    string += '';
                    for (i = 0; i < t.length;) {
                        if (t[i] && t[i] === elem) {
                            r = true;
                        }
                        i = i + 1;
                    }
                    if (!r) { r = (string.indexOf(elem, (offset || 0)) > -1) ? true : r; }
                    return (r);
                };
                var base = this;
                this.skin = skin||"dhx_skyblue";
                this.setSkin = function(skin){
                    this.skin = skin;
                    this.base.className = "dhtmlxcalendar_container dhtmlxcalendar_skin_" + this.skin + " " +
                                          Options.Name + "-calendar";
                }
                this.base = document.createElement("DIV");
                this.base.className = "dhtmlxcalendar_container";
                this.base.style.display = "none";
                if (p != null) {
                    this._hasParent = true;
                    p.appendChild(this.base);
                    p = null;
                } else { 
                    document.body.appendChild(this.base);
                }
                this.setParent = function(p) {
                    if (this._hasParent) {
                        if (typeof(p) == "object") {
                            p.appendChild(this.base);
                        } else if (typeof(p) == "string") {
                            document.getElementById(p).appendChild(this.base);
                        }
                    }
                }
                this.setSkin(this.skin);
                this.base.onclick = function(e) {
                    e = e||event;
                    e.cancelBubble = true;
                    base.addImage(element);
                }
                this.loadUserLanguage = function(lang) {
                    if (!this.langData[lang]) return;
                    this.lang = lang;
                    this.setWeekStartDay(this.langData[this.lang].weekstart);
                    if (this.msCont) {
                        var e = 0;
                        for (var q=0; q<this.msCont.childNodes.length; q++) {
                            for (var w=0; w<this.msCont.childNodes[q].childNodes.length; w++) {
                                this.msCont.childNodes[q].childNodes[w].innerHTML =
                                this.langData[this.lang].monthesSNames[e++];
                            }
                        }
                    }
                }
                this.contMonth = document.createElement("DIV");
                this.contMonth.className = "dhtmlxcalendar_month_cont";
                this.contMonth.onselectstart = function(e){e=e||event;e.cancelBubble=true;
                                                           e.returnValue=false;return false;}
                this.base.appendChild(this.contMonth);
                var ul = document.createElement("UL");
                ul.className = "dhtmlxcalendar_line";
                this.contMonth.appendChild(ul);
                var li = document.createElement("LI");

                li.className = "dhtmlxcalendar_cell dhtmlxcalendar_month_hdr";
                li.innerHTML = "<div class='dhtmlxcalendar_month_arrow dhtmlxcalendar_month_arrow_left' " +
                               "onmouseover='this.className=\"dhtmlxcalendar_month_arrow dhtmlxcalendar_" +
                               "month_arrow_left_hover\";' onmouseout='this.className=\"dhtmlxcalendar_m" +
                               "onth_arrow dhtmlxcalendar_month_arrow_left\";'></div><span class='dhtmlx" +
                               "calendar_month_label_month'>Month</span><span class='dhtmlxcalendar_mont" +
                               "h_label_year'>Year</span><div class='dhtmlxcalendar_month_arrow dhtmlxca" +
                               "lendar_month_arrow_right' onmouseover='this.className=\"dhtmlxcalendar_m" +
                               "onth_arrow dhtmlxcalendar_month_arrow_right_hover\";' onmouseout='this.c" +
                               "lassName=\"dhtmlxcalendar_month_arrow dhtmlxcalendar_month_arrow_right\"" +
                               ";'></div>";
                ul.appendChild(li);
                var that = this;
                li.onclick = function(e) {
                    e = e||event;
                    var t = (e.target||e.srcElement);
                    if (t.className && t.className.indexOf("dhtmlxcalendar_month_arrow") === 0) {
                        that._hideSelector();
                        var ind = (t.parentNode.firstChild==t?-1:1);
                        that._drawMonth(new Date(that._activeMonth.getFullYear(),
                               that._activeMonth.getMonth()+ind, 1, 0, 0, 0, 0));
                        return;
                    }
                    if (t.className && t.className == "dhtmlxcalendar_month_label_month") {
                        e.cancelBubble = true;
                        that._showSelector("month",31,21,"selector_month",true);
                        return;
                    }
                    if (t.className && t.className == "dhtmlxcalendar_month_label_year") {
                        e.cancelBubble = true;
                        that._showSelector("year",42,21,"selector_year",true);
                        return;
                    }
                    that._hideSelector();
                }
                this.contDays = document.createElement("DIV");
                this.contDays.className = "dhtmlxcalendar_days_cont";
                this.base.appendChild(this.contDays);

                this.setWeekStartDay = function(ind) {
                    if (ind == 0) ind = 7;
                    this._wStart = Math.min(Math.max((isNaN(ind)?1:ind),1),7);
                    this._drawDaysOfWeek();
                }
                this._drawDaysOfWeek = function() {
                    if (this.contDays.childNodes.length == 0) {
                        var ul = document.createElement("UL");
                        ul.className = "dhtmlxcalendar_line";
                        this.contDays.appendChild(ul);
                    } else {
                        var ul = this.contDays.firstChild;
                    }
                    var w = this._wStart;
                    var k = this.langData[this.lang].daysSNames;
                    k.push(String(this.langData[this.lang].daysSNames[0]).valueOf());
                    for (var q=0; q<7; q++) {
                        if (ul.childNodes[q] == null) {
                            var li = document.createElement("LI");
                            ul.appendChild(li);
                        } else {
                            var li = ul.childNodes[q];
                        }
                        li.className = "dhtmlxcalendar_cell"+(w>=6?
                        " dhtmlxcalendar_day_weekday_cell":"")+(q==0?"_first":"");
                        li.innerHTML = k[w];
                        if (++w > 7) w = 1;


                    }
                    if (this._activeMonth != null) this._drawMonth(this._activeMonth);
                }
                this._wStart = this.langData[this.lang].weekstart;
                this.setWeekStartDay(this._wStart);
                this.contDates = document.createElement("DIV");
                this.contDates.className = "dhtmlxcalendar_dates_cont";
                this.base.appendChild(this.contDates);
                this.contDates.onclick = function(e){
                    e = e||event;
                    var t = (e.target||e.srcElement);
                    if (t._date != null && !t._css_dis) {
                        var t1 = that._activeDate.getHours();
                        var t2 = that._activeDate.getMinutes();
                        if (that.checkEvent("onBeforeChange")) {
                            if (!that.callEvent("onBeforeChange",[new Date(t._date.getFullYear(),
                                 t._date.getMonth(),t._date.getDate(),t1,t2)])) return;
                        }
                        if (that._activeDateCell != null) {
                            that._activeDateCell._css_date = false;
                            that._updateCellStyle(that._activeDateCell._q, that._activeDateCell._w);
                        }
                        var refreshView = (that._hasParent && that._activeDate.getFullYear()+"_"+
                        that._activeDate.getMonth() != t._date.getFullYear()+"_"+t._date.getMonth());
                        that._activeDate = new Date(t._date.getFullYear(),
                                           t._date.getMonth(),t._date.getDate(),t1,t2);
                        that._activeDateCell = t;
                        that._activeDateCell._css_date = true;
                        that._activeDateCell._css_hover = false;
                        that._lastHover = null;
                        that._updateCellStyle(that._activeDateCell._q, that._activeDateCell._w);
                        if (refreshView) that._drawMonth(that._activeDate);
                        if (that._activeInp && that.i[that._activeInp]) {
                            that.i[that._activeInp].value = that._dateToStr(new Date(that._activeDate.getTime()));
                        }
                        if (!that._hasParent) that._hide();
                        that.callEvent("onClick",[new Date(that._activeDate.getTime())]);
                    }
                }
                this.contDates.onmouseover = function(e) {
                    e = e||event;
                    var t = (e.target||e.srcElement);
                    if (t._date != null) {
                        t._css_hover = true;
                        that._updateCellStyle(t._q, t._w);
                        that._lastHover = t;
                    }
                }
                this.contDates.onmouseout = function() {
                    that._clearDayHover();
                }
                this._lastHover = null;
                this._clearDayHover = function() {
                    if (!this._lastHover) return;
                    this._lastHover._css_hover = false;
                    this._updateCellStyle(this._lastHover._q, this._lastHover._w);
                    this._lastHover = null;
                }
                for (var q=0; q<6; q++) {
                    var ul = document.createElement("UL");
                    ul.className = "dhtmlxcalendar_line";
                    this.contDates.appendChild(ul);
                    for (var w=0; w<7; w++) {
                        var li = document.createElement("LI");
                        li.className = "dhtmlxcalendar_cell";
                        ul.appendChild(li);
                    }
                }
                this.contTime = document.createElement("DIV");
                this.contTime.className = "dhtmlxcalendar_time_cont";
                this.base.appendChild(this.contTime);
                this.showTime = function() {
                    if (String(this.base.className).search("dhtmlxcalendar_time_hidden") > 0) {
                        this.base.className = String(this.base.className) .
                                              replace(/dhtmlxcalendar_time_hidden/gi, "");
                    }
                }
                this.hideTime = function() {
                    if (String(this.base.className).search("dhtmlxcalendar_time_hidden") < 0) {
                        this.base.className += " dhtmlxcalendar_time_hidden";
                    }
                }
                var ul = document.createElement("UL");
                ul.className = "dhtmlxcalendar_line";
                this.contTime.appendChild(ul);
                var li = document.createElement("LI");
                li.className = "dhtmlxcalendar_cell dhtmlxcalendar_time_hdr";
                li.innerHTML = "<div class='dhtmlxcalendar_time_label'></div>" +
                               "<span class='dhtmlxcalendar_label_hours'></span>" +
                               "<span class='dhtmlxcalendar_label_colon'>:</span>" +
                               "<span class='dhtmlxcalendar_label_minutes'></span>";
                ul.appendChild(li);
                li.onclick = function(e) {
                    e = e||event;
                    var t = (e.target||e.srcElement);
                    if (t.className && t.className == "dhtmlxcalendar_label_hours") {
                        e.cancelBubble = true;
                        that._showSelector("hours",3,115,"selector_hours",true);
                        return;
                    }
                    if (t.className && t.className == "dhtmlxcalendar_label_minutes") {
                        e.cancelBubble = true;
                        that._showSelector("minutes",59,115,"selector_minutes",true);
                        return;
                    }
                    that._hideSelector();
                }
                this._activeMonth = null;
                this._activeDate = new Date();
                this._activeDateCell = null;
                this.setDate = function(d) {
                    if (d === "") d = new Date();
                    if (!(d instanceof Date)) d = this._strToDate(d,false);
                    var time = d.getTime();
                    if (this._isOutOfRange(time)) return;
                    this._activeDate = new Date(time);
                    this._drawMonth(this._activeDate);
                    this._updateVisibleHours();
                    this._updateVisibleMinutes();
                }
                this.getDate = function(formated) {
                    var t = new Date(this._activeDate.getTime());
                    if (formated) return this._dateToStr(t);
                    return t;
                }
                this._drawMonth = function(d) {
                    if (!(d instanceof Date)) return;
                    if (isNaN(d.getFullYear())) d = new Date(this._activeMonth.getFullYear(),
                                                    this._activeMonth.getMonth(), 1, 0, 0, 0, 0);
                    this._activeMonth = new Date(d.getFullYear(), d.getMonth(), 1, 0, 0, 0, 0);
                    this._activeDateCell = null;
                    var first = new Date(this._activeMonth.getTime());
                    var d0 = first.getDay();
                    var e0 = d0-this._wStart;
                    if (e0 < 0) e0 = e0+7;
                    first.setDate(first.getDate()-e0);
                    var mx = d.getMonth();
                    var dx = new Date(this._activeDate.getFullYear(), this._activeDate.getMonth(),
                                      this._activeDate.getDate(), 0, 0, 0, 0).getTime();
                    var i = 0;
                    for (var q=0; q<6; q++) {
                        var ws = this._wStart;
                        for (var w=0; w<7; w++) {
                            var d2 = new Date(first.getFullYear(), first.getMonth(),
                                              first.getDate()+i++, 0, 0, 0, 0);
                            this.contDates.childNodes[q].childNodes[w].innerHTML = d2.getDate();
                            var day = d2.getDay();
                            var time = d2.getTime();
                            this.contDates.childNodes[q].childNodes[w]._date = new Date(time);
                            this.contDates.childNodes[q].childNodes[w]._q = q;
                            this.contDates.childNodes[q].childNodes[w]._w = w;
                            this.contDates.childNodes[q].childNodes[w]._css_month = (d2.getMonth()==mx);
                            this.contDates.childNodes[q].childNodes[w]._css_date = (time==dx);
                            this.contDates.childNodes[q].childNodes[w]._css_weekend = (ws>=6);
                            this.contDates.childNodes[q].childNodes[w]._css_dis = this._isOutOfRange(time);
                            this.contDates.childNodes[q].childNodes[w]._css_holiday = (this._holidays[time] == true);
                            this._updateCellStyle(q, w);
                            if (time==dx) this._activeDateCell = this.contDates.childNodes[q].childNodes[w];
                            if (++ws > 7) ws = 1;
                        }
                    }
                    this.contMonth.firstChild.firstChild.childNodes[1].innerHTML =
                    this.langData[this.lang].monthesFNames[d.getMonth()];
                    this.contMonth.firstChild.firstChild.childNodes[2].innerHTML = d.getFullYear();
                }
                this._updateCellStyle = function(q, w) {
                    var r = this.contDates.childNodes[q].childNodes[w],
                        s = "dhtmlxcalendar_cell dhtmlxcalendar_cell";
                    s += (r._css_month ? "_month" : "");
                    s += (r._css_date ? "_date" : "");
                    s += (r._css_weekend ? "_weekend" : "");
                    s += (r._css_holiday ? "_holiday" : "");
                    s += (r._css_dis ? "_dis" : "");
                    s += (r._css_hover && !r._css_dis ? "_hover" : "");
                    r.className = s;
                    r = null;
                }
                this._initSelector = function(type,css) {
                    if (!this._selCover) {
                        this._selCover = document.createElement("DIV");
                        this._selCover.className = "dhtmlxcalendar_selector_cover";
                        this.base.appendChild(this._selCover);
                    }
                    if (!this._sel) {
                        this._sel = document.createElement("DIV");
                        this._sel.className = "dhtmlxcalendar_selector_obj";
                        this.base.appendChild(this._sel);
                        this._sel.appendChild(document.createElement("TABLE"));
                        this._sel.firstChild.className = "dhtmlxcalendar_selector_table";
                        this._sel.firstChild.cellSpacing = 0;
                        this._sel.firstChild.cellPadding = 0;
                        this._sel.firstChild.border = 0;
                        this._sel.firstChild.appendChild(document.createElement("TBODY"));
                        this._sel.firstChild.firstChild.appendChild(document.createElement("TR"));
                        this._sel.firstChild.firstChild.firstChild.appendChild(document.createElement("TD"));
                        this._sel.firstChild.firstChild.firstChild.appendChild(document.createElement("TD"));
                        this._sel.firstChild.firstChild.firstChild.appendChild(document.createElement("TD"));
                        this._sel.firstChild.firstChild.firstChild.childNodes[0].className =
                            "dhtmlxcalendar_selector_cell_left";
                        this._sel.firstChild.firstChild.firstChild.childNodes[1].className =
                            "dhtmlxcalendar_selector_cell_middle";
                        this._sel.firstChild.firstChild.firstChild.childNodes[2].className =
                            "dhtmlxcalendar_selector_cell_right";
                        this._sel.firstChild.firstChild.firstChild.childNodes[0].innerHTML = "&nbsp;";
                        this._sel.firstChild.firstChild.firstChild.childNodes[2].innerHTML = "&nbsp;";
                        this._sel.firstChild.firstChild.firstChild.childNodes[0].onmouseover = function(){
                            this.className = "dhtmlxcalendar_selector_cell_left " +
                                             "dhtmlxcalendar_selector_cell_left_hover";
                        }
                        this._sel.firstChild.firstChild.firstChild.childNodes[0].onmouseout = function(){
                            this.className = "dhtmlxcalendar_selector_cell_left";
                        }
                        this._sel.firstChild.firstChild.firstChild.childNodes[2].onmouseover = function(){
                            this.className = "dhtmlxcalendar_selector_cell_right " +
                                             "dhtmlxcalendar_selector_cell_right_hover";
                        }
                        this._sel.firstChild.firstChild.firstChild.childNodes[2].onmouseout = function(){
                            this.className = "dhtmlxcalendar_selector_cell_right";
                        }
                        this._sel.firstChild.firstChild.firstChild.childNodes[0].onclick = function(e){
                            e = e||event;
                            e.cancelBubble = true;
                            that._scrollYears(-1);
                        }
                        this._sel.firstChild.firstChild.firstChild.childNodes[2].onclick = function(e){
                            e = e||event;
                            e.cancelBubble = true;
                            that._scrollYears(1);
                        }
                        this._sel._ta = {};
                        this._selHover = null;
                        this._sel.onmouseover = function(e) {
                            e = e||event;
                            var t = (e.target||e.srcElement);
                            if (t._cell === true) {
                                if (that._selHover != t) that._clearSelHover();
                                var ndt = /^\s{0,}dhtmlxcalendar_selector_cell\s{0,}$/gi;
                                if (String(t.className).match(ndt) !=null) {
                                    t.className += " dhtmlxcalendar_selector_cell_hover";
                                    that._selHover = t;
                                }
                            }
                        }
                        this._sel.onmouseout = function() {
                            that._clearSelHover();
                        }
                        this._sel.appendChild(document.createElement("DIV"));
                        this._sel.lastChild.className = "dhtmlxcalendar_selector_obj_arrow";
                    }
                    if (this._sel._ta[type] == true) return;
                    if (type == "month") {
                        this._msCells = {};
                        this.msCont = document.createElement("DIV");

                        this.msCont.className = "dhtmlxcalendar_area_"+css;
                        this._sel.firstChild.firstChild.firstChild.childNodes[1].appendChild(this.msCont);
                        var i = 0;
                        for (var q=0; q<4; q++) {
                            var ul = document.createElement("UL");
                            ul.className = "dhtmlxcalendar_selector_line";
                            this.msCont.appendChild(ul);
                            for (var w=0; w<3; w++) {
                                var li = document.createElement("LI");
                                li.innerHTML = this.langData[this.lang].monthesSNames[i];
                                li.className = "dhtmlxcalendar_selector_cell";
                                ul.appendChild(li);
                                li._month = i;
                                li._cell = true;
                                this._msCells[i++] = li;
                            }
                        }
                        this.msCont.onclick = function(e) {
                            e = e||event;
                            e.cancelBubble = true;
                            var t = (e.target||e.srcElement);
                            if (t._month != null) {
                                that._hideSelector();
                                that._updateActiveMonth();
                                that._drawMonth(new Date(that._activeMonth.getFullYear(),
                                                         t._month, 1, 0, 0, 0, 0));
                                that._doOnSelectorChange();
                            }
                        }
                    }
                    if (type == "year") {
                        this._ysCells = {};
                        this.ysCont = document.createElement("DIV");
                        this.ysCont.className = "dhtmlxcalendar_area_"+css;
                        this._sel.firstChild.firstChild.firstChild.childNodes[1].appendChild(this.ysCont);
                        for (var q=0; q<4; q++) {
                            var ul = document.createElement("UL");
                            ul.className = "dhtmlxcalendar_selector_line";
                            this.ysCont.appendChild(ul);
                            for (var w=0; w<3; w++) {
                                var li = document.createElement("LI");
                                li.className = "dhtmlxcalendar_selector_cell";
                                li._cell = true;
                                ul.appendChild(li);
                            }
                        }
                        this.ysCont.onclick = function(e) {
                            e = e||event;
                            e.cancelBubble = true;
                            var t = (e.target||e.srcElement);
                            if (t._year != null) {
                                that._hideSelector();
                                that._drawMonth(new Date(t._year, that._activeMonth.getMonth(), 1, 0, 0, 0, 0));
                                that._doOnSelectorChange();
                            }
                        }
                    }
                    if (type == "hours") {
                        this._hsCells = {};
                        this.hsCont = document.createElement("DIV");
                        this.hsCont.className = "dhtmlxcalendar_area_"+css;
                        this._sel.firstChild.firstChild.firstChild.childNodes[1].appendChild(this.hsCont);
                        var i = 0;
                        for (var q=0; q<4; q++) {
                            var ul = document.createElement("UL");
                            ul.className = "dhtmlxcalendar_selector_line";
                            this.hsCont.appendChild(ul);
                            for (var w=0; w<6; w++) {
                                var li = document.createElement("LI");
                                li.innerHTML = this._fixLength(i,2);
                                li.className = "dhtmlxcalendar_selector_cell";
                                ul.appendChild(li);
                                li._hours = i;
                                li._cell = true;
                                this._hsCells[i++] = li;
                            }
                        }
                        this.hsCont.onclick = function(e) {
                            e = e||event;
                            e.cancelBubble = true;
                            var t = (e.target||e.srcElement);
                            if (t._hours != null) {
                                that._hideSelector();
                                that._activeDate.setHours(t._hours);
                                that._updateActiveHours();
                                that._updateVisibleHours();
                                that._doOnSelectorChange();
                            }
                        }
                    }
                    if (type == "minutes") {
                        this._rsCells = {};
                        this.rsCont = document.createElement("DIV");
                        this.rsCont.className = "dhtmlxcalendar_area_"+css;
                        this._sel.firstChild.firstChild.firstChild.childNodes[1].appendChild(this.rsCont);
                        var i = 0;
                        for (var q=0; q<4; q++) {
                            var ul = document.createElement("UL");
                            ul.className = "dhtmlxcalendar_selector_line";
                            this.rsCont.appendChild(ul);
                            for (var w=0; w<3; w++) {
                                var li = document.createElement("LI");
                                li.innerHTML = this._fixLength(i,2);
                                li.className = "dhtmlxcalendar_selector_cell";
                                ul.appendChild(li);
                                li._minutes = i;
                                li._cell = true;
                                this._rsCells[i] = li;
                                i+=5;
                            }
                        }
                        this.rsCont.onclick = function(e) {
                            e = e||event;
                            e.cancelBubble = true;
                            var t = (e.target||e.srcElement);
                            if (t._minutes != null) {
                                that._hideSelector();
                                that._activeDate.setMinutes(t._minutes);
                                that._updateActiveMinutes();
                                that._updateVisibleMinutes();
                                that._doOnSelectorChange();
                            }
                        }
                    }
                    this._sel._ta[type] = true;
                }
                this._showSelector = function(type,x,y,css,autoHide) {
                    if (autoHide === true && this._sel != null && this._isSelectorVisible()
                        && type == this._sel._t) {
                        this._hideSelector();
                        return;
                    }
                    if (!this._sel || !this._sel._ta[type]) this._initSelector(type,css);
                    this._selCover.style.display = "";
                    this._sel._t = type;
                    this._sel.style.left = x+"px";
                    this._sel.style.top = y+"px";
                    this._sel.style.display = "";
                    this._sel.className = "dhtmlxcalendar_selector_obj dhtmlxcalendar_"+css;
                    this._doOnSelectorShow(type);
                }
                this._doOnSelectorShow = function(type) {
                    if (type == "month") this._updateActiveMonth();
                    if (type == "year") this._updateYearsList(this._activeMonth);
                    if (type == "hours") this._updateActiveHours();
                    if (type == "minutes") this._updateActiveMinutes();
                }
                this._hideSelector = function() {
                    if (!this._sel) return;
                    this._sel.style.display = "none";
                    this._selCover.style.display = "none";
                }
                this._isSelectorVisible = function() {
                    if (!this._sel) return false;
                    return (this._sel.style.display != "none");
                }
                this._doOnSelectorChange = function(state) {
                    this.callEvent("onChange",[new Date(this._activeMonth.getFullYear(),
                    this._activeMonth.getMonth(), this._activeDate.getDate(),
                    this._activeDate.getHours(), this._activeDate.getMinutes(),
                    this._activeDate.getSeconds()),state]);
                }
                this._clearSelHover = function() {
                    if (!this._selHover) return;
                    this._selHover.className =
                    String(this._selHover.className.replace(/dhtmlxcalendar_selector_cell_hover/gi,""));
                    this._selHover = null;
                }
                this._updateActiveMonth = function() {
                    if (typeof(this._msActive) != "undefined" &&
                        typeof(this._msCells[this._msActive]) != "undefined")
                        this._msCells[this._msActive].className = "dhtmlxcalendar_selector_cell";
                    this._msActive = this._activeMonth.getMonth();
                    this._msCells[this._msActive].className =
                    "dhtmlxcalendar_selector_cell dhtmlxcalendar_selector_cell_active";
                }
                this._updateActiveYear = function() {
                    var i = this._activeMonth.getFullYear();
                    if (this._ysCells[i]) {
                        this._ysCells[i].className = "dhtmlxcalendar_selector_cell " +
                                                     "dhtmlxcalendar_selector_cell_active";
                    }
                }
                this._updateYearsList = function(d) {
                    for (var a in this._ysCells) {
                        this._ysCells[a] = null;
                        delete this._ysCells[a];
                    }
                    var i = 12*Math.floor(d.getFullYear()/12);
                    for (var q=0; q<4; q++) {
                        for (var w=0; w<3; w++) {
                            this.ysCont.childNodes[q].childNodes[w].innerHTML = i;
                            this.ysCont.childNodes[q].childNodes[w]._year = i;
                            this.ysCont.childNodes[q].childNodes[w].className =
                                "dhtmlxcalendar_selector_cell";
                            this._ysCells[i++] = this.ysCont.childNodes[q].childNodes[w];
                        }
                    }
                    this._updateActiveYear();
                }
                this._scrollYears = function(i) {
                    var y = (i<0?this.ysCont.firstChild.firstChild._year:
                                 this.ysCont.lastChild.lastChild._year)+i;
                    var d = new Date(y, this._activeMonth.getMonth(), 1, 0, 0, 0, 0);
                    this._updateYearsList(d);
                }
                this._updateActiveHours = function() {
                    if (typeof(this._hsActive) != "undefined" &&
                        typeof(this._hsCells[this._hsActive]) != "undefined")
                        this._hsCells[this._hsActive].className = "dhtmlxcalendar_selector_cell";
                    this._hsActive = this._activeDate.getHours();
                    this._hsCells[this._hsActive].className =
                        "dhtmlxcalendar_selector_cell dhtmlxcalendar_selector_cell_active";
                }
                this._updateVisibleHours = function() {
                    this.contTime.firstChild.firstChild.childNodes[1].innerHTML =
                    this._fixLength(this._activeDate.getHours(),2);
                }
                this._updateActiveMinutes = function() {
                    if (typeof(this._rsActive) != "undefined" &&
                        typeof(this._rsCells[this._rsActive]) != "undefined") {
                        this._rsCells[this._rsActive].className = "dhtmlxcalendar_selector_cell";
                    }
                    this._rsActive = this._activeDate.getMinutes();
                    if (typeof(this._rsCells[this._rsActive]) != "undefined") {
                        this._rsCells[this._rsActive].className =
                        "dhtmlxcalendar_selector_cell dhtmlxcalendar_selector_cell_active";
                    }
                }
                this._updateVisibleMinutes = function() {
                    this.contTime.firstChild.firstChild.childNodes[3].innerHTML =
                    this._fixLength(this._activeDate.getMinutes(),2);
                }
                this._fixLength = function(t, r) {
                    while (String(t).length < r) t = "0"+String(t);
                    return t;
                }
                this._dateFormat = "";
                this._dateFormatRE = null;
                this.setDateFormat = function(format) {
                    this._dateFormat = format;
                    this._dateFormatRE = new RegExp(String(this._dateFormat) .
                                         replace(/%[a-zA-Z]+/g, function (t) {
                        var t2 = t.replace(/%/,"");
                        switch (t2) {
                            case "m":
                            case "d":
                            case "H":
                            case "i":
                            case "s":
                                return "\\d{2}";
                            case "Y":
                                return "\\d{4}";
                        }
                        return t;
                    }));
                }
                this.setDateFormat("%d-%m-%Y");
                this._strToDate = function(val,getSet,format) {
                    var i = {Y:false, m:false, d:false, H:false, i:false, s:false};
                    var a = String(val).match(/[0-9]{1,}/g);
                    var b = (format||this._dateFormat).match(/%[a-zA-Z]/g);
                    if (!a) return "Invalid Date";
                    for (var q=0; q<b.length; q++) {
                        var r = b[q].replace(/%/g,"");
                        if (typeof(i[r]) != "undefined") i[r] = Number(a[q]);
                    }
                    if (getSet) return i;
                    for (var a in i) if (i[a] === false) i[a] = 0;
                    return new Date(i.Y,i.m-1,i.d,i.H,i.i,i.s,0);
                }
                this._dateToStr = function(val, format) {
                    if (val instanceof Date) {
                        var z = function(t) {
                            return (String(t).length==1?"0"+String(t):t);
                        }
                        var k = function(t) {
                            switch(t) {
                                case "%d": return z(val.getDate());
                                case "%j": return val.getDate();
                                case "%D": return that.langData[that.lang].daysSNames[val.getDay()];
                                case "%l": return that.langData[that.lang].daysFNames[val.getDay()];
                                case "%m": return z(val.getMonth()+1);
                                case "%n": return date.getMonth()+1;
                                case "%M": return that.langData[that.lang].monthesSNames[val.getMonth()];
                                case "%F": return that.langData[that.lang].monthesFNames[val.getMonth()];
                                case "%y": return z(val.getYear()%100);
                                case "%Y": return val.getFullYear();
                                case "%g": return (val.getHours()+11)%12+1;
                                case "%h": return z((val.getHours()+11)%12+1);
                                case "%G": return val.getHours();
                                case "%H": return z(val.getHours());
                                case "%i": return z(val.getMinutes());
                                case "%s": return z(val.getSeconds());
                                case "%a": return (val.getHours()>11?"pm":"am");
                                case "%A": return (val.getHours()>11?"PM":"AM");
                                case "%%": "%";
                                default: return t;
                            }
                        }
                        var t = String(format||this._dateFormat).replace(/%[a-zA-Z]/g, k);
                    }
                    return (t||String(val));
                }
                this._updateDateStr = function(str) {
                    if (str == "") {
                        this.setDate(new Date());
                        this.callEvent("onChange",[null,true]);
                        return;
                    } else {
                        if (!this._dateFormatRE || !str.match(this._dateFormatRE)) return;
                    }
                    var r = this._strToDate(str, true);
                    var newDate = new Date(this._activeMonth.getFullYear(), this._activeMonth.getMonth(),
                    this._activeDate.getDate(), this._activeDate.getHours(), this._activeDate.getMinutes(),
                    this._activeDate.getSeconds());
                    if (r.Y !== false && r.Y != newDate.getFullYear()) this._activeDate.setFullYear(r.Y);
                    if (r.m !== false) {r.m--; if (r.m != newDate.getMonth()) this._activeDate.setMonth(r.m); }
                    if (r.d !== false && r.d != newDate.getDate()) this._activeDate.setDate(r.d);
                    if (r.H !== false && r.H != newDate.getHours()) this._activeDate.setHours(r.H);
                    if (r.i !== false && r.i != newDate.getMinutes()) this._activeDate.setMinutes(r.i);
                    if (r.s !== false && r.s != newDate.getSeconds()) this._activeDate.setSeconds(r.s);
                    this._drawMonth(this._activeDate);
                    this._updateVisibleMinutes();
                    this._updateVisibleHours();
                    if (this._sel && this._isSelectorVisible()) this._doOnSelectorShow(this._sel._t);
                    this._doOnSelectorChange(true);
                }
                this.setFormatedDate = function(format, str, a, return_only) {
                    var date = this._strToDate(str, false, format);
                    if (return_only) return date;
                    this.setDate(date);
                }
                this.getFormatedDate = function(format, date) {


                    if (!(date && date instanceof Date)) date = new Date(this._activeDate);
                    return this._dateToStr(date, format);
                }
                this.show = function(id) {
                    if (!id && this._hasParent) {
                        this._show();
                        return;
                    }
                    if (typeof(id) == "object" && typeof(id._dhtmlxcalendar_uid) != "undefined"
                        && this.i[id._dhtmlxcalendar_uid] == id) {
                        this._show(id._dhtmlxcalendar_uid);
                        return;
                    }
                    if (typeof(id) == "undefined") { for (var a in this.i) if (!id) id = a; }
                    if (!id) return;
                    this._show(id);
                }
                this.hide = function() {
                    if (this._isVisible()) this._hide();
                }
                this.isVisible = function() {
                    return this._isVisible();
                }
                this.draw = function() {
                    this.show();
                }
                this.close = function() {
                    this.hide();
                }
                this._activeInp = null;
                this.pos = "bottom";
                this.setPosition = function(x, y) {
                    if (x == "right" || x == "bottom") {
                        this.pos = x;
                        return;
                    }
                    if (!this._hasParent) {
                        if (typeof(x) != "undefined" && !isNaN(x)) this.base.style.left = x+"px";
                        if (typeof(y) != "undefined" && !isNaN(y)) this.base.style.top = y+"px";
                    }
                }
                this._show = function(inpId, autoHide) {
                    if (autoHide === true && this._activeInp == inpId && this._isVisible()) {
                        this._hide();
                        return;
                    }
                    if (!inpId) {
                        this.base.style.left = "0px";
                        this.base.style.top = "0px";
                    } else {
                        if (this.pos == "right") {
                            this.base.style.left = this._getLeft(this.i[inpId]) +
                            this.i[inpId].offsetWidth-1+"px";
                            this.base.style.top = this._getTop(this.i[inpId]) + "px";
                        } else {
                            var e = this.i[inpId];
                            if (e) {
                                this.base.style.left = this._getLeft(e)+"px";
                                this.base.style.top = this._getTop(e)+e.offsetHeight-1 + "px";
                            }
                        }
                        this._activeInp = inpId;
                    }
                    this._hideSelector();
                    this.base.style.display = "";
                }
                this._hide = function() {
                    this._hideSelector();
                    this.base.style.display = "none";
                    this._activeInp = null;
                }
                this._isVisible = function() {
                    return (this.base.style.display!="none");
                }
                this._getLeft = function(obj) {
                    var t = this._posGetOffset(obj);
                    if (t) { return t.left; }
                }
                this._getTop = function(obj) {
                    var t = this._posGetOffset(obj);
                    if (t) { return t.top; }
                }
                this._posGetOffsetSum = function(elem) {
                    var top=0, left=0;
                    while(elem) {
                        top = top + parseInt(elem.offsetTop);
                        left = left + parseInt(elem.offsetLeft);
                        elem = elem.offsetParent;
                    }
                    return {top: top, left: left};
                }
                this._posGetOffsetRect = function(elem) {
                    var box = elem.getBoundingClientRect(),
                        body = document.body,
                        docElem = document.documentElement,
                        scrollTop = window.pageYOffset || docElem.scrollTop || body.scrollTop,
                        scrollLeft = window.pageXOffset || docElem.scrollLeft || body.scrollLeft,
                        clientTop = docElem.clientTop || body.clientTop || 0,
                        clientLeft = docElem.clientLeft || body.clientLeft || 0,
                        top  = box.top +  scrollTop - clientTop,
                        left = box.left + scrollLeft - clientLeft;
                    return { top: Math.round(top), left: Math.round(left) };                                 
                }
                this._posGetOffset = function(elem) {
                    if (elem) {
                        return this[elem.getBoundingClientRect?
                        "_posGetOffsetRect":"_posGetOffsetSum"](elem);
                    }
                }
                this._rangeActive = false;
                this._rangeFrom = null;
                this._rangeTo = null;
                this._rangeSet = {};
                this.setInsensitiveDays = function(d) {
                    var t = this._extractDates(d);
                    for (var q=0; q<t.length; q++) {
                        this._rangeSet[new Date(t[q].getFullYear(),t[q].getMonth(),
                                                   t[q].getDate(),0,0,0,0).getTime()] = true;
                    }
                    this._drawMonth(this._activeMonth);
                }
                this.clearInsensitiveDays = function() {
                    this._clearRangeSet();
                    this._drawMonth(this._activeMonth);
                }
                this._holidays = {};
                this.setHolidays = function(r) {
                    if (r == null) {
                        this._clearHolidays();
                    } else if (r != null) {
                        var t = this._extractDates(r);
                        for (var q=0; q<t.length; q++) {
                            this._holidays[new Date(t[q].getFullYear(),t[q].getMonth(),
                                                       t[q].getDate(),0,0,0,0).getTime()] = true;
                        }
                    }
                    this._drawMonth(this._activeMonth);
                }
                this._extractDates = function(r) {
                    if (typeof(r) == "string" || r instanceof Date) r = [r];
                    var t = [];
                    for (var q=0; q<r.length; q++) {
                        if (typeof(r[q]) == "string") {
                            var e = r[q].split(",");
                            for (var w=0; w<e.length; w++) t.push(this._strToDate(e[w],false));
                        } else if (r[q] instanceof Date) {
                            t.push(r[q]);
                        }
                    }
                    return t;
                }
                this._clearRange = function() {
                    this._rangeActive = false;
                    this._rangeType = null;
                    this._rangeFrom = null;
                    this._rangeTo = null;
                }
                this._clearRangeSet = function() {
                    for (var a in this._rangeSet) {
                        this._rangeSet[a] = null;
                        delete this._rangeSet[a];
                    }
                }
                this._clearHolidays = function() {
                    for (var a in this._holidays) {

                        this._holidays[a] = null;
                        delete this._holidays[a];
                    }
                }
                this._isOutOfRange = function(time) {
                    if (this._rangeSet[time] == true) return true;
                    if (this._rangeActive) {
                        if (this._rangeType == "in" && (time<this._rangeFrom || time>this._rangeTo)) return true;
                        if (this._rangeType == "out" && (time>=this._rangeFrom && time<=this._rangeTo)) return true;
                        if (this._rangeType == "from" && time<this._rangeFrom)return true;
                        if (this._rangeType == "to" && time>this._rangeTo) return true;
                    }
                    var t0 = new Date(time);
                    if (this._rangeWeek) {
                        if (this._rangeWeekData[t0.getDay()] === true) return true;
                    }
                    if (this._rangeMonth) {
                        if (this._rangeMonthData[t0.getDate()] === true) return true;
                    }
                    if (this._rangeYear) {
                        if (this._rangeYearData[t0.getMonth()+"_"+t0.getDate()] === true) return true;
                    }
                    return false;
                }
                this.clearSensitiveRange = function() {
                    this._clearRange();
                    this._drawMonth(this._activeMonth);
                }
                this.setSensitiveRange = function(from, to, ins) {
                    var f = false;
                    if (from != null && to != null) {
                        if (!(from instanceof Date)) from = this._strToDate(from,false);
                        if (!(to instanceof Date)) to = this._strToDate(to,false);
                        if (from.getTime() > to.getTime()) return;
                        this._rangeFrom = new Date(from.getFullYear(),from.getMonth(),
                                                   from.getDate(),0,0,0,0).getTime();
                        this._rangeTo = new Date(to.getFullYear(),to.getMonth(),
                                                 to.getDate(),0,0,0,0).getTime();
                        this._rangeActive = true;
                        this._rangeType = "in";
                        f = true;
                    }
                    if (!f && from != null && to == null) {
                        if (!(from instanceof Date)) from = this._strToDate(from,false);
                        this._rangeFrom = new Date(from.getFullYear(),from.getMonth(),
                                                   from.getDate(),0,0,0,0).getTime();
                        this._rangeTo = null;
                        if (ins === true) this._rangeFrom++;
                        this._rangeActive = true;
                        this._rangeType = "from";
                        f = true;

                    }
                    if (!f && from == null && to != null) {
                        if (!(to instanceof Date)) to = this._strToDate(to,false);
                        this._rangeFrom = null;
                        this._rangeTo = new Date(to.getFullYear(),to.getMonth(),
                                                 to.getDate(),0,0,0,0).getTime();
                        if (ins === true) this._rangeTo--;
                        this._rangeActive = true;
                        this._rangeType = "to";
                        f = true;
                    }
                    if (f) this._drawMonth(this._activeMonth);
                }
                this.setInsensitiveRange = function(from, to) {
                    if (from != null && to != null) {
                        if (!(from instanceof Date)) from = this._strToDate(from,false);
                        if (!(to instanceof Date)) to = this._strToDate(to,false);
                        if (from.getTime() > to.getTime()) return;
                        this._rangeFrom = new Date(from.getFullYear(),from.getMonth(),
                                                   from.getDate(),0,0,0,0).getTime();
                        this._rangeTo = new Date(to.getFullYear(),to.getMonth(),
                                                 to.getDate(),0,0,0,0).getTime();
                        this._rangeActive = true;
                        this._rangeType = "out";
                        this._drawMonth(this._activeMonth);
                        return;
                    }
                    if (from != null && to == null) {
                        this.setSensitiveRange(null, from, true);
                        return;
                    }
                    if (from == null && to != null) {
                        this.setSensitiveRange(to, null, true);
                        return;
                    }
                }
                this.disableDays = function(mode, d) {
                    if (mode == "week") {
                        if (typeof(d) != "object" && typeof(d.length) == "undefined") d = [d];
                        if (!this._rangeWeekData) this._rangeWeekData = {};
                        for (var a in this._rangeWeekData) {
                            this._rangeWeekData[a] = false;
                            delete this._rangeWeekData[a];
                        }
                        for (var q=0; q<d.length; q++) {
                            this._rangeWeekData[d[q]] = true;
                            if (d[q] == 7) this._rangeWeekData[0] = true;
                        }
                        this._rangeWeek = true;
                    }
                    if (mode == "month") {
                        if (typeof(d) != "object" && typeof(d.length) == "undefined") { d = [d]; }
                        if (!this._rangeMonthData) { this._rangeMonthData = {}; }
                        for (var a in this._rangeMonthData) {
                            this._rangeMonthData[a] = false;
                            delete this._rangeMonthData[a];
                        }
                        for (var q=0; q<d.length; q++) { this._rangeMonthData[d[q]] = true; }
                        this._rangeMonth = true;
                    }
                    if (mode == "year") {
                        var t = this._extractDates(d);
                        if (!this._rangeYearData) this._rangeYearData = {};
                        for (var a in this._rangeYearData) {
                            this._rangeYearData[a] = false;
                            delete this._rangeYearData[a];
                        }
                        for (var q=0; q<t.length; q++) {
                            this._rangeYearData[t[q].getMonth() + "_" + t[q].getDate()] = true;
                        }
                        this._rangeYear = true;
                    }
                    this._drawMonth(this._activeMonth);
                }
                this.enableDays = function(mode) {
                    if (mode == "week") {
                        this._rangeWeek = false;
                    }
                    if (mode == "month") {
                        this._rangeMonth = false;
                    }
                    if (mode == "year") {
                        this._rangeYear = false;
                    }
                    this._drawMonth(this._activeMonth);
                }
                this._doOnClick = function(e) {
                    e = e || event;
                    var t = (e.target || e.srcElement);
                    if (t._dhtmlxcalendar_uid && that._isVisible() &&
                        t._dhtmlxcalendar_uid != that._activeInp) {
                        that._hide();
                        return;
                    }
                    if (!t._dhtmlxcalendar_uid || !that.i[t._dhtmlxcalendar_uid]) {
                        if (that._isSelectorVisible()) { that._hideSelector(); }
                        else if (!that._hasParent && that._isVisible()) { that._hide(); }
                    }
                }
                this._doOnKeyDown = function(e) {
                    e = e||event;
                    if (e.keyCode == 27) {
                        if (that._isSelectorVisible()) { that._hideSelector(); }
                        else if (that._isVisible() && !that._hasParent) { that._hide(); }
                    }

                }
                this._doOnInpClick = function(e) {
                    e = e||event;
                    var t = (e.target||e.srcElement);
                    if (!t._dhtmlxcalendar_uid) return;
                    that._updateDateStr(t.value);
                    that._show(t._dhtmlxcalendar_uid, true);
                }
                this._doOnInpKeyUp = function(e) {
                    e = e||event;
                    var t = (e.target||e.srcElement);
                    if (e.keyCode == 13 || !t._dhtmlxcalendar_uid) { return; }
                    that._updateDateStr(t.value);
                }
                this._doOnUnload = function() {
                    that.unload();
                }
                if (window.addEventListener) {
                    document.body.addEventListener("click", that._doOnClick, false);
                    window.addEventListener("keydown", that._doOnKeyDown, false);
                    window.addEventListener("unload", that._doOnUnload, false);
                } else {
                    document.body.attachEvent("onclick", that._doOnClick);
                    document.body.attachEvent("onkeydown", that._doOnKeyDown);
                    window.attachEvent("onunload", that._doOnUnload);
                }
                this.attachObj = function(obj) {
                    var a = this.uid();
                    this.i[a] = obj;
                    this._attachEventsToObject(a);
                }
                this.detachObj = function(obj) {
                    var a = obj._dhtmlxcalendar_uid;
                    if (this.i[a] != null) {
                        this._detachEventsFromObject(a);
                        this.i[a]._dhtmlxcalendar_uid = null;
                        this.i[a] = null;
                        delete this.i[a];
                    }
                }
                var that = this;
                this._attachEventsToObject = function(a) {
                    that.i[a]._dhtmlxcalendar_uid = a;
                    if (window.addEventListener) {
                        that.i[a].addEventListener("click", that._doOnInpClick, false);
                        that.i[a].addEventListener("keyup", that._doOnInpKeyUp, false);
                    } else {
                        that.i[a].attachEvent("onclick", that._doOnInpClick);
                        that.i[a].attachEvent("onkeyup", that._doOnInpKeyUp);
                    }
                }
                this._detachEventsFromObject = function(a) {
                    if (window.addEventListener) {
                        that.i[a].removeEventListener("click", that._doOnInpClick, false);
                        that.i[a].removeEventListener("keyup", that._doOnInpKeyUp, false);
                    } else {
                        that.i[a].detachEvent("onclick", that._doOnInpClick);
                        that.i[a].detachEvent("onkeyup", that._doOnInpKeyUp);
                    }
                }
                for (var a in this.i) {this._attachEventsToObject(a);}
                this.evs = {};
                this.attachEvent = function(name, func) {
                    var eId = this.uid();
                    this.evs[eId] = {name: String(name).toLowerCase(), func: func};
                    return eId;
                }
                this.detachEvent = function(id) {
                    if (this.evs[id]) {
                        this.evs[id].name = null;
                        this.evs[id].func = null;
                        this.evs[id] = null;
                        delete this.evs[id];
                    }
                }
                this.callEvent = function(name, params) {
                    var u = true;
                    var n = String(name).toLowerCase();
                    params = (params||[]);
                    for (var a in this.evs) {
                        if (this.evs[a].name == n) {
                            var r = this.evs[a].func.apply(this,params);
                            u = (u && r);
                        }
                    }
                    return u;

                }
                this.checkEvent = function(name) {
                    var u = false;
                    var n = String(name).toLowerCase();
                    for (var a in this.evs) u = (u || this.evs[a].name == n);
                    return u;
                }
                this.unload = function() {return;
                    this._activeDate = null;
                    this._activeDateCell = null;
                    this._activeInp = null;
                    this._activeMonth = null;
                    this._dateFormat = null;
                    this._dateFormatRE = null;
                    this._lastHover = null;
                    this.uid = null;
                    this.uidd = null;
                    if (window.addEventListener) {
                        document.body.removeEventListener("click", that._doOnClick, false);
                        window.removeEventListener("keydown", that._doOnKeyDown, false);
                        window.removeEventListener("unload", that._doOnUnload, false);
                    } else {
                        document.body.detachEvent("onclick", that._doOnClick);
                        document.body.detachEvent("onkeydown", that._doOnKeyDown);
                        window.detachEvent("onunload", that._doOnKeyDown);
                    }
                    this._doOnClick = null;
                    this._doOnKeyDown = null;
                    this._doOnUnload = null;
                    for (var a in this.i) {
                        this.i[a]._dhtmlxcalendar_uid = null;
                        if (window.addEventListener) {
                            this.i[a].removeEventListener("click", that._doOnInpClick, false);
                            this.i[a].removeEventListener("keyup", that._doOnInpKeyUp, false);
                        } else {
                            this.i[a].detachEvent("onclick", that._doOnInpClick);
                            this.i[a].detachEvent("onkeyup", that._doOnInpKeyUp);
                        }
                        this.i[a] = null;
                        delete this.i[a];
                    }
                    this.i = null;
                    this._doOnInpClick = null;
                    this._doOnInpKeyUp = null;
                    for (var a in this.evs) this.detachEvent(a);
                    this.evs = null;
                    this.attachEvent = null;
                    this.detachEvent = null;
                    this.checkEvent = null;
                    this.callEvent = null;
                    this.contMonth.onselectstart = null;
                    this.contMonth.firstChild.firstChild.onclick = null;
                    this.contMonth.firstChild.firstChild.firstChild.onmouseover = null;
                    this.contMonth.firstChild.firstChild.firstChild.onmouseout = null;
                    this.contMonth.firstChild.firstChild.lastChild.onmouseover = null;
                    this.contMonth.firstChild.firstChild.lastChild.onmouseout = null;
                    while (this.contMonth.firstChild.firstChild.childNodes.length > 0) {
                        this.contMonth.firstChild.firstChild.removeChild(
                        this.contMonth.firstChild.firstChild.lastChild);
                    }
                    this.contMonth.firstChild.removeChild(this.contMonth.firstChild.firstChild);
                    this.contMonth.removeChild(this.contMonth.firstChild);
                    this.contMonth.parentNode.removeChild(this.contMonth);
                    this.contMonth = null;
                    while (this.contDays.firstChild.childNodes.length > 0) {
                        this.contDays.firstChild.removeChild(this.contDays.firstChild.lastChild);
                    }
                    this.contDays.removeChild(this.contDays.firstChild);
                    this.contDays.parentNode.removeChild(this.contDays);
                    this.contDays = null;
                    this.contDates.onclick = null;
                    this.contDates.onmouseover = null;
                    this.contDates.onmouseout = null;
                    while (this.contDates.childNodes.length > 0) {
                        while (this.contDates.lastChild.childNodes.length > 0) {
                            this.contDates.lastChild.lastChild._css_date = null;
                            this.contDates.lastChild.lastChild._css_month = null;
                            this.contDates.lastChild.lastChild._css_weekend = null;
                            this.contDates.lastChild.lastChild._css_hover = null;
                            this.contDates.lastChild.lastChild._date = null;
                            this.contDates.lastChild.lastChild._q = null;
                            this.contDates.lastChild.lastChild._w = null;
                            this.contDates.lastChild.removeChild(this.contDates.lastChild.lastChild);
                        }
                        this.contDates.removeChild(this.contDates.lastChild);
                    }
                    this.contDates.parentNode.removeChild(this.contDates);
                    this.contDates = null;
                    this.contTime.firstChild.firstChild.onclick = null;
                    while (this.contTime.firstChild.firstChild.childNodes.length > 0) {
                        this.contTime.firstChild.firstChild.removeChild(
                        this.contTime.firstChild.firstChild.lastChild);
                    }
                    this.contTime.firstChild.removeChild(this.contTime.firstChild.firstChild);
                    this.contTime.removeChild(this.contTime.firstChild);
                    this.contTime.parentNode.removeChild(this.contTime);
                    this.contTime = null;
                    this._lastHover = null;
                    if (this.msCont) {
                        this.msCont.onclick = null;
                        this._msActive = null;
                        for (var a in this._msCells) {
                            this._msCells[a]._cell = null;
                            this._msCells[a]._month = null;
                            this._msCells[a].parentNode.removeChild(this._msCells[a]);
                            this._msCells[a] = null;
                        }
                        this._msCells = null;
                        while (this.msCont.childNodes.length > 0) {
                            this.msCont.removeChild(this.msCont.lastChild);
                        }
                        this.msCont.parentNode.removeChild(this.msCont);
                        this.msCont = null;
                    }
                    if (this.ysCont) {
                        this.ysCont.onclick = null;
                        for (var a in this._ysCells) {
                            this._ysCells[a]._cell = null;
                            this._ysCells[a]._year = null;
                            this._ysCells[a].parentNode.removeChild(this._ysCells[a]);
                            this._ysCells[a] = null;
                        }
                        this._ysCells = null;
                        while (this.ysCont.childNodes.length > 0) {
                            this.ysCont.removeChild(this.ysCont.lastChild);
                        }
                        this.ysCont.parentNode.removeChild(this.ysCont);
                        this.ysCont = null;
                    }
                    if (this.hsCont) {
                        this.hsCont.onclick = null;
                        this._hsActive = null;
                        for (var a in this._hsCells) {
                            this._hsCells[a]._cell = null;
                            this._hsCells[a]._hours = null;
                            this._hsCells[a].parentNode.removeChild(this._hsCells[a]);
                            this._hsCells[a] = null;
                        }
                        this._hsCells = null;
                        while (this.hsCont.childNodes.length > 0) {
                            this.hsCont.removeChild(this.hsCont.lastChild);
                        }
                        this.hsCont.parentNode.removeChild(this.hsCont);
                        this.hsCont = null;
                    }
                    if (this.rsCont) {
                        this.rsCont.onclick = null;
                        this._rsActive = null;
                        for (var a in this._rsCells) {
                            this._rsCells[a]._cell = null;
                            this._rsCells[a]._minutes = null;
                            this._rsCells[a].parentNode.removeChild(this._rsCells[a]);
                            this._rsCells[a] = null;
                        }
                        this._rsCells = null;
                        while (this.rsCont.childNodes.length > 0) {
                            this.rsCont.removeChild(this.rsCont.lastChild);
                        }
                        this.rsCont.parentNode.removeChild(this.rsCont);
                        this.rsCont = null;
                    }
                    if (this._selCover) {
                        this._selCover.parentNode.removeChild(this._selCover);
                        this._selCover = null;
                    }
                    if (this._sel) {
                        for (var a in this._sel._ta) { this._sel._ta[a] = null; }
                        this._sel._ta = null;
                        this._sel._t = null;
                        this._sel.onmouseover = null;
                        this._sel.onmouseout = null;
                        while (this._sel.firstChild.firstChild.firstChild.childNodes.length > 0) {
                            this._sel.firstChild.firstChild.firstChild.lastChild.onclick = null;
                            this._sel.firstChild.firstChild.firstChild.lastChild.onmouseover = null;
                            this._sel.firstChild.firstChild.firstChild.lastChild.onmouseout = null;
                            this._sel.firstChild.firstChild.firstChild.removeChild(
                            this._sel.firstChild.firstChild.firstChild.lastChild);
                        }
                        this._sel.firstChild.firstChild.removeChild(this._sel.firstChild.firstChild.firstChild);
                        this._sel.firstChild.removeChild(this._sel.firstChild.firstChild);
                        while (this._sel.childNodes.length > 0) { this._sel.removeChild(this._sel.lastChild); }
                        this._sel.parentNode.removeChild(this._sel);
                        this._sel = null;
                    }
                    this.base.onclick = null;
                    this.base.parentNode.removeChild(this.base);
                    this.base = null;
                    this._clearDayHover = null;
                    this._clearSelHover = null;
                    this._doOnSelectorChange = null;
                    this._doOnSelectorShow = null;
                    this._drawMonth = null;
                    this._fixLength = null;
                    this._getLeft = null;
                    this._getTop = null;
                    this._hide = null;
                    this._hideSelector = null;
                    this._initSelector = null;
                    this._isSelectorVisible = null;
                    this._isVisible = null;
                    this._posGetOffset = null;
                    this._posGetOffsetRect = null;
                    this._posGetOffsetSum = null;
                    this._scrollYears = null;
                    this._show = null;
                    this._showSelector = null;
                    this._strToDate = null;
                    this._updateActiveHours = null;
                    this._updateActiveMinutes = null;
                    this._updateActiveMonth = null;
                    this._updateActiveYear = null;
                    this._updateCellStyle = null;
                    this._updateDateStr = null;
                    this._updateVisibleHours = null;
                    this._updateVisibleMinutes = null;
                    this._updateYearsList = null;
                    this.hide = null;
                    this.hideTime = null;
                    this.setDate = null;
                    this.setDateFormat = null;
                    this.show = null;
                    this.showTime = null;
                    this.unload = null;
                    for (var a in this) delete this[a];
                    a = that = null;
                }
                this.setDate(this._activeDate);
                return this;
            };
            that = this;
            this.config = function () { return (this); };
            this.disable = function (options, f) {
                var current;
                if (typeof options === "object") {
                    if (options.franchise) { this.addFranchise(this.Options.Name,
                                             options.franchise); }
                    if ((options.disableDates && f === 'prefix') ||
                        (!f && (options.dates || options.disableDates))) {
                        current = f ? options.disableDates :
                                 (options.dates || options.disableDates);
                        this.Options.temp.disableDates = current;
                        this.disableDates(this.Options.Name, current);
                    }
                    if ((options.disableRange && f === 'prefix') ||
                        (!f && (options.range || options.disableRange))) {
                        current = (typeof (f ?
                            options.disableRange : (options.range ||
                            options.disableRange))[0] !== 'object') ?
                            [(f ? options.disableRange : (options.range ||
                            options.disableRange))] : f ? options.disableRange :
                            (options.range || options.disableRange);
                        this.Options.temp.disableRange = current;
                        this.disableRange(this.Options.Name, current);
                    }
                    if ((options.disableDays && f === 'prefix') || (!f &&
                        (options.days || options.disableDays))) {
                        current = f ? options.disableDays : (options.days || options.disableDays);
                        this.Options.temp.disableDays = current;
                        this.disableDays(this.Options.Name, current);
                    }
                    if (options.setBaseDate) { this.setBaseDate(options.setBaseDate); }
                    for (k in options) {
                        if (options[k] !== undefined) {
                            if (options[k].franchise) { this.addFranchise(k, options[k].franchise); }
                            if ((options[k].disableDates && f === 'prefix') ||
                                (!f && (options[k].dates || options[k].disableDates))) {
                                current = (options[k].dates || options[k].disableDates);
                                this.Options.temp.disableDates = current;
                                this.disableDates(k, current);
                            }
                            if ((options[k].disableRange && f === 'prefix') ||
                                (!f && (options[k].range || options[k].disableRange))) {
                                current = (typeof (f ?
                                    options[k].disableRange : options[k].range)[0] !== 'object') ?
                                    [(f ? options[k].disableRange :
                                     (options[k].range || options[k].disableRange))] :
                                    (f ? options[k].disableRange :
                                    (options[k].range || options[k].disableRange));
                                this.Options.temp.disableRange = current;
                                this.disableRange(k, current);
                            }
                            if ((options[k].disableDays && f === 'prefix') ||
                                (!f && (options[k].days || options[k].disableDays))) {
                                current = (options[k].days || options[k].disableDays);
                                this.Options.temp.disableDays = current;
                                this.disableDays(k, current);
                            }
                            if (options[k].setBaseDate) { this.setBaseDate(options[k].setBaseDate); }
                        }
                    }
                }
                return (this);
            };
            this.dhtmlXCalendarObject.prototype.lang = "en";
            this.dhtmlXCalendarObject.prototype.langData = {
                "en": {
                    dateformat: "%d-%m-%Y",
                    monthesFNames: ["January", "February", "March", "April",
                                    "May", "June", "July", "August", "September",
                                    "October", "November", "December"],
                    monthesSNames: ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
                                    "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
                    daysFNames: ["Sunday", "Monday", "Tuesday", "Wednesday",
                                 "Thursday", "Friday", "Saturday"],
                    daysSNames: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"],
                    weekstart: 1
                }
            };
            this.add = function (o) {
                if (!this.Options.active) { this.load(); }
                myRoot = ((typeof $ !== 'undefined' && $.eventActive) ? $ :
                         (((root && root.eventActive) || !root.onload) ? this : false));
                if (myRoot && myRoot.Event) {
                    myRoot.Event(root, 'load', function () { var don = that.load('outerload');
                    if (don && that.Options.temp.load) { don.actionCalendar('add', o); return (that); } });
                }
                this.actionCalendar('add', o);
                return (this);
            };
            this.root = ':root';
            this.remove = function (o) {
                if (!this.Options.active && o !== ':root') { this.load(); }
                if (o !== ':root') { this.update(); }
                this.actionCalendar('remove', o);
                return (this);
            };
            this.load = function (tt) {
                if (!that.Options.active) {
                    var I, R, a, o, o1 = {}, o2 = {}, d1, d2, i, ff, hk, hl,
                        t = root.document.getElementsByTagName('input'),
                        d = String(new Date()).split(' '), img;
                    for (i in t) {
                        if (typeof t[i] === 'object' && t[i].type === 'text' &&
                             (that.Options.Type === '.' ?
                             (that.find(t[i].className, that.Options.Name)) :
                             (that.find(t[i].id, that.Options.Name)))) {
                            that.Options.active = true;
                            that.Options.rootCalendar = new that.dhtmlXCalendarObject(t[i],
                                                       (that.Options.layout || 'omega'), that,
                                       that.Options, i, that.Options.funcObj);
                            calendar = that.Options.rootCalendar;
                            calendar.hideTime();
                            if (that.Options.limiter) {
                                hk = String(that.date("d-m-Y", that.Options.limiter[0])).split('-');
                                hl = String(that.date("d-m-Y", that.Options.limiter[1])).split('-');
                                calendar.setSensitiveRange(
                                    new Date(hk[2], hk[1] - 1, hk[0]),
                                    new Date(hl[2], hl[1] - 1, hl[0])
                                );
                            }
                            if (that.find(t[i].id, '-') && (id = (t[i].id + ' ')
                                 .match(/-([a-z0-9]+) /i)) !== undefined && id[1] !== undefined) {
                                o1 = that.Options.Store[that.Options.Name][id[1]];
                            }
                            o2 = that.Options.Store[that.Options.Name][that.Options.Name] || {};
                            if ((o1.disableDates !== undefined && o1.disableDates.length) ||
                                 (o2.disableDates !== undefined && o2.disableDates.length)) {
                                if (o1.disableDates && o2.disableDates) {
                                o1.disableDates = o1.disableDates.concat(o2.disableDates); }
                                calendar.setInsensitiveDays(o1.disableDates || o2.disableDates);
                            }
                            if ((o1.disableDays !== undefined && o1.disableDays.length) ||
                                 (o2.disableDays !== undefined && o2.disableDays.length)) {
                                if (o1.disableDays && o2.disableDays) {
                                o1.disableDays = o1.disableDays.concat(o2.disableDays); }
                                calendar.disableDays("week", o1.disableDays || o2.disableDays);
                            }
                            if ((o1.setBaseDate !== undefined && o1.setBaseDate) ||
                                 (o2.setBaseDate !== undefined && o2.setBaseDate)) {
                                that.setBaseDate(o1.setBaseDate || o2.setBaseDate);
                            }
                            if ((o1.disableRange !== undefined && o1.disableRange.length) ||
                                 (o2.disableRange !== undefined && o2.disableRange.length)) {
                                if (o1.disableRange && o2.disableRange) {
                                    o1.disableRange = o1.disableRange.concat(o2.disableRange); }
                                o = (o1.disableRange || o2.disableRange);
                                for (I = 0; I < o.length; I += 1) {
                                    if ((R = o[I]) !== undefined) {
                                        d1 = (d1 = R[0].split('-')) !== undefined ?
                                            new Date(d1[2], d1[1]-1, d1[0]) : (new Date()).getTime();
                                        d2 = (d2 = R[1].split('-')) !== undefined ?
                                            new Date(d2[2], d2[1]-1, d2[0]) : (new Date()).getTime();
                                        if ((a = that.getDatesBetween(d1, d2)) !== undefined && d1 && d2) {
                                            calendar.setInsensitiveDays(a); }
                                    }
                                }
                            }
                            t[i].disabled = true;
                            that.Options.Calendar = calendar;
                            if (!that.Options.limiter) {
                                if (that.Options.setCur[that.Options.Name] &&
                                    that.Options.setCur[that.Options.Name].length) {
                                    for (i in (a = that.Options.setCur[that.Options.Name])) {
                                        if (a[i] !== undefined) {
                                            calendar.setSensitiveRange(a[i], null);
                                        }
                                    }
                                }
                                if (that.Options.setCurGlobal) {
                                    calendar.setSensitiveRange(that.Options.setCurGlobal, null);
                                }
                            }
                            img = new Image();
                            img.src = that.Options.clearImage;
                            that.addImage(t[i], i, that.Options.Name);
                        }
                    }
                }
                return (this);
            };
            this.block = function () {
                var i,
                    t = name.substr(0, 1) === '.' ?
                        root.document.getElementsByClassName(name.substr(1)) :
                        root.document.getElementById(name.substr(1));
                if (typeof t === 'object') {
                    for (i = 0; i < t.length; i += 1) {
                        if (t[i] !== undefined && options && this.Options.temp.readOnly) {
                            t[i].readOnly = true;
                            t[i].style.cursor = 'text';
                        }
                    }
                } else {
                    if (t !== undefined && options && this.Options.temp.readOnly) {
                        t.readOnly = true;
                        t.style.cursor = 'text';
                    }
                }
                return (this);
            };
            this.removeElement = function (d, c) {
                c = c.substr(0, 1) === '.' ?
                        root.document.getElementsByClassName(c.substr(1)) :
                        [root.document.getElementById(c.substr(1))];
                if (typeof c === 'object') {
                    for (i = 0; i < c.length; i += 1) {
                        if (c[i] !== undefined) {
                            d.removeChild(c[i]);
                        }
                    }
                } else {
                    d.removeChild(c);
                }
                return (this);
            };
            this.plugin = function (o, f, r) {
                var i, t = false, count = 0;
                this.plugin['revert'] = function () { return (that); };
                if (o !== 'clear' && ((typeof o === 'string' &&
                   (typeof f === 'function' || typeof f === 'object')) ||
                   (typeof o === 'function' && (f && typeof f !== 'string')
                    && !r && (t = true) !== undefined))) {
                    if (t) {
                        f = o; r = t;
                        for (i in this.plugin) {
                            if (+i > 0) { count += 1; }
                        }
                        o = count + 1;
                    }
                    this.plugin[o] = (typeof f === 'function' ?
                                     (function () { f(arguments); return this; }) : f);
                    if (r && typeof f === 'function') { (this.plugin[o]()); }
                }
                return (this);
            };
            this.limit = function (limit) {
                var c;
                if (!this.Options.Storage.baseDate) {
                    this.Options.Storage.baseDate = this.date('Y-m-d');
                } else {
                    c = String(this.Options.Storage.baseDate).replace(/-/g, '/');
                    this.Options.Storage.baseDate = this.date("Y-m-d",
                    this.strtotime(c.split('-').reverse().join('-')));
                }
                if (limit) {
                    this.Options.limiter = [this.strtotime(String(this.Options.Storage.baseDate).
                                            replace(/-/g, '/').split('-').reverse().join('-')),
                        this.strtotime(String(limit ?
                            this.date("Y-m-d", this.strtotime(limit,
                                this.strtotime(String(this.Options.Storage.baseDate).replace(/-/g, '/').split('-').
                                reverse().join('-')))):String(this.Options.Storage.baseDate).replace(/-/g,
                                '/').split('-').reverse().join('-')).replace(/-/g, '/').split('-').
                                reverse().join('-'))];
                }
                this.Options.temp.limit = limit;
                return (this);
            };
            this.update = function () {
                var t = root.document.getElementsByClassName();
                that.removeElement(root.document.body, '.' + that.Options.Name + '-calendar');
                this.Options.temp.auto = true;
                return (new Calendar(name, this.Options.temp));
            };
            this.layout = function (o) {
                this.Options.layout = o;
            };
            this.disable(this.Options.temp, 'prefix').block().store = this.Options.Store[this.Options.Name];
            if (this.Options.temp && this.Options.temp.limit) { this.limit(this.Options.temp.limit); }
            if (this.Options.temp && this.Options.temp.disable) { this.disable(this.Options.temp.disable); }
            if (this.Options.temp && this.Options.temp.layout) { this.layout(this.Options.temp.layout); }
            if (this.Options.temp && this.Options.temp.auto) { this.add(); }
            return (this);
        }
    };
    root.Calendar = function (a, b) { return (new root._Calendar(a, b)); };
}(window));

