/***********************************************************************************************************************
 File		: CalendarInfo.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		: 12.01.06 (as part of CalendarNav.js)
 Author			: Kurt Schwedes, xtendo technologies
 Last Change	: 18.01.06; 16.01.06
.......................................................................................................................

 Informations for a day 

.......................................................................................................................
 Develeped for 	: xtendo technologies Kurt Schwedes, 76185 Karlsruhe, Germany
 Contact		: kurt.schwedes@xtendo.de
 Documentation 	: ---
***********************************************************************************************************************/

/*----------------------------------------------------------------------------------------------------------------------
 CLASS CONSTANTS/DEFINITIONS
----------------------------------------------------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------------------------------------------------
 CONSTRUCTOR OF CLASS, INHERITANCE
----------------------------------------------------------------------------------------------------------------------*/

function CalInfo (def)
{
	if (! def || typeof def != 'object') def = {};
	this.CLASS	= CalInfo;

	this.tmpl 			= def.tmpl 			|| null;
	this.container 		= def.container 	|| null;
	
	this.date 			= def.date 			|| new Date();
	this.filter			= def.filter 		|| {};
	this.fmtDate		= def.fmtDate		|| this.date.formats.date;
	this.stdValues		= def.stdValues 	|| {};
	this.weekly			= def.weekly		|| false;
	
	this._build();
	return this;
}

/*----------------------------------------------------------------------------------------------------------------------
 PUBLIC OBJECT METHODS
----------------------------------------------------------------------------------------------------------------------*/

CalInfo.prototype.create = function (d)
{
	with (this){
		if (tmpl && typeof tmpl == 'object' && tmpl.CLASS == window.TmplObj){
			if (d) date = d;
			
			tmpl.resetTokens();
			var t = tmpl.tokens;
			t.date = date.byFormat(fmtDate);
			
			var serial = weekly ? date.getWeekSerial() : date.getSerial();
			if (serial && CalInfo.Schedule[serial]){
				var ds = CalInfo.Schedule[serial];
				var unit = -1;
				for (var p in ds){
					unit = p;
					if (!filter || filter[p]) break;
				}
				if (unit > -1 && CalInfo.Units[unit]) {
					var oU = CalInfo.Units[unit];
					t.from 	 = ds[unit][0];
					t.till 	 = ds[unit][1];
					t.name   = oU[0];
					t.zip 	 = oU[1];
					t.city 	 = oU[2];
					t.street = oU[3];
					t.phone  = oU[4];
				}
			}
			for (var p in t)
				if (! t[p])
					t[p] = stdValues[p] || '';
			
			tmpl.output = '';
			tmpl.resolveTokens();

			if (container){
				container.innerHTML = tmpl.output;
				container.style.display = 'block'
			}
		}
	}
	return this;
}

CalInfo.prototype.hide = function (d)
{
	with (this){
		if (container)
			container.style.display = 'none'
	}
	return this;
}
/*----------------------------------------------------------------------------------------------------------------------
 PRIVATE OBJECT METHODS
----------------------------------------------------------------------------------------------------------------------*/

CalInfo.prototype._build = function ()
{
	with (this){
		if (tmpl && typeof tmpl == 'object' && tmpl.innerHTML){
			var t = tmpl;
			tmpl = new TmplObj({content: t.innerHTML});
			if (! container){
				container = t;
				t.innerHTML = '';
			}
		}
		if (! CalInfo.Units || typeof CalInfo.Units != 'object' || ! CalInfo.Units.length)
			CalInfo.Units = [];
		if (! CalInfo.Schedule || typeof CalInfo.Schedule != 'object' || CalInfo.Schedule.length)
			CalInfo.Schedule = {};			
	}
	return this;
}

/*----------------------------------------------------------------------------------------------------------------------
 PRIVATE EVENT HANDLER
----------------------------------------------------------------------------------------------------------------------*/





