
Rax = {}
Rax.OnDOMReady = function() {
/* nocode */
}
Rax.NullProc = function() {
/* nocode */
}

Rax.Get = function(id) {
    if (typeof(id) == 'string') {
        return document.getElementById(id);
    }

    return id;
}

Rax.HookEvent = function(proc, el, o, h) {
    el[proc] = function() {
        h.apply(o, arguments);
    }
}

Rax.WindowOpen = function(url) {
    window.open(url, "fytf", "toolbar=0,scrollbars=0,status=1,resizable=1,width=900,height=600");
}

/*  Rax.InitDataObject
 */
Rax.InitDataObject = function(o, p) {
    for (var key in p) {
        if (typeof(o[key]) == 'undefined') {
            o[key] = p[key]
        }
    }
}

/*  var control = new Rax.FieldSet();
 *
 *  control.Fields.Field1 = new Field('a');
 *  control.Fields.Field2 = new Field('b');
 *
 *  data = control.Export();
 */
Rax.FieldSet = function() {
    this.Fields = new Object();
}

Rax.FieldSet.prototype.Export = function() {
    var ret = new Object();
    for (var key in this.Fields) {
        ret[key] = this.Fields[key].Export();
    }

    return ret;
}

Rax.FieldSet.prototype.Import = function(o) {
    for (var key in o) {
        if (typeof(this.Fields[key]) != 'undefined') {
            this.Fields[key].Import(o[key]);
        }
    }
}



/*  var control = new Rax.Input({
 *      Id : 'TextField',
 *      Width : 100,
 *      Text : 'Abc...',
 *
 *      Init : function() {
 *          this.OnType = function() {
 *              alert('Typed text...');
 *          }
 *      }
 *  });
 */
Rax.Input = function(o) {
    Rax.InitDataObject(o, {
        Width : 100,
        Text : '',
        Init : Rax.NullProc
    });

    this.OnType = Rax.NullProc;
	this.OnEnter = Rax.NullProc;
    this.El = Rax.Get(o.Id);
    this.El.value = o.Text;
    this.Enable();

    o.Init.call(this);

    Rax.HookEvent('onkeyup', this.El, this, function(evt) {
	    if (!evt) {
		    evt = window.event;
		}

		if (evt.keyCode == 13) {
		    this.OnEnter();
			return;
		}

        this.OnType();
    });
}

Rax.Input.prototype.Export = function() {
    return this.El.value;
}

Rax.Input.prototype.Import = function(o) {
    this.El.value = o;
}

Rax.Input.prototype.Enable = function() {
    this.El.readOnly = false;
    this.El.style.border = '1px solid #679';
    this.El.style.padding = '3px';
    this.El.style.color = '#000';
    this.El.style.fontFamily = 'Arial,Tahoma,Verdana,sans-serif';
    this.El.style.fontSize = '12px';
    //this.El.style.fontWeight = 'bold';
    this.El.style.backgroundColor = '#FFF';
}

Rax.Input.prototype.Highlight = function() {
    this.El.style.border = '1px solid #f00';
	this.El.style.backgroundColor = '#FDD';
}

Rax.Input.prototype.IsInteger = function() {
    var i = 0;
	var s = this.El.value;

    for ( ; i < s.length; i++) {
        var c = s.charAt(i);

        if ((c < '0') || (c > '9')) {
		    return false;
		}
    }

    return true;
}

Rax.Input.prototype.IsFloat = function() {
    var i = 0;
	var s = this.El.value;
	var t = false;

    for ( ; i < s.length; i++) {
        var c = s.charAt(i);
		if (c == '.' || c == ',') {
		    if (t == true) {
			    return false;
			}

			t = true;
			continue;
		}

        if ((c < '0') || (c > '9')) {
		    return false;
		}
    }

    return true;
}

Rax.Input.prototype.Disable = function() {
    this.El.disabled = true;
    this.El.style.border = '1px solid #a9acb0';
    this.El.style.padding = '3px';
    this.El.style.color = '#aaa';
    this.El.style.fontFamily = 'Arial,Tahoma,Verdana,sans-serif';
    this.El.style.fontSize = '12px';
    //this.El.style.fontWeight = 'bold';
    this.El.style.backgroundColor = '#F6F6F6';
}



/*  var control = new Rax.RadioSet({
 *      Init : function() {
 *          this.AddRadioButton('Buttonas', {
 *              Id : 'ID',
 *              Init : function() {
 *                  this.OnSelect = function() {
 *                      alert('OK!');
 *                  }
 *              }
 *          });
 *      }
 *  });
 */
Rax.RadioSet = function(o) {
    Rax.InitDataObject(o, {
        Init : Rax.NullProc
    });

    this.Items = new Object();
    this.Selected = 'None';

    o.Init.call(this);

    /*  Paziurim, ar yra selectintu batonu
     */
    /*
    for (var key in this.Items) {
        if (this.Items[key].El.checked == true) {
            this.Items[key].OnSelect(this);
            this.Selected = this.Items[key].El.value;
            break;
        }
    }*/
}

Rax.RadioSet.prototype.AddRadioButton = function(n, o) {
    var RaButton = function(a, t) {
        Rax.InitDataObject(a, {
            Init : Rax.NullProc,
            Selected : false
        });

        this.OnSelect = Rax.NullProc;
        this.El = Rax.Get(a.Id);

        a.Init.call(this);

        if (o.Selected == true) {
            t.Selected = n;
			this.El.checked = true;
            //this.OnSelect();
        }

        Rax.HookEvent('onclick', this.El, this, function() {
            t.Selected = n;
            this.OnSelect(t);
        });
    }

    this.Items[n] = new RaButton(o, this);
}

Rax.RadioSet.prototype.Export = function() {
    return this.Selected;
}

Rax.RadioSet.prototype.Import = function(o) {
    for (var key in this.Items) {
        if (this.Items[key]) {
            this.Selected = o;
            this.Items[key].El.checked = true;
            this.Items[key].OnSelect();
            return;
        }
    }
}

Rax.RadioSet.prototype.Enable = function() {
    for (var key in this.Items) {
        this.Items[key].El.disabled = false;
    }
}

Rax.RadioSet.prototype.Disable = function() {
    for (var key in this.Items) {
        this.Items[key].El.disabled = true;
    }
}




/*  var control = new Rax.CheckBox({
 *      Id : 'Check',
 *      Init : function() {
 *          this.OnCheck = function() {
 *              alert('Checked...');
 *          }
 *      }
 *  });
 */
Rax.CheckBox = function(o) {
    Rax.InitDataObject(o, {
        Init : Rax.NullProc,
		Checked : false
    });

    this.OnCheck = Rax.NullProc;
    this.OnUnCheck = Rax.NullProc;

    this.El = Rax.Get(o.Id);

    Rax.HookEvent('onclick', this.El, this, function() {
        if (this.El.checked) {
            this.OnCheck();
            return;
        }

        this.OnUnCheck();
    });

    o.Init.call(this);

    if (this.El.checked == true || o.Checked == true) {
	    //this.Check();
		this.El.checked = true;
        //this.OnCheck();
    }/* else {
        this.OnUnCheck();
    }*/
}

Rax.CheckBox.prototype.Export = function() {
    return this.El.checked;
}

Rax.CheckBox.prototype.Import = function(o) {
    if (o == false)
        this.El.checked = false;
    else
        this.El.checked = true;
}

Rax.CheckBox.prototype.Enable = function() {
    this.El.disabled = false;
}

Rax.CheckBox.prototype.Disable = function() {
    this.El.disabled = true;
    this.El.checked = false;
}

Rax.CheckBox.prototype.Check = function() {
    this.El.checked = true;
    this.OnCheck();
}

Rax.CheckBox.prototype.UnCheck = function() {
    this.El.checked = false;
    this.OnUnCheck();
}




/*  var control = new Rax.CheckBoxSet({
 *    Items : [
 *        'a', 'b', 'c',
 *        Init : function() {
 *            alert(this.Items.a.id);
 *        }
 *    ]
 *  });
 */
Rax.CheckBoxSet = function(o) {
    Rax.InitDataObject(o, {
        Items : [],
        Init : Rax.NullProc
    });

    this.Items = new Object();

    for (var i = 0; i < o.Items.length; i++) {
        this.Items[o.Items[i]] = Rax.Get(o.Items[i]);
    }

    o.Init.call(this);
}

Rax.CheckBoxSet.prototype.Export = function() {
    var e = new Array();
    for (var key in this.Items) {
        if (this.Items[key].checked) {
            e.push(this.Items[key].id);
        }
    }

    return e;//.join(';');
}

Rax.CheckBoxSet.prototype.Import = function(o) {
    this.UncheckAll();
    var e = o.split(';');
    for (var i = 0; i < e.length; i++) {
        if (typeof(this.Items[e[i]]) == 'object') {
            this.Items[e[i]].checked = true;
        }
    }
}

Rax.CheckBoxSet.prototype.UncheckAll = function() {
    for (var key in this.Items) {
        this.Items[key].checked = false;
    }
}

Rax.CheckBoxSet.prototype.CheckAll = function() {
    for (var key in this.Items) {
        this.Items[key].checked = true;
    }
}

Rax.CheckBoxSet.prototype.Enable = function() {
    for (var key in this.Items) {
        this.Items[key].disabled = false;
    }
}

Rax.CheckBoxSet.prototype.Disable = function() {
    for (var key in this.Items) {
        this.Items[key].disabled = true;
    }
}




/*  var control = new Rax.Button({
 *      Init : function() {
 *          this.OnAction = function() {
 *              alert('Batonas paspaustas...');
 *          }
 *      }
 *  });
 */
Rax.Button = function(o) {
    Rax.InitDataObject(o, {
        Init : Rax.NullProc
    });

    this.OnAction = Rax.NullProc;
    this.El = Rax.Get(o.Id);
	this.El.style.fontFamily = 'Tahoma,Verdana,Arial,sans-serif';
	this.El.style.fontSize = '11px';
	this.El.style.fontWeight = 'bold';
	this.El.style.padding = '2px';
    o.Init.call(this);

    Rax.HookEvent('onclick', this.El, this, function() {
        this.OnAction();
    });
}

Rax.Button.prototype.Export = function() {
    return null;
}

Rax.Button.prototype.Import = function(o) {
/* nocode */
}

Rax.Button.prototype.Enable = function() {
    this.El.disabled = false;
}

Rax.Button.prototype.Disable = function() {
    this.El.disabled = true;
}

Rax.Button.prototype.Hide = function() {
    this.El.style.display = 'none';
    this.El.style.visibility = 'hidden';
}

Rax.Button.prototype.Show = function() {
    this.El.style.visibility = 'visible';
    this.El.style.display = 'block';
}




/*  var control = new Rax.Select({
 *      Init : function() {
 *          this.OnChange = function(id) {
 *              alert('Pasirinkta ' + id);
 *          }
 *      }
 *  });
 */
Rax.Select = function(o) {
    Rax.InitDataObject(o, {
        Init : Rax.NullProc,
        Selected : null
    });

    this.OnChange = Rax.NullProc;
    this.El = Rax.Get(o.Id);
    //this.El.style.border = '1px solid #235';
    this.El.style.padding = '1px';
    this.El.style.fontFamily = 'Arial,Tahoma,Verdana,sans-serif';
    this.El.style.fontSize = '12px';
    //this.El.style.fontWeight = 'bold';

    if (o.Selected != null) {
        this.Import(o.Selected);
    }

    o.Init.call(this);

    Rax.HookEvent('onchange', this.El, this, function() {
        this.OnChange(this.El.options[this.El.selectedIndex].value);
    });
}

Rax.Select.prototype.Export = function() {
    return this.El.options[this.El.selectedIndex].value;
}

Rax.Select.prototype.Import = function(o) {
    for (var i = 0; i < this.El.options.length; i++) {
        if (this.El.options[i].value == o) {
            this.El.selectedIndex = i;
            return;
        }
    }
}

Rax.Select.prototype.Enable = function() {
    this.El.disabled = false;
}

Rax.Select.prototype.Disable = function() {
    this.El.disabled = true;
}



/*  var control = new Rax.TextArea({
 *      Id : 'Id'
 *  });
 */
Rax.TextArea = function(o) {
    Rax.InitDataObject(o, {
        Init : Rax.NullProc,
        Text : '',
		Width : 250,
		Height : 100
    });

    this.El = Rax.Get(o.Id);
    this.El.value = o.Text;
	this.El.style.fontFamily = 'Arial,Tahoma,Verdana,sans-serif';
	this.El.style.fontSize = '12px';
	this.El.style.padding = '3px';
	this.El.style.width = ''+o.Width+'px';
	this.El.style.height = ''+o.Height+'px';
    o.Init.call(this);
}

Rax.TextArea.prototype.Export = function() {
    return this.El.value;
}

Rax.TextArea.prototype.Import = function(o) {
    this.El.value = o;
}

Rax.TextArea.prototype.Disable = function() {
    this.El.disabled = true;
}

Rax.TextArea.prototype.Enable = function() {
    this.El.disabled = false;
}


switch (_lang) {
case 'lt_lt':
Rax.Date_DayAcro = [
'P','A','T','K','P','Š','S'
];
Rax.Date_Months = [
'Sausis',
'Vasaris',
'Kovas',
'Balandis',
'Geguže',
'Birželis',
'Liepa',
'Rugpjutis',
'Rugsejis',
'Spalis',
'Lapkritis',
'Gruodis'
];
break;
case 'ru_ru':
Rax.Date_DayAcro = [
'P','A','T','K','P','Š','S'
];
Rax.Date_Months = [
'Января',
'Февраля',
'Марта',
'Апреля',
'Майя',
'Июня',
'Июля',
'Августa',
'Сентября',
'Октября',
'Ноября',
'Декабря'
];
break;
case 'lv_lv':
Rax.Date_DayAcro = [
'P','A','T','K','P','Š','S'
];
Rax.Date_Months = [
"Janvāra",
"Februāra",
"Marta",
"Aprīļa",
"Maija",
"Jūnija",
"Jūlija",
"Augusta",
"Septembra",
"Oktobra",
"Novembra",
"Decembra"
];
break;
case 'ee_ee':
Rax.Date_DayAcro = [
'P','A','T','K','P','Š','S'
];
Rax.Date_Months = [
"Jaanuaril",
"Veebruaril",
"Märtsil",
"Aprillil",
"Mail",
"Juunil",
"Juulil",
"Augustil", 
"Septembril",
"Oktoobril",
"Novembril",
"Detsembril"
];
break;
case 'de_de':
Rax.Date_DayAcro = [
'P','A','T','K','P','Š','S'
];
Rax.Date_Months = [
"Januar",
"Februar",
"März",
"April",
"Mai",
"Juni",
"Juli",
"August",
"September",
"Oktober",
"November",
"Dezember"
];
break;
case 'en_en':
Rax.Date_DayAcro = [
'P','A','T','K','P','Š','S'
];
Rax.Date_Months = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
];
break;
}


Rax.Date_MonthDays = [
31,28,31,30,31,30,31,31,30,31,30,31
];

Rax.GetAbsolutePos = function(el) {
	var SL = 0, ST = 0;
	var is_div = /^div$/i.test(el.tagName);
	if (is_div && el.scrollLeft)
		SL = el.scrollLeft;
	if (is_div && el.scrollTop)
		ST = el.scrollTop;
	var r = { x: el.offsetLeft - SL, y: el.offsetTop - ST };
	if (el.offsetParent) {
		var tmp = Rax.GetAbsolutePos(el.offsetParent);
		r.x += tmp.x;
		r.y += tmp.y;
	}
	return r;
};

Rax.DateSelect = function(o) {
    Rax.InitDataObject(o, {
        Id : null,
        MaxDate : '3000/01/01',
        MinDate : '1970/01/01',
        CurDate : '2000/01/01',
        DisableWeekends : false,
		OnSelect : function(cd) {
		    return true;
		}
    });

    var Cal = this; /* kalendorius lokaliam accessui */
    Cal.tds = []; /* 42 td elementai dienom */
    Cal.minDate = new Date(o.MinDate);
    Cal.maxDate = new Date(o.MaxDate);
    Cal.curDate = new Date(o.CurDate);
    Cal.tmpDate = new Date();
	Cal.disSelects = new Array();
    Cal.db = null;

    if (Cal.maxDate.getTime() < Cal.minDate.getTime()) {
        Cal.maxDate.setTime(Cal.minDate.getTime());
    }

    /* teiblas datos rodymui */
    this.aDisplayTable = document.createElement('TABLE');
    this.aDisplayTable.border = 0;
    this.aDisplayTable.cellSpacing = 2;
    this.aDisplayTable.cellPadding = 0;
    this.aDisplayTable.style.border = '1px solid #456';
    this.aDisplayTable.style.width = '110px';
    var aDisplayTbody = document.createElement('TBODY');
    var aDisplayTr = document.createElement('TR');
    this.aDisplayTd1 = document.createElement('TD');
    var aDisplayTd2 = document.createElement('TD');

    this.aDisplayTd1.className = 'dateoutput';

    aDisplayTr.appendChild(this.aDisplayTd1);
    aDisplayTr.appendChild(aDisplayTd2);
    aDisplayTbody.appendChild(aDisplayTr);
    this.aDisplayTable.appendChild(aDisplayTbody);
    aDisplayTd2.style.width = '16px';
    aDisplayTd2.style.height = '15px';
    aDisplayTd2.style.backgroundImage = "url('/g/cal.gif')";
    aDisplayTd2.style.backgroundRepeat = 'no-repeat';
    aDisplayTd2.style.cursor = 'pointer';

    aDisplayTd2.onmousedown = function() {
	    var sel = document.getElementsByTagName('SELECT');
		for (var i = 0; i < sel.length; i++) {
		    if (sel[i].disabled == false) {
			    sel[i].disabled = true;
				sel[i].style.visibility = 'hidden';
				Cal.disSelects.push(sel[i]);
			}
		}

        var pos = Rax.GetAbsolutePos(this);
        pos.y += this.offsetHeight;
        Cal.aCont.style.top = ''+pos.y+'px';
        Cal.aCont.style.left = ''+pos.x+'px';
        Cal.aCont.style.visibility = 'visible';
        Cal.aCont.style.display = 'block';
        Cal.tmpDate.setTime(Cal.curDate.getTime());
        SetMonth();
    }

    var contain = Rax.Get(o.Id);
    contain.appendChild(this.aDisplayTable);

    var CreateTable = function() {
        var t = document.createElement('TABLE');
        t.cellSpacing = 0;
        t.cellPadding = 0;
        t.border = 0;
        return t;
    }

    var SetMonth = function() {
        var index = 0;
        for ( ; index < Cal.tmpDate.GetFirstMonthDayWeekDay(); index++) {
            Cal.tds[index]._disabled = true;
            Cal.tds[index].innerHTML = '&nbsp;';
        }

        var i = 1;
        var a = 0;
        var b = 42;
        if (Cal.minDate.getFullYear() == Cal.tmpDate.getFullYear()) {
            if (Cal.minDate.getMonth() == Cal.tmpDate.getMonth()) {
                a = Cal.minDate.getDate();
            }
        }

        if (Cal.maxDate.getFullYear() == Cal.tmpDate.getFullYear()) {
            if (Cal.maxDate.getMonth() == Cal.tmpDate.getMonth()) {
                b = Cal.maxDate.getDate();
            }
        }

        for ( ; i <= Cal.tmpDate.GetMonthDays(); index++) {
            if (i < a || i > b || Cal.tds[index]._disableWeekend) {
                Cal.tds[index].className = 'monthdaydisabled';
                Cal.tds[index]._disabled = true;
            } else {
                Cal.tds[index].className = 'monthday';
                Cal.tds[index]._disabled = false;
            }

            Cal.tds[index].innerHTML = i;
			i++;
        }

        for ( ; index < 42; index++) {
            Cal.tds[index]._disabled = true;
            Cal.tds[index].innerHTML = '&nbsp;';
        }

        Cal.db.innerHTML = Cal.tmpDate.PrintYearMonth();

        if (Cal.tmpDate.getFullYear() == Cal.minDate.getFullYear()) {
            Cal.td2._disable();
            if (Cal.tmpDate.getMonth() == Cal.minDate.getMonth()) {
                Cal.td1._disable();
            } else {
                Cal.td1._enable();
            }
        } else if ((Cal.tmpDate.getFullYear()-1) == Cal.minDate.getFullYear()) {
            Cal.td1._enable();
            if (Cal.tmpDate.getMonth() < Cal.minDate.getMonth()) {
                Cal.td2._disable();
            } else {
                Cal.td2._enable();
            }
        } else {
            Cal.td2._enable();
            Cal.td1._enable();
        }

        if (Cal.tmpDate.getFullYear() == Cal.maxDate.getFullYear()) {
            Cal.td4._disable();
            if (Cal.tmpDate.getMonth() == Cal.maxDate.getMonth()) {
                Cal.td5._disable();
            } else {
                Cal.td5._enable();
            }
        } else if ((Cal.tmpDate.getFullYear()+1) == Cal.maxDate.getFullYear()) {
            Cal.td5._enable();
            if (Cal.tmpDate.getMonth() > Cal.maxDate.getMonth()) {
                Cal.td4._disable();
            } else {
                Cal.td4._enable();
            }
        } else {
            Cal.td4._enable();
            Cal.td5._enable();
        }
    }

    var NextMonth = function() {
        Cal.tmpDate.NextMonth();
    }

    var PrevMonth = function() {
        Cal.tmpDate.PrevMonth();
    }

    var NextYear = function() {
        Cal.tmpDate.setFullYear(Cal.tmpDate.getFullYear()+1);
    }

    var PrevYear = function() {
        Cal.tmpDate.setFullYear(Cal.tmpDate.getFullYear()-1);
    }

    var HideCal = function() {
        Cal.aCont.style.display = 'none';
		for (var i = 0; i < Cal.disSelects.length; i++) {
		    Cal.disSelects[i].disabled = false;
			Cal.disSelects[i].style.visibility = 'visible';
		}
    }

    var CreateButton = function(w, h, pos, pp) {
        var td = document.createElement('TD');
        td.style.width = ''+w+'px';
        td.style.height = ''+h+'px';
        td.style.backgroundImage = "url('/bg.gif')";
        td.style.backgroundPosition = ''+pos+'px 0px';
        td.style.backgroundRepeat = 'no-repeat';
        td._pos = pos;
        td._disabled = false;
        td.onmousedown = function() {
            if (this._disabled != true) {
                this.style.backgroundPosition = ''+this._pos+'px -17px';
            }
        }

        td.onmouseup = function() {
            if (this._disabled != true) {
                this.style.backgroundPosition = ''+this._pos+'px 0px';
                pp();
                SetMonth();
            }
        }

        td._disable = function() {
            this._disabled = true;
            this.style.backgroundPosition = ''+this._pos+'px -34px';
        }

        td._enable = function() {
            this.style.backgroundPosition = ''+this._pos+'px 0px';
            this._disabled = false;
        }

        return td;
    }

    var CreateDatebar = function() {
        var td = document.createElement('TD');
        td.className = 'datebar';
        td.unselectable = 'on';
        Cal.db = td;
        return td;
    }

    var CellOver = function() {
        if (this._disabled == false) {
            this.style.backgroundColor = '#cde';
        }
    }

    var CellOut = function() {
        if (this._disabled == false) {
            this.style.backgroundColor = '#fff';
        }
    }

    var CellDown = function() {
        if (this._disabled == false) {
		    var cd = new Date();
			cd.setDate(this._day - Cal.tmpDate.GetFirstMonthDayWeekDay());
            cd.setMonth(Cal.tmpDate.getMonth());
            cd.setFullYear(Cal.tmpDate.getFullYear());

		    if (o.OnSelect.call(Cal, cd) == true) {
			    Cal.curDate.setDate(this._day - Cal.tmpDate.GetFirstMonthDayWeekDay());
                Cal.curDate.setMonth(Cal.tmpDate.getMonth());
                Cal.curDate.setFullYear(Cal.tmpDate.getFullYear());
                Cal.aDisplayTd1.innerHTML = Cal.curDate.Print();
                Cal.aCont.style.display = 'none';
				for (var i = 0; i < Cal.disSelects.length; i++) {
		            Cal.disSelects[i].disabled = false;
			        Cal.disSelects[i].style.visibility = 'visible';
		        }
			}
        }
    }

    var aTopTable  = CreateTable();
    var aTopTbody  = document.createElement('TBODY');
    var aTopTr1    = document.createElement('TR');
    var aTopTr2    = document.createElement('TR');
    var aTopTd1    = document.createElement('TD');
    var aTopTd2    = document.createElement('TD');
    var hTable     = CreateTable();
    var hTbody     = document.createElement('TBODY');
    var hTr        = document.createElement('TR');
    var hTd1       = CreateButton(23, 17, 0, PrevMonth);
    var hTd2       = CreateButton(17, 17, -23, PrevYear);
    var hTd3       = CreateDatebar();
    var hTd4       = CreateButton(17, 17, -40, NextYear);
    var hTd5       = CreateButton(23, 17, -57, NextMonth);
    var hTd6       = CreateButton(23, 17, -80, HideCal);
    /**/
    var oTable     = CreateTable();
    var oTbody     = document.createElement('TBODY');
    var oTr1       = document.createElement('TR');

    hTr.appendChild(hTd1);
    hTr.appendChild(hTd2);
    hTr.appendChild(hTd3);
    hTr.appendChild(hTd4);
    hTr.appendChild(hTd5);
    hTr.appendChild(hTd6);

    hTbody.appendChild(hTr);
    hTable.appendChild(hTbody);
    aTopTd1.appendChild(hTable);
    aTopTr1.appendChild(aTopTd1);

    oTbody.appendChild(oTr1);
    oTable.appendChild(oTbody);
    aTopTd2.appendChild(oTable);
    aTopTr2.appendChild(aTopTd2);

    aTopTbody.appendChild(aTopTr1);
    aTopTbody.appendChild(aTopTr2);
    aTopTable.appendChild(aTopTbody);


    for (var index = 0; index < 7; index++) {
        var td = document.createElement('TD');
        td.appendChild(document.createTextNode(Rax.Date_DayAcro[index]));
        td.className = 'weekday';
        td.unselectable = 'on';
        oTr1.appendChild(td);
    }

    var i = 1;
    for (var r = 0; r < 6; r++) {
        var tr = document.createElement('TR');
        for (var c = 0; c < 7; c++) {
            var td = document.createElement('TD');
            if ((c == 5 || c == 6) && o.DisableWeekends) {
                td._disableWeekend = true;
            } else {
                td._disableWeekend = false;
            }

            td.className = 'monthday';
            td.unselectable = 'on';
            td.innerHTML = c;
            tr.appendChild(td);
            td._day = i++;
            td.onmouseover = CellOver;
            td.onmouseout = CellOut;
            td.onmousedown = CellDown;
            this.tds.push(td);
        }

        oTbody.appendChild(tr);
    }

    aTopTd1.className = 'header';
    this.aCont = document.createElement('DIV');
    this.aCont.className = 'container';
    this.aCont.appendChild(aTopTable);
    this.td1 = hTd1;
    this.td2 = hTd2;
    this.td4 = hTd4;
    this.td5 = hTd5;
    SetMonth();
    Cal.aDisplayTd1.innerHTML = Cal.curDate.Print();
    document.body.appendChild(this.aCont);
}

Date.prototype.GetMonthDays = function() {
    var year = this.getFullYear();
    var month = this.getMonth();
	if (((0 == (year%4)) && ( (0 != (year%100)) || (0 == (year%400)))) && month == 1) {
		return 29;
	} else {
		return Rax.Date_MonthDays[month];
	}
}

Date.prototype.GetFirstMonthDayWeekDay = function() {
    var d = new Date();
    d.setFullYear(this.getFullYear());
    d.setDate(1);
    d.setMonth(this.getMonth());
    if(d.getDay() != 0) {
				return d.getDay()-1;
		} else {
				return d.getDay()+6;
		}
}

Date.prototype.NextMonth = function() {
    if (this.getMonth() == 12) {
        this.setMonth(1);
        this.setFullYear(this.getFullYear()+1);
    } else {
        this.setMonth(this.getMonth()+1);
    }
}

Date.prototype.PrevMonth = function() {
    if (this.getMonth() == 1) {
        this.setMonth(12);
        this.setFullYear(this.getFullYear()-1);
    } else {
        this.setMonth(this.getMonth()-1);
    }
}

Date.prototype.PrintYearMonth = function() {
    var y = this.getFullYear();
    var m = this.getMonth();
    return ''+y+' '+Rax.Date_Months[m];
}

Date.prototype.Print = function() {
    var y = this.getFullYear();
    var d = this.getDate();
    var m = this.getMonth()+1;

    if (d < 10)
        d = '0'+d;
    if (m < 10)
        m = '0'+m;
    return ''+y+'/'+m+'/'+d;
}

Rax.DateSelect.prototype.Export = function() {
    return this.curDate.Print();
}

Rax.DateSelect.prototype.Import = function(s) {
    this.curDate = new Date(s);
}

Rax.DateSelect.prototype.SetMinDate = function(s) {
    var d = new Date(s);
	this.minDate.setTime(d.getTime());
}

Rax.DateSelect.prototype.SetMaxDate = function(s) {
    var d = new Date(s);
	this.maxDate.setTime(d.getTime());
}



/*  var control = new Rax.Panel('Panel1', true);
 *  control.Wait();
 *
 *  Processing...
 *
 *  control.WakeUp();
 */
Rax.Panel = function(o, v) {
    this.El = Rax.Get(o);
    if (v != true) {
        this.Hide();
    }

    this.MaskEl = null;
    this.WaitingEl = null;
    this.DisabledElements = [];
}

Rax.Panel.prototype.Wait = function() {
    if (this.MaskEl == null) {
        this.MaskEl = document.createElement('DIV');
        this.MaskEl.style.position = 'absolute';
        this.MaskEl.style.backgroundColor = '#FFF';
        this.MaskEl.style.zoom = '1';
        this.MaskEl.style.zIndex = '20000';
        this.MaskEl.style.opacity = '.75';
        this.MaskEl.style.filter = 'alpha(opacity=75)';
        this.MaskEl.style.display = 'none';
        document.body.appendChild(this.MaskEl);
    }

    var pos = Rax.GetAbsolutePos(this.El);
    this.MaskEl.style.top = ''+pos.y+'px';
    this.MaskEl.style.left = ''+pos.x+'px';
    this.MaskEl.style.width = '' + this.El.offsetWidth + 'px';
    this.MaskEl.style.height = '' + this.El.offsetHeight + 'px';

    var els = this.El.getElementsByTagName('SELECT');
    for (var index = 0; index < els.length; index++) {
        if (els[index].disabled == false) {
            this.DisabledElements.push(els[index]);
            els[index].disabled = true;
        }
    }

    this.MaskEl.style.display = 'block';
}

Rax.Panel.prototype.WakeUp = function() {
    for (var index = 0; index < this.DisabledElements.length; index++) {
        this.DisabledElements[index].disabled = false;
    }

    this.DisabledElements.length = 0;
    this.MaskEl.style.display = 'none';
}

Rax.Panel.prototype.Hide = function() {
    this.El.style.display = 'none';
    this.El.style.visibility = 'hidden';
}

Rax.Panel.prototype.Show = function() {
    this.El.style.visibility = 'visible';
    this.El.style.display = 'block';
}



/*  Rax.Label
 */
Rax.Label = function(id) {
    this.El = Rax.Get(id);
    this.Hide();
}

Rax.Label.prototype.Hide = function() {
    this.El.style.display = 'none';
    this.El.style.visibility = 'hidden';
}

Rax.Label.prototype.Show = function(text) {
    for (var i = 0; i < this.El.childNodes.length; i++) {
        this.El.removeChild(this.El.childNodes[i]);
    }

    this.El.appendChild(document.createTextNode(text));
    this.El.style.display = 'block';
    this.El.style.visibility = 'visible';
}




window.onload = function() {
    Rax.OnDOMReady();
    document.body.style.visibility = 'visible';
}

