var mdatecalendars = new Array();var ctime = null;var ctimefrom = null;var ctimeto = null;function mdate(inputelm) {    this.show = false;    this.created = false;    this.active = false;    this.mdateactive = false;    this.years = new Array();    this.months = new Array();    this.mdateelm_input = inputelm;    this.mdateelm_container = null;    this.mdateelm_msiepopup = null;    this.mdateelm_datepicker = null;    this.mdateelm_yearselect = null;    this.mdateelm_monthselect = null;    this.mdateelm_table = null;    this.mdateelm_tbody = null;    this.mdateelm_trows = new Array();    this.mdateelm_tcells = new Array();    this.hidetimeout = null;    this.xwidth = 0;    this.xheight = 0;        this.datevalue = null;    this.dateproposal = null;    this.datestart = null;    this.dateend = null;        this.monthdays = new Array(31,28,31,30,31,30,31,31,30,31,30,31);    this.monthnames = new Array('January','February','March','April','May','June','July','August','September','October','November','December');    this.daynames = new Array('Mon','Tue','Wed','Thu','Fri','Sat','Sun');        var xhtml = document.getElementsByTagName('html')[0];    if (xhtml.getAttribute('lang')) {        if (xhtml.getAttribute('lang') == 'cs') {            this.monthnames = new Array('Leden','Únor','Březen','Duben','Květen','Červen','Červenec','Srpen','Září','Říjen','Listopad','Prosinec');            this.daynames = new Array('Po','Út','St','Čt','Pá','So','Ne');        }    }        this.xcreateelement = function(context,type) {        var result = false;        if (context.createElementNS) {            result = context.createElementNS('http://www.w3.org/1999/xhtml','html:'+type);        } else {            result = context.createElement(type);        }        return result;    }        this.xcreatetextnode = function(context,text) {        return context.createTextNode(text);    }        this.setnewdate = function(obj,year,month,day) {        obj.setHours(12,0,0,0);        obj.setFullYear(year,month,day);    }        this.preparedates = function(obj) {        var nowdate = new Date();        obj.datevalue = new Date();        obj.setnewdate(obj.datevalue,nowdate.getFullYear(),nowdate.getMonth(),nowdate.getDate());        obj.dateproposal = new Date();        obj.setnewdate(obj.dateproposal,nowdate.getFullYear(),nowdate.getMonth(),nowdate.getDate());        obj.datestart = new Date();        obj.setnewdate(obj.datestart,1970,0,1);        obj.dateend = new Date();        obj.setnewdate(obj.dateend,2038,0,19);        if (obj.mdateelm_input.getAttribute('alt')) {            var result = obj.mdateelm_input.getAttribute('alt').match(/(\d{1,2})\.(\d{1,2})\.(\d{4})\s*-\s*(\d{1,2})\.(\d{1,2})\.(\d{4})/);            if(result) {                obj.setnewdate(obj.datestart,result[3],result[2]-1,result[1]);                obj.setnewdate(obj.dateend,result[6],result[5]-1,result[4]);                if (obj.datestart>obj.dateend) {                    obj.setnewdate(obj.datestart,result[6],result[5]-1,result[4]);                    obj.setnewdate(obj.dateend,result[3],result[2]-1,result[1]);                }            }        }        result = obj.mdateelm_input.value.match(/(\d{1,2})\.(\d{1,2})\.(\d{4})/);        if(result) {            obj.setnewdate(obj.dateproposal,result[3],result[2]-1,result[1]);        }        if (obj.dateproposal<obj.datestart) {            obj.setnewdate(obj.dateproposal,obj.datestart.getFullYear(),obj.datestart.getMonth(),obj.datestart.getDate());        }        else if (obj.dateproposal>obj.dateend) {            obj.setnewdate(obj.dateproposal,obj.dateend.getFullYear(),obj.dateend.getMonth(),obj.dateend.getDate());        }        obj.setnewdate(obj.datevalue,obj.dateproposal.getFullYear(),obj.dateproposal.getMonth(),obj.dateproposal.getDate());    }        this.showmdate = function() {        obj = this.mdate;        if (obj.hidetimeout != null) {            window.clearTimeout(obj.hidetimeout);        }        obj.hidetimeout = null;        if (!obj.active) {            for (var i=0;i<mdatecalendars.length;i++) {                if (mdatecalendars[i].active) {                    mdatecalendars[i].hidemdate(mdatecalendars[i]);                }            }            obj.mdateelm_container.style.display = 'block';            obj.mdateelm_container.style.visibility = 'visible';            if (obj.mdateelm_msiepopup != null) {                obj.xwidth = obj.mdateelm_container.offsetWidth;                obj.mdateelm_msiepopup.document.body.style.background = '#FFFFFF';                obj.mdateelm_msiepopup.show(0,0,obj.xwidth,0,obj.mdateelm_container);                obj.mdateelm_table.style.width = (obj.xwidth-2)+'px';                obj.xheight = obj.mdateelm_msiepopup.document.body.scrollHeight;                obj.mdateelm_msiepopup.hide()                obj.mdateelm_container.style.height = obj.xheight+'px';                obj.mdateelm_msiepopup.show(0,0,obj.xwidth,obj.xheight,obj.mdateelm_container);                obj.mdateelm_msiepopup.document.focus();            }            obj.active = true;        }    }    this.hidemdate = function(obj) {        obj.hidetimeout = null;        if (obj.active) {            if(!obj.mdateactive) {                obj.active = false;                obj.mdateelm_container.style.display = 'none';                obj.mdateelm_container.style.visibility = 'hidden';                if (obj.mdateelm_msiepopup != null) {                    obj.mdateelm_msiepopup.hide();                }            }        }    }        this.hidemdatetimeout = function(){        obj = this.mdate;        if (obj.active) {            if(!obj.mdateactive) {                window.mdate = obj;                obj.hidetimeout = window.setTimeout('this.mdate.hidemdate(obj);',500);            }        }    }        this.selectactivated = function() {        obj = this.parentNode.mdate;        obj.mdateactive = true;    }        this.selectdeactivated = function() {        obj = this.parentNode.mdate;        obj.mdateactive = false;    }        this.changeyear = function() {        obj = this.parentNode.mdate;        obj.mdateactive = false;        obj.setnewdate(obj.dateproposal,this.value,obj.datevalue.getMonth(),obj.datevalue.getDate());        obj.redrawmdate(obj);    }        this.changemonth = function() {        obj = this.parentNode.mdate;        obj.mdateactive = false;        obj.setnewdate(obj.dateproposal,obj.datevalue.getFullYear(),this.value-1,obj.datevalue.getDate());        obj.redrawmdate(obj);    }        this.changeday = function() {        obj = this.parentNode.parentNode.parentNode.parentNode.mdate;        obj.mdateactive = false;        obj.setnewdate(obj.dateproposal,obj.datevalue.getFullYear(),obj.datevalue.getMonth(),this.firstChild.nodeValue);        obj.redrawmdate(obj);    }        this.redrawmdate = function(obj) {        if (obj.dateproposal<obj.datestart) {            obj.setnewdate(obj.dateproposal,obj.datestart.getFullYear(),obj.datestart.getMonth(),obj.datestart.getDate());        }        else if (obj.dateproposal>obj.dateend) {            obj.setnewdate(obj.dateproposal,obj.dateend.getFullYear(),obj.dateend.getMonth(),obj.dateend.getDate());        }        obj.setnewdate(obj.datevalue,obj.dateproposal.getFullYear(),obj.dateproposal.getMonth(),obj.dateproposal.getDate());        var day = ''+obj.datevalue.getDate();        if (day.length == 1) {            day = '0'+day;        }        var month = ''+(obj.datevalue.getMonth()+1);        if (month.length == 1) {            month = '0'+month;        }        obj.mdateelm_input.value = day+'.'+month+'.'+obj.datevalue.getFullYear();                var trows = obj.mdateelm_trows.length;        obj.drawtablebody(obj);        obj.mdateelm_monthselect.selectedIndex = obj.datevalue.getMonth();        if (trows != obj.mdateelm_trows.length) {            if (obj.mdateelm_msiepopup != null) {                if (obj.active) {                    obj.mdateelm_msiepopup.hide();                    obj.mdateelm_msiepopup.show(0,0,obj.xwidth,0,obj.mdateelm_container);                    obj.xheight = obj.mdateelm_msiepopup.document.body.scrollHeight;                    obj.mdateelm_msiepopup.hide();                    obj.mdateelm_container.style.height = obj.xheight+'px';                    obj.mdateelm_msiepopup.show(0,0,obj.xwidth,obj.xheight,obj.mdateelm_container);                }            }        }    }        this.tdmouseover = function() {         if (this.mdateselected) {            this.className = 'activeselectedhover';        } else {            this.className = 'activehover';        }    }        this.tdmouseout = function() {        if (this.mdateselected) {            this.className = 'activeselected';        } else {            this.className = 'active';        }    }        this.drawtablebody = function(obj) {        obj.mdateelm_trows = new Array();        obj.mdateelm_tcells = new Array();                if (obj.mdateelm_tbody) {            obj.mdateelm_table.removeChild(obj.mdateelm_tbody);        }                obj.mdateelm_tbody = obj.xcreateelement(obj.createcontext,'tbody');        obj.mdateelm_table.appendChild(obj.mdateelm_tbody);        obj.mdateelm_trows[0] = obj.xcreateelement(obj.createcontext,'tr');        obj.mdateelm_tbody.appendChild(obj.mdateelm_trows[0]);        obj.mdateelm_tcells[0] = new Array();        for (i=0;i<obj.daynames.length;i++) {            obj.mdateelm_tcells[0][i] = obj.xcreateelement(obj.createcontext,'th');            obj.mdateelm_tcells[0][i].appendChild(obj.xcreatetextnode(obj.createcontext,obj.daynames[i]));            obj.mdateelm_trows[0].appendChild(obj.mdateelm_tcells[0][i]);        }                var actmonthdays = obj.monthdays[obj.datevalue.getMonth()];        if (obj.datevalue.getMonth()==1) {            if ((obj.datevalue.getFullYear()%4 == 0)&&(obj.datevalue.getFullYear()%100 != 0)||(obj.datevalue.getFullYear()%400 == 0)) {                actmonthdays = 29;            }        }        var monthday = 1;        var tablecellindex = 0;        var rowcellindex = 0;        var trindex = 0;        var dateinmonth = new Date();        while (monthday <= actmonthdays) {            rowcellindex = tablecellindex%7;            trindex = 1+Math.floor(tablecellindex/7);            obj.setnewdate(dateinmonth,obj.datevalue.getFullYear(),obj.datevalue.getMonth(),monthday);            if (rowcellindex == 0) {                obj.mdateelm_trows[trindex] = obj.xcreateelement(obj.createcontext,'tr');                obj.mdateelm_tbody.appendChild(obj.mdateelm_trows[trindex]);                obj.mdateelm_tcells[trindex] = new Array();            }            if (monthday == 1) {                var monthstartday = dateinmonth.getDay();                if (monthstartday == 0) {                    monthstartday = 7;                }                for (i=1;i<monthstartday;i++) {                    rowcellindex = tablecellindex%7;                    obj.mdateelm_tcells[trindex][rowcellindex] = obj.xcreateelement(obj.createcontext,'td');                    obj.mdateelm_trows[trindex].appendChild(obj.mdateelm_tcells[trindex][rowcellindex]);                    tablecellindex++;                }            }                        obj.mdateelm_tcells[trindex][rowcellindex] = obj.xcreateelement(obj.createcontext,'td');            if ((dateinmonth>=obj.datestart)&&(dateinmonth<=obj.dateend)) {                obj.mdateelm_tcells[trindex][rowcellindex].className = 'active';                if (monthday == obj.datevalue.getDate()) {                    obj.mdateelm_tcells[trindex][rowcellindex].mdateselected = true;                    obj.mdateelm_tcells[trindex][rowcellindex].className = 'activeselected';                }                obj.mdateelm_tcells[trindex][rowcellindex].onmouseover = obj.tdmouseover;                obj.mdateelm_tcells[trindex][rowcellindex].onmouseout = obj.tdmouseout;                obj.mdateelm_tcells[trindex][rowcellindex].onclick = obj.changeday;            }                        obj.mdateelm_tcells[trindex][rowcellindex].appendChild(obj.xcreatetextnode(obj.createcontext,monthday));            obj.mdateelm_trows[trindex].appendChild(obj.mdateelm_tcells[trindex][rowcellindex]);                        if (monthday == actmonthdays) {                var monthendday = dateinmonth.getDay();                if (monthendday == 0) {                    monthendday = 7;                }                monthendday++;                for (i=monthendday;i<=7;i++) {                    rowcellindex = tablecellindex%7;                    obj.mdateelm_tcells[trindex][rowcellindex] = obj.xcreateelement(obj.createcontext,'td');                    obj.mdateelm_trows[trindex].appendChild(obj.mdateelm_tcells[trindex][rowcellindex]);                    tablecellindex++;                }            }            monthday++;            tablecellindex++;        }    }        this.drawyears = function(obj) {            if (obj.mdateelm_yearselect) {            obj.mdateelm_datepicker.removeChild(obj.mdateelm_yearselect);        }        obj.mdateelm_yearselect = obj.xcreateelement(obj.createcontext,'select');        obj.mdateelm_yearselect.onchange = obj.changeyear;        obj.mdateelm_yearselect.onfocus = obj.selectactivated;        obj.mdateelm_yearselect.onblur = obj.selectdeactivated;                if (obj.mdateelm_table) {            obj.mdateelm_datepicker.insertBefore(obj.mdateelm_yearselect,obj.mdateelm_table);        } else {            obj.mdateelm_datepicker.appendChild(obj.mdateelm_yearselect);        }                for (i=obj.datestart.getFullYear();i<=obj.dateend.getFullYear();i++) {            obj.years[i] = obj.xcreateelement(obj.createcontext,'option');            obj.years[i].appendChild(obj.xcreatetextnode(obj.createcontext,i));            obj.years[i].value = i;            if (obj.datevalue.getFullYear()==i) {                obj.years[i].selected = true;            }            obj.mdateelm_yearselect.appendChild(obj.years[i]);        }    }    this.create = function()  {        if (!this.created) {            if (this.mdateelm_input != null) {                            this.preparedates(this);                                this.createcontext = document;                if (isIEBug()) {                    this.mdateelm_msiepopup = window.createPopup();                    this.mdateelm_msiepopup.document.createStyleSheet('/xchen.css');                    this.createcontext = this.mdateelm_msiepopup.document;                }                                //this.mdateelm_input.disabled = true;                this.mdateelm_input.color = '#000000';                this.mdateelm_input.mdate = this;                if (this.mdateelm_msiepopup == null) {                    this.mdateelm_input.onmouseover = this.showmdate;                    this.mdateelm_input.onmouseout = this.hidemdatetimeout;                } else {                    this.mdateelm_input.onclick = this.showmdate;                }                this.mdateelm_input.onfocus = this.showmdate;                if (this.mdateelm_input.style.cursor) {                    this.mdateelm_input.style.cursor = 'pointer';                }                                this.mdateelm_container = this.xcreateelement(document,'div');                this.mdateelm_container.mdate = this;                this.mdateelm_container.style.position = 'absolute';                this.mdateelm_container.style.zIndex = '1000';                this.mdateelm_container.style.top = (this.mdateelm_input.offsetTop+this.mdateelm_input.offsetHeight-1)+'px';                this.mdateelm_container.style.left = this.mdateelm_input.offsetLeft+'px';                this.mdateelm_container.className = 'mdatecontainer';                this.mdateelm_container.style.display = 'none';                this.mdateelm_container.style.visibility = 'hidden';                this.mdateelm_input.parentNode.insertBefore(this.mdateelm_container,this.mdateelm_input);                this.mdateelm_datepicker = this.xcreateelement(this.createcontext,'div');                this.mdateelm_datepicker.className = 'mdate';                this.mdateelm_datepicker.mdate = this;                                if (this.mdateelm_msiepopup == null) {                    this.mdateelm_datepicker.onmouseover = this.showmdate;                    this.mdateelm_datepicker.onmouseout = this.hidemdatetimeout;                    this.mdateelm_container.appendChild(this.mdateelm_datepicker);                } else {                    this.mdateelm_msiepopup.document.body.mdate = this;                    this.mdateelm_msiepopup.document.body.appendChild(this.mdateelm_datepicker);                }                                this.mdateelm_monthselect = this.xcreateelement(this.createcontext,'select');                for (i=0;i<this.monthnames.length;i++) {                    this.months[i] = this.xcreateelement(this.createcontext,'option');                    this.months[i].appendChild(this.xcreatetextnode(this.createcontext,this.monthnames[i]));                    this.months[i].value = i+1;                    if (this.datevalue.getMonth()==i) {                        this.months[i].selected = true;                    }                    this.mdateelm_monthselect.appendChild(this.months[i]);                }                this.mdateelm_monthselect.onchange = this.changemonth;                this.mdateelm_monthselect.onfocus = this.selectactivated;                this.mdateelm_monthselect.onblur = this.selectdeactivated;                this.mdateelm_datepicker.appendChild(this.mdateelm_monthselect);                this.drawyears(this);                                this.mdateelm_table = this.xcreateelement(this.createcontext,'table');                this.mdateelm_datepicker.appendChild(this.mdateelm_table);                this.redrawmdate(this);                this.created = true;            }        }    }        this.create();}function mdateinit() {    if (!isIE5()) {        this.xinputs = document.getElementsByTagName('input');        var j=0;        for(var i=0;i<this.xinputs.length;i++) {            if(this.xinputs[i].className == 'mdateinput')  {                mdatecalendars[j] = new mdate(this.xinputs[i]);                j++;            }        }    }    /* reg specific */    ctime = document.getElementById('in_course');    ctime.onchange = changeCTimeDates;    ctimefrom = document.getElementById('in_ctimefrom');    ctimeto = document.getElementById('in_ctimeto');}function changeCTimeDates() {    var result = this.options[this.selectedIndex].firstChild.nodeValue.match(/(\d{1,2})\.(\d{1,2})\.(\d{4})\s*-\s*(\d{1,2})\.(\d{1,2})\.(\d{4})/);    if(result) {        ctimefrom.value = result[1]+'.'+result[2]+'.'+result[3];        ctimefrom.setAttribute('alt',result[0]);        ctimeto.value = result[4]+'.'+result[5]+'.'+result[6];        ctimeto.setAttribute('alt',result[0]);    } else {        var nowdate = new Date();        var nowdatestr = nowdate.getDate()+'.'+(nowdate.getMonth()+1)+'.'+nowdate.getFullYear();        ctimefrom.value = nowdatestr;        ctimefrom.setAttribute('alt','');        ctimeto.value = nowdatestr;        ctimeto.setAttribute('alt','');    }    ctimefrom.mdate.preparedates(ctimefrom.mdate);    ctimefrom.mdate.redrawmdate(ctimefrom.mdate);    ctimefrom.mdate.drawyears(ctimefrom.mdate);    ctimeto.mdate.preparedates(ctimeto.mdate);    ctimeto.mdate.redrawmdate(ctimeto.mdate);    ctimeto.mdate.drawyears(ctimeto.mdate);}function isIEBug() {    var agt=navigator.userAgent.toLowerCase();    var is_major = parseInt(navigator.appVersion);    var is_ie = ((agt.indexOf('msie') != -1) && (agt.indexOf('opera') == -1));    var is_ie67 = (is_ie && ((agt.indexOf('msie 5.5') != -1)||(agt.indexOf('msie 6') != -1)||(agt.indexOf('msie 7') != -1)||(agt.indexOf('msie 8') != -1)));    return is_ie67;}function isIE5() {    var agt=navigator.userAgent.toLowerCase();    var is_major = parseInt(navigator.appVersion);    var is_ie = ((agt.indexOf('msie') != -1) && (agt.indexOf('opera') == -1));    var is_ie5 = (is_ie && (agt.indexOf('msie 5.5') == -1)&&(agt.indexOf('msie 6') == -1)&&(agt.indexOf('msie 7') == -1)&&(agt.indexOf('msie 8') == -1));    return is_ie5;}function addEvent(obj, evType, fn){    if (obj.addEventListener){        obj.addEventListener(evType, fn, false);        return true;    } else if (obj.attachEvent){        var r = obj.attachEvent("on"+evType, fn);        return r;    } else {        return false;    }}addEvent(window,'load',mdateinit);/* reg specific functions */