/**
 * Naptár készítő.
 * 
 * @author sassas (Kaprf Andras)
 * @since 0.1 - 2008.02.05.
 * @since 0.2 - 2008.02.07.
 * @since 0.3 - 2008.02.11. keyControl()
 * @since 0.4 - 2008.02.14. maxEv,maxHo,maxNap
 * @vesion 0.4
 */

/**
 * Az első három paraméter megadása kötelező
 * @param ev obj
 * @param ho obj
 * @param nap obj
 * @param minEv string
 * @param minHo string
 * @param minNap string
 * @return naptár forraskodja
 * @access public
 */
function Naptar(ev,ho,nap,minEv,minHo,minNap,maxEv,maxHo,maxNap) {
	//debug
	this.debug = false;
	
	try {
		//import
		this.ClassName = new ClassName();
		//set
		this.iframe = null;
		this.ieBug  = false;
		this.userAgent = navigator.userAgent.toLowerCase();
		if ( document.all && this.userAgent.indexOf("opera") < 0 &&  this.userAgent.indexOf("msie 7") < 0 ) {
			this.ieBug = true;
		}
		this.cel = ev;
		this.targetEv = ev;
		this.targetHo = ho;
		this.targetNap = nap;
		this.minEv = minEv;
		this.minHo = minHo;
		this.minNap = minNap;
		this.MinimumDatum = new Date( Number(this.minEv) ,Number(this.minHo) - 1, Number(this.minNap));
		this.maxEv = maxEv;
		this.maxHo = maxHo;
		this.maxNap = maxNap;
		this.MaximumDatum = new Date( Number(this.maxEv) ,Number(this.maxHo) - 1, Number(this.maxNap));
		this.mostEv;
		this.mostHo;
		this.mostNap;
		this.aktivNap = null;
		if ( this.targetEv.value == '' ) {
			this.Calendar = new Date();
		} else {
			if (this.targetHo.value == '') this.targetHo.value =  '01';
			if (this.targetNap.value == '') this.targetNap.value = '01';
			this.Calendar = new Date(this.targetEv.value,this.targetHo.value,this.targetNap.value);
		}
		this.year = this.Calendar.getFullYear();
		if ( this.targetHo.value.length == 0 ) {
			this.month = Number(this.Calendar.getMonth());
		} else {
			this.month = Number(this.Calendar.getMonth()) - 1;
		}
		if (this.month == -1) this.month = 11;
		this.today = this.Calendar.getDate();
		this.weekday = this.Calendar.getDay();		
		this.napok = new Array(6,0,1,2,3,4,5);
		this.day_of_week = new Array('V','H','K','Sze','Cs','P','Szo','V');
		this.month_of_year = new Array('Január','Február','Március','Április','Május','Június','Július','Augusztus','Szeptember','Október','November','December');
		this.DAYS_OF_WEEK = 7;
		this.DAYS_OF_MONTH = 31;
		this.isDrag = false;
		this.firstScrollPozX = 0;
		this.firstScrollPozY = 0;		
		//create
		this.naptar = this.createCelendar();
		this.intervalID;
		this.aktivTD = null;
		this.elozoTD = null;
		this.kovetkezoTD = null;
		//event
		EventListener.addEvent(this.naptar, 'click', this.scope('handleClick'));
		//EventListener.addEvent(this.naptar, 'mousedown', this.scope('startDrag'));
		//EventListener.addEvent(document, 'mousemove', this.scope('drag'));
		//EventListener.addEvent(document, 'mouseup', this.scope('endDrag'));
		EventListener.addEvent(document, 'keyup', this.scope('keyControl'));
		EventListener.addEvent(this.targetEv, 'keyup', this.scope('inputListener'));
		EventListener.addEvent(this.targetHo, 'change', this.scope('inputListener'));
		EventListener.addEvent(this.targetNap, 'keyup', this.scope('inputListener'));
		EventListener.addEvent(this.naptar, 'mouseover', this.scope('handleOver'));
		EventListener.addEvent(this.naptar, 'mouseout', this.scope('handleOut'));		
	} catch ( exception ) {
		if ( this.debug ) alert('Naptar.construct()' + ' - ' + exception.message);
		return null;
	}
}

Naptar.prototype = {
	scope:function(method) {
		var scope = this;
		return function() {
			scope[method].apply(scope, arguments);
		}
	},
		
	getNaptarNodes:function(aktivTD) {
		try{
			var honapSorok = 0;
			var honpaSorLehet=false;
			var trs = this.naptar.getElementsByTagName("tr"); 
			for (var i = 0; i < trs.length; i++) { 
				var tds = trs[i].getElementsByTagName("td"); 
				if ( honpaSorLehet ) {
					honapSorok++;
					for (var j = 0; j < tds.length; j++) { 
						if ( tds[j] == aktivTD ) {
							return {tr:i,td:j}	
						}
					}
				}
				if (trs[i].id=="napszakok") {
					honpaSorLehet = true;
				}
			}
		} catch ( exception ) {
			if ( this.debug ) alert('Naptar.getNaptarNodes()' + ' - ' + exception.message);
			return null;
		}
	},
	
	keyControl:function(e) {
		try{
			
			if ( !this.naptar ) return;
			//else this.naptar.focus();
			
			var esc = 27;
			var fel = 38;
			var le = 40;
			var bal = 37;
			var jobb = 39;
			var enter = 13;
			
			if ( !this.aktivTD ) this.aktivTD = document.getElementById('aktivnap');
			var aktiv = this.getNaptarNodes(this.aktivTD);
			var trSorszam = aktiv.tr;
			var tdSorszam = aktiv.td;
			this.aktivTD = this.naptar.getElementsByTagName("tr")[trSorszam].getElementsByTagName("td")[tdSorszam];
			
			if ( e.keyCode == enter ) {
				if ( this.isAlowedDate( this.aktivTD, 'min' ) && this.minEv != '' ) {
					alert('Nem lehet korábbi dátum, mint '+ this.minEv + ' ' + this.month_of_year[Number(this.minHo)-1].toLowerCase()  + ' ' +  this.minNap +'!');
					return;
				}
				if ( this.isAlowedDate( this.aktivTD, 'max' ) && this.maxEv != '' ) {
					alert('Nem lehet későbbi dátum, mint '+ this.maxEv + ' ' + this.month_of_year[Number(this.maxHo)-1].toLowerCase()  + ' ' +  this.maxNap +'!');
					return;
				}
				
				this.targetEv.value = this.mostEv;
				if ( Number(this.mostHo + 1) < 10 ) {
					this.targetHo.value = '0' + String(this.mostHo + 1);
				} else {
					this.targetHo.value = String(this.mostHo + 1);
				}
				this.targetNap.value = this.mostNap;
				this.removeCelendar();	
				return EventListener.cancelEvent(e);
			}
			
			if ( e.keyCode == esc ) {
				this.removeCelendar();
				return EventListener.cancelEvent(e);
			}
				
			if ( e.keyCode == fel ) {
				//előző
				trSorszam--;
				this.elozoTD = this.naptar.getElementsByTagName("tr")[trSorszam].getElementsByTagName("td")[tdSorszam];
				//alert(Number(this.elozoTD.innerHTML));
				if ( !this.elozoTD || this.elozoTD.innerHTML=='' || isNaN(Number(this.elozoTD.innerHTML)) ) {
					return EventListener.cancelEvent(e);
				} else {
					if( this.ClassName.hasClass(this.elozoTD, 'naptar_nap_bg') ) {
						if ( this.isAlowedDate(this.elozoTD, 'min') && this.minEv != '' ) {
							this.ClassName.addClass(this.elozoTD, 'naptar_nap_bg_hiba');
						}
						if ( this.isAlowedDate(this.elozoTD, 'max') && this.maxEv != '' ) {
							this.ClassName.addClass(this.elozoTD, 'naptar_nap_bg_hiba');
						}
						this.ClassName.removeClass(this.elozoTD, 'naptar_nap_bg');
						this.ClassName.addClass(this.elozoTD, 'naptar_nap_bg_over');
					}
					this.ClassName.removeClass(this.aktivTD, 'naptar_nap_bg_hiba');
					this.ClassName.removeClass(this.aktivTD, 'naptar_nap_bg_over');
					this.ClassName.addClass(this.aktivTD, 'naptar_nap_bg');
					this.aktivTD = this.elozoTD;
				}
				return EventListener.cancelEvent(e);
			}
			
			if ( e.keyCode == bal) {
				
				//előző
				if (tdSorszam == 0) {
					tdSorszam=6;
					trSorszam--;
				}  else {
					tdSorszam--;
				}
				this.elozoTD = this.naptar.getElementsByTagName("tr")[trSorszam].getElementsByTagName("td")[tdSorszam];
				
				if ( !this.elozoTD || this.elozoTD.innerHTML=='' ) {
					return EventListener.cancelEvent(e);
				} else {
					if( this.ClassName.hasClass(this.elozoTD, 'naptar_nap_bg') ) {
						if ( this.isAlowedDate(this.elozoTD, 'min') && this.minEv != '' ) {
							this.ClassName.addClass(this.elozoTD, 'naptar_nap_bg_hiba');
						}
						if ( this.isAlowedDate(this.elozoTD, 'max') && this.maxEv != '' ) {
							this.ClassName.addClass(this.elozoTD, 'naptar_nap_bg_hiba');
						}
						this.ClassName.removeClass(this.elozoTD, 'naptar_nap_bg');
						this.ClassName.addClass(this.elozoTD, 'naptar_nap_bg_over');
					}
					this.ClassName.removeClass(this.aktivTD, 'naptar_nap_bg_hiba');
					this.ClassName.removeClass(this.aktivTD, 'naptar_nap_bg_over');
					this.ClassName.addClass(this.aktivTD, 'naptar_nap_bg');
					this.aktivTD = this.elozoTD;
				}
				return EventListener.cancelEvent(e);
			}
			
			if ( e.keyCode == le) {
				//következő
				trSorszam++;
				this.kovetkezoTD = this.naptar.getElementsByTagName("tr")[trSorszam].getElementsByTagName("td")[tdSorszam];

				if ( !this.naptar.getElementsByTagName("tr")[trSorszam] ) {	
					return EventListener.cancelEvent(e);
				} else if ( !this.kovetkezoTD || this.kovetkezoTD.innerHTML=='' || isNaN(Number(this.kovetkezoTD.innerHTML)) ) {
					return EventListener.cancelEvent(e);
				} else {
					if( this.ClassName.hasClass(this.kovetkezoTD, 'naptar_nap_bg') ) {
						if ( this.isAlowedDate(this.kovetkezoTD, 'min') && this.minEv != '' ) {
							this.ClassName.addClass(this.kovetkezoTD, 'naptar_nap_bg_hiba');
						}
						if ( this.isAlowedDate(this.kovetkezoTD, 'max') && this.maxEv != '' ) {
							this.ClassName.addClass(this.kovetkezoTD, 'naptar_nap_bg_hiba');
						}
						this.ClassName.removeClass(this.kovetkezoTD, 'naptar_nap_bg');
						this.ClassName.addClass(this.kovetkezoTD, 'naptar_nap_bg_over');
					}
					this.ClassName.removeClass(this.aktivTD, 'naptar_nap_bg_hiba');
					this.ClassName.removeClass(this.aktivTD, 'naptar_nap_bg_over');
					this.ClassName.addClass(this.aktivTD, 'naptar_nap_bg');
					this.aktivTD = this.kovetkezoTD;
				}
				return EventListener.cancelEvent(e);
			}
			
			if ( e.keyCode == jobb) {
				
				//következő
				if (tdSorszam == 6) {
					tdSorszam=0;
					trSorszam++;
				}  else {
					tdSorszam++;
				}
				this.kovetkezoTD = this.naptar.getElementsByTagName("tr")[trSorszam].getElementsByTagName("td")[tdSorszam];
				
				if ( !this.kovetkezoTD || this.kovetkezoTD.innerHTML=='' ) {
					return EventListener.cancelEvent(e);
				} else {
					if( this.ClassName.hasClass(this.kovetkezoTD, 'naptar_nap_bg') ) {
						if ( this.isAlowedDate(this.kovetkezoTD, 'min') && this.minEv != '' ) {
							this.ClassName.addClass(this.kovetkezoTD, 'naptar_nap_bg_hiba');
						}
						if ( this.isAlowedDate(this.kovetkezoTD, 'max') && this.maxEv != '' ) {
							this.ClassName.addClass(this.kovetkezoTD, 'naptar_nap_bg_hiba');
						}
						this.ClassName.removeClass(this.kovetkezoTD, 'naptar_nap_bg');
						this.ClassName.addClass(this.kovetkezoTD, 'naptar_nap_bg_over');
					}
					this.ClassName.removeClass(this.aktivTD, 'naptar_nap_bg_hiba');
					this.ClassName.removeClass(this.aktivTD, 'naptar_nap_bg_over');
					this.ClassName.addClass(this.aktivTD, 'naptar_nap_bg');
					this.aktivTD = this.kovetkezoTD;
				}
				return EventListener.cancelEvent(e);
			}	
			
		} catch ( exception ) {
			if ( this.debug ) alert('Naptar.keyControl()' + ' - ' + exception.message);
			return EventListener.cancelEvent(e);
		}
	},
	
	inputListener:function(e) {
		if ( !this.naptar ) return;
		var target = e.target || e.srcElement;
		
		if ( this.targetEv == target && target.value.length == 4 && this.naptar ) {
			this.year=Number(target.value); 
			this.createCelendar();
		}
		if ( this.targetHo == target && this.naptar ) {
			this.month=Number(target.options[target.selectedIndex].value) - 1; 
			this.createCelendar();
		}
		if ( this.targetNap == target && target.value.length >= 1 && this.naptar ) {
			this.today=Number(target.value); 
			this.createCelendar();
		}
		//esemény törlése
		return EventListener.cancelEvent(e);
	},
		
	handleClick:function(e) {
		try {
			if ( !this.naptar ) return;
			var target = e.target || e.srcElement;
			if(/^img$/i.test(target.nodeName) && this.ClassName.hasClass(target, 'naptar_x')) {
				this.removeCelendar();
			}
			
			if(/^td$/i.test(target.nodeName) && this.ClassName.hasClass(target, 'naptar_nap_bg_over')) {
				if ( this.minEv != '' ) {
					if ( this.isAlowedDate(target, 'min') ) {
						alert('Nem lehet korábbi dátum, mint '+ this.minEv + ' ' + this.month_of_year[Number(this.minHo)-1].toLowerCase()  + ' ' +  this.minNap +'!');
						return;
					}
					if ( this.isAlowedDate(target, 'max' ) ) {
						alert('Nem lehet későbbi dátum, mint '+ this.maxEv + ' ' + this.month_of_year[Number(this.maxHo)-1].toLowerCase()  + ' ' +  this.maxNap +'!');
						return;
					}
				}
				this.targetEv.value = this.mostEv;
				if ( Number(this.mostHo + 1) < 10 ) {
					this.targetHo.value = '0' + String(this.mostHo + 1);
				} else {
					this.targetHo.value = String(this.mostHo + 1);
				}
				this.targetNap.value = this.mostNap;
				this.removeCelendar();
			}
	
			if(/^td$/i.test(target.nodeName) && this.ClassName.hasClass(target, 'naptar_k_ho')) {
				this.kovetkezoHo();
			}
			
			if(/^td$/i.test(target.nodeName) && this.ClassName.hasClass(target, 'naptar_k_ev')) {
				this.kovetkezoEv();
			}
			
			if(/^td$/i.test(target.nodeName) && this.ClassName.hasClass(target, 'naptar_e_ho')) {
				this.elozoHo();
			}
			
			if(/^td$/i.test(target.nodeName) && this.ClassName.hasClass(target, 'naptar_e_ev')) {
				this.elozoEv();
			}
			
			//esemény törlése
			return EventListener.cancelEvent(e);
		} catch ( exception ) {
			if ( this.debug ) alert('Naptar.handleClick()' + ' - ' + exception.message);
			return null;
		}
	},
	
	kovetkezoEv:function() {
		this.year++;
		this.createCelendar();
	},
	
	kovetkezoHo:function() {
		if ( this.month < 11 ) {
			this.month++;
			this.createCelendar();
		} else {
			this.month=0;
			this.kovetkezoEv();
		}
	},
	
	elozoEv:function() {
		this.year--;
		this.createCelendar();
	},
	
	elozoHo:function() {
		if ( this.month >= 1 ) {
			this.month--;
			this.createCelendar();
		} else {
			this.month=11;
			this.elozoEv();
		}
	},
	
	isAlowedDate:function(target, type){
			this.mostEv = Number(this.year);
			this.mostHo = Number(this.month);
			var eloszam = '';
			if (target.lastChild.nodeValue.length == 1) eloszam = '0';
			this.mostNap = eloszam + String(target.lastChild.nodeValue);	
			if (type == 'min') {
				if ( this.datumOsszehasonlito(this.MinimumDatum, new Date(this.mostEv,this.mostHo,this.mostNap)) ) {
					return true;
				}
			} else if (type == 'max') {
				if ( this.datumOsszehasonlito(new Date(this.mostEv,this.mostHo,this.mostNap), this.MaximumDatum) ) {
					return true;
				}
			}
			return false;
	},
	
	datumOsszehasonlito:function(elotteDatum,utanaDatum) {
		var hiba = false;
		var elotteDate = elotteDatum.getTime();
		var utanaDate = utanaDatum.getTime();
		if( utanaDate-elotteDate < 0 ) hiba = true;
		return hiba;
	},
	
	handleOver:function(e) {
		try {
			if ( !this.naptar ) return;
			var target = e.target || e.srcElement;
			if( this.ClassName.hasClass(target, 'naptar_nap_bg') ) {
				if ( this.ClassName.hasClass(target, 'naptar_aktivnap_bg') ) {
					this.aktivNap = target;
					this.ClassName.removeClass(target, 'naptar_aktivnap_bg');
				}
				if ( this.isAlowedDate(target, 'min') && this.minEv != '' ) {
					this.ClassName.addClass(target, 'naptar_nap_bg_hiba');
				}
				if ( this.isAlowedDate(target, 'max') && this.maxEv != '' ) {
					this.ClassName.addClass(target, 'naptar_nap_bg_hiba');
				}
				this.ClassName.removeClass(target, 'naptar_nap_bg');
				this.ClassName.addClass(target, 'naptar_nap_bg_over');
			}
		} catch ( exception ) {
			if ( this.debug ) alert('Naptar.handleOver()' + ' - ' + exception.message);
			return null;
		}
	},
	
	handleOut:function(e) {
		try {
			if ( !this.naptar ) return;
			var target = e.target || e.srcElement;
			this.ClassName.removeClass(target, 'naptar_nap_bg_hiba');
			if( this.ClassName.hasClass(target, 'naptar_nap_bg_over') ) {
				this.ClassName.removeClass(target, 'naptar_nap_bg_over');
				this.ClassName.addClass(target, 'naptar_nap_bg');
			}
			if ( this.aktivNap ) {
				this.ClassName.addClass(this.aktivNap, 'naptar_aktivnap_bg');
				this.aktivNap = null;
			}
		} catch ( exception ) {
			if ( this.debug ) alert('Naptar.handleOut()' + ' - ' + exception.message);
			return null;
		}
	},
	
	/*
	Ez az esemény akkor következik be, ha lenyomjuk a baloldali egérgombot.
	*/	
	startDrag:function(e) {
		try {
			
			//tényleges forrás objectum megkapása
			var target = e.target || e.srcElement;
			
			//ha li mezobe kattintottunk, elmentjuk a forrás objectumot, és a parent li-t
			if( this.ClassName.hasClass(target, 'naptar_drag_fejlec') ) {
				this.isDrag = true;
			}
			
			if( this.ClassName.hasClass(target, 'naptar_k_ev') ) {
				this.intervalID = setInterval(this.scope('kovetkezoEv'), 200);
			}
			if( this.ClassName.hasClass(target, 'naptar_k_ho') ) {
				this.intervalID = setInterval(this.scope('kovetkezoHo'), 400);
			}
			if( this.ClassName.hasClass(target, 'naptar_e_ev') ) {
				this.intervalID = setInterval(this.scope('elozoEv'), 200);
			}
			if( this.ClassName.hasClass(target, 'naptar_e_ho') ) {
				this.intervalID = setInterval(this.scope('elozoHo'), 400);
			}

			var poz = this.localToGlobal(this.naptar);
			this.firstScrollPozX = Math.abs(e.clientX - poz.x);
			this.firstScrollPozY = Math.abs(e.clientY - poz.y);
			
			//esemény törlése
			return EventListener.cancelEvent(e);
		} catch ( exception ) {
			if ( this.debug ) alert('Naptar.startDrag()' + ' - ' + exception.message);
			return null;
		}
	},
	
	/*
	Ez az esemény akkor következik be, ha van kijelölt objektum, ami this.dragTarget van elmentve.
	*/	
	drag:function(e) {
		try {
			if(!this.isDrag) return;
			
			var scrollpoz = this.getScrollPoz();
			this.naptar.style.left = String( Math.min (Math.max(e.clientX - this.firstScrollPozX + scrollpoz.x, scrollpoz.x), (document.documentElement.clientWidth - this.naptar.offsetWidth) )) +'px';
			this.naptar.style.top = String( Math.min (Math.max(e.clientY - this.firstScrollPozY + scrollpoz.y, scrollpoz.y), (document.documentElement.clientHeight - this.naptar.offsetHeight + scrollpoz.y) )) +'px';
			if ( this.ieBug ) {
				this.iframe.style.left = this.naptar.style.left;	
				this.iframe.style.top = this.naptar.style.top;
			}
			//esemény törlése
			return EventListener.cancelEvent(e);
		} catch ( exception ) {
			if ( this.debug ) alert('Naptar.drag()' + ' - ' + exception.message);
			return null;
		}
	},
					
	/*
	Ez az esemény akkor következik be, ha felemeljük a baloldali egérgombot.
	*/		
	endDrag:function(e) {
		try {
			
			if(this.intervalID>0) clearTimeout(this.intervalID);
			
			if(!this.isDrag) return;
					
			this.isDrag=false;
			
			//esemény törlése
			return EventListener.cancelEvent(e);
		} catch ( exception ) {
			if ( this.debug ) alert('Naptar.endDrag()' + ' - ' + exception.message);
			return null;
		}		
	},
	
	removeCelendar:function() {
		try {
			if ( !this.naptar ) return;
			document.body.removeChild(this.naptar);
			if ( this.ieBug ) {
				document.body.removeChild(this.iframe);
			}
			this.naptar = null;
			if (this.targetEv.value == '') {
				this.targetEv.focus();
			} else {
				this.targetNap.focus();
			}
		} catch ( exception ) {
			if ( this.debug ) alert('Naptar.removeCelendar()' + ' - ' + exception.message);
			return null;
		}		
	},
	
	honapUtolsoNapja:function(kulonbseg) {
		try {
			var kovHo = new Date(this.Calendar.getFullYear(),this.Calendar.getMonth(),'1');
			var utolsoNap = new Date(kovHo.getFullYear(),kovHo.getMonth(),kovHo.getDate() - 1 );
			return utolsoNap.getDate();
		} catch ( exception ) {
			if ( this.debug ) alert('Naptar.honapNapjainakSzama()' + ' - ' + exception.message);
			return null;
		}
	},
			
	createCelendar:function() {
		try {
			this.Calendar.setDate(1);
			this.Calendar.setMonth(this.month);
			this.Calendar.setYear(this.year);
			
			//begin
			cal =  '<table class="naptar naptar_betu" border="0" cellspacing="0" cellpadding="0"><tr><td>';
			cal += '<table class="naptar_betu" border="0" cellspacing="0" cellpadding="0">';
			cal += '<tr>';
			//drageable fejléc
			cal += '<td class="naptar_drag_fejlec" colspan="'+ this.DAYS_OF_WEEK +'" align="right"><img class="naptar_x" src="../../images/naptar/x.gif" /></td>';
			cal += '</tr>';
			//léptető
			cal += '<td class="naptar_fejlec_bg naptar_e_ev" title="Előző év">&nbsp;</td><td class="naptar_fejlec_bg naptar_e_ho" title="Előző hónap">&nbsp;</td><td class="naptar_fejlec_bg naptar_betu" colspan="3"><CENTER><B>'+ this.year  + ' ' +  this.month_of_year[this.month] + '</B></CENTER></td><td class="naptar_fejlec_bg naptar_k_ho" title="Következő hónap">&nbsp;</td><td class="naptar_fejlec_bg naptar_k_ev" title="Következő év">&nbsp;</td>';
			cal += '</tr>';
			cal += '<tr id="napszakok">';
			
			//napszakok
			for(index=1; index <= this.DAYS_OF_WEEK; index++) {
				cal += '<td class="naptar_napszak_bg naptar_betu">' + this.day_of_week[index] + '</td>';
			}
			
			
			cal += '<tr>';
			
			//első üres sorok a naptárban
			for(index=0; index < this.napok[this.Calendar.getDay()]; index++) {
				cal += '<td class="naptar_nap_bg_ures naptar_betu"></td>';
			}
			
			//naptár
			for(index=0; index < this.DAYS_OF_MONTH; index++) {
				if( this.Calendar.getDate() > index ) {
					week_day = this.Calendar.getDay();
					
					if(week_day == 1) cal += '<tr>';
					
					if( week_day != this.DAYS_OF_WEEK ) {
						var day  = this.Calendar.getDate();
						if( this.today == day ) {
							cal += '<td id="aktivnap" class="naptar_nap_bg naptar_aktivnap_bg naptar_betu">' + day + '</td>';
						} else { 
							cal += '<td class="naptar_nap_bg naptar_betu">' + day + '</td>';
						}
					}
					if( week_day == this.DAYS_OF_WEEK ) cal += '</tr>';
				  }
			   this.Calendar.setDate(this.Calendar.getDate()+1);
			}
			//end
			cal += '</td></tr></TABLE></TABLE>';
			
			if ( !this.naptar ) {					
				var div = document.createElement('div');
				div.style.border = '1px solid #666666';
				div.style.position = 'absolute';
				div.style.left = this.localToGlobal(this.cel).x + "px";	
				div.style.top = this.localToGlobal(this.cel).y + this.cel.clientHeight + 4 + "px";
				div.style.zIndex = 1000; 	
				div.innerHTML = cal;
				document.body.appendChild(div);
				if ( this.ieBug ) {
					var divBorder = Number(div.style.borderWidth.split("px").join(''));
					this.iframe = document.createElement('iframe');
					this.iframe.style.zIndex = div.style.zIndex-1; 
					this.iframe.style.width = div.clientWidth + (divBorder * 2); 
					this.iframe.style.height = div.clientHeight + (divBorder * 2);
					this.iframe.style.position = 'absolute';
					this.iframe.style.left = this.localToGlobal(this.cel).x + "px";	
					this.iframe.style.top = this.localToGlobal(this.cel).y + this.cel.clientHeight + 4 + "px";
					document.body.appendChild(this.iframe);
				}
				return div;
			} else {
				this.naptar.innerHTML = cal;
				if ( this.ieBug ) {
					var divBorder = Number(this.naptar.style.borderWidth.split("px").join(''));
					this.iframe.style.height = this.naptar.clientWidth + (divBorder * 2); 	
					this.iframe.style.height = this.naptar.clientHeight + (divBorder * 2); 
				}
			}
			this.aktivTD = null;
		} catch ( exception ) {
			if ( this.debug ) alert('Naptar.createCelendar()' + ' - ' + exception.message);
			return null;
		}
	},
	
						
	localToGlobal:function(div) {
		try {
			var myObject = new Object();
			myObject.x = 0;
			myObject.y = 0;
			while (div != null) {
			   myObject.x += div.offsetLeft;
			   myObject.y += div.offsetTop;
			   div = div.offsetParent;
			}
			return myObject;
		} catch ( exception ) {
			if ( this.debug ) alert('Naptar.localToGlobal()' + ' - ' + exception.message);
		}
	},
		
	getScrollPoz:function() {
		try {
			var scrOfX = 0, scrOfY = 0;
			if( typeof( window.pageYOffset ) == 'number' ) {
				//Netscape compliant
				scrOfY = window.pageYOffset;
				scrOfX = window.pageXOffset;
			} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
				//DOM compliant
				scrOfY = document.body.scrollTop;
				scrOfX = document.body.scrollLeft;
			} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
				//IE6 standards compliant mode
				scrOfY = document.documentElement.scrollTop;
				scrOfX = document.documentElement.scrollLeft;
			}
			return { x:scrOfX, y:scrOfY };
		} catch ( exception ) {
			if ( this.debug ) alert('Naptar.getScrollPoz()' + ' - ' + exception.message);
		}
	},
	
	setScrollPoz:function(scrOfX, scrOfY) {
		try {
			var scrOfX = 0, scrOfY = 0;
			if( typeof( window.pageYOffset ) == 'number' ) {
				//Netscape compliant
				window.pageYOffset = scrOfY;
				window.pageXOffset = scrOfX;
			} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
				//DOM compliant
				document.body.scrollTop = scrOfY;
				document.body.scrollLeft = scrOfX;
			} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
				//IE6 standards compliant mode
				document.documentElement.scrollTop = scrOfY;
				document.documentElement.scrollLeft = scrOfX;
			}
		} catch ( exception ) {
			if ( this.debug ) alert('Naptar.setScrollPoz()' + ' - ' + exception.message);
		}
	}
}