var calendarsClicker = 0;
var outsideCalendarsClicker = true;

var cals_from;
var cals_to;

function clickOutsideCalendars() {

	//alert(outsideCalendarsClicker);
	if (outsideCalendarsClicker)
	{
		//alert('pokazuje selecty');
		hideUnusedCalendars();
		try{
			helper1.removeFocus();
			helper1.selectedIndex=0;
		}
		catch (e){}
		try{
			helper2.removeFocus();
			helper2.selectedIndex=0;
		}
		catch (e){}
		try{
			helper3.removeFocus();
			helper3.selectedIndex=0;
		}
		catch (e){}
		try{
			helper4.removeFocus();
			helper4.selectedIndex=0;
		}
		catch (e){}

	}

	outsideCalendarsClicker = true;
}

function clickOnCalendars()
{
	outsideCalendarsClicker = false;
}

function hide_calendar(ktory)
{
	if(ktory=="cals_from")
	{
		try {	cals_from.hideCalendars();}catch (e){	}
	}
	else if (ktory=="cals_to")
	{
		try {	cals_to.hideCalendars();}catch (e){	}
	}
}

function hideUnusedCalendars(){
	try {	cals_from.hideCalendars();}catch (e){	}
	try {	cals_to.hideCalendars();}catch (e){	}

}

function createCalendars()
{
	rok_od = document.getElementById('w_r').value;
	mies_od = document.getElementById('w_m').value-1;
	dzien_od = document.getElementById('w_d').value;
	start_cal_dni = document.getElementById('start_cal_dni').value;
//	default_date = new Date(rok_od,mies_od,dzien_od,0,0,0,0);
	current_time = new Date();
	start_from_dni = parseInt(current_time.getDate()) + parseInt(start_cal_dni);

	czas_od = new Date(current_time.getFullYear(),current_time.getMonth(),start_from_dni,0,0,0,0);
	afid = document.getElementById('afid').value;
	aver = document.getElementById('aver').value;
	//alert(afid+aver);
	if(rok_od=="" || mies_od=="" ||dzien_od=="")
		czas_od=new Date();
	cals_from = new Calendars(czas_od,null,null,null,"cals_from",document.getElementById("calendar_from"),12,2,"DDMMYYYY",Array(
		"w_d",
		"w_m",
		"w_r",
		"date_from"),
		Array(),afid,aver);
	cals_to = new Calendars(czas_od,null,null,null,"cals_to",document.getElementById("calendar_to"),12,2,"DDMMYYYY",Array(
		"p_d",
		"p_m",
		"p_r",
		"date_to"),
		Array(),afid,aver);
	cals_from.setRightCalendars(cals_to);
	cals_to.setLeftCalendars(cals_from);
	cals_from.builtCalendars();
	cals_to.builtCalendars();
}


function Calendars(
	startDate,
	endDate,
	firstDate,
	selectedDate,
	objName,
	destinationObj,
	countCalendars,
	countShowCalendars,
	destinationTypeDate,
	destinationIdDate,
	elementsToDisable,
	afid,
	aver
)
{
	this.afid = afid;
	this.aver = aver;

	this.className = "Calendars";
	this.version = "1.0";

	//od jakiego dnia można wybrać date
	this.startDate = startDate;
	//do jakiego dnia można wybrać date
	this.endDate = endDate;
	//jaki jest pierwszy miesiąc
	if (firstDate == null)
		this.firstDate = new Date();
	else
		this.firstDate = firstDate;
	//data zaznaczona
	this.selectedDate = selectedDate;

	this.destinationObj = destinationObj;

	this.destinationObj.className = "calendars";

	this.objName = objName;

	//ilosc kalendarzy
	this.countCalendars = countCalendars;
	//ilosc widocznych kalendarzy
	this.countShowCalendars = countShowCalendars;

	//przechowuje tablice idków w których znajdują się kalendarze
	this.calendarsArrayObj = Array();

	//przechowuje tablice idków <TR> w których znajdują się kalendarze
	this.calendarsArrayObjTR = Array();

	//id obiektu(ów) w którym należy umieścić kalendarz
	this.destinationIdDate = destinationIdDate;
	//typ daty jaki ma być zwrócony
	this.destinationTypeDate = destinationTypeDate;

	//zapamietuje który był wcześniej zaznaczony żeby wiedzieć który kalendarz przebudować
	this.prevSelected = null;

	//ustalenie zaleznosci miedzy kalendarzami
	this.leftCalendars = null;
	this.rightCalendars = null;

	//elementy które trzeba wyłączyć bo prześwitują (problem selectów w IE)
	if (elementsToDisable)
		this.elementsToDisable = elementsToDisable;
	else
		this.elementsToDisable = Array();

	//przechowuje index pierwszego i ostatniego kalendarza który jest widoczny
	this.shownCalendars = Array();

	//przechowuje obiekty z kalendarzami
	this.calendars = Array();

	this.ie = false;
	if(navigator.appName == "Microsoft Internet Explorer")
		this.ie=true;

	this.builtCalendars=function()
	{
		var buffor = "";

		buffor += "<table class=\"calendarsTable\">";

		for (var i=0; i<=this.countCalendars-1; i++)
		{
			buffor += "<tr id=\""+this.objName+"_Row_"+(i+1)+"\"><td class=\"naviTop\" width=\"15px\"><a href=\"javascript:"+this.objName+".prevMonth()\"><img id=\""+this.objName+"_LeftArrow_"+(i+1)+"\" src=\"avio_external/img/"+this.afid+"/"+this.aver+"/previous.png\" style=\"border:none\" alt=\"previous\"/></a></td><td class=\"naviTop\"  width=\"104px\"><div style=\"width:104;\"class=\"nameMonthPrev\" id=\""+this.objName+"_nameMont"+(i+1)+"\">Month name</div></td><td class=\"naviTop\" width=\"15px\"><a href=\"javascript:"+this.objName+".nextMonth()\"><img id=\""+this.objName+"_RightArrow_"+(i+1)+"\" src=\"avio_external/img/"+this.afid+"/"+this.aver+"/next.png\" style=\"border:none;\" alt=\"next\"/></a></td></tr>";


			buffor += "<tr id=\""+this.objName+"_calendar_TR_"+i+"\" style=\"display:none\"><td colspan=\"3\" class=\"calendar\" id=\""+this.objName+"_calendar_"+i+"\"></td></tr>";
		}

		buffor += "<tr><td colspan=\"3\"><hr color=\"#e1e7fd\" height=\"1px\" style=\"margin:0px 0px\"></hr></td></tr>";
		buffor += "<tr><td colspan=\"3\" class=\"closecalendar\" id=\""+this.objName+"_closecalendar\"><span onMouseOver=\"document.getElementById('"+this.objName+"_closecalendar').className='closecalendar_mouse_over';\" onMouseOut=\"document.getElementById('"+this.objName+"_closecalendar').className='closecalendar';\" onclick=\"hide_calendar('"+this.objName+"');\">Close</span></td></tr>";

		buffor += "</table><!--[if lte IE 6.5]><iframe class='calendarFIX'></iframe><![endif]-->";

		this.destinationObj.innerHTML = buffor;
		buffor = "";

		for (var i=0; i<this.countCalendars; i++)
		{
			this.calendarsArrayObj[this.calendarsArrayObj.length] = document.getElementById(this.objName+"_calendar_"+i);
			this.calendarsArrayObjTR[this.calendarsArrayObjTR.length] = document.getElementById(this.objName+"_calendar_TR_"+i);
		}

		dateTmp = this.firstDate;
		dateTmp.setDate(1);

		for (var i=0; i<this.countCalendars; i++)
		{
			this.calendars[this.calendars.length] = new Calendar(this.startDate,this.endDate,null,null,null,dateTmp,null,document.getElementById(this.objName+"_calendar_"+i),this.destinationTypeDate,this.destinationIdDate);
			//this.calendars[this.calendars.length-1].showMonthAndYearHeader = true;
			this.calendars[this.calendars.length-1].afterOnclick = this.objName+".hideCalendars();"+this.objName+".newSelectedDay(true);";
			//this.calendars[this.calendars.length-1].builtCalendar();
			dateTmp.setMonth(dateTmp.getMonth()+1);
		}
		//this.newSelectedDay(true);
		//dateTmp = this.checkDateFromDestinationInput();

	}

	this.displayCalendars=function()
	{

		clickOnCalendars();
		//hideUnusedCalendars();
		this.hideElements();
		dateTmp = this.getDateFromDestinationInput();

		if (this.startDate != null)
		{
			if (this.startDate > dateTmp)
				dateTmp = this.startDate;
		}

		for (var i=0; i<this.calendars.length;i++)
		{
			if ( (this.calendars[i].getMonth() == dateTmp.getMonth()) && (this.calendars[i].getYear() == dateTmp.getFullYear()) )
			{
				this.shownCalendars["left"] = i;
				this.shownCalendars["right"] = i+this.countShowCalendars-1;
				while(!this.calendarsArrayObj[this.shownCalendars["right"]])
				{
					this.shownCalendars["left"]--;
					this.shownCalendars["right"]--;
				}
				break;
			}
		}
		if (!this.shownCalendars["left"])
		{
			this.shownCalendars["left"] = 0;
			this.shownCalendars["right"] = this.countShowCalendars-1;
		}

		var index = 1;
		//alert(this.shownCalendars["left"]+"____"+this.shownCalendars["right"]);
		//for (var i=this.shownCalendars["left"]; i<=this.shownCalendars["right"]; i++)
		for (var i=this.shownCalendars["left"]; i<=this.shownCalendars["right"]; i++)
		{
			this.newSelectedDay(true);
			if (!this.calendars[i].isBuild)
				this.calendars[i].builtCalendar();

			if (this.ie)
			{
				this.calendarsArrayObj[i].style.display="block";
				this.calendarsArrayObjTR[i].style.display="block";
			}
			else
			{
				this.calendarsArrayObj[i].style.display="table-cell";
				this.calendarsArrayObjTR[i].style.display="table-row";
			}

			//document.getElementById(this.objName+"_nameMont"+index).innerHTML = this.calendars[i].getMonthName()+" "+this.calendars[i].getYear();
			//index++;
		}

		for(index=1;index<=12;index++)
		{

			document.getElementById(this.objName+"_nameMont"+index).innerHTML = this.calendars[index-1].getMonthName()+" "+this.calendars[index-1].getYear();
			document.getElementById(this.objName+"_nameMont"+index).style.display="none";
			document.getElementById(this.objName+"_LeftArrow_"+index).style.display="none";
			document.getElementById(this.objName+"_RightArrow_"+index).style.display="none";
			document.getElementById(this.objName+"_Row_"+index).style.display="none";

			if (this.ie || navigator.userAgent.indexOf("opera")==-1)
			{
				m=1;
				for (var i=this.shownCalendars["left"]; i<=this.shownCalendars["right"]; i++)
				{
					if(i==index-1)
					{
						document.getElementById(this.objName+"_nameMont"+index).style.display="block";
						document.getElementById(this.objName+"_Row_"+index).style.display="block";
						if(m==1)
						{
							document.getElementById(this.objName+"_LeftArrow_"+index).style.display="block";
							document.getElementById(this.objName+"_RightArrow_"+index).style.display="none";
						}
						else
						{
							document.getElementById(this.objName+"_LeftArrow_"+index).style.display="none";
							document.getElementById(this.objName+"_RightArrow_"+index).style.display="block";
						}
					}
					m++;
				}
			}
			else
			{
				m=1;
				for (var i=this.shownCalendars["left"]; i<=this.shownCalendars["right"]; i++)
				{
					if(i==index-1)
					{
						document.getElementById(this.objName+"_nameMont"+index).style.display="table-cell";
						document.getElementById(this.objName+"_Row_"+index).style.display="table-row";
						if(m==1)
						{
							document.getElementById(this.objName+"_LeftArrow_"+index).style.display="table-cell";
							document.getElementById(this.objName+"_RightArrow_"+index).style.display="none";
						}
						else
						{
							document.getElementById(this.objName+"_LeftArrow_"+index).style.display="none";
							document.getElementById(this.objName+"_RightArrow_"+index).style.display="table-cell";
						}
					}
					m++;
				}
			}
			//alert(document.getElementById(this.objName+"_nameMont"+index).id);
		}

		// AERO path
			this.calendarsArrayObj[this.shownCalendars["left"]].className = this.calendarsArrayObj[this.shownCalendars["left"]].className.replace(/ leftVisibleCalendar/,"");
			this.calendarsArrayObj[this.shownCalendars["left"]].className = this.calendarsArrayObj[this.shownCalendars["left"]].className.replace(/ rightVisibleCalendar/,"");
			this.calendarsArrayObj[this.shownCalendars["right"]].className = this.calendarsArrayObj[this.shownCalendars["right"]].className.replace(/ leftVisibleCalendar/,"");
			this.calendarsArrayObj[this.shownCalendars["right"]].className = this.calendarsArrayObj[this.shownCalendars["right"]].className.replace(/ rightVisibleCalendar/,"");
			this.calendarsArrayObj[this.shownCalendars["left"]].className += ' leftVisibleCalendar';
			this.calendarsArrayObj[this.shownCalendars["right"]].className += ' rightVisibleCalendar';
			//dodane

		// AERO path end

		this.destinationObj.style.display="block";
//		$(this.destinationObj).fadeIn('slow');
	}

	this.hideCalendars=function()
	{
		this.showElements();
		this.destinationObj.style.display="none";
		//$(this.destinationObj).fadeOut('slow');
		for (var i=this.shownCalendars["left"]; i<=this.shownCalendars["right"]; i++)
		{
			this.calendarsArrayObj[i].style.display="none";
		}
		this.shownCalendars = Array();
	}

	this.hideElements=function()
	{
		for (var i=0; i<this.elementsToDisable.length; i++)
		{
			try
			{
				if (this.elementsToDisable.length)
				{
					if (typeof this.elementsToDisable[i] == "object")
					{
						this.elementsToDisable[i].style.visibility="hidden";
					}
					else
						document.getElementById(this.elementsToDisable[i]).style.visibility="hidden";
				}
			}
			catch (e)
			{
			}
			//alert(this.elementsToDisable[i].id);
		}

			//this.elementsToDisable[i].style.display="none";
	}

	this.showElements=function()
	{
		for (var i=0; i<this.elementsToDisable.length; i++)
		{
			try
			{
					if (typeof this.elementsToDisable[i] == "object")
					{
						this.elementsToDisable[i].style.visibility="visible";
					}
					else
						document.getElementById(this.elementsToDisable[i]).style.visibility="visible";
			}
			catch (e)
			{
			}
				//this.elementsToDisable[i].style.display="display";
		}
	}

	/**
	 *
	 */
	this.newSelectedDay=function(informDependencies)
	{
		if (this.prevSelected == null)
		{
			this.prevSelected = this.getDateFromDestinationInput();
			this.rebuildMonth(this.prevSelected,this.prevSelected);
			this.selectedDate = this.prevSelected;
		}
		else
		{
			var dateTmp = this.getDateFromDestinationInput();
			//jesli kliknelismy w ten sam miesiac to przebudowyujemy tylko jeden miesiac
			if ((dateTmp.getMonth() == this.prevSelected.getMonth()) && (dateTmp.getFullYear() == this.prevSelected.getFullYear()))
			{
				this.rebuildMonth(dateTmp,dateTmp);
				this.prevSelected = dateTmp;
			}
			else
			{
				this.rebuildMonth(this.prevSelected,dateTmp);
				this.rebuildMonth(dateTmp,dateTmp);
				this.prevSelected = dateTmp;
			}

		}

		this.selectedDate = this.prevSelected;
		if (informDependencies)
			this.informDependencies();
	}

	this.informDependencies=function()
	{
		if (this.leftCalendars != null)
			this.leftCalendars.informFromRightCalendar(this.selectedDate);

		if (this.rightCalendars != null)
			this.rightCalendars.informFromLeftCalendar(this.selectedDate);
	}

	this.informFromLeftCalendar=function(startDate)
	{
		if(this.selectedDate == null) this.newSelectedDay();
		if (startDate > this.selectedDate)
			{
				this.selectedDate = startDate;
				this.setHiddenInputFromSelectedDate();
			}

		this.rebuildMonthByStartDate(startDate);
	}

	this.informFromRightCalendar=function(endDate)
	{
		//alert(this.objName+" - otyrzymalem od prawego "+endDate);
	}

	this.rebuildMonth=function(dateToRebuild,selectedDate)
	{
		//znalezienie kalendarza ktory wymaga przebudowania
		for (var i=0; i<this.calendars.length; i++)
		{
			if ( (this.calendars[i].getMonth() == dateToRebuild.getMonth()) && (this.calendars[i].getYear() == dateToRebuild.getFullYear()))
			{
				this.calendars[i].setSelectedDate(selectedDate);
				this.calendars[i].builtCalendar();
				break;
			}
		}
	}

	this.rebuildMonthByStartDate=function(startDate)
	{
		if (this.startDate == null)
		{
			var i = 0;
			while(
					this.calendars[i]
					&&
					(
						(
							(this.calendars[i].getMonth() <= startDate.getMonth())
							&&
							(this.calendars[i].getYear() == startDate.getFullYear())
						)
						||
						(
							this.calendars[i].getYear() < startDate.getFullYear()
						)
					)
				)
			{
				this.calendars[i].setStartDate(startDate);
				this.calendars[i].setShowDate(startDate);
				this.calendars[i].builtCalendar();
				i++;
			}
			this.startDate = startDate;
		}
		else
		{
			var i = 0;
			dateTmp = this.startDate;
			if (this.startDate < startDate)
				dateTmp = startDate;
			while(
					this.calendars[i]
					&&
					(
						(
							(this.calendars[i].getMonth() <= dateTmp.getMonth())
							&&
							(this.calendars[i].getYear() == dateTmp.getFullYear())
						)
						||
						(
							this.calendars[i].getYear() < dateTmp.getFullYear()
						)
					)
				)
			{
				this.calendars[i].setStartDate(startDate);
				this.calendars[i].setShowDate(startDate);
				this.calendars[i].builtCalendar();
				i++;
			}
			this.startDate = startDate;
		}

		if (this.rightCalendars != null)
			this.rightCalendars.informFromLeftCalendar(startDate);
	}

	this.prevMonth=function()
	{
		if (this.isPrevMonth())
		{
			this.calendarsArrayObj[this.shownCalendars["right"]].style.display="none";
			this.calendarsArrayObjTR[this.shownCalendars["right"]].style.display="none";

			if (!this.calendars[this.shownCalendars["left"]-1].isBuild)
				this.calendars[this.shownCalendars["left"]-1].builtCalendar();

			if (this.ie)
			{
				this.calendarsArrayObj[this.shownCalendars["left"]-1].style.display="block";
				this.calendarsArrayObjTR[this.shownCalendars["left"]-1].style.display="block";
			}
			else
			{
				this.calendarsArrayObj[this.shownCalendars["left"]-1].style.display="table-cell";
				this.calendarsArrayObjTR[this.shownCalendars["left"]-1].style.display="";
			}
			this.shownCalendars["right"]--;
			this.shownCalendars["left"]--;

			// AERO path
			this.calendarsArrayObj[this.shownCalendars["left"]].className = this.calendarsArrayObj[this.shownCalendars["left"]].className.replace(/ leftVisibleCalendar/,"");
			this.calendarsArrayObj[this.shownCalendars["left"]].className = this.calendarsArrayObj[this.shownCalendars["left"]].className.replace(/ rightVisibleCalendar/,"");
			this.calendarsArrayObj[this.shownCalendars["right"]].className = this.calendarsArrayObj[this.shownCalendars["right"]].className.replace(/ leftVisibleCalendar/,"");
			this.calendarsArrayObj[this.shownCalendars["right"]].className = this.calendarsArrayObj[this.shownCalendars["right"]].className.replace(/ rightVisibleCalendar/,"");
			this.calendarsArrayObj[this.shownCalendars["left"]+1].className = this.calendarsArrayObj[this.shownCalendars["left"]+1].className.replace(/ leftVisibleCalendar/,"");
			this.calendarsArrayObj[this.shownCalendars["left"]+1].className = this.calendarsArrayObj[this.shownCalendars["left"]+1].className.replace(/ rightVisibleCalendar/,"");
			this.calendarsArrayObj[this.shownCalendars["right"]+1].className = this.calendarsArrayObj[this.shownCalendars["right"]+1].className.replace(/ leftVisibleCalendar/,"");
			this.calendarsArrayObj[this.shownCalendars["right"]+1].className = this.calendarsArrayObj[this.shownCalendars["right"]+1].className.replace(/ rightVisibleCalendar/,"");
			this.calendarsArrayObj[this.shownCalendars["left"]].className += ' leftVisibleCalendar';
			this.calendarsArrayObj[this.shownCalendars["right"]].className += ' rightVisibleCalendar';
		// AERO path end

			var index=1;
			/*
			//to było
			for (var i=this.shownCalendars["left"]; i<=this.shownCalendars["right"]; i++)
			{
				document.getElementById(this.objName+"_nameMont"+index).innerHTML = this.calendars[i].getMonthName()+" "+this.calendars[i].getYear();
				index++;
			}
			*/
			for(j=1;j<=12;j++)
			{
				document.getElementById(this.objName+"_nameMont"+j).style.display="none";
				document.getElementById(this.objName+"_LeftArrow_"+j).style.display="none";
				document.getElementById(this.objName+"_RightArrow_"+j).style.display="none";
				document.getElementById(this.objName+"_Row_"+j).style.display="none";
			}
			n=1;
			for (var i=this.shownCalendars["left"]; i<=this.shownCalendars["right"]; i++)
			{
				k=i+1;
				//alert(k);
				if (this.ie || navigator.userAgent.indexOf("opera")==-1)
				{
					document.getElementById(this.objName+"_nameMont"+k).style.display="block";
					document.getElementById(this.objName+"_Row_"+k).style.display="block";
					if(n==1)
					{
						document.getElementById(this.objName+"_LeftArrow_"+k).style.display="block";
						document.getElementById(this.objName+"_RightArrow_"+k).style.display="none";
					}
					else
					{
						document.getElementById(this.objName+"_LeftArrow_"+k).style.display="none";
						document.getElementById(this.objName+"_RightArrow_"+k).style.display="block";
					}

				}
				else
				{
					document.getElementById(this.objName+"_nameMont"+k).style.display="table-cell";
					document.getElementById(this.objName+"_Row_"+k).style.display="table-row";
					if(n==1)
					{
						document.getElementById(this.objName+"_LeftArrow_"+k).style.display="table-cell";
						document.getElementById(this.objName+"_RightArrow_"+k).style.display="none";
					}
					else
					{
						document.getElementById(this.objName+"_LeftArrow_"+k).style.display="none";
						document.getElementById(this.objName+"_RightArrow_"+k).style.display="table-cell";
					}

				}
				n++;
				index++;
			}
		}
	}

	this.nextMonth=function()
	{
		if (this.isNextMonth())
		{
			this.calendarsArrayObj[this.shownCalendars["left"]].style.display="none";
			this.calendarsArrayObjTR[this.shownCalendars["left"]].style.display="none";
			if (!this.calendars[this.shownCalendars["right"]+1].isBuild)
				this.calendars[this.shownCalendars["right"]+1].builtCalendar();
			if (this.ie)
			{
				this.calendarsArrayObj[this.shownCalendars["right"]+1].style.display="block";
				this.calendarsArrayObjTR[this.shownCalendars["right"]+1].style.display="block";
			}
			else
			{
				this.calendarsArrayObj[this.shownCalendars["right"]+1].style.display="table-cell";
				this.calendarsArrayObjTR[this.shownCalendars["right"]+1].style.display="table-row";
			}
			this.shownCalendars["right"]++;
			this.shownCalendars["left"]++;

			// AERO path
			this.calendarsArrayObj[this.shownCalendars["left"]].className = this.calendarsArrayObj[this.shownCalendars["left"]].className.replace(/ leftVisibleCalendar/,"");
			this.calendarsArrayObj[this.shownCalendars["left"]].className = this.calendarsArrayObj[this.shownCalendars["left"]].className.replace(/ rightVisibleCalendar/,"");
			this.calendarsArrayObj[this.shownCalendars["right"]].className = this.calendarsArrayObj[this.shownCalendars["right"]].className.replace(/ leftVisibleCalendar/,"");
			this.calendarsArrayObj[this.shownCalendars["right"]].className = this.calendarsArrayObj[this.shownCalendars["right"]].className.replace(/ rightVisibleCalendar/,"");
			this.calendarsArrayObj[this.shownCalendars["left"]-1].className = this.calendarsArrayObj[this.shownCalendars["left"]-1].className.replace(/ leftVisibleCalendar/,"");
			this.calendarsArrayObj[this.shownCalendars["left"]-1].className = this.calendarsArrayObj[this.shownCalendars["left"]-1].className.replace(/ rightVisibleCalendar/,"");
			this.calendarsArrayObj[this.shownCalendars["right"]-1].className = this.calendarsArrayObj[this.shownCalendars["right"]-1].className.replace(/ leftVisibleCalendar/,"");
			this.calendarsArrayObj[this.shownCalendars["right"]-1].className = this.calendarsArrayObj[this.shownCalendars["right"]-1].className.replace(/ rightVisibleCalendar/,"");
			this.calendarsArrayObj[this.shownCalendars["left"]].className += ' leftVisibleCalendar';
			this.calendarsArrayObj[this.shownCalendars["right"]].className += ' rightVisibleCalendar';
			// AERO path end

			var index=1;
			//alert(this.shownCalendars["left"]+"___"+this.shownCalendars["right"]);
			/*
			//to było
			for (var i=this.shownCalendars["left"]; i<=this.shownCalendars["right"]; i++)
			{
				document.getElementById(this.objName+"_nameMont"+index).innerHTML = this.calendars[i].getMonthName()+" "+this.calendars[i].getYear();
				index++;
			}
			*/
			for(j=1;j<=12;j++)
			{
				document.getElementById(this.objName+"_nameMont"+j).style.display="none";
				document.getElementById(this.objName+"_LeftArrow_"+j).style.display="none";
				document.getElementById(this.objName+"_RightArrow_"+j).style.display="none";
				document.getElementById(this.objName+"_Row_"+j).style.display="none";
			}
			n=1;
			for (var i=this.shownCalendars["left"]; i<=this.shownCalendars["right"]; i++)
			{
				k=i+1;
				//alert(n);
				if (this.ie || navigator.userAgent.indexOf("opera")==-1)
				{
					document.getElementById(this.objName+"_nameMont"+k).style.display="block";
					document.getElementById(this.objName+"_Row_"+k).style.display="block";
					if(n==1)
					{
						document.getElementById(this.objName+"_LeftArrow_"+k).style.display="block";
						document.getElementById(this.objName+"_RightArrow_"+k).style.display="none";
					}
					else
					{
						document.getElementById(this.objName+"_LeftArrow_"+k).style.display="none";
						document.getElementById(this.objName+"_RightArrow_"+k).style.display="block";
					}

				}
				else
				{
					document.getElementById(this.objName+"_nameMont"+k).style.display="table-cell";
					document.getElementById(this.objName+"_Row_"+k).style.display="table-row";
					if(n==1)
					{
						document.getElementById(this.objName+"_LeftArrow_"+k).style.display="table-cell";
						document.getElementById(this.objName+"_RightArrow_"+k).style.display="none";
					}
					else
					{
						document.getElementById(this.objName+"_LeftArrow_"+k).style.display="none";
						document.getElementById(this.objName+"_RightArrow_"+k).style.display="table-cell";
					}

				}
				index++;
				n++;
			}
		}
	}

	this.isPrevMonth=function()
	{
		if (this.calendarsArrayObj[this.shownCalendars["left"]-1])
			return true;
		return false;
	}

	this.isNextMonth=function()
	{
		if (this.calendarsArrayObj[this.shownCalendars["right"]+1])
			return true;
		return false;
	}


	this.setHiddenInputFromSelectedDate=function()
	{
		switch(this.destinationTypeDate)
		{
			case "STANDARD" :
			case "TWOPLACES" :
				document.getElementById(destinationIdDate[0]).value = this.selectedDate.getDate();
				document.getElementById(destinationIdDate[1]).value = this.selectedDate.getMonth()+1;
				document.getElementById(destinationIdDate[2]).value = this.selectedDate.getFullYear();
				document.getElementById(destinationIdDate[3]).value = this.selectedDate.getDate()+"."+(this.selectedDate.getMonth()+1)+"."+this.selectedDate.getFullYear();
				break;
				//if (this.checkDate(day,month,year))
				//	returnDate.setFullYear(year,month-1,day);
			case "TWOPLACESMINI" :
				document.getElementById('miniform').elements[destinationIdDate[0]].value = this.selectedDate.getDate();
				document.getElementById('miniform').elements[destinationIdDate[1]].value = this.selectedDate.getMonth()+1;
				document.getElementById('miniform').elements[destinationIdDate[2]].value = this.selectedDate.getFullYear();
				document.getElementById(destinationIdDate[3]).value = this.selectedDate.getDate()+"."+(this.selectedDate.getMonth()+1)+"."+this.selectedDate.getFullYear();
				break;

			case "INONEINPUT" :
				document.getElementById(destinationIdDate[3]).value = this.selectedDate.getDate()+"."+(this.selectedDate.getMonth()+1)+"."+this.selectedDate.getFullYear();
				//var explode = dateString.split(".");
				//if (explode.length == 3)
				//{
				//	returnDate.setFullYear(explode[2],explode[1]-1,explode[0]);
				//}
			case "DDMMYYYY" :
				document.getElementById(destinationIdDate[0]).value = this.selectedDate.getDate();
				document.getElementById(destinationIdDate[1]).value = this.selectedDate.getMonth()+1;
				document.getElementById(destinationIdDate[2]).value = this.selectedDate.getFullYear();
				document.getElementById(destinationIdDate[3]).value = this.selectedDate.getDate()+"/"+(this.selectedDate.getMonth()+1)+"/"+this.selectedDate.getFullYear();
				break;

		}
		//alert(destinationIdDate);
		//alert('przestaw hiddeny '+this.selectedDate);
	}

	this.getDateFromDestinationInput=function()
	{
		var returnDate = new Date();
		switch(this.destinationTypeDate)
		{
			case "STANDARD" :
			case "TWOPLACES" :
				day = document.getElementById(destinationIdDate[0]).value;
				month = document.getElementById(destinationIdDate[1]).value;
				year = document.getElementById(destinationIdDate[2]).value;
				if (this.checkDate(day,month,year))
					returnDate.setFullYear(year,month-1,day);

				dateString = document.getElementById(destinationIdDate[0]).value;
				var explode = dateString.split(".");
				if (explode.length == 3)
				{
					returnDate.setFullYear(explode[2],explode[1]-1,explode[0]);
				}
				break;

			case "TWOPLACESMINI" :
				day = document.getElementById('miniform').elements[destinationIdDate[0]].value;
				month = document.getElementById('miniform').elements[destinationIdDate[1]].value;
				year = document.getElementById('miniform').elements[destinationIdDate[2]].value;
				if (this.checkDate(day,month,year))
					returnDate.setFullYear(year,month-1,day);

				dateString = document.getElementById(destinationIdDate[0]).value;
				var explode = dateString.split(".");
				if (explode.length == 3)
				{
					returnDate.setFullYear(explode[2],explode[1]-1,explode[0]);
				}
				break;

			case "INONEINPUT" :
				dateString = document.getElementById(destinationIdDate[0]).value;
				var explode = dateString.split(".");
				if (explode.length == 3)
				{
					returnDate.setFullYear(explode[2],explode[1]-1,explode[0]);
				}
			case "DDMMYYYY" :
				day = document.getElementById(destinationIdDate[0]).value;
				month = document.getElementById(destinationIdDate[1]).value;
				year = document.getElementById(destinationIdDate[2]).value;
				if (this.checkDate(day,month,year))
					returnDate.setFullYear(year,month-1,day);

				dateString = document.getElementById(destinationIdDate[0]).value;
				var explode = dateString.split("/");
				if (explode.length == 3)
				{
					returnDate.setFullYear(explode[2],explode[1]-1,explode[0]);
				}
				break;
		}

		this.monthToDisplay = returnDate.getMonth();
		this.yearToDisplay = returnDate.getFullYear();
		if (this.startDate != null)
		{
			if (returnDate < this.startDate)
			{
				this.monthToDisplay = this.startDate.getMonth();
				this.yearToDisplay = this.startDate.getFullYear();
			}
		}
		if (this.endDate != null)
		{
			if (returnDate > this.endDate)
			{
				this.monthToDisplay = this.endDate.getMonth();
				this.yearToDisplay = this.endDate.getFullYear();
			}
		}
		return returnDate;
	}

	this.checkDateFromDestinationInput=function()
	{
		switch(this.destinationTypeDate)
		{
			case "STANDARD" :
				day = document.getElementById(destinationIdDate[0]).value;
				month = document.getElementById(destinationIdDate[1]).value;
				year = document.getElementById(destinationIdDate[2]).value;
				if (this.checkDate(day,month,year))
					return true

			case "INONEINPUT" :
				dateString = document.getElementById(destinationIdDate[0]).value;
				var explode = dateString.split(".");
				if (explode.length == 3)
				{
					returnDate.setFullYear(explode[2],explode[1]-1,explode[0]);
				}
		}
		return false;
	}

	this.checkDate=function(day,month,year)
	{
		if ((day > 0) && (day < 32) && (month >= 0) && (month <= 12) && (year > 1990) && (year < 2050))
			return true;
		else
			return false;
	}
	this.setLeftCalendars=function(calendar)
	{
		this.leftCalendars = calendar;
	}

	this.setRightCalendars=function(calendar)
	{
		this.rightCalendars = calendar;
	}

	this.addActionAfterClick=function(action)
	{
		for (var i=0; i<this.calendars.length; i++)
		{
			this.calendars[i].afterOnclick += action+";";
		}
	}

}



function wstaw_date(destination,ile_dni)
{
	d1 = document.getElementById(destination[0][0]).value;
	m1 = document.getElementById(destination[0][1]).value;
	r1 = document.getElementById(destination[0][2]).value;

	data = new Date();
	milisec = data.getTime();

	data.setTime((milisec+(ile_dni*1000*60*60*24)));

	for (var i=0; i<destination.length; i++)
	{
		if (destination[i].length == 3)
		{
			document.getElementById(destination[i][0]).value = format(data.getDate());
			document.getElementById(destination[i][1]).value = format(data.getMonth()+1);
			document.getElementById(destination[i][2]).value = data.getFullYear();
		}
		else
		{
			document.getElementById(destination[i][0]).value = format(data.getDate())+"."+format(data.getMonth()+1)+"."+data.getFullYear();
		}
	}
}

function format(str)
{
	if (str < 10)
		str = "0"+str;
	return str;
}

function wstaw_daty()
{
	wstaw_date(
		Array(
			Array('w_d','w_m','w_r'),
			Array('date_from')
			)
		,7);

	wstaw_date(
		Array(
			Array('p_d','p_m','p_r'),
			Array('date_to')
			)
		,7);
}
