IE4 = false;
N6 = false;
N4 = false;


if(document.all) IE4 = true;
if(document.getElementById && !document.all) N6 = true;
if(document.layers) N4 = true;


//deklarace promennych pro kalendar
genkal_sumOfMonthDay = new Array(null,31,28,31,30,31,30,31,31,30,31,30,31);
genkal_nazevMesice = new Array(null,"LEDEN","ÚNOR","BŘEZEN","DUBEN","KVĚTEN","ČERVEN","ČERVENEC","SRPEN","ZÁŘÍ","ŘÍJEN","LISTOPAD","PROSINEC");

//**************** OBJEKT Kalendar *****************
//metody objektu

function setSelectedDay(selDay){
	this.actDay=selDay;
	this.hideKalendar();
	this.returnFromKalendar();
}

function returnFromKalendar(){
	if(this.formInput != null){
		this.formInput.value = this.actDay + "-" + this.actMonth + "-" + this.actYear;
		this.formInput = null;
	}
	if(this.alwaysThisDay==true) { //pri dalsim zobrazeni kalendare bude zase zacinat aktualnim dnem
		dnesniDen = new Date();
		this.actDay = null;
		this.actMonth = dnesniDen.getMonth()+1;
		this.actYear = dnesniDen.getFullYear();
	}
}

function showKalendar(event,inp){
	//nastaveni reference na input pole ve formulari
	this.formInput = inp;
	offsetMouseX = 0;
	offsetMouseY = 0;
	if(event.type == "focus" && IE4){
		offsetMouseX = event.offsetX-40;
		offsetMouseY = event.offsetY-5;
	}
	//zobrazeni kalendare na souradnicich mysi
	mouseX=0;
	mouseY=0;
	if(IE4){
	 	mouseY = event.clientY+document.body.scrollTop-offsetMouseY;
	 	mouseX = event.clientX+document.body.scrollLeft-offsetMouseX;
	}
	if(N6){
	 	mouseY = event.clientY + window.pageYOffset;
	 	mouseX = event.clientX + window.pageXOffset;
	}
	gk_name = "genkal_" + this.uniqName;
	if(IE4){
		document.all[gk_name].style.pixelTop = mouseY;
		document.all[gk_name].style.pixelLeft = mouseX;
		document.all[gk_name].style.visibility = "visible";
	}
	if(N6){
		divBlock = document.getElementById(gk_name);
		divBlock.style.left = mouseX;
		divBlock.style.top = mouseY;
		divBlock.style.visibility = "visible";
	}
	if(IE4 || N6) this.setKalendar();
}

function writeKalendar(){
	if(IE4 || N6){
		document.write('<DIV id="genkal_' + this.uniqName + '"><TABLE bgcolor="#ffffff" width="218" cellspacing=0 cellpadding=0 border=0><TR><TD rowspan=2 width="218" align="center">');

		document.write('<TABLE bgcolor="#ffffff" width="216" cellspacing=0 cellpadding=0 border=0><TR><TD width="35" height="23" bgcolor="'+ this.bgcolHorniPruh+'"><img src="'+this.genkalImgPath+'trpix.gif" width="5" height="1"><A HREF="javascript:'+ this.uniqName+'.setMonthMinus()"><img src="'+this.genkalImgPath+'go_minus.gif" width="12" height="15" alt="" border="0"></A></TD><TD width="146" height="23" bgcolor="'+ this.bgcolHorniPruh+'" align="center"><img src="'+this.genkalImgPath+'trpix.gif" width="1" height="2"><br><DIV id="genkal_' + this.uniqName + '_gen_month_year" style="font-family: Arial,Verdana, sans-serif; font-size: 11px; font-weight: bold; color: '+this.monthFontColor+'">&nbsp;</DIV></TD><TD width="15" height="23" bgcolor="'+ this.bgcolHorniPruh+'"><A HREF="javascript:'+ this.uniqName+'.setMonthPlus()"><img src="'+this.genkalImgPath+'go_plus.gif" width="12" height="15" alt="" border="0"></A></TD><TD width="20" height="23" bgcolor="'+ this.bgcolHorniPruh+'" align="right"><A HREF="javascript:'+ this.uniqName+'.hideKalendar()"><img src="'+this.genkalImgPath+'kal_close.gif" width="15" height="17" alt="" border="0"></A><img src="'+this.genkalImgPath+'/trpix.gif" width="3" height="1"></TD></TR></TABLE><TABLE bgcolor="#ffffff"  width="216" cellspacing=0 cellpadding=0 border=0><TR><TD align="center"><img src="'+this.genkalImgPath+'trpix.gif" width="1" height="1"><br><img src="'+this.genkalImgPath+'days.gif" width="216" height="12" alt="" border="0"></TD></TR></TABLE>');

		document.write('<DIV id="genkal_' + this.uniqName +'_gen_days"></DIV>');
		document.write('<TABLE bgcolor="#ffffff" width="100%" cellspacing=0 cellpadding=0 border=0><TR><TD background="'+this.genkalImgPath+'dolni_back.gif"><img src="'+this.genkalImgPath+'ldolni.gif" width="10" height="4" alt="" border="0"></TD></TR></TABLE>');

		document.write('</TD><TD width="3" background="'+this.genkalImgPath+'bocni_back.gif" valign="top"><img src="'+this.genkalImgPath+'phorni.gif" width="3" height="10" alt="" border="0"></TD></TR>');

		document.write('<TR><TD width="3" background="'+this.genkalImgPath+'bocni_back.gif" valign="bottom"><img src="'+this.genkalImgPath+'pdolni.gif" width="3" height="7" alt="" border="0"></TD></TR></TABLE>');
		document.write('</DIV>');
	}
}

function hideKalendar(){
	gk_name = "genkal_" + this.uniqName;
	if(IE4){
		document.all[gk_name].style.visibility = "hidden";
	}
	if(N6){
			divBlock = document.getElementById(gk_name);
			divBlock.style.visibility = "hidden";
	}
}


function setMonthMinus(){
	this.actMonth--;
	if(this.actMonth<1) {
		this.actMonth=12;
		this.actYear=this.actYear-1;
	}
	this.setKalendar();
}

function setMonthPlus(){
	this.actMonth++;
	if(this.actMonth>12) {
		this.actMonth=1;
		this.actYear=this.actYear+1;
	}
	this.setKalendar();
}


function setKalendar(){
	gk_name = "genkal_" + this.uniqName;
	gk_my = gk_name + "_gen_month_year";
	gk_days = gk_name + "_gen_days";
	
	if(IE4)	document.all[gk_my].innerHTML = genkal_nazevMesice[this.actMonth] + " " + this.actYear;
	if(N6){
		divBlock = document.getElementById(gk_my);
 		divBlock.innerHTML = genkal_nazevMesice[this.actMonth] + " " + this.actYear;
	}
	
	if(N6 || IE4){
		obsah = this.actTab[0];
		this.setNewMonthLoc();
	
		for(i=1;i<=this.rowCount;i++){
			obsah =  obsah + this.actTab[i];
		}

		obsah =  obsah + this.actTab[7];
	}
	
	if(IE4) document.all[gk_days].innerHTML = obsah;
	if(N6){
		divBlock2 = document.getElementById(gk_days);
		divBlock2.innerHTML = obsah;
	}
}

function setNewMonthLoc(){

//DOPLNENO 15.10.2002
	dnesniDen = new Date();
		dnesniDen = new Date();
		dnesniDen.actDay = dnesniDen.getDate();
		dnesniDen.actMonth = dnesniDen.getMonth()+1;
		dnesniDen.actYear = dnesniDen.getFullYear();
// KONEC DOPLNKU 

	sumDay = genkal_sumOfMonthDay[this.actMonth];
	this.parseDay=0;
	if(this.actMonth==2){ 
		if( this.actYear % 4 == 0 && this.actYear % 100 != 0 || this.actYear % 400 == 0) sumDay=29;
	}
	
	parseMonth = new Date(this.actYear,this.actMonth-1,1);
	this.weekday = parseMonth.getDay();
	if(this.weekday == 0) this.weekday = 7;
	for(i=1;i<=6;i++){
		this.actTab[i]="<TR>";
		for(j=1;j<=7;j++){
			if(i==1){
				if(this.weekday==j) this.parseDay=1;
			}

			(j==6 || j==7) ? bgcol=this.bgcolVDny : bgcol=this.bgcolPDny;
			(j==6 || j==7) ? tdclass="kdays2" : tdclass ="kdays1";

//DOPLNENO 15.10.2002
			if(this.MARK_TODAY_FIELD == true) {
				if(this.actYear == dnesniDen.actYear && this.actMonth == dnesniDen.actMonth && this.parseDay == dnesniDen.actDay) {
					bgcol=this.bgcolToday;
				}
			}
// KONEC DOPLNKU
			
			if(this.parseDay>0 && this.parseDay<=sumDay){
				this.actTab[i]=this.actTab[i]+'<TD width=30 align=center bgcolor="'+ bgcol +'" class="'+ tdclass +'"><A HREF="javascript:' + this.uniqName +'.setSelectedDay('+ this.parseDay +')" class="'+ tdclass +'">&nbsp;' + this.parseDay + '&nbsp;</A></TD>';
				if(this.parseDay==sumDay) this.rowCount=i;
				this.parseDay++;
			} else {
				this.actTab[i] = this.actTab[i] + '<TD width=30 align=center bgcolor="'+ bgcol +'" class="kdays1">&nbsp;</TD>';
			}
		}
	this.actTab[i]=this.actTab[i]+"</TR>";
	}
}


//funkce zapisu vyvolavaci sipky //DOPLNENO 15.10.2002
function useKalendar(formInputName){
	if(N6 || IE4){
	 document.write('&nbsp;<A HREF="javascript:void(0)" onclick="prvnikal.showKalendar(event,' + formInputName +')"><img align="absmiddle" src="' + this.genkalImgPath + 'kal_open.gif" width="15" height="21" alt="" border="0"></A>');
	}
}

//konstruktor objektu
function Kalendar(uniqName,alwThisDay,genkalImgPath){
	dnesniDen = new Date();
	this.bgcolHorniPruh = "#E4E4E4";
	this.bgcolPDny = "#EFEFEF";
	this.bgcolVDny = "#E2E2E2";
	this.bgcolToday = "#c8dff0"; //DOPLNENO 15.10.2002
	this.MARK_TODAY_FIELD = true; //DOPLNENO 15.10.2002
	this.monthFontColor = "#004863";
	//this.pDnyFontColor = "#30323B";
	//this.vDnyFontColor = "#E30407";
	this.genkalImgPath = genkalImgPath;
	this.uniqName = uniqName;
	this.event = null;
	this.weekday = 0;
	this.parseDay = 0;
	this.actDay = null;
	this.actMonth = dnesniDen.getMonth()+1;
	this.actYear = dnesniDen.getFullYear();
	this.actTab = new Array();
	this.actTab[0] = "<TABLE width=218 bgcolor=\"#ffffff\" cellspacing=1 cellpadding=0 border=0>";
	this.actTab[7] = "</TABLE>";
	this.rowCount=6;
	(alwThisDay==1) ? this.alwaysThisDay = true : this.alwaysThisDay = false;
	
	this.writeKalendar = writeKalendar;
	this.showKalendar = showKalendar;
	this.hideKalendar = hideKalendar;
	this.setMonthMinus = setMonthMinus;
	this.setMonthPlus = setMonthPlus;
	this.setKalendar = setKalendar;
	this.setNewMonthLoc = setNewMonthLoc;
	this.setSelectedDay = setSelectedDay;
	this.returnFromKalendar = returnFromKalendar;
	this.useKalendar = useKalendar; //DOPLNENO 15.10.2002
}
// KONEC KONSTRUKTORU PRO OBJEKT Kalendar 
