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 hideUnusedCalendars(){
	try {	cals_from.hideCalendars();}catch (e){	}
	try {	cals_to.hideCalendars();}catch (e){	}

}

function createCalendars_two()
{	
	//mierzeczas = new Date();
	cals_from = new Calendars(new Date(),null,null,null,"cals_from",document.getElementById("calendar_from"),12,2,"TWOPLACES",Array(
		"w_d",
		"w_m",
		"w_r",
		"date_from"),
		Array());
	cals_to = new Calendars(new Date(),null,null,null,"cals_to",document.getElementById("calendar_to"),12,2,"TWOPLACES",Array(
		"p_d",
		"p_m",
		"p_r",
		"date_to"),
		Array("corner-right-bottom")
		);
	
	cals_from.setRightCalendars(cals_to);
	cals_to.setLeftCalendars(cals_from);
	
	cals_from.builtCalendars();
	cals_to.builtCalendars();

}
function createCalendars_homePage()
{	
	//mierzeczas = new Date();
	cals_from = new Calendars(new Date(),null,null,null,"cals_from",document.getElementById("calendar_from"),12,2,"TWOPLACES",Array(
		"w_d",
		"w_m",
		"w_r",
		"date_from"),
		Array("godz_w","godz_p","ile_dor","ile_mlo","ile_nie","ile_dzi"));
	cals_to = new Calendars(new Date(),null,null,null,"cals_to",document.getElementById("calendar_to"),12,2,"TWOPLACES",Array(
		"p_d",
		"p_m",
		"p_r",
		"date_to"),
		Array("godz_p","ile_nie","ile_dzi")
		);
	cals_from.setRightCalendars(cals_to);
	cals_to.setLeftCalendars(cals_from);
	cals_from.builtCalendars();
	cals_to.builtCalendars();
}

function createCalendars_miniform()
{	
	//mierzeczas = new Date();
	
	cals_from = new Calendars(new Date(),null,null,null,"cals_from",document.getElementById("calendar_from"),12,2,"TWOPLACESMINI",Array(
		"w_d",
		"w_m",
		"w_r",
		"date_from"),
		Array(document.getElementById('godz_w_wid'),document.getElementById('godz_p_wid')));
	cals_to = new Calendars(new Date(),null,null,null,"cals_to",document.getElementById("calendar_to"),12,2,"TWOPLACESMINI",Array(
		"p_d",
		"p_m",
		"p_r",
		"date_to"),
		Array(document.getElementById('godz_p_wid'))
		);
	
	cals_from.setRightCalendars(cals_to);
	cals_to.setLeftCalendars(cals_from);
	
	cals_from.builtCalendars();
	cals_to.builtCalendars();

}

function createCalendars_one_to()
{	
	//mierzeczas = new Date();
	
	cals_to = new Calendars(new Date(),null,null,null,"cals_to",document.getElementById("calendar_to"),12,2,"TWOPLACES",Array(
		"p_d",
		"p_m",
		"p_r",
		"date_to"),
		Array()
		);
	
	cals_to.builtCalendars();

}

function createCalendars_one_from()
{	
	//mierzeczas = new Date();
	
	cals_from = new Calendars(new Date(),null,null,null,"cals_from",document.getElementById("calendar_from"),12,2,"TWOPLACES",Array(
		"w_d",
		"w_m",
		"w_r",
		"date_from"),
		Array()
		);
	
	cals_from.builtCalendars();

}


function Calendars(
	startDate,
	endDate,
	firstDate,
	selectedDate,
	objName,
	destinationObj,
	countCalendars,
	countShowCalendars,
	destinationTypeDate,
	destinationIdDate,
	elementsToDisable
)
{
	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();
	
	//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\" >";
		buffor += "<tr><td class=\"naviLeft\"><div class=\"nameMonthPrev\" id=\""+this.objName+"_nameMont1\">Nazwa miesiaca</div></td><td class=\"naviRight\"><img src=\"/img/AERO/PL/x.jpg\" alt=\"Zamknij kalandarz\" class=\"closecalendar\" onclick=\"clickOutsideCalendars()\" /><div class=\"nameMonthNext\" id=\""+this.objName+"_nameMont2\">Nazwa miesiaca</div></td></tr>"
		buffor += "<tr>";
		for (var i=0; i<this.countCalendars; i++)
		{
			buffor += "<td class=\"calendar\" id=\""+this.objName+"_calendar_"+i+"\"></td>";	
		}
		buffor += "</tr>"
		buffor += "<tr><td style=\"padding-bottom:0px\" colspan=\"2\" class=\"bottom_tiny_line\"></td></tr>"
		buffor += "<tr><td style=\"padding-bottom:0px\"><a style=\"background-image:url(../../../img/AERO/PL/link_arrow_left.gif);margin-left:10px;background-repeat:no-repeat;background-position:0% 4px;float:left;margin-bottom:10px;padding-left:10px !important;color:#38495E;text-decoration:underline;\" alt=\"poprzedni\" href=\"javascript:"+this.objName+".prevMonth()\">poprzedni</a></td>"
		buffor += "<td style=\"padding-bottom:0px\"><a style=\"background-image:url(../../../img/AERO/PL/link_arrow_right.gif);margin-right:10px;background-repeat:no-repeat;background-position:100% 4px;float:right;padding-right:10px !important;color:#38495E;margin-bottom:10px;text-decoration:underline;\" alt=\"nastêpny\" href=\"javascript:"+this.objName+".nextMonth()\">nastêpny<br</a></td></tr>"
		buffor += "</table>";
		this.destinationObj.innerHTML = buffor;
		buffor = "";
		
		for (var i=0; i<this.countCalendars; i++)
		{
			this.calendarsArrayObj[this.calendarsArrayObj.length] = document.getElementById(this.objName+"_calendar_"+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;
		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";
			else
				{
				this.calendarsArrayObj[i].style.display="table-cell";
				}
			document.getElementById(this.objName+"_nameMont"+index).innerHTML = this.calendars[i].getMonthName()+" "+this.calendars[i].getYear();
			index++;
		}
		
		// 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';
		// AERO path end	
		
		this.destinationObj.style.display="block";

	}
	
	this.hideCalendars=function()
	{
		this.showElements();
		this.destinationObj.style.display="none";
		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";
			
			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";
			else
				this.calendarsArrayObj[this.shownCalendars["left"]-1].style.display="table-cell";
			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;
			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++;
			}
		}
	}
	
	this.nextMonth=function()
	{
		if (this.isNextMonth())
		{
			this.calendarsArrayObj[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";
			else
				this.calendarsArrayObj[this.shownCalendars["right"]+1].style.display="table-cell";
			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;
			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++;
			}
		}
	}
	
	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]);
				//} 
			
		}
		//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]);
				} 
		}

		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')
			)
		,3); 
		
	wstaw_date(
		Array(
			Array('p_d','p_m','p_r'),
			Array('date_to')
			)
		,7);
}
