	function LengthOfMonth(Y, M){
		with (new Date(Y,M,1,12)){
			setDate(0);
			return getDate();
		}
	}

	var D_Opt = new Array()
	function datuminit(){
		var inputs=document.getElementsByTagName("input");
		for(i=0;i<inputs.length;i++){
			input=inputs[i];
			if(input.className=="datumselect"){
				input.style.display="none";

				evselect=document.createElement("select");
				evselect.id=input.name+"_ev";
				evselect.className="orig";

				hoselect=document.createElement("select");
				hoselect.id=input.name+"_ho";
				hoselect.className="orig";

				napselect=document.createElement("select");
				napselect.id=input.name+"_nap";
				napselect.className="orig";

				evselect.onchange=function() {
					this.className="changed";
					idt=this.id.split('_');
					idt=idt.splice(0,idt.length-1);
					id=idt.join("_");
					Yr=document.getElementById(id+"_ev");
					Mo=document.getElementById(id+"_ho");
					Dy=document.getElementById(id+"_nap");

					DiM = LengthOfMonth(+Yr.options[Yr.selectedIndex].text, Mo.selectedIndex+1-1)+1
					Dol = Dy.options.length
					if ( (NsI = Dy.selectedIndex) >= DiM ) NsI = DiM-1

					for (K=Dol; K >DiM ; K--){
						D_Opt[K] = Dy.options[K-1] ;
						Dy.options[K-1] = null
					}
					for (K=Dol+1 ; K<=DiM ; K++) Dy.options[K-1] = D_Opt[K]
					Dy.selectedIndex = NsI
					document.getElementById(id).value=(Yr.selectedIndex>0 ? Yr.options[Yr.selectedIndex].text : "0000")+"-" + (parseInt(Mo.selectedIndex,10)<10 ? "0" : "") + (Mo.selectedIndex+1-1) + "-" + (parseInt(Dy.selectedIndex,10)<10 ? "0" : "") + (Dy.selectedIndex+1-1);
			 	}

				hoselect.onchange=function() {
					this.className="changed";
					idt=this.id.split('_');
					idt=idt.splice(0,idt.length-1);
					id=idt.join("_");
					Yr=document.getElementById(id+"_ev");
					Mo=document.getElementById(id+"_ho");
					Dy=document.getElementById(id+"_nap");

					DiM = LengthOfMonth(+Yr.options[Yr.selectedIndex].text, Mo.selectedIndex+1-1)+1
					Dol = Dy.options.length
					if ( (NsI = Dy.selectedIndex) >= DiM ) NsI = DiM-1
					for (K=Dol ; K >DiM ; K--){
						D_Opt[K] = Dy.options[K-1] ;
						Dy.options[K-1] = null
					}
					for (K=Dol+1 ; K<=DiM ; K++) Dy.options[K-1] = D_Opt[K]
					Dy.selectedIndex = NsI
					document.getElementById(id).value=Yr.options[Yr.selectedIndex].text+"-" + (parseInt(Mo.selectedIndex,10)<10 ? "0" : "") + (Mo.selectedIndex+1-1) + "-" + (parseInt(Dy.selectedIndex,10)<10 ? "0" : "") + (Dy.selectedIndex+1-1);
				}

				napselect.onchange=function() {
					this.className="changed";
					idt=this.id.split('_');
					idt=idt.splice(0,idt.length-1);
					id=idt.join("_");
					Yr=document.getElementById(id+"_ev");
					Mo=document.getElementById(id+"_ho");
					Dy=document.getElementById(id+"_nap");
					document.getElementById(id).value=Yr.options[Yr.selectedIndex].text+"-" + (parseInt(Mo.selectedIndex,10)<10 ? "0" : "") + (Mo.selectedIndex+1-1) + "-" + (parseInt(Dy.selectedIndex,10)<10 ? "0" : "") + (Dy.selectedIndex+1-1);
				}



				base = new Date().getFullYear();
				mon3 = ["jan.", "febr.", "márc.", "ápr.", "máj.", "jún.", "júl.", "aug.", "szept.", "okt.", "nov.", "dec."]
				evselect.options[0]=new Option ("év",0);
				hoselect.options[0]=new Option ("hónap",0);
				napselect.options[0]=new Option ("nap",0);

				if (input.getAttribute("alt")) {
					tol=parseInt(input.getAttribute("alt"),10);
				} else {
					tol=base-3;
				}
				if (input.getAttribute("title")) {
					ig=parseInt(input.getAttribute("title"),10);
				} else {
					ig=base+3;
				}

				for (j=1; j<=ig-tol+1; j++) evselect.options[j] = new Option(j+tol-1)
				for (j=1; j<=12 ; j++) hoselect.options[j] = new Option(mon3[j-1])
				for (j=1; j<=31 ; j++){
					if(j+1-1<10) nap="0"+(j+1-1);
					else nap=(j+1-1);
					napselect.options[j] = new Option(nap)
				}
				input.parentNode.appendChild(evselect);
				input.parentNode.appendChild(hoselect);
				input.parentNode.appendChild(napselect);
				if(input.value!=""){
					datumt=input.value.split("-");

					evselect.selectedIndex=(j=parseInt(datumt[0],10)-tol+1)>=0&&j<evselect.length ? j : 0;
					hoselect.selectedIndex=parseInt(datumt[1],10)-1+1;
					napselect.selectedIndex=parseInt(datumt[2],10)-1+1;

					Yr=evselect;
					Mo=hoselect;
					Dy=napselect;

					DiM = LengthOfMonth(+Yr.options[Yr.selectedIndex].text, Mo.selectedIndex+1-1)+1
					Dol = Dy.options.length
					if ( (NsI = Dy.selectedIndex) >= DiM ) NsI = DiM-1
					for (K=Dol ; K >DiM ; K--){
						D_Opt[K] = Dy.options[K-1] ;
						Dy.options[K-1] = null
					}
					for (K=Dol+1 ; K<=DiM ; K++) Dy.options[K-1] = D_Opt[K]
					Dy.selectedIndex = NsI
				}
			}
		}
	}

	//addLoadEvent(datuminit);
	addEvent(window, 'load', datuminit);
