2010-12-02 23:34:41 +00:00
// Title: Tigra Calendar
// URL: http://www.softcomplex.com/products/tigra_calendar/
// Version: 3.2 (European date format)
// Date: 10/14/2002 (mm/dd/yyyy)
// Feedback: feedback@softcomplex.com (specify product title in the subject)
// Note: Permission given to use this script in ANY kind of applications if
// header lines are left unchanged.
// Note: Script consists of two files: calendar?.js and calendar.html
// About us: Our company provides offshore IT consulting services.
// Contact us at sales@softcomplex.com if you have any programming task you
// want to be handled by professionals. Our typical hourly rate is $20.
// if two digit year input dates after this year considered 20 century.
var NUM _CENTYEAR = 30 ;
// is time input control required by default
var BUL _TIMECOMPONENT = false ;
// are year scrolling buttons required by default
var BUL _YEARSCROLL = true ;
var calendars = [ ] ;
var RE _NUM = /^\-?\d+$/ ;
function calendar1 ( obj _target ) {
// assing methods
this . gen _date = cal _gen _date1 ;
this . gen _time = cal _gen _time1 ;
this . gen _tsmp = cal _gen _tsmp1 ;
this . prs _date = cal _prs _date1 ;
this . prs _time = cal _prs _time1 ;
this . prs _tsmp = cal _prs _tsmp1 ;
this . popup = cal _popup1 ;
this . fecha = "0" ;
// validate input parameters
if ( ! obj _target )
return cal _error ( "Error calling the calendar: no target control specified" ) ;
if ( obj _target . value == null )
return cal _error ( "Error calling the calendar: parameter specified is not valid tardet control" ) ;
this . target = obj _target ;
this . time _comp = BUL _TIMECOMPONENT ;
this . year _scroll = BUL _YEARSCROLL ;
// register in global collections
this . id = calendars . length ;
calendars [ this . id ] = this ;
}
function cal _popup1 ( str _datetime ) {
this . dt _current = this . prs _tsmp ( str _datetime ? str _datetime : this . target . value ) ;
if ( ! this . dt _current ) return ;
var obj _calwindow = window . open (
'calendar.html?datetime=' + this . dt _current . valueOf ( ) + '&id=' + this . id ,
'Calendar' , 'width=200,height=' + ( this . time _comp ? 215 : 190 ) +
',status=no,resizable=no,top=200,left=200,dependent=yes,alwaysRaised=yes'
) ;
obj _calwindow . opener = window ;
obj _calwindow . focus ( ) ;
}
// timestamp generating function
function cal _gen _tsmp1 ( dt _datetime ) {
return ( this . gen _date ( dt _datetime ) + ' ' + this . gen _time ( dt _datetime ) ) ;
}
// date generating function
function cal _gen _date1 ( dt _datetime ) {
return (
( dt _datetime . getDate ( ) < 10 ? '0' : '' ) + dt _datetime . getDate ( ) + "-"
+ ( dt _datetime . getMonth ( ) < 9 ? '0' : '' ) + ( dt _datetime . getMonth ( ) + 1 ) + "-"
+ dt _datetime . getFullYear ( )
) ;
}
// time generating function
function cal _gen _time1 ( dt _datetime ) {
return (
( dt _datetime . getHours ( ) < 10 ? '0' : '' ) + dt _datetime . getHours ( ) + ":"
+ ( dt _datetime . getMinutes ( ) < 10 ? '0' : '' ) + ( dt _datetime . getMinutes ( ) ) + ":"
+ ( dt _datetime . getSeconds ( ) < 10 ? '0' : '' ) + ( dt _datetime . getSeconds ( ) )
) ;
}
// timestamp parsing function
function cal _prs _tsmp1 ( str _datetime ) {
// if no parameter specified return current timestamp
if ( ! str _datetime )
return ( new Date ( ) ) ;
// if positive integer treat as milliseconds from epoch
if ( RE _NUM . exec ( str _datetime ) )
return new Date ( str _datetime ) ;
// else treat as date in string format
var arr _datetime = str _datetime . split ( ' ' ) ;
return this . prs _time ( arr _datetime [ 1 ] , this . prs _date ( arr _datetime [ 0 ] ) ) ;
}
// date parsing function
function cal _prs _date1 ( str _date ) {
var arr _date = str _date . split ( '-' ) ;
if ( arr _date . length != 3 ) return cal _error ( "Invalid date format: '" + str _date + "'.\nFormat accepted is dd-mm-yyyy." ) ;
if ( ! arr _date [ 0 ] ) return cal _error ( "Invalid date format: '" + str _date + "'.\nNo day of month value can be found." ) ;
if ( ! RE _NUM . exec ( arr _date [ 0 ] ) ) return cal _error ( "Invalid day of month value: '" + arr _date [ 0 ] + "'.\nAllowed values are unsigned integers." ) ;
if ( ! arr _date [ 1 ] ) return cal _error ( "Invalid date format: '" + str _date + "'.\nNo month value can be found." ) ;
if ( ! RE _NUM . exec ( arr _date [ 1 ] ) ) return cal _error ( "Invalid month value: '" + arr _date [ 1 ] + "'.\nAllowed values are unsigned integers." ) ;
if ( ! arr _date [ 2 ] ) return cal _error ( "Invalid date format: '" + str _date + "'.\nNo year value can be found." ) ;
if ( ! RE _NUM . exec ( arr _date [ 2 ] ) ) return cal _error ( "Invalid year value: '" + arr _date [ 2 ] + "'.\nAllowed values are unsigned integers." ) ;
var dt _date = new Date ( ) ;
dt _date . setDate ( 1 ) ;
if ( arr _date [ 1 ] < 1 || arr _date [ 1 ] > 12 ) return cal _error ( "Invalid month value: '" + arr _date [ 1 ] + "'.\nAllowed range is 01-12." ) ;
dt _date . setMonth ( arr _date [ 1 ] - 1 ) ;
if ( arr _date [ 2 ] < 100 ) arr _date [ 2 ] = Number ( arr _date [ 2 ] ) + ( arr _date [ 2 ] < NUM _CENTYEAR ? 2000 : 1900 ) ;
dt _date . setFullYear ( arr _date [ 2 ] ) ;
var dt _numdays = new Date ( arr _date [ 2 ] , arr _date [ 1 ] , 0 ) ;
dt _date . setDate ( arr _date [ 0 ] ) ;
if ( dt _date . getMonth ( ) != ( arr _date [ 1 ] - 1 ) ) return cal _error ( "Invalid day of month value: '" + arr _date [ 0 ] + "'.\nAllowed range is 01-" + dt _numdays . getDate ( ) + "." ) ;
return ( dt _date )
}
// time parsing function
function cal _prs _time1 ( str _time , dt _date ) {
if ( ! dt _date ) return null ;
var arr _time = String ( str _time ? str _time : '' ) . split ( ':' ) ;
if ( ! arr _time [ 0 ] ) dt _date . setHours ( 0 ) ;
else if ( RE _NUM . exec ( arr _time [ 0 ] ) )
if ( arr _time [ 0 ] < 24 ) dt _date . setHours ( arr _time [ 0 ] ) ;
else return cal _error ( "Invalid hours value: '" + arr _time [ 0 ] + "'.\nAllowed range is 00-23." ) ;
else return cal _error ( "Invalid hours value: '" + arr _time [ 0 ] + "'.\nAllowed values are unsigned integers." ) ;
if ( ! arr _time [ 1 ] ) dt _date . setMinutes ( 0 ) ;
else if ( RE _NUM . exec ( arr _time [ 1 ] ) )
if ( arr _time [ 1 ] < 60 ) dt _date . setMinutes ( arr _time [ 1 ] ) ;
else return cal _error ( "Invalid minutes value: '" + arr _time [ 1 ] + "'.\nAllowed range is 00-59." ) ;
else return cal _error ( "Invalid minutes value: '" + arr _time [ 1 ] + "'.\nAllowed values are unsigned integers." ) ;
if ( ! arr _time [ 2 ] ) dt _date . setSeconds ( 0 ) ;
else if ( RE _NUM . exec ( arr _time [ 2 ] ) )
if ( arr _time [ 2 ] < 60 ) dt _date . setSeconds ( arr _time [ 2 ] ) ;
else return cal _error ( "Invalid seconds value: '" + arr _time [ 2 ] + "'.\nAllowed range is 00-59." ) ;
else return cal _error ( "Invalid seconds value: '" + arr _time [ 2 ] + "'.\nAllowed values are unsigned integers." ) ;
dt _date . setMilliseconds ( 0 ) ;
return dt _date ;
}
function cal _error ( str _message ) {
alert ( str _message ) ;
return null ;
}
2012-10-18 17:00:03 +00:00