/***********************************************************************************************************************
 File		: CalendarNav.js
 File Type	: Javascript (IE5.5ff, NS6ff, Firefox 1.5ff)

 Copyright 	: xtendo technologies Kurt Schwedes & Ralf Ziegler GbR, 76185 Karlsruhe, Germany
		      All rights reserved
.......................................................................................................................
 Created		: 31.03.2004 (as Calendar.js in xtWS031201)
 Author			: Kurt Schwedes, xtendo technologies
 Last Change	: 16.01.06
.......................................................................................................................

 Support Code for Index.html

.......................................................................................................................
 Develeped for 	: xtendo technologies Kurt Schwedes, 76185 Karlsruhe, Germany
 Contact		: kurt.schwedes@xtendo.de
 Documentation 	: ---
***********************************************************************************************************************/

/*----------------------------------------------------------------------------------------------------------------------
 CLASS CONSTANTS/DEFINITIONS
----------------------------------------------------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------------------------------------------------
 CONSTRUCTOR OF CLASS, INHERITANCE
----------------------------------------------------------------------------------------------------------------------*/

function CalNav (def)
{
	if (! def || typeof def != 'object') def = {};
	this.CLASS	= CalNav;
	
	this.calendar		= def.calendar 		|| null;
	this.info			= def.info	 		|| null;
	
	this.btnNext		= def.btnNext 		|| null;
	this.btnNow			= def.btnNow 		|| null;
	this.btnPrevious	= def.btnPrevious 	|| null;

	this.cssHover		= def.cssHover 		|| '';
	this.cssSelect	 	= def.cssSelect		|| '';
	
	this.selected		= null;
	
	this._build();
	return this;
}

/*----------------------------------------------------------------------------------------------------------------------
 PRIVATE OBJECT METHODS
----------------------------------------------------------------------------------------------------------------------*/

CalNav.prototype._build = function ()
{
	with (this){
		if (btnPrevious && typeof btnPrevious == 'object'){
			btnPrevious.navObj = this;
			btnPrevious.name = 'L';
			btnPrevious.enable = function (){
				btnPrevious.className = 'L0';
				btnPrevious.onmouseover = CalNav.highlightNav;
				btnPrevious.onmouseout = CalNav.normalizeNav;
				btnPrevious.onmouseup = CalNav.showPreviousMonth;
				btnPrevious.title = 'Vorhergehenden Monat zeigen';
			}
			
			btnPrevious.disable = function (){
				btnPrevious.className = 'L';
				btnPrevious.onmouseover = btnPrevious.onmouseout = btnPrevious.onmouseup = null;
				btnPrevious.title = 'Für den vorhergehenden Monat sind keine Daten mehr verfügbar!';
			}
			
			btnPrevious.enable();
		}
		
		if (btnNext && typeof btnNext == 'object'){
			btnNext.navObj = this;
			btnNext.name = 'R';
			btnNext.enable = function (e){
				btnNext.className = 'R0';
				btnNext.onmouseover = CalNav.highlightNav;
				btnNext.onmouseout = CalNav.normalizeNav;
				btnNext.onmouseup = CalNav.showNextMonth;
				btnNext.title = 'Nächsten Monat zeigen';
			}
				
			btnNext.disable = function (){
				btnNext.className = 'R';
				btnNext.onmouseover = btnNext.onmouseout = btnNext.onmouseup = null;
				btnNext.title = 'Für den nächsten Monat sind noch keine Daten verfügbar!';
			}
			
			btnNext.enable();
		}
		
		if (btnNow && typeof btnNow == 'object'){
			btnNow.navObj = this;
			btnNow.name = 'Today';
			btnNow.onmouseover = CalNav.highlightNav;
			btnNow.onmouseout = CalNav.normalizeNav;
			btnNow.onmouseup = CalNav.showToday;
			btnNow.title = 'Notdienst für den heutigen Tag anzeigen';
		}

		if (calendar && typeof calendar == 'object' && calendar.CLASS == window.ACTB){
			var c = calendar.container;
			if (c){
				this.checkDateField = new RegExp(calendar.prefixId + '(\\d+)|' + calendar.todayId);
				c.navObj = this;
				c.onmouseup = CalNav.selectDay;
				c.onmouseover = CalNav.highlightDay ;
				c.onmouseout = CalNav.normalizeDay;
			}
		}
	}
	return this;
}

CalNav.prototype._getElement = function (moz)
{
	var ev = moz ? moz : window.event;
	var E = moz ? ev.target : ev.srcElement;
	with (this)
		return E.tagName == 'TD' && E.id && E.id.match(checkDateField) ? E : null;
}

/*----------------------------------------------------------------------------------------------------------------------
 PRIVATE EVENT HANDLER
----------------------------------------------------------------------------------------------------------------------*/

CalNav.highlightNav = function ()
{
	with (this)
		className = name + '1';
}

CalNav.normalizeNav = function ()
{
	with (this)
		className = name + '0';
}

CalNav.showPreviousMonth = function ()
{
	with (this.navObj){
		if (info)
			info.hide();
		if (calendar)
			calendar.showPrevious();
	}
}

CalNav.showNextMonth = function ()
{
	with (this.navObj){
		if (info)
			info.hide();
		if (calendar)
			calendar.showNext();
	}
}

CalNav.showToday = function ()
{
	with (this.navObj){
		if (info){
			info.hide();
			info.create(TODAY);
		}
		if (calendar)
			calendar.showToday();
	}
}

CalNav.selectDay = function (moz)
{
	with (this.navObj){
		var E = _getElement(moz);
		if (E && info){
			var d = calendar.date;
			if (selected && selected.stdClassName)
				selected.className = selected.stdClassName;
			if (cssSelect){
				if (! E.stdClassName) E.stdClassName = E.className;
				E.className = cssSelect;
			}
			selected = E;
			info.create(RegExp.$1 ? new Date(d.getFullYear(), d.getMonth(), RegExp.$1) : TODAY);
		}
	}
}

CalNav.highlightDay = function (moz) {
	with (this.navObj){
		var E = _getElement(moz);
		if (E && cssHover && selected != E){
			E.stdClassName = E.className;
			E.className = cssHover;
		}
	}
}

CalNav.normalizeDay = function (moz) {
	var E = this.navObj._getElement(moz);
	if (E && E.stdClassName && this.navObj.selected != E)
		E.className = E.stdClassName;
}


