function hssDateCtrl()
{
	this.objHidden = null;
	this.objDay = null;
	this.objMonthYear = null;
	this.arMonth = new Array('', 
					'Januar', 'Februar', 'März', 'April', 'Mai', 'Juni',
					'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember' );
	this.arDays  = new Array(0, 31, 28, 31, 30, 31, 30, 
					            31, 31, 30, 31, 30, 31 );
	this.dNow = null;
					
	this.Attach = function( oHidden, oDay, oMonthYear)
	{
		this.objHidden    = oHidden;
		this.objDay       = oDay;
		this.objMonthYear = oMonthYear;
		this.dNow  = new Date();
	}
	
	this.IsLeap = function(y)
	{
		
		if( parseInt(y) == 2008 ) return true;
		if( parseInt(y) == 2012 ) return true;
		if( parseInt(y) == 2016 ) return true;
		if( parseInt(y) == 2020 ) return true;
		if( parseInt(y) == 2024 ) return true;
		return false;
	}
	
	this.SetGerman = function()
	{
		this.arMonth = new Array('', 
						'Januar', 'Februar', 'März', 'April', 'Mai', 'Juni',
						'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember' );
	}

	this.SetNetherland = function()
	{
		this.arMonth = new Array('',
			'januari',			'februari',			'maart',			'april',			'mei',			'juni',
			'juli',			'augustus',			'september',			'oktober',			'november',	'december' );
	}

	this.SetAustria = function()
	{
		this.arMonth = new Array('', 
						'Jänner', 'Februar', 'März', 'April', 'Mai', 'Juni',
						'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember' );
	}
	
	this.SetCzech = function()
	{
		this.arMonth = new Array('', 
						'leden', 'únor', 'březen', 'duben', 'květen', 'červen',
						'červenec', 'srpen', 'září', 'říjen', 'listopad', 'prosinec' );
	}
	
	
	this.SetStartDay = function(sDate)
	{
		sDate = sDate.replace(/-/, ".");  sDate = sDate.replace(/-/, ".");
		
		p1    = sDate.indexOf(".");
		maxTT = sDate.substr(0, p1 ) * 1;
		sDate = sDate.substr( p1+1, 10 );
		
		p1    = sDate.indexOf(".");
		maxMM = sDate.substr(0,p1) * 1 - 1;
		maxYY = sDate.substr( p1+1, 10 ) * 1;

		this.dNow  = new Date(maxYY, maxMM, maxTT);
	}
	
	this.FillMonth = function(sDate)
	{
		sDate = sDate.replace(/-/, ".");  sDate = sDate.replace(/-/, ".");
		
		p1    = sDate.indexOf(".");
		maxTT = sDate.substr(0, p1 ) * 1;
		sDate = sDate.substr( p1+1, 10 );
		
		p1    = sDate.indexOf(".");
		maxMM = sDate.substr(0,p1) * 1;
		maxYY = sDate.substr( p1+1, 10 ) * 1;
		
		CurYear = this.dNow.getUTCFullYear();
		 
		CurMonth = this.dNow.getMonth() + 1; // 0=januar  also +1 !!!
		
	
		y = CurYear;
		for( m = CurMonth; m <= 12; m++)
		{
			if( y < maxYY || y==maxYY && m <= maxMM )
			{
				s1 = this.arMonth[ m ] + " " + y;
				if( m < 10 )
					s2 = "0" + m + "." + y;
				else
					s2 = m + "." + y;
				
				NeuerEintrag = new Option(s1 , s2, false, false);
				this.objMonthYear.options[this.objMonthYear.options.length] = NeuerEintrag;
			}
			else
				break;
			
			if( m == 12 ) 
			{
				m = 0;	y++;
			}
		}
		
		//Fill Days
		this.SelChangeMonthYear();
	}
	
	this.BuildAndSetDate = function()
	{
		tt = this.objDay.value;
		if( tt.length < 2 ) tt = "0" + tt;
		mm_yy =this.objMonthYear.value;
		
		this.objHidden.value = tt + "." + mm_yy;
	}
	
	this.FillDays = function(m,y)
	{
		oldDay = this.objDay.value;
		
		while( this.objDay.length > 0 )	this.objDay.options[0] = null;
		
		maxDD = this.arDays[ m * 1 ];
		if( maxDD == 28 && this.IsLeap(y) == true )
			maxDD = 29;
			
		bSet = false;
		for( d = 1; d <= maxDD; ++d)
		{
			if( oldDay == d )
			{
				bSet = true;
				this.objDay.options[ this.objDay.options.length ] = new Option( d, d, false, true );
			}
			else
				this.objDay.options[ this.objDay.options.length ] = new Option( d, d, false, false );
		}
		if( bSet == false )
			this.objDay.options[0].selected = true;
		
		//this.objDay.value = oldDay;
	}
	
	this.SelectDay = function(sDate)
	{
		sDateAll = sDate;
		sDate = sDate.replace(/-/, ".");  sDate = sDate.replace(/-/, ".");
		p1    = sDate.indexOf(".");
		maxTT = sDate.substr(0, p1 ) * 1;
		sDate = sDate.substr( p1+1, 10 );
		
		p1    = sDate.indexOf(".");
		maxMM = sDate.substr( 0, p1 );
		maxYY = sDate.substr( p1+1, 10 );
		
		if( maxMM.length < 2 )
		{
			this.objMonthYear.value = "0" + maxMM + "." + maxYY;
		}
		else
		{
			this.objMonthYear.value = maxMM + "." + maxYY;
		}
		this.objDay.value    = maxTT; 
		this.objHidden.value = sDateAll;
		this.FillDays( maxMM, maxYY );
		this.objDay.value    = maxTT; 
	}
	
	this.SelChangeMonthYear = function()
	{
		my = this.objMonthYear.value;
		p = my.indexOf('.');
		m = my.substr(0, p);
		y = my.substr(p+1, 10);
		this.FillDays(m,y);
		this.BuildAndSetDate();
	}
	
	this.SelChangeDay = function()
	{
		this.BuildAndSetDate();
	}
	
	this.CalendarOpen = function()
	{
		
	}
	
	this.SelectMonthItem = function(i)
	{
		if( i >= 0 )
		{
			this.objMonthYear.selectedIndex = i;
			s = "01." + this.objMonthYear.options[i].value;
			this.SelectDay( s );
		}
		else if( i == -1)
		{
			this.objMonthYear.selectedIndex = this.objMonthYear.options.length - 1;
			s = "01." + this.objMonthYear.options[this.objMonthYear.options.length - 1].value;
			this.SelectDay( s );
		}
	}
	
	
	this.SelectTodayOffset = function(tt_offset, mm_offset, sDATESEP_DISP)
	{
		var heute = new Date();
		
		var oneday = 1000*60*60*24;			//--- ein Tag in Milisekunden
		var tt_ms = oneday * tt_offset;
		var dtheute1 = new Date( heute.getTime() + tt_ms);
		
		if( mm_offset != 0 )
		{
			var tt1 = dtheute1.getDate();
			var mm1 = dtheute1.getMonth() + 1;
			var yy1 = dtheute1.getUTCFullYear();
			
			mm2 = mm1 * 1 + mm_offset * 1;
			if( mm2 > 12 ) 
			{
				mm2 = mm2 - 12;
				yy1++;
			}
			
			if( mm2 == 2  && this.IsLeap(yy1) == false && tt1 > 28)
				tt1 = 28;
			else if( tt1 == 31 && (mm2 == 2 || mm2 == 4 || mm2 == 6 || mm2 == 9 || mm2 == 11) )
				tt1 = 30;
			
			dtheute1 = new Date( yy1, mm2-1, tt1 );
		}
		
		sTo = "";
		sTo = sTo + dtheute1.getDate();
		sTo = sTo.concat( sDATESEP_DISP );
		
		if( dtheute1.getMonth() + 1 < 10 )
			sTo = sTo + "0";
		sTo = sTo.concat( dtheute1.getMonth() + 1 );
		sTo = sTo.concat( sDATESEP_DISP );
		
		if( dtheute1.getUTCFullYear() < 10 )
			sTo = sTo + "0";	
		sTo = sTo.concat( dtheute1.getUTCFullYear() );
		
		if( this.objHidden != null && this.objDay != null && this.objMonthYear != null )
			this.SelectDay(sTo);
		return sTo;
	}
}	

