function hx_gb_calendar2 () {
this.editable = false;
}
hx_gb_calendar2.prototype = {
leapYear: false,
sday: null,
smonth: null,
syear: null,
month: null,
year: null,
firstDay: null,
upMonth: false,
upYear: false,
monthNames: new Array( loc_js.jan, loc_js.feb , loc_js.mar, loc_js.apr, loc_js.may, loc_js.jun, loc_js.jul, loc_js.aug, loc_js.sep, loc_js.oct, loc_js.nov, loc_js.dec ),
normalMonths: new Array( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ),
leapMonths: new Array( 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ),
create: function( _id, _layer, _editable ){
this.id = _id;
this.editable = _editable;
this.element = _layer;
this.composeCalendar();
this.working( false );
},
destroy: function() {
monthNames = null;
normalMonths = null;
leapMonths = null;
return null;
},
composeCalendar: function() {
var i = ge( this.element );
if( i ) {
var code = '';
/*code += '

';*/
code += '';
code += this.composeControls();
code += this.composeWeekHeader();
for( var week = 0; week < 6; week++ ) code += this.composeWeek( week );
code += '
';
re( i, code );
var f = ge( this.id + '.cnt.day' );
this.enableControls();
}
},
composeControls: function() {
var thisPtr = this;
var code = '';
if( this.editable ) {
code += '| << | ';
code += '< | ';
code += '- | ';
code += '> | ';
code += '>> | ';
} else {
code += '- | ';
}
code += '
';
return code;
},
enableControls: function() {
var t = null;
t = ge( this.id + '.ylclick' );
var thisPtr = this;
if( t ) t.onclick = function( evt ) { thisPtr.move( evt, thisPtr, '-y' ); return false; };
t = ge( this.id + '.mlclick' );
if( t ) t.onclick = function( evt ) { thisPtr.move( evt, thisPtr, '-m' ); return false; };
t = ge( this.id + '.mmclick' );
if( t ) t.onclick = function( evt ) { thisPtr.move( evt, thisPtr, '+m' ); return false; };
t = ge( this.id + '.ymclick' );
if( t ) t.onclick = function( evt ) { thisPtr.move( evt, thisPtr, '+y' ); return false; };
},
composeWeekHeader: function() {
var code = '';
return code;
},
composeWeek: function( _wid ) {
var code = '';
code += ' | ';
for( var j = 0; j < 7; j++ ){
code += ' | ';
}
code += '
';
return code;
},
working: function( _w ) {
/*var el = ge( 'calovr' );
if( el ) el.style.visibility = _w?'visible':'hidden';*/
},
update: function() {
this.upMonth = false;
this.upYear = false;
this.composeMonth();
},
moveDate: function( _month, _year ) {
this.month = _month;
this.year = _year;
this.setCaption();
if( this.upYear ) this.getYearData();
this.update();
},
setDate: function( _day, _month, _year ){
this.upMonth = ( _month!= this.month );
this.upYear = ( _year != this.year );
this.sday = _day;
this.smonth = _month;
this.syear = _year;
this.month = this.smonth;
this.year = this.syear;
this.setCaption();
if( this.upYear ) this.getYearData();
this.update();
this.onDateChanged();
},
setCaption: function() {
var txt = this.monthNames[ this.month ] + ' ' + this.year;
re( ge( this.id + '.cnt.day' ), txt );
},
getYearData: function() {
var d = new Date;
d.setDate( 1 );
d.setMonth( 0 );
d.setFullYear( this.year );
d.setHours( 0 );
d.setMinutes( 0 );
d.setSeconds( 0 );
this.firstDay = d.getDay();
d.setDate( 29 );
d.setMonth( 1 );
d.setFullYear( this.year );
d.setHours( 0 );
d.setMinutes( 0 );
d.setSeconds( 0 );
this.leapYear = ( d.getDate() == 29 );
},
composeMonth: function() {
var ma = null;
if( this.leapYear ) ma = this.leapMonths; else ma = this.normalMonths;
var offset = 0;
for( var m = 0; m < this.month; m++ )
offset += ma[ m ];
var firstDay = ( this.firstDay + offset ) % 7;
if( firstDay == 0 ) firstDay = 7;
var thisPtr = this;
var firstWeek = Math.floor( offset / 7 ) + 1;
var monthCount = - firstDay + 2;
var monthTotal = ma[ this.month ];
for( var w = 0; w < 6; w++ ) {
re( ge( this.id + '.wid.' + w ), firstWeek++ );
for( var d = 0; d < 7; d++ ) {
var id = this.id + '.day.' + w + '.' + d;
var el = ge( id );
if( gfc( el ) ) el.removeChild( gfc( el ) );
var ddiv = null;
if( monthCount > 0 && monthCount <= monthTotal ) {
ddiv = document.createElement( 'a' );
ddiv.className = 'clickable';
if( monthCount == this.sday && this.month == this.smonth && this.year == this.syear) ddiv.className += ' currentday';
ddiv.innerHTML = this.getDay( monthCount );
if( this.editable ) ddiv.onclick = bargs( this.clickDay, this, monthCount );
} else {
ddiv = document.createElement( 'p' );
}
el.appendChild( ddiv );
monthCount++;
}
}
},
clickDay: function( _parent, _day ) {
_parent.sday = _day;
_parent.smonth = _parent.month;
_parent.syear = _parent.year;
_parent.onDateChanged();
return false;
},
onDateChanged: function(){
this.composeMonth();
if( this.onPostDateChanged ) this.onPostDateChanged();
},
move: function( _evt, _parent, _movement ) {
var m = _parent.month;
var y = _parent.year;
if( _movement == '-m' ) m--;
if( _movement == '+m' ) m++;
if( _movement == '-y' ) { y--; this.upYear = true; }
if( _movement == '+y' ) { y++; this.upYear = true; }
if( m < 0 ) { m = 11; y--; this.upYear = true; }
if( m > 11 ) { m = 0; y++; this.upYear = true; }
_parent.moveDate( m, y );
if( !_evt ) window.event.cancelBubble = true;
else _evt.stopPropagation();
},
getDay: function( _day ) {
return _day;
},
getDate: function() {
var d = new Date();
d.setUTCFullYear( this.syear );
d.setUTCMonth( this.smonth );
d.setUTCDate( this.sday );
d.setUTCHours( 0 );
d.setUTCMinutes( 0 );
d.setUTCSeconds( 0 );
d.setUTCMilliseconds( 0 );
return { 'd': this.sday, 'm': this.smonth, 'ml': this.monthNames[ this.month], 'y': this.syear, 'ts': d.getTime() };
}
}
function hx_gb_clock() {
}
hx_gb_clock.prototype = {
create: function( _layer ){
this.layer = _layer;
this.compose();
this.hour = -1;
this.minute = -1;
this.mode = null;
},
createLine: function( _type, _from, _to, _btn, _table ){
var step = 5;
if( _type == 'hour' ) step = 1;
var tr = document.createElement( 'tr' );
var td = document.createElement( 'td' );
td.className = 'blank';
//st( td, ' ' );
tr.appendChild( td );
for( var j = _from; j < _to; j += step ) {
var btn = this.createClickButton();
//st( btn.a, ( ( j < 10 )?'0':'' ) + j );
btn.a.innerHTML = ( ( j < 10 )?'0':'' ) + j;
btn.a.id = this.layer + ( ( _type == 'hour' )?'h':'m' ) + j;
btn.a.onclick = bargs( this.onBtnClick, this, _type, j );
tr.appendChild( btn.td );
}
tr.appendChild( this.createButton( _btn ) );
return tr;
},
createButton: function( _type ) {
var btn = this.createClickButton();
switch( _type ) {
case 'am':{
btn.a.id = this.layer + 'am';
btn.a.onclick = bargs( this.switchAMPM, this, 'am' );
btn.a.innerHTML = 'AM';
break;
}
case 'pm':{
btn.a.id = this.layer + 'pm';
btn.a.onclick = bargs( this.switchAMPM, this, 'pm' );
btn.a.innerHTML = 'PM';
break;
}
case '-':{
btn.a.innerHTML = '-';
break;
}
case '+':{
btn.a.innerHTML = '+';
break;
}
}
return btn.td;
},
createClickButton: function() {
var td = document.createElement( 'td' );
var a = document.createElement( 'a' );
a.className = 'clickable';
a.href = '#';
td.appendChild( a );
return { 'td': td, 'a': a };
},
compose: function() {
var el = ge( this.layer );
if( !el ) return;
var p = document.createElement( 'p' );
p.id = this.layer + 'p';
p.className = 'title';
el.appendChild( p );
var t = document.createElement( 'table' );
var tbody = document.createElement( 'tbody' );
t.className = 'clock_container';
tbody.appendChild( this.createLine( 'hour', 0, 6, 'am' ) );
tbody.appendChild( this.createLine( 'hour', 6, 12, 'pm' ) );
tbody.appendChild( this.createLine( 'minute', 0, 30, '-' ) );
tbody.appendChild( this.createLine( 'minute', 30, 60, '+' ) );
t.appendChild( tbody );
el.appendChild( t );
},
onBtnClick: function( _this, _type, _id ) {
if( _type == 'hour' ) {
if( _this.hour != _id ) {
var el = ge( _this.layer + 'h' + _this.hour );
if( el ) el.className = 'clickable';
}
_this.hour = _id;
} else {
if( _this.minute != _id ) {
var el = ge( _this.layer + 'm' + _this.minute );
if( el ) el.className = 'clickable';
}
_this.minute = _id;
}
var el = ge( _this.layer + ( ( _type == 'hour' )?'h':'m' ) + _id );
if( el ) el.className += ' current';
_this.onChange( _this );
return false;
},
onChange: function( _this ) {
_this = _this || this;
var t = _this.getTime();
st( ge( _this.layer + 'p' ), t.h + ':' + t.m );
if( _this.onPostTimeChanged ) _this.onPostTimeChanged();
},
getTime: function() {
var h = this.hour;
if( this.mode == 'pm' ) h += 12;
return { 'h': ( ( h < 10 )?'0':'' ) + h, 'm': ( ( this.minute < 10 )?'0':'' ) + this.minute, 's': 0 };
},
switchAMPM: function( _this, _id ) {
if( _this.mode ) {
var el = ge( _this.layer + ( ( _id == 'am' )?'pm':'am' ) );
if( el ) el.className = 'clickable';
}
var el = ge( _this.layer + _id );
if( el ) el.className += ' current';
for( var j = 0; j < 12; j++ ) {
var el = ge( _this.layer + 'h' + j );
if( el ) {
var v = j;
if( _id == 'pm' ) v += 12;
st( el, ( ( v < 10 )?'0':'' ) + v );
}
}
_this.mode = _id;
_this.onChange();
return false;
},
setTime: function( _h, _m, _s, _z ) {
this.mode = 'am';
if( _h > 11 ) { _h -= 12; this.mode = 'pm'; }
_m = Math.floor( _m / 5 ) * 5;
this.onBtnClick( this, 'hour', _h );
this.onBtnClick( this, 'minute', _m );
this.switchAMPM( this, this.mode );
}
}