var calLink = new Array("hu","en","de","ro","sr","pl");
	calLink["hu"] = "page.fcgi?menuparam3=5&nyelv=hu";
	calLink["en"] = "page.fcgi?menuparam3=5&nyelv=en";
	calLink["de"] = "page.fcgi?menuparam3=5&nyelv=de";
	calLink["ro"] = "page.fcgi?menuparam3=5&nyelv=ro";
	calLink["sr"] = "page.fcgi?menuparam3=5&nyelv=sr";
	calLink["pl"] = "page.fcgi?menuparam3=5&nyelv=pl";

var theMonths = new Array("hu","en","de","ro","sr","pl");
	theMonths["hu"] = new Array("Január", "Február", "Március", "Április", "Május", "Június", "Július", "Augusztus", "Szeptember", "Október", "November", "December");
	theMonths["en"] = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
	theMonths["de"] = new Array("Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember");
	theMonths["ro"] = new Array("ianuarie", "februarie", "martie", "aprilie", "mai", "iunie", "iulie", "august", "septembrie", "octombrie", "noiembrie", "decembrie");
	theMonths["sr"] = new Array("Januar", "Februar", "Mart", "April", "Maj", "Juni", "Juli", "Avgust", "Septembar", "Oktobar", "Novembar", "Decembar");
	theMonths["pl"] = new Array("styczen", "luty", "marzec", "kwiecien", "maj", "czerwiec", "lipiec", "sierpien", "wrzesien", "pazdziernik", "listopad", "grudzien");

var calHead = new Array("hu","en","de","ro","sr","pl");
	calHead["hu"] = "<tr><th>H</th><th>K</th><th>Sz</th><th>Cs</th><th>P</th><th>Sz</th><th>V</th></tr>";
	calHead["en"] = "<tr><th>S</th><th>M</th><th>T</th><th>W</th><th>T</th><th>F</th><th>S</th></tr>";
	calHead["de"] = "<tr><th>M</th><th>D</th><th>M</th><th>D</th><th>F</th><th>S</th><th>S</th></tr>";
	calHead["ro"] = "<tr><th>l</th><th>m</th><th>m</th><th>j</th><th>v</th><th>s</th><th>d</th></tr>";
	calHead["sr"] = "<tr><th>p</th><th>u</th><th>s</th><th></th><th>p</th><th>s</th><th>n</th></tr>";
	calHead["pl"] = "<tr><th>p</th><th>w</th><th>s</th><th>c</th><th>p</th><th>s</th><th>n</th></tr>";

var calTitle = new Array("hu","en","de","ro","sr","pl");
	calTitle["hu"] = function(y,m,l){return y + '. ' + theMonths[l][m];};
	calTitle["en"] = function(y,m,l){return theMonths[l][m] + ' ' + y;};
	calTitle["de"] = function(y,m,l){return y + '. ' + theMonths[l][m];};
	calTitle["ro"] = function(y,m,l){return theMonths[l][m] + ' ' + y;};
	calTitle["sr"] = function(y,m,l){return theMonths[l][m] + ' ' + y;};
	calTitle["pl"] = function(y,m,l){return theMonths[l][m] + ' ' + y;};

var caldiff = new Array("hu","en","de","ro","sr","pl"); //hét első napja
	caldiff["hu"] = function(v){v=v-1;if (v == 0 ) {v = 7 };return v;}; //Hétfő
	caldiff["en"] = function(v){return v;};  //Sunday
	caldiff["de"] = function(v){v=v-1;if (v == 0 ) {v = 7 };return v;}; //Montag
	caldiff["ro"] = function(v){v=v-1;if (v == 0 ) {v = 7 };return v;}; //lun
	caldiff["sr"] = function(v){v=v-1;if (v == 0 ) {v = 7 };return v;}; //pn
	caldiff["pl"] = function(v){v=v-1;if (v == 0 ) {v = 7 };return v;}; //pn
	
var calNoValidDate = new Array("hu","en","de","ro","sr","pl");
	calNoValidDate["hu"] = 'A kiválasztott dátumra ezen termék nem rendelhető';
	calNoValidDate["en"] = '';
	calNoValidDate["de"] = '';
	calNoValidDate["ro"] = '';
	calNoValidDate["sr"] = '';
	calNoValidDate["pl"] = '';

var oneDay = 1000 * 60 * 60 * 24;

function getFirstDay(theYear, theMonth){
    var firstDate = new Date(theYear,theMonth,1);
    return firstDate.getDay() + 1;
}
function getMonthLen(theYear, theMonth) {

    var lastDay = new Date;
	var nextMonth = new Date(theYear, theMonth + 1, 1);
	lastDay.setTime(nextMonth.getTime() - oneDay);
	var len = lastDay.getDate();
    return len;
}

function checkDayIn(theYear, theMonth,theDay,addDay,thisYear, thisMonth,thisDay){
    var theDate = new Date(theYear,theMonth-1,theDay);
    var thisDate = new Date(thisYear,thisMonth-1,thisDay);
    var thisDateMax = new Date(thisYear,thisMonth-1,thisDay-0+addDay);

    if ((thisDate<=theDate) && (thisDateMax>theDate))
      {
      return true;
      }
    return false;
}

function displayDate(theYear, theMonth,theDay,theLang,addDay){
    var theDate = new Date(theYear,theMonth-1,theDay);
    var maxDate = new Date(theYear,theMonth-1,theDay-0+addDay-1);
    var ty = theDate.getYear();
    if (ty < 999) {ty += 1900;}
    var displaytext = ''+ty+'.'+theMonths[theLang][theDate.getMonth()]+' '+theDate.getDate()+'.';
    if (addDay>1)
      {
      var ty = maxDate.getYear();
      if (ty < 999) {ty += 1900;}
      displaytext += ' - '+ty+'.'+theMonths[theLang][maxDate.getMonth()]+' '+maxDate.getDate()+'.';
      }
    return displaytext;
}

function allowedDate(theYear, theMonth,theDay,theLang,doalert){
    var theDate = new Date(theYear,theMonth-1,theDay);
    var maxDate = new Date(maxYear,maxMonth-1,maxDay);
    var minDate = new Date(minYear,minMonth-1,minDay);
    if ((theDate>maxDate) || (theDate<minDate))
      {
      if (doalert) { alert(calNoValidDate[theLang]);}
      return false;
      }
    return true;
}
function makeCalendar(theYear, theMonth, theLang, theDiv)
{

         if ((theYear  == 0)  && (baseYear != 0))
         {
         theYear=baseYear;
         }
         if ((theMonth  == 0)  && (baseMonth != 0))
         {
         theMonth=baseMonth;
         }

	if  (theYear  == 0) {
		var d=new Date();
		theYear  = d.getYear();
		if (theYear < 999) {theYear += 1900;}
		theMonth = d.getMonth();
	}
	else {
		theMonth--;
	}
        if (theYear < 999) {theYear += 1900;}

	var content = "";
	var header = "";
	var firstDay = getFirstDay(theYear, theMonth);

	firstDay = caldiff[theLang](firstDay);
	var howMany = getMonthLen(theYear, theMonth) + firstDay;

	var prevYear = theYear;
	var prevMonth = theMonth;
	if (prevMonth < 1){prevYear--; prevMonth=12;}

	var nextYear = theYear;
	var nextMonth = theMonth+2;
	if (nextMonth > 12) {nextYear++; nextMonth=1;}

	header += '<div class="naptardate">';
	header += '<table border="0" cellspacing="0" cellpadding="0" align="center"><tr><td width="10">';

	if (prevYear > minYear || (prevYear == minYear && prevMonth >= minMonth)) {
		header += '<a href="#" onclick="makeCalendar(\''+prevYear+'\',\''+ prevMonth+'\',\''+theLang+'\',\''+theDiv+'\');return false;"><img src="kepek/hatra.gif" border="0"></a>';
	}
	//else {header += '<img src="kepek/hatra0.gif" border="0">';}
	header += '</td><td width="140">';
	header += calTitle[theLang](theYear, theMonth, theLang);
	header += '</td><td width="10">';
	if (nextYear < maxYear || (nextYear == maxYear && nextMonth <= maxMonth)) {
		header += '<a href="#" onclick="makeCalendar(\''+nextYear+'\',\''+ nextMonth +'\',\''+theLang+'\',\''+theDiv+'\');return false;"><img src="kepek/elore.gif" border="0"></a>';
	}

	//else {header += '<img src="kepek/elore0.gif" border="0">';}
	header += '</td></tr></table>';
	header += '</div>';

	content +='<table width="160" border="0" cellpadding="0" cellspacing="1" class="naptartable" align="center">';
	content +=calHead[theLang];
	content += "<tr>";

	for (var i = 1; i < howMany; i++) {
		if (i < firstDay) {
			// 'empty' boxes prior to first day
			content += "<td></td>";
		} else {
			// enter date number
			var day = i - firstDay + 1;
                        var pday = day; if (pday <10) {pday = "0"+pday}
                        var pMonth = theMonth+1; if (pMonth <10) {pMonth = "0"+pMonth}
                        var actualday = "kiemeltnap";
                        var linkday = theYear+"-"+pMonth+"-"+pday;

                        if (checkDayIn(theYear, pMonth,pday,selectDays,thisYear, thisMonth,thisDay))
                          {
                          actualday = "mainap";
                          }
                        if (allowedDate(theYear,pMonth,pday,theLang,false))
                          {
		          content += '<td class="'+actualday+'"><a href="#" onclick="if (allowedDate('+theYear+','+pMonth+','+pday+',\''+theLang+'\',true)) {thisYear='+theYear+';thisMonth='+pMonth+';thisDay='+pday+';document.getElementById(\'kosarinfo1\').value=\''+linkday+'\';document.getElementById(\'kosarinfo1b\').value=displayDate('+theYear+','+pMonth+','+pday+',\''+theLang+'\','+selectDays+');document.getElementById(\'kosarinfo2\').value=document.getElementById(\'kosarinfo1b\').value;makeCalendar('+theYear+', '+pMonth+', \''+theLang+'\', \''+theDiv+'\');}return false;" >' + day + "</a></td>";
		          }
		        else
                          {
                          var actualday = "";
                          if (checkDayIn(theYear, pMonth,pday,selectDays,thisYear, thisMonth,thisDay))
                            {
                            actualday = ' class="mainap"';
                            }
                          content += '<td '+actualday+'>' + day + "</td>";
                          }

		}
		// start new row after each week
		if (i % 7 == 0 &&  i != howMany) {
			content += "</tr><tr>";
		}
	}

	for (var i = (howMany-1) % 7; i <= 6 && i != 0; i++) {
		// 'empty' boxes after last day
		content += "<td></td>";
	}

	content += "</tr>";
	content += "</table>";

	document.getElementById(theDiv).innerHTML = header + content;
return true;
}
